porffor 0.22.8 → 0.22.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 +21 -3
- package/compiler/builtins/_internal_object.ts +61 -4
- package/compiler/builtins/console.ts +17 -2
- package/compiler/builtins/object.ts +31 -2
- package/compiler/builtins.js +36 -27
- package/compiler/builtins_objects.js +181 -0
- package/compiler/builtins_precompiled.js +4603 -0
- package/compiler/codegen.js +88 -79
- package/compiler/havoc.js +0 -25
- package/compiler/precompile.js +1 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
- package/compiler/generated_builtins.js +0 -4603
package/compiler/codegen.js
CHANGED
@@ -295,7 +295,7 @@ const internalThrow = (scope, constructor, message, expectsValue = Prefs.alwaysV
|
|
295
295
|
arguments: [
|
296
296
|
{
|
297
297
|
type: 'Literal',
|
298
|
-
value: message
|
298
|
+
value: Prefs.d ? `${message} (in ${scope.name})` : message
|
299
299
|
}
|
300
300
|
]
|
301
301
|
}
|
@@ -316,13 +316,11 @@ const generateIdent = (scope, decl) => {
|
|
316
316
|
return wasm.slice();
|
317
317
|
}
|
318
318
|
|
319
|
-
// todo: enable this by default in future
|
320
319
|
if (!Object.hasOwn(funcIndex, name) && Object.hasOwn(builtinFuncs, name)) {
|
321
320
|
includeBuiltin(scope, name);
|
322
|
-
return number(funcIndex[name] - importedFuncs.length);
|
323
321
|
}
|
324
322
|
|
325
|
-
if (isExistingProtoFunc(name) || Object.hasOwn(internalConstrs, name)
|
323
|
+
if (isExistingProtoFunc(name) || Object.hasOwn(internalConstrs, name)) {
|
326
324
|
// todo: return an actual something
|
327
325
|
return number(1);
|
328
326
|
}
|
@@ -1177,6 +1175,7 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
|
|
1177
1175
|
const asmFuncToAsm = (scope, func) => {
|
1178
1176
|
return func(scope, {
|
1179
1177
|
TYPES, TYPE_NAMES, typeSwitch, makeArray, makeString, allocPage, internalThrow,
|
1178
|
+
getNodeType, generateIdent,
|
1180
1179
|
builtin: n => {
|
1181
1180
|
let idx = funcIndex[n] ?? importedFuncs[n];
|
1182
1181
|
if (idx == null && builtinFuncs[n]) {
|
@@ -1228,7 +1227,7 @@ const asmFuncToAsm = (scope, func) => {
|
|
1228
1227
|
});
|
1229
1228
|
};
|
1230
1229
|
|
1231
|
-
const asmFunc = (name, { wasm, params = [], locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], data: _data = [], table = false, constr = false, hasRestArgument = false } = {}) => {
|
1230
|
+
const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTypes = [], globals: globalTypes = [], globalInits = [], returns = [], returnType, localNames = [], globalNames = [], data: _data = [], table = false, constr = false, hasRestArgument = false } = {}) => {
|
1232
1231
|
if (wasm == null) { // called with no builtin
|
1233
1232
|
log.warning('codegen', `${name} has no built-in!`);
|
1234
1233
|
wasm = [];
|
@@ -1256,6 +1255,7 @@ const asmFunc = (name, { wasm, params = [], locals: localTypes = [], globals: gl
|
|
1256
1255
|
const func = {
|
1257
1256
|
name,
|
1258
1257
|
params,
|
1258
|
+
typedParams,
|
1259
1259
|
locals,
|
1260
1260
|
localInd: allLocals.length,
|
1261
1261
|
returns,
|
@@ -2263,7 +2263,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2263
2263
|
|
2264
2264
|
// get if func we are calling is a constructor or not
|
2265
2265
|
[ Opcodes.local_get, funcLocal ],
|
2266
|
-
...number(
|
2266
|
+
...number(128, Valtype.i32),
|
2267
2267
|
[ Opcodes.i32_mul ],
|
2268
2268
|
...number(2, Valtype.i32),
|
2269
2269
|
[ Opcodes.i32_add ],
|
@@ -2284,7 +2284,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2284
2284
|
...brTable([
|
2285
2285
|
// get argc of func we are calling
|
2286
2286
|
[ Opcodes.local_get, funcLocal ],
|
2287
|
-
...number(
|
2287
|
+
...number(128, Valtype.i32),
|
2288
2288
|
[ Opcodes.i32_mul ],
|
2289
2289
|
[ Opcodes.i32_load16_u, 0, ...unsignedLEB128(allocPage(scope, 'func lut') * pageSize), 'read func lut' ]
|
2290
2290
|
], tableBc, valtypeBinary)
|
@@ -2296,7 +2296,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2296
2296
|
|
2297
2297
|
const func = funcs[idx - importedFuncs.length]; // idx === scope.index ? scope : funcs.find(x => x.index === idx);
|
2298
2298
|
const userFunc = func && !func.internal;
|
2299
|
-
const typedParams = userFunc ||
|
2299
|
+
const typedParams = userFunc || func?.typedParams;
|
2300
2300
|
const typedReturns = (userFunc && func.returnType == null) || builtinFuncs[name]?.typedReturns;
|
2301
2301
|
let paramCount = func && (typedParams ? Math.floor(func.params.length / 2) : func.params.length);
|
2302
2302
|
|
@@ -2791,9 +2791,11 @@ const generateVar = (scope, decl) => {
|
|
2791
2791
|
|
2792
2792
|
if (x.init && isFuncType(x.init.type)) {
|
2793
2793
|
// hack for let a = function () { ... }
|
2794
|
-
x.init.id
|
2795
|
-
|
2796
|
-
|
2794
|
+
if (!x.init.id) {
|
2795
|
+
x.init.id = { name };
|
2796
|
+
generateFunc(scope, x.init);
|
2797
|
+
continue;
|
2798
|
+
}
|
2797
2799
|
}
|
2798
2800
|
|
2799
2801
|
if (topLevel && Object.hasOwn(builtinVars, name)) {
|
@@ -2919,7 +2921,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2919
2921
|
[ Opcodes.local_set, localTmp(scope, '#member_prop_assign') ],
|
2920
2922
|
|
2921
2923
|
// todo: review last type usage here
|
2922
|
-
...typeSwitch(scope, getNodeType(scope,
|
2924
|
+
...typeSwitch(scope, getNodeType(scope, object), {
|
2923
2925
|
[TYPES.array]: [
|
2924
2926
|
...objectWasm,
|
2925
2927
|
Opcodes.i32_to_u,
|
@@ -3140,7 +3142,16 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3140
3142
|
]
|
3141
3143
|
}),
|
3142
3144
|
|
3143
|
-
default: internalThrow(scope, 'TypeError', `Cannot assign member with
|
3145
|
+
// default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
|
3146
|
+
default: [
|
3147
|
+
...objectWasm,
|
3148
|
+
[ Opcodes.drop ],
|
3149
|
+
|
3150
|
+
...propertyWasm,
|
3151
|
+
[ Opcodes.drop ],
|
3152
|
+
|
3153
|
+
...generate(scope, decl.right)
|
3154
|
+
]
|
3144
3155
|
}, valtypeBinary)
|
3145
3156
|
];
|
3146
3157
|
}
|
@@ -3534,18 +3545,6 @@ const generateForOf = (scope, decl) => {
|
|
3534
3545
|
const [ local, isGlobal ] = lookupName(scope, leftName);
|
3535
3546
|
if (!local) return todo(scope, 'for of failed to get left local (probably destructure)');
|
3536
3547
|
|
3537
|
-
// // todo: we should only do this for strings but we don't know at compile-time :(
|
3538
|
-
// hack: this is naughty and will break things!
|
3539
|
-
let newOut = number(0, Valtype.i32), newPointer = number(0, Valtype.i32);
|
3540
|
-
|
3541
|
-
const known = knownType(scope, getNodeType(scope, decl.right));
|
3542
|
-
if ((known === TYPES.string || known === TYPES.bytestring) || (pages.hasAnyString && known == null)) {
|
3543
|
-
// todo: we use i16 even for bytestrings which should not make a bad thing happen, just be confusing for debugging?
|
3544
|
-
0, [ newOut, newPointer ] = makeArray(scope, {
|
3545
|
-
rawElements: new Array(0)
|
3546
|
-
}, isGlobal, leftName, true, 'i16', true);
|
3547
|
-
}
|
3548
|
-
|
3549
3548
|
// set type for local
|
3550
3549
|
// todo: optimize away counter and use end pointer
|
3551
3550
|
out.push(...typeSwitch(scope, getNodeType(scope, decl.right), {
|
@@ -3591,8 +3590,9 @@ const generateForOf = (scope, decl) => {
|
|
3591
3590
|
[TYPES.string]: [
|
3592
3591
|
...setType(scope, leftName, TYPES.string),
|
3593
3592
|
|
3594
|
-
//
|
3595
|
-
...
|
3593
|
+
// allocate out string
|
3594
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
|
3595
|
+
[ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3596
3596
|
|
3597
3597
|
// set length to 1
|
3598
3598
|
...number(1, Valtype.i32),
|
@@ -3601,7 +3601,7 @@ const generateForOf = (scope, decl) => {
|
|
3601
3601
|
[ Opcodes.loop, Blocktype.void ],
|
3602
3602
|
|
3603
3603
|
// use as pointer for store later
|
3604
|
-
|
3604
|
+
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3605
3605
|
|
3606
3606
|
// load current string ind {arg}
|
3607
3607
|
[ Opcodes.local_get, pointer ],
|
@@ -3611,7 +3611,7 @@ const generateForOf = (scope, decl) => {
|
|
3611
3611
|
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
3612
3612
|
|
3613
3613
|
// return new string (page)
|
3614
|
-
|
3614
|
+
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3615
3615
|
Opcodes.i32_from_u,
|
3616
3616
|
|
3617
3617
|
[ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
|
@@ -3644,8 +3644,9 @@ const generateForOf = (scope, decl) => {
|
|
3644
3644
|
[TYPES.bytestring]: [
|
3645
3645
|
...setType(scope, leftName, TYPES.bytestring),
|
3646
3646
|
|
3647
|
-
//
|
3648
|
-
...
|
3647
|
+
// allocate out string
|
3648
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
|
3649
|
+
[ Opcodes.local_tee, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3649
3650
|
|
3650
3651
|
// set length to 1
|
3651
3652
|
...number(1, Valtype.i32),
|
@@ -3654,7 +3655,7 @@ const generateForOf = (scope, decl) => {
|
|
3654
3655
|
[ Opcodes.loop, Blocktype.void ],
|
3655
3656
|
|
3656
3657
|
// use as pointer for store later
|
3657
|
-
|
3658
|
+
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3658
3659
|
|
3659
3660
|
// load current string ind {arg}
|
3660
3661
|
[ Opcodes.local_get, pointer ],
|
@@ -3666,7 +3667,7 @@ const generateForOf = (scope, decl) => {
|
|
3666
3667
|
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
3667
3668
|
|
3668
3669
|
// return new string (page)
|
3669
|
-
|
3670
|
+
[ Opcodes.local_get, localTmp(scope, '#forof_allocd', Valtype.i32) ],
|
3670
3671
|
Opcodes.i32_from_u,
|
3671
3672
|
|
3672
3673
|
[ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
|
@@ -4261,11 +4262,9 @@ const StoreOps = {
|
|
4261
4262
|
let data = [];
|
4262
4263
|
|
4263
4264
|
const compileBytes = (val, itemType) => {
|
4264
|
-
// todo: this is a mess and needs confirming / ????
|
4265
4265
|
switch (itemType) {
|
4266
4266
|
case 'i8': return [ val % 256 ];
|
4267
4267
|
case 'i16': return [ val % 256, (val / 256 | 0) % 256 ];
|
4268
|
-
case 'i16': return [ val % 256, (val / 256 | 0) % 256 ];
|
4269
4268
|
case 'i32': return [...new Uint8Array(new Int32Array([ val ]).buffer)];
|
4270
4269
|
// todo: i64
|
4271
4270
|
|
@@ -4624,17 +4623,13 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4624
4623
|
const name = decl.object.name;
|
4625
4624
|
|
4626
4625
|
// hack: .name
|
4627
|
-
if (decl.property.name === 'name') {
|
4628
|
-
|
4629
|
-
let nameProp = name;
|
4626
|
+
if (decl.property.name === 'name' && hasFuncWithName(name)) {
|
4627
|
+
let nameProp = name;
|
4630
4628
|
|
4631
|
-
|
4632
|
-
|
4629
|
+
// eg: __String_prototype_toLowerCase -> toLowerCase
|
4630
|
+
if (nameProp.startsWith('__')) nameProp = nameProp.split('_').pop();
|
4633
4631
|
|
4634
|
-
|
4635
|
-
} else {
|
4636
|
-
return withType(scope, number(0), TYPES.undefined);
|
4637
|
-
}
|
4632
|
+
return withType(scope, makeString(scope, nameProp, _global, _name, true), TYPES.bytestring);
|
4638
4633
|
}
|
4639
4634
|
|
4640
4635
|
// hack: .length
|
@@ -4643,7 +4638,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4643
4638
|
|
4644
4639
|
const func = funcs.find(x => x.name === name);
|
4645
4640
|
if (func) {
|
4646
|
-
const typedParams = !func.internal ||
|
4641
|
+
const typedParams = !func.internal || func.typedParams;
|
4647
4642
|
return withType(scope, number(typedParams ? Math.floor(func.params.length / 2) : (func.constr ? (func.params.length - 1) : func.params.length)), TYPES.number);
|
4648
4643
|
}
|
4649
4644
|
|
@@ -4668,7 +4663,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4668
4663
|
|
4669
4664
|
const type = getNodeType(scope, decl.object);
|
4670
4665
|
const known = knownType(scope, type);
|
4671
|
-
if (known != null) {
|
4666
|
+
if (known != null && known != TYPES.function) {
|
4672
4667
|
if (typeHasFlag(known, TYPE_FLAGS.length)) return [
|
4673
4668
|
...out,
|
4674
4669
|
|
@@ -4679,28 +4674,32 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4679
4674
|
return number(0);
|
4680
4675
|
}
|
4681
4676
|
|
4682
|
-
const
|
4683
|
-
const tmp = useTmp && localTmp(scope, '#length_tmp', Valtype.i32);
|
4677
|
+
const tmp = localTmp(scope, '#length_tmp', Valtype.i32);
|
4684
4678
|
return [
|
4685
|
-
...
|
4686
|
-
|
4687
|
-
[ Opcodes.local_set, tmp ],
|
4688
|
-
] : []),
|
4679
|
+
...out,
|
4680
|
+
[ Opcodes.local_set, tmp ],
|
4689
4681
|
|
4690
4682
|
...getNodeType(scope, decl.object),
|
4691
4683
|
...number(TYPE_FLAGS.length, Valtype.i32),
|
4692
4684
|
[ Opcodes.i32_and ],
|
4693
4685
|
[ Opcodes.if, valtypeBinary ],
|
4694
|
-
|
4686
|
+
[ Opcodes.local_get, tmp ],
|
4695
4687
|
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
4696
4688
|
Opcodes.i32_from_u,
|
4697
4689
|
|
4698
4690
|
...setLastType(scope, TYPES.number),
|
4699
4691
|
[ Opcodes.else ],
|
4700
|
-
...(
|
4701
|
-
|
4702
|
-
|
4703
|
-
]
|
4692
|
+
...getNodeType(scope, decl.object),
|
4693
|
+
...number(TYPES.function, Valtype.i32),
|
4694
|
+
[ Opcodes.i32_eq ],
|
4695
|
+
[ Opcodes.if, Blocktype.void ],
|
4696
|
+
[ Opcodes.local_get, tmp ],
|
4697
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_funcLut_length').index) ],
|
4698
|
+
Opcodes.i32_from_u,
|
4699
|
+
|
4700
|
+
...setLastType(scope, TYPES.number),
|
4701
|
+
[ Opcodes.br, 1 ],
|
4702
|
+
[ Opcodes.end ],
|
4704
4703
|
|
4705
4704
|
...number(0),
|
4706
4705
|
...setLastType(scope, TYPES.undefined),
|
@@ -4739,22 +4738,13 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4739
4738
|
const object = decl.object;
|
4740
4739
|
const property = getMemberProperty(decl);
|
4741
4740
|
|
4741
|
+
// generate now (it gets cached)
|
4742
|
+
generate(scope, object);
|
4743
|
+
|
4742
4744
|
// todo/perf: use i32 object (and prop?) locals
|
4743
4745
|
const objectWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_obj') ] ];
|
4744
4746
|
const propertyWasm = [ [ Opcodes.local_get, localTmp(scope, '#member_prop') ] ];
|
4745
4747
|
|
4746
|
-
// // todo: we should only do this for strings but we don't know at compile-time :(
|
4747
|
-
// hack: this is naughty and will break things!
|
4748
|
-
let newOut = number(0, Valtype.i32), newPointer = number(0, Valtype.i32);
|
4749
|
-
|
4750
|
-
const known = knownType(scope, getNodeType(scope, object));
|
4751
|
-
if ((known === TYPES.string || known === TYPES.bytestring) || (pages.hasAnyString && known == null)) {
|
4752
|
-
// todo: we use i16 even for bytestrings which should not make a bad thing happen, just be confusing for debugging?
|
4753
|
-
0, [ newOut, newPointer ] = makeArray(scope, {
|
4754
|
-
rawElements: new Array(0)
|
4755
|
-
}, _global, _name, true, 'i16', true);
|
4756
|
-
}
|
4757
|
-
|
4758
4748
|
const out = typeSwitch(scope, getNodeType(scope, object), {
|
4759
4749
|
[TYPES.array]: [
|
4760
4750
|
...loadArray(scope, objectWasm, propertyWasm),
|
@@ -4762,15 +4752,16 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4762
4752
|
],
|
4763
4753
|
|
4764
4754
|
[TYPES.string]: [
|
4765
|
-
//
|
4766
|
-
...
|
4755
|
+
// allocate out string
|
4756
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
|
4757
|
+
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4767
4758
|
|
4768
4759
|
// set length to 1
|
4769
4760
|
...number(1, Valtype.i32),
|
4770
4761
|
[ Opcodes.i32_store, 0, 0 ],
|
4771
4762
|
|
4772
4763
|
// use as pointer for store later
|
4773
|
-
|
4764
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4774
4765
|
|
4775
4766
|
...propertyWasm,
|
4776
4767
|
Opcodes.i32_to_u,
|
@@ -4789,21 +4780,22 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4789
4780
|
[ Opcodes.i32_store16, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
|
4790
4781
|
|
4791
4782
|
// return new string (page)
|
4792
|
-
|
4783
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4793
4784
|
Opcodes.i32_from_u,
|
4794
4785
|
...setLastType(scope, TYPES.string)
|
4795
4786
|
],
|
4796
4787
|
|
4797
4788
|
[TYPES.bytestring]: [
|
4798
|
-
//
|
4799
|
-
...
|
4789
|
+
// allocate out string
|
4790
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_allocate').index) ],
|
4791
|
+
[ Opcodes.local_tee, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4800
4792
|
|
4801
4793
|
// set length to 1
|
4802
4794
|
...number(1, Valtype.i32),
|
4803
4795
|
[ Opcodes.i32_store, 0, 0 ],
|
4804
4796
|
|
4805
4797
|
// use as pointer for store later
|
4806
|
-
|
4798
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4807
4799
|
|
4808
4800
|
...propertyWasm,
|
4809
4801
|
Opcodes.i32_to_u,
|
@@ -4819,7 +4811,7 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4819
4811
|
[ Opcodes.i32_store8, 0, ValtypeSize.i32 ],
|
4820
4812
|
|
4821
4813
|
// return new string (page)
|
4822
|
-
|
4814
|
+
[ Opcodes.local_get, localTmp(scope, '#member_allocd', Valtype.i32) ],
|
4823
4815
|
Opcodes.i32_from_u,
|
4824
4816
|
...setLastType(scope, TYPES.bytestring)
|
4825
4817
|
],
|
@@ -4837,6 +4829,19 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4837
4829
|
...setLastType(scope)
|
4838
4830
|
],
|
4839
4831
|
|
4832
|
+
[TYPES.function]: [
|
4833
|
+
...objectWasm,
|
4834
|
+
Opcodes.i32_to_u,
|
4835
|
+
...getNodeType(scope, object),
|
4836
|
+
|
4837
|
+
...propertyWasm,
|
4838
|
+
...getNodeType(scope, property),
|
4839
|
+
...toPropertyKey(scope, true),
|
4840
|
+
|
4841
|
+
[ Opcodes.call, ...unsignedLEB128(includeBuiltin(scope, '__Porffor_object_get').index) ],
|
4842
|
+
...setLastType(scope)
|
4843
|
+
],
|
4844
|
+
|
4840
4845
|
...wrapBC({
|
4841
4846
|
[TYPES.uint8array]: [
|
4842
4847
|
[ Opcodes.i32_add ],
|
@@ -4915,7 +4920,11 @@ const generateMember = (scope, decl, _global, _name) => {
|
|
4915
4920
|
postlude: setLastType(scope, TYPES.number)
|
4916
4921
|
}),
|
4917
4922
|
|
4918
|
-
default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
|
4923
|
+
// default: internalThrow(scope, 'TypeError', 'Unsupported member expression object', true)
|
4924
|
+
default: [
|
4925
|
+
...number(0),
|
4926
|
+
...setLastType(scope, TYPES.undefined)
|
4927
|
+
]
|
4919
4928
|
});
|
4920
4929
|
|
4921
4930
|
if (decl.optional) {
|
@@ -5291,7 +5300,7 @@ export default program => {
|
|
5291
5300
|
Opcodes.lt = [ Opcodes.i32_lt_s, Opcodes.i64_lt_s, Opcodes.f64_lt ][valtypeInd];
|
5292
5301
|
|
5293
5302
|
builtinFuncs = new BuiltinFuncs();
|
5294
|
-
builtinVars = new BuiltinVars();
|
5303
|
+
builtinVars = new BuiltinVars({ builtinFuncs });
|
5295
5304
|
prototypeFuncs = new PrototypeFuncs();
|
5296
5305
|
allocator = makeAllocator(Prefs.allocator ?? 'static');
|
5297
5306
|
|
package/compiler/havoc.js
CHANGED
@@ -90,29 +90,4 @@ export const f64ToI32s = (func, targets) => {
|
|
90
90
|
}
|
91
91
|
}
|
92
92
|
}
|
93
|
-
};
|
94
|
-
|
95
|
-
export const withLocalDomains = (func, targets, domains) => {
|
96
|
-
const { wasm } = func;
|
97
|
-
|
98
|
-
// update wasm
|
99
|
-
for (let i = 0; i < wasm.length; i++) {
|
100
|
-
const op = wasm[i];
|
101
|
-
const opcode = op[0];
|
102
|
-
const idx = op[1];
|
103
|
-
|
104
|
-
let target;
|
105
|
-
if ((opcode === Opcodes.local_get || opcode === Opcodes.local_tee) &&
|
106
|
-
(target = targets.indexOf(idx)) !== -1) {
|
107
|
-
const n1 = wasm[i + 1];
|
108
|
-
if (n1?.[0] !== Opcodes.i32_const && n1?.[0] !== Opcodes.f64_const) continue;
|
109
|
-
|
110
|
-
const n2 = wasm[i + 2];
|
111
|
-
if (!n2?.[0]) continue;
|
112
|
-
|
113
|
-
switch (n2[0]) {
|
114
|
-
|
115
|
-
}
|
116
|
-
}
|
117
|
-
}
|
118
93
|
};
|
package/compiler/precompile.js
CHANGED
@@ -212,4 +212,4 @@ ${x.table ? ` table: 1,` : ''}${x.constr ? ` constr: 1,` : ''}${x.hasRestA
|
|
212
212
|
};`;
|
213
213
|
};
|
214
214
|
|
215
|
-
fs.writeFileSync(join(__dirname, '
|
215
|
+
fs.writeFileSync(join(__dirname, 'builtins_precompiled.js'), await precompile());
|
package/package.json
CHANGED