tengwar 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tengwar/__init__.py ADDED
@@ -0,0 +1,20 @@
1
+ """
2
+ TENGWAR - The AI-Native Programming Language
3
+
4
+ Built from first principles for machine intelligence.
5
+ Zero ambiguity. Maximum semantic density. Binary AST protocol.
6
+ """
7
+
8
+ __version__ = "0.3.1"
9
+ __author__ = "TENGWAR Project"
10
+
11
+ from .lexer import tokenize
12
+ from .parser import parse
13
+ from .interpreter import Interpreter
14
+ from .repl import repl, run_file
15
+ from .errors import TengwarError, LexError, ParseError, RuntimeError_, ProofError
16
+ from .binary_ast import (
17
+ encode, decode, run_binary, encode_b64, run_b64,
18
+ ASTBuilder, Encoder, Decoder, Op
19
+ )
20
+ from .vm import VM, Compiler
tengwar/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ """Run Tengwar REPL or execute files: python -m tengwar [file.tw]"""
2
+ import sys
3
+ from .repl import repl, run_file
4
+
5
+ if len(sys.argv) > 1:
6
+ run_file(sys.argv[1])
7
+ else:
8
+ repl()
tengwar/ast_nodes.py ADDED
@@ -0,0 +1,351 @@
1
+ """
2
+ TENGWAR AST Node Definitions
3
+
4
+ Every node in the TENGWAR Abstract Syntax Tree.
5
+ The source representation IS the AST — no lossy parsing step.
6
+ """
7
+ from dataclasses import dataclass, field
8
+ from typing import Any
9
+ from enum import Enum, auto
10
+
11
+
12
+ class NodeType(Enum):
13
+ # Literals
14
+ INT = auto()
15
+ FLOAT = auto()
16
+ STRING = auto()
17
+ BOOL = auto()
18
+ UNIT = auto() # ∅
19
+
20
+ # Identifiers
21
+ SYMBOL = auto() # Regular symbol
22
+ HASH_ID = auto() # #abc content-addressed id
23
+ ADDR_REF = auto() # @abc address reference
24
+
25
+ # Core forms
26
+ LAMBDA = auto() # λ
27
+ BIND = auto() # →
28
+ COND = auto() # ?
29
+ MATCH = auto() # ~
30
+ SEQ = auto() # >> (sequence/do)
31
+ PARALLEL = auto() # ∥
32
+ MODULE = auto() # □
33
+ DEFINE = auto() # :=
34
+ RECURSE = auto() # ↺
35
+ TYPE_ANN = auto() # τ
36
+ PROOF = auto() # ⊢
37
+ EFFECT = auto() # ⊕
38
+ MUTATE = auto() # μ
39
+
40
+ # Collections
41
+ TUPLE = auto() # ⟨⟩
42
+ VECTOR = auto() # ⟦⟧
43
+
44
+ # Application
45
+ APPLY = auto() # (f args...)
46
+
47
+ # Binary / Unary ops
48
+ BINOP = auto()
49
+ UNOP = auto()
50
+
51
+ # Special
52
+ IMPORT = auto()
53
+ EXPORT = auto()
54
+ COMMENT = auto() # ;; machine-readable metadata
55
+ LET = auto() # (let bindings body)
56
+ PIPE = auto() # (|> val f1 f2 f3)
57
+ PY_IMPORT = auto() # (py-import "module")
58
+ THROW = auto() # (throw expr)
59
+ CATCH = auto() # (catch expr handler)
60
+
61
+
62
+ @dataclass
63
+ class ASTNode:
64
+ type: NodeType = None
65
+ line: int = 0
66
+ col: int = 0
67
+
68
+
69
+ @dataclass
70
+ class IntLit(ASTNode):
71
+ value: int = 0
72
+ def __post_init__(self):
73
+ self.type = NodeType.INT
74
+
75
+
76
+ @dataclass
77
+ class FloatLit(ASTNode):
78
+ value: float = 0.0
79
+ def __post_init__(self):
80
+ self.type = NodeType.FLOAT
81
+
82
+
83
+ @dataclass
84
+ class StrLit(ASTNode):
85
+ value: str = ""
86
+ def __post_init__(self):
87
+ self.type = NodeType.STRING
88
+
89
+
90
+ @dataclass
91
+ class BoolLit(ASTNode):
92
+ value: bool = False
93
+ def __post_init__(self):
94
+ self.type = NodeType.BOOL
95
+
96
+
97
+ @dataclass
98
+ class UnitLit(ASTNode):
99
+ def __post_init__(self):
100
+ self.type = NodeType.UNIT
101
+ self.value = None
102
+
103
+
104
+ @dataclass
105
+ class Symbol(ASTNode):
106
+ name: str = ""
107
+ def __post_init__(self):
108
+ self.type = NodeType.SYMBOL
109
+
110
+
111
+ @dataclass
112
+ class HashId(ASTNode):
113
+ """Content-addressed identifier like #a3f"""
114
+ hash: str = ""
115
+ def __post_init__(self):
116
+ self.type = NodeType.HASH_ID
117
+
118
+
119
+ @dataclass
120
+ class AddrRef(ASTNode):
121
+ """Address reference like @e4c2"""
122
+ addr: str = ""
123
+ def __post_init__(self):
124
+ self.type = NodeType.ADDR_REF
125
+
126
+
127
+ @dataclass
128
+ class Lambda(ASTNode):
129
+ """(λ params body) or (λ params τ type body)"""
130
+ params: list = field(default_factory=list)
131
+ body: Any = None
132
+ type_ann: Any = None # Optional type annotation
133
+ def __post_init__(self):
134
+ self.type = NodeType.LAMBDA
135
+
136
+
137
+ @dataclass
138
+ class Bind(ASTNode):
139
+ """expr → target"""
140
+ expr: Any = None
141
+ target: Any = None
142
+ def __post_init__(self):
143
+ self.type = NodeType.BIND
144
+
145
+
146
+ @dataclass
147
+ class Define(ASTNode):
148
+ """:= name value"""
149
+ name: Any = None
150
+ value: Any = None
151
+ def __post_init__(self):
152
+ self.type = NodeType.DEFINE
153
+
154
+
155
+ @dataclass
156
+ class Cond(ASTNode):
157
+ """(? condition then else)"""
158
+ condition: Any = None
159
+ then_branch: Any = None
160
+ else_branch: Any = None
161
+ def __post_init__(self):
162
+ self.type = NodeType.COND
163
+
164
+
165
+ @dataclass
166
+ class Match(ASTNode):
167
+ """(~ expr (pattern result)...)"""
168
+ expr: Any = None
169
+ cases: list = field(default_factory=list) # List of (pattern, body) tuples
170
+ def __post_init__(self):
171
+ self.type = NodeType.MATCH
172
+
173
+
174
+ @dataclass
175
+ class Seq(ASTNode):
176
+ """(>> expr1 expr2 ...) - sequential execution"""
177
+ exprs: list = field(default_factory=list)
178
+ def __post_init__(self):
179
+ self.type = NodeType.SEQ
180
+
181
+
182
+ @dataclass
183
+ class Parallel(ASTNode):
184
+ """(∥ expr1 expr2 ...) - parallel execution"""
185
+ exprs: list = field(default_factory=list)
186
+ def __post_init__(self):
187
+ self.type = NodeType.PARALLEL
188
+
189
+
190
+ @dataclass
191
+ class Module(ASTNode):
192
+ """(□ ...definitions)"""
193
+ name: str = ""
194
+ body: list = field(default_factory=list)
195
+ def __post_init__(self):
196
+ self.type = NodeType.MODULE
197
+
198
+
199
+ @dataclass
200
+ class Recurse(ASTNode):
201
+ """(↺ name body) - explicit recursion"""
202
+ name: Any = None
203
+ body: Any = None
204
+ def __post_init__(self):
205
+ self.type = NodeType.RECURSE
206
+
207
+
208
+ @dataclass
209
+ class TypeAnn(ASTNode):
210
+ """τ(type) - type annotation"""
211
+ type_expr: Any = None
212
+ def __post_init__(self):
213
+ self.type = NodeType.TYPE_ANN
214
+
215
+
216
+ @dataclass
217
+ class Proof(ASTNode):
218
+ """(⊢ assertion) - proof obligation"""
219
+ assertion: Any = None
220
+ def __post_init__(self):
221
+ self.type = NodeType.PROOF
222
+
223
+
224
+ @dataclass
225
+ class Effect(ASTNode):
226
+ """⊕{effects} - effect declaration"""
227
+ effects: list = field(default_factory=list)
228
+ def __post_init__(self):
229
+ self.type = NodeType.EFFECT
230
+
231
+
232
+ @dataclass
233
+ class Mutate(ASTNode):
234
+ """(μ name value) - mutable cell"""
235
+ name: Any = None
236
+ value: Any = None
237
+ def __post_init__(self):
238
+ self.type = NodeType.MUTATE
239
+
240
+
241
+ @dataclass
242
+ class Tuple(ASTNode):
243
+ """⟨expr1 expr2 ...⟩"""
244
+ elements: list = field(default_factory=list)
245
+ def __post_init__(self):
246
+ self.type = NodeType.TUPLE
247
+
248
+
249
+ @dataclass
250
+ class Vector(ASTNode):
251
+ """⟦expr1 expr2 ...⟧"""
252
+ elements: list = field(default_factory=list)
253
+ def __post_init__(self):
254
+ self.type = NodeType.VECTOR
255
+
256
+
257
+ @dataclass
258
+ class Apply(ASTNode):
259
+ """(func arg1 arg2 ...)"""
260
+ func: Any = None
261
+ args: list = field(default_factory=list)
262
+ def __post_init__(self):
263
+ self.type = NodeType.APPLY
264
+
265
+
266
+ @dataclass
267
+ class BinOp(ASTNode):
268
+ """(op left right)"""
269
+ op: str = ""
270
+ left: Any = None
271
+ right: Any = None
272
+ def __post_init__(self):
273
+ self.type = NodeType.BINOP
274
+
275
+
276
+ @dataclass
277
+ class UnOp(ASTNode):
278
+ """(op operand)"""
279
+ op: str = ""
280
+ operand: Any = None
281
+ def __post_init__(self):
282
+ self.type = NodeType.UNOP
283
+
284
+
285
+ @dataclass
286
+ class Import(ASTNode):
287
+ """(⇐ @addr) - import module"""
288
+ addr: Any = None
289
+ def __post_init__(self):
290
+ self.type = NodeType.IMPORT
291
+
292
+
293
+ @dataclass
294
+ class Let(ASTNode):
295
+ """(let x 1 y 2 body) - local bindings"""
296
+ bindings: list = field(default_factory=list) # [(name, value), ...]
297
+ body: Any = None
298
+ def __post_init__(self):
299
+ self.type = NodeType.LET
300
+
301
+
302
+ @dataclass
303
+ class Pipe(ASTNode):
304
+ """(|> value f1 f2 f3) - pipe value through functions"""
305
+ value: Any = None
306
+ funcs: list = field(default_factory=list)
307
+ def __post_init__(self):
308
+ self.type = NodeType.PIPE
309
+
310
+
311
+ @dataclass
312
+ class Throw(ASTNode):
313
+ """(throw expr) - throw an error"""
314
+ expr: Any = None
315
+ def __post_init__(self):
316
+ self.type = NodeType.THROW
317
+
318
+
319
+ @dataclass
320
+ class Catch(ASTNode):
321
+ """(catch expr handler) - catch errors"""
322
+ expr: Any = None
323
+ handler: Any = None
324
+ def __post_init__(self):
325
+ self.type = NodeType.CATCH
326
+
327
+
328
+ @dataclass
329
+ class PyImportNode(ASTNode):
330
+ """(py-import \"module\") - import Python module"""
331
+ module_name: Any = None
332
+ alias: str = ""
333
+ def __post_init__(self):
334
+ self.type = NodeType.PY_IMPORT
335
+
336
+
337
+ @dataclass
338
+ class Comment(ASTNode):
339
+ """;; metadata comment (machine-readable)"""
340
+ content: str = ""
341
+ metadata: dict = field(default_factory=dict)
342
+ def __post_init__(self):
343
+ self.type = NodeType.COMMENT
344
+
345
+
346
+ @dataclass
347
+ class Program(ASTNode):
348
+ """Top-level program node"""
349
+ body: list = field(default_factory=list)
350
+ def __post_init__(self):
351
+ self.type = None