@scriptc/compiler 0.0.25 → 0.0.27
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/ambient/scriptc-node-fallback.d.ts +15 -7
- package/dist/backend/cc.d.ts +22 -0
- package/dist/backend/cc.js +128 -10
- package/dist/backend/cc.js.map +1 -1
- package/dist/backend/emission/emit-exprs.js +81 -10
- package/dist/backend/emission/emit-exprs.js.map +1 -1
- package/dist/backend/emission/emitter.d.ts +14 -1
- package/dist/backend/emission/emitter.js +126 -13
- package/dist/backend/emission/emitter.js.map +1 -1
- package/dist/backend/emission/may-throw.js +11 -1
- package/dist/backend/emission/may-throw.js.map +1 -1
- package/dist/backend/ffi-callbacks.d.ts +11 -0
- package/dist/backend/ffi-callbacks.js +33 -0
- package/dist/backend/ffi-callbacks.js.map +1 -0
- package/dist/backend/llvm/classes.js +21 -21
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/dyn.d.ts +7 -4
- package/dist/backend/llvm/dyn.js +145 -141
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +7 -1
- package/dist/backend/llvm/emitter.js +961 -303
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/shapes.d.ts +4 -0
- package/dist/backend/llvm/shapes.js +26 -24
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/unsupported.js +1 -1
- package/dist/backend/llvm/unsupported.js.map +1 -1
- package/dist/backend/llvm/walkers.d.ts +2 -0
- package/dist/backend/llvm/walkers.js +50 -46
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/coverage/surface-manifest.js +1 -1
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +1 -1
- package/dist/diagnostics/diagnostic.js +3 -2
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/ffi/profile.d.ts +20 -2
- package/dist/ffi/profile.js +130 -6
- package/dist/ffi/profile.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +58 -22
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +17 -7
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +5 -0
- package/dist/frontend/lowering/lower-server.js +129 -37
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.js +8 -1
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/surfaces.d.ts +3 -2
- package/dist/frontend/lowering/surfaces.js +4 -3
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm.d.ts +16 -0
- package/dist/frontend/npm.js +257 -0
- package/dist/frontend/npm.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.js +188 -5
- package/dist/index.js.map +1 -1
- package/dist/ir/nodes.d.ts +54 -13
- package/dist/ir/nodes.js +49 -7
- package/dist/ir/nodes.js.map +1 -1
- package/dist/ir/validate.js +10 -22
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/profile.d.ts +11 -0
- package/dist/library/profile.js +74 -2
- package/dist/library/profile.js.map +1 -1
- package/dist/wasi-paths.d.ts +5 -0
- package/dist/wasi-paths.js +22 -0
- package/dist/wasi-paths.js.map +1 -0
- package/package.json +2 -2
- package/surface-manifest.json +2 -2
package/dist/backend/llvm/dyn.js
CHANGED
|
@@ -33,9 +33,6 @@ function f64Lit(n) {
|
|
|
33
33
|
return `0x${[...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, "0")).join("").toUpperCase()}`;
|
|
34
34
|
}
|
|
35
35
|
const FN_ATTRS = "#0";
|
|
36
|
-
/** i64 spelling of (SIZE_MAX - 9) / 10 — the canonical-index overflow
|
|
37
|
-
* guard the C helpers compare against. */
|
|
38
|
-
const IDX_MAX_DIV10 = "1844674407370955160";
|
|
39
36
|
export class LlDyn {
|
|
40
37
|
host;
|
|
41
38
|
dynMatchers = new Map();
|
|
@@ -52,16 +49,23 @@ export class LlDyn {
|
|
|
52
49
|
constructor(host) {
|
|
53
50
|
this.host = host;
|
|
54
51
|
}
|
|
52
|
+
get S() { return this.host.sizeType; }
|
|
53
|
+
abiOffset(native64, wasm32) {
|
|
54
|
+
return this.S === "i32" ? wasm32 : native64;
|
|
55
|
+
}
|
|
56
|
+
get indexMaxDiv10() {
|
|
57
|
+
return this.S === "i32" ? "429496728" : "1844674407370955160";
|
|
58
|
+
}
|
|
55
59
|
/** The value LLVM type of a dynCheck result / toDyn operand for `t`. */
|
|
56
60
|
valTy(t) {
|
|
57
61
|
return t.kind === "f64" ? "double" : t.kind === "bool" ? "i1" : "ptr";
|
|
58
62
|
}
|
|
59
63
|
/* ── dyn node plumbing ─────────────────────────────────────────────── */
|
|
60
|
-
/** Loads a dyn node's kind tag (
|
|
64
|
+
/** Loads a dyn node's kind tag (after the size_t rc word). */
|
|
61
65
|
kindOf(B, d) {
|
|
62
66
|
const p = B.tmp();
|
|
63
67
|
const k = B.tmp();
|
|
64
|
-
B.line(`${p} = getelementptr inbounds i8, ptr ${d}, i64 8 ; ->kind`);
|
|
68
|
+
B.line(`${p} = getelementptr inbounds i8, ptr ${d}, i64 ${this.abiOffset(8, 4)} ; ->kind`);
|
|
65
69
|
B.line(`${k} = load i32, ptr ${p}`);
|
|
66
70
|
return k;
|
|
67
71
|
}
|
|
@@ -83,19 +87,19 @@ export class LlDyn {
|
|
|
83
87
|
B.line(`${b} = trunc i8 ${raw} to i1`);
|
|
84
88
|
return b;
|
|
85
89
|
}
|
|
86
|
-
/** Loads v.arr/v.obj length (
|
|
90
|
+
/** Loads v.arr/v.obj length (size_t at +16). */
|
|
87
91
|
lenOf(B, d) {
|
|
88
92
|
const p = B.tmp();
|
|
89
93
|
const n = B.tmp();
|
|
90
94
|
B.line(`${p} = getelementptr inbounds i8, ptr ${d}, i64 16 ; ->v.arr.len`);
|
|
91
|
-
B.line(`${n} = load
|
|
95
|
+
B.line(`${n} = load ${this.S}, ptr ${p}`);
|
|
92
96
|
return n;
|
|
93
97
|
}
|
|
94
|
-
/** Loads v.arr.items / v.obj.entries
|
|
98
|
+
/** Loads v.arr.items / v.obj.entries after two size_t fields. */
|
|
95
99
|
itemsOf(B, d) {
|
|
96
100
|
const p = B.tmp();
|
|
97
101
|
const it = B.tmp();
|
|
98
|
-
B.line(`${p} = getelementptr inbounds i8, ptr ${d}, i64 32 ; ->v.arr.items`);
|
|
102
|
+
B.line(`${p} = getelementptr inbounds i8, ptr ${d}, i64 ${this.abiOffset(32, 24)} ; ->v.arr.items`);
|
|
99
103
|
B.line(`${it} = load ptr, ptr ${p}`);
|
|
100
104
|
return it;
|
|
101
105
|
}
|
|
@@ -103,7 +107,7 @@ export class LlDyn {
|
|
|
103
107
|
itemAt(B, items, i) {
|
|
104
108
|
const p = B.tmp();
|
|
105
109
|
const e = B.tmp();
|
|
106
|
-
B.line(`${p} = getelementptr inbounds ptr, ptr ${items},
|
|
110
|
+
B.line(`${p} = getelementptr inbounds ptr, ptr ${items}, ${this.S} ${i}`);
|
|
107
111
|
B.line(`${e} = load ptr, ptr ${p}`);
|
|
108
112
|
return e;
|
|
109
113
|
}
|
|
@@ -112,17 +116,17 @@ export class LlDyn {
|
|
|
112
116
|
entryAt(B, entries, i) {
|
|
113
117
|
const off = B.tmp();
|
|
114
118
|
const base = B.tmp();
|
|
115
|
-
B.line(`${off} = mul
|
|
116
|
-
B.line(`${base} = getelementptr inbounds i8, ptr ${entries},
|
|
119
|
+
B.line(`${off} = mul ${this.S} ${i}, ${this.abiOffset(24, 12)} ; sizeof(ScrDynEntry)`);
|
|
120
|
+
B.line(`${base} = getelementptr inbounds i8, ptr ${entries}, ${this.S} ${off}`);
|
|
117
121
|
const key = B.tmp();
|
|
118
122
|
B.line(`${key} = load ptr, ptr ${base}`);
|
|
119
123
|
const klp = B.tmp();
|
|
120
124
|
const keyLen = B.tmp();
|
|
121
|
-
B.line(`${klp} = getelementptr inbounds i8, ptr ${base}, i64 8`);
|
|
122
|
-
B.line(`${keyLen} = load
|
|
125
|
+
B.line(`${klp} = getelementptr inbounds i8, ptr ${base}, i64 ${this.abiOffset(8, 4)}`);
|
|
126
|
+
B.line(`${keyLen} = load ${this.S}, ptr ${klp}`);
|
|
123
127
|
const vp = B.tmp();
|
|
124
128
|
const value = B.tmp();
|
|
125
|
-
B.line(`${vp} = getelementptr inbounds i8, ptr ${base}, i64 16`);
|
|
129
|
+
B.line(`${vp} = getelementptr inbounds i8, ptr ${base}, i64 ${this.abiOffset(16, 8)}`);
|
|
126
130
|
B.line(`${value} = load ptr, ptr ${vp}`);
|
|
127
131
|
return { key, keyLen, value };
|
|
128
132
|
}
|
|
@@ -133,8 +137,8 @@ export class LlDyn {
|
|
|
133
137
|
const len = B.tmp();
|
|
134
138
|
const data = B.tmp();
|
|
135
139
|
B.line(`${lp} = getelementptr inbounds %ScrStr, ptr ${s}, i64 0, i32 1`);
|
|
136
|
-
B.line(`${len} = load
|
|
137
|
-
B.line(`${data} = getelementptr inbounds i8, ptr ${s}, i64 24 ; ->data`);
|
|
140
|
+
B.line(`${len} = load ${this.S}, ptr ${lp}`);
|
|
141
|
+
B.line(`${data} = getelementptr inbounds i8, ptr ${s}, i64 ${this.abiOffset(24, 12)} ; ->data`);
|
|
138
142
|
return { len, data };
|
|
139
143
|
}
|
|
140
144
|
/** `call ptr @scr_dyn_retain_v(x)` (+1; immortals skip). */
|
|
@@ -153,10 +157,10 @@ export class LlDyn {
|
|
|
153
157
|
}
|
|
154
158
|
/** scr_dyn_obj_get with a compile-time key: borrowed member or null. */
|
|
155
159
|
objGetLit(B, d, key) {
|
|
156
|
-
this.host.declare(`declare ptr @scr_dyn_obj_get(ptr, ptr,
|
|
160
|
+
this.host.declare(`declare ptr @scr_dyn_obj_get(ptr, ptr, ${this.S})`);
|
|
157
161
|
const t = B.tmp();
|
|
158
162
|
const len = Buffer.byteLength(key, "utf8");
|
|
159
|
-
B.line(`${t} = call ptr @scr_dyn_obj_get(ptr ${d}, ptr ${this.host.cstr(key)},
|
|
163
|
+
B.line(`${t} = call ptr @scr_dyn_obj_get(ptr ${d}, ptr ${this.host.cstr(key)}, ${this.S} ${len}) ; .${key}`);
|
|
160
164
|
return t;
|
|
161
165
|
}
|
|
162
166
|
/** Appends an ScrStr's bytes into a ScrJsonBuf (walkers' putScrStr). */
|
|
@@ -164,8 +168,8 @@ export class LlDyn {
|
|
|
164
168
|
this.host.declare(`declare void @scr_jb_putc(ptr, i8)`);
|
|
165
169
|
const { len, data } = this.strParts(B, s);
|
|
166
170
|
const jSlot = B.slot();
|
|
167
|
-
B.entryAllocas.push(`${jSlot} = alloca
|
|
168
|
-
B.line(`store
|
|
171
|
+
B.entryAllocas.push(`${jSlot} = alloca ${this.S}`);
|
|
172
|
+
B.line(`store ${this.S} 0, ptr ${jSlot}`);
|
|
169
173
|
const lc = B.newLabel("dps.c");
|
|
170
174
|
const lb = B.newLabel("dps.b");
|
|
171
175
|
const le = B.newLabel("dps.e");
|
|
@@ -173,18 +177,18 @@ export class LlDyn {
|
|
|
173
177
|
B.startBlock(lc);
|
|
174
178
|
const j = B.tmp();
|
|
175
179
|
const cont = B.tmp();
|
|
176
|
-
B.line(`${j} = load
|
|
177
|
-
B.line(`${cont} = icmp ult
|
|
180
|
+
B.line(`${j} = load ${this.S}, ptr ${jSlot}`);
|
|
181
|
+
B.line(`${cont} = icmp ult ${this.S} ${j}, ${len}`);
|
|
178
182
|
B.condBr(cont, lb, le);
|
|
179
183
|
B.startBlock(lb);
|
|
180
184
|
const cp = B.tmp();
|
|
181
185
|
const c = B.tmp();
|
|
182
|
-
B.line(`${cp} = getelementptr inbounds i8, ptr ${data},
|
|
186
|
+
B.line(`${cp} = getelementptr inbounds i8, ptr ${data}, ${this.S} ${j}`);
|
|
183
187
|
B.line(`${c} = load i8, ptr ${cp}`);
|
|
184
188
|
B.line(`call void @scr_jb_putc(ptr ${buf}, i8 ${c})`);
|
|
185
189
|
const j2 = B.tmp();
|
|
186
|
-
B.line(`${j2} = add
|
|
187
|
-
B.line(`store
|
|
190
|
+
B.line(`${j2} = add ${this.S} ${j}, 1`);
|
|
191
|
+
B.line(`store ${this.S} ${j2}, ptr ${jSlot}`);
|
|
188
192
|
B.br(lc);
|
|
189
193
|
B.startBlock(le);
|
|
190
194
|
}
|
|
@@ -192,12 +196,12 @@ export class LlDyn {
|
|
|
192
196
|
this.host.declare(`declare void @scr_jb_puts(ptr, ptr)`);
|
|
193
197
|
B.line(`call void @scr_jb_puts(ptr ${buf}, ptr ${this.host.cstr(text)}) ; ${JSON.stringify(text)}`);
|
|
194
198
|
}
|
|
195
|
-
/**
|
|
199
|
+
/** A size_t counting loop: emits header/body, calls `body(i)`, closes.
|
|
196
200
|
* The body must not terminate its final block. */
|
|
197
201
|
i64Loop(B, hint, limit, body) {
|
|
198
202
|
const iSlot = B.slot();
|
|
199
|
-
B.entryAllocas.push(`${iSlot} = alloca
|
|
200
|
-
B.line(`store
|
|
203
|
+
B.entryAllocas.push(`${iSlot} = alloca ${this.S}`);
|
|
204
|
+
B.line(`store ${this.S} 0, ptr ${iSlot}`);
|
|
201
205
|
const lc = B.newLabel(`${hint}.c`);
|
|
202
206
|
const lb = B.newLabel(`${hint}.b`);
|
|
203
207
|
const ln = B.newLabel(`${hint}.n`);
|
|
@@ -206,16 +210,16 @@ export class LlDyn {
|
|
|
206
210
|
B.startBlock(lc);
|
|
207
211
|
const i = B.tmp();
|
|
208
212
|
const cont = B.tmp();
|
|
209
|
-
B.line(`${i} = load
|
|
210
|
-
B.line(`${cont} = icmp ult
|
|
213
|
+
B.line(`${i} = load ${this.S}, ptr ${iSlot}`);
|
|
214
|
+
B.line(`${cont} = icmp ult ${this.S} ${i}, ${limit}`);
|
|
211
215
|
B.condBr(cont, lb, le);
|
|
212
216
|
B.startBlock(lb);
|
|
213
217
|
body(i, () => B.br(ln), ln);
|
|
214
218
|
B.br(ln);
|
|
215
219
|
B.startBlock(ln);
|
|
216
220
|
const i2 = B.tmp();
|
|
217
|
-
B.line(`${i2} = add
|
|
218
|
-
B.line(`store
|
|
221
|
+
B.line(`${i2} = add ${this.S} ${i}, 1`);
|
|
222
|
+
B.line(`store ${this.S} ${i2}, ptr ${iSlot}`);
|
|
219
223
|
B.br(lc);
|
|
220
224
|
B.startBlock(le);
|
|
221
225
|
}
|
|
@@ -284,9 +288,9 @@ export class LlDyn {
|
|
|
284
288
|
this.dynMatchers.set(key, name);
|
|
285
289
|
const B = new BlockBuilder();
|
|
286
290
|
if (isRefCounted(t) && t.kind !== "dyn") {
|
|
287
|
-
this.host.declare(`declare zeroext i1 @scr_dyn_typed_ref_is(ptr, ptr,
|
|
291
|
+
this.host.declare(`declare zeroext i1 @scr_dyn_typed_ref_is(ptr, ptr, ${this.S})`);
|
|
288
292
|
const matched = B.tmp();
|
|
289
|
-
B.line(`${matched} = call zeroext i1 @scr_dyn_typed_ref_is(ptr %d, ptr ${this.host.cstr(key)},
|
|
293
|
+
B.line(`${matched} = call zeroext i1 @scr_dyn_typed_ref_is(ptr %d, ptr ${this.host.cstr(key)}, ${this.S} ${Buffer.byteLength(key, "utf8")})`);
|
|
290
294
|
const lRef = B.newLabel("dm.tr");
|
|
291
295
|
const lNext = B.newLabel("dm.nt");
|
|
292
296
|
B.condBr(matched, lRef, lNext);
|
|
@@ -359,7 +363,7 @@ export class LlDyn {
|
|
|
359
363
|
B.startBlock(l1);
|
|
360
364
|
const len = this.lenOf(B, "%d");
|
|
361
365
|
const lenOk = B.tmp();
|
|
362
|
-
B.line(`${lenOk} = icmp eq
|
|
366
|
+
B.line(`${lenOk} = icmp eq ${this.S} ${len}, ${byIndex.length}`);
|
|
363
367
|
const l2 = B.newLabel("dm.l");
|
|
364
368
|
B.condBr(lenOk, l2, fail);
|
|
365
369
|
B.startBlock(l2);
|
|
@@ -408,7 +412,7 @@ export class LlDyn {
|
|
|
408
412
|
// Index-signature shapes: UNDECLARED keys must fit the overflow
|
|
409
413
|
// value type. A dyn value type accepts anything.
|
|
410
414
|
if (shape.indexValue && shape.indexValue.kind !== "dyn") {
|
|
411
|
-
this.host.declare(`declare i32 @memcmp(ptr, ptr,
|
|
415
|
+
this.host.declare(`declare i32 @memcmp(ptr, ptr, ${this.S})`);
|
|
412
416
|
const n = this.lenOf(B, "%d");
|
|
413
417
|
const entries = this.itemsOf(B, "%d");
|
|
414
418
|
this.i64Loop(B, "dm.ov", n, (i, brNext) => {
|
|
@@ -417,14 +421,14 @@ export class LlDyn {
|
|
|
417
421
|
for (const f of shape.fields) {
|
|
418
422
|
const klen = Buffer.byteLength(f.name, "utf8");
|
|
419
423
|
const lenEq = B.tmp();
|
|
420
|
-
B.line(`${lenEq} = icmp eq
|
|
424
|
+
B.line(`${lenEq} = icmp eq ${this.S} ${ent.keyLen}, ${klen}`);
|
|
421
425
|
const lCmp = B.newLabel("dm.kc");
|
|
422
426
|
const lNo = B.newLabel("dm.kn");
|
|
423
427
|
B.condBr(lenEq, lCmp, lNo);
|
|
424
428
|
B.startBlock(lCmp);
|
|
425
429
|
const c = B.tmp();
|
|
426
430
|
const same = B.tmp();
|
|
427
|
-
B.line(`${c} = call i32 @memcmp(ptr ${ent.key}, ptr ${this.host.cstr(f.name)},
|
|
431
|
+
B.line(`${c} = call i32 @memcmp(ptr ${ent.key}, ptr ${this.host.cstr(f.name)}, ${this.S} ${klen}) ; ${f.name}`);
|
|
428
432
|
B.line(`${same} = icmp eq i32 ${c}, 0`);
|
|
429
433
|
const lNo2 = B.newLabel("dm.kn");
|
|
430
434
|
const skip = B.newLabel("dm.ks");
|
|
@@ -513,10 +517,10 @@ export class LlDyn {
|
|
|
513
517
|
const want = host.cstr(this.dynDesc(t));
|
|
514
518
|
const B = new BlockBuilder();
|
|
515
519
|
if (isRefCounted(t) && t.kind !== "dyn") {
|
|
516
|
-
host.declare(`declare zeroext i1 @scr_dyn_typed_ref_is(ptr, ptr,
|
|
520
|
+
host.declare(`declare zeroext i1 @scr_dyn_typed_ref_is(ptr, ptr, ${host.sizeType})`);
|
|
517
521
|
host.declare(`declare ptr @scr_dyn_typed_ref_unbox(ptr)`);
|
|
518
522
|
const matched = B.tmp();
|
|
519
|
-
B.line(`${matched} = call zeroext i1 @scr_dyn_typed_ref_is(ptr %d, ptr ${host.cstr(key)},
|
|
523
|
+
B.line(`${matched} = call zeroext i1 @scr_dyn_typed_ref_is(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")})`);
|
|
520
524
|
const lRef = B.newLabel("dc.tr");
|
|
521
525
|
const lNext = B.newLabel("dc.nt");
|
|
522
526
|
B.condBr(matched, lRef, lNext);
|
|
@@ -527,8 +531,8 @@ export class LlDyn {
|
|
|
527
531
|
B.startBlock(lNext);
|
|
528
532
|
if (t.kind !== "union") {
|
|
529
533
|
host.declare(`declare ptr @scr_dyn_typed_ref_materialize(ptr)`);
|
|
530
|
-
host.declare(`declare ptr @scr_dyn_typed_ref_cached_cast(ptr, ptr,
|
|
531
|
-
host.declare(`declare void @scr_dyn_typed_ref_cache_cast(ptr, ptr,
|
|
534
|
+
host.declare(`declare ptr @scr_dyn_typed_ref_cached_cast(ptr, ptr, ${host.sizeType})`);
|
|
535
|
+
host.declare(`declare void @scr_dyn_typed_ref_cache_cast(ptr, ptr, ${host.sizeType}, ptr, ptr, ptr)`);
|
|
532
536
|
host.declare(`declare void @scr_dyn_release_v(ptr)`);
|
|
533
537
|
const rc = vAdapters(host, t);
|
|
534
538
|
const kind = this.kindOf(B, "%d");
|
|
@@ -539,7 +543,7 @@ export class LlDyn {
|
|
|
539
543
|
B.condBr(capsule, lCapsule, lPlain);
|
|
540
544
|
B.startBlock(lCapsule);
|
|
541
545
|
const cached = B.tmp();
|
|
542
|
-
B.line(`${cached} = call ptr @scr_dyn_typed_ref_cached_cast(ptr %d, ptr ${host.cstr(key)},
|
|
546
|
+
B.line(`${cached} = call ptr @scr_dyn_typed_ref_cached_cast(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")})`);
|
|
543
547
|
const hasCached = B.tmp();
|
|
544
548
|
B.line(`${hasCached} = icmp ne ptr ${cached}, null`);
|
|
545
549
|
if (t.kind !== "record" && t.kind !== "array") {
|
|
@@ -597,8 +601,8 @@ export class LlDyn {
|
|
|
597
601
|
: []),
|
|
598
602
|
]
|
|
599
603
|
: [
|
|
600
|
-
{ index: 1, type:
|
|
601
|
-
{ index: 2, type:
|
|
604
|
+
{ index: 1, type: host.sizeType, name: "length" },
|
|
605
|
+
{ index: 2, type: host.sizeType, name: "capacity" },
|
|
602
606
|
{ index: 7, type: "ptr", name: "data" },
|
|
603
607
|
];
|
|
604
608
|
members.forEach((member) => {
|
|
@@ -619,7 +623,7 @@ export class LlDyn {
|
|
|
619
623
|
B.line(`call void ${releaseSym(host, t)}(ptr ${checked})`);
|
|
620
624
|
B.terminate(`ret ptr ${cached}`);
|
|
621
625
|
B.startBlock(lCache);
|
|
622
|
-
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)},
|
|
626
|
+
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")}, ptr ${checked}, ptr ${rc.retain}, ptr ${rc.release})`);
|
|
623
627
|
B.terminate(`ret ptr ${checked}`);
|
|
624
628
|
}
|
|
625
629
|
else {
|
|
@@ -627,7 +631,7 @@ export class LlDyn {
|
|
|
627
631
|
const lReturn = B.newLabel("dc.tr.ret");
|
|
628
632
|
B.condBr(ok, lCache, lReturn);
|
|
629
633
|
B.startBlock(lCache);
|
|
630
|
-
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)},
|
|
634
|
+
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")}, ptr ${checked}, ptr ${rc.retain}, ptr ${rc.release})`);
|
|
631
635
|
B.br(lReturn);
|
|
632
636
|
B.startBlock(lReturn);
|
|
633
637
|
B.terminate(`ret ptr ${checked}`);
|
|
@@ -745,7 +749,7 @@ export class LlDyn {
|
|
|
745
749
|
B.line(`${kp} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 1`);
|
|
746
750
|
B.line(`store ptr ${keyText === null ? "null" : host.cstr(keyText)}, ptr ${kp}`);
|
|
747
751
|
B.line(`${ip} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 2`);
|
|
748
|
-
B.line(`store
|
|
752
|
+
B.line(`store ${host.sizeType} ${index}, ptr ${ip}`);
|
|
749
753
|
};
|
|
750
754
|
const setPathKeyPtr = (keyPtr) => {
|
|
751
755
|
const pp = B.tmp();
|
|
@@ -756,7 +760,7 @@ export class LlDyn {
|
|
|
756
760
|
B.line(`${kp} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 1`);
|
|
757
761
|
B.line(`store ptr ${keyPtr}, ptr ${kp}`);
|
|
758
762
|
B.line(`${ip} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 2`);
|
|
759
|
-
B.line(`store
|
|
763
|
+
B.line(`store ${host.sizeType} 0, ptr ${ip}`);
|
|
760
764
|
};
|
|
761
765
|
const storeInto = (fieldName, ft, value) => {
|
|
762
766
|
const idx = fieldIndex.get(fieldName);
|
|
@@ -778,7 +782,7 @@ export class LlDyn {
|
|
|
778
782
|
requireKind(DK.ARR, "dct");
|
|
779
783
|
const len = this.lenOf(B, "%d");
|
|
780
784
|
const lenOk = B.tmp();
|
|
781
|
-
B.line(`${lenOk} = icmp eq
|
|
785
|
+
B.line(`${lenOk} = icmp eq ${host.sizeType} ${len}, ${byIndex.length}`);
|
|
782
786
|
const lGo = B.newLabel("dct.g");
|
|
783
787
|
const lAr = B.newLabel("dct.a");
|
|
784
788
|
B.condBr(lenOk, lGo, lAr);
|
|
@@ -862,8 +866,8 @@ export class LlDyn {
|
|
|
862
866
|
// overflow map.
|
|
863
867
|
if (shape.indexValue) {
|
|
864
868
|
const iv = shape.indexValue;
|
|
865
|
-
host.declare(`declare i32 @memcmp(ptr, ptr,
|
|
866
|
-
host.declare(`declare ptr @scr_str_new(ptr,
|
|
869
|
+
host.declare(`declare i32 @memcmp(ptr, ptr, ${host.sizeType})`);
|
|
870
|
+
host.declare(`declare ptr @scr_str_new(ptr, ${host.sizeType})`);
|
|
867
871
|
host.declare(`declare void @scr_str_release(ptr)`);
|
|
868
872
|
const ovfp = B.tmp();
|
|
869
873
|
const ovf = B.tmp();
|
|
@@ -876,14 +880,14 @@ export class LlDyn {
|
|
|
876
880
|
for (const f of shape.fields) {
|
|
877
881
|
const klen = Buffer.byteLength(f.name, "utf8");
|
|
878
882
|
const lenEq = B.tmp();
|
|
879
|
-
B.line(`${lenEq} = icmp eq
|
|
883
|
+
B.line(`${lenEq} = icmp eq ${host.sizeType} ${ent.keyLen}, ${klen}`);
|
|
880
884
|
const lCmp = B.newLabel("dcv.kc");
|
|
881
885
|
const lNo = B.newLabel("dcv.kn");
|
|
882
886
|
B.condBr(lenEq, lCmp, lNo);
|
|
883
887
|
B.startBlock(lCmp);
|
|
884
888
|
const c = B.tmp();
|
|
885
889
|
const same = B.tmp();
|
|
886
|
-
B.line(`${c} = call i32 @memcmp(ptr ${ent.key}, ptr ${host.cstr(f.name)},
|
|
890
|
+
B.line(`${c} = call i32 @memcmp(ptr ${ent.key}, ptr ${host.cstr(f.name)}, ${host.sizeType} ${klen}) ; ${f.name}`);
|
|
887
891
|
B.line(`${same} = icmp eq i32 ${c}, 0`);
|
|
888
892
|
const skip = B.newLabel("dcv.ks");
|
|
889
893
|
const lNo2 = B.newLabel("dcv.kn");
|
|
@@ -905,7 +909,7 @@ export class LlDyn {
|
|
|
905
909
|
this.pendingBail(B, "dcv", releaseR, "ptr null");
|
|
906
910
|
}
|
|
907
911
|
const ek = B.tmp();
|
|
908
|
-
B.line(`${ek} = call ptr @scr_str_new(ptr ${ent.key},
|
|
912
|
+
B.line(`${ek} = call ptr @scr_str_new(ptr ${ent.key}, ${host.sizeType} ${ent.keyLen})`);
|
|
909
913
|
if (iv.kind === "f64") {
|
|
910
914
|
host.declare(`declare void @scr_map_set_str_f64(ptr, ptr, double)`);
|
|
911
915
|
B.line(`call void @scr_map_set_str_f64(ptr ${ovf}, ptr ${ek}, double ${ev})`);
|
|
@@ -946,7 +950,7 @@ export class LlDyn {
|
|
|
946
950
|
B.line(`${kp} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 1`);
|
|
947
951
|
B.line(`store ptr null, ptr ${kp}`);
|
|
948
952
|
B.line(`${ip} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 2`);
|
|
949
|
-
B.line(`store
|
|
953
|
+
B.line(`store ${host.sizeType} ${i}, ptr ${ip}`);
|
|
950
954
|
const e = this.itemAt(B, items, i);
|
|
951
955
|
const v = B.tmp();
|
|
952
956
|
B.line(`${v} = call ${this.valTy(elem)} @${c}(ptr ${e}, ptr ${pathSlot})`);
|
|
@@ -1011,8 +1015,8 @@ export class LlDyn {
|
|
|
1011
1015
|
// snapshot (the compiler's width-coercion stance, rather than a
|
|
1012
1016
|
// live narrowed alias).
|
|
1013
1017
|
host.declare(`declare ptr @scr_dyn_typed_ref_materialize(ptr)`);
|
|
1014
|
-
host.declare(`declare ptr @scr_dyn_typed_ref_cached_cast(ptr, ptr,
|
|
1015
|
-
host.declare(`declare void @scr_dyn_typed_ref_cache_cast(ptr, ptr,
|
|
1018
|
+
host.declare(`declare ptr @scr_dyn_typed_ref_cached_cast(ptr, ptr, ${host.sizeType})`);
|
|
1019
|
+
host.declare(`declare void @scr_dyn_typed_ref_cache_cast(ptr, ptr, ${host.sizeType}, ptr, ptr, ptr)`);
|
|
1016
1020
|
host.declare(`declare void @scr_dyn_release_v(ptr)`);
|
|
1017
1021
|
host.declare(`declare void @scr_union_release(ptr)`);
|
|
1018
1022
|
const rc = vAdapters(host, t);
|
|
@@ -1024,7 +1028,7 @@ export class LlDyn {
|
|
|
1024
1028
|
B.condBr(capsule, lCapsule, lFail);
|
|
1025
1029
|
B.startBlock(lCapsule);
|
|
1026
1030
|
const cached = B.tmp();
|
|
1027
|
-
B.line(`${cached} = call ptr @scr_dyn_typed_ref_cached_cast(ptr %d, ptr ${host.cstr(key)},
|
|
1031
|
+
B.line(`${cached} = call ptr @scr_dyn_typed_ref_cached_cast(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")})`);
|
|
1028
1032
|
const hasCached = B.tmp();
|
|
1029
1033
|
B.line(`${hasCached} = icmp ne ptr ${cached}, null`);
|
|
1030
1034
|
const materialized = B.tmp();
|
|
@@ -1072,7 +1076,7 @@ export class LlDyn {
|
|
|
1072
1076
|
B.line(`call void @scr_union_release(ptr ${checked})`);
|
|
1073
1077
|
B.terminate(`ret ptr ${cached}`);
|
|
1074
1078
|
B.startBlock(lCache);
|
|
1075
|
-
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)},
|
|
1079
|
+
B.line(`call void @scr_dyn_typed_ref_cache_cast(ptr %d, ptr ${host.cstr(key)}, ${host.sizeType} ${Buffer.byteLength(key, "utf8")}, ptr ${checked}, ptr ${rc.retain}, ptr ${rc.release})`);
|
|
1076
1080
|
B.terminate(`ret ptr ${checked}`);
|
|
1077
1081
|
B.startBlock(lFail);
|
|
1078
1082
|
B.line(`call void @scr_dyn_check_fail(ptr %path, ptr ${want}, ptr %d)`);
|
|
@@ -1090,7 +1094,7 @@ export class LlDyn {
|
|
|
1090
1094
|
host.declare(`declare i32 @strcmp(ptr, ptr)`);
|
|
1091
1095
|
const sigp = B.tmp();
|
|
1092
1096
|
const sig = B.tmp();
|
|
1093
|
-
B.line(`${sigp} = getelementptr inbounds i8, ptr %d, i64 32 ; ->v.fn.sig`);
|
|
1097
|
+
B.line(`${sigp} = getelementptr inbounds i8, ptr %d, i64 ${this.abiOffset(32, 24)} ; ->v.fn.sig`);
|
|
1094
1098
|
B.line(`${sig} = load ptr, ptr ${sigp}`);
|
|
1095
1099
|
const cmp = B.tmp();
|
|
1096
1100
|
const same = B.tmp();
|
|
@@ -1109,17 +1113,17 @@ export class LlDyn {
|
|
|
1109
1113
|
B.line(`${r} = call ptr @scr_closure_retain_v(ptr ${clo})`);
|
|
1110
1114
|
B.terminate(`ret ptr ${r}`);
|
|
1111
1115
|
B.startBlock(lWrap);
|
|
1112
|
-
host.declare(`declare ptr @scr_closure_new(ptr,
|
|
1116
|
+
host.declare(`declare ptr @scr_closure_new(ptr, ${host.sizeType})`);
|
|
1113
1117
|
host.declare(`declare ptr @scr_box_new_obj(ptr, ptr, ptr)`);
|
|
1114
1118
|
host.declare(`declare void @scr_box_set_ref(ptr, ptr)`);
|
|
1115
1119
|
host.declare(`declare ptr @scr_dyn_retain_v(ptr)`);
|
|
1116
1120
|
host.declare(`declare void @scr_dyn_release_v(ptr)`);
|
|
1117
1121
|
const a = B.tmp();
|
|
1118
|
-
B.line(`${a} = call ptr @scr_closure_new(ptr @${adapter},
|
|
1122
|
+
B.line(`${a} = call ptr @scr_closure_new(ptr @${adapter}, ${host.sizeType} 1)`);
|
|
1119
1123
|
const box = B.tmp();
|
|
1120
1124
|
B.line(`${box} = call ptr @scr_box_new_obj(ptr @scr_dyn_retain_v, ptr @scr_dyn_release_v, ptr null)`);
|
|
1121
1125
|
const capp = B.tmp();
|
|
1122
|
-
B.line(`${capp} = getelementptr inbounds
|
|
1126
|
+
B.line(`${capp} = getelementptr inbounds %ScrClosure, ptr ${a}, i64 1 ; caps[0]`);
|
|
1123
1127
|
B.line(`store ptr ${box}, ptr ${capp}`);
|
|
1124
1128
|
const rd = this.retainDyn(B, "%d");
|
|
1125
1129
|
B.line(`call void @scr_box_set_ref(ptr ${box}, ptr ${rd})`);
|
|
@@ -1228,7 +1232,7 @@ export class LlDyn {
|
|
|
1228
1232
|
B.line(`${b} = trunc i8 ${raw} to i1`);
|
|
1229
1233
|
return b;
|
|
1230
1234
|
};
|
|
1231
|
-
host.declare(`declare void @scr_dyn_obj_set(ptr, ptr,
|
|
1235
|
+
host.declare(`declare void @scr_dyn_obj_set(ptr, ptr, ${host.sizeType}, ptr)`);
|
|
1232
1236
|
// CYCLE-CAPABLE shapes guard the deep copy: enter TRAPS on a value
|
|
1233
1237
|
// already being converted (a cyclic value has no finite dyn copy —
|
|
1234
1238
|
// SEMANTICS.md; the C emitter's contract exactly).
|
|
@@ -1285,7 +1289,7 @@ export class LlDyn {
|
|
|
1285
1289
|
const fv = loadFieldOf(f.name, f.type);
|
|
1286
1290
|
const conv = B.tmp();
|
|
1287
1291
|
B.line(`${conv} = call ptr @${this.toDynHelper(f.type)}(${this.valTy(f.type)} ${fv})`);
|
|
1288
|
-
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${host.cstr(f.name)},
|
|
1292
|
+
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${host.cstr(f.name)}, ${host.sizeType} ${klen}, ptr ${conv}) ; ${f.name}`);
|
|
1289
1293
|
}
|
|
1290
1294
|
if (shape.indexValue) {
|
|
1291
1295
|
const iv = shape.indexValue;
|
|
@@ -1343,14 +1347,14 @@ export class LlDyn {
|
|
|
1343
1347
|
host.declare(`declare ptr @scr_dyn_new_bool(i1 zeroext)`);
|
|
1344
1348
|
B.line(`${boxed} = call ptr @scr_dyn_new_bool(i1 ${val})`);
|
|
1345
1349
|
}
|
|
1346
|
-
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata},
|
|
1350
|
+
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata}, ${host.sizeType} ${klen}, ptr ${boxed})`);
|
|
1347
1351
|
}
|
|
1348
1352
|
else if (iv.kind === "dyn") {
|
|
1349
1353
|
// get_str_ref returns +1 — exactly the ownership obj_set takes.
|
|
1350
1354
|
host.declare(`declare ptr @scr_map_get_str_ref(ptr, ptr)`);
|
|
1351
1355
|
const hit = B.tmp();
|
|
1352
1356
|
B.line(`${hit} = call ptr @scr_map_get_str_ref(ptr ${ovf}, ptr ${k})`);
|
|
1353
|
-
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata},
|
|
1357
|
+
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata}, ${host.sizeType} ${klen}, ptr ${hit})`);
|
|
1354
1358
|
}
|
|
1355
1359
|
else {
|
|
1356
1360
|
host.declare(`declare ptr @scr_map_get_str_ref(ptr, ptr)`);
|
|
@@ -1358,7 +1362,7 @@ export class LlDyn {
|
|
|
1358
1362
|
B.line(`${hit} = call ptr @scr_map_get_str_ref(ptr ${ovf}, ptr ${k})`);
|
|
1359
1363
|
const conv = B.tmp();
|
|
1360
1364
|
B.line(`${conv} = call ptr @${this.toDynHelper(iv)}(ptr ${hit})`);
|
|
1361
|
-
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata},
|
|
1365
|
+
B.line(`call void @scr_dyn_obj_set(ptr ${d}, ptr ${kdata}, ${host.sizeType} ${klen}, ptr ${conv})`);
|
|
1362
1366
|
B.line(`call void ${releaseSym(host, iv)}(ptr ${hit})`);
|
|
1363
1367
|
}
|
|
1364
1368
|
B.line(`call void @scr_str_release(ptr ${k})`);
|
|
@@ -1717,7 +1721,7 @@ export class LlDyn {
|
|
|
1717
1721
|
const items = this.itemsOf(B, "%d");
|
|
1718
1722
|
this.i64Loop(B, "ds.ar", n, (i, brNext) => {
|
|
1719
1723
|
const nz = B.tmp();
|
|
1720
|
-
B.line(`${nz} = icmp ugt
|
|
1724
|
+
B.line(`${nz} = icmp ugt ${this.S} ${i}, 0`);
|
|
1721
1725
|
const lcm = B.newLabel("ds.cm");
|
|
1722
1726
|
const lel = B.newLabel("ds.el");
|
|
1723
1727
|
B.condBr(nz, lcm, lel);
|
|
@@ -1812,7 +1816,7 @@ export class LlDyn {
|
|
|
1812
1816
|
B.startBlock(lt);
|
|
1813
1817
|
const { len } = this.strParts(B, s);
|
|
1814
1818
|
const nz = B.tmp();
|
|
1815
|
-
B.line(`${nz} = icmp ne
|
|
1819
|
+
B.line(`${nz} = icmp ne ${this.S} ${len}, 0`);
|
|
1816
1820
|
B.line(`store i1 ${nz}, ptr ${slot}`);
|
|
1817
1821
|
B.br(lj);
|
|
1818
1822
|
B.startBlock(lj);
|
|
@@ -1842,7 +1846,7 @@ export class LlDyn {
|
|
|
1842
1846
|
const bufp = B.tmp();
|
|
1843
1847
|
const bufRaw = B.tmp();
|
|
1844
1848
|
const isBuf = B.tmp();
|
|
1845
|
-
B.line(`${bufp} = getelementptr inbounds i8, ptr %d, i64 12 ; ->buffer`);
|
|
1849
|
+
B.line(`${bufp} = getelementptr inbounds i8, ptr %d, i64 ${this.abiOffset(12, 8)} ; ->buffer`);
|
|
1846
1850
|
B.line(`${bufRaw} = load i8, ptr ${bufp}`);
|
|
1847
1851
|
B.line(`${isBuf} = icmp ne i8 ${bufRaw}, 0`);
|
|
1848
1852
|
const lBuf = B.newLabel("ds.bu");
|
|
@@ -1863,13 +1867,13 @@ export class LlDyn {
|
|
|
1863
1867
|
const blen = B.tmp();
|
|
1864
1868
|
const bdatap = B.tmp();
|
|
1865
1869
|
const bdata = B.tmp();
|
|
1866
|
-
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 8 ; ->len`);
|
|
1867
|
-
B.line(`${blen} = load
|
|
1868
|
-
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 24 ; ->data`);
|
|
1870
|
+
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(8, 4)} ; ->len`);
|
|
1871
|
+
B.line(`${blen} = load ${this.S}, ptr ${blenp}`);
|
|
1872
|
+
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(24, 12)} ; ->data`);
|
|
1869
1873
|
B.line(`${bdata} = load ptr, ptr ${bdatap}`);
|
|
1870
1874
|
this.i64Loop(B, "ds.by", blen, (i) => {
|
|
1871
1875
|
const nz = B.tmp();
|
|
1872
|
-
B.line(`${nz} = icmp ugt
|
|
1876
|
+
B.line(`${nz} = icmp ugt ${this.S} ${i}, 0`);
|
|
1873
1877
|
const lcm = B.newLabel("ds.bc");
|
|
1874
1878
|
const lv = B.newLabel("ds.bv");
|
|
1875
1879
|
B.condBr(nz, lcm, lv);
|
|
@@ -1880,7 +1884,7 @@ export class LlDyn {
|
|
|
1880
1884
|
const cp = B.tmp();
|
|
1881
1885
|
const c = B.tmp();
|
|
1882
1886
|
const cd = B.tmp();
|
|
1883
|
-
B.line(`${cp} = getelementptr inbounds i8, ptr ${bdata},
|
|
1887
|
+
B.line(`${cp} = getelementptr inbounds i8, ptr ${bdata}, ${this.S} ${i}`);
|
|
1884
1888
|
B.line(`${c} = load i8, ptr ${cp}`);
|
|
1885
1889
|
B.line(`${cd} = uitofp i8 ${c} to double`);
|
|
1886
1890
|
const s = B.tmp();
|
|
@@ -1896,7 +1900,7 @@ export class LlDyn {
|
|
|
1896
1900
|
this.puts(B, "%b", "function ");
|
|
1897
1901
|
const namep = B.tmp();
|
|
1898
1902
|
const nm = B.tmp();
|
|
1899
|
-
B.line(`${namep} = getelementptr inbounds i8, ptr %d, i64 40 ; ->v.fn.name`);
|
|
1903
|
+
B.line(`${namep} = getelementptr inbounds i8, ptr %d, i64 ${this.abiOffset(40, 28)} ; ->v.fn.name`);
|
|
1900
1904
|
B.line(`${nm} = load ptr, ptr ${namep}`);
|
|
1901
1905
|
const nn = B.tmp();
|
|
1902
1906
|
B.line(`${nn} = icmp ne ptr ${nm}, null`);
|
|
@@ -2094,7 +2098,7 @@ export class LlDyn {
|
|
|
2094
2098
|
B.startBlock(lOpt);
|
|
2095
2099
|
retainUndef();
|
|
2096
2100
|
B.startBlock(lThrow);
|
|
2097
|
-
host.declare(`declare ptr @scr_str_new(ptr,
|
|
2101
|
+
host.declare(`declare ptr @scr_str_new(ptr, ${host.sizeType})`);
|
|
2098
2102
|
host.declare(`declare ptr @scr_str_concat(ptr, ptr)`);
|
|
2099
2103
|
host.declare(`declare void @scr_str_release(ptr)`);
|
|
2100
2104
|
host.declare(`declare void @scr_throw_error(i32, ptr)`);
|
|
@@ -2103,14 +2107,14 @@ export class LlDyn {
|
|
|
2103
2107
|
const base = B.tmp();
|
|
2104
2108
|
B.line(`${base} = select i1 ${isU}, ptr ${host.cstr(baseU)}, ptr ${host.cstr(baseN)}`);
|
|
2105
2109
|
const baseLen = B.tmp();
|
|
2106
|
-
B.line(`${baseLen} = select i1 ${isU},
|
|
2110
|
+
B.line(`${baseLen} = select i1 ${isU}, ${host.sizeType} ${Buffer.byteLength(baseU)}, ${host.sizeType} ${Buffer.byteLength(baseN)}`);
|
|
2107
2111
|
const head = B.tmp();
|
|
2108
|
-
B.line(`${head} = call ptr @scr_str_new(ptr ${base},
|
|
2112
|
+
B.line(`${head} = call ptr @scr_str_new(ptr ${base}, ${host.sizeType} ${baseLen})`);
|
|
2109
2113
|
const withKey = B.tmp();
|
|
2110
2114
|
B.line(`${withKey} = call ptr @scr_str_concat(ptr ${head}, ptr %k)`);
|
|
2111
2115
|
B.line(`call void @scr_str_release(ptr ${head})`);
|
|
2112
2116
|
const tail = B.tmp();
|
|
2113
|
-
B.line(`${tail} = call ptr @scr_str_new(ptr ${host.cstr("')")},
|
|
2117
|
+
B.line(`${tail} = call ptr @scr_str_new(ptr ${host.cstr("')")}, ${host.sizeType} 2)`);
|
|
2114
2118
|
const msg = B.tmp();
|
|
2115
2119
|
B.line(`${msg} = call ptr @scr_str_concat(ptr ${withKey}, ptr ${tail})`);
|
|
2116
2120
|
B.line(`call void @scr_str_release(ptr ${withKey})`);
|
|
@@ -2162,9 +2166,9 @@ export class LlDyn {
|
|
|
2162
2166
|
const lNext = B.newLabel("kg.n");
|
|
2163
2167
|
B.condBr(isObj, lObj, lNext);
|
|
2164
2168
|
B.startBlock(lObj);
|
|
2165
|
-
host.declare(`declare ptr @scr_dyn_obj_get(ptr, ptr,
|
|
2169
|
+
host.declare(`declare ptr @scr_dyn_obj_get(ptr, ptr, ${host.sizeType})`);
|
|
2166
2170
|
const m = B.tmp();
|
|
2167
|
-
B.line(`${m} = call ptr @scr_dyn_obj_get(ptr %d, ptr ${kParts.data},
|
|
2171
|
+
B.line(`${m} = call ptr @scr_dyn_obj_get(ptr %d, ptr ${kParts.data}, ${host.sizeType} ${kParts.len})`);
|
|
2168
2172
|
const has = B.tmp();
|
|
2169
2173
|
B.line(`${has} = icmp ne ptr ${m}, null`);
|
|
2170
2174
|
const u = this.undef(B);
|
|
@@ -2193,18 +2197,18 @@ export class LlDyn {
|
|
|
2193
2197
|
const parseIndex = () => {
|
|
2194
2198
|
const digitsSlot = B.slot();
|
|
2195
2199
|
const idxSlot = B.slot();
|
|
2196
|
-
B.entryAllocas.push(`${digitsSlot} = alloca i1`, `${idxSlot} = alloca
|
|
2200
|
+
B.entryAllocas.push(`${digitsSlot} = alloca i1`, `${idxSlot} = alloca ${host.sizeType}`);
|
|
2197
2201
|
B.line(`store i1 false, ptr ${digitsSlot}`);
|
|
2198
|
-
B.line(`store
|
|
2202
|
+
B.line(`store ${host.sizeType} 0, ptr ${idxSlot}`);
|
|
2199
2203
|
// k->len > 0 && !(k->len > 1 && k->data[0] == '0')
|
|
2200
2204
|
const nz = B.tmp();
|
|
2201
|
-
B.line(`${nz} = icmp ugt
|
|
2205
|
+
B.line(`${nz} = icmp ugt ${host.sizeType} ${kParts.len}, 0`);
|
|
2202
2206
|
const lGo = B.newLabel("kg.ix");
|
|
2203
2207
|
const lOut = B.newLabel("kg.io");
|
|
2204
2208
|
B.condBr(nz, lGo, lOut);
|
|
2205
2209
|
B.startBlock(lGo);
|
|
2206
2210
|
const multi = B.tmp();
|
|
2207
|
-
B.line(`${multi} = icmp ugt
|
|
2211
|
+
B.line(`${multi} = icmp ugt ${host.sizeType} ${kParts.len}, 1`);
|
|
2208
2212
|
const c0 = B.tmp();
|
|
2209
2213
|
B.line(`${c0} = load i8, ptr ${kParts.data}`);
|
|
2210
2214
|
const isZero = B.tmp();
|
|
@@ -2218,16 +2222,16 @@ export class LlDyn {
|
|
|
2218
2222
|
this.i64Loop(B, "kg.id", kParts.len, (i) => {
|
|
2219
2223
|
const cp = B.tmp();
|
|
2220
2224
|
const c = B.tmp();
|
|
2221
|
-
B.line(`${cp} = getelementptr inbounds i8, ptr ${kParts.data},
|
|
2225
|
+
B.line(`${cp} = getelementptr inbounds i8, ptr ${kParts.data}, ${host.sizeType} ${i}`);
|
|
2222
2226
|
B.line(`${c} = load i8, ptr ${cp}`);
|
|
2223
2227
|
const lt0 = B.tmp();
|
|
2224
2228
|
const gt9 = B.tmp();
|
|
2225
2229
|
B.line(`${lt0} = icmp ult i8 ${c}, 48`);
|
|
2226
2230
|
B.line(`${gt9} = icmp ugt i8 ${c}, 57`);
|
|
2227
2231
|
const cur = B.tmp();
|
|
2228
|
-
B.line(`${cur} = load
|
|
2232
|
+
B.line(`${cur} = load ${host.sizeType}, ptr ${idxSlot}`);
|
|
2229
2233
|
const over = B.tmp();
|
|
2230
|
-
B.line(`${over} = icmp ugt
|
|
2234
|
+
B.line(`${over} = icmp ugt ${host.sizeType} ${cur}, ${this.indexMaxDiv10}`);
|
|
2231
2235
|
const bad0 = B.tmp();
|
|
2232
2236
|
const bad = B.tmp();
|
|
2233
2237
|
B.line(`${bad0} = or i1 ${lt0}, ${gt9}`);
|
|
@@ -2241,36 +2245,36 @@ export class LlDyn {
|
|
|
2241
2245
|
B.startBlock(lStep);
|
|
2242
2246
|
const ten = B.tmp();
|
|
2243
2247
|
const digit = B.tmp();
|
|
2244
|
-
const
|
|
2248
|
+
const digitSize = B.tmp();
|
|
2245
2249
|
const nx = B.tmp();
|
|
2246
|
-
B.line(`${ten} = mul
|
|
2250
|
+
B.line(`${ten} = mul ${host.sizeType} ${cur}, 10`);
|
|
2247
2251
|
B.line(`${digit} = sub i8 ${c}, 48`);
|
|
2248
|
-
B.line(`${
|
|
2249
|
-
B.line(`${nx} = add
|
|
2250
|
-
B.line(`store
|
|
2252
|
+
B.line(`${digitSize} = zext i8 ${digit} to ${host.sizeType}`);
|
|
2253
|
+
B.line(`${nx} = add ${host.sizeType} ${ten}, ${digitSize}`);
|
|
2254
|
+
B.line(`store ${host.sizeType} ${nx}, ptr ${idxSlot}`);
|
|
2251
2255
|
});
|
|
2252
2256
|
B.br(lOut);
|
|
2253
2257
|
B.startBlock(lOut);
|
|
2254
2258
|
const digits = B.tmp();
|
|
2255
2259
|
const idx = B.tmp();
|
|
2256
2260
|
B.line(`${digits} = load i1, ptr ${digitsSlot}`);
|
|
2257
|
-
B.line(`${idx} = load
|
|
2261
|
+
B.line(`${idx} = load ${host.sizeType}, ptr ${idxSlot}`);
|
|
2258
2262
|
return { digits, idx };
|
|
2259
2263
|
};
|
|
2260
2264
|
const isLength = () => {
|
|
2261
|
-
host.declare(`declare i32 @memcmp(ptr, ptr,
|
|
2265
|
+
host.declare(`declare i32 @memcmp(ptr, ptr, ${host.sizeType})`);
|
|
2262
2266
|
const slot = B.slot();
|
|
2263
2267
|
B.entryAllocas.push(`${slot} = alloca i1`);
|
|
2264
2268
|
B.line(`store i1 false, ptr ${slot}`);
|
|
2265
2269
|
const len6 = B.tmp();
|
|
2266
|
-
B.line(`${len6} = icmp eq
|
|
2270
|
+
B.line(`${len6} = icmp eq ${host.sizeType} ${kParts.len}, 6`);
|
|
2267
2271
|
const lCmp = B.newLabel("kg.l6");
|
|
2268
2272
|
const lj = B.newLabel("kg.lj");
|
|
2269
2273
|
B.condBr(len6, lCmp, lj);
|
|
2270
2274
|
B.startBlock(lCmp);
|
|
2271
2275
|
const c = B.tmp();
|
|
2272
2276
|
const same = B.tmp();
|
|
2273
|
-
B.line(`${c} = call i32 @memcmp(ptr ${kParts.data}, ptr ${host.cstr("length")},
|
|
2277
|
+
B.line(`${c} = call i32 @memcmp(ptr ${kParts.data}, ptr ${host.cstr("length")}, ${host.sizeType} 6)`);
|
|
2274
2278
|
B.line(`${same} = icmp eq i32 ${c}, 0`);
|
|
2275
2279
|
B.line(`store i1 ${same}, ptr ${slot}`);
|
|
2276
2280
|
B.br(lj);
|
|
@@ -2295,21 +2299,21 @@ export class LlDyn {
|
|
|
2295
2299
|
const bts = this.payloadOf(B, "%d", "ptr");
|
|
2296
2300
|
const blenp = B.tmp();
|
|
2297
2301
|
const blen = B.tmp();
|
|
2298
|
-
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 8 ; ->len`);
|
|
2299
|
-
B.line(`${blen} = load
|
|
2302
|
+
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(8, 4)} ; ->len`);
|
|
2303
|
+
B.line(`${blen} = load ${host.sizeType}, ptr ${blenp}`);
|
|
2300
2304
|
const lLen = B.newLabel("kg.bl");
|
|
2301
2305
|
const lIdx = B.newLabel("kg.bi");
|
|
2302
2306
|
B.condBr(lenHit, lLen, lIdx);
|
|
2303
2307
|
B.startBlock(lLen);
|
|
2304
2308
|
const lenD = B.tmp();
|
|
2305
2309
|
const r0 = B.tmp();
|
|
2306
|
-
B.line(`${lenD} = uitofp
|
|
2310
|
+
B.line(`${lenD} = uitofp ${host.sizeType} ${blen} to double`);
|
|
2307
2311
|
B.line(`${r0} = call ptr @scr_dyn_new_num(double ${lenD})`);
|
|
2308
2312
|
B.terminate(`ret ptr ${r0}`);
|
|
2309
2313
|
B.startBlock(lIdx);
|
|
2310
2314
|
const inRange = B.tmp();
|
|
2311
2315
|
const hit = B.tmp();
|
|
2312
|
-
B.line(`${inRange} = icmp ult
|
|
2316
|
+
B.line(`${inRange} = icmp ult ${host.sizeType} ${idx}, ${blen}`);
|
|
2313
2317
|
B.line(`${hit} = and i1 ${digits}, ${inRange}`);
|
|
2314
2318
|
const lHit = B.newLabel("kg.bh");
|
|
2315
2319
|
const lMiss = B.newLabel("kg.bm");
|
|
@@ -2317,13 +2321,13 @@ export class LlDyn {
|
|
|
2317
2321
|
B.startBlock(lHit);
|
|
2318
2322
|
const bdatap = B.tmp();
|
|
2319
2323
|
const bdata = B.tmp();
|
|
2320
|
-
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 24 ; ->data`);
|
|
2324
|
+
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(24, 12)} ; ->data`);
|
|
2321
2325
|
B.line(`${bdata} = load ptr, ptr ${bdatap}`);
|
|
2322
2326
|
const bp = B.tmp();
|
|
2323
2327
|
const bv = B.tmp();
|
|
2324
2328
|
const bd = B.tmp();
|
|
2325
2329
|
const r1 = B.tmp();
|
|
2326
|
-
B.line(`${bp} = getelementptr inbounds i8, ptr ${bdata},
|
|
2330
|
+
B.line(`${bp} = getelementptr inbounds i8, ptr ${bdata}, ${host.sizeType} ${idx}`);
|
|
2327
2331
|
B.line(`${bv} = load i8, ptr ${bp}`);
|
|
2328
2332
|
B.line(`${bd} = uitofp i8 ${bv} to double`);
|
|
2329
2333
|
B.line(`${r1} = call ptr @scr_dyn_new_num(double ${bd})`);
|
|
@@ -2340,9 +2344,9 @@ export class LlDyn {
|
|
|
2340
2344
|
const lNext = B.newLabel("kg.n");
|
|
2341
2345
|
B.condBr(isF, lF, lNext);
|
|
2342
2346
|
B.startBlock(lF);
|
|
2343
|
-
host.declare(`declare ptr @scr_dyn_fn_get(ptr, ptr,
|
|
2347
|
+
host.declare(`declare ptr @scr_dyn_fn_get(ptr, ptr, ${host.sizeType})`);
|
|
2344
2348
|
const m = B.tmp();
|
|
2345
|
-
B.line(`${m} = call ptr @scr_dyn_fn_get(ptr %d, ptr ${kParts.data},
|
|
2349
|
+
B.line(`${m} = call ptr @scr_dyn_fn_get(ptr %d, ptr ${kParts.data}, ${host.sizeType} ${kParts.len})`);
|
|
2346
2350
|
const has = B.tmp();
|
|
2347
2351
|
B.line(`${has} = icmp ne ptr ${m}, null`);
|
|
2348
2352
|
const lHit = B.newLabel("kg.fh");
|
|
@@ -2380,7 +2384,7 @@ export class LlDyn {
|
|
|
2380
2384
|
const n = this.lenOf(B, "%d");
|
|
2381
2385
|
const nd = B.tmp();
|
|
2382
2386
|
const r = B.tmp();
|
|
2383
|
-
B.line(`${nd} = uitofp
|
|
2387
|
+
B.line(`${nd} = uitofp ${host.sizeType} ${n} to double`);
|
|
2384
2388
|
B.line(`${r} = call ptr @scr_dyn_new_num(double ${nd})`);
|
|
2385
2389
|
B.terminate(`ret ptr ${r}`);
|
|
2386
2390
|
B.startBlock(lStr);
|
|
@@ -2403,7 +2407,7 @@ export class LlDyn {
|
|
|
2403
2407
|
B.startBlock(lArr);
|
|
2404
2408
|
const n = this.lenOf(B, "%d");
|
|
2405
2409
|
const inR = B.tmp();
|
|
2406
|
-
B.line(`${inR} = icmp ult
|
|
2410
|
+
B.line(`${inR} = icmp ult ${host.sizeType} ${idx}, ${n}`);
|
|
2407
2411
|
const lHit = B.newLabel("kg.ah");
|
|
2408
2412
|
B.condBr(inR, lHit, lMiss);
|
|
2409
2413
|
B.startBlock(lHit);
|
|
@@ -2419,7 +2423,7 @@ export class LlDyn {
|
|
|
2419
2423
|
const n2 = B.tmp();
|
|
2420
2424
|
B.line(`${n2} = call double @scr_str_utf16_len(ptr ${s})`);
|
|
2421
2425
|
const idxD = B.tmp();
|
|
2422
|
-
B.line(`${idxD} = uitofp
|
|
2426
|
+
B.line(`${idxD} = uitofp ${host.sizeType} ${idx} to double`);
|
|
2423
2427
|
const inR2 = B.tmp();
|
|
2424
2428
|
B.line(`${inR2} = fcmp olt double ${idxD}, ${n2}`);
|
|
2425
2429
|
const lHit2 = B.newLabel("kg.ash");
|
|
@@ -2532,7 +2536,7 @@ export class LlDyn {
|
|
|
2532
2536
|
const materialized = B.tmp();
|
|
2533
2537
|
const out = B.tmp();
|
|
2534
2538
|
B.line(`${materialized} = call ptr @scr_dyn_typed_ref_materialize(ptr %d)`);
|
|
2535
|
-
B.line(`${out} = call ptr @${name}(ptr ${materialized},
|
|
2539
|
+
B.line(`${out} = call ptr @${name}(ptr ${materialized}, ${host.sizeType} %n)`);
|
|
2536
2540
|
B.line(`call void @scr_dyn_release_v(ptr ${materialized})`);
|
|
2537
2541
|
B.terminate(`ret ptr ${out}`);
|
|
2538
2542
|
B.startBlock(lNext);
|
|
@@ -2634,7 +2638,7 @@ export class LlDyn {
|
|
|
2634
2638
|
{
|
|
2635
2639
|
const n = this.lenOf(B, "%d");
|
|
2636
2640
|
const inR = B.tmp();
|
|
2637
|
-
B.line(`${inR} = icmp ult
|
|
2641
|
+
B.line(`${inR} = icmp ult ${host.sizeType} ${i}, ${n}`);
|
|
2638
2642
|
const lHit = B.newLabel("din.ah");
|
|
2639
2643
|
const lMiss = B.newLabel("din.am");
|
|
2640
2644
|
B.condBr(inR, lHit, lMiss);
|
|
@@ -2656,23 +2660,23 @@ export class LlDyn {
|
|
|
2656
2660
|
const bts = this.payloadOf(B, "%d", "ptr");
|
|
2657
2661
|
const blenp = B.tmp();
|
|
2658
2662
|
const blen = B.tmp();
|
|
2659
|
-
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 8 ; ->len`);
|
|
2660
|
-
B.line(`${blen} = load
|
|
2663
|
+
B.line(`${blenp} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(8, 4)} ; ->len`);
|
|
2664
|
+
B.line(`${blen} = load ${host.sizeType}, ptr ${blenp}`);
|
|
2661
2665
|
const inR = B.tmp();
|
|
2662
|
-
B.line(`${inR} = icmp ult
|
|
2666
|
+
B.line(`${inR} = icmp ult ${host.sizeType} ${i}, ${blen}`);
|
|
2663
2667
|
const lHit = B.newLabel("din.bh");
|
|
2664
2668
|
const lMiss = B.newLabel("din.bm");
|
|
2665
2669
|
B.condBr(inR, lHit, lMiss);
|
|
2666
2670
|
B.startBlock(lHit);
|
|
2667
2671
|
const bdatap = B.tmp();
|
|
2668
2672
|
const bdata = B.tmp();
|
|
2669
|
-
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 24 ; ->data`);
|
|
2673
|
+
B.line(`${bdatap} = getelementptr inbounds i8, ptr ${bts}, i64 ${this.abiOffset(24, 12)} ; ->data`);
|
|
2670
2674
|
B.line(`${bdata} = load ptr, ptr ${bdatap}`);
|
|
2671
2675
|
const bp = B.tmp();
|
|
2672
2676
|
const bv = B.tmp();
|
|
2673
2677
|
const bd = B.tmp();
|
|
2674
2678
|
const r = B.tmp();
|
|
2675
|
-
B.line(`${bp} = getelementptr inbounds i8, ptr ${bdata},
|
|
2679
|
+
B.line(`${bp} = getelementptr inbounds i8, ptr ${bdata}, ${host.sizeType} ${i}`);
|
|
2676
2680
|
B.line(`${bv} = load i8, ptr ${bp}`);
|
|
2677
2681
|
B.line(`${bd} = uitofp i8 ${bv} to double`);
|
|
2678
2682
|
B.line(`${r} = call ptr @scr_dyn_new_num(double ${bd})`);
|
|
@@ -2695,9 +2699,9 @@ export class LlDyn {
|
|
|
2695
2699
|
B.line(`${len} = call double @scr_str_utf16_len(ptr ${s})`);
|
|
2696
2700
|
const atSlot = B.slot();
|
|
2697
2701
|
const stepSlot = B.slot();
|
|
2698
|
-
B.entryAllocas.push(`${atSlot} = alloca double`, `${stepSlot} = alloca
|
|
2702
|
+
B.entryAllocas.push(`${atSlot} = alloca double`, `${stepSlot} = alloca ${host.sizeType}`);
|
|
2699
2703
|
B.line(`store double ${f64Lit(0)}, ptr ${atSlot}`);
|
|
2700
|
-
B.line(`store
|
|
2704
|
+
B.line(`store ${host.sizeType} 0, ptr ${stepSlot}`);
|
|
2701
2705
|
const lc = B.newLabel("din.sc");
|
|
2702
2706
|
const lb = B.newLabel("din.sb");
|
|
2703
2707
|
const le = B.newLabel("din.se");
|
|
@@ -2708,9 +2712,9 @@ export class LlDyn {
|
|
|
2708
2712
|
const c1 = B.tmp();
|
|
2709
2713
|
const c2 = B.tmp();
|
|
2710
2714
|
const cont = B.tmp();
|
|
2711
|
-
B.line(`${st} = load
|
|
2715
|
+
B.line(`${st} = load ${host.sizeType}, ptr ${stepSlot}`);
|
|
2712
2716
|
B.line(`${at} = load double, ptr ${atSlot}`);
|
|
2713
|
-
B.line(`${c1} = icmp ult
|
|
2717
|
+
B.line(`${c1} = icmp ult ${host.sizeType} ${st}, ${i}`);
|
|
2714
2718
|
B.line(`${c2} = fcmp olt double ${at}, ${len}`);
|
|
2715
2719
|
B.line(`${cont} = and i1 ${c1}, ${c2}`);
|
|
2716
2720
|
B.condBr(cont, lb, le);
|
|
@@ -2724,8 +2728,8 @@ export class LlDyn {
|
|
|
2724
2728
|
B.line(`store double ${at2}, ptr ${atSlot}`);
|
|
2725
2729
|
B.line(`call void @scr_str_release(ptr ${cp})`);
|
|
2726
2730
|
const st2 = B.tmp();
|
|
2727
|
-
B.line(`${st2} = add
|
|
2728
|
-
B.line(`store
|
|
2731
|
+
B.line(`${st2} = add ${host.sizeType} ${st}, 1`);
|
|
2732
|
+
B.line(`store ${host.sizeType} ${st2}, ptr ${stepSlot}`);
|
|
2729
2733
|
B.br(lc);
|
|
2730
2734
|
B.startBlock(le);
|
|
2731
2735
|
const atF = B.tmp();
|
|
@@ -2755,7 +2759,7 @@ export class LlDyn {
|
|
|
2755
2759
|
B.line(`call void @scr_dyn_arr_push(ptr ${out}, ptr ${item}) ; push takes ownership`);
|
|
2756
2760
|
});
|
|
2757
2761
|
B.terminate(`ret ptr ${out}`);
|
|
2758
|
-
this.defs.push(`define internal ptr @${name}(ptr %d,
|
|
2762
|
+
this.defs.push(`define internal ptr @${name}(ptr %d, ${host.sizeType} %n) ${FN_ATTRS} { ; destructuring GetIterator + N steps`, B.render(), `}`, ``);
|
|
2759
2763
|
return name;
|
|
2760
2764
|
}
|
|
2761
2765
|
/* ── the checked-dynamic function boundary (ported) ────────────────── */
|
|
@@ -2801,7 +2805,7 @@ export class LlDyn {
|
|
|
2801
2805
|
const adSlot = B.slot();
|
|
2802
2806
|
B.entryAllocas.push(`${adSlot} = alloca ptr`);
|
|
2803
2807
|
const has = B.tmp();
|
|
2804
|
-
B.line(`${has} = icmp ult
|
|
2808
|
+
B.line(`${has} = icmp ult ${host.sizeType} ${i}, %argc`);
|
|
2805
2809
|
const lHas = B.newLabel("dfk.h");
|
|
2806
2810
|
const lMiss = B.newLabel("dfk.m");
|
|
2807
2811
|
const lj = B.newLabel("dfk.j");
|
|
@@ -2809,7 +2813,7 @@ export class LlDyn {
|
|
|
2809
2813
|
B.startBlock(lHas);
|
|
2810
2814
|
const ap = B.tmp();
|
|
2811
2815
|
const av = B.tmp();
|
|
2812
|
-
B.line(`${ap} = getelementptr inbounds ptr, ptr %args,
|
|
2816
|
+
B.line(`${ap} = getelementptr inbounds ptr, ptr %args, ${host.sizeType} ${i}`);
|
|
2813
2817
|
B.line(`${av} = load ptr, ptr ${ap}`);
|
|
2814
2818
|
B.line(`store ptr ${av}, ptr ${adSlot}`);
|
|
2815
2819
|
B.br(lj);
|
|
@@ -2856,7 +2860,7 @@ export class LlDyn {
|
|
|
2856
2860
|
B.line(`${kp2} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 1`);
|
|
2857
2861
|
B.line(`store ptr null, ptr ${kp2}`);
|
|
2858
2862
|
B.line(`${ip} = getelementptr inbounds %ScrDynPath, ptr ${pathSlot}, i64 0, i32 2`);
|
|
2859
|
-
B.line(`store
|
|
2863
|
+
B.line(`store ${host.sizeType} ${i}, ptr ${ip}`);
|
|
2860
2864
|
const a = B.tmp();
|
|
2861
2865
|
B.line(`${a} = call ${this.valTy(p)} @${this.dynCheckHelper(p)}(ptr ${ad}, ptr ${pathSlot})`);
|
|
2862
2866
|
this.pendingBail(B, "dfk", () => {
|
|
@@ -2877,8 +2881,8 @@ export class LlDyn {
|
|
|
2877
2881
|
rest = B.tmp();
|
|
2878
2882
|
B.line(`${rest} = call ptr @scr_dyn_new_arr()`);
|
|
2879
2883
|
const riSlot = B.slot();
|
|
2880
|
-
B.entryAllocas.push(`${riSlot} = alloca
|
|
2881
|
-
B.line(`store
|
|
2884
|
+
B.entryAllocas.push(`${riSlot} = alloca ${host.sizeType}`);
|
|
2885
|
+
B.line(`store ${host.sizeType} ${t.params.length}, ptr ${riSlot}`);
|
|
2882
2886
|
const lc = B.newLabel("dfk.rc");
|
|
2883
2887
|
const lb = B.newLabel("dfk.rb");
|
|
2884
2888
|
const le = B.newLabel("dfk.re");
|
|
@@ -2886,19 +2890,19 @@ export class LlDyn {
|
|
|
2886
2890
|
B.startBlock(lc);
|
|
2887
2891
|
const ri = B.tmp();
|
|
2888
2892
|
const cont = B.tmp();
|
|
2889
|
-
B.line(`${ri} = load
|
|
2890
|
-
B.line(`${cont} = icmp ult
|
|
2893
|
+
B.line(`${ri} = load ${host.sizeType}, ptr ${riSlot}`);
|
|
2894
|
+
B.line(`${cont} = icmp ult ${host.sizeType} ${ri}, %argc`);
|
|
2891
2895
|
B.condBr(cont, lb, le);
|
|
2892
2896
|
B.startBlock(lb);
|
|
2893
2897
|
const ap = B.tmp();
|
|
2894
2898
|
const av = B.tmp();
|
|
2895
|
-
B.line(`${ap} = getelementptr inbounds ptr, ptr %args,
|
|
2899
|
+
B.line(`${ap} = getelementptr inbounds ptr, ptr %args, ${host.sizeType} ${ri}`);
|
|
2896
2900
|
B.line(`${av} = load ptr, ptr ${ap}`);
|
|
2897
2901
|
const rv = this.retainDyn(B, av);
|
|
2898
2902
|
B.line(`call void @scr_dyn_arr_push(ptr ${rest}, ptr ${rv})`);
|
|
2899
2903
|
const ri2 = B.tmp();
|
|
2900
|
-
B.line(`${ri2} = add
|
|
2901
|
-
B.line(`store
|
|
2904
|
+
B.line(`${ri2} = add ${host.sizeType} ${ri}, 1`);
|
|
2905
|
+
B.line(`store ${host.sizeType} ${ri2}, ptr ${riSlot}`);
|
|
2902
2906
|
B.br(lc);
|
|
2903
2907
|
B.startBlock(le);
|
|
2904
2908
|
}
|
|
@@ -2935,7 +2939,7 @@ export class LlDyn {
|
|
|
2935
2939
|
B.line(`call void ${releaseSym(host, t.ret)}(ptr ${r})`);
|
|
2936
2940
|
B.terminate(`ret ptr ${out}`);
|
|
2937
2941
|
}
|
|
2938
|
-
this.defs.push(`define internal ptr @${name}(ptr %c, ptr %args,
|
|
2942
|
+
this.defs.push(`define internal ptr @${name}(ptr %c, ptr %args, ${host.sizeType} %argc) ${FN_ATTRS} { ; dyn call thunk for ${key}`, B.render(), `}`, ``);
|
|
2939
2943
|
return name;
|
|
2940
2944
|
}
|
|
2941
2945
|
/** The box builder dynFrom emits for one closure signature. */
|
|
@@ -2966,13 +2970,13 @@ export class LlDyn {
|
|
|
2966
2970
|
const host = this.host;
|
|
2967
2971
|
const B = new BlockBuilder();
|
|
2968
2972
|
host.declare(`declare ptr @scr_box_get_ref(ptr)`);
|
|
2969
|
-
host.declare(`declare ptr @scr_dyn_call(ptr, ptr,
|
|
2973
|
+
host.declare(`declare ptr @scr_dyn_call(ptr, ptr, ${host.sizeType}, ptr)`);
|
|
2970
2974
|
host.declare(`declare void @scr_dyn_release(ptr)`);
|
|
2971
2975
|
const retTy = t.ret.kind === "void" ? "void" : this.valTy(t.ret);
|
|
2972
2976
|
const dummy = t.ret.kind === "void" ? "void" : retTy === "double" ? `double ${f64Lit(0)}` : retTy === "i1" ? "i1 false" : "ptr null";
|
|
2973
2977
|
const capp = B.tmp();
|
|
2974
2978
|
const box = B.tmp();
|
|
2975
|
-
B.line(`${capp} = getelementptr inbounds
|
|
2979
|
+
B.line(`${capp} = getelementptr inbounds %ScrClosure, ptr %sc_env, i64 1 ; caps[0]`);
|
|
2976
2980
|
B.line(`${box} = load ptr, ptr ${capp}`);
|
|
2977
2981
|
const fnv = B.tmp();
|
|
2978
2982
|
B.line(`${fnv} = call ptr @scr_box_get_ref(ptr ${box}) ; +1`);
|
|
@@ -2987,7 +2991,7 @@ export class LlDyn {
|
|
|
2987
2991
|
const v = this.toDynExpr(B, p, `%a${i}`);
|
|
2988
2992
|
argVals.push(v);
|
|
2989
2993
|
const slotp = B.tmp();
|
|
2990
|
-
B.line(`${slotp} = getelementptr inbounds [${t.params.length} x ptr], ptr ${arr}, i64 0,
|
|
2994
|
+
B.line(`${slotp} = getelementptr inbounds [${t.params.length} x ptr], ptr ${arr}, i64 0, ${host.sizeType} ${i}`);
|
|
2991
2995
|
B.line(`store ptr ${v}, ptr ${slotp}`);
|
|
2992
2996
|
if (isRefCounted(p))
|
|
2993
2997
|
B.line(`call void ${releaseSym(host, p)}(ptr %a${i})`);
|
|
@@ -2997,7 +3001,7 @@ export class LlDyn {
|
|
|
2997
3001
|
// The kind is FUNC by construction; `what` is unreachable — spelled
|
|
2998
3002
|
// anyway (the C's "value").
|
|
2999
3003
|
const r = B.tmp();
|
|
3000
|
-
B.line(`${r} = call ptr @scr_dyn_call(ptr ${fnv}, ptr ${argsPtr},
|
|
3004
|
+
B.line(`${r} = call ptr @scr_dyn_call(ptr ${fnv}, ptr ${argsPtr}, ${host.sizeType} ${t.params.length}, ptr ${host.cstr("value")})`);
|
|
3001
3005
|
B.line(`call void @scr_dyn_release(ptr ${fnv})`);
|
|
3002
3006
|
for (const v of argVals)
|
|
3003
3007
|
B.line(`call void @scr_dyn_release(ptr ${v})`);
|