porffor 0.25.8 → 0.25.10
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/compiler/assemble.js +4 -1
- package/compiler/builtins/_internal_object.ts +84 -0
- package/compiler/builtins/arraybuffer.ts +20 -14
- package/compiler/builtins.js +1 -1
- package/compiler/builtins_objects.js +2 -2
- package/compiler/builtins_precompiled.js +667 -643
- package/compiler/codegen.js +41 -34
- package/compiler/decompile.js +1 -1
- package/compiler/index.js +0 -3
- package/compiler/precompile.js +4 -3
- package/compiler/wrap.js +17 -6
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -376,7 +376,7 @@ const generateReturn = (scope, decl) => {
|
|
376
376
|
...generate(scope, arg),
|
377
377
|
...(scope.returnType != null ? [] : getNodeType(scope, arg)),
|
378
378
|
|
379
|
-
[ Opcodes.call,
|
379
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_resolve').index ],
|
380
380
|
[ Opcodes.drop ],
|
381
381
|
[ Opcodes.drop ],
|
382
382
|
|
@@ -546,7 +546,7 @@ const concatStrings = (scope, left, right, leftType, rightType, allBytestrings =
|
|
546
546
|
[ Opcodes.if, Blocktype.void ],
|
547
547
|
[ Opcodes.local_get, leftPointer ],
|
548
548
|
[ Opcodes.local_get, leftLength ],
|
549
|
-
[ Opcodes.call,
|
549
|
+
[ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
|
550
550
|
[ Opcodes.local_set, leftPointer ],
|
551
551
|
[ Opcodes.end ],
|
552
552
|
|
@@ -556,7 +556,7 @@ const concatStrings = (scope, left, right, leftType, rightType, allBytestrings =
|
|
556
556
|
[ Opcodes.if, Blocktype.void ],
|
557
557
|
[ Opcodes.local_get, rightPointer ],
|
558
558
|
[ Opcodes.local_get, rightLength ],
|
559
|
-
[ Opcodes.call,
|
559
|
+
[ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
|
560
560
|
[ Opcodes.local_set, rightPointer ],
|
561
561
|
[ Opcodes.end ]
|
562
562
|
]),
|
@@ -662,7 +662,7 @@ const compareStrings = (scope, left, right, leftType, rightType, allBytestrings
|
|
662
662
|
[ Opcodes.if, Blocktype.void ],
|
663
663
|
[ Opcodes.local_get, leftPointer ],
|
664
664
|
[ Opcodes.local_get, leftLength ],
|
665
|
-
[ Opcodes.call,
|
665
|
+
[ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
|
666
666
|
[ Opcodes.local_set, leftPointer ],
|
667
667
|
[ Opcodes.end ],
|
668
668
|
|
@@ -673,7 +673,7 @@ const compareStrings = (scope, left, right, leftType, rightType, allBytestrings
|
|
673
673
|
[ Opcodes.local_get, rightPointer ],
|
674
674
|
[ Opcodes.local_get, rightPointer ],
|
675
675
|
[ Opcodes.i32_load, 0, 0 ],
|
676
|
-
[ Opcodes.call,
|
676
|
+
[ Opcodes.call, funcIndex.__Porffor_bytestringToString ],
|
677
677
|
[ Opcodes.local_set, rightPointer ],
|
678
678
|
[ Opcodes.end ]
|
679
679
|
]),
|
@@ -1016,7 +1016,7 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
1016
1016
|
return finalize([
|
1017
1017
|
...left,
|
1018
1018
|
...right,
|
1019
|
-
[ Opcodes.call,
|
1019
|
+
[ Opcodes.call, idx ]
|
1020
1020
|
]);
|
1021
1021
|
}
|
1022
1022
|
|
@@ -1239,7 +1239,7 @@ const asmFuncToAsm = (scope, func) => {
|
|
1239
1239
|
if (idx == null) throw new Error(`builtin('${n}') failed: could not find func (from ${scope.name})`);
|
1240
1240
|
if (offset) idx -= importedFuncs.length;
|
1241
1241
|
|
1242
|
-
return float ? ieee754_binary64(idx) :
|
1242
|
+
return float ? ieee754_binary64(idx) : idx;
|
1243
1243
|
},
|
1244
1244
|
glbl: (opcode, name, type) => {
|
1245
1245
|
const globalName = '#porf#' + name; // avoid potential name clashing with user js
|
@@ -1940,7 +1940,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1940
1940
|
...getNodeType(scope, decl.arguments[0]),
|
1941
1941
|
|
1942
1942
|
// call regex func
|
1943
|
-
[ Opcodes.call,
|
1943
|
+
[ Opcodes.call, idx ],
|
1944
1944
|
Opcodes.i32_from_u,
|
1945
1945
|
|
1946
1946
|
...setLastType(scope, Rhemyn.types[funcName])
|
@@ -1983,7 +1983,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1983
1983
|
...getNodeType(scope, target),
|
1984
1984
|
|
1985
1985
|
// call regex func
|
1986
|
-
[ Opcodes.call,
|
1986
|
+
[ Opcodes.call, idx ],
|
1987
1987
|
Opcodes.i32_from,
|
1988
1988
|
|
1989
1989
|
...setLastType(scope, Rhemyn.types[protoName])
|
@@ -2170,10 +2170,16 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2170
2170
|
const op = wasmOps[opName];
|
2171
2171
|
|
2172
2172
|
const argOut = [];
|
2173
|
-
for (let i = 0; i < op.args.length; i++)
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2173
|
+
for (let i = 0; i < op.args.length; i++) {
|
2174
|
+
if (!op.args[i]) globalThis.noi32F64CallConv = true;
|
2175
|
+
|
2176
|
+
argOut.push(
|
2177
|
+
...generate(scope, decl.arguments[i]),
|
2178
|
+
...(op.args[i] ? [ Opcodes.i32_to ] : [])
|
2179
|
+
);
|
2180
|
+
|
2181
|
+
globalThis.noi32F64CallConv = false;
|
2182
|
+
}
|
2177
2183
|
|
2178
2184
|
// literals only
|
2179
2185
|
const imms = decl.arguments.slice(op.args.length).map(x => x.value);
|
@@ -2491,13 +2497,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2491
2497
|
if (valtypeBinary === Valtype.i32 &&
|
2492
2498
|
(func && func.params[paramOffset + i * (typedParams ? 2 : 1)] === Valtype.f64)
|
2493
2499
|
) {
|
2494
|
-
out.push(
|
2500
|
+
out.push(Opcodes.i32_from);
|
2495
2501
|
}
|
2496
2502
|
|
2497
2503
|
if (typedParams) out = out.concat(getNodeType(scope, arg));
|
2498
2504
|
}
|
2499
2505
|
|
2500
|
-
out.push([ Opcodes.call,
|
2506
|
+
out.push([ Opcodes.call, idx ]);
|
2501
2507
|
|
2502
2508
|
if (!typedReturns) {
|
2503
2509
|
// let type;
|
@@ -2515,7 +2521,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2515
2521
|
out.push(Opcodes.i32_from);
|
2516
2522
|
}
|
2517
2523
|
|
2518
|
-
if (builtinFuncs[name] && builtinFuncs[name].returns?.[0] === Valtype.f64 && valtypeBinary === Valtype.i32) {
|
2524
|
+
if (builtinFuncs[name] && builtinFuncs[name].returns?.[0] === Valtype.f64 && valtypeBinary === Valtype.i32 && !globalThis.noi32F64CallConv) {
|
2519
2525
|
out.push(Opcodes.i32_trunc_sat_f64_s);
|
2520
2526
|
}
|
2521
2527
|
|
@@ -3127,12 +3133,12 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3127
3133
|
[ Opcodes.local_get, localTmp(scope, '#objset_property', Valtype.i32) ],
|
3128
3134
|
[ Opcodes.local_get, localTmp(scope, '#objset_property_type', Valtype.i32) ],
|
3129
3135
|
|
3130
|
-
[ Opcodes.call,
|
3136
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
|
3131
3137
|
...setLastType(scope)
|
3132
3138
|
], generate(scope, decl.right), getLastType(scope), getNodeType(scope, decl.right), false, name, true)),
|
3133
3139
|
...getNodeType(scope, decl),
|
3134
3140
|
|
3135
|
-
[ Opcodes.call,
|
3141
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_set').index ],
|
3136
3142
|
[ Opcodes.drop ],
|
3137
3143
|
// ...setLastType(scope, getNodeType(scope, decl)),
|
3138
3144
|
],
|
@@ -3431,7 +3437,7 @@ const generateUnary = (scope, decl) => {
|
|
3431
3437
|
...getNodeType(scope, property),
|
3432
3438
|
...toPropertyKey(scope, true),
|
3433
3439
|
|
3434
|
-
[ Opcodes.call,
|
3440
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_delete').index ],
|
3435
3441
|
[ Opcodes.drop ],
|
3436
3442
|
Opcodes.i32_from_u
|
3437
3443
|
];
|
@@ -3744,7 +3750,7 @@ const generateForOf = (scope, decl) => {
|
|
3744
3750
|
...setType(scope, leftName, TYPES.string),
|
3745
3751
|
|
3746
3752
|
// allocate out string
|
3747
|
-
[ Opcodes.call,
|
3753
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
3748
3754
|
[ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3749
3755
|
|
3750
3756
|
// set length to 1
|
@@ -3798,7 +3804,7 @@ const generateForOf = (scope, decl) => {
|
|
3798
3804
|
...setType(scope, leftName, TYPES.bytestring),
|
3799
3805
|
|
3800
3806
|
// allocate out string
|
3801
|
-
[ Opcodes.call,
|
3807
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
3802
3808
|
[ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3803
3809
|
|
3804
3810
|
// set length to 1
|
@@ -4588,7 +4594,7 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
4588
4594
|
|
4589
4595
|
if (name === '#member_prop_assign') {
|
4590
4596
|
out.push(
|
4591
|
-
[ Opcodes.call,
|
4597
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ]
|
4592
4598
|
);
|
4593
4599
|
shouldGet = false;
|
4594
4600
|
}
|
@@ -4728,7 +4734,7 @@ const generateArray = (scope, decl, global = false, name = '$undeclared', initEm
|
|
4728
4734
|
};
|
4729
4735
|
|
4730
4736
|
const toPropertyKey = (scope, i32Conv = false) => [
|
4731
|
-
[ Opcodes.call,
|
4737
|
+
[ Opcodes.call, includeBuiltin(scope, '__ecma262_ToPropertyKey').index ],
|
4732
4738
|
...(i32Conv ? [
|
4733
4739
|
[ Opcodes.local_set, localTmp(scope, '#swap', Valtype.i32) ],
|
4734
4740
|
Opcodes.i32_to_u,
|
@@ -4738,7 +4744,7 @@ const toPropertyKey = (scope, i32Conv = false) => [
|
|
4738
4744
|
|
4739
4745
|
const generateObject = (scope, decl, global = false, name = '$undeclared') => {
|
4740
4746
|
const out = [
|
4741
|
-
[ Opcodes.call,
|
4747
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ]
|
4742
4748
|
];
|
4743
4749
|
|
4744
4750
|
if (decl.properties.length > 0) {
|
@@ -4746,8 +4752,8 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
|
|
4746
4752
|
out.push([ Opcodes.local_tee, tmp ]);
|
4747
4753
|
|
4748
4754
|
for (const x of decl.properties) {
|
4749
|
-
|
4750
|
-
|
4755
|
+
// method, shorthand are made into useful values by parser for us :)
|
4756
|
+
const { computed, kind, key, value } = x;
|
4751
4757
|
|
4752
4758
|
let k = key;
|
4753
4759
|
if (!computed && key.type !== 'Literal') k = {
|
@@ -4764,9 +4770,10 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
|
|
4764
4770
|
...toPropertyKey(scope, true),
|
4765
4771
|
|
4766
4772
|
...generate(scope, value),
|
4773
|
+
...(kind !== 'init' ? [ Opcodes.i32_to_u ] : []),
|
4767
4774
|
...getNodeType(scope, value),
|
4768
4775
|
|
4769
|
-
[ Opcodes.call,
|
4776
|
+
[ Opcodes.call, includeBuiltin(scope, `__Porffor_object_expr_${kind}`).index ],
|
4770
4777
|
|
4771
4778
|
[ Opcodes.drop ],
|
4772
4779
|
[ Opcodes.drop ]
|
@@ -4887,7 +4894,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
4887
4894
|
[ Opcodes.i32_eq ],
|
4888
4895
|
[ Opcodes.if, Blocktype.void ],
|
4889
4896
|
[ Opcodes.local_get, tmp ],
|
4890
|
-
[ Opcodes.call,
|
4897
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_funcLut_length').index ],
|
4891
4898
|
Opcodes.i32_from_u,
|
4892
4899
|
|
4893
4900
|
...setLastType(scope, TYPES.number),
|
@@ -4946,7 +4953,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
4946
4953
|
|
4947
4954
|
[TYPES.string]: [
|
4948
4955
|
// allocate out string
|
4949
|
-
[ Opcodes.call,
|
4956
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
4950
4957
|
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4951
4958
|
|
4952
4959
|
// set length to 1
|
@@ -4980,7 +4987,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
4980
4987
|
|
4981
4988
|
[TYPES.bytestring]: [
|
4982
4989
|
// allocate out string
|
4983
|
-
[ Opcodes.call,
|
4990
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_allocate').index ],
|
4984
4991
|
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4985
4992
|
|
4986
4993
|
// set length to 1
|
@@ -5018,7 +5025,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
5018
5025
|
...getNodeType(scope, property),
|
5019
5026
|
...toPropertyKey(scope, true),
|
5020
5027
|
|
5021
|
-
[ Opcodes.call,
|
5028
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
|
5022
5029
|
...setLastType(scope)
|
5023
5030
|
],
|
5024
5031
|
|
@@ -5031,7 +5038,7 @@ const generateMember = (scope, decl, _global, _name, _objectWasm = undefined) =>
|
|
5031
5038
|
...getNodeType(scope, property),
|
5032
5039
|
...toPropertyKey(scope, true),
|
5033
5040
|
|
5034
|
-
[ Opcodes.call,
|
5041
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_object_get').index ],
|
5035
5042
|
...setLastType(scope)
|
5036
5043
|
],
|
5037
5044
|
|
@@ -5302,7 +5309,7 @@ const generateFunc = (scope, decl) => {
|
|
5302
5309
|
if (decl.async) {
|
5303
5310
|
// make promise at the start
|
5304
5311
|
wasm.unshift(
|
5305
|
-
[ Opcodes.call,
|
5312
|
+
[ Opcodes.call, includeBuiltin(func, '__Porffor_promise_create').index ],
|
5306
5313
|
[ Opcodes.drop ],
|
5307
5314
|
[ Opcodes.local_set, func.locals['#async_out_promise'].idx ]
|
5308
5315
|
);
|
@@ -5341,7 +5348,7 @@ const generateFunc = (scope, decl) => {
|
|
5341
5348
|
// inject promise job runner func at the end of main if used
|
5342
5349
|
if (Object.hasOwn(funcIndex, '__ecma262_HostEnqueuePromiseJob')) {
|
5343
5350
|
wasm.push(
|
5344
|
-
[ Opcodes.call,
|
5351
|
+
[ Opcodes.call, includeBuiltin(scope, '__Porffor_promise_runJobs').index ],
|
5345
5352
|
[ Opcodes.drop ],
|
5346
5353
|
[ Opcodes.drop ]
|
5347
5354
|
);
|
package/compiler/decompile.js
CHANGED
@@ -98,7 +98,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
|
|
98
98
|
}
|
99
99
|
|
100
100
|
if (inst[0] === Opcodes.call || inst[0] === Opcodes.return_call) {
|
101
|
-
const idx =
|
101
|
+
const idx = inst[1];
|
102
102
|
const callFunc = funcs.find(x => x.index === idx);
|
103
103
|
if (callFunc) out += ` ;; $${callFunc.name} ${makeSignature(callFunc.params, callFunc.returns)}`;
|
104
104
|
if (globalThis.importFuncs && idx < importFuncs.length) {
|
package/compiler/index.js
CHANGED
@@ -117,14 +117,11 @@ export default (code, flags) => {
|
|
117
117
|
|
118
118
|
const done = new Set();
|
119
119
|
for (let i = 0; i < data.length; i++) {
|
120
|
-
// const run = (x, done = new Set()) => {
|
121
120
|
const run = x => {
|
122
121
|
const out = [ x.name, [] ];
|
123
122
|
if (x.includes && !done.has(x.name)) {
|
124
123
|
done.add(x.name);
|
125
124
|
for (const y of x.includes) {
|
126
|
-
// out[1].push(run(funcsByName[y], new Set(done)));
|
127
|
-
// out[1].push(run(funcsByName[y], done));
|
128
125
|
out[1].push(run(funcsByName[y], done));
|
129
126
|
}
|
130
127
|
}
|
package/compiler/precompile.js
CHANGED
@@ -57,6 +57,7 @@ const compile = async (file, _funcs) => {
|
|
57
57
|
|
58
58
|
const paramOverrides = {
|
59
59
|
__Porffor_object_set: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
|
60
|
+
__Porffor_object_expr_init: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
|
60
61
|
__Porffor_object_define: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32, Valtype.i32, Valtype.i32 ],
|
61
62
|
};
|
62
63
|
|
@@ -91,7 +92,7 @@ const compile = async (file, _funcs) => {
|
|
91
92
|
const y = wasm[i];
|
92
93
|
const n = wasm[i + 1];
|
93
94
|
if (y[0] === Opcodes.call) {
|
94
|
-
const idx =
|
95
|
+
const idx = y[1];
|
95
96
|
const f = funcs.find(x => x.index === idx);
|
96
97
|
if (!f) continue;
|
97
98
|
|
@@ -203,8 +204,8 @@ ${funcs.map(x => {
|
|
203
204
|
.replace(/\["alloc","(.*?)","(.*?)",(.*?)\]/g, (_, reason, type, valtype) => `...number(allocPage(scope, '${reason}', '${type}') * pageSize, ${valtype})`)
|
204
205
|
.replace(/\["global",(.*?),"(.*?)",(.*?)\]/g, (_, opcode, name, valtype) => `...glbl(${opcode}, '${name}', ${valtype})`)
|
205
206
|
.replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}', ${valtype})]`)
|
206
|
-
.replace(/\[16,"(.*?)"]/g, (_, name) => `[16,
|
207
|
-
.replace(/\[68,"funcref","(.*?)"]/g, (_, name, offset) => `[68
|
207
|
+
.replace(/\[16,"(.*?)"]/g, (_, name) => `[16, builtin('${name}')]`)
|
208
|
+
.replace(/\[68,"funcref","(.*?)"]/g, (_, name, offset) => `[68, ...builtin('${name}', true, true)]`)
|
208
209
|
.replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(scope, '${constructor}', \`${message}\`)`)
|
209
210
|
.replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(scope, { name: '${objName}' })`);
|
210
211
|
|
package/compiler/wrap.js
CHANGED
@@ -75,9 +75,10 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type, override = undefin
|
|
75
75
|
porfToJSValue({ memory, funcs, pages }, vValue, vType);
|
76
76
|
|
77
77
|
const flags = tail & 0xff;
|
78
|
+
const accessor = flags & 0b0001;
|
78
79
|
|
79
80
|
let get, set;
|
80
|
-
if (
|
81
|
+
if (accessor) {
|
81
82
|
0, [ get, set ] = read(Uint32Array, memory, value + offset + 4, 2);
|
82
83
|
}
|
83
84
|
|
@@ -99,11 +100,21 @@ ${flags & 0b0001 ? ` get func idx: ${get}
|
|
99
100
|
const configurable = flags & 0b0010;
|
100
101
|
const enumerable = flags & 0b0100;
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
103
|
+
if (accessor) {
|
104
|
+
// mock get/set funcs
|
105
|
+
Object.defineProperty(out, k, {
|
106
|
+
get: () => {},
|
107
|
+
set: () => {},
|
108
|
+
configurable,
|
109
|
+
enumerable,
|
110
|
+
});
|
111
|
+
} else {
|
112
|
+
Object.defineProperty(out, k, {
|
113
|
+
value: v,
|
114
|
+
configurable,
|
115
|
+
enumerable,
|
116
|
+
});
|
117
|
+
}
|
107
118
|
}
|
108
119
|
|
109
120
|
return out;
|
package/package.json
CHANGED