@scriptc/compiler 0.0.34 → 0.0.36
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 +7 -6
- package/dist/backend/build-cache.d.ts +44 -0
- package/dist/backend/build-cache.js +241 -0
- package/dist/backend/build-cache.js.map +1 -0
- package/dist/backend/{emission/emit-async.d.ts → c/async.d.ts} +21 -30
- package/dist/backend/{emission/emit-async.js → c/async.js} +270 -286
- package/dist/backend/c/async.js.map +1 -0
- package/dist/backend/{emission/emitter.d.ts → c/c-emitter.d.ts} +6 -23
- package/dist/backend/{emission/emitter.js → c/c-emitter.js} +53 -107
- package/dist/backend/c/c-emitter.js.map +1 -0
- package/dist/backend/c/exprs.d.ts +8 -0
- package/dist/backend/c/exprs.js +7913 -0
- package/dist/backend/c/exprs.js.map +1 -0
- package/dist/backend/{emission/emit-island.d.ts → c/island.d.ts} +5 -5
- package/dist/backend/{emission/emit-island.js → c/island.js} +24 -22
- package/dist/backend/c/island.js.map +1 -0
- package/dist/backend/{emission → c}/may-throw.d.ts +1 -1
- package/dist/backend/{emission → c}/may-throw.js +1 -1
- package/dist/backend/c/may-throw.js.map +1 -0
- package/dist/backend/{emission/emit-shapes.d.ts → c/shapes.d.ts} +19 -19
- package/dist/backend/{emission/emit-shapes.js → c/shapes.js} +78 -87
- package/dist/backend/c/shapes.js.map +1 -0
- package/dist/backend/{emission/emit-stmts.d.ts → c/stmts.d.ts} +12 -12
- package/dist/backend/{emission/emit-stmts.js → c/stmts.js} +377 -343
- package/dist/backend/c/stmts.js.map +1 -0
- package/dist/backend/{emission/emit-types.d.ts → c/types.d.ts} +1 -1
- package/dist/backend/{emission/emit-types.js → c/types.js} +42 -286
- package/dist/backend/c/types.js.map +1 -0
- package/dist/backend/c/types.test.js +25 -0
- package/dist/backend/c/types.test.js.map +1 -0
- package/dist/backend/{emission/emit-walkers.d.ts → c/walkers.d.ts} +19 -41
- package/dist/backend/{emission/emit-walkers.js → c/walkers.js} +238 -298
- package/dist/backend/c/walkers.js.map +1 -0
- package/dist/backend/ffi-callbacks.d.ts +1 -1
- package/dist/backend/ffi-callbacks.js +4 -3
- package/dist/backend/ffi-callbacks.js.map +1 -1
- package/dist/backend/{library-identity.d.ts → library-identity-markers.d.ts} +0 -4
- package/dist/backend/{library-identity.js → library-identity-markers.js} +10 -9
- package/dist/backend/library-identity-markers.js.map +1 -0
- package/dist/backend/llvm/blocks.d.ts +4 -0
- package/dist/backend/llvm/blocks.js +29 -0
- package/dist/backend/llvm/blocks.js.map +1 -1
- package/dist/backend/llvm/classes.d.ts +2 -19
- package/dist/backend/llvm/classes.js +20 -52
- package/dist/backend/llvm/classes.js.map +1 -1
- package/dist/backend/llvm/common.d.ts +4 -0
- package/dist/backend/llvm/common.js +27 -0
- package/dist/backend/llvm/common.js.map +1 -0
- package/dist/backend/llvm/dyn.d.ts +3 -8
- package/dist/backend/llvm/dyn.js +152 -224
- package/dist/backend/llvm/dyn.js.map +1 -1
- package/dist/backend/llvm/emitter.d.ts +4 -1
- package/dist/backend/llvm/emitter.js +514 -9981
- package/dist/backend/llvm/emitter.js.map +1 -1
- package/dist/backend/llvm/expr-async.d.ts +4 -0
- package/dist/backend/llvm/expr-async.js +726 -0
- package/dist/backend/llvm/expr-async.js.map +1 -0
- package/dist/backend/llvm/expr-bytes.d.ts +13 -0
- package/dist/backend/llvm/expr-bytes.js +456 -0
- package/dist/backend/llvm/expr-bytes.js.map +1 -0
- package/dist/backend/llvm/expr-callbacks.d.ts +22 -0
- package/dist/backend/llvm/expr-callbacks.js +520 -0
- package/dist/backend/llvm/expr-callbacks.js.map +1 -0
- package/dist/backend/llvm/expr-calls.d.ts +2 -0
- package/dist/backend/llvm/expr-calls.js +618 -0
- package/dist/backend/llvm/expr-calls.js.map +1 -0
- package/dist/backend/llvm/expr-containers.d.ts +25 -0
- package/dist/backend/llvm/expr-containers.js +623 -0
- package/dist/backend/llvm/expr-containers.js.map +1 -0
- package/dist/backend/llvm/expr-context.d.ts +255 -0
- package/dist/backend/llvm/expr-context.js +2 -0
- package/dist/backend/llvm/expr-context.js.map +1 -0
- package/dist/backend/llvm/expr-control.d.ts +2 -0
- package/dist/backend/llvm/expr-control.js +473 -0
- package/dist/backend/llvm/expr-control.js.map +1 -0
- package/dist/backend/llvm/expr-dispatch.d.ts +4 -0
- package/dist/backend/llvm/expr-dispatch.js +151 -0
- package/dist/backend/llvm/expr-dispatch.js.map +1 -0
- package/dist/backend/llvm/expr-dynamic.d.ts +2 -0
- package/dist/backend/llvm/expr-dynamic.js +810 -0
- package/dist/backend/llvm/expr-dynamic.js.map +1 -0
- package/dist/backend/llvm/expr-island.d.ts +15 -0
- package/dist/backend/llvm/expr-island.js +690 -0
- package/dist/backend/llvm/expr-island.js.map +1 -0
- package/dist/backend/llvm/expr-primitives.d.ts +6 -0
- package/dist/backend/llvm/expr-primitives.js +622 -0
- package/dist/backend/llvm/expr-primitives.js.map +1 -0
- package/dist/backend/llvm/expr-records.d.ts +9 -0
- package/dist/backend/llvm/expr-records.js +299 -0
- package/dist/backend/llvm/expr-records.js.map +1 -0
- package/dist/backend/llvm/expr-stream-bridges.d.ts +13 -0
- package/dist/backend/llvm/expr-stream-bridges.js +396 -0
- package/dist/backend/llvm/expr-stream-bridges.js.map +1 -0
- package/dist/backend/llvm/expr-stream-callbacks.d.ts +12 -0
- package/dist/backend/llvm/expr-stream-callbacks.js +360 -0
- package/dist/backend/llvm/expr-stream-callbacks.js.map +1 -0
- package/dist/backend/llvm/lib-dispatch.d.ts +5 -0
- package/dist/backend/llvm/lib-dispatch.js +267 -0
- package/dist/backend/llvm/lib-dispatch.js.map +1 -0
- package/dist/backend/llvm/lib-filesystem.d.ts +6 -0
- package/dist/backend/llvm/lib-filesystem.js +594 -0
- package/dist/backend/llvm/lib-filesystem.js.map +1 -0
- package/dist/backend/llvm/lib-network.d.ts +2 -0
- package/dist/backend/llvm/lib-network.js +429 -0
- package/dist/backend/llvm/lib-network.js.map +1 -0
- package/dist/backend/llvm/lib-process.d.ts +5 -0
- package/dist/backend/llvm/lib-process.js +585 -0
- package/dist/backend/llvm/lib-process.js.map +1 -0
- package/dist/backend/llvm/lib-shared.d.ts +6 -0
- package/dist/backend/llvm/lib-shared.js +687 -0
- package/dist/backend/llvm/lib-shared.js.map +1 -0
- package/dist/backend/llvm/lib-stream.d.ts +2 -0
- package/dist/backend/llvm/lib-stream.js +470 -0
- package/dist/backend/llvm/lib-stream.js.map +1 -0
- package/dist/backend/llvm/shapes.d.ts +12 -2
- package/dist/backend/llvm/shapes.js +66 -307
- package/dist/backend/llvm/shapes.js.map +1 -1
- package/dist/backend/llvm/shapes.test.js +52 -0
- package/dist/backend/llvm/shapes.test.js.map +1 -0
- package/dist/backend/llvm/split.d.ts +43 -0
- package/dist/backend/llvm/split.js +227 -0
- package/dist/backend/llvm/split.js.map +1 -0
- package/dist/backend/llvm/split.test.d.ts +1 -0
- package/dist/backend/llvm/split.test.js +102 -0
- package/dist/backend/llvm/split.test.js.map +1 -0
- package/dist/backend/llvm/unsupported.d.ts +1 -1
- package/dist/backend/llvm/walkers.d.ts +2 -3
- package/dist/backend/llvm/walkers.js +164 -218
- package/dist/backend/llvm/walkers.js.map +1 -1
- package/dist/backend/native-codegen.d.ts +38 -0
- package/dist/backend/native-codegen.js +261 -0
- package/dist/backend/native-codegen.js.map +1 -0
- package/dist/backend/native-codegen.test.d.ts +1 -0
- package/dist/backend/native-codegen.test.js +188 -0
- package/dist/backend/native-codegen.test.js.map +1 -0
- package/dist/backend/native-link-info.d.ts +96 -0
- package/dist/backend/native-link-info.js +219 -0
- package/dist/backend/native-link-info.js.map +1 -0
- package/dist/backend/native-link-info.test.d.ts +1 -0
- package/dist/backend/native-link-info.test.js +134 -0
- package/dist/backend/native-link-info.test.js.map +1 -0
- package/dist/backend/{cc.d.ts → native-toolchain.d.ts} +139 -47
- package/dist/backend/{cc.js → native-toolchain.js} +1008 -910
- package/dist/backend/native-toolchain.js.map +1 -0
- package/dist/backend/native-toolchain.test.d.ts +1 -0
- package/dist/backend/{cc-cache.test.js → native-toolchain.test.js} +1297 -127
- package/dist/backend/native-toolchain.test.js.map +1 -0
- package/dist/backend/object-localize.js +1 -1
- package/dist/backend/object-localize.test.js +20 -0
- package/dist/backend/object-localize.test.js.map +1 -1
- package/dist/backend/runtime-abi.d.ts +10 -0
- package/dist/backend/runtime-abi.js +11 -0
- package/dist/backend/runtime-abi.js.map +1 -0
- package/dist/backend/runtime-pack.d.ts +137 -0
- package/dist/backend/runtime-pack.js +400 -0
- package/dist/backend/runtime-pack.js.map +1 -0
- package/dist/backend/runtime-pack.test.d.ts +1 -0
- package/dist/backend/runtime-pack.test.js +438 -0
- package/dist/backend/runtime-pack.test.js.map +1 -0
- package/dist/backend/targets.d.ts +30 -0
- package/dist/backend/targets.js +46 -0
- package/dist/backend/targets.js.map +1 -0
- package/dist/backend/targets.test.d.ts +1 -0
- package/dist/backend/targets.test.js +19 -0
- package/dist/backend/targets.test.js.map +1 -0
- package/dist/backend/vendor-archives.d.ts +41 -0
- package/dist/backend/vendor-archives.js +462 -0
- package/dist/backend/vendor-archives.js.map +1 -0
- package/dist/compat/fetch-profile.d.ts +0 -1
- package/dist/compat/fetch-profile.js +0 -1
- package/dist/compat/fetch-profile.js.map +1 -1
- package/dist/coverage/report.js +3 -3
- package/dist/coverage/report.js.map +1 -1
- package/dist/coverage/surface-manifest.js +25 -32
- package/dist/coverage/surface-manifest.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +11 -12
- package/dist/diagnostics/diagnostic.js +19 -17
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/diagnostics/render.d.ts +1 -1
- package/dist/diagnostics/render.js +1 -1
- package/dist/diagnostics/render.js.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +9 -0
- package/dist/errors.js.map +1 -0
- package/dist/executable/executable-cache.d.ts +86 -0
- package/dist/executable/executable-cache.js +398 -0
- package/dist/executable/executable-cache.js.map +1 -0
- package/dist/executable/executable-cache.test.d.ts +1 -0
- package/dist/executable/executable-cache.test.js +300 -0
- package/dist/executable/executable-cache.test.js.map +1 -0
- package/dist/ffi/{profile.d.ts → ffi-manifest.d.ts} +7 -2
- package/dist/ffi/{profile.js → ffi-manifest.js} +2 -1
- package/dist/ffi/ffi-manifest.js.map +1 -0
- package/dist/frontend/builtin-modules.d.ts +21 -0
- package/dist/frontend/builtin-modules.js +82 -0
- package/dist/frontend/builtin-modules.js.map +1 -0
- package/dist/frontend/cjs-lexer.d.ts +7 -0
- package/dist/frontend/cjs-lexer.js +15 -17
- package/dist/frontend/cjs-lexer.js.map +1 -1
- package/dist/frontend/dts-paths.d.ts +26 -0
- package/dist/frontend/dts-paths.js +41 -0
- package/dist/frontend/dts-paths.js.map +1 -0
- package/dist/frontend/input-tracker.d.ts +0 -2
- package/dist/frontend/input-tracker.js +1 -4
- package/dist/frontend/input-tracker.js.map +1 -1
- package/dist/frontend/lib-contract.d.ts +1 -5
- package/dist/frontend/lib-contract.js +1 -1
- package/dist/frontend/lib-contract.js.map +1 -1
- package/dist/frontend/lib-exports.d.ts +1 -1
- package/dist/frontend/lowering/call-position.d.ts +4 -0
- package/dist/frontend/lowering/call-position.js +7 -0
- package/dist/frontend/lowering/call-position.js.map +1 -0
- package/dist/frontend/lowering/callback-arg.d.ts +20 -0
- package/dist/frontend/lowering/callback-arg.js +44 -0
- package/dist/frontend/lowering/callback-arg.js.map +1 -0
- package/dist/frontend/lowering/lib-boundary.d.ts +1 -1
- package/dist/frontend/lowering/lib-boundary.js +34 -34
- package/dist/frontend/lowering/lib-boundary.js.map +1 -1
- package/dist/frontend/lowering/lower-assert.d.ts +3 -3
- package/dist/frontend/lowering/lower-assert.js +214 -241
- package/dist/frontend/lowering/lower-assert.js.map +1 -1
- package/dist/frontend/lowering/lower-builtins.d.ts +74 -146
- package/dist/frontend/lowering/lower-builtins.js +1126 -1234
- package/dist/frontend/lowering/lower-builtins.js.map +1 -1
- package/dist/frontend/lowering/lower-calls.d.ts +56 -188
- package/dist/frontend/lowering/lower-calls.js +1409 -1494
- package/dist/frontend/lowering/lower-calls.js.map +1 -1
- package/dist/frontend/lowering/lower-classes.d.ts +62 -125
- package/dist/frontend/lowering/lower-classes.js +832 -866
- package/dist/frontend/lowering/lower-classes.js.map +1 -1
- package/dist/frontend/lowering/lower-comptime.d.ts +5 -12
- package/dist/frontend/lowering/lower-comptime.js +32 -31
- package/dist/frontend/lowering/lower-comptime.js.map +1 -1
- package/dist/frontend/lowering/lower-containers.d.ts +35 -135
- package/dist/frontend/lowering/lower-containers.js +1394 -1715
- package/dist/frontend/lowering/lower-containers.js.map +1 -1
- package/dist/frontend/lowering/lower-dgram.d.ts +3 -7
- package/dist/frontend/lowering/lower-dgram.js +97 -111
- package/dist/frontend/lowering/lower-dgram.js.map +1 -1
- package/dist/frontend/lowering/lower-enums.d.ts +4 -4
- package/dist/frontend/lowering/lower-enums.js +30 -30
- package/dist/frontend/lowering/lower-enums.js.map +1 -1
- package/dist/frontend/lowering/{lower-emitter.d.ts → lower-event-emitter.d.ts} +7 -18
- package/dist/frontend/lowering/{lower-emitter.js → lower-event-emitter.js} +172 -174
- package/dist/frontend/lowering/lower-event-emitter.js.map +1 -0
- package/dist/frontend/lowering/lower-expando.d.ts +5 -5
- package/dist/frontend/lowering/lower-expando.js +40 -40
- package/dist/frontend/lowering/lower-expando.js.map +1 -1
- package/dist/frontend/lowering/lower-exprs.d.ts +56 -264
- package/dist/frontend/lowering/lower-exprs.js +1644 -1704
- package/dist/frontend/lowering/lower-exprs.js.map +1 -1
- package/dist/frontend/lowering/lower-generators.d.ts +6 -6
- package/dist/frontend/lowering/lower-generators.js +73 -72
- package/dist/frontend/lowering/lower-generators.js.map +1 -1
- package/dist/frontend/lowering/lower-inspect.d.ts +5 -17
- package/dist/frontend/lowering/lower-inspect.js +236 -238
- package/dist/frontend/lowering/lower-inspect.js.map +1 -1
- package/dist/frontend/lowering/lower-island.d.ts +34 -45
- package/dist/frontend/lowering/lower-island.js +440 -511
- package/dist/frontend/lowering/lower-island.js.map +1 -1
- package/dist/frontend/lowering/lower-mixins.d.ts +7 -10
- package/dist/frontend/lowering/lower-mixins.js +86 -86
- package/dist/frontend/lowering/lower-mixins.js.map +1 -1
- package/dist/frontend/lowering/lower-modules.d.ts +12 -18
- package/dist/frontend/lowering/lower-modules.js +284 -283
- package/dist/frontend/lowering/lower-modules.js.map +1 -1
- package/dist/frontend/lowering/lower-namespaces.d.ts +23 -49
- package/dist/frontend/lowering/lower-namespaces.js +123 -115
- package/dist/frontend/lowering/lower-namespaces.js.map +1 -1
- package/dist/frontend/lowering/lower-server.d.ts +18 -25
- package/dist/frontend/lowering/lower-server.js +899 -899
- package/dist/frontend/lowering/lower-server.js.map +1 -1
- package/dist/frontend/lowering/lower-stmts.d.ts +30 -149
- package/dist/frontend/lowering/lower-stmts.js +1176 -1229
- package/dist/frontend/lowering/lower-stmts.js.map +1 -1
- package/dist/frontend/lowering/lower-stream.d.ts +12 -12
- package/dist/frontend/lowering/lower-stream.js +300 -301
- package/dist/frontend/lowering/lower-stream.js.map +1 -1
- package/dist/frontend/lowering/lower-test.d.ts +5 -5
- package/dist/frontend/lowering/lower-test.js +82 -82
- package/dist/frontend/lowering/lower-test.js.map +1 -1
- package/dist/frontend/lowering/lowerer.d.ts +66 -20
- package/dist/frontend/lowering/lowerer.js +421 -198
- package/dist/frontend/lowering/lowerer.js.map +1 -1
- package/dist/frontend/lowering/pairs-snapshot.d.ts +11 -0
- package/dist/frontend/lowering/pairs-snapshot.js +85 -0
- package/dist/frontend/lowering/pairs-snapshot.js.map +1 -0
- package/dist/frontend/lowering/static-this.d.ts +6 -0
- package/dist/frontend/lowering/static-this.js +24 -0
- package/dist/frontend/lowering/static-this.js.map +1 -0
- package/dist/frontend/lowering/surfaces.d.ts +14 -33
- package/dist/frontend/lowering/surfaces.js +64 -64
- package/dist/frontend/lowering/surfaces.js.map +1 -1
- package/dist/frontend/npm-static-rewrite.js +6 -28
- package/dist/frontend/npm-static-rewrite.js.map +1 -1
- package/dist/frontend/npm-static.d.ts +0 -10
- package/dist/frontend/npm-static.js +4 -7
- package/dist/frontend/npm-static.js.map +1 -1
- package/dist/frontend/npm.d.ts +0 -24
- package/dist/frontend/npm.js +11 -85
- package/dist/frontend/npm.js.map +1 -1
- package/dist/frontend/program.d.ts +3 -1
- package/dist/frontend/program.js +51 -17
- package/dist/frontend/program.js.map +1 -1
- package/dist/frontend/provenance-registry.d.ts +0 -2
- package/dist/frontend/provenance-registry.js +0 -10
- package/dist/frontend/provenance-registry.js.map +1 -1
- package/dist/frontend/provenance.js +4 -7
- package/dist/frontend/provenance.js.map +1 -1
- package/dist/frontend/resolve.d.ts +7 -2
- package/dist/frontend/resolve.js +12 -17
- package/dist/frontend/resolve.js.map +1 -1
- package/dist/frontend/resolve.test.d.ts +1 -0
- package/dist/frontend/resolve.test.js +29 -0
- package/dist/frontend/resolve.test.js.map +1 -0
- package/dist/frontend/ts7/adapter.d.ts +2 -2
- package/dist/frontend/ts7/adapter.js +1 -1
- package/dist/frontend/ts7/adapter.js.map +1 -1
- package/dist/frontend/ts7/checker.d.ts +40 -2
- package/dist/frontend/ts7/checker.js +182 -54
- package/dist/frontend/ts7/checker.js.map +1 -1
- package/dist/frontend/ts7/enums.js +2 -1
- package/dist/frontend/ts7/enums.js.map +1 -1
- package/dist/frontend/ts7/{program.js → program-adapter.js} +7 -6
- package/dist/frontend/ts7/program-adapter.js.map +1 -0
- package/dist/frontend/ts7/world-check.d.ts +1 -3
- package/dist/frontend/ts7/world-check.js +3 -1
- package/dist/frontend/ts7/world-check.js.map +1 -1
- package/dist/frontend/tsc-codes.d.ts +8 -0
- package/dist/frontend/tsc-codes.js +109 -0
- package/dist/frontend/tsc-codes.js.map +1 -0
- package/dist/frontend/{types.d.ts → type-mapper.d.ts} +2 -25
- package/dist/frontend/{types.js → type-mapper.js} +31 -52
- package/dist/frontend/type-mapper.js.map +1 -0
- package/dist/frontend/workspace-registry.d.ts +26 -0
- package/dist/frontend/workspace-registry.js +71 -0
- package/dist/frontend/workspace-registry.js.map +1 -0
- package/dist/index.d.ts +115 -30
- package/dist/index.js +650 -146
- package/dist/index.js.map +1 -1
- package/dist/ir/analysis.d.ts +37 -0
- package/dist/ir/analysis.js +118 -0
- package/dist/ir/analysis.js.map +1 -0
- package/dist/ir/analysis.test.d.ts +1 -0
- package/dist/ir/analysis.test.js +21 -0
- package/dist/ir/analysis.test.js.map +1 -0
- package/dist/ir/build.d.ts +9 -0
- package/dist/ir/build.js +33 -0
- package/dist/ir/build.js.map +1 -0
- package/dist/ir/integer-loops.d.ts +1 -1
- package/dist/ir/{nodes.d.ts → ir.d.ts} +60 -26
- package/dist/ir/{nodes.js → ir.js} +173 -141
- package/dist/ir/ir.js.map +1 -0
- package/dist/ir/ir.test.d.ts +1 -0
- package/dist/ir/ir.test.js +17 -0
- package/dist/ir/ir.test.js.map +1 -0
- package/dist/ir/serialize.d.ts +1 -1
- package/dist/ir/serialize.js +2 -1
- package/dist/ir/serialize.js.map +1 -1
- package/dist/ir/validate.d.ts +1 -1
- package/dist/ir/validate.js +16 -5
- package/dist/ir/validate.js.map +1 -1
- package/dist/library/cache-primitives.d.ts +24 -0
- package/dist/library/cache-primitives.js +83 -0
- package/dist/library/cache-primitives.js.map +1 -0
- package/dist/library/cache-reset.test.d.ts +1 -0
- package/dist/library/cache-reset.test.js +47 -0
- package/dist/library/cache-reset.test.js.map +1 -0
- package/dist/library/compiler-self-identity.d.ts +23 -0
- package/dist/library/compiler-self-identity.js +84 -0
- package/dist/library/compiler-self-identity.js.map +1 -0
- package/dist/library/fence-eval.d.ts +3 -1
- package/dist/library/fence-eval.js +5 -1
- package/dist/library/fence-eval.js.map +1 -1
- package/dist/library/int-infer.d.ts +1 -36
- package/dist/library/int-infer.js +17 -17
- package/dist/library/int-infer.js.map +1 -1
- package/dist/library/{early-cache.d.ts → library-cache.d.ts} +1 -1
- package/dist/library/{early-cache.js → library-cache.js} +37 -111
- package/dist/library/library-cache.js.map +1 -0
- package/dist/library/library-cache.test.d.ts +1 -0
- package/dist/library/{early-cache.test.js → library-cache.test.js} +2 -2
- package/dist/library/library-cache.test.js.map +1 -0
- package/dist/library/{profile.d.ts → library-profile.d.ts} +4 -7
- package/dist/library/{profile.js → library-profile.js} +18 -11
- package/dist/library/library-profile.js.map +1 -0
- package/dist/library/semantic-source.js +2 -1
- package/dist/library/semantic-source.js.map +1 -1
- package/dist/library/sidecar.d.ts +5 -2
- package/dist/library/sidecar.js +11 -5
- package/dist/library/sidecar.js.map +1 -1
- package/dist/startup-cache.d.ts +6 -0
- package/dist/startup-cache.js +6 -0
- package/dist/startup-cache.js.map +1 -0
- package/package.json +7 -2
- package/surface-manifest.json +1 -1
- package/dist/backend/cc-cache.test.js.map +0 -1
- package/dist/backend/cc.js.map +0 -1
- package/dist/backend/emission/emit-async.js.map +0 -1
- package/dist/backend/emission/emit-exprs.d.ts +0 -13
- package/dist/backend/emission/emit-exprs.js +0 -7407
- package/dist/backend/emission/emit-exprs.js.map +0 -1
- package/dist/backend/emission/emit-island.js.map +0 -1
- package/dist/backend/emission/emit-shapes.js.map +0 -1
- package/dist/backend/emission/emit-stmts.js.map +0 -1
- package/dist/backend/emission/emit-types.js.map +0 -1
- package/dist/backend/emission/emit-walkers.js.map +0 -1
- package/dist/backend/emission/emitter.js.map +0 -1
- package/dist/backend/emission/may-throw.js.map +0 -1
- package/dist/backend/library-identity.js.map +0 -1
- package/dist/ffi/profile.js.map +0 -1
- package/dist/frontend/lowering/lower-emitter.js.map +0 -1
- package/dist/frontend/shared.d.ts +0 -82
- package/dist/frontend/shared.js +0 -308
- package/dist/frontend/shared.js.map +0 -1
- package/dist/frontend/ts7/program.js.map +0 -1
- package/dist/frontend/types.js.map +0 -1
- package/dist/ir/nodes.js.map +0 -1
- package/dist/library/early-cache.js.map +0 -1
- package/dist/library/early-cache.test.js.map +0 -1
- package/dist/library/profile.js.map +0 -1
- /package/dist/backend/{cc-cache.test.d.ts → c/types.test.d.ts} +0 -0
- /package/dist/{library/early-cache.test.d.ts → backend/llvm/shapes.test.d.ts} +0 -0
- /package/dist/frontend/ts7/{program.d.ts → program-adapter.d.ts} +0 -0
|
@@ -1,43 +1,62 @@
|
|
|
1
|
+
import { InternalCompilerError } from "../../errors.js";
|
|
1
2
|
import { mangleArgPack, mangleAsyncSpawn, mangleChildDataThunk, mangleChildExitThunk, mangleCloseBindThunk, mangleCloseOverrideWrap, mangleConnectResThunk, mangleConnectSockThunk, mangleDgramMsgThunk, mangleDnsLookupThunk, mangleField, mangleFsRenameThunk, mangleFunction, mangleGenDrop, mangleGenResThunk, mangleGenSpawn, mangleGlobal, mangleLocal, mangleRaceThunk, mangleRawParam, mangleNetLookupAnswerThunk, mangleEmitterInvokeThunk, mangleStreamCbThunk, mangleStreamDoneFn, mangleRecordNew, mangleRecordRelease, mangleRecordStruct, mangleResolveThunk, mangleSniAnswerThunk, mangleTrampoline } from "../mangle.js";
|
|
2
|
-
import { cDecl, cType, releaseCallC, retainCallC, vAdapters } from "./
|
|
3
|
-
import { isRefCounted, isUnitType, typeEquals, typeKey } from "../../ir/
|
|
3
|
+
import { cDecl, cType, releaseCallC, retainCallC, vAdapters } from "./types.js";
|
|
4
|
+
import { isRefCounted, isUnitType, typeEquals, typeKey } from "../../ir/ir.js";
|
|
5
|
+
/** The argument-pack ABI and trampoline prefix shared by async functions
|
|
6
|
+
* and generators. Their promise/generator completion and spawn tails stay
|
|
7
|
+
* with the callers below. */
|
|
8
|
+
function emitArgPackAndTrampolinePrologue(fn) {
|
|
9
|
+
const pack = mangleArgPack(fn.name);
|
|
10
|
+
const lifted = fn.captures !== undefined;
|
|
11
|
+
const fields = [];
|
|
12
|
+
if (lifted)
|
|
13
|
+
fields.push("ScrClosure *sc_env;");
|
|
14
|
+
const boxedIds = new Set(fn.locals.filter((l) => l.boxed).map((l) => l.id));
|
|
15
|
+
const pname = (p) => boxedIds.has(p.localId) ? mangleRawParam(p.localId) : mangleLocal(p.localId);
|
|
16
|
+
for (const p of fn.params)
|
|
17
|
+
fields.push(`${cDecl(p.type, pname(p))};`);
|
|
18
|
+
const definitions = [``, `typedef struct { ${fields.join(" ") || "char sc_unused;"} } ${pack};`];
|
|
19
|
+
const callArgs = [
|
|
20
|
+
...(lifted ? ["sc_a.sc_env"] : []),
|
|
21
|
+
...fn.params.map((p) => `sc_a.${pname(p)}`),
|
|
22
|
+
].join(", ");
|
|
23
|
+
const ret = fn.returnType;
|
|
24
|
+
const bodyCall = `${mangleFunction(fn.name)}(${callArgs})`;
|
|
25
|
+
const lines = [
|
|
26
|
+
`static void ${mangleTrampoline(fn.name)}(ScrFiber *sc_self, void *sc_ap0) {`,
|
|
27
|
+
` ${pack} sc_a = *(${pack} *)sc_ap0;`,
|
|
28
|
+
` free(sc_ap0);`,
|
|
29
|
+
];
|
|
30
|
+
if (ret.kind === "void") {
|
|
31
|
+
lines.push(` ${bodyCall};`);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
lines.push(` ${cDecl(ret, "sc_r")} = ${bodyCall};`);
|
|
35
|
+
}
|
|
36
|
+
if (lifted)
|
|
37
|
+
lines.push(` scr_closure_release(sc_a.sc_env);`);
|
|
38
|
+
const spawnParams = [
|
|
39
|
+
...(lifted ? ["ScrClosure *sc_env"] : []),
|
|
40
|
+
...fn.params.map((p) => cDecl(p.type, pname(p))),
|
|
41
|
+
];
|
|
42
|
+
const argPackLines = [
|
|
43
|
+
` ${pack} *sc_ap = malloc(sizeof *sc_ap);`,
|
|
44
|
+
` if (!sc_ap) { scr_trap("scriptc: out of memory\\n"); }`,
|
|
45
|
+
...(lifted ? [` sc_ap->sc_env = scr_closure_retain(sc_env);`] : []),
|
|
46
|
+
...fn.params.map((p) => ` sc_ap->${pname(p)} = ${pname(p)};`),
|
|
47
|
+
];
|
|
48
|
+
return { definitions, pack, lifted, pname, ret, lines, spawnParams, argPackLines };
|
|
49
|
+
}
|
|
4
50
|
/** Per-async-function machinery: an argument pack, a fiber trampoline
|
|
5
51
|
* (unpacks, runs the ordinary compiled body, settles the promise), and a
|
|
6
52
|
* spawn wrapper call sites use. Lifted async lambdas additionally thread
|
|
7
53
|
* their closure env through the pack (+1, released after the body). */
|
|
8
|
-
export function emitAsyncScaffolding(
|
|
9
|
-
for (const fn of
|
|
54
|
+
export function emitAsyncScaffolding(emitter, out) {
|
|
55
|
+
for (const fn of emitter.mod.functions) {
|
|
10
56
|
if (!fn.async)
|
|
11
57
|
continue;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const fields = [];
|
|
15
|
-
if (lifted)
|
|
16
|
-
fields.push("ScrClosure *sc_env;");
|
|
17
|
-
const boxedIds = new Set(fn.locals.filter((l) => l.boxed).map((l) => l.id));
|
|
18
|
-
const pname = (p) => boxedIds.has(p.localId) ? mangleRawParam(p.localId) : mangleLocal(p.localId);
|
|
19
|
-
for (const p of fn.params)
|
|
20
|
-
fields.push(`${cDecl(p.type, pname(p))};`);
|
|
21
|
-
out.push(``, `typedef struct { ${fields.join(" ") || "char sc_unused;"} } ${pack};`);
|
|
22
|
-
const callArgs = [
|
|
23
|
-
...(lifted ? ["sc_a.sc_env"] : []),
|
|
24
|
-
...fn.params.map((p) => `sc_a.${pname(p)}`),
|
|
25
|
-
].join(", ");
|
|
26
|
-
const ret = fn.returnType;
|
|
27
|
-
const bodyCall = `${mangleFunction(fn.name)}(${callArgs})`;
|
|
28
|
-
const lines = [
|
|
29
|
-
`static void ${mangleTrampoline(fn.name)}(ScrFiber *sc_self, void *sc_ap0) {`,
|
|
30
|
-
` ${pack} sc_a = *(${pack} *)sc_ap0;`,
|
|
31
|
-
` free(sc_ap0);`,
|
|
32
|
-
];
|
|
33
|
-
if (ret.kind === "void") {
|
|
34
|
-
lines.push(` ${bodyCall};`);
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
lines.push(` ${cDecl(ret, "sc_r")} = ${bodyCall};`);
|
|
38
|
-
}
|
|
39
|
-
if (lifted)
|
|
40
|
-
lines.push(` scr_closure_release(sc_a.sc_env);`);
|
|
58
|
+
const { definitions, ret, lines, spawnParams, argPackLines } = emitArgPackAndTrampolinePrologue(fn);
|
|
59
|
+
out.push(...definitions);
|
|
41
60
|
lines.push(` if (!scr_exc_pending()) {`);
|
|
42
61
|
switch (ret.kind) {
|
|
43
62
|
case "void":
|
|
@@ -55,7 +74,7 @@ export function emitAsyncScaffolding(E, out) {
|
|
|
55
74
|
break;
|
|
56
75
|
default: {
|
|
57
76
|
const v = vAdapters(ret);
|
|
58
|
-
lines.push(` scr_promise_fulfill_ref(scr_fiber_promise(sc_self), sc_r, ${v.retain}, ${v.release}, ${
|
|
77
|
+
lines.push(` scr_promise_fulfill_ref(scr_fiber_promise(sc_self), sc_r, ${v.retain}, ${v.release}, ${emitter.traceArgC(ret)});`);
|
|
59
78
|
}
|
|
60
79
|
}
|
|
61
80
|
lines.push(` }`);
|
|
@@ -65,15 +84,11 @@ export function emitAsyncScaffolding(E, out) {
|
|
|
65
84
|
}
|
|
66
85
|
lines.push(`}`);
|
|
67
86
|
out.push(...lines);
|
|
68
|
-
const spawnParams = [
|
|
69
|
-
...(lifted ? ["ScrClosure *sc_env"] : []),
|
|
70
|
-
...fn.params.map((p) => cDecl(p.type, pname(p))),
|
|
71
|
-
];
|
|
72
87
|
const cache = fn.asyncCacheGlobal !== undefined ? mangleGlobal(fn.asyncCacheGlobal) : null;
|
|
73
88
|
const cycleCache = fn.asyncCycleCacheGlobal !== undefined ? mangleGlobal(fn.asyncCycleCacheGlobal) : null;
|
|
74
89
|
out.push(`static ScrPromise *${mangleAsyncSpawn(fn.name)}(${spawnParams.join(", ") || "void"}) {`, ...(cache !== null
|
|
75
90
|
? [` if (${cache}) return scr_promise_retain(${cache});`]
|
|
76
|
-
: []),
|
|
91
|
+
: []), ...argPackLines, ` ScrPromise *sc_p = scr_async_spawn(&${mangleTrampoline(fn.name)}, sc_ap);`, ...(cache !== null
|
|
77
92
|
? [
|
|
78
93
|
// Module evaluation promises are loader-owned from the
|
|
79
94
|
// moment evaluation starts. Mark even a pending promise
|
|
@@ -104,7 +119,7 @@ export function emitAsyncScaffolding(E, out) {
|
|
|
104
119
|
]
|
|
105
120
|
: []), ` return sc_p;`, `}`);
|
|
106
121
|
}
|
|
107
|
-
emitGenScaffolding(
|
|
122
|
+
emitGenScaffolding(emitter, out);
|
|
108
123
|
}
|
|
109
124
|
/** Per-generator-function machinery — the async scaffolding's lazy
|
|
110
125
|
* sibling: the same argument pack, a fiber trampoline whose epilogue
|
|
@@ -112,39 +127,12 @@ export function emitAsyncScaffolding(E, out) {
|
|
|
112
127
|
* promoting the parked .return value), a spawn wrapper that only
|
|
113
128
|
* ALLOCATES the suspended fiber (nothing runs until the first .next()),
|
|
114
129
|
* and the never-started teardown that drops the packed (+1) arguments. */
|
|
115
|
-
function emitGenScaffolding(
|
|
116
|
-
for (const fn of
|
|
130
|
+
function emitGenScaffolding(emitter, out) {
|
|
131
|
+
for (const fn of emitter.mod.functions) {
|
|
117
132
|
if (!fn.generator)
|
|
118
133
|
continue;
|
|
119
|
-
const pack =
|
|
120
|
-
|
|
121
|
-
const fields = [];
|
|
122
|
-
if (lifted)
|
|
123
|
-
fields.push("ScrClosure *sc_env;");
|
|
124
|
-
const boxedIds = new Set(fn.locals.filter((l) => l.boxed).map((l) => l.id));
|
|
125
|
-
const pname = (p) => boxedIds.has(p.localId) ? mangleRawParam(p.localId) : mangleLocal(p.localId);
|
|
126
|
-
for (const p of fn.params)
|
|
127
|
-
fields.push(`${cDecl(p.type, pname(p))};`);
|
|
128
|
-
out.push(``, `typedef struct { ${fields.join(" ") || "char sc_unused;"} } ${pack};`);
|
|
129
|
-
const callArgs = [
|
|
130
|
-
...(lifted ? ["sc_a.sc_env"] : []),
|
|
131
|
-
...fn.params.map((p) => `sc_a.${pname(p)}`),
|
|
132
|
-
].join(", ");
|
|
133
|
-
const ret = fn.returnType;
|
|
134
|
-
const bodyCall = `${mangleFunction(fn.name)}(${callArgs})`;
|
|
135
|
-
const lines = [
|
|
136
|
-
`static void ${mangleTrampoline(fn.name)}(ScrFiber *sc_self, void *sc_ap0) {`,
|
|
137
|
-
` ${pack} sc_a = *(${pack} *)sc_ap0;`,
|
|
138
|
-
` free(sc_ap0);`,
|
|
139
|
-
];
|
|
140
|
-
if (ret.kind === "void") {
|
|
141
|
-
lines.push(` ${bodyCall};`);
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
lines.push(` ${cDecl(ret, "sc_r")} = ${bodyCall};`);
|
|
145
|
-
}
|
|
146
|
-
if (lifted)
|
|
147
|
-
lines.push(` scr_closure_release(sc_a.sc_env);`);
|
|
134
|
+
const { definitions, pack, lifted, pname, ret, lines, spawnParams, argPackLines } = emitArgPackAndTrampolinePrologue(fn);
|
|
135
|
+
out.push(...definitions);
|
|
148
136
|
lines.push(` ScrGen *sc_g = scr_gen_of_fiber(sc_self);`);
|
|
149
137
|
// Normal completion stores the (typed) return value; void completes
|
|
150
138
|
// with the NONE slot — JS's undefined done-value. A GENRET unwind
|
|
@@ -169,13 +157,9 @@ function emitGenScaffolding(E, out) {
|
|
|
169
157
|
? [` ${releaseCallC(ret, "sc_r")}; /* unwound: the never-read dummy */`]
|
|
170
158
|
: []), ` }`, `}`);
|
|
171
159
|
out.push(...lines);
|
|
172
|
-
const spawnParams = [
|
|
173
|
-
...(lifted ? ["ScrClosure *sc_env"] : []),
|
|
174
|
-
...fn.params.map((p) => cDecl(p.type, pname(p))),
|
|
175
|
-
];
|
|
176
160
|
out.push(`static void ${mangleGenDrop(fn.name)}(void *sc_ap0) {`, ` ${pack} sc_a = *(${pack} *)sc_ap0;`, ` free(sc_ap0);`, ...(lifted ? [` scr_closure_release(sc_a.sc_env);`] : []), ...fn.params
|
|
177
161
|
.filter((p) => isRefCounted(p.type))
|
|
178
|
-
.map((p) => ` ${releaseCallC(p.type, `sc_a.${pname(p)}`)};`), ...(!lifted && !fn.params.some((p) => isRefCounted(p.type)) ? [` (void)sc_a;`] : []), `}`, `static ScrGen *${mangleGenSpawn(fn.name)}(${spawnParams.join(", ") || "void"}) {`,
|
|
162
|
+
.map((p) => ` ${releaseCallC(p.type, `sc_a.${pname(p)}`)};`), ...(!lifted && !fn.params.some((p) => isRefCounted(p.type)) ? [` (void)sc_a;`] : []), `}`, `static ScrGen *${mangleGenSpawn(fn.name)}(${spawnParams.join(", ") || "void"}) {`, ...argPackLines, ` return scr_gen_new(&${mangleTrampoline(fn.name)}, sc_ap, &${mangleGenDrop(fn.name)});`, `}`);
|
|
179
163
|
}
|
|
180
164
|
}
|
|
181
165
|
/** Interned per-union child exit adapter: the runtime invokes
|
|
@@ -185,22 +169,22 @@ function emitGenScaffolding(E, out) {
|
|
|
185
169
|
* owns the union param per the universal convention (unit-arm
|
|
186
170
|
* instances are immortal; their release is a no-op). The one-param
|
|
187
171
|
* shape ignores the signal. */
|
|
188
|
-
export function childExitThunkFor(
|
|
172
|
+
export function childExitThunkFor(emitter, param) {
|
|
189
173
|
if (param.kind !== "union")
|
|
190
|
-
throw new
|
|
174
|
+
throw new InternalCompilerError("emitter bug: exit listener param not a union");
|
|
191
175
|
const key = param.unionId;
|
|
192
|
-
let sym =
|
|
176
|
+
let sym = emitter.childExitThunks.get(key);
|
|
193
177
|
if (!sym) {
|
|
194
|
-
sym = mangleChildExitThunk(
|
|
195
|
-
|
|
196
|
-
const def =
|
|
178
|
+
sym = mangleChildExitThunk(emitter.childExitThunks.size);
|
|
179
|
+
emitter.childExitThunks.set(key, sym);
|
|
180
|
+
const def = emitter.unionsById.get(param.unionId);
|
|
197
181
|
const f64Tag = def ? def.arms.findIndex((a) => a.kind === "f64") : -1;
|
|
198
182
|
const nullTag = def ? def.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
199
183
|
if (f64Tag < 0 || nullTag < 0) {
|
|
200
|
-
throw new
|
|
184
|
+
throw new InternalCompilerError("emitter bug: exit listener union lacks its arms");
|
|
201
185
|
}
|
|
202
|
-
|
|
203
|
-
|
|
186
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, bool sc_has, double sc_code, const char *sc_sig);`);
|
|
187
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, bool sc_has, double sc_code, const char *sc_sig) {`, ` (void)sc_sig;`, ` ScrUnion *sc_u = sc_has ? scr_union_new_f64(${f64Tag}, sc_code)`, ` : ${emitter.unitInstanceRef(param.unionId, nullTag)};`, ` ((void (*)(ScrClosure *, ScrUnion *))sc_cb->fn)(sc_cb, sc_u);`, `}`);
|
|
204
188
|
}
|
|
205
189
|
return sym;
|
|
206
190
|
}
|
|
@@ -208,26 +192,26 @@ export function childExitThunkFor(E, param) {
|
|
|
208
192
|
* the code union as above plus the signal as its own `string | null`
|
|
209
193
|
* union (a fresh string from the runtime's static signal name when a
|
|
210
194
|
* signal killed the child, the null arm otherwise). */
|
|
211
|
-
export function
|
|
195
|
+
export function childExitSignalThunkFor(emitter, codeParam, sigParam) {
|
|
212
196
|
if (codeParam.kind !== "union" || sigParam.kind !== "union") {
|
|
213
|
-
throw new
|
|
197
|
+
throw new InternalCompilerError("emitter bug: exit listener params not unions");
|
|
214
198
|
}
|
|
215
199
|
const key = `${codeParam.unionId}+${sigParam.unionId}`;
|
|
216
|
-
let sym =
|
|
200
|
+
let sym = emitter.childExitThunks.get(key);
|
|
217
201
|
if (!sym) {
|
|
218
|
-
sym = mangleChildExitThunk(
|
|
219
|
-
|
|
220
|
-
const codeDef =
|
|
202
|
+
sym = mangleChildExitThunk(emitter.childExitThunks.size);
|
|
203
|
+
emitter.childExitThunks.set(key, sym);
|
|
204
|
+
const codeDef = emitter.unionsById.get(codeParam.unionId);
|
|
221
205
|
const f64Tag = codeDef ? codeDef.arms.findIndex((a) => a.kind === "f64") : -1;
|
|
222
206
|
const codeNullTag = codeDef ? codeDef.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
223
|
-
const sigDef =
|
|
207
|
+
const sigDef = emitter.unionsById.get(sigParam.unionId);
|
|
224
208
|
const strTag = sigDef ? sigDef.arms.findIndex((a) => a.kind === "string") : -1;
|
|
225
209
|
const sigNullTag = sigDef ? sigDef.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
226
210
|
if (f64Tag < 0 || codeNullTag < 0 || strTag < 0 || sigNullTag < 0) {
|
|
227
|
-
throw new
|
|
211
|
+
throw new InternalCompilerError("emitter bug: exit listener unions lack their arms");
|
|
228
212
|
}
|
|
229
|
-
|
|
230
|
-
|
|
213
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, bool sc_has, double sc_code, const char *sc_sig);`);
|
|
214
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, bool sc_has, double sc_code, const char *sc_sig) {`, ` ScrUnion *sc_u = sc_has ? scr_union_new_f64(${f64Tag}, sc_code)`, ` : ${emitter.unitInstanceRef(codeParam.unionId, codeNullTag)};`, ` ScrUnion *sc_s = sc_sig`, ` ? scr_union_new_ref(${strTag}, scr_str_new(sc_sig, strlen(sc_sig)), &scr_str_retain_v, &scr_str_release_v, NULL)`, ` : ${emitter.unitInstanceRef(sigParam.unionId, sigNullTag)};`, ` ((void (*)(ScrClosure *, ScrUnion *, ScrUnion *))sc_cb->fn)(sc_cb, sc_u, sc_s);`, `}`);
|
|
231
215
|
}
|
|
232
216
|
return sym;
|
|
233
217
|
}
|
|
@@ -237,21 +221,21 @@ export function childExitThunkFor2(E, codeParam, sigParam) {
|
|
|
237
221
|
* the arm exists — the ngrok `Buffer | string` listener; strings never
|
|
238
222
|
* fire from a pipe) and calls the listener, which owns the union param
|
|
239
223
|
* per the universal convention. */
|
|
240
|
-
export function childDataThunkFor(
|
|
224
|
+
export function childDataThunkFor(emitter, param) {
|
|
241
225
|
if (param.kind !== "union")
|
|
242
|
-
throw new
|
|
226
|
+
throw new InternalCompilerError("emitter bug: stream data listener param not a union");
|
|
243
227
|
const key = param.unionId;
|
|
244
|
-
let sym =
|
|
228
|
+
let sym = emitter.childDataThunks.get(key);
|
|
245
229
|
if (!sym) {
|
|
246
|
-
sym = mangleChildDataThunk(
|
|
247
|
-
|
|
248
|
-
const def =
|
|
230
|
+
sym = mangleChildDataThunk(emitter.childDataThunks.size);
|
|
231
|
+
emitter.childDataThunks.set(key, sym);
|
|
232
|
+
const def = emitter.unionsById.get(param.unionId);
|
|
249
233
|
const bytesTag = def ? def.arms.findIndex((a) => a.kind === "bytes" && a.elem === "u8") : -1;
|
|
250
234
|
if (bytesTag < 0) {
|
|
251
|
-
throw new
|
|
235
|
+
throw new InternalCompilerError("emitter bug: stream data listener union lacks its Buffer arm");
|
|
252
236
|
}
|
|
253
|
-
|
|
254
|
-
|
|
237
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrBytes *sc_chunk);`);
|
|
238
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrBytes *sc_chunk) {`, ` ScrUnion *sc_u = scr_union_new_ref(${bytesTag}, scr_bytes_retain(sc_chunk), &scr_bytes_retain_v, &scr_bytes_release_v, NULL);`, ` ((void (*)(ScrClosure *, ScrUnion *))sc_cb->fn)(sc_cb, sc_u);`, `}`);
|
|
255
239
|
}
|
|
256
240
|
return sym;
|
|
257
241
|
}
|
|
@@ -263,38 +247,38 @@ export function childDataThunkFor(E, param) {
|
|
|
263
247
|
* `(err?: Error) => void`) behind an emitted zero-arg trampoline that
|
|
264
248
|
* fires it with the undefined arm (a clean close carries no error) —
|
|
265
249
|
* and answers the +1 server (Node's chaining return). */
|
|
266
|
-
export function closeBindThunkFor(
|
|
250
|
+
export function closeBindThunkFor(emitter, cbUnion, retServer) {
|
|
267
251
|
if (cbUnion.kind !== "union")
|
|
268
|
-
throw new
|
|
252
|
+
throw new InternalCompilerError("emitter bug: bound-close callback param not a union");
|
|
269
253
|
const key = `${cbUnion.unionId}:${retServer ? "srv" : "void"}`;
|
|
270
|
-
let sym =
|
|
254
|
+
let sym = emitter.closeBindThunks.get(key);
|
|
271
255
|
if (sym)
|
|
272
256
|
return sym;
|
|
273
|
-
sym = mangleCloseBindThunk(
|
|
274
|
-
|
|
275
|
-
const def =
|
|
257
|
+
sym = mangleCloseBindThunk(emitter.closeBindThunks.size);
|
|
258
|
+
emitter.closeBindThunks.set(key, sym);
|
|
259
|
+
const def = emitter.unionsById.get(cbUnion.unionId);
|
|
276
260
|
const funcTag = def ? def.arms.findIndex((a) => a.kind === "func") : -1;
|
|
277
261
|
const funcArm = funcTag >= 0 ? def.arms[funcTag] : null;
|
|
278
262
|
if (!funcArm)
|
|
279
|
-
throw new
|
|
263
|
+
throw new InternalCompilerError("emitter bug: bound-close callback union lacks its func arm");
|
|
280
264
|
const oneParam = funcArm.params.length === 1;
|
|
281
265
|
let trampoline = null;
|
|
282
266
|
if (oneParam) {
|
|
283
267
|
const errParam = funcArm.params[0];
|
|
284
268
|
if (errParam.kind !== "union") {
|
|
285
|
-
throw new
|
|
269
|
+
throw new InternalCompilerError("emitter bug: bound-close callback's err param is not a union");
|
|
286
270
|
}
|
|
287
|
-
const errDef =
|
|
271
|
+
const errDef = emitter.unionsById.get(errParam.unionId);
|
|
288
272
|
const undefTag = errDef ? errDef.arms.findIndex((a) => a.kind === "undefinedT") : -1;
|
|
289
273
|
if (undefTag < 0)
|
|
290
|
-
throw new
|
|
274
|
+
throw new InternalCompilerError("emitter bug: bound-close err union lacks its undefined arm");
|
|
291
275
|
trampoline = `${sym}_cb`;
|
|
292
|
-
|
|
293
|
-
|
|
276
|
+
emitter.walkerProtos.push(`static void ${trampoline}(ScrClosure *sc_self);`);
|
|
277
|
+
emitter.walkerDefs.push(`static void ${trampoline}(ScrClosure *sc_self) { /* close cb: fire with no error */`, ` ScrClosure *sc_inner = (ScrClosure *)scr_box_get_ref(sc_self->caps[0]); /* +1 */`, ` ((void (*)(ScrClosure *, ScrUnion *))sc_inner->fn)(sc_inner, ${emitter.unitInstanceRef(errParam.unionId, undefTag)});`, ` scr_closure_release(sc_inner);`, `}`);
|
|
294
278
|
}
|
|
295
279
|
const retC = retServer ? "ScrNetServer *" : "void";
|
|
296
|
-
|
|
297
|
-
|
|
280
|
+
emitter.walkerProtos.push(`static ${retC}${retServer ? "" : " "}${sym}(ScrClosure *sc_self, ScrUnion *sc_cb);`);
|
|
281
|
+
emitter.walkerDefs.push(`static ${retC}${retServer ? "" : " "}${sym}(ScrClosure *sc_self, ScrUnion *sc_cb) { /* bound server.close */`, ` ScrNetServer *sc_srv = (ScrNetServer *)scr_box_get_ref(sc_self->caps[0]); /* +1 */`, ` ScrClosure *sc_reg = NULL;`, ` if (sc_cb->tag == ${funcTag}) {`, ...(oneParam
|
|
298
282
|
? [
|
|
299
283
|
` sc_reg = scr_closure_new((void *)&${trampoline}, 1);`,
|
|
300
284
|
` sc_reg->caps[0] = scr_box_new(SCR_BOX_FUNC);`,
|
|
@@ -310,27 +294,27 @@ export function closeBindThunkFor(E, cbUnion, retServer) {
|
|
|
310
294
|
* types, so this wrapper carries the user function and fires it with
|
|
311
295
|
* the undefined-arm callback argument (tags are program data),
|
|
312
296
|
* releasing the chaining-return server when the signature answers one. */
|
|
313
|
-
export function closeOverrideWrapFor(
|
|
297
|
+
export function closeOverrideWrapFor(emitter, cbUnion, retServer) {
|
|
314
298
|
if (cbUnion.kind !== "union")
|
|
315
|
-
throw new
|
|
299
|
+
throw new InternalCompilerError("emitter bug: close-override callback param not a union");
|
|
316
300
|
const key = `${cbUnion.unionId}:${retServer ? "srv" : "void"}`;
|
|
317
|
-
let sym =
|
|
301
|
+
let sym = emitter.closeOverrideWraps.get(key);
|
|
318
302
|
if (sym)
|
|
319
303
|
return sym;
|
|
320
|
-
sym = mangleCloseOverrideWrap(
|
|
321
|
-
|
|
322
|
-
const def =
|
|
304
|
+
sym = mangleCloseOverrideWrap(emitter.closeOverrideWraps.size);
|
|
305
|
+
emitter.closeOverrideWraps.set(key, sym);
|
|
306
|
+
const def = emitter.unionsById.get(cbUnion.unionId);
|
|
323
307
|
const undefTag = def ? def.arms.findIndex((a) => a.kind === "undefinedT") : -1;
|
|
324
308
|
if (undefTag < 0)
|
|
325
|
-
throw new
|
|
326
|
-
|
|
327
|
-
|
|
309
|
+
throw new InternalCompilerError("emitter bug: close-override callback union lacks its undefined arm");
|
|
310
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_self);`);
|
|
311
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_self) { /* close override wrapper */`, ` ScrClosure *sc_inner = (ScrClosure *)scr_box_get_ref(sc_self->caps[0]); /* +1 */`, ...(retServer
|
|
328
312
|
? [
|
|
329
|
-
` ScrNetServer *sc_r = ((ScrNetServer *(*)(ScrClosure *, ScrUnion *))sc_inner->fn)(sc_inner, ${
|
|
313
|
+
` ScrNetServer *sc_r = ((ScrNetServer *(*)(ScrClosure *, ScrUnion *))sc_inner->fn)(sc_inner, ${emitter.unitInstanceRef(cbUnion.unionId, undefTag)});`,
|
|
330
314
|
` scr_net_server_release(sc_r); /* the chaining return is unobserved here */`,
|
|
331
315
|
]
|
|
332
316
|
: [
|
|
333
|
-
` ((void (*)(ScrClosure *, ScrUnion *))sc_inner->fn)(sc_inner, ${
|
|
317
|
+
` ((void (*)(ScrClosure *, ScrUnion *))sc_inner->fn)(sc_inner, ${emitter.unitInstanceRef(cbUnion.unionId, undefTag)});`,
|
|
334
318
|
]), ` scr_closure_release(sc_inner);`, `}`);
|
|
335
319
|
return sym;
|
|
336
320
|
}
|
|
@@ -341,17 +325,17 @@ export function closeOverrideWrapFor(E, cbUnion, retServer) {
|
|
|
341
325
|
* which owns both params per the universal convention (msg retains like
|
|
342
326
|
* the net data thunk). Zero/one-param listeners take the runtime's own
|
|
343
327
|
* scr_dgram_msg_thunk0/1. */
|
|
344
|
-
export function dgramMsgThunkFor(
|
|
328
|
+
export function dgramMsgThunkFor(emitter, param) {
|
|
345
329
|
if (param.kind !== "record")
|
|
346
|
-
throw new
|
|
330
|
+
throw new InternalCompilerError("emitter bug: message listener rinfo not a record");
|
|
347
331
|
const key = param.shapeId;
|
|
348
|
-
let sym =
|
|
332
|
+
let sym = emitter.dgramMsgThunks.get(key);
|
|
349
333
|
if (!sym) {
|
|
350
|
-
sym = mangleDgramMsgThunk(
|
|
351
|
-
|
|
334
|
+
sym = mangleDgramMsgThunk(emitter.dgramMsgThunks.size);
|
|
335
|
+
emitter.dgramMsgThunks.set(key, sym);
|
|
352
336
|
const struct = mangleRecordStruct(param.shapeId);
|
|
353
|
-
|
|
354
|
-
|
|
337
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrBytes *sc_msg, ScrStr *sc_addr, ScrStr *sc_family, double sc_port, double sc_size);`);
|
|
338
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrBytes *sc_msg, ScrStr *sc_addr, ScrStr *sc_family, double sc_port, double sc_size) {`, ` ${struct} *sc_ri = ${mangleRecordNew(param.shapeId)}();`, ` sc_ri->${mangleField("address")} = scr_str_retain(sc_addr);`, ` sc_ri->${mangleField("family")} = scr_str_retain(sc_family);`, ` sc_ri->${mangleField("port")} = sc_port;`, ` sc_ri->${mangleField("size")} = sc_size;`, ` ((void (*)(ScrClosure *, ScrBytes *, ${struct} *))sc_cb->fn)(sc_cb, scr_bytes_retain(sc_msg), sc_ri);`, `}`);
|
|
355
339
|
}
|
|
356
340
|
return sym;
|
|
357
341
|
}
|
|
@@ -361,61 +345,61 @@ export function dgramMsgThunkFor(E, param) {
|
|
|
361
345
|
* argument (tags are program data — the frontend pinned the union) and
|
|
362
346
|
* calls the listener with as many arguments as it declared, each owned
|
|
363
347
|
* per the universal convention. */
|
|
364
|
-
export function dnsLookupThunkFor(
|
|
348
|
+
export function dnsLookupThunkFor(emitter, cbT) {
|
|
365
349
|
if (cbT.kind !== "func")
|
|
366
|
-
throw new
|
|
350
|
+
throw new InternalCompilerError("emitter bug: dns.lookup callback not a func");
|
|
367
351
|
const nparams = cbT.params.length;
|
|
368
352
|
if (nparams === 0)
|
|
369
353
|
return "scr_dns_thunk0";
|
|
370
354
|
const errT = cbT.params[0];
|
|
371
355
|
if (errT.kind !== "union")
|
|
372
|
-
throw new
|
|
356
|
+
throw new InternalCompilerError("emitter bug: dns.lookup err param not a union");
|
|
373
357
|
const key = `${errT.unionId}/${nparams}`;
|
|
374
|
-
let sym =
|
|
358
|
+
let sym = emitter.dnsLookupThunks.get(key);
|
|
375
359
|
if (!sym) {
|
|
376
|
-
sym = mangleDnsLookupThunk(
|
|
377
|
-
|
|
378
|
-
const def =
|
|
360
|
+
sym = mangleDnsLookupThunk(emitter.dnsLookupThunks.size);
|
|
361
|
+
emitter.dnsLookupThunks.set(key, sym);
|
|
362
|
+
const def = emitter.unionsById.get(errT.unionId);
|
|
379
363
|
const errTag = def ? def.arms.findIndex((a) => a.kind === "object") : -1;
|
|
380
364
|
const nullTag = def ? def.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
381
365
|
if (errTag < 0 || nullTag < 0) {
|
|
382
|
-
throw new
|
|
366
|
+
throw new InternalCompilerError("emitter bug: dns.lookup err union lacks its arms");
|
|
383
367
|
}
|
|
384
368
|
const callSig = ["ScrClosure *", "ScrUnion *", ...(nparams >= 2 ? ["ScrStr *"] : []), ...(nparams >= 3 ? ["double"] : [])].join(", ");
|
|
385
369
|
const callArgs = ["sc_cb", "sc_u", ...(nparams >= 2 ? ["scr_str_retain(sc_addr)"] : []), ...(nparams >= 3 ? ["sc_family"] : [])].join(", ");
|
|
386
|
-
|
|
387
|
-
|
|
370
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrStr *sc_err, ScrStr *sc_addr, double sc_family);`);
|
|
371
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrStr *sc_err, ScrStr *sc_addr, double sc_family) {`, ` (void)sc_addr; (void)sc_family;`, ` ScrUnion *sc_u = sc_err`, ` ? scr_union_new_ref(${errTag}, scr_error_new(0, sc_err), &scr_error_retain_v, &scr_error_release_v, NULL)`, ` : ${emitter.unitInstanceRef(errT.unionId, nullTag)};`, ` ((void (*)(${callSig}))sc_cb->fn)(${callArgs});`, `}`);
|
|
388
372
|
}
|
|
389
373
|
return sym;
|
|
390
374
|
}
|
|
391
375
|
/** Interned fs.rename callback adapter. The runtime supplies a borrowed
|
|
392
376
|
* ScrError (or NULL); the adapter builds the callback's program-specific
|
|
393
377
|
* Error | null union, or a dyn error/null for checkJs callbacks. */
|
|
394
|
-
export function fsRenameThunkFor(
|
|
378
|
+
export function fsRenameThunkFor(emitter, cbT) {
|
|
395
379
|
if (cbT.kind !== "func")
|
|
396
|
-
throw new
|
|
380
|
+
throw new InternalCompilerError("emitter bug: fs.rename callback not a func");
|
|
397
381
|
if (cbT.params.length === 0)
|
|
398
382
|
return "scr_fs_rename_thunk0";
|
|
399
383
|
const param = cbT.params[0];
|
|
400
384
|
const key = typeKey(cbT);
|
|
401
|
-
let sym =
|
|
385
|
+
let sym = emitter.fsRenameThunks.get(key);
|
|
402
386
|
if (sym)
|
|
403
387
|
return sym;
|
|
404
|
-
sym = mangleFsRenameThunk(
|
|
405
|
-
|
|
406
|
-
|
|
388
|
+
sym = mangleFsRenameThunk(emitter.fsRenameThunks.size);
|
|
389
|
+
emitter.fsRenameThunks.set(key, sym);
|
|
390
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrError *sc_err);`);
|
|
407
391
|
if (param.kind === "dyn") {
|
|
408
|
-
|
|
392
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrError *sc_err) {`, ` ScrDyn *sc_arg = sc_err ? scr_dyn_from_error(sc_err) : scr_dyn_new_null();`, ` ((void (*)(ScrClosure *, ScrDyn *))sc_cb->fn)(sc_cb, sc_arg);`, `}`);
|
|
409
393
|
return sym;
|
|
410
394
|
}
|
|
411
395
|
if (param.kind !== "union")
|
|
412
|
-
throw new
|
|
413
|
-
const def =
|
|
396
|
+
throw new InternalCompilerError("emitter bug: fs.rename error param not a union");
|
|
397
|
+
const def = emitter.unionsById.get(param.unionId);
|
|
414
398
|
const errTag = def ? def.arms.findIndex((a) => a.kind === "object" && a.className === "%Error") : -1;
|
|
415
399
|
const nullTag = def ? def.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
416
400
|
if (errTag < 0 || nullTag < 0)
|
|
417
|
-
throw new
|
|
418
|
-
|
|
401
|
+
throw new InternalCompilerError("emitter bug: fs.rename error union lacks its arms");
|
|
402
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrError *sc_err) {`, ` ScrUnion *sc_u = sc_err`, ` ? scr_union_new_ref(${errTag}, scr_error_retain(sc_err), &scr_error_retain_v, &scr_error_release_v, NULL)`, ` : ${emitter.unitInstanceRef(param.unionId, nullTag)};`, ` ((void (*)(ScrClosure *, ScrUnion *))sc_cb->fn)(sc_cb, sc_u);`, `}`);
|
|
419
403
|
return sym;
|
|
420
404
|
}
|
|
421
405
|
/** Interned CONNECT-listener adapter for a UNION socket slot — the h2
|
|
@@ -424,48 +408,48 @@ export function fsRenameThunkFor(E, cbT) {
|
|
|
424
408
|
* the adapter wraps the socket at the union's netSocket arm (its tag is
|
|
425
409
|
* program data) and drops `head` when the listener declares two params.
|
|
426
410
|
* All three runtime args arrive +1; the union takes the socket's. */
|
|
427
|
-
export function connectSockThunkFor(
|
|
411
|
+
export function connectSockThunkFor(emitter, cbT) {
|
|
428
412
|
if (cbT.kind !== "func" || cbT.params[1]?.kind !== "union") {
|
|
429
|
-
throw new
|
|
413
|
+
throw new InternalCompilerError("emitter bug: connect listener union shape (frontend must fence)");
|
|
430
414
|
}
|
|
431
415
|
const key = typeKey(cbT);
|
|
432
|
-
let sym =
|
|
416
|
+
let sym = emitter.connectSockThunks.get(key);
|
|
433
417
|
if (sym)
|
|
434
418
|
return sym;
|
|
435
|
-
sym = mangleConnectSockThunk(
|
|
436
|
-
|
|
419
|
+
sym = mangleConnectSockThunk(emitter.connectSockThunks.size);
|
|
420
|
+
emitter.connectSockThunks.set(key, sym);
|
|
437
421
|
const sockT = cbT.params[1];
|
|
438
|
-
const def =
|
|
422
|
+
const def = emitter.unionsById.get(sockT.unionId);
|
|
439
423
|
const tag = def ? def.arms.findIndex((a) => a.kind === "netSocket") : -1;
|
|
440
424
|
if (tag < 0)
|
|
441
|
-
throw new
|
|
425
|
+
throw new InternalCompilerError("emitter bug: connect listener union lacks its socket arm");
|
|
442
426
|
const three = cbT.params.length === 3;
|
|
443
|
-
|
|
444
|
-
|
|
427
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrHttpReq *sc_req, ScrNetSocket *sc_sock, ScrBytes *sc_head);`);
|
|
428
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrHttpReq *sc_req, ScrNetSocket *sc_sock, ScrBytes *sc_head) {`, ...(three ? [] : [` scr_bytes_release(sc_head);`]), ` ScrUnion *sc_u = scr_union_new_ref(${tag}, sc_sock, &scr_net_sock_retain_v, &scr_net_sock_release_v, NULL);`, three
|
|
445
429
|
? ` ((void (*)(ScrClosure *, ScrHttpReq *, ScrUnion *, ScrBytes *))sc_cb->fn)(sc_cb, sc_req, sc_u, sc_head);`
|
|
446
430
|
: ` ((void (*)(ScrClosure *, ScrHttpReq *, ScrUnion *))sc_cb->fn)(sc_cb, sc_req, sc_u);`, `}`);
|
|
447
431
|
return sym;
|
|
448
432
|
}
|
|
449
|
-
export function connectResThunkFor(
|
|
433
|
+
export function connectResThunkFor(emitter, cbT) {
|
|
450
434
|
if (cbT.kind !== "func")
|
|
451
|
-
throw new
|
|
435
|
+
throw new InternalCompilerError("emitter bug: connect listener shape");
|
|
452
436
|
const key = `res:${typeKey(cbT)}`;
|
|
453
|
-
let sym =
|
|
437
|
+
let sym = emitter.connectSockThunks.get(key);
|
|
454
438
|
if (sym)
|
|
455
439
|
return sym;
|
|
456
|
-
sym = mangleConnectResThunk(
|
|
457
|
-
|
|
440
|
+
sym = mangleConnectResThunk(emitter.connectSockThunks.size);
|
|
441
|
+
emitter.connectSockThunks.set(key, sym);
|
|
458
442
|
const p1 = cbT.params[1];
|
|
459
|
-
const def = p1?.kind === "union" ?
|
|
443
|
+
const def = p1?.kind === "union" ? emitter.unionsById.get(p1.unionId) : undefined;
|
|
460
444
|
const tag = def ? def.arms.findIndex((a) => a.kind === "httpRes") : -1;
|
|
461
445
|
if (p1?.kind === "union" && tag < 0)
|
|
462
|
-
throw new
|
|
463
|
-
|
|
446
|
+
throw new InternalCompilerError("emitter bug: connect listener union lacks its response arm");
|
|
447
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ScrHttpReq *sc_req, ScrHttpRes *sc_res);`);
|
|
464
448
|
const second = p1?.kind === "union"
|
|
465
449
|
? `ScrUnion *sc_u = scr_union_new_ref(${tag}, sc_res, &scr_http_res_retain_v, &scr_http_res_release_v, NULL);`
|
|
466
450
|
: "";
|
|
467
451
|
const arg = p1?.kind === "union" ? "sc_u" : "sc_res";
|
|
468
|
-
|
|
452
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ScrHttpReq *sc_req, ScrHttpRes *sc_res) {`, ...(second ? [` ${second}`] : []), ...(cbT.params.length === 0
|
|
469
453
|
? [" scr_http_req_release(sc_req);", " scr_http_res_release(sc_res);", " ((void (*)(ScrClosure *))sc_cb->fn)(sc_cb);"]
|
|
470
454
|
: cbT.params.length === 1
|
|
471
455
|
? [" scr_http_res_release(sc_res);", " ((void (*)(ScrClosure *, ScrHttpReq *))sc_cb->fn)(sc_cb, sc_req);"]
|
|
@@ -480,32 +464,32 @@ export function connectResThunkFor(E, cbT) {
|
|
|
480
464
|
* tag) and the addresses record's field layout down to the runtime's
|
|
481
465
|
* (has_err, message, ip-list) answer. Params arrive +1 and release
|
|
482
466
|
* here; the extracted message/ips hand over +1. */
|
|
483
|
-
export function netLookupAnswerThunkFor(
|
|
467
|
+
export function netLookupAnswerThunkFor(emitter, cbT) {
|
|
484
468
|
if (cbT.kind !== "func" || cbT.params.length !== 2) {
|
|
485
|
-
throw new
|
|
469
|
+
throw new InternalCompilerError("emitter bug: lookup answer cb shape (frontend must fence)");
|
|
486
470
|
}
|
|
487
471
|
const key = typeKey(cbT);
|
|
488
|
-
let sym =
|
|
472
|
+
let sym = emitter.netLookupAnswerThunks.get(key);
|
|
489
473
|
if (sym)
|
|
490
474
|
return sym;
|
|
491
|
-
sym = mangleNetLookupAnswerThunk(
|
|
492
|
-
|
|
475
|
+
sym = mangleNetLookupAnswerThunk(emitter.netLookupAnswerThunks.size);
|
|
476
|
+
emitter.netLookupAnswerThunks.set(key, sym);
|
|
493
477
|
const errT = cbT.params[0];
|
|
494
478
|
if (errT.kind !== "union")
|
|
495
|
-
throw new
|
|
496
|
-
const errDef =
|
|
479
|
+
throw new InternalCompilerError("emitter bug: lookup answer err param not a union");
|
|
480
|
+
const errDef = emitter.unionsById.get(errT.unionId);
|
|
497
481
|
const nullTag = errDef ? errDef.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
498
482
|
if (nullTag < 0)
|
|
499
|
-
throw new
|
|
483
|
+
throw new InternalCompilerError("emitter bug: lookup answer err union lacks its null arm");
|
|
500
484
|
const addrsT = cbT.params[1];
|
|
501
485
|
if (addrsT.kind !== "array" || addrsT.elem.kind !== "record") {
|
|
502
|
-
throw new
|
|
486
|
+
throw new InternalCompilerError("emitter bug: lookup answer addresses param not a record array");
|
|
503
487
|
}
|
|
504
488
|
const recStruct = mangleRecordStruct(addrsT.elem.shapeId);
|
|
505
489
|
const recRelease = mangleRecordRelease(addrsT.elem.shapeId);
|
|
506
490
|
const addrField = mangleField("address");
|
|
507
|
-
|
|
508
|
-
|
|
491
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_self, ScrUnion *sc_err, ScrArr *sc_addrs);`);
|
|
492
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_self, ScrUnion *sc_err, ScrArr *sc_addrs) {`, ` bool sc_has_err = sc_err->tag != ${nullTag};`, ` ScrStr *sc_msg = NULL;`, ` if (sc_has_err) sc_msg = scr_str_retain(((ScrError *)scr_union_peek(sc_err))->message);`, ` ScrArr *sc_ips = NULL;`, ` if (!sc_has_err) {`, ` double sc_n = scr_arr_len(sc_addrs);`, ` sc_ips = scr_arr_new(SCR_ELEM_STR, (size_t)sc_n);`, ` for (double sc_i = 0; sc_i < sc_n; sc_i++) {`, ` ${recStruct} *sc_r = (${recStruct} *)scr_arr_get_ref(sc_addrs, sc_i);`, ` scr_arr_push_ref(sc_ips, scr_str_retain(sc_r->${addrField}));`, ` ${recRelease}(sc_r);`, ` }`, ` }`, ` scr_net_lookup_answer(sc_self, sc_has_err, sc_msg, sc_ips);`, ` scr_str_release(sc_msg);`, ` scr_arr_release(sc_ips);`, ` scr_union_release(sc_err);`, ` scr_arr_release(sc_addrs);`, `}`);
|
|
509
493
|
return sym;
|
|
510
494
|
}
|
|
511
495
|
/** Interned SNI answer-closure thunk: the fn of the runtime-minted `cb`
|
|
@@ -516,15 +500,15 @@ export function netLookupAnswerThunkFor(E, cbT) {
|
|
|
516
500
|
* to the runtime's (has_err, ctx-or-NULL) answer. The thunk owns its
|
|
517
501
|
* union params per the universal convention (the ctx payload retains
|
|
518
502
|
* +1 before its union releases; ownership moves to the runtime). */
|
|
519
|
-
export function sniAnswerThunkFor(
|
|
503
|
+
export function sniAnswerThunkFor(emitter, cbT) {
|
|
520
504
|
if (cbT.kind !== "func")
|
|
521
|
-
throw new
|
|
505
|
+
throw new InternalCompilerError("emitter bug: SNI answer cb not a func");
|
|
522
506
|
const key = typeKey(cbT);
|
|
523
|
-
let sym =
|
|
507
|
+
let sym = emitter.sniAnswerThunks.get(key);
|
|
524
508
|
if (sym)
|
|
525
509
|
return sym;
|
|
526
|
-
sym = mangleSniAnswerThunk(
|
|
527
|
-
|
|
510
|
+
sym = mangleSniAnswerThunk(emitter.sniAnswerThunks.size);
|
|
511
|
+
emitter.sniAnswerThunks.set(key, sym);
|
|
528
512
|
const nparams = cbT.params.length;
|
|
529
513
|
const params = ["ScrClosure *sc_self"];
|
|
530
514
|
const body = [];
|
|
@@ -532,11 +516,11 @@ export function sniAnswerThunkFor(E, cbT) {
|
|
|
532
516
|
if (nparams >= 1) {
|
|
533
517
|
const errT = cbT.params[0];
|
|
534
518
|
if (errT.kind !== "union")
|
|
535
|
-
throw new
|
|
536
|
-
const def =
|
|
519
|
+
throw new InternalCompilerError("emitter bug: SNI answer err param not a union");
|
|
520
|
+
const def = emitter.unionsById.get(errT.unionId);
|
|
537
521
|
const nullTag = def ? def.arms.findIndex((a) => a.kind === "nullT") : -1;
|
|
538
522
|
if (nullTag < 0)
|
|
539
|
-
throw new
|
|
523
|
+
throw new InternalCompilerError("emitter bug: SNI answer err union lacks its null arm");
|
|
540
524
|
params.push("ScrUnion *sc_err");
|
|
541
525
|
hasErr = `sc_err->tag != ${nullTag}`;
|
|
542
526
|
}
|
|
@@ -544,11 +528,11 @@ export function sniAnswerThunkFor(E, cbT) {
|
|
|
544
528
|
if (nparams >= 2) {
|
|
545
529
|
const ctxT = cbT.params[1];
|
|
546
530
|
if (ctxT.kind !== "union")
|
|
547
|
-
throw new
|
|
548
|
-
const def =
|
|
531
|
+
throw new InternalCompilerError("emitter bug: SNI answer ctx param not a union");
|
|
532
|
+
const def = emitter.unionsById.get(ctxT.unionId);
|
|
549
533
|
const ctxTag = def ? def.arms.findIndex((a) => a.kind === "secureCtx") : -1;
|
|
550
534
|
if (ctxTag < 0)
|
|
551
|
-
throw new
|
|
535
|
+
throw new InternalCompilerError("emitter bug: SNI answer ctx union lacks its SecureContext arm");
|
|
552
536
|
params.push("ScrUnion *sc_ctx");
|
|
553
537
|
body.push(` ScrSecureCtx *sc_c = sc_ctx->tag == ${ctxTag} ? scr_secure_ctx_retain((ScrSecureCtx *)scr_union_peek(sc_ctx)) : NULL;`, ` scr_union_release(sc_ctx);`);
|
|
554
538
|
ctx = "sc_c";
|
|
@@ -557,8 +541,8 @@ export function sniAnswerThunkFor(E, cbT) {
|
|
|
557
541
|
if (nparams >= 1)
|
|
558
542
|
body.push(` scr_union_release(sc_err);`);
|
|
559
543
|
body.push(` scr_tls_sni_answer(sc_self, sc_has_err, ${ctx});`);
|
|
560
|
-
|
|
561
|
-
|
|
544
|
+
emitter.walkerProtos.push(`static void ${sym}(${params.join(", ")});`);
|
|
545
|
+
emitter.walkerDefs.push(`static void ${sym}(${params.join(", ")}) {`, ...body, `}`);
|
|
562
546
|
return sym;
|
|
563
547
|
}
|
|
564
548
|
/** Interned Promise.race fulfillment adapter: converts a settled entry's
|
|
@@ -569,29 +553,29 @@ export function sniAnswerThunkFor(E, cbT) {
|
|
|
569
553
|
* entry re-tags arm-wise (canonical arm order makes the mapping a
|
|
570
554
|
* typeKey lookup). Rejections never reach adapters — the runtime copies
|
|
571
555
|
* them raw. */
|
|
572
|
-
export function raceAdapterFor(
|
|
556
|
+
export function raceAdapterFor(emitter, from, to) {
|
|
573
557
|
if (typeEquals(from, to))
|
|
574
558
|
return "scr_promise_adapt_copy";
|
|
575
559
|
const key = `${typeKey(from)}=>${typeKey(to)}`;
|
|
576
|
-
let sym =
|
|
560
|
+
let sym = emitter.raceThunks.get(key);
|
|
577
561
|
if (sym)
|
|
578
562
|
return sym;
|
|
579
|
-
sym = mangleRaceThunk(
|
|
580
|
-
|
|
563
|
+
sym = mangleRaceThunk(emitter.raceThunks.size);
|
|
564
|
+
emitter.raceThunks.set(key, sym);
|
|
581
565
|
if (to.kind !== "union")
|
|
582
|
-
throw new
|
|
583
|
-
const toDef =
|
|
566
|
+
throw new InternalCompilerError("emitter bug: race adapter to a non-union");
|
|
567
|
+
const toDef = emitter.unionsById.get(to.unionId);
|
|
584
568
|
if (!toDef)
|
|
585
|
-
throw new
|
|
569
|
+
throw new InternalCompilerError("emitter bug: race adapter to an unknown union");
|
|
586
570
|
const tagOf = (t) => {
|
|
587
571
|
const tag = toDef.arms.findIndex((a) => typeEquals(a, t));
|
|
588
572
|
if (tag < 0)
|
|
589
|
-
throw new
|
|
573
|
+
throw new InternalCompilerError("emitter bug: race adapter arm missing (frontend must fence)");
|
|
590
574
|
return tag;
|
|
591
575
|
};
|
|
592
576
|
const rv = vAdapters(to);
|
|
593
|
-
const fulfill = (value) => `scr_promise_fulfill_ref(sc_dst, ${value}, ${rv.retain}, ${rv.release}, ${
|
|
594
|
-
|
|
577
|
+
const fulfill = (value) => `scr_promise_fulfill_ref(sc_dst, ${value}, ${rv.retain}, ${rv.release}, ${emitter.traceArgC(to)});`;
|
|
578
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrPromise *sc_dst, ScrPromise *sc_src);`);
|
|
595
579
|
if (from.kind !== "union") {
|
|
596
580
|
// One arm wrap, straight off the payload accessors.
|
|
597
581
|
const tag = tagOf(from);
|
|
@@ -608,22 +592,22 @@ export function raceAdapterFor(E, from, to) {
|
|
|
608
592
|
break;
|
|
609
593
|
default: {
|
|
610
594
|
const fv = vAdapters(from);
|
|
611
|
-
value = `scr_union_new_ref(${tag}, scr_promise_payload_ref(sc_src), ${fv.retain}, ${fv.release}, ${
|
|
595
|
+
value = `scr_union_new_ref(${tag}, scr_promise_payload_ref(sc_src), ${fv.retain}, ${fv.release}, ${emitter.traceArgC(from)})`;
|
|
612
596
|
}
|
|
613
597
|
}
|
|
614
|
-
|
|
598
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrPromise *sc_dst, ScrPromise *sc_src) {`, ` ${fulfill(value)}`, `}`);
|
|
615
599
|
return sym;
|
|
616
600
|
}
|
|
617
601
|
// Sub-union re-tag: switch over the entry's arms, rebuild under the
|
|
618
602
|
// result's tags (payloads retained through each arm's own adapters).
|
|
619
|
-
const fromDef =
|
|
603
|
+
const fromDef = emitter.unionsById.get(from.unionId);
|
|
620
604
|
if (!fromDef)
|
|
621
|
-
throw new
|
|
605
|
+
throw new InternalCompilerError("emitter bug: race adapter from an unknown union");
|
|
622
606
|
const cases = fromDef.arms.map((arm, i) => {
|
|
623
607
|
const tag = tagOf(arm);
|
|
624
608
|
let build;
|
|
625
609
|
if (isUnitType(arm)) {
|
|
626
|
-
build =
|
|
610
|
+
build = emitter.unitInstanceRef(to.unionId, tag);
|
|
627
611
|
}
|
|
628
612
|
else if (arm.kind === "f64") {
|
|
629
613
|
build = `scr_union_new_f64(${tag}, scr_union_get_f64(sc_u))`;
|
|
@@ -633,11 +617,11 @@ export function raceAdapterFor(E, from, to) {
|
|
|
633
617
|
}
|
|
634
618
|
else {
|
|
635
619
|
const av = vAdapters(arm);
|
|
636
|
-
build = `scr_union_new_ref(${tag}, ${av.retain}(scr_union_peek(sc_u)), ${av.retain}, ${av.release}, ${
|
|
620
|
+
build = `scr_union_new_ref(${tag}, ${av.retain}(scr_union_peek(sc_u)), ${av.retain}, ${av.release}, ${emitter.traceArgC(arm)})`;
|
|
637
621
|
}
|
|
638
622
|
return ` case ${i}: sc_v = ${build}; break;`;
|
|
639
623
|
});
|
|
640
|
-
|
|
624
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrPromise *sc_dst, ScrPromise *sc_src) {`, ` ScrUnion *sc_u = (ScrUnion *)scr_promise_payload_ref(sc_src);`, ` ScrUnion *sc_v = NULL;`, ` switch (sc_u->tag) {`, ...cases, ` default: break;`, ` }`, ` scr_union_release(sc_u);`, ` ${fulfill("sc_v")}`, `}`);
|
|
641
625
|
return sym;
|
|
642
626
|
}
|
|
643
627
|
/** Interned generator-resume result builder: reads the post-resume state
|
|
@@ -649,18 +633,18 @@ export function raceAdapterFor(E, from, to) {
|
|
|
649
633
|
* a present completion value wraps the same way and an empty OUT is
|
|
650
634
|
* JS's undefined (the interned undefined arm — or the dyn undefined
|
|
651
635
|
* when V is dyn, the any/unknown channel). */
|
|
652
|
-
export function genResultThunkFor(
|
|
636
|
+
export function genResultThunkFor(emitter, genT, recT) {
|
|
653
637
|
const key = typeKey(genT);
|
|
654
|
-
let sym =
|
|
638
|
+
let sym = emitter.genResThunks.get(key);
|
|
655
639
|
if (sym)
|
|
656
640
|
return sym;
|
|
657
|
-
sym = mangleGenResThunk(
|
|
658
|
-
|
|
641
|
+
sym = mangleGenResThunk(emitter.genResThunks.size);
|
|
642
|
+
emitter.genResThunks.set(key, sym);
|
|
659
643
|
const struct = mangleRecordStruct(recT.shapeId);
|
|
660
|
-
const shape =
|
|
644
|
+
const shape = emitter.mod.records?.find((r) => r.id === recT.shapeId);
|
|
661
645
|
const valueT = shape?.fields.find((f) => f.name === "value")?.type;
|
|
662
646
|
if (!valueT)
|
|
663
|
-
throw new
|
|
647
|
+
throw new InternalCompilerError("emitter bug: genResume record lacks its value field");
|
|
664
648
|
const lines = [
|
|
665
649
|
`static ${struct} *${sym}(ScrGen *sc_g) {`,
|
|
666
650
|
` ${struct} *sc_r = ${mangleRecordNew(recT.shapeId)}();`,
|
|
@@ -673,20 +657,20 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
673
657
|
}
|
|
674
658
|
else {
|
|
675
659
|
if (valueT.kind !== "union") {
|
|
676
|
-
throw new
|
|
660
|
+
throw new InternalCompilerError("emitter bug: genResume value slot is neither dyn nor a union");
|
|
677
661
|
}
|
|
678
|
-
const def =
|
|
662
|
+
const def = emitter.unionsById.get(valueT.unionId);
|
|
679
663
|
if (!def)
|
|
680
|
-
throw new
|
|
664
|
+
throw new InternalCompilerError("emitter bug: genResume value union unknown");
|
|
681
665
|
const tagOf = (t) => {
|
|
682
666
|
const tag = def.arms.findIndex((a) => typeEquals(a, t));
|
|
683
667
|
if (tag < 0)
|
|
684
|
-
throw new
|
|
668
|
+
throw new InternalCompilerError("emitter bug: genResume value union lacks an arm");
|
|
685
669
|
return tag;
|
|
686
670
|
};
|
|
687
671
|
const undefTag = def.arms.findIndex((a) => a.kind === "undefinedT");
|
|
688
672
|
if (undefTag < 0)
|
|
689
|
-
throw new
|
|
673
|
+
throw new InternalCompilerError("emitter bug: genResume value union lacks undefined");
|
|
690
674
|
// Lines that leave the wrapped value in `sc_v`, taking OUT's payload.
|
|
691
675
|
const wrapFrom = (srcT) => {
|
|
692
676
|
if (srcT.kind === "f64") {
|
|
@@ -698,7 +682,7 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
698
682
|
if (srcT.kind !== "union") {
|
|
699
683
|
const v = vAdapters(srcT);
|
|
700
684
|
return [
|
|
701
|
-
` sc_v = scr_union_new_ref(${tagOf(srcT)}, scr_gen_take_out_ref(sc_g), ${v.retain}, ${v.release}, ${
|
|
685
|
+
` sc_v = scr_union_new_ref(${tagOf(srcT)}, scr_gen_take_out_ref(sc_g), ${v.retain}, ${v.release}, ${emitter.traceArgC(srcT)});`,
|
|
702
686
|
];
|
|
703
687
|
}
|
|
704
688
|
// A union channel: OUT holds the union box itself. Identical V
|
|
@@ -707,14 +691,14 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
707
691
|
if (typeEquals(srcT, valueT)) {
|
|
708
692
|
return [` sc_v = (ScrUnion *)scr_gen_take_out_ref(sc_g);`];
|
|
709
693
|
}
|
|
710
|
-
const srcDef =
|
|
694
|
+
const srcDef = emitter.unionsById.get(srcT.unionId);
|
|
711
695
|
if (!srcDef)
|
|
712
|
-
throw new
|
|
696
|
+
throw new InternalCompilerError("emitter bug: genResume channel union unknown");
|
|
713
697
|
const cases = srcDef.arms.map((arm, i) => {
|
|
714
698
|
const tag = tagOf(arm);
|
|
715
699
|
let build;
|
|
716
700
|
if (isUnitType(arm)) {
|
|
717
|
-
build =
|
|
701
|
+
build = emitter.unitInstanceRef(valueT.unionId, tag);
|
|
718
702
|
}
|
|
719
703
|
else if (arm.kind === "f64") {
|
|
720
704
|
build = `scr_union_new_f64(${tag}, scr_union_get_f64(sc_u))`;
|
|
@@ -724,7 +708,7 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
724
708
|
}
|
|
725
709
|
else {
|
|
726
710
|
const av = vAdapters(arm);
|
|
727
|
-
build = `scr_union_new_ref(${tag}, ${av.retain}(scr_union_peek(sc_u)), ${av.retain}, ${av.release}, ${
|
|
711
|
+
build = `scr_union_new_ref(${tag}, ${av.retain}(scr_union_peek(sc_u)), ${av.retain}, ${av.release}, ${emitter.traceArgC(arm)})`;
|
|
728
712
|
}
|
|
729
713
|
return ` case ${i}: sc_v = ${build}; break;`;
|
|
730
714
|
});
|
|
@@ -732,12 +716,12 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
732
716
|
` { ScrUnion *sc_u = (ScrUnion *)scr_gen_take_out_ref(sc_g);`,
|
|
733
717
|
` switch (sc_u->tag) {`,
|
|
734
718
|
...cases,
|
|
735
|
-
` default: sc_v = ${
|
|
719
|
+
` default: sc_v = ${emitter.unitInstanceRef(valueT.unionId, undefTag)}; break;`,
|
|
736
720
|
` }`,
|
|
737
721
|
` scr_union_release(sc_u); }`,
|
|
738
722
|
];
|
|
739
723
|
};
|
|
740
|
-
const undefLine = ` sc_v = ${
|
|
724
|
+
const undefLine = ` sc_v = ${emitter.unitInstanceRef(valueT.unionId, undefTag)};`;
|
|
741
725
|
lines.push(` ScrUnion *sc_v;`);
|
|
742
726
|
lines.push(` if (!sc_d) {`);
|
|
743
727
|
// yieldT VOID marks a generator that can never yield (TS's `never`):
|
|
@@ -750,20 +734,20 @@ export function genResultThunkFor(E, genT, recT) {
|
|
|
750
734
|
lines.push(` sc_r->${mangleField("value")} = sc_v;`);
|
|
751
735
|
}
|
|
752
736
|
lines.push(` return sc_r;`, `}`);
|
|
753
|
-
|
|
754
|
-
|
|
737
|
+
emitter.walkerProtos.push(`static ${struct} *${sym}(ScrGen *sc_g);`);
|
|
738
|
+
emitter.walkerDefs.push(...lines, ``);
|
|
755
739
|
return sym;
|
|
756
740
|
}
|
|
757
741
|
/** Interned per inner-type resolve thunk for ref-kind new Promise. */
|
|
758
|
-
export function resolveThunkFor(
|
|
742
|
+
export function resolveThunkFor(emitter, inner) {
|
|
759
743
|
const key = typeKey(inner);
|
|
760
|
-
let sym =
|
|
744
|
+
let sym = emitter.resolveThunks.get(key);
|
|
761
745
|
if (!sym) {
|
|
762
|
-
sym = mangleResolveThunk(
|
|
763
|
-
|
|
746
|
+
sym = mangleResolveThunk(emitter.resolveThunks.size);
|
|
747
|
+
emitter.resolveThunks.set(key, sym);
|
|
764
748
|
const v = vAdapters(inner);
|
|
765
|
-
|
|
766
|
-
|
|
749
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_self, ${cDecl(inner, "sc_v")});`);
|
|
750
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_self, ${cDecl(inner, "sc_v")}) {`, ` scr_resolve_ref_impl(sc_self, sc_v, ${v.retain}, ${v.release}, ${emitter.traceArgC(inner)});`, `}`);
|
|
767
751
|
}
|
|
768
752
|
return sym;
|
|
769
753
|
}
|
|
@@ -773,16 +757,16 @@ export function resolveThunkFor(E, inner) {
|
|
|
773
757
|
* the tuple, so reads agree with writes), retains each refcounted value
|
|
774
758
|
* (the callee owns +1 per the universal convention; f64/bool copy), and
|
|
775
759
|
* calls cb->fn behind its exact C signature. Interned per func-type key. */
|
|
776
|
-
export function emitterInvokeThunkFor(
|
|
760
|
+
export function emitterInvokeThunkFor(emitter, cbT) {
|
|
777
761
|
if (cbT.kind !== "func") {
|
|
778
|
-
throw new
|
|
762
|
+
throw new InternalCompilerError("emitter bug: emitter.on listener not a func (frontend must fence)");
|
|
779
763
|
}
|
|
780
764
|
const key = typeKey(cbT);
|
|
781
|
-
let sym =
|
|
765
|
+
let sym = emitter.emitterInvokeThunks.get(key);
|
|
782
766
|
if (sym)
|
|
783
767
|
return sym;
|
|
784
|
-
sym = mangleEmitterInvokeThunk(
|
|
785
|
-
|
|
768
|
+
sym = mangleEmitterInvokeThunk(emitter.emitterInvokeThunks.size);
|
|
769
|
+
emitter.emitterInvokeThunks.set(key, sym);
|
|
786
770
|
const reads = [];
|
|
787
771
|
const passed = [];
|
|
788
772
|
cbT.params.forEach((p, i) => {
|
|
@@ -807,8 +791,8 @@ export function emitterInvokeThunkFor(E, cbT) {
|
|
|
807
791
|
// listener return values.
|
|
808
792
|
const retC = cbT.ret.kind === "void" ? "void" : cType(cbT.ret).trim();
|
|
809
793
|
const invoke = `((${retC} (*)(${sigParams}))sc_cb->fn)(${["sc_cb", ...passed].join(", ")})`;
|
|
810
|
-
|
|
811
|
-
|
|
794
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, va_list sc_ap);`);
|
|
795
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, va_list sc_ap) {`, ...(cbT.params.length === 0 ? [` (void)sc_ap;`] : reads), ...(cbT.ret.kind === "void"
|
|
812
796
|
? [` ${invoke};`]
|
|
813
797
|
: isRefCounted(cbT.ret)
|
|
814
798
|
? [` ${retC} sc_r = ${invoke};`, ` if (sc_r) ${releaseCallC(cbT.ret, "sc_r")};`]
|
|
@@ -823,16 +807,16 @@ export function emitterInvokeThunkFor(E, cbT) {
|
|
|
823
807
|
* scr_stream_final_done, "d" scr_stream_destroy_done, "t"
|
|
824
808
|
* scr_stream_transform_done, "l" scr_stream_flush_done. Args arrive
|
|
825
809
|
* callee-owned (+1) per the universal convention and are released here. */
|
|
826
|
-
|
|
810
|
+
function streamDoneFnFor(emitter, kind, doneT) {
|
|
827
811
|
if (doneT.kind !== "func") {
|
|
828
|
-
throw new
|
|
812
|
+
throw new InternalCompilerError("emitter bug: stream done callback not a func (frontend must fence)");
|
|
829
813
|
}
|
|
830
814
|
const key = `${kind}:${typeKey(doneT)}`;
|
|
831
|
-
let sym =
|
|
815
|
+
let sym = emitter.streamDoneFns.get(key);
|
|
832
816
|
if (sym)
|
|
833
817
|
return sym;
|
|
834
|
-
sym = mangleStreamDoneFn(
|
|
835
|
-
|
|
818
|
+
sym = mangleStreamDoneFn(emitter.streamDoneFns.size);
|
|
819
|
+
emitter.streamDoneFns.set(key, sym);
|
|
836
820
|
const params = ["ScrClosure *sc_self"];
|
|
837
821
|
const body = [
|
|
838
822
|
` ScrStream *sc_s = (ScrStream *)scr_box_get_ref(sc_self->caps[0]); /* +1 */`,
|
|
@@ -841,11 +825,11 @@ export function streamDoneFnFor(E, kind, doneT) {
|
|
|
841
825
|
const errT = doneT.params[0];
|
|
842
826
|
if (errT !== undefined) {
|
|
843
827
|
if (errT.kind !== "union")
|
|
844
|
-
throw new
|
|
845
|
-
const def =
|
|
828
|
+
throw new InternalCompilerError("emitter bug: stream done err param not a union");
|
|
829
|
+
const def = emitter.unionsById.get(errT.unionId);
|
|
846
830
|
const errTag = def ? def.arms.findIndex((a) => a.kind === "object") : -1;
|
|
847
831
|
if (errTag < 0)
|
|
848
|
-
throw new
|
|
832
|
+
throw new InternalCompilerError("emitter bug: stream done err union lacks its Error arm");
|
|
849
833
|
params.push("ScrUnion *sc_e");
|
|
850
834
|
body.push(` if (sc_e && sc_e->tag == ${errTag}) sc_err = scr_error_retain((ScrError *)scr_union_peek(sc_e));`);
|
|
851
835
|
}
|
|
@@ -855,8 +839,8 @@ export function streamDoneFnFor(E, kind, doneT) {
|
|
|
855
839
|
body.push(...dataLines);
|
|
856
840
|
if (dataT !== undefined) {
|
|
857
841
|
if (dataT.kind !== "union")
|
|
858
|
-
throw new
|
|
859
|
-
const def =
|
|
842
|
+
throw new InternalCompilerError("emitter bug: stream done data param not a union");
|
|
843
|
+
const def = emitter.unionsById.get(dataT.unionId);
|
|
860
844
|
const bytesTag = def ? def.arms.findIndex((a) => a.kind === "bytes") : -1;
|
|
861
845
|
const strTag = def ? def.arms.findIndex((a) => a.kind === "string") : -1;
|
|
862
846
|
params.push("ScrUnion *sc_d");
|
|
@@ -874,8 +858,8 @@ export function streamDoneFnFor(E, kind, doneT) {
|
|
|
874
858
|
const tail = kind === "t" || kind === "l"
|
|
875
859
|
? `${entry}(sc_s, sc_err, sc_data, sc_dataStr);`
|
|
876
860
|
: `${entry}(sc_s, sc_err);`;
|
|
877
|
-
|
|
878
|
-
|
|
861
|
+
emitter.walkerProtos.push(`static void ${sym}(${params.join(", ")});`);
|
|
862
|
+
emitter.walkerDefs.push(`static void ${sym}(${params.join(", ")}) {`, ...body, ` ${tail} /* moves sc_err/sc_data; borrows sc_s */`, ` scr_stream_release(sc_s);`, ...(errT !== undefined ? [` if (sc_e) scr_union_release(sc_e);`] : []), ...((kind === "t" || kind === "l") && dataT !== undefined ? [` if (sc_d) scr_union_release(sc_d);`] : []), `}`, ``);
|
|
879
863
|
return sym;
|
|
880
864
|
}
|
|
881
865
|
/** The stream-'data' listener invoke adapter for one listener func type:
|
|
@@ -887,19 +871,19 @@ export function streamDoneFnFor(E, kind, doneT) {
|
|
|
887
871
|
* just hand the value over — SEMANTICS.md). Zero-parameter listeners
|
|
888
872
|
* ignore both slots; DYN-parameter listeners (the JS lane's adapter,
|
|
889
873
|
* emitter.onDataDyn) box by tag, which is always right. */
|
|
890
|
-
export function streamDataThunkFor(
|
|
874
|
+
export function streamDataThunkFor(emitter, cbT) {
|
|
891
875
|
if (cbT.kind !== "func") {
|
|
892
|
-
throw new
|
|
876
|
+
throw new InternalCompilerError("emitter bug: stream data listener not a func (frontend must fence)");
|
|
893
877
|
}
|
|
894
878
|
const key = `data:${typeKey(cbT)}`;
|
|
895
|
-
let sym =
|
|
879
|
+
let sym = emitter.emitterInvokeThunks.get(key);
|
|
896
880
|
if (sym)
|
|
897
881
|
return sym;
|
|
898
|
-
sym = mangleEmitterInvokeThunk(
|
|
899
|
-
|
|
882
|
+
sym = mangleEmitterInvokeThunk(emitter.emitterInvokeThunks.size);
|
|
883
|
+
emitter.emitterInvokeThunks.set(key, sym);
|
|
900
884
|
const p = cbT.params[0];
|
|
901
885
|
if (cbT.params.length > 1 || (p && p.kind !== "bytes" && p.kind !== "string" && p.kind !== "dyn")) {
|
|
902
|
-
throw new
|
|
886
|
+
throw new InternalCompilerError("emitter bug: stream data listener param shape (frontend must fence)");
|
|
903
887
|
}
|
|
904
888
|
const body = [
|
|
905
889
|
` ScrBytes *sc_b = va_arg(sc_ap, ScrBytes *);`,
|
|
@@ -925,8 +909,8 @@ export function streamDataThunkFor(E, cbT) {
|
|
|
925
909
|
const sigParams = ["ScrClosure *", ...cbT.params.map((q) => cType(q).trim())].join(", ");
|
|
926
910
|
const retC = cbT.ret.kind === "void" ? "void" : cType(cbT.ret).trim();
|
|
927
911
|
const invoke = `((${retC} (*)(${sigParams}))sc_cb->fn)(${passed.join(", ")})`;
|
|
928
|
-
|
|
929
|
-
|
|
912
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, va_list sc_ap);`);
|
|
913
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, va_list sc_ap) {`, ...body, ...(cbT.ret.kind === "void"
|
|
930
914
|
? [` ${invoke};`]
|
|
931
915
|
: isRefCounted(cbT.ret)
|
|
932
916
|
? [` ${retC} sc_r = ${invoke};`, ` if (sc_r) ${releaseCallC(cbT.ret, "sc_r")};`]
|
|
@@ -944,16 +928,16 @@ export function streamDataThunkFor(E, cbT) {
|
|
|
944
928
|
* never complete, exactly Node. Kinds: "r" read(size), "w" write(chunk,
|
|
945
929
|
* enc, cb), "f" final(cb), "d" destroy(err, cb), "t" transform(chunk,
|
|
946
930
|
* enc, cb), "l" flush(cb). */
|
|
947
|
-
export function streamCbThunkFor(
|
|
931
|
+
export function streamCbThunkFor(emitter, kind, cbT) {
|
|
948
932
|
if (cbT.kind !== "func") {
|
|
949
|
-
throw new
|
|
933
|
+
throw new InternalCompilerError("emitter bug: stream option callback not a func (frontend must fence)");
|
|
950
934
|
}
|
|
951
935
|
const key = `${kind}:${typeKey(cbT)}`;
|
|
952
|
-
let sym =
|
|
936
|
+
let sym = emitter.streamCbThunks.get(key);
|
|
953
937
|
if (sym)
|
|
954
938
|
return sym;
|
|
955
|
-
sym = mangleStreamCbThunk(
|
|
956
|
-
|
|
939
|
+
sym = mangleStreamCbThunk(emitter.streamCbThunks.size);
|
|
940
|
+
emitter.streamCbThunks.set(key, sym);
|
|
957
941
|
// The runtime-facing C signatures, per kind.
|
|
958
942
|
const runtimeParams = kind === "r" ? ["ScrStream *sc_s", "double sc_size"] :
|
|
959
943
|
kind === "w" || kind === "t" ? ["ScrStream *sc_s", "ScrBytes *sc_chunk"] :
|
|
@@ -967,7 +951,7 @@ export function streamCbThunkFor(E, kind, cbT) {
|
|
|
967
951
|
const declared = cbT.params;
|
|
968
952
|
const hasThis = declared[0] !== undefined && declared[0].kind === "object";
|
|
969
953
|
if (declared.length === 0) {
|
|
970
|
-
throw new
|
|
954
|
+
throw new InternalCompilerError("emitter bug: stream option callback with no params (frontend must fence)");
|
|
971
955
|
}
|
|
972
956
|
const passed = hasThis
|
|
973
957
|
? ["sc_cb", `(${cType(declared[0]).trim()})scr_stream_retain(sc_s)`]
|
|
@@ -977,7 +961,7 @@ export function streamCbThunkFor(E, kind, cbT) {
|
|
|
977
961
|
const full = (kind === "r" ? 1 : kind === "w" || kind === "t" ? 3 : kind === "d" ? 2 : 1) + off;
|
|
978
962
|
// "e" (the finished/pipeline callback): ONE Node position — the error.
|
|
979
963
|
if (declared.length > full) {
|
|
980
|
-
throw new
|
|
964
|
+
throw new InternalCompilerError(`emitter bug: stream '${kind}' callback declares ${declared.length} params (frontend must fence)`);
|
|
981
965
|
}
|
|
982
966
|
for (let i = off; i < declared.length; i++) {
|
|
983
967
|
const p = declared[i];
|
|
@@ -1019,7 +1003,7 @@ export function streamCbThunkFor(E, kind, cbT) {
|
|
|
1019
1003
|
passed.push(`sc_done`);
|
|
1020
1004
|
}
|
|
1021
1005
|
else {
|
|
1022
|
-
throw new
|
|
1006
|
+
throw new InternalCompilerError(`emitter bug: stream '${kind}' dyn callback param ${i} has no adapter`);
|
|
1023
1007
|
}
|
|
1024
1008
|
continue;
|
|
1025
1009
|
}
|
|
@@ -1037,26 +1021,26 @@ export function streamCbThunkFor(E, kind, cbT) {
|
|
|
1037
1021
|
// undefined` (the @types signature); success prefers the undefined
|
|
1038
1022
|
// arm there (Node calls the eos callback with NO arguments).
|
|
1039
1023
|
if (p.kind !== "union")
|
|
1040
|
-
throw new
|
|
1041
|
-
const def =
|
|
1024
|
+
throw new InternalCompilerError("emitter bug: stream destroy err param not a union");
|
|
1025
|
+
const def = emitter.unionsById.get(p.unionId);
|
|
1042
1026
|
const errTag = def ? def.arms.findIndex((a) => a.kind === "object") : -1;
|
|
1043
1027
|
const undefTag = kind === "e" && def ? def.arms.findIndex((a) => a.kind === "undefinedT") : -1;
|
|
1044
1028
|
const nullTag = def
|
|
1045
1029
|
? (undefTag >= 0 ? undefTag : def.arms.findIndex((a) => a.kind === "nullT"))
|
|
1046
1030
|
: -1;
|
|
1047
1031
|
if (errTag < 0 || nullTag < 0)
|
|
1048
|
-
throw new
|
|
1049
|
-
body.push(` ScrUnion *sc_eu = sc_err ? scr_union_new_ref(${errTag}, scr_error_retain(sc_err), &scr_error_retain_v, &scr_error_release_v, scr_error_trace_arg()) : scr_union_retain(${
|
|
1032
|
+
throw new InternalCompilerError("emitter bug: stream destroy err union lacks its arms");
|
|
1033
|
+
body.push(` ScrUnion *sc_eu = sc_err ? scr_union_new_ref(${errTag}, scr_error_retain(sc_err), &scr_error_retain_v, &scr_error_release_v, scr_error_trace_arg()) : scr_union_retain(${emitter.unitInstanceRef(p.unionId, nullTag)});`);
|
|
1050
1034
|
passed.push(`sc_eu`);
|
|
1051
1035
|
}
|
|
1052
1036
|
else if (isDonePos) {
|
|
1053
1037
|
const doneKind = kind; // "e" has no done position
|
|
1054
|
-
const doneFn = streamDoneFnFor(
|
|
1038
|
+
const doneFn = streamDoneFnFor(emitter, doneKind, p);
|
|
1055
1039
|
body.push(` ScrClosure *sc_done = scr_closure_new((void *)&${doneFn}, 1);`, ` sc_done->caps[0] = scr_box_new_obj(&scr_stream_retain_v, &scr_stream_release_v, &scr_stream_trace);`, ` scr_box_set_ref(sc_done->caps[0], scr_stream_retain(sc_s));`);
|
|
1056
1040
|
passed.push(`sc_done`);
|
|
1057
1041
|
}
|
|
1058
1042
|
else {
|
|
1059
|
-
throw new
|
|
1043
|
+
throw new InternalCompilerError(`emitter bug: stream '${kind}' callback param ${i} has no adapter`);
|
|
1060
1044
|
}
|
|
1061
1045
|
}
|
|
1062
1046
|
const sigParams = ["ScrClosure *", ...declared.map((p) => cType(p).trim())].join(", ");
|
|
@@ -1076,12 +1060,12 @@ export function streamCbThunkFor(E, kind, cbT) {
|
|
|
1076
1060
|
// callback results (`read: () => this.push(null)`).
|
|
1077
1061
|
const retC = cbT.ret.kind === "void" ? "void" : cType(cbT.ret).trim();
|
|
1078
1062
|
const invoke = `((${retC} (*)(${sigParams}))sc_cb->fn)(${passed.join(", ")})`;
|
|
1079
|
-
|
|
1080
|
-
|
|
1063
|
+
emitter.walkerProtos.push(`static void ${sym}(ScrClosure *sc_cb, ${runtimeParams.join(", ")});`);
|
|
1064
|
+
emitter.walkerDefs.push(`static void ${sym}(ScrClosure *sc_cb, ${runtimeParams.join(", ")}) {`, ...unused, ...body, ...(cbT.ret.kind === "void"
|
|
1081
1065
|
? [` ${invoke};`]
|
|
1082
1066
|
: isRefCounted(cbT.ret)
|
|
1083
1067
|
? [` ${retC} sc_r = ${invoke};`, ` if (sc_r) ${releaseCallC(cbT.ret, "sc_r")};`]
|
|
1084
1068
|
: [` (void)${invoke};`]), `}`, ``);
|
|
1085
1069
|
return sym;
|
|
1086
1070
|
}
|
|
1087
|
-
//# sourceMappingURL=
|
|
1071
|
+
//# sourceMappingURL=async.js.map
|