@hyperscale0/hsx 1.0.0-alpha.1
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/AUTHORS +8 -0
- package/CHANGELOG.md +59 -0
- package/LICENSE +661 -0
- package/LICENSING.md +52 -0
- package/README.md +170 -0
- package/SECURITY.md +47 -0
- package/TRADEMARKS.md +35 -0
- package/bin/hsx.ts +15 -0
- package/dist/bin/hsx.d.ts +7 -0
- package/dist/bin/hsx.d.ts.map +1 -0
- package/dist/bin/hsx.js +14 -0
- package/dist/bin/hsx.js.map +1 -0
- package/dist/src/ast.d.ts +172 -0
- package/dist/src/ast.d.ts.map +1 -0
- package/dist/src/ast.js +22 -0
- package/dist/src/ast.js.map +1 -0
- package/dist/src/check.d.ts +11 -0
- package/dist/src/check.d.ts.map +1 -0
- package/dist/src/check.js +1214 -0
- package/dist/src/check.js.map +1 -0
- package/dist/src/cli.d.ts +20 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +137 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/compile.d.ts +39 -0
- package/dist/src/compile.d.ts.map +1 -0
- package/dist/src/compile.js +59 -0
- package/dist/src/compile.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lex.d.ts +23 -0
- package/dist/src/lex.d.ts.map +1 -0
- package/dist/src/lex.js +125 -0
- package/dist/src/lex.js.map +1 -0
- package/dist/src/lower.d.ts +93 -0
- package/dist/src/lower.d.ts.map +1 -0
- package/dist/src/lower.js +2081 -0
- package/dist/src/lower.js.map +1 -0
- package/dist/src/model.d.ts +307 -0
- package/dist/src/model.d.ts.map +1 -0
- package/dist/src/model.js +15 -0
- package/dist/src/model.js.map +1 -0
- package/dist/src/parse.d.ts +19 -0
- package/dist/src/parse.d.ts.map +1 -0
- package/dist/src/parse.js +484 -0
- package/dist/src/parse.js.map +1 -0
- package/dist/src/version.d.ts +16 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +16 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +79 -0
- package/spec/hsx-ir.schema.json +522 -0
- package/src/ast.ts +231 -0
- package/src/check.ts +1699 -0
- package/src/cli.ts +173 -0
- package/src/compile.ts +98 -0
- package/src/index.ts +16 -0
- package/src/lex.ts +161 -0
- package/src/lower.ts +2619 -0
- package/src/model.ts +340 -0
- package/src/parse.ts +580 -0
- package/src/version.ts +17 -0
package/src/ast.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The HSX abstract syntax tree.
|
|
3
|
+
*
|
|
4
|
+
* Every node carries a byte-offset span into the original source. Spans are
|
|
5
|
+
* the compiler's source-mapping currency: diagnostics at every later stage
|
|
6
|
+
* (typecheck, lowering, verdicts) point at source coordinates, never at
|
|
7
|
+
* lowered IR paths. Offsets convert to line/column via `lineColAt`.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface Span {
|
|
11
|
+
/** Inclusive start byte offset into the source text. */
|
|
12
|
+
readonly start: number;
|
|
13
|
+
/** Exclusive end byte offset into the source text. */
|
|
14
|
+
readonly end: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LineCol {
|
|
18
|
+
/** 1-indexed line. */
|
|
19
|
+
readonly line: number;
|
|
20
|
+
/** 1-indexed column, counted in UTF-16 code units. */
|
|
21
|
+
readonly column: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Convert a byte offset to a 1-indexed line/column position. */
|
|
25
|
+
export function lineColAt(source: string, offset: number): LineCol {
|
|
26
|
+
let line = 1;
|
|
27
|
+
let lineStart = 0;
|
|
28
|
+
const clamped = Math.max(0, Math.min(offset, source.length));
|
|
29
|
+
for (let index = 0; index < clamped; index += 1) {
|
|
30
|
+
if (source.charCodeAt(index) === 10) {
|
|
31
|
+
line += 1;
|
|
32
|
+
lineStart = index + 1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return { column: clamped - lineStart + 1, line };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// --- Expressions -----------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
export interface IdentExpr {
|
|
41
|
+
readonly kind: "ident";
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly span: Span;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface StringExpr {
|
|
47
|
+
readonly kind: "string";
|
|
48
|
+
readonly span: Span;
|
|
49
|
+
readonly value: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface NumberExpr {
|
|
53
|
+
readonly kind: "number";
|
|
54
|
+
/** The literal exactly as written, e.g. "99.5". Interpretation is typed later. */
|
|
55
|
+
readonly raw: string;
|
|
56
|
+
readonly span: Span;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface PercentExpr {
|
|
60
|
+
/** Exact basis points: 99.5% is 9950. Percents never round. */
|
|
61
|
+
readonly bps: number;
|
|
62
|
+
readonly kind: "percent";
|
|
63
|
+
readonly raw: string;
|
|
64
|
+
readonly span: Span;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A type or constructor application: `money(SAR)`, `id(vehicle)`. */
|
|
68
|
+
export interface CallExpr {
|
|
69
|
+
readonly args: readonly Expr[];
|
|
70
|
+
readonly callee: IdentExpr;
|
|
71
|
+
readonly kind: "call";
|
|
72
|
+
readonly span: Span;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A reference to a decision port, optionally bounded (`port dispute within
|
|
77
|
+
* P14D`) or carrying the date that decides when the port has not
|
|
78
|
+
* (`port approve_release | at(releaseDueAt)`).
|
|
79
|
+
*/
|
|
80
|
+
export interface PortRefExpr {
|
|
81
|
+
/** `| at(<field>)`, the stored date field that resolves an undecided hold. */
|
|
82
|
+
readonly deadline?: IdentExpr;
|
|
83
|
+
readonly kind: "port_ref";
|
|
84
|
+
readonly name: IdentExpr;
|
|
85
|
+
readonly span: Span;
|
|
86
|
+
readonly within?: IdentExpr;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* `retention.release`, one settlement naming another settlement's exit. The
|
|
91
|
+
* only cross-settlement reference the language has: it is resolved wholly at
|
|
92
|
+
* check time, never by a caller at runtime.
|
|
93
|
+
*/
|
|
94
|
+
export interface SettlementRefExpr {
|
|
95
|
+
readonly kind: "settlement_ref";
|
|
96
|
+
/** The exit named on the owner, e.g. `release`. */
|
|
97
|
+
readonly member: IdentExpr;
|
|
98
|
+
/** The settlement being referenced. */
|
|
99
|
+
readonly owner: IdentExpr;
|
|
100
|
+
readonly span: Span;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export interface ListExpr {
|
|
104
|
+
readonly items: readonly Expr[];
|
|
105
|
+
readonly kind: "list";
|
|
106
|
+
readonly span: Span;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A brace block of entries: `{ buyer: 1%, seller: 2% }`. */
|
|
110
|
+
export interface BlockExpr {
|
|
111
|
+
readonly entries: readonly Entry[];
|
|
112
|
+
readonly kind: "block";
|
|
113
|
+
readonly span: Span;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* A named typed binding inside an expression position:
|
|
118
|
+
* `amount: price: money(SAR)` binds the field name `price` to type
|
|
119
|
+
* `money(SAR)`: the entry key is `amount`, the value is this binding.
|
|
120
|
+
*/
|
|
121
|
+
interface BindingExpr {
|
|
122
|
+
readonly kind: "binding";
|
|
123
|
+
readonly name: IdentExpr;
|
|
124
|
+
readonly span: Span;
|
|
125
|
+
readonly type: Expr;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type Expr =
|
|
129
|
+
| BindingExpr
|
|
130
|
+
| BlockExpr
|
|
131
|
+
| CallExpr
|
|
132
|
+
| IdentExpr
|
|
133
|
+
| ListExpr
|
|
134
|
+
| NumberExpr
|
|
135
|
+
| PercentExpr
|
|
136
|
+
| PortRefExpr
|
|
137
|
+
| SettlementRefExpr
|
|
138
|
+
| StringExpr;
|
|
139
|
+
|
|
140
|
+
// --- Entries ---------------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* One keyed entry inside a declaration body. Three surface shapes normalize
|
|
144
|
+
* here: `payer: buyer` (key + value), `fees { ... }` (key + block value),
|
|
145
|
+
* and `on_cancel(funded) { ... }` (key + qualifiers + block value).
|
|
146
|
+
*/
|
|
147
|
+
export interface Entry {
|
|
148
|
+
readonly key: IdentExpr;
|
|
149
|
+
readonly qualifiers: readonly IdentExpr[];
|
|
150
|
+
readonly span: Span;
|
|
151
|
+
readonly value: Expr;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// --- Declarations ----------------------------------------------------------
|
|
155
|
+
|
|
156
|
+
/** `program used_car_escrow "Used-car escrow"` names the company program. */
|
|
157
|
+
export interface ProgramDecl {
|
|
158
|
+
readonly kind: "program";
|
|
159
|
+
readonly name: IdentExpr;
|
|
160
|
+
readonly span: Span;
|
|
161
|
+
readonly title?: StringExpr;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** `import { held_payment } from "settlement"`. */
|
|
165
|
+
export interface ImportDecl {
|
|
166
|
+
readonly from: StringExpr;
|
|
167
|
+
readonly kind: "import";
|
|
168
|
+
readonly names: readonly IdentExpr[];
|
|
169
|
+
readonly span: Span;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** `party buyer: person` with an optional attribute block. */
|
|
173
|
+
export interface PartyDecl {
|
|
174
|
+
readonly attrs?: BlockExpr;
|
|
175
|
+
readonly kind: "party";
|
|
176
|
+
readonly name: IdentExpr;
|
|
177
|
+
readonly partyKind: IdentExpr;
|
|
178
|
+
readonly span: Span;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** `asset vehicle: good { title_transfer: off_platform }`. */
|
|
182
|
+
export interface AssetDecl {
|
|
183
|
+
readonly assetKind: IdentExpr;
|
|
184
|
+
readonly attrs?: BlockExpr;
|
|
185
|
+
readonly kind: "asset";
|
|
186
|
+
readonly name: IdentExpr;
|
|
187
|
+
readonly span: Span;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/** `settlement sale = held_payment { ... }`, an archetype instantiation. */
|
|
191
|
+
export interface SettlementDecl {
|
|
192
|
+
readonly archetype: IdentExpr;
|
|
193
|
+
readonly body: BlockExpr;
|
|
194
|
+
readonly kind: "settlement";
|
|
195
|
+
readonly name: IdentExpr;
|
|
196
|
+
readonly span: Span;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** `port confirm_handover { allowed: [buyer], ... }`. */
|
|
200
|
+
export interface PortDecl {
|
|
201
|
+
readonly body: BlockExpr;
|
|
202
|
+
readonly kind: "port";
|
|
203
|
+
readonly name: IdentExpr;
|
|
204
|
+
readonly span: Span;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type Decl =
|
|
208
|
+
| AssetDecl
|
|
209
|
+
| ImportDecl
|
|
210
|
+
| PartyDecl
|
|
211
|
+
| PortDecl
|
|
212
|
+
| ProgramDecl
|
|
213
|
+
| SettlementDecl;
|
|
214
|
+
|
|
215
|
+
// --- Program ---------------------------------------------------------------
|
|
216
|
+
|
|
217
|
+
export interface Program {
|
|
218
|
+
readonly decls: readonly Decl[];
|
|
219
|
+
readonly span: Span;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// --- Diagnostics -----------------------------------------------------------
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* A parse-stage problem, worded for the program's author. Parsing is total:
|
|
226
|
+
* it never throws, it returns the best-effort tree plus these.
|
|
227
|
+
*/
|
|
228
|
+
export interface Diagnostic {
|
|
229
|
+
readonly message: string;
|
|
230
|
+
readonly span: Span;
|
|
231
|
+
}
|