porffor 0.19.9 → 0.19.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/builtins/symbol.ts +10 -0
- package/compiler/codegen.js +50 -14
- package/compiler/generated_builtins.js +526 -519
- package/compiler/precompile.js +71 -36
- package/compiler/wrap.js +9 -5
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -62,4 +62,14 @@ export const __Symbol_prototype_toLocaleString = (_this: Symbol) => __Symbol_pro
|
|
62
62
|
|
63
63
|
export const __Symbol_prototype_valueOf = (_this: Symbol) => {
|
64
64
|
return _this;
|
65
|
+
};
|
66
|
+
|
67
|
+
const forStore = new Map();
|
68
|
+
export const __Symbol_for = (key: any): Symbol => {
|
69
|
+
if (forStore.has(key)) return forStore.get(key);
|
70
|
+
|
71
|
+
const out: Symbol = Symbol(key);
|
72
|
+
forStore.set(key, out);
|
73
|
+
|
74
|
+
return out;
|
65
75
|
};
|
package/compiler/codegen.js
CHANGED
@@ -297,7 +297,7 @@ const generateIdent = (scope, decl) => {
|
|
297
297
|
if (builtinVars[name].floatOnly && valtype[0] === 'i') throw new Error(`Cannot use ${unhackName(name)} with integer valtype`);
|
298
298
|
|
299
299
|
let wasm = builtinVars[name];
|
300
|
-
if (typeof wasm === 'function') wasm = asmFuncToAsm(
|
300
|
+
if (typeof wasm === 'function') wasm = asmFuncToAsm({ name }, wasm);
|
301
301
|
return wasm.slice();
|
302
302
|
}
|
303
303
|
|
@@ -1119,7 +1119,7 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
|
|
1119
1119
|
return out;
|
1120
1120
|
};
|
1121
1121
|
|
1122
|
-
const asmFuncToAsm = (
|
1122
|
+
const asmFuncToAsm = (scope, func) => {
|
1123
1123
|
return func(scope, {
|
1124
1124
|
TYPES, TYPE_NAMES, typeSwitch, makeArray, makeString, allocPage, internalThrow,
|
1125
1125
|
builtin: n => {
|
@@ -1131,6 +1131,39 @@ const asmFuncToAsm = (func, scope) => {
|
|
1131
1131
|
|
1132
1132
|
if (idx == null) throw new Error(`builtin('${n}') failed to find a func (inside ${scope.name})`);
|
1133
1133
|
return idx;
|
1134
|
+
},
|
1135
|
+
glbl: (opcode, name, type) => {
|
1136
|
+
if (!globals[name]) {
|
1137
|
+
const idx = globals['#ind']++;
|
1138
|
+
globals[name] = { idx, type };
|
1139
|
+
|
1140
|
+
const tmpIdx = globals['#ind']++;
|
1141
|
+
globals[name + '#glbl_inited'] = { idx: tmpIdx, type: Valtype.i32 };
|
1142
|
+
|
1143
|
+
if (scope.globalInits[name]) return [
|
1144
|
+
[ Opcodes.global_get, tmpIdx ],
|
1145
|
+
[ Opcodes.i32_eqz ],
|
1146
|
+
[ Opcodes.if, Blocktype.void ],
|
1147
|
+
...asmFuncToAsm(scope, scope.globalInits[name]),
|
1148
|
+
...number(1, Valtype.i32),
|
1149
|
+
[ Opcodes.global_set, tmpIdx ],
|
1150
|
+
[ Opcodes.end ],
|
1151
|
+
|
1152
|
+
[ opcode, globals[name].idx ]
|
1153
|
+
];
|
1154
|
+
}
|
1155
|
+
|
1156
|
+
return [
|
1157
|
+
[ opcode, globals[name].idx ]
|
1158
|
+
];
|
1159
|
+
},
|
1160
|
+
loc: (name, type) => {
|
1161
|
+
if (!scope.locals[name]) {
|
1162
|
+
const idx = scope.localInd++;
|
1163
|
+
scope.locals[name] = { idx, type };
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
return scope.locals[name].idx;
|
1134
1167
|
}
|
1135
1168
|
});
|
1136
1169
|
};
|
@@ -1165,7 +1198,8 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
|
|
1165
1198
|
internal: true,
|
1166
1199
|
index: currentFuncIndex++,
|
1167
1200
|
table,
|
1168
|
-
constr
|
1201
|
+
constr,
|
1202
|
+
globalInits
|
1169
1203
|
};
|
1170
1204
|
|
1171
1205
|
funcs.push(func);
|
@@ -1173,7 +1207,7 @@ const asmFunc = (name, { wasm, params, locals: localTypes, globals: globalTypes
|
|
1173
1207
|
|
1174
1208
|
if (typeof wasm === 'function') {
|
1175
1209
|
if (globalThis.precompile) wasm = [];
|
1176
|
-
else wasm = asmFuncToAsm(
|
1210
|
+
else wasm = asmFuncToAsm(func, wasm);
|
1177
1211
|
}
|
1178
1212
|
|
1179
1213
|
let baseGlobalIdx, i = 0;
|
@@ -2681,21 +2715,23 @@ const generateVar = (scope, decl) => {
|
|
2681
2715
|
if (x.init) {
|
2682
2716
|
const alreadyArray = scope.arrays?.get(name) != null;
|
2683
2717
|
|
2684
|
-
const
|
2718
|
+
const newOut = generate(scope, x.init, global, name);
|
2685
2719
|
if (!alreadyArray && scope.arrays?.get(name) != null) {
|
2686
2720
|
// hack to set local as pointer before
|
2687
|
-
|
2688
|
-
if (
|
2689
|
-
|
2690
|
-
generated.push([ Opcodes.drop ]);
|
2691
|
-
|
2692
|
-
out = out.concat(generated);
|
2721
|
+
newOut.unshift(...number(scope.arrays.get(name)), [ global ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
2722
|
+
if (newOut.at(-1) == Opcodes.i32_from_u) newOut.pop();
|
2723
|
+
newOut.push([ Opcodes.drop ]);
|
2693
2724
|
} else {
|
2694
|
-
|
2695
|
-
out.push([ global ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
2725
|
+
newOut.push([ global ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
2696
2726
|
}
|
2697
2727
|
|
2698
|
-
|
2728
|
+
newOut.push(...setType(scope, name, getNodeType(scope, x.init)));
|
2729
|
+
out = out.concat(newOut);
|
2730
|
+
|
2731
|
+
if (globalThis.precompile && global) {
|
2732
|
+
scope.globalInits ??= {};
|
2733
|
+
scope.globalInits[name] = newOut;
|
2734
|
+
}
|
2699
2735
|
}
|
2700
2736
|
|
2701
2737
|
// hack: this follows spec properly but is mostly unneeded 😅
|