novac 2.1.1 → 2.2.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 (138) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +0 -0
  3. package/demo.nv +0 -0
  4. package/demo_builtins.nv +0 -0
  5. package/demo_http.nv +0 -0
  6. package/examples/bf.nv +69 -0
  7. package/examples/math.nv +21 -0
  8. package/kits/birdAPI/kitdef.js +954 -0
  9. package/kits/kitRNG/kitdef.js +740 -0
  10. package/kits/kitSSH/kitdef.js +1272 -0
  11. package/kits/kitadb/kitdef.js +606 -0
  12. package/kits/kitai/kitdef.js +2185 -0
  13. package/kits/kitcanvas/kitdef.js +914 -0
  14. package/kits/kitclippy/kitdef.js +925 -0
  15. package/kits/kitgps/kitdef.js +1862 -0
  16. package/kits/kitlibproc/kitdef.js +3 -2
  17. package/kits/kitmorse/kitdef.js +229 -0
  18. package/kits/kitmpatch/kitdef.js +906 -0
  19. package/kits/kitnet/kitdef.js +1401 -0
  20. package/kits/kitproto/kitdef.js +613 -0
  21. package/kits/kitqr/kitdef.js +637 -0
  22. package/kits/kitrequire/kitdef.js +1599 -0
  23. package/kits/libtea/kitdef.js +2691 -0
  24. package/kits/libterm/kitdef.js +2 -0
  25. package/novac/LICENSE +21 -0
  26. package/novac/README.md +1823 -0
  27. package/novac/bin/novac +950 -0
  28. package/novac/bin/nvc +522 -0
  29. package/novac/bin/nvml +542 -0
  30. package/novac/demo.nv +245 -0
  31. package/novac/demo_builtins.nv +209 -0
  32. package/novac/demo_http.nv +62 -0
  33. package/novac/examples/bf.nv +69 -0
  34. package/novac/examples/math.nv +21 -0
  35. package/novac/kits/kitai/kitdef.js +2185 -0
  36. package/novac/kits/kitansi/kitdef.js +1402 -0
  37. package/novac/kits/kitformat/kitdef.js +1485 -0
  38. package/novac/kits/kitgps/kitdef.js +1862 -0
  39. package/novac/kits/kitlibfs/kitdef.js +231 -0
  40. package/{examples/example-project/nova_modules → novac/kits}/kitlibproc/kitdef.js +3 -2
  41. package/novac/kits/kitmatrix/ex.js +19 -0
  42. package/novac/kits/kitmatrix/kitdef.js +960 -0
  43. package/novac/kits/kitmpatch/kitdef.js +906 -0
  44. package/novac/kits/kitnovacweb/README.md +1572 -0
  45. package/novac/kits/kitnovacweb/demo.nv +12 -0
  46. package/novac/kits/kitnovacweb/demo.nvml +71 -0
  47. package/novac/kits/kitnovacweb/index.nova +12 -0
  48. package/novac/kits/kitnovacweb/kitdef.js +692 -0
  49. package/novac/kits/kitnovacweb/nova.kit.json +8 -0
  50. package/novac/kits/kitnovacweb/nvml/executor.js +739 -0
  51. package/novac/kits/kitnovacweb/nvml/index.js +67 -0
  52. package/novac/kits/kitnovacweb/nvml/lexer.js +263 -0
  53. package/novac/kits/kitnovacweb/nvml/parser.js +508 -0
  54. package/novac/kits/kitnovacweb/nvml/renderer.js +924 -0
  55. package/novac/kits/kitparse/kitdef.js +1688 -0
  56. package/novac/kits/kitregex++/kitdef.js +1353 -0
  57. package/novac/kits/kitrequire/kitdef.js +1599 -0
  58. package/novac/kits/kitx11/kitdef.js +1 -0
  59. package/novac/kits/kitx11/kitx11.js +2472 -0
  60. package/novac/kits/kitx11/kitx11_conn.js +948 -0
  61. package/novac/kits/kitx11/kitx11_worker.js +121 -0
  62. package/novac/kits/libterm/ex.js +285 -0
  63. package/novac/kits/libterm/kitdef.js +1927 -0
  64. package/novac/node_modules/chalk/license +9 -0
  65. package/novac/node_modules/chalk/package.json +83 -0
  66. package/novac/node_modules/chalk/readme.md +297 -0
  67. package/novac/node_modules/chalk/source/index.d.ts +325 -0
  68. package/novac/node_modules/chalk/source/index.js +225 -0
  69. package/novac/node_modules/chalk/source/utilities.js +33 -0
  70. package/novac/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
  71. package/novac/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
  72. package/novac/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
  73. package/novac/node_modules/chalk/source/vendor/supports-color/browser.js +34 -0
  74. package/novac/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
  75. package/novac/node_modules/chalk/source/vendor/supports-color/index.js +190 -0
  76. package/novac/node_modules/commander/LICENSE +22 -0
  77. package/novac/node_modules/commander/Readme.md +1176 -0
  78. package/novac/node_modules/commander/esm.mjs +16 -0
  79. package/novac/node_modules/commander/index.js +24 -0
  80. package/novac/node_modules/commander/lib/argument.js +150 -0
  81. package/novac/node_modules/commander/lib/command.js +2777 -0
  82. package/novac/node_modules/commander/lib/error.js +39 -0
  83. package/novac/node_modules/commander/lib/help.js +747 -0
  84. package/novac/node_modules/commander/lib/option.js +380 -0
  85. package/novac/node_modules/commander/lib/suggestSimilar.js +101 -0
  86. package/novac/node_modules/commander/package-support.json +19 -0
  87. package/novac/node_modules/commander/package.json +82 -0
  88. package/novac/node_modules/commander/typings/esm.d.mts +3 -0
  89. package/novac/node_modules/commander/typings/index.d.ts +1113 -0
  90. package/novac/node_modules/node-addon-api/LICENSE.md +9 -0
  91. package/novac/node_modules/node-addon-api/README.md +95 -0
  92. package/novac/node_modules/node-addon-api/common.gypi +21 -0
  93. package/novac/node_modules/node-addon-api/except.gypi +25 -0
  94. package/novac/node_modules/node-addon-api/index.js +14 -0
  95. package/novac/node_modules/node-addon-api/napi-inl.deprecated.h +186 -0
  96. package/novac/node_modules/node-addon-api/napi-inl.h +7165 -0
  97. package/novac/node_modules/node-addon-api/napi.h +3364 -0
  98. package/novac/node_modules/node-addon-api/node_addon_api.gyp +42 -0
  99. package/novac/node_modules/node-addon-api/node_api.gyp +9 -0
  100. package/novac/node_modules/node-addon-api/noexcept.gypi +26 -0
  101. package/novac/node_modules/node-addon-api/package-support.json +21 -0
  102. package/novac/node_modules/node-addon-api/package.json +480 -0
  103. package/novac/node_modules/node-addon-api/tools/README.md +73 -0
  104. package/novac/node_modules/node-addon-api/tools/check-napi.js +99 -0
  105. package/novac/node_modules/node-addon-api/tools/clang-format.js +71 -0
  106. package/novac/node_modules/node-addon-api/tools/conversion.js +301 -0
  107. package/novac/node_modules/serialize-javascript/LICENSE +27 -0
  108. package/novac/node_modules/serialize-javascript/README.md +149 -0
  109. package/novac/node_modules/serialize-javascript/index.js +297 -0
  110. package/novac/node_modules/serialize-javascript/package.json +33 -0
  111. package/novac/package.json +27 -0
  112. package/novac/scripts/update-bin.js +24 -0
  113. package/novac/src/core/bstd.js +1035 -0
  114. package/novac/src/core/config.js +155 -0
  115. package/novac/src/core/describe.js +187 -0
  116. package/novac/src/core/emitter.js +499 -0
  117. package/novac/src/core/error.js +86 -0
  118. package/novac/src/core/executor.js +5606 -0
  119. package/novac/src/core/formatter.js +686 -0
  120. package/novac/src/core/lexer.js +1026 -0
  121. package/novac/src/core/nova_builtins.js +717 -0
  122. package/novac/src/core/nova_thread_worker.js +166 -0
  123. package/novac/src/core/parser.js +2181 -0
  124. package/novac/src/core/types.js +112 -0
  125. package/novac/src/index.js +28 -0
  126. package/novac/src/runtime/stdlib.js +244 -0
  127. package/package.json +3 -2
  128. package/scripts/update-bin.js +0 -0
  129. package/src/core/bstd.js +835 -361
  130. package/src/core/executor.js +427 -246
  131. package/src/core/lexer.js +19 -2
  132. package/src/core/parser.js +13 -0
  133. package/src/index.js +0 -0
  134. package/examples/example-project/README.md +0 -3
  135. package/examples/example-project/src/main.nova +0 -3
  136. package/src/core/environment.js +0 -0
  137. /package/{kits → novac/kits}/libtea/tf.js +0 -0
  138. /package/{examples/example-project/bin/example-project.nv → novac/node_modules/node-addon-api/nothing.c} +0 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * nova_thread_worker.js
