porffor 0.24.0 → 0.24.2
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/2c.js +6 -0
- package/compiler/allocators.js +6 -2
- package/compiler/assemble.js +38 -33
- package/compiler/builtins_objects.js +39 -11
- package/compiler/builtins_precompiled.js +23 -23
- package/compiler/codegen.js +29 -5
- package/compiler/index.js +10 -5
- package/compiler/precompile.js +1 -1
- package/compiler/prefs.js +1 -1
- package/compiler/wrap.js +5 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/2c.js
CHANGED
@@ -675,6 +675,12 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
|
|
675
675
|
|
676
676
|
break;
|
677
677
|
|
678
|
+
case Opcodes.call_indirect:
|
679
|
+
// stub, todo
|
680
|
+
vals.pop();
|
681
|
+
vals.push('0', '0');
|
682
|
+
break;
|
683
|
+
|
678
684
|
case Opcodes.drop:
|
679
685
|
// line(vals.pop());
|
680
686
|
vals.pop();
|
package/compiler/allocators.js
CHANGED
@@ -39,7 +39,10 @@ export class StaticAllocator {
|
|
39
39
|
if (globalThis.precompile && scopeName === 'main') scopeName = globalThis.precompile;
|
40
40
|
const reason = `${this.allocType(itemType)}: ${Prefs.scopedPageNames ? (scopeName + '/') : ''}${name}`;
|
41
41
|
|
42
|
-
if (pages.has(reason))
|
42
|
+
if (pages.has(reason)) {
|
43
|
+
const ptr = this.lastPtr = this.ptr(pages.get(reason).ind);
|
44
|
+
return number(ptr, Valtype.i32);
|
45
|
+
}
|
43
46
|
|
44
47
|
if (reason.startsWith('array:')) pages.hasArray = true;
|
45
48
|
if (reason.startsWith('string:')) pages.hasString = true;
|
@@ -52,7 +55,8 @@ export class StaticAllocator {
|
|
52
55
|
scope.pages ??= new Map();
|
53
56
|
scope.pages.set(reason, { ind, type: itemType });
|
54
57
|
|
55
|
-
|
58
|
+
const ptr = this.lastPtr = this.ptr(ind);
|
59
|
+
return number(ptr, Valtype.i32);
|
56
60
|
}
|
57
61
|
}
|
58
62
|
|
package/compiler/assemble.js
CHANGED
@@ -72,8 +72,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
72
72
|
return typeCache[hash] = idx;
|
73
73
|
};
|
74
74
|
|
75
|
-
let importFuncs = [];
|
76
|
-
|
75
|
+
let importFuncs = [], importDelta = 0;
|
77
76
|
if (optLevel < 1 || !Prefs.treeshakeWasmImports || noTreeshake) {
|
78
77
|
importFuncs = importedFuncs;
|
79
78
|
} else {
|
@@ -92,45 +91,45 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
92
91
|
}
|
93
92
|
}
|
94
93
|
|
95
|
-
importFuncs = [...imports.values()];
|
94
|
+
importFuncs = globalThis.importFuncs = [...imports.values()];
|
95
|
+
importDelta = importedFuncs.length - importFuncs.length;
|
96
|
+
}
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
f.index -= delta;
|
98
|
+
// fix call indexes for non-imports
|
99
|
+
// also fix call_indirect types
|
100
|
+
for (const f of funcs) {
|
101
|
+
f.originalIndex = f.index;
|
102
|
+
f.index -= importDelta;
|
103
103
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
if (inst[0] === Opcodes.call_indirect) {
|
110
|
-
if (!funcs.table) funcs.table = true;
|
104
|
+
for (const inst of f.wasm) {
|
105
|
+
if ((inst[0] === Opcodes.call || inst[0] === Opcodes.return_call) && inst[1] >= importedFuncs.length) {
|
106
|
+
inst[1] -= importDelta;
|
107
|
+
}
|
111
108
|
|
112
|
-
|
113
|
-
|
114
|
-
params.push(valtypeBinary, Valtype.i32);
|
115
|
-
}
|
109
|
+
if (inst[0] === Opcodes.call_indirect) {
|
110
|
+
if (!funcs.table) funcs.table = true;
|
116
111
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
112
|
+
const params = [];
|
113
|
+
for (let i = 0; i < inst[1]; i++) {
|
114
|
+
params.push(valtypeBinary, Valtype.i32);
|
115
|
+
}
|
121
116
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
}
|
117
|
+
if (inst.at(-1) === 'constr') {
|
118
|
+
inst.pop();
|
119
|
+
params.unshift(Valtype.i32);
|
120
|
+
}
|
127
121
|
|
128
|
-
|
122
|
+
let returns = [ valtypeBinary, Valtype.i32 ];
|
123
|
+
if (inst.at(-1) === 'no_type_return') {
|
124
|
+
inst.pop();
|
125
|
+
returns = [ valtypeBinary ];
|
129
126
|
}
|
127
|
+
|
128
|
+
inst[1] = getType(params, returns);
|
130
129
|
}
|
131
130
|
}
|
132
131
|
}
|
133
|
-
|
132
|
+
|
134
133
|
|
135
134
|
if (Prefs.optLog) log('assemble', `treeshake: using ${importFuncs.length}/${importedFuncs.length} imports`);
|
136
135
|
|
@@ -160,7 +159,13 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
160
159
|
] ])
|
161
160
|
);
|
162
161
|
|
163
|
-
if (pages.has('func lut')
|
162
|
+
if (pages.has('func lut')) {
|
163
|
+
const offset = pages.get('func lut').ind * pageSize;
|
164
|
+
if (data.addedFuncArgcLut) {
|
165
|
+
// remove existing data
|
166
|
+
data = data.filter(x => x.offset !== offset);
|
167
|
+
}
|
168
|
+
|
164
169
|
// generate func lut data
|
165
170
|
const bytes = [];
|
166
171
|
for (let i = 0; i < funcs.length; i++) {
|
@@ -192,7 +197,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
192
197
|
}
|
193
198
|
|
194
199
|
data.push({
|
195
|
-
offset
|
200
|
+
offset,
|
196
201
|
bytes
|
197
202
|
});
|
198
203
|
data.addedFuncArgcLut = true;
|
@@ -104,7 +104,12 @@ export default function({ builtinFuncs }, Prefs) {
|
|
104
104
|
};
|
105
105
|
|
106
106
|
const builtinFuncKeys = Object.keys(builtinFuncs);
|
107
|
-
const
|
107
|
+
const autoFuncKeys = name => builtinFuncKeys.filter(x => x.startsWith('__' + name + '_')).map(x => x.slice(name.length + 3));
|
108
|
+
const autoFuncs = name => props({
|
109
|
+
writable: true,
|
110
|
+
enumerable: false,
|
111
|
+
configurable: true
|
112
|
+
}, autoFuncKeys(name));
|
108
113
|
|
109
114
|
object('Math', {
|
110
115
|
...props({
|
@@ -126,13 +131,22 @@ export default function({ builtinFuncs }, Prefs) {
|
|
126
131
|
DEG_PER_RAD: 180 / Math.PI
|
127
132
|
}),
|
128
133
|
|
129
|
-
...
|
130
|
-
writable: true,
|
131
|
-
enumerable: false,
|
132
|
-
configurable: true
|
133
|
-
}, autoFuncs('Math'))
|
134
|
+
...autoFuncs('Math')
|
134
135
|
});
|
135
136
|
|
137
|
+
object('Reflect', autoFuncs('Reflect'));
|
138
|
+
|
139
|
+
// automatically generate objects for prototypes
|
140
|
+
for (const x of builtinFuncKeys.reduce((acc, x) => {
|
141
|
+
const ind = x.indexOf('_prototype_');
|
142
|
+
if (ind === -1) return acc;
|
143
|
+
|
144
|
+
acc.add(x.slice(0, ind + 10));
|
145
|
+
return acc;
|
146
|
+
}, new Set())) {
|
147
|
+
object(x, autoFuncs(x));
|
148
|
+
}
|
149
|
+
|
136
150
|
|
137
151
|
// todo: support when existing func
|
138
152
|
// object('Number', {
|
@@ -150,7 +164,7 @@ export default function({ builtinFuncs }, Prefs) {
|
|
150
164
|
// });
|
151
165
|
|
152
166
|
|
153
|
-
// technically not spec compliant as it should be
|
167
|
+
// these technically not spec compliant as it should be classes or non-enumerable but eh
|
154
168
|
object('navigator', {
|
155
169
|
...props({
|
156
170
|
writable: false,
|
@@ -161,20 +175,34 @@ export default function({ builtinFuncs }, Prefs) {
|
|
161
175
|
})
|
162
176
|
});
|
163
177
|
|
178
|
+
for (const x of [
|
179
|
+
'console',
|
180
|
+
'crypto',
|
181
|
+
'performance',
|
182
|
+
]) {
|
183
|
+
object(x, {
|
184
|
+
...props({
|
185
|
+
writable: true,
|
186
|
+
enumerable: true,
|
187
|
+
configurable: true
|
188
|
+
}, autoFuncKeys(x).slice(0, 12))
|
189
|
+
});
|
190
|
+
}
|
191
|
+
|
164
192
|
if (Prefs.logMissingObjects) for (const x of Object.keys(builtinFuncs).concat(Object.keys(this))) {
|
165
193
|
if (!x.startsWith('__')) continue;
|
166
194
|
|
167
|
-
const name = x.split('_').slice(2, -1).join('_')
|
195
|
+
const name = x.split('_').slice(2, -1).join('_');
|
168
196
|
|
169
197
|
let t = globalThis;
|
170
|
-
for (const x of name.split('
|
198
|
+
for (const x of name.split('_')) {
|
171
199
|
t = t[x];
|
172
200
|
if (!t) break;
|
173
201
|
}
|
174
202
|
if (!t) continue;
|
175
203
|
|
176
|
-
if (!done.has(name)) {
|
177
|
-
console.log(name);
|
204
|
+
if (!done.has(name) && !done.has('__' + name)) {
|
205
|
+
console.log(name.replaceAll('_', '.'), !!builtinFuncs[name]);
|
178
206
|
done.add(name);
|
179
207
|
}
|
180
208
|
}
|