edict-lang 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +202 -0
- package/dist/ast/nodes.d.ts +248 -0
- package/dist/ast/nodes.d.ts.map +1 -0
- package/dist/ast/nodes.js +95 -0
- package/dist/ast/nodes.js.map +1 -0
- package/dist/ast/types.d.ts +78 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +7 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/check.d.ts +19 -0
- package/dist/check.d.ts.map +1 -0
- package/dist/check.js +49 -0
- package/dist/check.js.map +1 -0
- package/dist/checker/check.d.ts +7 -0
- package/dist/checker/check.d.ts.map +1 -0
- package/dist/checker/check.js +548 -0
- package/dist/checker/check.js.map +1 -0
- package/dist/checker/type-env.d.ts +24 -0
- package/dist/checker/type-env.d.ts.map +1 -0
- package/dist/checker/type-env.js +67 -0
- package/dist/checker/type-env.js.map +1 -0
- package/dist/checker/types-equal.d.ts +18 -0
- package/dist/checker/types-equal.d.ts.map +1 -0
- package/dist/checker/types-equal.js +79 -0
- package/dist/checker/types-equal.js.map +1 -0
- package/dist/codegen/builtins.d.ts +27 -0
- package/dist/codegen/builtins.d.ts.map +1 -0
- package/dist/codegen/builtins.js +54 -0
- package/dist/codegen/builtins.js.map +1 -0
- package/dist/codegen/codegen.d.ts +32 -0
- package/dist/codegen/codegen.d.ts.map +1 -0
- package/dist/codegen/codegen.js +1192 -0
- package/dist/codegen/codegen.js.map +1 -0
- package/dist/codegen/runner.d.ts +16 -0
- package/dist/codegen/runner.d.ts.map +1 -0
- package/dist/codegen/runner.js +82 -0
- package/dist/codegen/runner.js.map +1 -0
- package/dist/codegen/string-table.d.ts +35 -0
- package/dist/codegen/string-table.d.ts.map +1 -0
- package/dist/codegen/string-table.js +62 -0
- package/dist/codegen/string-table.js.map +1 -0
- package/dist/compile.d.ts +18 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +40 -0
- package/dist/compile.js.map +1 -0
- package/dist/contracts/translate.d.ts +39 -0
- package/dist/contracts/translate.d.ts.map +1 -0
- package/dist/contracts/translate.js +372 -0
- package/dist/contracts/translate.js.map +1 -0
- package/dist/contracts/verify.d.ts +8 -0
- package/dist/contracts/verify.d.ts.map +1 -0
- package/dist/contracts/verify.js +400 -0
- package/dist/contracts/verify.js.map +1 -0
- package/dist/contracts/z3-context.d.ts +14 -0
- package/dist/contracts/z3-context.d.ts.map +1 -0
- package/dist/contracts/z3-context.js +24 -0
- package/dist/contracts/z3-context.js.map +1 -0
- package/dist/effects/call-graph.d.ts +21 -0
- package/dist/effects/call-graph.d.ts.map +1 -0
- package/dist/effects/call-graph.js +135 -0
- package/dist/effects/call-graph.js.map +1 -0
- package/dist/effects/effect-check.d.ts +13 -0
- package/dist/effects/effect-check.d.ts.map +1 -0
- package/dist/effects/effect-check.js +48 -0
- package/dist/effects/effect-check.js.map +1 -0
- package/dist/errors/structured-errors.d.ts +193 -0
- package/dist/errors/structured-errors.d.ts.map +1 -0
- package/dist/errors/structured-errors.js +96 -0
- package/dist/errors/structured-errors.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/create-server.d.ts +3 -0
- package/dist/mcp/create-server.d.ts.map +1 -0
- package/dist/mcp/create-server.js +157 -0
- package/dist/mcp/create-server.js.map +1 -0
- package/dist/mcp/handlers.d.ts +44 -0
- package/dist/mcp/handlers.d.ts.map +1 -0
- package/dist/mcp/handlers.js +112 -0
- package/dist/mcp/handlers.js.map +1 -0
- package/dist/mcp/server.d.ts +3 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +129 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/resolver/levenshtein.d.ts +12 -0
- package/dist/resolver/levenshtein.d.ts.map +1 -0
- package/dist/resolver/levenshtein.js +54 -0
- package/dist/resolver/levenshtein.js.map +1 -0
- package/dist/resolver/resolve.d.ts +7 -0
- package/dist/resolver/resolve.d.ts.map +1 -0
- package/dist/resolver/resolve.js +393 -0
- package/dist/resolver/resolve.js.map +1 -0
- package/dist/resolver/scope.d.ts +34 -0
- package/dist/resolver/scope.d.ts.map +1 -0
- package/dist/resolver/scope.js +51 -0
- package/dist/resolver/scope.js.map +1 -0
- package/dist/validator/id-tracker.d.ts +14 -0
- package/dist/validator/id-tracker.d.ts.map +1 -0
- package/dist/validator/id-tracker.js +28 -0
- package/dist/validator/id-tracker.js.map +1 -0
- package/dist/validator/node-validators.d.ts +6 -0
- package/dist/validator/node-validators.d.ts.map +1 -0
- package/dist/validator/node-validators.js +808 -0
- package/dist/validator/node-validators.js.map +1 -0
- package/dist/validator/validate.d.ts +17 -0
- package/dist/validator/validate.d.ts.map +1 -0
- package/dist/validator/validate.js +27 -0
- package/dist/validator/validate.js.map +1 -0
- package/package.json +75 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sowiedu
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# Edict
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Sowiedu/Edict/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
[](https://nodejs.org)
|
|
6
|
+
[](https://modelcontextprotocol.io/)
|
|
7
|
+
|
|
8
|
+
**A programming language designed for AI agents.** No parser. No syntax. Agents produce AST directly as JSON.
|
|
9
|
+
|
|
10
|
+
Edict is a statically-typed, effect-tracked programming language where the canonical program format is a JSON AST. It's purpose-built so AI agents can write, verify, and execute programs through a structured pipeline — no text parsing, no human-readable syntax, no ambiguity.
|
|
11
|
+
|
|
12
|
+
```
|
|
13
|
+
Agent (LLM)
|
|
14
|
+
│ produces JSON AST via MCP tool call
|
|
15
|
+
↓
|
|
16
|
+
Schema Validator ─── invalid? → StructuredError → Agent retries
|
|
17
|
+
↓
|
|
18
|
+
Name Resolver ────── undefined? → StructuredError + candidates → Agent retries
|
|
19
|
+
↓
|
|
20
|
+
Type Checker ─────── mismatch? → StructuredError + expected type → Agent retries
|
|
21
|
+
↓
|
|
22
|
+
Effect Checker ───── violation? → StructuredError + propagation chain → Agent retries
|
|
23
|
+
↓
|
|
24
|
+
Contract Verifier ── unproven? → StructuredError + counterexample → Agent retries
|
|
25
|
+
(Z3/SMT) ↓
|
|
26
|
+
Code Generator (binaryen) → WASM → Execute
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- **JSON AST** — Programs are JSON objects, not text files. No lexer, no parser.
|
|
32
|
+
- **Structured errors** — Every error is a typed JSON object with enough context for an agent to self-repair.
|
|
33
|
+
- **Type system** — `Int`, `Float`, `String`, `Bool`, `Array<T>`, `Option<T>`, `Result<T,E>`, records, enums, refinement types.
|
|
34
|
+
- **Effect tracking** — Functions declare `pure`, `reads`, `writes`, `io`, `fails`. The compiler verifies consistency.
|
|
35
|
+
- **Contract verification** — Pre/post conditions verified at compile time by Z3 (via SMT). Failing contracts return concrete counterexamples.
|
|
36
|
+
- **WASM compilation** — Verified programs compile to WebAssembly via binaryen and run in Node.js.
|
|
37
|
+
- **MCP interface** — All tools exposed via [Model Context Protocol](https://modelcontextprotocol.io/) for direct agent integration.
|
|
38
|
+
|
|
39
|
+
## Quick Start
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npm install
|
|
43
|
+
npm test # 488 tests, ~1.5s
|
|
44
|
+
npm run mcp # start MCP server (stdio transport)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## MCP Tools
|
|
48
|
+
|
|
49
|
+
| Tool | Description |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `edict_schema` | Returns the full AST JSON Schema — the spec for how to write programs |
|
|
52
|
+
| `edict_examples` | Returns 10 example programs as JSON ASTs |
|
|
53
|
+
| `edict_validate` | Validates AST structure (field names, types, node kinds) |
|
|
54
|
+
| `edict_check` | Full pipeline: validate → resolve names → type check → effect check → verify contracts |
|
|
55
|
+
| `edict_compile` | Compiles a checked AST to WASM (returns base64-encoded binary) |
|
|
56
|
+
| `edict_run` | Executes a compiled WASM binary, returns output and exit code |
|
|
57
|
+
|
|
58
|
+
### MCP Resources
|
|
59
|
+
|
|
60
|
+
| URI | Description |
|
|
61
|
+
|---|---|
|
|
62
|
+
| `edict://schema` | The AST JSON Schema |
|
|
63
|
+
| `edict://examples` | All example programs |
|
|
64
|
+
|
|
65
|
+
## Example Program
|
|
66
|
+
|
|
67
|
+
A "Hello, World!" in Edict's JSON AST:
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"kind": "module",
|
|
72
|
+
"id": "mod-hello-001",
|
|
73
|
+
"name": "hello",
|
|
74
|
+
"imports": [],
|
|
75
|
+
"definitions": [
|
|
76
|
+
{
|
|
77
|
+
"kind": "fn",
|
|
78
|
+
"id": "fn-main-001",
|
|
79
|
+
"name": "main",
|
|
80
|
+
"params": [],
|
|
81
|
+
"effects": ["io"],
|
|
82
|
+
"returnType": { "kind": "basic", "name": "Int" },
|
|
83
|
+
"contracts": [],
|
|
84
|
+
"body": [
|
|
85
|
+
{
|
|
86
|
+
"kind": "call",
|
|
87
|
+
"id": "call-print-001",
|
|
88
|
+
"fn": { "kind": "ident", "id": "ident-print-001", "name": "print" },
|
|
89
|
+
"args": [
|
|
90
|
+
{ "kind": "literal", "id": "lit-msg-001", "value": "Hello, World!" }
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
{ "kind": "literal", "id": "lit-ret-001", "value": 0 }
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## The Agent Loop
|
|
101
|
+
|
|
102
|
+
The core design: an agent submits an AST → the compiler validates it → if wrong, returns a `StructuredError` with enough context for the agent to self-repair → the agent fixes it → resubmits.
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
// 1. Agent reads the schema to learn the AST format
|
|
106
|
+
const schema = edict_schema();
|
|
107
|
+
|
|
108
|
+
// 2. Agent writes a program (may contain errors)
|
|
109
|
+
const program = agentWritesProgram(schema);
|
|
110
|
+
|
|
111
|
+
// 3. Compile — returns structured errors or WASM
|
|
112
|
+
const result = edict_compile(program);
|
|
113
|
+
|
|
114
|
+
if (!result.ok) {
|
|
115
|
+
// 4. Agent reads errors and fixes the program
|
|
116
|
+
// Errors include: nodeId, expected type, candidates, counterexamples
|
|
117
|
+
const fixed = agentFixesProgram(program, result.errors);
|
|
118
|
+
// 5. Resubmit
|
|
119
|
+
return edict_compile(fixed);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 6. Run the WASM
|
|
123
|
+
const output = edict_run(result.wasm);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Architecture
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
src/
|
|
130
|
+
├── ast/ # TypeScript interfaces for every AST node
|
|
131
|
+
├── validator/ # Schema validation (structural correctness)
|
|
132
|
+
├── resolver/ # Name resolution (scope-aware, with Levenshtein suggestions)
|
|
133
|
+
├── checker/ # Type checking (bidirectional, with unit types)
|
|
134
|
+
├── effects/ # Effect checking (call-graph propagation)
|
|
135
|
+
├── contracts/ # Contract verification (Z3/SMT integration)
|
|
136
|
+
├── codegen/ # WASM code generation (binaryen)
|
|
137
|
+
│ ├── codegen.ts # AST → WASM compilation
|
|
138
|
+
│ ├── runner.ts # WASM execution (Node.js WebAssembly API)
|
|
139
|
+
│ ├── builtins.ts # Built-in functions (print)
|
|
140
|
+
│ └── string-table.ts # String interning for WASM memory
|
|
141
|
+
├── mcp/ # MCP server (tools + resources)
|
|
142
|
+
└── errors/ # Structured error types
|
|
143
|
+
|
|
144
|
+
tests/ # 488 tests across 21 files
|
|
145
|
+
examples/ # 10 example programs as JSON ASTs
|
|
146
|
+
schema/ # Auto-generated JSON Schema
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Type System
|
|
150
|
+
|
|
151
|
+
| Type | Example |
|
|
152
|
+
|---|---|
|
|
153
|
+
| Basic | `Int`, `Float`, `String`, `Bool` |
|
|
154
|
+
| Array | `Array<Int>` |
|
|
155
|
+
| Option | `Option<String>` |
|
|
156
|
+
| Result | `Result<String, String>` |
|
|
157
|
+
| Record | `Point { x: Float, y: Float }` |
|
|
158
|
+
| Enum | `Shape = Circle { radius: Float } \| Rectangle { w: Float, h: Float }` |
|
|
159
|
+
| Refinement | `{ i: Int \| i > 0 }` — predicates verified by Z3 |
|
|
160
|
+
| Function | `(Int, Int) -> Int` |
|
|
161
|
+
|
|
162
|
+
## Effect System
|
|
163
|
+
|
|
164
|
+
Functions declare their effects. The compiler enforces:
|
|
165
|
+
|
|
166
|
+
- A `pure` function cannot call an `io` function
|
|
167
|
+
- Effects propagate through the call graph
|
|
168
|
+
- Missing effects are detected and reported
|
|
169
|
+
|
|
170
|
+
Effects: `pure`, `reads`, `writes`, `io`, `fails`
|
|
171
|
+
|
|
172
|
+
## Contract Verification
|
|
173
|
+
|
|
174
|
+
Pre/post conditions are verified at compile time using Z3:
|
|
175
|
+
|
|
176
|
+
```json
|
|
177
|
+
{
|
|
178
|
+
"kind": "post",
|
|
179
|
+
"id": "post-001",
|
|
180
|
+
"condition": {
|
|
181
|
+
"kind": "binop", "op": ">",
|
|
182
|
+
"left": { "kind": "ident", "name": "result" },
|
|
183
|
+
"right": { "kind": "ident", "name": "x" }
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Z3 either proves `unsat` (contract holds ✅) or returns `sat` with a concrete counterexample the agent can reason about.
|
|
189
|
+
|
|
190
|
+
## Contributing
|
|
191
|
+
|
|
192
|
+
We welcome contributions from agents and humans alike. See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions, coding standards, and the PR workflow.
|
|
193
|
+
|
|
194
|
+
**Looking for a place to start?** Check issues labeled [`good first issue`](https://github.com/Sowiedu/Edict/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22).
|
|
195
|
+
|
|
196
|
+
## Roadmap
|
|
197
|
+
|
|
198
|
+
See [ROADMAP.md](ROADMAP.md) for the full development plan and [FEATURE_SPEC.md](FEATURE_SPEC.md) for the language specification.
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import type { TypeExpr } from "./types.js";
|
|
2
|
+
export type { TypeExpr } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* The 5 canonical effect categories.
|
|
5
|
+
* A function's signature includes which effects it may perform.
|
|
6
|
+
*/
|
|
7
|
+
export type Effect = "pure" | "reads" | "writes" | "io" | "fails";
|
|
8
|
+
export declare const VALID_EFFECTS: readonly Effect[];
|
|
9
|
+
/**
|
|
10
|
+
* A complete Edict program / module.
|
|
11
|
+
*/
|
|
12
|
+
export interface EdictModule {
|
|
13
|
+
kind: "module";
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
imports: Import[];
|
|
17
|
+
definitions: Definition[];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Import names from another module.
|
|
21
|
+
*/
|
|
22
|
+
export interface Import {
|
|
23
|
+
kind: "import";
|
|
24
|
+
id: string;
|
|
25
|
+
module: string;
|
|
26
|
+
names: string[];
|
|
27
|
+
}
|
|
28
|
+
export type Definition = FunctionDef | TypeDef | RecordDef | EnumDef | ConstDef;
|
|
29
|
+
/**
|
|
30
|
+
* Function definition with effects, contracts, and body.
|
|
31
|
+
*/
|
|
32
|
+
export interface FunctionDef {
|
|
33
|
+
kind: "fn";
|
|
34
|
+
id: string;
|
|
35
|
+
name: string;
|
|
36
|
+
params: Param[];
|
|
37
|
+
effects: Effect[];
|
|
38
|
+
returnType: TypeExpr;
|
|
39
|
+
contracts: Contract[];
|
|
40
|
+
body: Expression[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Type alias definition.
|
|
44
|
+
*/
|
|
45
|
+
export interface TypeDef {
|
|
46
|
+
kind: "type";
|
|
47
|
+
id: string;
|
|
48
|
+
name: string;
|
|
49
|
+
definition: TypeExpr;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Record (struct) definition.
|
|
53
|
+
*/
|
|
54
|
+
export interface RecordDef {
|
|
55
|
+
kind: "record";
|
|
56
|
+
id: string;
|
|
57
|
+
name: string;
|
|
58
|
+
fields: RecordField[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A field in a record definition.
|
|
62
|
+
*/
|
|
63
|
+
export interface RecordField {
|
|
64
|
+
kind: "field";
|
|
65
|
+
id: string;
|
|
66
|
+
name: string;
|
|
67
|
+
type: TypeExpr;
|
|
68
|
+
defaultValue?: Expression;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Enum (tagged union / sum type) definition.
|
|
72
|
+
*/
|
|
73
|
+
export interface EnumDef {
|
|
74
|
+
kind: "enum";
|
|
75
|
+
id: string;
|
|
76
|
+
name: string;
|
|
77
|
+
variants: EnumVariant[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* A variant of an enum. Fields are empty for unit variants (e.g., None).
|
|
81
|
+
*/
|
|
82
|
+
export interface EnumVariant {
|
|
83
|
+
kind: "variant";
|
|
84
|
+
id: string;
|
|
85
|
+
name: string;
|
|
86
|
+
fields: RecordField[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Constant definition.
|
|
90
|
+
*/
|
|
91
|
+
export interface ConstDef {
|
|
92
|
+
kind: "const";
|
|
93
|
+
id: string;
|
|
94
|
+
name: string;
|
|
95
|
+
type: TypeExpr;
|
|
96
|
+
value: Expression;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Function parameter.
|
|
100
|
+
*/
|
|
101
|
+
export interface Param {
|
|
102
|
+
kind: "param";
|
|
103
|
+
id: string;
|
|
104
|
+
name: string;
|
|
105
|
+
type: TypeExpr;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Pre/post contract on a function.
|
|
109
|
+
*/
|
|
110
|
+
export interface Contract {
|
|
111
|
+
kind: "pre" | "post";
|
|
112
|
+
id: string;
|
|
113
|
+
condition: Expression;
|
|
114
|
+
}
|
|
115
|
+
export type Expression = Literal | Identifier | BinaryOp | UnaryOp | Call | IfExpr | LetExpr | MatchExpr | ArrayExpr | TupleExpr | RecordExpr | EnumConstructor | FieldAccess | LambdaExpr | BlockExpr;
|
|
116
|
+
export interface Literal {
|
|
117
|
+
kind: "literal";
|
|
118
|
+
id: string;
|
|
119
|
+
value: number | string | boolean;
|
|
120
|
+
type?: TypeExpr;
|
|
121
|
+
}
|
|
122
|
+
export interface Identifier {
|
|
123
|
+
kind: "ident";
|
|
124
|
+
id: string;
|
|
125
|
+
name: string;
|
|
126
|
+
}
|
|
127
|
+
export type BinaryOperator = "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | ">" | "<=" | ">=" | "and" | "or" | "implies";
|
|
128
|
+
export declare const VALID_BINARY_OPS: readonly BinaryOperator[];
|
|
129
|
+
export interface BinaryOp {
|
|
130
|
+
kind: "binop";
|
|
131
|
+
id: string;
|
|
132
|
+
op: BinaryOperator;
|
|
133
|
+
left: Expression;
|
|
134
|
+
right: Expression;
|
|
135
|
+
}
|
|
136
|
+
export type UnaryOperator = "not" | "-";
|
|
137
|
+
export declare const VALID_UNARY_OPS: readonly UnaryOperator[];
|
|
138
|
+
export interface UnaryOp {
|
|
139
|
+
kind: "unop";
|
|
140
|
+
id: string;
|
|
141
|
+
op: UnaryOperator;
|
|
142
|
+
operand: Expression;
|
|
143
|
+
}
|
|
144
|
+
export interface Call {
|
|
145
|
+
kind: "call";
|
|
146
|
+
id: string;
|
|
147
|
+
fn: Expression;
|
|
148
|
+
args: Expression[];
|
|
149
|
+
}
|
|
150
|
+
export interface IfExpr {
|
|
151
|
+
kind: "if";
|
|
152
|
+
id: string;
|
|
153
|
+
condition: Expression;
|
|
154
|
+
then: Expression[];
|
|
155
|
+
else?: Expression[];
|
|
156
|
+
}
|
|
157
|
+
export interface LetExpr {
|
|
158
|
+
kind: "let";
|
|
159
|
+
id: string;
|
|
160
|
+
name: string;
|
|
161
|
+
type?: TypeExpr;
|
|
162
|
+
value: Expression;
|
|
163
|
+
}
|
|
164
|
+
export interface MatchExpr {
|
|
165
|
+
kind: "match";
|
|
166
|
+
id: string;
|
|
167
|
+
target: Expression;
|
|
168
|
+
arms: MatchArm[];
|
|
169
|
+
}
|
|
170
|
+
export interface MatchArm {
|
|
171
|
+
kind: "arm";
|
|
172
|
+
id: string;
|
|
173
|
+
pattern: Pattern;
|
|
174
|
+
body: Expression[];
|
|
175
|
+
}
|
|
176
|
+
export type Pattern = LiteralPattern | WildcardPattern | BindingPattern | ConstructorPattern;
|
|
177
|
+
export interface LiteralPattern {
|
|
178
|
+
kind: "literal_pattern";
|
|
179
|
+
value: number | string | boolean;
|
|
180
|
+
}
|
|
181
|
+
export interface WildcardPattern {
|
|
182
|
+
kind: "wildcard";
|
|
183
|
+
}
|
|
184
|
+
export interface BindingPattern {
|
|
185
|
+
kind: "binding";
|
|
186
|
+
name: string;
|
|
187
|
+
}
|
|
188
|
+
export interface ConstructorPattern {
|
|
189
|
+
kind: "constructor";
|
|
190
|
+
name: string;
|
|
191
|
+
fields: Pattern[];
|
|
192
|
+
}
|
|
193
|
+
export interface ArrayExpr {
|
|
194
|
+
kind: "array";
|
|
195
|
+
id: string;
|
|
196
|
+
elements: Expression[];
|
|
197
|
+
}
|
|
198
|
+
export interface TupleExpr {
|
|
199
|
+
kind: "tuple_expr";
|
|
200
|
+
id: string;
|
|
201
|
+
elements: Expression[];
|
|
202
|
+
}
|
|
203
|
+
export interface RecordExpr {
|
|
204
|
+
kind: "record_expr";
|
|
205
|
+
id: string;
|
|
206
|
+
name: string;
|
|
207
|
+
fields: FieldInit[];
|
|
208
|
+
}
|
|
209
|
+
export interface EnumConstructor {
|
|
210
|
+
kind: "enum_constructor";
|
|
211
|
+
id: string;
|
|
212
|
+
enumName: string;
|
|
213
|
+
variant: string;
|
|
214
|
+
fields: FieldInit[];
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Field initialization in record expressions and enum constructors.
|
|
218
|
+
* Gives these inline objects a proper `kind` discriminator like every other AST node.
|
|
219
|
+
*/
|
|
220
|
+
export interface FieldInit {
|
|
221
|
+
kind: "field_init";
|
|
222
|
+
name: string;
|
|
223
|
+
value: Expression;
|
|
224
|
+
}
|
|
225
|
+
export interface FieldAccess {
|
|
226
|
+
kind: "access";
|
|
227
|
+
id: string;
|
|
228
|
+
target: Expression;
|
|
229
|
+
field: string;
|
|
230
|
+
}
|
|
231
|
+
export interface LambdaExpr {
|
|
232
|
+
kind: "lambda";
|
|
233
|
+
id: string;
|
|
234
|
+
params: Param[];
|
|
235
|
+
body: Expression[];
|
|
236
|
+
}
|
|
237
|
+
export interface BlockExpr {
|
|
238
|
+
kind: "block";
|
|
239
|
+
id: string;
|
|
240
|
+
body: Expression[];
|
|
241
|
+
}
|
|
242
|
+
export declare const VALID_DEFINITION_KINDS: readonly ["fn", "type", "record", "enum", "const"];
|
|
243
|
+
export declare const VALID_EXPRESSION_KINDS: readonly ["literal", "ident", "binop", "unop", "call", "if", "let", "match", "array", "tuple_expr", "record_expr", "enum_constructor", "access", "lambda", "block"];
|
|
244
|
+
export declare const VALID_TYPE_KINDS: readonly ["basic", "array", "option", "result", "unit_type", "refined", "fn_type", "named", "tuple"];
|
|
245
|
+
export declare const VALID_PATTERN_KINDS: readonly ["literal_pattern", "wildcard", "binding", "constructor"];
|
|
246
|
+
export declare const VALID_BASIC_TYPE_NAMES: readonly ["Int", "Float", "String", "Bool"];
|
|
247
|
+
export declare const ALL_VALID_KINDS: readonly ["module", "import", "fn", "type", "record", "enum", "const", "param", "field", "variant", "pre", "post", "arm", "field_init", "literal", "ident", "binop", "unop", "call", "if", "let", "match", "array", "tuple_expr", "record_expr", "enum_constructor", "access", "lambda", "block", "basic", "array", "option", "result", "unit_type", "refined", "fn_type", "named", "tuple", "literal_pattern", "wildcard", "binding", "constructor"];
|
|
248
|
+
//# sourceMappingURL=nodes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/ast/nodes.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAG3C,YAAY,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAM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,0 +1,95 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Edict AST Node Definitions
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Every valid Edict program is a tree of these nodes, serialized as JSON.
|
|
5
|
+
// No lexer, no parser — agents produce these directly.
|
|
6
|
+
export const VALID_EFFECTS = [
|
|
7
|
+
"pure",
|
|
8
|
+
"reads",
|
|
9
|
+
"writes",
|
|
10
|
+
"io",
|
|
11
|
+
"fails",
|
|
12
|
+
];
|
|
13
|
+
export const VALID_BINARY_OPS = [
|
|
14
|
+
"+",
|
|
15
|
+
"-",
|
|
16
|
+
"*",
|
|
17
|
+
"/",
|
|
18
|
+
"%",
|
|
19
|
+
"==",
|
|
20
|
+
"!=",
|
|
21
|
+
"<",
|
|
22
|
+
">",
|
|
23
|
+
"<=",
|
|
24
|
+
">=",
|
|
25
|
+
"and",
|
|
26
|
+
"or",
|
|
27
|
+
"implies",
|
|
28
|
+
];
|
|
29
|
+
export const VALID_UNARY_OPS = ["not", "-"];
|
|
30
|
+
// =============================================================================
|
|
31
|
+
// Valid kind values — used by the validator
|
|
32
|
+
// =============================================================================
|
|
33
|
+
export const VALID_DEFINITION_KINDS = [
|
|
34
|
+
"fn",
|
|
35
|
+
"type",
|
|
36
|
+
"record",
|
|
37
|
+
"enum",
|
|
38
|
+
"const",
|
|
39
|
+
];
|
|
40
|
+
export const VALID_EXPRESSION_KINDS = [
|
|
41
|
+
"literal",
|
|
42
|
+
"ident",
|
|
43
|
+
"binop",
|
|
44
|
+
"unop",
|
|
45
|
+
"call",
|
|
46
|
+
"if",
|
|
47
|
+
"let",
|
|
48
|
+
"match",
|
|
49
|
+
"array",
|
|
50
|
+
"tuple_expr",
|
|
51
|
+
"record_expr",
|
|
52
|
+
"enum_constructor",
|
|
53
|
+
"access",
|
|
54
|
+
"lambda",
|
|
55
|
+
"block",
|
|
56
|
+
];
|
|
57
|
+
export const VALID_TYPE_KINDS = [
|
|
58
|
+
"basic",
|
|
59
|
+
"array",
|
|
60
|
+
"option",
|
|
61
|
+
"result",
|
|
62
|
+
"unit_type",
|
|
63
|
+
"refined",
|
|
64
|
+
"fn_type",
|
|
65
|
+
"named",
|
|
66
|
+
"tuple",
|
|
67
|
+
];
|
|
68
|
+
export const VALID_PATTERN_KINDS = [
|
|
69
|
+
"literal_pattern",
|
|
70
|
+
"wildcard",
|
|
71
|
+
"binding",
|
|
72
|
+
"constructor",
|
|
73
|
+
];
|
|
74
|
+
export const VALID_BASIC_TYPE_NAMES = [
|
|
75
|
+
"Int",
|
|
76
|
+
"Float",
|
|
77
|
+
"String",
|
|
78
|
+
"Bool",
|
|
79
|
+
];
|
|
80
|
+
export const ALL_VALID_KINDS = [
|
|
81
|
+
"module",
|
|
82
|
+
"import",
|
|
83
|
+
...VALID_DEFINITION_KINDS,
|
|
84
|
+
"param",
|
|
85
|
+
"field",
|
|
86
|
+
"variant",
|
|
87
|
+
"pre",
|
|
88
|
+
"post",
|
|
89
|
+
"arm",
|
|
90
|
+
"field_init",
|
|
91
|
+
...VALID_EXPRESSION_KINDS,
|
|
92
|
+
...VALID_TYPE_KINDS,
|
|
93
|
+
...VALID_PATTERN_KINDS,
|
|
94
|
+
];
|
|
95
|
+
//# sourceMappingURL=nodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/ast/nodes.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAChF,0EAA0E;AAC1E,uDAAuD;AAiBvD,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC5C,MAAM;IACN,OAAO;IACP,QAAQ;IACR,IAAI;IACJ,OAAO;CACD,CAAC;AA2LX,MAAM,CAAC,MAAM,gBAAgB,GAA8B;IACvD,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,GAAG;IACH,GAAG;IACH,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,IAAI;IACJ,SAAS;CACH,CAAC;AAYX,MAAM,CAAC,MAAM,eAAe,GAA6B,CAAC,KAAK,EAAE,GAAG,CAAU,CAAC;AAiI/E,gFAAgF;AAChF,4CAA4C;AAC5C,gFAAgF;AAEhF,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,IAAI;IACJ,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;CACD,CAAC;AAEX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,IAAI;IACJ,KAAK;IACL,OAAO;IACP,OAAO;IACP,YAAY;IACZ,aAAa;IACb,kBAAkB;IAClB,QAAQ;IACR,QAAQ;IACR,OAAO;CACD,CAAC;AAEX,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC5B,OAAO;IACP,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,WAAW;IACX,SAAS;IACT,SAAS;IACT,OAAO;IACP,OAAO;CACD,CAAC;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG;IAC/B,iBAAiB;IACjB,UAAU;IACV,SAAS;IACT,aAAa;CACP,CAAC;AAEX,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,KAAK;IACL,OAAO;IACP,QAAQ;IACR,MAAM;CACA,CAAC;AAEX,MAAM,CAAC,MAAM,eAAe,GAAG;IAC3B,QAAQ;IACR,QAAQ;IACR,GAAG,sBAAsB;IACzB,OAAO;IACP,OAAO;IACP,SAAS;IACT,KAAK;IACL,MAAM;IACN,KAAK;IACL,YAAY;IACZ,GAAG,sBAAsB;IACzB,GAAG,gBAAgB;IACnB,GAAG,mBAAmB;CAChB,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Union of all type expressions in Edict.
|
|
3
|
+
*/
|
|
4
|
+
export type TypeExpr = BasicType | ArrayType | OptionType | ResultType | UnitType | RefinedType | FunctionType | NamedType | TupleType;
|
|
5
|
+
/**
|
|
6
|
+
* Primitive types.
|
|
7
|
+
*/
|
|
8
|
+
export interface BasicType {
|
|
9
|
+
kind: "basic";
|
|
10
|
+
name: "Int" | "Float" | "String" | "Bool";
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Homogeneous array type.
|
|
14
|
+
*/
|
|
15
|
+
export interface ArrayType {
|
|
16
|
+
kind: "array";
|
|
17
|
+
element: TypeExpr;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Optional value — None or Some(T).
|
|
21
|
+
*/
|
|
22
|
+
export interface OptionType {
|
|
23
|
+
kind: "option";
|
|
24
|
+
inner: TypeExpr;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Result type for error handling. Interacts with the "fails" effect.
|
|
28
|
+
*/
|
|
29
|
+
export interface ResultType {
|
|
30
|
+
kind: "result";
|
|
31
|
+
ok: TypeExpr;
|
|
32
|
+
err: TypeExpr;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Semantic unit type — compile-time enforcement, zero runtime cost.
|
|
36
|
+
* Prevents mixing incompatible units (e.g., currency<usd> + temp<celsius>).
|
|
37
|
+
*/
|
|
38
|
+
export interface UnitType {
|
|
39
|
+
kind: "unit_type";
|
|
40
|
+
base: "Int" | "Float";
|
|
41
|
+
unit: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Refinement type — base type + logical predicate verified by Z3 (Phase 4).
|
|
45
|
+
* Example: { v: Int | v > 0 } is a positive integer.
|
|
46
|
+
*/
|
|
47
|
+
export interface RefinedType {
|
|
48
|
+
kind: "refined";
|
|
49
|
+
id: string;
|
|
50
|
+
base: TypeExpr;
|
|
51
|
+
variable: string;
|
|
52
|
+
predicate: Expression;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Function type — for higher-order functions and lambdas.
|
|
56
|
+
*/
|
|
57
|
+
export interface FunctionType {
|
|
58
|
+
kind: "fn_type";
|
|
59
|
+
params: TypeExpr[];
|
|
60
|
+
effects: Effect[];
|
|
61
|
+
returnType: TypeExpr;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Reference to a user-defined type (RecordDef or EnumDef) by name.
|
|
65
|
+
*/
|
|
66
|
+
export interface NamedType {
|
|
67
|
+
kind: "named";
|
|
68
|
+
name: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fixed-size heterogeneous tuple.
|
|
72
|
+
*/
|
|
73
|
+
export interface TupleType {
|
|
74
|
+
kind: "tuple";
|
|
75
|
+
elements: TypeExpr[];
|
|
76
|
+
}
|
|
77
|
+
import type { Expression, Effect } from "./nodes.js";
|
|
78
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/ast/types.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,MAAM,QAAQ,GACd,SAAS,GACT,SAAS,GACT,UAAU,GACV,UAAU,GACV,QAAQ,GACR,WAAW,GACX,YAAY,GACZ,SAAS,GACT,SAAS,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC7C;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,QAAQ,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,QAAQ,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,QAAQ,CAAC;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,UAAU,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,QAAQ,EAAE,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACxB;AAID,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Edict AST Type Expressions
|
|
3
|
+
// =============================================================================
|
|
4
|
+
// Every possible type in the Edict type system.
|
|
5
|
+
// Types are compile-time only — unit types are erased after type checking.
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/ast/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAChF,gDAAgD;AAChD,2EAA2E"}
|