porffor 0.17.0-bf4206d7b → 0.17.0-cab4904b8
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/builtins/math.ts +6 -2
- package/compiler/builtins/set.ts +5 -0
- package/compiler/builtins.js +14 -0
- package/compiler/codegen.js +140 -31
- package/compiler/generated_builtins.js +12 -2
- package/compiler/wrap.js +50 -8
- package/package.json +1 -1
- package/runner/index.js +3 -1
@@ -16,7 +16,7 @@ export const __Math_exp = (x: number): number => {
|
|
16
16
|
return 1 / Math.exp(-x);
|
17
17
|
}
|
18
18
|
|
19
|
-
|
19
|
+
let k: number = Math.floor(x / Math.LN2);
|
20
20
|
const r: number = x - k * Math.LN2;
|
21
21
|
|
22
22
|
// Taylor series via Horner's method
|
@@ -30,7 +30,11 @@ export const __Math_exp = (x: number): number => {
|
|
30
30
|
i++;
|
31
31
|
}
|
32
32
|
|
33
|
-
|
33
|
+
while (k-- > 0) {
|
34
|
+
sum *= 2;
|
35
|
+
}
|
36
|
+
|
37
|
+
return sum;
|
34
38
|
};
|
35
39
|
|
36
40
|
export const __Math_log2 = (y: number): number => {
|
package/compiler/builtins/set.ts
CHANGED
package/compiler/builtins.js
CHANGED
@@ -184,6 +184,20 @@ export const BuiltinFuncs = function() {
|
|
184
184
|
]
|
185
185
|
};
|
186
186
|
|
187
|
+
this['f64_**'] = this['i32_**'] = {
|
188
|
+
params: [ valtypeBinary, valtypeBinary ],
|
189
|
+
locals: [],
|
190
|
+
returns: [ valtypeBinary ],
|
191
|
+
returnType: TYPES.number,
|
192
|
+
wasm: (scope, { builtin }) => [
|
193
|
+
[ Opcodes.local_get, 0 ],
|
194
|
+
...number(TYPES.number, Valtype.i32),
|
195
|
+
[ Opcodes.local_get, 1 ],
|
196
|
+
...number(TYPES.number, Valtype.i32),
|
197
|
+
[ Opcodes.call, builtin('__Math_pow') ]
|
198
|
+
]
|
199
|
+
};
|
200
|
+
|
187
201
|
// add bitwise ops by converting operands to i32 first
|
188
202
|
for (const [ char, op ] of [ ['&', Opcodes.i32_and], ['|', Opcodes.i32_or], ['^', Opcodes.i32_xor], ['<<', Opcodes.i32_shl], ['>>', Opcodes.i32_shr_s], ['>>>', Opcodes.i32_shr_u] ]) {
|
189
203
|
this[`f64_${char}`] = {
|
package/compiler/codegen.js
CHANGED
@@ -72,6 +72,9 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
72
72
|
case 'ExpressionStatement':
|
73
73
|
return generateExp(scope, decl);
|
74
74
|
|
75
|
+
case 'SequenceExpression':
|
76
|
+
return generateSequence(scope, decl);
|
77
|
+
|
75
78
|
case 'CallExpression':
|
76
79
|
return generateCall(scope, decl, global, name, valueUnused);
|
77
80
|
|
@@ -264,10 +267,12 @@ const internalThrow = (scope, constructor, message, expectsValue = Prefs.alwaysV
|
|
264
267
|
argument: {
|
265
268
|
type: 'NewExpression',
|
266
269
|
callee: {
|
270
|
+
type: 'Identifier',
|
267
271
|
name: constructor
|
268
272
|
},
|
269
273
|
arguments: [
|
270
274
|
{
|
275
|
+
type: 'Literal',
|
271
276
|
value: message
|
272
277
|
}
|
273
278
|
]
|
@@ -289,12 +294,13 @@ const generateIdent = (scope, decl) => {
|
|
289
294
|
return wasm.slice();
|
290
295
|
}
|
291
296
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
297
|
+
// todo: enable this by default in future
|
298
|
+
// if (!Object.hasOwn(funcIndex, name) && Object.hasOwn(builtinFuncs, name)) {
|
299
|
+
// includeBuiltin(scope, name);
|
300
|
+
// return number(funcIndex[name] - importedFuncs.length);
|
301
|
+
// }
|
296
302
|
|
297
|
-
if (isExistingProtoFunc(name)) {
|
303
|
+
if (isExistingProtoFunc(name) || Object.hasOwn(internalConstrs, name) || Object.hasOwn(builtinFuncs, name)) {
|
298
304
|
// todo: return an actual something
|
299
305
|
return number(1);
|
300
306
|
}
|
@@ -973,6 +979,33 @@ const performOp = (scope, op, left, right, leftType, rightType, _global = false,
|
|
973
979
|
};
|
974
980
|
|
975
981
|
const generateBinaryExp = (scope, decl, _global, _name) => {
|
982
|
+
if (decl.operator === 'instanceof') {
|
983
|
+
// very hacky basic instanceof
|
984
|
+
// todo: support dynamic right-hand side
|
985
|
+
|
986
|
+
const out = generate(scope, decl.left);
|
987
|
+
disposeLeftover(out);
|
988
|
+
|
989
|
+
const rightName = decl.right.name;
|
990
|
+
if (!rightName) return todo(scope, 'instanceof dynamic right-hand side is not supported yet', true);
|
991
|
+
|
992
|
+
const checkType = TYPES[rightName.toLowerCase()];
|
993
|
+
if (checkType == null || rightName !== TYPE_NAMES[checkType] || checkType === TYPES.undefined) return todo(scope, 'instanceof right-hand side type unsupported', true);
|
994
|
+
|
995
|
+
if ([TYPES.number, TYPES.boolean, TYPES.string, TYPES.symbol, TYPES.object].includes(checkType)) {
|
996
|
+
out.push(...number(0));
|
997
|
+
} else {
|
998
|
+
out.push(
|
999
|
+
...getNodeType(scope, decl.left),
|
1000
|
+
...number(checkType, Valtype.i32),
|
1001
|
+
[ Opcodes.i32_eq ],
|
1002
|
+
Opcodes.i32_from_u
|
1003
|
+
);
|
1004
|
+
}
|
1005
|
+
|
1006
|
+
return out;
|
1007
|
+
}
|
1008
|
+
|
976
1009
|
const out = performOp(scope, decl.operator, generate(scope, decl.left), generate(scope, decl.right), getNodeType(scope, decl.left), getNodeType(scope, decl.right), _global, _name);
|
977
1010
|
|
978
1011
|
if (valtype !== 'i32' && ['==', '===', '!=', '!==', '>', '>=', '<', '<='].includes(decl.operator)) out.push(Opcodes.i32_from_u);
|
@@ -1279,7 +1312,7 @@ const getNodeType = (scope, node) => {
|
|
1279
1312
|
}
|
1280
1313
|
|
1281
1314
|
if (node.type === 'BinaryExpression') {
|
1282
|
-
if (['==', '===', '!=', '!==', '>', '>=', '<', '<='].includes(node.operator)) return TYPES.boolean;
|
1315
|
+
if (['==', '===', '!=', '!==', '>', '>=', '<', '<=', 'instanceof'].includes(node.operator)) return TYPES.boolean;
|
1283
1316
|
if (node.operator !== '+') return TYPES.number;
|
1284
1317
|
|
1285
1318
|
const knownLeft = knownType(scope, getNodeType(scope, node.left));
|
@@ -1424,6 +1457,18 @@ const generateExp = (scope, decl) => {
|
|
1424
1457
|
return out;
|
1425
1458
|
};
|
1426
1459
|
|
1460
|
+
const generateSequence = (scope, decl) => {
|
1461
|
+
let out = [];
|
1462
|
+
|
1463
|
+
const exprs = decl.expressions;
|
1464
|
+
for (let i = 0; i < exprs.length; i++) {
|
1465
|
+
if (i > 0) disposeLeftover(out);
|
1466
|
+
out.push(...generate(scope, exprs[i]));
|
1467
|
+
}
|
1468
|
+
|
1469
|
+
return out;
|
1470
|
+
};
|
1471
|
+
|
1427
1472
|
const CTArrayUtil = {
|
1428
1473
|
getLengthI32: pointer => [
|
1429
1474
|
...number(0, Valtype.i32),
|
@@ -2299,11 +2344,6 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2299
2344
|
const { type, name } = decl.left;
|
2300
2345
|
const [ local, isGlobal ] = lookupName(scope, name);
|
2301
2346
|
|
2302
|
-
if (type === 'ObjectPattern') {
|
2303
|
-
// hack: ignore object parts of `var a = {} = 2`
|
2304
|
-
return generate(scope, decl.right);
|
2305
|
-
}
|
2306
|
-
|
2307
2347
|
if (isFuncType(decl.right.type)) {
|
2308
2348
|
// hack for a = function () { ... }
|
2309
2349
|
decl.right.id = { name };
|
@@ -3029,32 +3069,101 @@ const generateLabel = (scope, decl) => {
|
|
3029
3069
|
const generateThrow = (scope, decl) => {
|
3030
3070
|
scope.throws = true;
|
3031
3071
|
|
3032
|
-
|
3072
|
+
const exceptionMode = Prefs.exceptionMode ?? 'lut';
|
3073
|
+
if (exceptionMode === 'lut') {
|
3074
|
+
let message = decl.argument.value, constructor = null;
|
3075
|
+
|
3076
|
+
// support `throw (new)? Error(...)`
|
3077
|
+
if (!message && (decl.argument.type === 'NewExpression' || decl.argument.type === 'CallExpression')) {
|
3078
|
+
constructor = decl.argument.callee.name;
|
3079
|
+
message = decl.argument.arguments[0]?.value ?? '';
|
3080
|
+
}
|
3081
|
+
|
3082
|
+
if (tags.length === 0) tags.push({
|
3083
|
+
params: [ Valtype.i32 ],
|
3084
|
+
results: [],
|
3085
|
+
idx: tags.length
|
3086
|
+
});
|
3087
|
+
|
3088
|
+
let exceptId = exceptions.push({ constructor, message }) - 1;
|
3089
|
+
|
3090
|
+
scope.exceptions ??= [];
|
3091
|
+
scope.exceptions.push(exceptId);
|
3033
3092
|
|
3034
|
-
|
3035
|
-
|
3036
|
-
|
3037
|
-
|
3093
|
+
return [
|
3094
|
+
[ Opcodes.i32_const, signedLEB128(exceptId) ],
|
3095
|
+
[ Opcodes.throw, tags[0].idx ]
|
3096
|
+
];
|
3038
3097
|
}
|
3039
3098
|
|
3040
|
-
if (
|
3041
|
-
|
3042
|
-
|
3043
|
-
|
3044
|
-
|
3099
|
+
if (exceptionMode === 'stack') {
|
3100
|
+
if (tags.length === 0) tags.push({
|
3101
|
+
params: [ valtypeBinary, Valtype.i32 ],
|
3102
|
+
results: [],
|
3103
|
+
idx: tags.length
|
3104
|
+
});
|
3045
3105
|
|
3046
|
-
|
3047
|
-
|
3106
|
+
return [
|
3107
|
+
...generate(scope, decl.argument),
|
3108
|
+
...getNodeType(scope, decl.argument),
|
3109
|
+
[ Opcodes.throw, tags[0].idx ]
|
3110
|
+
];
|
3111
|
+
}
|
3112
|
+
|
3113
|
+
if (exceptionMode === 'stackest') {
|
3114
|
+
let message = decl.argument, constructor = null;
|
3048
3115
|
|
3049
|
-
|
3050
|
-
|
3116
|
+
// support `throw (new)? Error(...)`
|
3117
|
+
if (message.type === 'NewExpression' || message.type === 'CallExpression') {
|
3118
|
+
constructor = decl.argument.callee;
|
3119
|
+
message = decl.argument.arguments[0];
|
3120
|
+
}
|
3051
3121
|
|
3052
|
-
|
3122
|
+
message ??= DEFAULT_VALUE;
|
3053
3123
|
|
3054
|
-
|
3055
|
-
|
3056
|
-
|
3057
|
-
|
3124
|
+
if (tags.length === 0) tags.push({
|
3125
|
+
params: [ valtypeBinary, valtypeBinary, Valtype.i32 ],
|
3126
|
+
results: [],
|
3127
|
+
idx: tags.length
|
3128
|
+
});
|
3129
|
+
|
3130
|
+
return [
|
3131
|
+
...(constructor == null ? number(-1) : generate(scope, constructor)),
|
3132
|
+
...generate(scope, message),
|
3133
|
+
...getNodeType(scope, message),
|
3134
|
+
[ Opcodes.throw, tags[0].idx ]
|
3135
|
+
];
|
3136
|
+
}
|
3137
|
+
|
3138
|
+
if (exceptionMode === 'partial') {
|
3139
|
+
let message = decl.argument, constructor = null;
|
3140
|
+
|
3141
|
+
// support `throw (new)? Error(...)`
|
3142
|
+
if (message.type === 'NewExpression' || message.type === 'CallExpression') {
|
3143
|
+
constructor = decl.argument.callee.name;
|
3144
|
+
message = decl.argument.arguments[0];
|
3145
|
+
}
|
3146
|
+
|
3147
|
+
message ??= DEFAULT_VALUE;
|
3148
|
+
|
3149
|
+
if (tags.length === 0) tags.push({
|
3150
|
+
params: [ Valtype.i32, valtypeBinary, Valtype.i32 ],
|
3151
|
+
results: [],
|
3152
|
+
idx: tags.length
|
3153
|
+
});
|
3154
|
+
|
3155
|
+
let exceptId = exceptions.push({ constructor }) - 1;
|
3156
|
+
|
3157
|
+
scope.exceptions ??= [];
|
3158
|
+
scope.exceptions.push(exceptId);
|
3159
|
+
|
3160
|
+
return [
|
3161
|
+
[ Opcodes.i32_const, signedLEB128(exceptId) ],
|
3162
|
+
...generate(scope, message),
|
3163
|
+
...getNodeType(scope, message),
|
3164
|
+
[ Opcodes.throw, tags[0].idx ]
|
3165
|
+
];
|
3166
|
+
}
|
3058
3167
|
};
|
3059
3168
|
|
3060
3169
|
const generateTry = (scope, decl) => {
|
@@ -3772,7 +3881,7 @@ const internalConstrs = {
|
|
3772
3881
|
|
3773
3882
|
// todo: check in wasm instead of here
|
3774
3883
|
const literalValue = arg.value ?? 0;
|
3775
|
-
if (literalValue < 0 || !Number.isFinite(literalValue) || literalValue > 4294967295) return internalThrow(scope, '
|
3884
|
+
if (literalValue < 0 || !Number.isFinite(literalValue) || literalValue > 4294967295) return internalThrow(scope, 'RangeError', 'Invalid array length', true);
|
3776
3885
|
|
3777
3886
|
return [
|
3778
3887
|
...out,
|
@@ -1417,7 +1417,7 @@ export const BuiltinFuncs = function() {
|
|
1417
1417
|
localNames: ["input","input#type","radix","radix#type","logictmpi","#last_type","#logicinner_tmp","#typeswitch_tmp","nMax","n","inputPtr","len","i","negative","endPtr","startChr","second","chr"],
|
1418
1418
|
};
|
1419
1419
|
this.__Math_exp = {
|
1420
|
-
wasm: (scope, {builtin,}) => [[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[32,0],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,0,0,0,0,0,0,240,63],[32,0],[154],[65,0],[16, builtin('__Math_exp')],[163],[15],[11],[32,0],[68,239,57,250,254,66,46,230,63],[163],[16, builtin('__Math_floor')],[33,2],[32,0],[32,2],[68,239,57,250,254,66,46,230,63],[162],[161],[34,3],[33,4],[68,0,0,0,0,0,0,240,63],[32,3],[160],[33,5],[68,0,0,0,0,0,0,0,64],[33,6],[3,64],[32,4],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,4],[32,3],[32,6],[163],[162],[33,4],[32,5],[32,4],[160],[33,5],[32,6],[68,0,0,0,0,0,0,240,63],[160],[33,6],[12,1],[11],[11],[32,
|
1420
|
+
wasm: (scope, {builtin,}) => [[32,0],[16, builtin('__Number_isFinite')],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,127],[154],[97],[4,64],[68,0,0,0,0,0,0,0,0],[15],[11],[32,0],[15],[11],[32,0],[68,0,0,0,0,0,0,0,0],[99],[4,64],[68,0,0,0,0,0,0,240,63],[32,0],[154],[65,0],[16, builtin('__Math_exp')],[163],[15],[11],[32,0],[68,239,57,250,254,66,46,230,63],[163],[16, builtin('__Math_floor')],[33,2],[32,0],[32,2],[68,239,57,250,254,66,46,230,63],[162],[161],[34,3],[33,4],[68,0,0,0,0,0,0,240,63],[32,3],[160],[33,5],[68,0,0,0,0,0,0,0,64],[33,6],[3,64],[32,4],[16, builtin('__Math_abs')],[68,22,86,231,158,175,3,210,60],[100],[4,64],[32,4],[32,3],[32,6],[163],[162],[33,4],[32,5],[32,4],[160],[33,5],[32,6],[68,0,0,0,0,0,0,240,63],[160],[33,6],[12,1],[11],[11],[3,64],[32,2],[32,2],[68,0,0,0,0,0,0,240,63],[161],[33,2],[68,0,0,0,0,0,0,0,0],[100],[4,64],[32,5],[68,0,0,0,0,0,0,0,64],[162],[33,5],[12,1],[11],[11],[32,5],[15]],
|
1421
1421
|
params: [124,127],
|
1422
1422
|
typedParams: true,
|
1423
1423
|
returns: [124],
|
@@ -1786,6 +1786,16 @@ export const BuiltinFuncs = function() {
|
|
1786
1786
|
locals: [124,127,127,127,124,127,127,127],
|
1787
1787
|
localNames: ["_this","_this#type","other","other#type","out","forof_base_pointer","forof_length","forof_counter","x","x#type","#last_type","#typeswitch_tmp"],
|
1788
1788
|
};
|
1789
|
+
this.__Set_prototype_toString = {
|
1790
|
+
wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: __Set_prototype_toString/out', 'i8') * pageSize, 124),[34,2],[65,18],[15]],
|
1791
|
+
params: [124,127],
|
1792
|
+
typedParams: true,
|
1793
|
+
returns: [124,127],
|
1794
|
+
typedReturns: true,
|
1795
|
+
locals: [124],
|
1796
|
+
localNames: ["_this","_this#type","out"],
|
1797
|
+
data: [{"bytes":[12,0,0,0,91,111,98,106,101,99,116,32,83,101,116,93],"offset":0}],
|
1798
|
+
};
|
1789
1799
|
this.__String_fromCharCode = {
|
1790
1800
|
wasm: (scope, {allocPage,}) => [[32,0],[65,128,2],[72],[4,64],...number(allocPage(scope, 'bytestring: __String_fromCharCode/out', 'i8') * pageSize, 127),[34,2],[32,0],[58,0,4],[32,2],[65,18],[15],[11],[32,2],[34,3],[65,1],[54,1,0],[32,3],[65,46],[59,0,4],[32,3],[34,2],[32,0],[59,0,4],[32,2],[65,2],[15]],
|
1791
1801
|
params: [127,127],
|
@@ -2175,7 +2185,7 @@ export const BuiltinFuncs = function() {
|
|
2175
2185
|
localNames: ["argument","argument#type","number"],
|
2176
2186
|
};
|
2177
2187
|
this.__ecma262_ToString = {
|
2178
|
-
wasm: (scope, {allocPage,builtin,internalThrow,}) => [...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,3],[68,0,0,0,0,0,0,0,64],[97],[32,3],[68,0,0,0,0,0,0,50,64],[97],[114],[4,64],[32,0],[15],[11],[32,3],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,3],[68,0,0,0,0,0,0,8,64],[97],[4,64],[32,2],[252,3],[34,4],[65,9],[54,1,0],[32,4],[65,245,0],[58,0,4],[32,4],[65,238,0],[58,0,5],[32,4],[65,228,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[65,230,0],[58,0,8],[32,4],[65,233,0],[58,0,9],[32,4],[65,238,0],[58,0,10],[32,4],[65,229,0],[58,0,11],[32,4],[65,228,0],[58,0,12],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,238,0],[58,0,4],[32,4],[65,245,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,236,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,244,0],[58,0,4],[32,4],[65,242,0],[58,0,5],[32,4],[65,245,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,2],[252,3],[34,4],[65,5],[54,1,0],[32,4],[65,230,0],[58,0,4],[32,4],[65,225,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,243,0],[58,0,7],[32,4],[65,229,0],[58,0,8],[32,4],[184],[34,2],[15],[11],[32,1],[33,6],[2,124],[32,6],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,0],[32,1],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[26],[12,1],[11],[32,6],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,0],[32,1],[16, builtin('__Boolean_prototype_toString')],[26],[12,1],[11],[32,6],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,0],[252,2],[32,1],[16, builtin('__String_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,0],[32,1],[16, builtin('__Object_prototype_toString')],[26],[12,1],[11],[32,6],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,0],[32,1],[16, builtin('__Function_prototype_toString')],[26],[12,1],[11],[32,6],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,0],[32,1],[16, builtin('__Symbol_prototype_toString')],[26],[12,1],[11],[32,6],[65,16],[70],[4,64,"TYPESWITCH|Array"],[32,0],[32,1],[16, builtin('__Array_prototype_toString')],[26],[12,1],[11],[32,6],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,0],[252,2],[32,1],[16, builtin('__ByteString_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,19],[70],[4,64,"TYPESWITCH|Date"],[32,0],[32,1],[16, builtin('__Date_prototype_toString')],[26],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[15]],
|
2188
|
+
wasm: (scope, {allocPage,builtin,internalThrow,}) => [...number(allocPage(scope, 'bytestring: __ecma262_ToString/out', 'i8') * pageSize, 124),[33,2],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[34,3],[68,0,0,0,0,0,0,0,64],[97],[32,3],[68,0,0,0,0,0,0,50,64],[97],[114],[4,64],[32,0],[15],[11],[32,3],[68,0,0,0,0,0,0,24,64],[97],[4,64],...internalThrow(scope, 'TypeError', `Cannot convert a Symbol value to a string`),[11],[32,3],[68,0,0,0,0,0,0,8,64],[97],[4,64],[32,2],[252,3],[34,4],[65,9],[54,1,0],[32,4],[65,245,0],[58,0,4],[32,4],[65,238,0],[58,0,5],[32,4],[65,228,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[65,230,0],[58,0,8],[32,4],[65,233,0],[58,0,9],[32,4],[65,238,0],[58,0,10],[32,4],[65,229,0],[58,0,11],[32,4],[65,228,0],[58,0,12],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,16,64],[97],[32,0],[68,0,0,0,0,0,0,0,0],[97],[113],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,238,0],[58,0,4],[32,4],[65,245,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,236,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,3],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,2],[252,3],[34,4],[65,4],[54,1,0],[32,4],[65,244,0],[58,0,4],[32,4],[65,242,0],[58,0,5],[32,4],[65,245,0],[58,0,6],[32,4],[65,229,0],[58,0,7],[32,4],[184],[34,2],[15],[11],[32,2],[252,3],[34,4],[65,5],[54,1,0],[32,4],[65,230,0],[58,0,4],[32,4],[65,225,0],[58,0,5],[32,4],[65,236,0],[58,0,6],[32,4],[65,243,0],[58,0,7],[32,4],[65,229,0],[58,0,8],[32,4],[184],[34,2],[15],[11],[32,1],[33,6],[2,124],[32,6],[65,0],[70],[4,64,"TYPESWITCH|Number"],[32,0],[32,1],[68,0,0,0,0,0,0,0,0],[65,3],[16, builtin('__Number_prototype_toString')],[26],[12,1],[11],[32,6],[65,1],[70],[4,64,"TYPESWITCH|Boolean"],[32,0],[32,1],[16, builtin('__Boolean_prototype_toString')],[26],[12,1],[11],[32,6],[65,2],[70],[4,64,"TYPESWITCH|String"],[32,0],[252,2],[32,1],[16, builtin('__String_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,4],[70],[4,64,"TYPESWITCH|Object"],[32,0],[32,1],[16, builtin('__Object_prototype_toString')],[26],[12,1],[11],[32,6],[65,5],[70],[4,64,"TYPESWITCH|Function"],[32,0],[32,1],[16, builtin('__Function_prototype_toString')],[26],[12,1],[11],[32,6],[65,6],[70],[4,64,"TYPESWITCH|Symbol"],[32,0],[32,1],[16, builtin('__Symbol_prototype_toString')],[26],[12,1],[11],[32,6],[65,16],[70],[4,64,"TYPESWITCH|Array"],[32,0],[32,1],[16, builtin('__Array_prototype_toString')],[26],[12,1],[11],[32,6],[65,18],[70],[4,64,"TYPESWITCH|ByteString"],[32,0],[252,2],[32,1],[16, builtin('__ByteString_prototype_toString')],[26],[183],[12,1],[11],[32,6],[65,19],[70],[4,64,"TYPESWITCH|Date"],[32,0],[32,1],[16, builtin('__Date_prototype_toString')],[26],[12,1],[11],[32,6],[65,20],[70],[4,64,"TYPESWITCH|Set"],[32,0],[32,1],[16, builtin('__Set_prototype_toString')],[26],[12,1],[11],...internalThrow(scope, 'TypeError', `'toString' proto func tried to be called on a type without an impl`),[11,"TYPESWITCH_end"],[15]],
|
2179
2189
|
params: [124,127],
|
2180
2190
|
typedParams: true,
|
2181
2191
|
returns: [124],
|
package/compiler/wrap.js
CHANGED
@@ -127,7 +127,7 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
127
127
|
|
128
128
|
globalThis.porfDebugInfo = { funcs, globals };
|
129
129
|
|
130
|
-
if (source.includes?.('export ')) flags.push('module');
|
130
|
+
if (process.argv[1].includes('/runner') && source.includes?.('export ')) flags.push('module');
|
131
131
|
|
132
132
|
// fs.writeFileSync('out.wasm', Buffer.from(wasm));
|
133
133
|
|
@@ -297,16 +297,58 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
|
|
297
297
|
return porfToJSValue({ memory, funcs, pages }, ret[0], ret[1]);
|
298
298
|
} catch (e) {
|
299
299
|
if (e.is && e.is(exceptTag)) {
|
300
|
-
const
|
301
|
-
|
300
|
+
const exceptionMode = Prefs.exceptionMode ?? 'lut';
|
301
|
+
if (exceptionMode === 'lut') {
|
302
|
+
const exceptId = e.getArg(exceptTag, 0);
|
303
|
+
const exception = exceptions[exceptId];
|
302
304
|
|
303
|
-
|
305
|
+
const constructorName = exception.constructor;
|
304
306
|
|
305
|
-
|
306
|
-
|
307
|
+
// no constructor, just throw message
|
308
|
+
if (!constructorName) throw exception.message;
|
307
309
|
|
308
|
-
|
309
|
-
|
310
|
+
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
311
|
+
throw new constructor(exception.message);
|
312
|
+
}
|
313
|
+
|
314
|
+
if (exceptionMode === 'stack') {
|
315
|
+
const value = e.getArg(exceptTag, 0);
|
316
|
+
const type = e.getArg(exceptTag, 1);
|
317
|
+
|
318
|
+
throw porfToJSValue({ memory, funcs, pages }, value, type);
|
319
|
+
}
|
320
|
+
|
321
|
+
if (exceptionMode === 'stackest') {
|
322
|
+
const constructorIdx = e.getArg(exceptTag, 0);
|
323
|
+
const constructorName = constructorIdx == -1 ? null : funcs.find(x => ((x.originalIndex ?? x.index) - importedFuncs.length) === constructorIdx)?.name;
|
324
|
+
|
325
|
+
const value = e.getArg(exceptTag, 1);
|
326
|
+
const type = e.getArg(exceptTag, 2);
|
327
|
+
const message = porfToJSValue({ memory, funcs, pages }, value, type);
|
328
|
+
|
329
|
+
// no constructor, just throw message
|
330
|
+
if (!constructorName) throw message;
|
331
|
+
|
332
|
+
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
333
|
+
throw new constructor(message);
|
334
|
+
}
|
335
|
+
|
336
|
+
if (exceptionMode === 'partial') {
|
337
|
+
const exceptId = e.getArg(exceptTag, 0);
|
338
|
+
const exception = exceptions[exceptId];
|
339
|
+
|
340
|
+
const constructorName = exception.constructor;
|
341
|
+
|
342
|
+
const value = e.getArg(exceptTag, 1);
|
343
|
+
const type = e.getArg(exceptTag, 2);
|
344
|
+
const message = porfToJSValue({ memory, funcs, pages }, value, type);
|
345
|
+
|
346
|
+
// no constructor, just throw message
|
347
|
+
if (!constructorName) throw message;
|
348
|
+
|
349
|
+
const constructor = globalThis[constructorName] ?? eval(`class ${constructorName} extends Error { constructor(message) { super(message); this.name = "${constructorName}"; } }; ${constructorName}`);
|
350
|
+
throw new constructor(message);
|
351
|
+
}
|
310
352
|
}
|
311
353
|
|
312
354
|
if (e instanceof WebAssembly.RuntimeError) {
|
package/package.json
CHANGED
package/runner/index.js
CHANGED
@@ -145,7 +145,9 @@ try {
|
|
145
145
|
// if (cache) process.stdout.write(cache);
|
146
146
|
} catch (e) {
|
147
147
|
// if (cache) process.stdout.write(cache);
|
148
|
-
|
148
|
+
let out = e;
|
149
|
+
if (!process.argv.includes('-i') && e.__proto__.message != null) out = `${e.constructor.name}${e.message != null ? `: ${e.message}` : ''}`;
|
150
|
+
console.error(out);
|
149
151
|
}
|
150
152
|
|
151
153
|
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`);
|