@scriptc/compiler 0.0.17 → 0.0.19
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 +4 -4
- package/dist/backend/cc.d.ts +5 -0
- package/dist/backend/cc.js +2 -0
- package/dist/backend/cc.js.map +1 -1
- package/dist/backend/emission/emit-async.js +35 -2
- package/dist/backend/emission/emit-async.js.map +1 -1
- package/dist/backend/emission/emit-exprs.js +40 -4
- package/dist/backend/emission/emit-exprs.js.map +1 -1
- package/dist/backend/emission/emitter.js +69 -11
- package/dist/backend/emission/emitter.js.map +1 -1
- package/dist/backend/emission/may-throw.d.ts +3 -3
- package/dist/backend/emission/may-throw.js +15 -4
- package/dist/backend/emission/may-throw.js.map +1 -1
- package/dist/backend/llvm/emitter.js +199 -21
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/frontend/lib-contract.d.ts +1 -0
- package/dist/frontend/lib-contract.js +2 -2
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.js +4 -7
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.js +17 -9
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +22 -17
- package/dist/frontend/lowering/lower-containers.js +628 -51
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.js +19 -1
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-island.js +55 -7
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.js +144 -10
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +8 -0
- package/dist/frontend/lowering/lower-stmts.js +408 -21
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +38 -0
- package/dist/frontend/lowering/lowerer.js +149 -2
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/surfaces.js +4 -0
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/index.js +97 -21
- package/dist/index.js.map +1 -1
- package/dist/ir/nodes.d.ts +46 -12
- package/dist/ir/nodes.js +41 -0
- package/dist/ir/nodes.js.map +1 -1
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +1 -1
- package/dist/ir/validate.js +98 -39
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/int-infer.d.ts +6 -1
- package/dist/library/int-infer.js +306 -53
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/int-infer.test.js +271 -1
- package/dist/library/int-infer.test.js.map +1 -1
- package/dist/library/profile.d.ts +6 -5
- package/dist/library/profile.js.map +1 -1
- package/dist/library/sidecar-validate.js +4 -1
- package/dist/library/sidecar-validate.js.map +1 -1
- package/dist/library/sidecar.d.ts +32 -4
- package/dist/library/sidecar.js +264 -47
- package/dist/library/sidecar.js.map +1 -1
- package/package.json +2 -2
- package/surface-manifest.json +25 -1
package/dist/ir/validate.js
CHANGED
|
@@ -1441,6 +1441,36 @@ export function validateModule(mod) {
|
|
|
1441
1441
|
function validateFunction(fn, functions, ffiByName, classes, records, unions, globals, errors) {
|
|
1442
1442
|
const locals = new Map(fn.locals.map((l) => [l.id, l]));
|
|
1443
1443
|
const err = (message, loc) => errors.push({ message: `in ${fn.name}: ${message}`, loc });
|
|
1444
|
+
const asyncCaches = [
|
|
1445
|
+
["asyncCacheGlobal", fn.asyncCacheGlobal],
|
|
1446
|
+
["asyncCycleCacheGlobal", fn.asyncCycleCacheGlobal],
|
|
1447
|
+
];
|
|
1448
|
+
for (const [field, cacheId] of asyncCaches) {
|
|
1449
|
+
if (cacheId === undefined)
|
|
1450
|
+
continue;
|
|
1451
|
+
if (fn.async !== true) {
|
|
1452
|
+
err(`an ${field} is only valid on an async function`, fn.loc);
|
|
1453
|
+
}
|
|
1454
|
+
if (fn.params.length !== 0 || (fn.captures?.length ?? 0) !== 0) {
|
|
1455
|
+
err("a cached async function must have no parameters or captures", fn.loc);
|
|
1456
|
+
}
|
|
1457
|
+
const cache = globals.get(cacheId);
|
|
1458
|
+
if (cache === undefined) {
|
|
1459
|
+
err(`async cache names undeclared global "${cacheId}"`, fn.loc);
|
|
1460
|
+
}
|
|
1461
|
+
else {
|
|
1462
|
+
const expected = { kind: "promise", inner: fn.returnType };
|
|
1463
|
+
if (!typeEquals(cache.type, expected)) {
|
|
1464
|
+
err(`async cache global "${cacheId}" has type ${typeKey(cache.type)}, expected ${typeKey(expected)}`, fn.loc);
|
|
1465
|
+
}
|
|
1466
|
+
if (!cache.mutable) {
|
|
1467
|
+
err(`async cache global "${cacheId}" is immutable`, fn.loc);
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
if (fn.asyncCycleCacheGlobal !== undefined && fn.asyncCacheGlobal === undefined) {
|
|
1472
|
+
err("an asyncCycleCacheGlobal requires a module asyncCacheGlobal", fn.loc);
|
|
1473
|
+
}
|
|
1444
1474
|
// The class graph's two questions (upcast/downcast/instanceOf/virtualCall
|
|
1445
1475
|
// legality): strict-descendant tests over the base links, and hierarchy
|
|
1446
1476
|
// membership (a class that extends or is extended).
|
|
@@ -2178,35 +2208,43 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
|
|
|
2178
2208
|
? { argTypes: [F64], minArgs: 1, result: F64 }
|
|
2179
2209
|
: e.method === "slice" || e.method === "subarray"
|
|
2180
2210
|
? { argTypes: [F64, F64], minArgs: 0, result: bytesOf(recv.elem) }
|
|
2181
|
-
: e.method === "
|
|
2182
|
-
? { argTypes: [
|
|
2183
|
-
: e.method === "
|
|
2184
|
-
? { argTypes: [
|
|
2185
|
-
: e.method === "
|
|
2186
|
-
? { argTypes: [STRING
|
|
2187
|
-
: e.method === "
|
|
2188
|
-
? { argTypes: [
|
|
2189
|
-
: e.method === "
|
|
2190
|
-
? { argTypes: [
|
|
2191
|
-
: e.method === "
|
|
2192
|
-
? { argTypes: [STRING, F64, F64
|
|
2193
|
-
: e.method === "
|
|
2194
|
-
? { argTypes: [
|
|
2195
|
-
: e.method
|
|
2196
|
-
? {
|
|
2197
|
-
|
|
2198
|
-
argTypes:
|
|
2199
|
-
|
|
2200
|
-
: [F64, F64,
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2211
|
+
: e.method === "toReversed"
|
|
2212
|
+
? { argTypes: [], minArgs: 0, result: bytesOf(recv.elem) }
|
|
2213
|
+
: e.method === "with"
|
|
2214
|
+
? { argTypes: [F64, F64], minArgs: 2, result: bytesOf(recv.elem) }
|
|
2215
|
+
: e.method === "join"
|
|
2216
|
+
? { argTypes: [STRING], minArgs: 1, result: STRING }
|
|
2217
|
+
: e.method === "toArray"
|
|
2218
|
+
? { argTypes: [], minArgs: 0, result: arrayOf(F64) }
|
|
2219
|
+
: e.method === "setFrom"
|
|
2220
|
+
? { argTypes: [bytesOf(recv.elem), F64], minArgs: 1, result: VOID }
|
|
2221
|
+
: e.method === "toString"
|
|
2222
|
+
? { argTypes: [STRING, F64, F64], minArgs: 1, result: STRING }
|
|
2223
|
+
: e.method === "readNum"
|
|
2224
|
+
? { argTypes: [STRING, F64], minArgs: 2, result: F64 }
|
|
2225
|
+
: e.method === "writeNum"
|
|
2226
|
+
? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
|
|
2227
|
+
: e.method === "readNumVar"
|
|
2228
|
+
? { argTypes: [STRING, F64, F64], minArgs: 3, result: F64 }
|
|
2229
|
+
: e.method === "writeNumVar"
|
|
2230
|
+
? { argTypes: [STRING, F64, F64, F64], minArgs: 4, result: F64 }
|
|
2231
|
+
: e.method === "dataViewNew"
|
|
2232
|
+
? { argTypes: [F64, F64], minArgs: 0, result: BYTES_U8 }
|
|
2233
|
+
: e.method.startsWith("dvSet")
|
|
2234
|
+
? {
|
|
2235
|
+
// dvSet*: [offset, value], the 8-bit setters take no littleEndian.
|
|
2236
|
+
argTypes: e.method === "dvSetUint8" || e.method === "dvSetInt8"
|
|
2237
|
+
? [F64, F64]
|
|
2238
|
+
: [F64, F64, BOOL],
|
|
2239
|
+
minArgs: 2,
|
|
2240
|
+
result: VOID,
|
|
2241
|
+
}
|
|
2242
|
+
: {
|
|
2243
|
+
// dvGet*: the 8-bit getters take no littleEndian.
|
|
2244
|
+
argTypes: e.method === "dvGetUint8" || e.method === "dvGetInt8" ? [F64] : [F64, BOOL],
|
|
2245
|
+
minArgs: 1,
|
|
2246
|
+
result: F64,
|
|
2247
|
+
});
|
|
2210
2248
|
if (e.args.length < sig.minArgs || e.args.length > sig.argTypes.length) {
|
|
2211
2249
|
err(`bytesIntrinsic ${e.method}: ${e.args.length} args`, e.loc);
|
|
2212
2250
|
}
|
|
@@ -2242,11 +2280,17 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
|
|
|
2242
2280
|
? { argTypes: [STRING], result: STRING }
|
|
2243
2281
|
: e.method === "slice"
|
|
2244
2282
|
? { argTypes: [F64, F64], result: e.receiver.type }
|
|
2245
|
-
: e.method === "
|
|
2246
|
-
? { argTypes: [
|
|
2247
|
-
: e.method === "
|
|
2248
|
-
? { argTypes: [], result: e.type }
|
|
2249
|
-
:
|
|
2283
|
+
: e.method === "toReversed"
|
|
2284
|
+
? { argTypes: [], result: e.receiver.type }
|
|
2285
|
+
: e.method === "toSpliced"
|
|
2286
|
+
? { argTypes: [F64, F64, e.receiver.type], result: e.receiver.type }
|
|
2287
|
+
: e.method === "with"
|
|
2288
|
+
? { argTypes: [F64, elem], result: e.receiver.type }
|
|
2289
|
+
: e.method === "splice"
|
|
2290
|
+
? { argTypes: [F64, F64], result: e.receiver.type }
|
|
2291
|
+
: e.method === "shift"
|
|
2292
|
+
? { argTypes: [], result: e.type } // union-checked below
|
|
2293
|
+
: { argTypes: [], result: F64 }; // length
|
|
2250
2294
|
if (e.method === "join" &&
|
|
2251
2295
|
elem.kind !== "f64" && elem.kind !== "string" && elem.kind !== "bool" &&
|
|
2252
2296
|
!(elem.kind === "union" &&
|
|
@@ -3262,6 +3306,19 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
|
|
|
3262
3306
|
break;
|
|
3263
3307
|
}
|
|
3264
3308
|
case "intrinsic":
|
|
3309
|
+
if (e.name === "module.await") {
|
|
3310
|
+
if (e.args.length !== 1)
|
|
3311
|
+
err("module.await takes exactly one argument", e.loc);
|
|
3312
|
+
for (const a of e.args) {
|
|
3313
|
+
checkExpr(a);
|
|
3314
|
+
if (a.type.kind !== "promise" || a.type.inner.kind !== "void") {
|
|
3315
|
+
err(`${typeKey(a.type)} argument to module.await (needs promise<void>)`, a.loc);
|
|
3316
|
+
}
|
|
3317
|
+
}
|
|
3318
|
+
if (e.type.kind !== "void")
|
|
3319
|
+
err("module.await must be void", e.loc);
|
|
3320
|
+
break;
|
|
3321
|
+
}
|
|
3265
3322
|
if (e.name === "promise.all") {
|
|
3266
3323
|
// ONE argument: an array of promises whose inner type is the
|
|
3267
3324
|
// result's array element (or void, collapsing to promise<void>).
|
|
@@ -3528,15 +3585,17 @@ function validateFunction(fn, functions, ffiByName, classes, records, unions, gl
|
|
|
3528
3585
|
}
|
|
3529
3586
|
break;
|
|
3530
3587
|
}
|
|
3531
|
-
if (e.fn === "http.requestCb" || e.fn === "
|
|
3588
|
+
if (e.fn === "http.requestCb" || e.fn === "https.requestCb" ||
|
|
3589
|
+
e.fn === "http.requestUrlCb" || e.fn === "http.clientOnResponse" ||
|
|
3532
3590
|
e.fn === "http.requestAgentCb" || e.fn === "https.requestAgentCb" ||
|
|
3533
3591
|
e.fn === "https.requestUrlCb") {
|
|
3534
3592
|
// The response listener: void, no params or exactly (res: httpReq).
|
|
3535
3593
|
const cbT = e.args[e.fn === "http.requestCb" ? 7
|
|
3536
|
-
: e.fn === "
|
|
3537
|
-
: e.fn === "http.
|
|
3538
|
-
: e.fn === "
|
|
3539
|
-
:
|
|
3594
|
+
: e.fn === "https.requestCb" ? 9
|
|
3595
|
+
: e.fn === "http.requestUrlCb" || e.fn === "https.requestUrlCb" ? 3
|
|
3596
|
+
: e.fn === "http.requestAgentCb" ? 8
|
|
3597
|
+
: e.fn === "https.requestAgentCb" ? 10
|
|
3598
|
+
: 1]?.type;
|
|
3540
3599
|
let ok = cbT?.kind === "func" && cbT.ret.kind === "void" && cbT.params.length <= 1;
|
|
3541
3600
|
if (ok && cbT?.kind === "func" && cbT.params.length === 1) {
|
|
3542
3601
|
ok = cbT.params[0].kind === "httpReq";
|