porffor 0.16.0-ec15a329e → 0.16.0-f9e625159
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/CONTRIBUTING.md +1 -1
- package/README.md +5 -17
- package/compiler/2c.js +75 -15
- package/compiler/allocators.js +128 -0
- package/compiler/assemble.js +12 -5
- package/compiler/builtins/array.ts +72 -5
- package/compiler/builtins/date.ts +3 -30
- package/compiler/builtins/number.ts +10 -21
- package/compiler/builtins/porffor.d.ts +7 -0
- package/compiler/builtins/set.ts +2 -5
- package/compiler/builtins/z_ecma262.ts +62 -0
- package/compiler/builtins.js +23 -3
- package/compiler/codegen.js +293 -366
- package/compiler/cyclone.js +535 -0
- package/compiler/decompile.js +3 -1
- package/compiler/generated_builtins.js +113 -75
- package/compiler/havoc.js +93 -0
- package/compiler/index.js +104 -7
- package/compiler/opt.js +10 -44
- package/compiler/parse.js +1 -7
- package/compiler/pgo.js +212 -0
- package/compiler/precompile.js +12 -7
- package/compiler/prefs.js +8 -4
- package/compiler/prototype.js +34 -43
- package/compiler/wasmSpec.js +2 -2
- package/compiler/wrap.js +55 -13
- package/package.json +3 -5
- package/runner/index.js +26 -11
- /package/runner/{profiler.js → profile.js} +0 -0
package/compiler/prefs.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused' ];
|
1
|
+
const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
|
2
2
|
|
3
3
|
let cache = {};
|
4
4
|
const obj = new Proxy({}, {
|
5
5
|
get(_, p) {
|
6
|
-
|
7
|
-
if (cache[p]) return cache[p];
|
6
|
+
if (cache[p] != null) return cache[p];
|
8
7
|
|
9
8
|
const ret = (() => {
|
10
9
|
// fooBar -> foo-bar
|
@@ -23,9 +22,14 @@ const obj = new Proxy({}, {
|
|
23
22
|
// do not cache in web demo as args are changed live
|
24
23
|
if (!globalThis.document) cache[p] = ret;
|
25
24
|
return ret;
|
25
|
+
},
|
26
|
+
|
27
|
+
set(_, p, v) {
|
28
|
+
cache[p] = v;
|
29
|
+
return true;
|
26
30
|
}
|
27
31
|
});
|
28
32
|
|
29
|
-
|
33
|
+
export const uncache = () => cache = {};
|
30
34
|
|
31
35
|
export default obj;
|
package/compiler/prototype.js
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import { Opcodes, Blocktype, Valtype, ValtypeSize } from './wasmSpec.js';
|
2
2
|
import { number } from './embedding.js';
|
3
|
-
import { unsignedLEB128 } from './encoding.js';
|
4
3
|
import { UNDEFINED } from './builtins.js';
|
5
4
|
import { TYPES } from './types.js';
|
6
5
|
import Prefs from './prefs.js';
|
@@ -55,10 +54,10 @@ export const PrototypeFuncs = function() {
|
|
55
54
|
|
56
55
|
// read from memory
|
57
56
|
[ Opcodes.local_get, iTmp ],
|
58
|
-
[ Opcodes.load, 0,
|
57
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
59
58
|
|
60
59
|
[ Opcodes.local_get, iTmp ],
|
61
|
-
[ Opcodes.i32_load8_u, 0,
|
60
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
62
61
|
],
|
63
62
|
|
64
63
|
// todo: only for 1 argument
|
@@ -74,12 +73,12 @@ export const PrototypeFuncs = function() {
|
|
74
73
|
// store value
|
75
74
|
[ Opcodes.local_get, iTmp ],
|
76
75
|
...wNewMember,
|
77
|
-
[ Opcodes.store, 0,
|
76
|
+
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
78
77
|
|
79
78
|
// store type
|
80
79
|
[ Opcodes.local_get, iTmp ],
|
81
80
|
...wType,
|
82
|
-
[ Opcodes.i32_store8, 0,
|
81
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
83
82
|
|
84
83
|
// bump array length by 1 and return it
|
85
84
|
...length.setI32([
|
@@ -137,10 +136,10 @@ export const PrototypeFuncs = function() {
|
|
137
136
|
[ Opcodes.local_set, iTmp ],
|
138
137
|
|
139
138
|
[ Opcodes.local_get, iTmp ],
|
140
|
-
[ Opcodes.load, 0,
|
139
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
141
140
|
|
142
141
|
[ Opcodes.local_get, iTmp ],
|
143
|
-
[ Opcodes.i32_load8_u, 0,
|
142
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ]
|
144
143
|
])
|
145
144
|
],
|
146
145
|
|
@@ -168,10 +167,10 @@ export const PrototypeFuncs = function() {
|
|
168
167
|
// load first element
|
169
168
|
// todo/perf: unusedValue opt
|
170
169
|
...pointer,
|
171
|
-
[ Opcodes.load, 0,
|
170
|
+
[ Opcodes.load, 0, ValtypeSize.i32 ],
|
172
171
|
|
173
172
|
...pointer,
|
174
|
-
[ Opcodes.i32_load8_u, 0,
|
173
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
175
174
|
|
176
175
|
// offset page by -1 ind
|
177
176
|
// ...number(pointer + ValtypeSize.i32, Valtype.i32), // dst = base array index + length size
|
@@ -250,12 +249,12 @@ export const PrototypeFuncs = function() {
|
|
250
249
|
// store value
|
251
250
|
[ Opcodes.local_get, iTmp2 ],
|
252
251
|
[ Opcodes.local_get, iTmp ],
|
253
|
-
[ Opcodes.store, 0,
|
252
|
+
[ Opcodes.store, 0, ValtypeSize.i32 ],
|
254
253
|
|
255
254
|
// store type
|
256
255
|
[ Opcodes.local_get, iTmp2 ],
|
257
256
|
...wType,
|
258
|
-
[ Opcodes.i32_store8, 0,
|
257
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 + ValtypeSize[valtype] ],
|
259
258
|
|
260
259
|
// pointer - sizeof value
|
261
260
|
...length.getCachedI32(),
|
@@ -292,11 +291,8 @@ export const PrototypeFuncs = function() {
|
|
292
291
|
const [ newOut, newPointer ] = arrayShell(1, 'i16');
|
293
292
|
|
294
293
|
return [
|
295
|
-
// setup new/out array
|
294
|
+
// setup new/out array and use pointer for store
|
296
295
|
...newOut,
|
297
|
-
[ Opcodes.drop ],
|
298
|
-
|
299
|
-
...number(0, Valtype.i32), // base 0 for store later
|
300
296
|
|
301
297
|
...wIndex,
|
302
298
|
Opcodes.i32_to_u,
|
@@ -335,13 +331,14 @@ export const PrototypeFuncs = function() {
|
|
335
331
|
[ Opcodes.i32_add ],
|
336
332
|
|
337
333
|
// load current string ind {arg}
|
338
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
334
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
339
335
|
|
340
336
|
// store to new string ind 0
|
341
|
-
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1,
|
337
|
+
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
342
338
|
|
343
339
|
// return new string (pointer)
|
344
|
-
...
|
340
|
+
...newPointer,
|
341
|
+
Opcodes.i32_from_u
|
345
342
|
];
|
346
343
|
},
|
347
344
|
|
@@ -350,11 +347,8 @@ export const PrototypeFuncs = function() {
|
|
350
347
|
const [ newOut, newPointer ] = arrayShell(1, 'i16');
|
351
348
|
|
352
349
|
return [
|
353
|
-
// setup new/out array
|
350
|
+
// setup new/out array and use as pointer for store
|
354
351
|
...newOut,
|
355
|
-
[ Opcodes.drop ],
|
356
|
-
|
357
|
-
...number(0, Valtype.i32), // base 0 for store later
|
358
352
|
|
359
353
|
...wIndex,
|
360
354
|
Opcodes.i32_to,
|
@@ -366,13 +360,14 @@ export const PrototypeFuncs = function() {
|
|
366
360
|
[ Opcodes.i32_add ],
|
367
361
|
|
368
362
|
// load current string ind {arg}
|
369
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
363
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
370
364
|
|
371
365
|
// store to new string ind 0
|
372
|
-
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1,
|
366
|
+
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
373
367
|
|
374
368
|
// return new string (page)
|
375
|
-
...
|
369
|
+
...newPointer,
|
370
|
+
Opcodes.i32_from_u
|
376
371
|
];
|
377
372
|
},
|
378
373
|
|
@@ -411,7 +406,7 @@ export const PrototypeFuncs = function() {
|
|
411
406
|
[ Opcodes.i32_add ],
|
412
407
|
|
413
408
|
// load current string ind {arg}
|
414
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
409
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
415
410
|
Opcodes.i32_from_u
|
416
411
|
],
|
417
412
|
|
@@ -433,7 +428,7 @@ export const PrototypeFuncs = function() {
|
|
433
428
|
[ Opcodes.block, Blocktype.void ],
|
434
429
|
|
435
430
|
[ Opcodes.local_get, iTmp ],
|
436
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
431
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
437
432
|
[ Opcodes.local_set, iTmp2 ],
|
438
433
|
|
439
434
|
// if not surrogate, continue
|
@@ -455,7 +450,7 @@ export const PrototypeFuncs = function() {
|
|
455
450
|
|
456
451
|
// if not followed by trailing surrogate, return false
|
457
452
|
[ Opcodes.local_get, iTmp ],
|
458
|
-
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1,
|
453
|
+
[ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 + ValtypeSize.i16 ],
|
459
454
|
...number(0xFC00, Valtype.i32),
|
460
455
|
[ Opcodes.i32_and ],
|
461
456
|
...number(0xDC00, Valtype.i32),
|
@@ -507,11 +502,8 @@ export const PrototypeFuncs = function() {
|
|
507
502
|
const [ newOut, newPointer ] = arrayShell(1, 'i8');
|
508
503
|
|
509
504
|
return [
|
510
|
-
// setup new/out array
|
505
|
+
// setup new/out array and use pointer for store later
|
511
506
|
...newOut,
|
512
|
-
[ Opcodes.drop ],
|
513
|
-
|
514
|
-
...number(0, Valtype.i32), // base 0 for store later
|
515
507
|
|
516
508
|
...wIndex,
|
517
509
|
Opcodes.i32_to_u,
|
@@ -548,13 +540,14 @@ export const PrototypeFuncs = function() {
|
|
548
540
|
[ Opcodes.i32_add ],
|
549
541
|
|
550
542
|
// load current string ind {arg}
|
551
|
-
[ Opcodes.i32_load8_u, 0,
|
543
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
552
544
|
|
553
545
|
// store to new string ind 0
|
554
|
-
[ Opcodes.i32_store8, 0,
|
546
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
555
547
|
|
556
548
|
// return new string (pointer)
|
557
|
-
...
|
549
|
+
...newPointer,
|
550
|
+
Opcodes.i32_from_u
|
558
551
|
];
|
559
552
|
},
|
560
553
|
|
@@ -563,11 +556,8 @@ export const PrototypeFuncs = function() {
|
|
563
556
|
const [ newOut, newPointer ] = arrayShell(1, 'i8');
|
564
557
|
|
565
558
|
return [
|
566
|
-
// setup new/out array
|
559
|
+
// setup new/out array and use pointer for later
|
567
560
|
...newOut,
|
568
|
-
[ Opcodes.drop ],
|
569
|
-
|
570
|
-
...number(0, Valtype.i32), // base 0 for store later
|
571
561
|
|
572
562
|
...wIndex,
|
573
563
|
Opcodes.i32_to,
|
@@ -576,13 +566,14 @@ export const PrototypeFuncs = function() {
|
|
576
566
|
[ Opcodes.i32_add ],
|
577
567
|
|
578
568
|
// load current string ind {arg}
|
579
|
-
[ Opcodes.i32_load8_u, 0,
|
569
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
580
570
|
|
581
571
|
// store to new string ind 0
|
582
|
-
[ Opcodes.i32_store8, 0,
|
572
|
+
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
583
573
|
|
584
574
|
// return new string (page)
|
585
|
-
...
|
575
|
+
...newPointer,
|
576
|
+
Opcodes.i32_from_u
|
586
577
|
];
|
587
578
|
},
|
588
579
|
|
@@ -618,7 +609,7 @@ export const PrototypeFuncs = function() {
|
|
618
609
|
[ Opcodes.i32_add ],
|
619
610
|
|
620
611
|
// load current string ind {arg}
|
621
|
-
[ Opcodes.i32_load8_u, 0,
|
612
|
+
[ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
|
622
613
|
Opcodes.i32_from_u
|
623
614
|
],
|
624
615
|
|
package/compiler/wasmSpec.js
CHANGED
@@ -191,6 +191,8 @@ export const Opcodes = {
|
|
191
191
|
i32_trunc_sat_f64_s: [ 0xfc, 0x02 ],
|
192
192
|
i32_trunc_sat_f64_u: [ 0xfc, 0x03 ],
|
193
193
|
|
194
|
+
memory_init: [ 0xfc, 0x08 ],
|
195
|
+
data_drop: [ 0xfc, 0x09 ],
|
194
196
|
memory_copy: [ 0xfc, 0x0a ],
|
195
197
|
|
196
198
|
// simd insts are 0xFD simdop: varuint32
|
@@ -209,8 +211,6 @@ export const Opcodes = {
|
|
209
211
|
i32x4_add: [ 0xfd, 0xae, 0x01 ],
|
210
212
|
i32x4_sub: [ 0xfd, 0xb1, 0x01 ],
|
211
213
|
i32x4_mul: [ 0xfd, 0xb5, 0x01 ],
|
212
|
-
|
213
|
-
i32x4_dot_i16x8_s: [ 0xfd, 0xba, 0x01 ],
|
214
214
|
};
|
215
215
|
|
216
216
|
export const FuncType = 0x60;
|
package/compiler/wrap.js
CHANGED
@@ -6,8 +6,25 @@ import { TYPES } from './types.js';
|
|
6
6
|
import { log } from './log.js';
|
7
7
|
import Prefs from './prefs.js';
|
8
8
|
|
9
|
+
const fs = (typeof process?.version !== 'undefined' ? (await import('node:fs')) : undefined);
|
10
|
+
|
9
11
|
const bold = x => `\u001b[1m${x}\u001b[0m`;
|
10
12
|
|
13
|
+
export const readByteStr = (memory, ptr) => {
|
14
|
+
const length = (new Int32Array(memory.buffer, ptr, 1))[0];
|
15
|
+
return Array.from(new Uint8Array(memory.buffer, ptr + 4, length)).map(x => String.fromCharCode(x)).join('');
|
16
|
+
};
|
17
|
+
|
18
|
+
export const writeByteStr = (memory, ptr, str) => {
|
19
|
+
const length = str.length;
|
20
|
+
(new Int32Array(memory.buffer, ptr, 1))[0] = length;
|
21
|
+
|
22
|
+
const arr = new Uint8Array(memory.buffer, ptr + 4, length);
|
23
|
+
for (let i = 0; i < length; i++) {
|
24
|
+
arr[i] = str.charCodeAt(i);
|
25
|
+
}
|
26
|
+
};
|
27
|
+
|
11
28
|
const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
12
29
|
switch (type) {
|
13
30
|
case TYPES.boolean: return Boolean(value);
|
@@ -87,13 +104,14 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
87
104
|
|
88
105
|
case TYPES.symbol: {
|
89
106
|
const descStore = pages.get('bytestring: __Porffor_symbol_descStore/ptr').ind * pageSize;
|
107
|
+
if (!descStore) return Symbol();
|
108
|
+
|
90
109
|
const offset = descStore + 4 + ((value - 1) * 9);
|
91
110
|
|
92
111
|
const v = (new Float64Array(memory.buffer.slice(offset, offset + 8), 0, 1))[0];
|
93
112
|
const t = (new Uint8Array(memory.buffer, offset + 8, 1))[0];
|
94
113
|
|
95
114
|
const desc = porfToJSValue({ memory, funcs, pages }, v, t);
|
96
|
-
|
97
115
|
return Symbol(desc);
|
98
116
|
}
|
99
117
|
|
@@ -101,28 +119,31 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
|
|
101
119
|
}
|
102
120
|
};
|
103
121
|
|
104
|
-
export default
|
122
|
+
export default (source, flags = [ 'module' ], customImports = {}, print = str => process.stdout.write(str)) => {
|
105
123
|
const times = [];
|
106
124
|
|
107
125
|
const t1 = performance.now();
|
108
|
-
const { wasm, funcs, globals, tags, exceptions, pages, c } = compile(source, flags);
|
126
|
+
const { wasm, funcs, globals, tags, exceptions, pages, c } = typeof source === 'object' ? source : compile(source, flags);
|
109
127
|
|
110
128
|
globalThis.porfDebugInfo = { funcs, globals };
|
111
129
|
|
112
|
-
if (source.includes('export
|
130
|
+
if (source.includes?.('export ')) flags.push('module');
|
113
131
|
|
114
|
-
//
|
132
|
+
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
115
133
|
|
116
134
|
times.push(performance.now() - t1);
|
117
135
|
if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
|
118
136
|
|
119
137
|
const backtrace = (funcInd, blobOffset) => {
|
120
|
-
if (funcInd == null || blobOffset == null
|
138
|
+
if (funcInd == null || blobOffset == null ||
|
139
|
+
Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
|
121
140
|
|
122
141
|
// convert blob offset -> function wasm offset.
|
123
142
|
// this is not good code and is somewhat duplicated
|
124
143
|
// I just want it to work for debugging, I don't care about perf/yes
|
125
144
|
const func = funcs.find(x => x.index === funcInd);
|
145
|
+
if (!func) return false;
|
146
|
+
|
126
147
|
const locals = Object.values(func.locals).sort((a, b) => a.idx - b.idx).slice(func.params.length).sort((a, b) => a.idx - b.idx);
|
127
148
|
|
128
149
|
let localDecl = [], typeCount = 0, lastType;
|
@@ -197,13 +218,15 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
197
218
|
|
198
219
|
let instance;
|
199
220
|
try {
|
200
|
-
let wasmEngine = WebAssembly;
|
201
|
-
if (Prefs.asur) {
|
202
|
-
|
203
|
-
|
204
|
-
}
|
205
|
-
|
206
|
-
0, { instance } = await wasmEngine.instantiate(wasm, {
|
221
|
+
// let wasmEngine = WebAssembly;
|
222
|
+
// if (Prefs.asur) {
|
223
|
+
// log.warning('wrap', 'using our !experimental! asur wasm engine instead of host to run');
|
224
|
+
// wasmEngine = await import('../asur/index.js');
|
225
|
+
// }
|
226
|
+
|
227
|
+
// 0, { instance } = await wasmEngine.instantiate(wasm, {
|
228
|
+
const module = new WebAssembly.Module(wasm);
|
229
|
+
instance = new WebAssembly.Instance(module, {
|
207
230
|
'': {
|
208
231
|
p: valtype === 'i64' ? i => print(Number(i).toString()) : i => print(i.toString()),
|
209
232
|
c: valtype === 'i64' ? i => print(String.fromCharCode(Number(i))) : i => print(String.fromCharCode(i)),
|
@@ -211,12 +234,31 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
|
|
211
234
|
u: () => performance.timeOrigin,
|
212
235
|
y: () => {},
|
213
236
|
z: () => {},
|
237
|
+
w: (ind, outPtr) => { // readArgv
|
238
|
+
const args = process.argv.slice(2).filter(x => !x.startsWith('-'));
|
239
|
+
const str = args[ind];
|
240
|
+
if (!str) return -1;
|
241
|
+
|
242
|
+
writeByteStr(memory, outPtr, str);
|
243
|
+
return str.length;
|
244
|
+
},
|
245
|
+
q: (pathPtr, outPtr) => { // readFile
|
246
|
+
try {
|
247
|
+
const path = readByteStr(memory, pathPtr);
|
248
|
+
const contents = fs.readFileSync(path, 'utf8');
|
249
|
+
writeByteStr(memory, outPtr, contents);
|
250
|
+
return contents.length;
|
251
|
+
} catch {
|
252
|
+
return -1;
|
253
|
+
}
|
254
|
+
},
|
214
255
|
...customImports
|
215
256
|
}
|
216
257
|
});
|
217
258
|
} catch (e) {
|
218
259
|
// only backtrace for runner, not test262/etc
|
219
260
|
if (!process.argv[1].includes('/runner')) throw e;
|
261
|
+
if (!(e instanceof WebAssembly.CompileError)) throw e;
|
220
262
|
|
221
263
|
const funcInd = parseInt(e.message.match(/function #([0-9]+) /)?.[1]);
|
222
264
|
const blobOffset = parseInt(e.message.split('@')?.[1]);
|
package/package.json
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
|
4
|
-
"version": "0.16.0-
|
4
|
+
"version": "0.16.0-f9e625159",
|
5
5
|
"author": "CanadaHonk",
|
6
6
|
"license": "MIT",
|
7
|
-
"scripts": {
|
8
|
-
"precompile": "node ./compiler/precompile.js"
|
9
|
-
},
|
7
|
+
"scripts": {},
|
10
8
|
"dependencies": {
|
11
9
|
"acorn": "^8.11.3",
|
12
10
|
"node-repl-polyfill": "^0.1.1"
|
@@ -28,5 +26,5 @@
|
|
28
26
|
"bugs": {
|
29
27
|
"url": "https://github.com/CanadaHonk/porffor/issues"
|
30
28
|
},
|
31
|
-
"homepage": "https://porffor.
|
29
|
+
"homepage": "https://porffor.dev"
|
32
30
|
}
|
package/runner/index.js
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
|
3
|
-
import compile from '../compiler/wrap.js';
|
4
2
|
import fs from 'node:fs';
|
5
3
|
|
4
|
+
// deno compat
|
5
|
+
if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
|
6
|
+
globalThis.process = await import('node:process');
|
7
|
+
}
|
8
|
+
|
6
9
|
const start = performance.now();
|
7
10
|
|
8
11
|
if (process.argv.includes('--compile-hints')) {
|
@@ -59,12 +62,22 @@ if (process.argv.includes('--help')) {
|
|
59
62
|
}
|
60
63
|
|
61
64
|
let file = process.argv.slice(2).find(x => x[0] !== '-');
|
62
|
-
if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(file)) {
|
65
|
+
if (['precompile', 'run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(file)) {
|
63
66
|
// remove this arg
|
64
67
|
process.argv.splice(process.argv.indexOf(file), 1);
|
65
68
|
|
69
|
+
if (file === 'precompile') {
|
70
|
+
await import('../compiler/precompile.js');
|
71
|
+
await new Promise(() => {}); // do nothing for the rest of this file
|
72
|
+
}
|
73
|
+
|
66
74
|
if (file === 'profile') {
|
67
|
-
await import('./
|
75
|
+
await import('./profile.js');
|
76
|
+
await new Promise(() => {}); // do nothing for the rest of this file
|
77
|
+
}
|
78
|
+
|
79
|
+
if (file === 'debug') {
|
80
|
+
await import('./debug.js');
|
68
81
|
await new Promise(() => {}); // do nothing for the rest of this file
|
69
82
|
}
|
70
83
|
|
@@ -76,11 +89,6 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
|
|
76
89
|
process.argv.push('--asur', '--wasm-debug');
|
77
90
|
}
|
78
91
|
|
79
|
-
if (file === 'debug') {
|
80
|
-
await import('./debug.js');
|
81
|
-
await new Promise(() => {}); // do nothing for the rest of this file
|
82
|
-
}
|
83
|
-
|
84
92
|
file = process.argv.slice(2).find(x => x[0] !== '-');
|
85
93
|
|
86
94
|
const nonOptOutFile = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
|
@@ -89,6 +97,8 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
|
|
89
97
|
}
|
90
98
|
}
|
91
99
|
|
100
|
+
globalThis.file = file;
|
101
|
+
|
92
102
|
if (!file) {
|
93
103
|
if (process.argv.includes('-v') || process.argv.includes('--version')) {
|
94
104
|
// just print version
|
@@ -103,6 +113,8 @@ if (!file) {
|
|
103
113
|
|
104
114
|
const source = fs.readFileSync(file, 'utf8');
|
105
115
|
|
116
|
+
const compile = (await import('../compiler/wrap.js')).default;
|
117
|
+
|
106
118
|
let cache = '';
|
107
119
|
const print = str => {
|
108
120
|
/* cache += str;
|
@@ -115,17 +127,20 @@ const print = str => {
|
|
115
127
|
process.stdout.write(str);
|
116
128
|
};
|
117
129
|
|
130
|
+
let runStart;
|
118
131
|
try {
|
119
132
|
if (process.argv.includes('-b')) {
|
120
133
|
const { wasm, exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
|
121
134
|
|
135
|
+
runStart = performance.now();
|
122
136
|
if (!process.argv.includes('--no-run')) exports.main();
|
123
137
|
|
124
138
|
console.log(`\n\nwasm size: ${wasm.byteLength} bytes`);
|
125
139
|
} else {
|
126
140
|
const { exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
|
127
141
|
|
128
|
-
|
142
|
+
runStart = performance.now();
|
143
|
+
if (!process.argv.includes('--no-run')) exports.main();
|
129
144
|
}
|
130
145
|
// if (cache) process.stdout.write(cache);
|
131
146
|
} catch (e) {
|
@@ -133,4 +148,4 @@ try {
|
|
133
148
|
console.error(process.argv.includes('-i') ? e : `${e.constructor.name}: ${e.message}`);
|
134
149
|
}
|
135
150
|
|
136
|
-
if (process.argv.includes('-t')) console.log(`${process.argv.includes('-b') ? '' : '\n\n'}total time: ${(performance.now() - start).toFixed(2)}ms`);
|
151
|
+
if (process.argv.includes('-t')) console.log(`${process.argv.includes('-b') ? '' : '\n\n'}total time: ${(performance.now() - start).toFixed(2)}ms\nexecution time: ${(performance.now() - runStart).toFixed(2)}ms`);
|
File without changes
|