3
+ * Spawned by Executor._initThread() via worker_threads.Worker.
4
+ *
5
+ * workerData shape:
6
+ * executorPath — absolute path to executor.js
7
+ * scopeSnapshot — structured-clone of the caller's scope variables
8
+ * (Nova class instances arrive as prototype-stripped plain
9
+ * objects; rehydrate() restores the right constructors)
10
+ * fnNode — structured-clone of the Nova AST function node to run
11
+ * rawsrc — original source string (for error messages)
12
+ *
13
+ * Message protocol (parentPort):
14
+ *
15
+ * Worker → Main
16
+ * { kind:'set', name, value } thread.set(name, val) — scope mutation
17
+ * { kind:'print', text } stdout relay
18
+ * { kind:'msg', value } thread.send(val)
19
+ * { kind:'done', result } normal exit
20
+ * { kind:'error', message } uncaught throw
21
+ *
22
+ * Main → Worker
23
+ * { kind:'msg', value } t.send(val) from main side
24
+ */
25
+
26
+ 'use strict';
27
+ const { parentPort, workerData, isMainThread } = require('worker_threads');
28
+
29
+ // Guard: this file must only execute as a spawned Worker, never require()'d directly.
30
+ if (isMainThread || !workerData) { module.exports = {}; return; }
31
+
32
+ const { executorPath, scopeSnapshot, fnNode, rawsrc } = workerData;
33
+
34
+ // ── load types from the same directory as executor ────────────────────────────
35
+ const path = require('path');
36
+ const typesPath = path.join(path.dirname(executorPath), 'types.js');
37
+ const {
38
+ NovaValue, NovaNumber, NovaString, NovaArray, NovaObject,
39
+ NovaBool, NovaNull, NovaRange, NovaStruct, NovaEnum,
40
+ } = require(typesPath);
41
+
42
+ // ── rehydrate ─────────────────────────────────────────────────────────────────
43
+ // structured-clone strips prototypes but preserves own properties.
44
+ // We reconstruct the right Nova class from the shape of what arrived.
45
+ function rehydrate(v) {
46
+ if (v === null || v === undefined) return v;
47
+ const t = typeof v;
48
+ if (t === 'number' || t === 'string' || t === 'boolean') return v;
49
+ if (t !== 'object') return v;
50
+ if (Array.isArray(v)) return v.map(rehydrate);
51
+
52
+ // NovaBool / NovaNumber / NovaString / NovaNull — all have _v
53
+ if ('_v' in v) {
54
+ if (v._v === null) return new NovaNull();
55
+ if (typeof v._v === 'boolean') return new NovaBool(v._v);
56
+ if (typeof v._v === 'number') return new NovaNumber(v._v);
57
+ if (typeof v._v === 'string') return new NovaString(v._v);
58
+ return v._v; // fallback
59
+ }
60
+
61
+ // NovaRange — { start, end }
62
+ if ('start' in v && 'end' in v && Object.keys(v).length === 2)
63
+ return new NovaRange(v.start, v.end);
64
+
65
+ // NovaStruct — { typeName, inner: {} }
66
+ if ('typeName' in v && 'inner' in v && typeof v.inner === 'object' && !Array.isArray(v.inner)) {
67
+ const inner = {};
68
+ for (const [k, val] of Object.entries(v.inner)) inner[k] = rehydrate(val);
69
+ return new NovaStruct(v.typeName, inner);
70
+ }
71
+
72
+ // NovaArray — { inner: [] }
73
+ if ('inner' in v && Array.isArray(v.inner))
74
+ return new NovaArray(v.inner.map(rehydrate));
75
+
76
+ // NovaObject — { inner: {} }
77
+ if ('inner' in v && typeof v.inner === 'object' && !Array.isArray(v.inner)) {
78
+ const inner = {};
79
+ for (const [k, val] of Object.entries(v.inner)) inner[k] = rehydrate(val);
80
+ return new NovaObject(inner);
81
+ }
82
+
83
+ // Nova AST function node — plain object with kind:'function', args, body
84
+ // These pass through structured clone perfectly; return as-is.
85
+ if ('kind' in v) return v;
86
+
87
+ // Native JS functions were serialized to source strings by the main thread
88
+ // and tagged { __jsfn__: '<source>' }
89
+ if ('__jsfn__' in v) {
90
+ try { return eval('(' + v.__jsfn__ + ')'); } catch { return null; }
91
+ }
92
+
93
+ // generic plain object — recurse
94
+ const out = {};
95
+ for (const [k, val] of Object.entries(v)) out[k] = rehydrate(val);
96
+ return out;
97
+ }
98
+
99
+ // ── boot executor ─────────────────────────────────────────────────────────────
100
+ const { Executor, Scope } = require(executorPath);
101
+ const exe = new Executor(rawsrc || '');
102
+
103
+ // relay stdout to main thread
104
+ process.stdout.write = (text) => {
105
+ parentPort.postMessage({ kind: 'print', text: String(text) });
106
+ return true;
107
+ };
108
+
109
+ // ── hydrate scope ─────────────────────────────────────────────────────────────
110
+ const workerScope = new Scope('thread', null, exe.globalScope);
111
+ for (const [name, frozen] of Object.entries(scopeSnapshot || {})) {
112
+ workerScope.set(name, rehydrate(frozen));
113
+ }
114
+
115
+ // ── inbox for thread.recv() ───────────────────────────────────────────────────
116
+ const inbox = [];
117
+ let inboxWaker = null;
118
+ parentPort.on('message', (msg) => {
119
+ if (msg.kind !== 'msg') return;
120
+ const val = rehydrate(msg.value);
121
+ if (inboxWaker) { const w = inboxWaker; inboxWaker = null; w(val); }
122
+ else inbox.push(val);
123
+ });
124
+
125
+ // ── thread control object exposed as 'thread' inside the worker ───────────────
126
+ const threadObj = new NovaObject({
127
+ // Mutate a variable back in the main thread's scope (applied on join())
128
+ set: (name, value) => {
129
+ parentPort.postMessage({ kind: 'set', name: String(name), value });
130
+ workerScope.set(String(name), value);
131
+ return value;
132
+ },
133
+ // Non-blocking send to main
134
+ send: (value) => {
135
+ parentPort.postMessage({ kind: 'msg', value });
136
+ return value;
137
+ },
138
+ // Sync-blocking receive from main (Atomics.wait)
139
+ recv: () => {
140
+ if (inbox.length) return inbox.shift();
141
+ const sab = new SharedArrayBuffer(8);
142
+ const flag = new Int32Array(sab);
143
+ let result;
144
+ inboxWaker = (v) => { result = v; Atomics.store(flag, 0, 1); Atomics.notify(flag, 0); };
145
+ Atomics.wait(flag, 0, 0);
146
+ return result;
147
+ },
148
+ print: (v) => {
149
+ parentPort.postMessage({ kind: 'print', text: exe.stringify(v) + '\n' });
150
+ },
151
+ id: require('worker_threads').threadId,
152
+ });
153
+ workerScope.set('thread', threadObj);
154
+
155
+ // ── run ───────────────────────────────────────────────────────────────────────
156
+ const rehydratedFn = rehydrate(fnNode);
157
+ try {
158
+ const result = rehydratedFn && rehydratedFn.body
159
+ ? exe.runFunctionNode(rehydratedFn, workerScope, [])
160
+ : null;
161
+ // result goes back raw via structured clone — main side rehydrates it too
162
+ parentPort.postMessage({ kind: 'done', result });
163
+ } catch (e) {
164
+ const msg = e && e.message ? e.message : String(e);
165
+ parentPort.postMessage({ kind: 'error', message: msg });
166
+ }