jz 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +315 -318
  2. package/bench/README.md +369 -0
  3. package/bench/bench.svg +102 -0
  4. package/cli.js +104 -30
  5. package/dist/interop.js +1 -0
  6. package/dist/jz.js +6024 -0
  7. package/index.d.ts +126 -0
  8. package/index.js +362 -84
  9. package/interop.js +159 -186
  10. package/jz.svg +5 -0
  11. package/jzify/arguments.js +97 -0
  12. package/jzify/bundler.js +382 -0
  13. package/jzify/classes.js +328 -0
  14. package/jzify/hoist-vars.js +177 -0
  15. package/jzify/index.js +51 -0
  16. package/jzify/names.js +37 -0
  17. package/jzify/switch.js +106 -0
  18. package/jzify/transform.js +349 -0
  19. package/layout.js +184 -0
  20. package/module/array.js +377 -176
  21. package/module/collection.js +639 -145
  22. package/module/console.js +55 -43
  23. package/module/core.js +264 -153
  24. package/module/date.js +15 -3
  25. package/module/function.js +73 -6
  26. package/module/index.js +2 -1
  27. package/module/json.js +226 -61
  28. package/module/math.js +551 -187
  29. package/module/number.js +327 -60
  30. package/module/object.js +474 -184
  31. package/module/regex.js +255 -25
  32. package/module/schema.js +24 -6
  33. package/module/simd.js +117 -0
  34. package/module/string.js +621 -226
  35. package/module/symbol.js +1 -1
  36. package/module/timer.js +9 -14
  37. package/module/typedarray.js +459 -73
  38. package/package.json +58 -14
  39. package/src/abi/index.js +39 -23
  40. package/src/abi/string.js +38 -41
  41. package/src/ast.js +460 -0
  42. package/src/autoload.js +29 -24
  43. package/src/bridge.js +111 -0
  44. package/src/compile/analyze-scans.js +824 -0
  45. package/src/compile/analyze.js +1600 -0
  46. package/src/compile/emit-assign.js +411 -0
  47. package/src/compile/emit.js +3512 -0
  48. package/src/compile/flow-types.js +103 -0
  49. package/src/{compile.js → compile/index.js} +778 -128
  50. package/src/{infer.js → compile/infer.js} +62 -98
  51. package/src/compile/loop-divmod.js +155 -0
  52. package/src/{narrow.js → compile/narrow.js} +409 -106
  53. package/src/compile/peel-stencil.js +261 -0
  54. package/src/compile/plan/advise.js +370 -0
  55. package/src/compile/plan/common.js +150 -0
  56. package/src/compile/plan/index.js +122 -0
  57. package/src/compile/plan/inline.js +682 -0
  58. package/src/compile/plan/literals.js +1199 -0
  59. package/src/compile/plan/loops.js +472 -0
  60. package/src/compile/plan/scope.js +649 -0
  61. package/src/compile/program-facts.js +423 -0
  62. package/src/ctx.js +220 -64
  63. package/src/ir.js +589 -172
  64. package/src/kind-traits.js +132 -0
  65. package/src/kind.js +524 -0
  66. package/src/op-policy.js +57 -0
  67. package/src/{optimize.js → optimize/index.js} +1432 -473
  68. package/src/optimize/vectorize.js +4660 -0
  69. package/src/param-reps.js +65 -0
  70. package/src/parse.js +44 -0
  71. package/src/{prepare.js → prepare/index.js} +649 -205
  72. package/src/prepare/lift-iife.js +149 -0
  73. package/src/reps.js +116 -0
  74. package/src/resolve.js +12 -3
  75. package/src/static.js +208 -0
  76. package/src/type.js +651 -0
  77. package/src/{assemble.js → wat/assemble.js} +275 -55
  78. package/src/wat/optimize.js +3938 -0
  79. package/transform.js +21 -0
  80. package/wasi.js +47 -5
  81. package/src/analyze.js +0 -3818
  82. package/src/emit.js +0 -3040
  83. package/src/jzify.js +0 -1580
  84. package/src/plan.js +0 -2132
  85. package/src/vectorize.js +0 -1088
  86. /package/src/{codegen.js → wat/codegen.js} +0 -0
package/module/symbol.js CHANGED
@@ -19,7 +19,7 @@
19
19
  */
20
20
 
21
21
  import { typed, asF64, mkPtrIR } from '../src/ir.js'
22
- import { emit } from '../src/emit.js'
22
+ import { emit } from '../src/bridge.js'
23
23
  import { err, inc, PTR } from '../src/ctx.js'
