tengwar 0.3.1__tar.gz
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-0.3.1/LICENSE +21 -0
- tengwar-0.3.1/PKG-INFO +202 -0
- tengwar-0.3.1/README.md +183 -0
- tengwar-0.3.1/pyproject.toml +32 -0
- tengwar-0.3.1/setup.cfg +4 -0
- tengwar-0.3.1/tengwar/__init__.py +20 -0
- tengwar-0.3.1/tengwar/__main__.py +8 -0
- tengwar-0.3.1/tengwar/ast_nodes.py +351 -0
- tengwar-0.3.1/tengwar/binary_ast.py +654 -0
- tengwar-0.3.1/tengwar/errors.py +43 -0
- tengwar-0.3.1/tengwar/interpreter.py +1845 -0
- tengwar-0.3.1/tengwar/lexer.py +483 -0
- tengwar-0.3.1/tengwar/mcp_server.py +496 -0
- tengwar-0.3.1/tengwar/parser.py +603 -0
- tengwar-0.3.1/tengwar/repl.py +152 -0
- tengwar-0.3.1/tengwar/vm.py +425 -0
- tengwar-0.3.1/tengwar.egg-info/PKG-INFO +202 -0
- tengwar-0.3.1/tengwar.egg-info/SOURCES.txt +21 -0
- tengwar-0.3.1/tengwar.egg-info/dependency_links.txt +1 -0
- tengwar-0.3.1/tengwar.egg-info/entry_points.txt +2 -0
- tengwar-0.3.1/tengwar.egg-info/top_level.txt +1 -0
- tengwar-0.3.1/tests/test_all.py +197 -0
- tengwar-0.3.1/tests/test_v03.py +457 -0
tengwar-0.3.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 TENGWAR Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tengwar-0.3.1/PKG-INFO
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tengwar
|
|
3
|
+
Version: 0.3.1
|
|
4
|
+
Summary: The AI-Native Programming Language
|
|
5
|
+
Author: TENGWAR Project
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://galcock.github.io/tengwar
|
|
8
|
+
Project-URL: Repository, https://github.com/galcock/tengwar
|
|
9
|
+
Keywords: ai,programming-language,functional,lisp,mcp,binary-ast
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# Tengwar
|
|
21
|
+
|
|
22
|
+
**The programming language built for AI.**
|
|
23
|
+
|
|
24
|
+
Tengwar is a functional programming language designed from the ground up for AI agents to write, reason about, and execute. It combines a minimal Lisp-like syntax with Unicode operators, Python interop, and a binary AST protocol that lets AI emit executable programs as structured opcodes — zero syntax errors, zero parsing overhead.
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
;; Tengwar: What AI-native code looks like
|
|
28
|
+
|
|
29
|
+
(pipe ⟦1 2 3 4 5 6 7 8 9 10⟧
|
|
30
|
+
{filter {> _ 5} _}
|
|
31
|
+
{map {* _ 2} _}
|
|
32
|
+
(reduce + 0)) ;; → 90
|
|
33
|
+
|
|
34
|
+
(let data (json-parse (dict-get (http-get "https://api.example.com/data") "body"))
|
|
35
|
+
ids (map {dict-get _ "id"} data)
|
|
36
|
+
(json-encode ids))
|
|
37
|
+
|
|
38
|
+
(>> (py-import "pandas")
|
|
39
|
+
(py-call pandas "read_csv" "data.csv") → df
|
|
40
|
+
(py-call df "describe"))
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Install
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install tengwar
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Why Tengwar?
|
|
50
|
+
|
|
51
|
+
| Feature | Python | JavaScript | Tengwar |
|
|
52
|
+
|---------|--------|------------|---------|
|
|
53
|
+
| AI syntax errors | Frequent | Frequent | **Impossible** (Binary AST) |
|
|
54
|
+
| Tokens per program | ~100 | ~120 | **~40** |
|
|
55
|
+
| Sandbox mode | Complex | Complex | **Built-in** |
|
|
56
|
+
| Python interop | N/A | None | **Native** |
|
|
57
|
+
| Functional stdlib | Limited | Limited | **80+ builtins** |
|
|
58
|
+
| Pattern matching | 3.10+ | No | **Native** |
|
|
59
|
+
| Tail recursion | No | No | **Yes** |
|
|
60
|
+
|
|
61
|
+
## Features
|
|
62
|
+
|
|
63
|
+
### Core Language
|
|
64
|
+
- **S-expression syntax** — minimal, unambiguous, zero-effort for AI to generate
|
|
65
|
+
- **Unicode operators** — `λ` `→` `⟦⟧` `⟨⟩` `∅` `≡` `↺` — or ASCII equivalents
|
|
66
|
+
- **Pattern matching** — `(match expr (pattern1 body1) (pattern2 body2))`
|
|
67
|
+
- **Let bindings** — `(let x 10 y 20 (+ x y))`
|
|
68
|
+
- **Pipe operator** — `(pipe value f1 f2 f3)` — thread data through transforms
|
|
69
|
+
- **Short lambdas** — `{+ _ 1}` = `(λ _ (+ _ 1))`
|
|
70
|
+
- **Closures** with lexical scope
|
|
71
|
+
- **Tail-call optimization** — 10,000+ recursive calls, no stack overflow
|
|
72
|
+
- **Parallel execution** — `(‖ expr1 expr2 expr3)` runs concurrently
|
|
73
|
+
- **Mutable state** — `(mut! x 0)` when you need it
|
|
74
|
+
|
|
75
|
+
### 80+ Standard Library Functions
|
|
76
|
+
|
|
77
|
+
**Collections:** `map` `filter` `reduce` `flat-map` `find` `take` `drop` `take-while` `drop-while` `zip-with` `group-by` `unique` `frequencies` `partition` `scan` `chunks` `interleave` `repeat` `iterate` `sort` `sort-by` `reverse` `concat` `len` `head` `tail` `nth` `range` `any?` `all?` `count`
|
|
78
|
+
|
|
79
|
+
**Dictionaries:** `dict` `dict-get` `dict-set` `dict-del` `dict-keys` `dict-vals` `dict-pairs` `dict-has?` `dict-merge` `dict-size`
|
|
80
|
+
|
|
81
|
+
**Strings:** `fmt` `starts-with?` `ends-with?` `chars` `char-at` `pad-left` `pad-right` `split` `join` `upper` `lower` `trim` `replace`
|
|
82
|
+
|
|
83
|
+
**Math:** `abs` `min` `max` `clamp` `floor` `ceil` `round` `pi` `e` `rand` `rand-int`
|
|
84
|
+
|
|
85
|
+
**Types:** `type` `int?` `float?` `str?` `bool?` `vec?` `tuple?` `dict?` `fn?` `nil?`
|
|
86
|
+
|
|
87
|
+
**I/O:** `read-file` `write-file` `append-file` `file-exists?` `http-get` `http-post` `json-parse` `json-encode`
|
|
88
|
+
|
|
89
|
+
**System:** `time-ms` `sleep` `uuid` `env-get`
|
|
90
|
+
|
|
91
|
+
### Python Interop
|
|
92
|
+
|
|
93
|
+
Call any Python library directly from Tengwar:
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
(py-import "numpy")
|
|
97
|
+
(>> (py-call numpy "array" ⟦1 2 3 4 5⟧) → arr
|
|
98
|
+
(py-call arr "mean")) ;; → 3.0
|
|
99
|
+
|
|
100
|
+
(py-import "requests")
|
|
101
|
+
(>> (py-call requests "get" "https://api.github.com") → resp
|
|
102
|
+
(py-attr resp "status_code")) ;; → 200
|
|
103
|
+
|
|
104
|
+
;; Dot access works too
|
|
105
|
+
(>> (py-import "math")
|
|
106
|
+
math.pi) ;; → 3.14159...
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Binary AST Protocol (TBAP)
|
|
110
|
+
|
|
111
|
+
**The killer AI feature.** Instead of generating text and parsing it, emit compact binary opcodes that map directly to AST nodes.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from tengwar.binary_ast import ASTBuilder, encode_b64, run_b64
|
|
115
|
+
|
|
116
|
+
# AI builds programs structurally — ZERO syntax errors possible
|
|
117
|
+
b = ASTBuilder()
|
|
118
|
+
program = b.program(
|
|
119
|
+
b.define("double", b.lam(["x"], b.binop("*", b.sym("x"), b.int(2)))),
|
|
120
|
+
b.apply(b.sym("double"), b.int(21))
|
|
121
|
+
)
|
|
122
|
+
result = b.run(program) # → 42
|
|
123
|
+
|
|
124
|
+
# Or encode to base64 for embedding in tool-call JSON
|
|
125
|
+
b64 = encode_b64("(reduce + 0 (map {* _ 2} ⟦1 2 3 4 5⟧))")
|
|
126
|
+
result = run_b64(b64) # → 30
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Sandbox Mode
|
|
130
|
+
|
|
131
|
+
Safe execution with resource limits:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from tengwar.interpreter import Interpreter
|
|
135
|
+
|
|
136
|
+
i = Interpreter(sandbox=True)
|
|
137
|
+
i.run_source("(reduce + 0 ⟦1 2 3 4 5⟧)") # ✓ Pure computation
|
|
138
|
+
|
|
139
|
+
i.run_source('(read-file "/etc/passwd")') # ✗ File I/O blocked
|
|
140
|
+
i.run_source('(http-get "http://evil.com")') # ✗ Network blocked
|
|
141
|
+
i.run_source('(py-import "os")') # ✗ Python imports blocked
|
|
142
|
+
|
|
143
|
+
i.max_steps = 10000 # Prevents infinite loops
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Error Handling
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
(catch (+ 1 2) (λ e (fmt "Error: {}" e))) ;; → 3
|
|
150
|
+
(catch (throw "oops") (λ e (fmt "Caught: {}" e))) ;; → "Caught: oops"
|
|
151
|
+
(try {+ 1 1} {_}) ;; → (true, ...)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Quick Reference
|
|
155
|
+
|
|
156
|
+
```
|
|
157
|
+
;; Define & functions
|
|
158
|
+
(≡ name value) (λ x y (+ x y)) {+ _ 1}
|
|
159
|
+
|
|
160
|
+
;; Conditional & pattern match
|
|
161
|
+
(? cond then else) (match val (0 "z") (_ "other"))
|
|
162
|
+
|
|
163
|
+
;; Let & pipe
|
|
164
|
+
(let x 10 y 20 (+ x y)) (pipe data sort head)
|
|
165
|
+
|
|
166
|
+
;; Collections
|
|
167
|
+
⟦1 2 3⟧ ⟨1 2 3⟩ (dict "a" 1 "b" 2)
|
|
168
|
+
|
|
169
|
+
;; Bind & sequence
|
|
170
|
+
(>> expr → name next) (↺ f (λ n (f (- n 1))))
|
|
171
|
+
|
|
172
|
+
;; Parallel
|
|
173
|
+
(‖ (http-get url1) (http-get url2) (http-get url3))
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## ASCII Mode
|
|
177
|
+
|
|
178
|
+
| Unicode | ASCII | Unicode | ASCII |
|
|
179
|
+
|---------|-------|---------|-------|
|
|
180
|
+
| `λ` | `fn` | `≡` | `def` |
|
|
181
|
+
| `→` | `->` | `⟦⟧` | `[]` |
|
|
182
|
+
| `⟨⟩` | tuple | `∅` | `nil` |
|
|
183
|
+
| `?` | `if` | `>>` | `do` |
|
|
184
|
+
| `↺` | `rec` | `‖` | `par` |
|
|
185
|
+
|
|
186
|
+
## v0.3 Changelog
|
|
187
|
+
|
|
188
|
+
- **80+ new builtins** — dictionaries, extended functional, strings, math, types, I/O
|
|
189
|
+
- **Let bindings** — `(let x 1 y 2 body)` local scope
|
|
190
|
+
- **Pipe operator** — `(pipe value f1 f2 f3)` data threading
|
|
191
|
+
- **Error handling** — `throw`, `catch`, `try` forms
|
|
192
|
+
- **Python interop** — `py-import`, `py-call`, `py-attr`, `py-eval`, dot access
|
|
193
|
+
- **HTTP/JSON/File I/O** — agent primitives for real-world tasks
|
|
194
|
+
- **Binary AST Protocol** — AI emits opcodes, zero syntax errors
|
|
195
|
+
- **ASTBuilder** — programmatic AST construction API
|
|
196
|
+
- **Sandbox mode** — safe execution with I/O, network, and step limits
|
|
197
|
+
- **Deep recursion** — 10,000+ recursive calls supported
|
|
198
|
+
- **200 tests** — comprehensive test suite
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
tengwar-0.3.1/README.md
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
# Tengwar
|
|
2
|
+
|
|
3
|
+
**The programming language built for AI.**
|
|
4
|
+
|
|
5
|
+
Tengwar is a functional programming language designed from the ground up for AI agents to write, reason about, and execute. It combines a minimal Lisp-like syntax with Unicode operators, Python interop, and a binary AST protocol that lets AI emit executable programs as structured opcodes — zero syntax errors, zero parsing overhead.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
;; Tengwar: What AI-native code looks like
|
|
9
|
+
|
|
10
|
+
(pipe ⟦1 2 3 4 5 6 7 8 9 10⟧
|
|
11
|
+
{filter {> _ 5} _}
|
|
12
|
+
{map {* _ 2} _}
|
|
13
|
+
(reduce + 0)) ;; → 90
|
|
14
|
+
|
|
15
|
+
(let data (json-parse (dict-get (http-get "https://api.example.com/data") "body"))
|
|
16
|
+
ids (map {dict-get _ "id"} data)
|
|
17
|
+
(json-encode ids))
|
|
18
|
+
|
|
19
|
+
(>> (py-import "pandas")
|
|
20
|
+
(py-call pandas "read_csv" "data.csv") → df
|
|
21
|
+
(py-call df "describe"))
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pip install tengwar
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Why Tengwar?
|
|
31
|
+
|
|
32
|
+
| Feature | Python | JavaScript | Tengwar |
|
|
33
|
+
|---------|--------|------------|---------|
|
|
34
|
+
| AI syntax errors | Frequent | Frequent | **Impossible** (Binary AST) |
|
|
35
|
+
| Tokens per program | ~100 | ~120 | **~40** |
|
|
36
|
+
| Sandbox mode | Complex | Complex | **Built-in** |
|
|
37
|
+
| Python interop | N/A | None | **Native** |
|
|
38
|
+
| Functional stdlib | Limited | Limited | **80+ builtins** |
|
|
39
|
+
| Pattern matching | 3.10+ | No | **Native** |
|
|
40
|
+
| Tail recursion | No | No | **Yes** |
|
|
41
|
+
|
|
42
|
+
## Features
|
|
43
|
+
|
|
44
|
+
### Core Language
|
|
45
|
+
- **S-expression syntax** — minimal, unambiguous, zero-effort for AI to generate
|
|
46
|
+
- **Unicode operators** — `λ` `→` `⟦⟧` `⟨⟩` `∅` `≡` `↺` — or ASCII equivalents
|
|
47
|
+
- **Pattern matching** — `(match expr (pattern1 body1) (pattern2 body2))`
|
|
48
|
+
- **Let bindings** — `(let x 10 y 20 (+ x y))`
|
|
49
|
+
- **Pipe operator** — `(pipe value f1 f2 f3)` — thread data through transforms
|
|
50
|
+
- **Short lambdas** — `{+ _ 1}` = `(λ _ (+ _ 1))`
|
|
51
|
+
- **Closures** with lexical scope
|
|
52
|
+
- **Tail-call optimization** — 10,000+ recursive calls, no stack overflow
|
|
53
|
+
- **Parallel execution** — `(‖ expr1 expr2 expr3)` runs concurrently
|
|
54
|
+
- **Mutable state** — `(mut! x 0)` when you need it
|
|
55
|
+
|
|
56
|
+
### 80+ Standard Library Functions
|
|
57
|
+
|
|
58
|
+
**Collections:** `map` `filter` `reduce` `flat-map` `find` `take` `drop` `take-while` `drop-while` `zip-with` `group-by` `unique` `frequencies` `partition` `scan` `chunks` `interleave` `repeat` `iterate` `sort` `sort-by` `reverse` `concat` `len` `head` `tail` `nth` `range` `any?` `all?` `count`
|
|
59
|
+
|
|
60
|
+
**Dictionaries:** `dict` `dict-get` `dict-set` `dict-del` `dict-keys` `dict-vals` `dict-pairs` `dict-has?` `dict-merge` `dict-size`
|
|
61
|
+
|
|
62
|
+
**Strings:** `fmt` `starts-with?` `ends-with?` `chars` `char-at` `pad-left` `pad-right` `split` `join` `upper` `lower` `trim` `replace`
|
|
63
|
+
|
|
64
|
+
**Math:** `abs` `min` `max` `clamp` `floor` `ceil` `round` `pi` `e` `rand` `rand-int`
|
|
65
|
+
|
|
66
|
+
**Types:** `type` `int?` `float?` `str?` `bool?` `vec?` `tuple?` `dict?` `fn?` `nil?`
|
|
67
|
+
|
|
68
|
+
**I/O:** `read-file` `write-file` `append-file` `file-exists?` `http-get` `http-post` `json-parse` `json-encode`
|
|
69
|
+
|
|
70
|
+
**System:** `time-ms` `sleep` `uuid` `env-get`
|
|
71
|
+
|
|
72
|
+
### Python Interop
|
|
73
|
+
|
|
74
|
+
Call any Python library directly from Tengwar:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
(py-import "numpy")
|
|
78
|
+
(>> (py-call numpy "array" ⟦1 2 3 4 5⟧) → arr
|
|
79
|
+
(py-call arr "mean")) ;; → 3.0
|
|
80
|
+
|
|
81
|
+
(py-import "requests")
|
|
82
|
+
(>> (py-call requests "get" "https://api.github.com") → resp
|
|
83
|
+
(py-attr resp "status_code")) ;; → 200
|
|
84
|
+
|
|
85
|
+
;; Dot access works too
|
|
86
|
+
(>> (py-import "math")
|
|
87
|
+
math.pi) ;; → 3.14159...
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Binary AST Protocol (TBAP)
|
|
91
|
+
|
|
92
|
+
**The killer AI feature.** Instead of generating text and parsing it, emit compact binary opcodes that map directly to AST nodes.
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from tengwar.binary_ast import ASTBuilder, encode_b64, run_b64
|
|
96
|
+
|
|
97
|
+
# AI builds programs structurally — ZERO syntax errors possible
|
|
98
|
+
b = ASTBuilder()
|
|
99
|
+
program = b.program(
|
|
100
|
+
b.define("double", b.lam(["x"], b.binop("*", b.sym("x"), b.int(2)))),
|
|
101
|
+
b.apply(b.sym("double"), b.int(21))
|
|
102
|
+
)
|
|
103
|
+
result = b.run(program) # → 42
|
|
104
|
+
|
|
105
|
+
# Or encode to base64 for embedding in tool-call JSON
|
|
106
|
+
b64 = encode_b64("(reduce + 0 (map {* _ 2} ⟦1 2 3 4 5⟧))")
|
|
107
|
+
result = run_b64(b64) # → 30
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Sandbox Mode
|
|
111
|
+
|
|
112
|
+
Safe execution with resource limits:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from tengwar.interpreter import Interpreter
|
|
116
|
+
|
|
117
|
+
i = Interpreter(sandbox=True)
|
|
118
|
+
i.run_source("(reduce + 0 ⟦1 2 3 4 5⟧)") # ✓ Pure computation
|
|
119
|
+
|
|
120
|
+
i.run_source('(read-file "/etc/passwd")') # ✗ File I/O blocked
|
|
121
|
+
i.run_source('(http-get "http://evil.com")') # ✗ Network blocked
|
|
122
|
+
i.run_source('(py-import "os")') # ✗ Python imports blocked
|
|
123
|
+
|
|
124
|
+
i.max_steps = 10000 # Prevents infinite loops
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Error Handling
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
(catch (+ 1 2) (λ e (fmt "Error: {}" e))) ;; → 3
|
|
131
|
+
(catch (throw "oops") (λ e (fmt "Caught: {}" e))) ;; → "Caught: oops"
|
|
132
|
+
(try {+ 1 1} {_}) ;; → (true, ...)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Quick Reference
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
;; Define & functions
|
|
139
|
+
(≡ name value) (λ x y (+ x y)) {+ _ 1}
|
|
140
|
+
|
|
141
|
+
;; Conditional & pattern match
|
|
142
|
+
(? cond then else) (match val (0 "z") (_ "other"))
|
|
143
|
+
|
|
144
|
+
;; Let & pipe
|
|
145
|
+
(let x 10 y 20 (+ x y)) (pipe data sort head)
|
|
146
|
+
|
|
147
|
+
;; Collections
|
|
148
|
+
⟦1 2 3⟧ ⟨1 2 3⟩ (dict "a" 1 "b" 2)
|
|
149
|
+
|
|
150
|
+
;; Bind & sequence
|
|
151
|
+
(>> expr → name next) (↺ f (λ n (f (- n 1))))
|
|
152
|
+
|
|
153
|
+
;; Parallel
|
|
154
|
+
(‖ (http-get url1) (http-get url2) (http-get url3))
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## ASCII Mode
|
|
158
|
+
|
|
159
|
+
| Unicode | ASCII | Unicode | ASCII |
|
|
160
|
+
|---------|-------|---------|-------|
|
|
161
|
+
| `λ` | `fn` | `≡` | `def` |
|
|
162
|
+
| `→` | `->` | `⟦⟧` | `[]` |
|
|
163
|
+
| `⟨⟩` | tuple | `∅` | `nil` |
|
|
164
|
+
| `?` | `if` | `>>` | `do` |
|
|
165
|
+
| `↺` | `rec` | `‖` | `par` |
|
|
166
|
+
|
|
167
|
+
## v0.3 Changelog
|
|
168
|
+
|
|
169
|
+
- **80+ new builtins** — dictionaries, extended functional, strings, math, types, I/O
|
|
170
|
+
- **Let bindings** — `(let x 1 y 2 body)` local scope
|
|
171
|
+
- **Pipe operator** — `(pipe value f1 f2 f3)` data threading
|
|
172
|
+
- **Error handling** — `throw`, `catch`, `try` forms
|
|
173
|
+
- **Python interop** — `py-import`, `py-call`, `py-attr`, `py-eval`, dot access
|
|
174
|
+
- **HTTP/JSON/File I/O** — agent primitives for real-world tasks
|
|
175
|
+
- **Binary AST Protocol** — AI emits opcodes, zero syntax errors
|
|
176
|
+
- **ASTBuilder** — programmatic AST construction API
|
|
177
|
+
- **Sandbox mode** — safe execution with I/O, network, and step limits
|
|
178
|
+
- **Deep recursion** — 10,000+ recursive calls supported
|
|
179
|
+
- **200 tests** — comprehensive test suite
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tengwar"
|
|
7
|
+
version = "0.3.1"
|
|
8
|
+
description = "The AI-Native Programming Language"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "TENGWAR Project"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["ai", "programming-language", "functional", "lisp", "mcp", "binary-ast"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Topic :: Software Development :: Interpreters",
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://galcock.github.io/tengwar"
|
|
26
|
+
Repository = "https://github.com/galcock/tengwar"
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
tengwar = "tengwar.repl:repl"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
include = ["tengwar*"]
|
tengwar-0.3.1/setup.cfg
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
|