24
24
 
25
25
  const RESERVED = 16 // first user atom ID
package/module/timer.js CHANGED
@@ -27,17 +27,12 @@
27
27
  */
28
28
 
29
29
  import { typed, asF64, asI64, UNDEF_NAN, MAX_CLOSURE_ARITY, temp, tempI64 } from '../src/ir.js'
30
- import { emit } from '../src/emit.js'
31
- import { inc, PTR, LAYOUT } from '../src/ctx.js'
30
+ import { emit, deps, hostImport } from '../src/bridge.js'
31
+ import { inc, PTR, LAYOUT, declGlobal } from '../src/ctx.js'
32
32
 
33
33
  const MAX_TIMERS = 64
34
34
  const ENTRY_SIZE = 40
35
35
 
36
- const addImportOnce = (ctx, mod, name, fn) => {
37
- if (ctx.module.imports.some(i => i[1] === `"${mod}"` && i[2] === `"${name}"`)) return
38
- ctx.module.imports.push(['import', `"${mod}"`, `"${name}"`, fn])
39
- }
40
-
41
36
  // Shared "fire a NaN-boxed closure with 0 args" trampoline. Funcref index lives
42
37
  // in upper 16 bits of the pointer payload; remaining $ftN slots get UNDEF_NAN.
43
38
  // Closure is also passed as $__env so captures resolve via env-load.
@@ -55,7 +50,7 @@ const setupWasi = (ctx) => {
55
50
  // Always include init + tick + loop when timer module loads (structural, not per-emitter)
56
51
  inc('__timer_init', '__timer_tick', '__timer_loop')
57
52
 
58
- Object.assign(ctx.core.stdlibDeps, {
53
+ deps({
59
54
  __timer_init: ['__alloc'],
60
55
  __timer_add: ['__time_ns'],
61
56
  __timer_cancel: [],
@@ -68,7 +63,7 @@ const setupWasi = (ctx) => {
68
63
  // call_indirect always matches the $ftN type (env, argc, a0..a7)
69
64
  ctx.closure.floor = MAX_CLOSURE_ARITY
70
65
 
71
- addImportOnce(ctx, 'wasi_snapshot_preview1', 'clock_time_get',
66
+ hostImport('wasi_snapshot_preview1', 'clock_time_get',
72
67
  ['func', '$__clock_time_get', ['param', 'i32'], ['param', 'i64'], ['param', 'i32'], ['result', 'i32']])
73
68
 
74
69
  // __time_ns() → i64 — current monotonic nanoseconds
@@ -235,9 +230,9 @@ const setupWasi = (ctx) => {
235
230
  // $__timer_queue: i32 — base address of timer array
236
231
  // $__timer_next_id: i32 — next timer ID
237
232
  // $__timer_count: i32 — number of active timers
238
- ctx.scope.globals.set('__timer_queue', '(global $__timer_queue (mut i32) (i32.const 0))')
239
- ctx.scope.globals.set('__timer_next_id', '(global $__timer_next_id (mut i32) (i32.const 0))')
240
- ctx.scope.globals.set('__timer_count', '(global $__timer_count (mut i32) (i32.const 0))')
233
+ declGlobal('__timer_queue', 'i32')
234
+ declGlobal('__timer_next_id', 'i32')
235
+ declGlobal('__timer_count', 'i32')
241
236
 
242
237
  // Emitter: setTimeout(closure, delay) → timer_id
243
238
  ctx.core.emit['setTimeout'] = (closureExpr, delayExpr) => {
@@ -279,9 +274,9 @@ const setupJsHost = (ctx) => {
279
274
  // canonicalization at the wasm→JS boundary (same reason as env.print —
280
275
  // see module/console.js header). delay is a real numeric f64 (no NaN-box
281
276
  // hazard), repeat is i32, return is the timer id (numeric int).
282
- const needSetTimeout = () => addImportOnce(ctx, 'env', 'setTimeout',
277
+ const needSetTimeout = () => hostImport('env', 'setTimeout',
283
278
  ['func', '$__set_timeout', ['param', 'i64'], ['param', 'f64'], ['param', 'i32'], ['result', 'f64']])
284
- const needClearTimeout = () => addImportOnce(ctx, 'env', 'clearTimeout',
279
+ const needClearTimeout = () => hostImport('env', 'clearTimeout',
285
280
  ['func', '$__clear_timeout', ['param', 'f64'], ['result', 'f64']])
286
281
 
287
282
  ctx.core.stdlib['__invoke_closure'] = invokeClosureFn(true)