porffor 0.2.0-371da1e → 0.2.0-3aaa9b4
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/CONTRIBUTING.md +183 -0
- package/README.md +71 -44
- package/asur/index.js +1 -1
- package/compiler/assemble.js +1 -1
- package/compiler/builtins/annexb_string.js +1 -1
- package/compiler/builtins/annexb_string.ts +1 -1
- package/compiler/builtins/array.ts +1 -1
- package/compiler/builtins/base64.ts +1 -1
- package/compiler/builtins/crypto.ts +1 -1
- package/compiler/builtins/date.ts +1850 -3
- package/compiler/builtins/escape.ts +1 -1
- package/compiler/builtins/int.ts +1 -1
- package/compiler/builtins/number.ts +1 -1
- package/compiler/builtins/porffor.d.ts +21 -4
- package/compiler/builtins/string.ts +1 -1
- package/compiler/builtins/tostring.ts +1 -1
- package/compiler/builtins.js +2 -5
- package/compiler/codegen.js +127 -53
- package/compiler/decompile.js +0 -1
- package/compiler/generated_builtins.js +801 -78
- package/compiler/parse.js +4 -2
- package/compiler/precompile.js +7 -2
- package/compiler/prefs.js +6 -5
- package/compiler/wasmSpec.js +1 -0
- package/compiler/wrap.js +7 -4
- package/package.json +1 -1
- package/rhemyn/compile.js +42 -25
- package/rhemyn/parse.js +4 -5
- package/runner/index.js +45 -4
- package/runner/repl.js +2 -2
- package/runner/sizes.js +1 -1
package/compiler/builtins/int.ts
CHANGED
@@ -7,23 +7,40 @@ type PorfforGlobal = {
|
|
7
7
|
wasm: {
|
8
8
|
(...args: any[]): any;
|
9
9
|
i32: {
|
10
|
-
or(a: i32, b: i32): i32;
|
11
|
-
|
12
10
|
load(pointer: i32, align: i32, offset: i32): i32;
|
13
11
|
store(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
14
12
|
load8_u(pointer: i32, align: i32, offset: i32): i32;
|
15
13
|
store8(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
16
14
|
load16_u(pointer: i32, align: i32, offset: i32): i32;
|
17
15
|
store16(pointer: i32, value: i32, align: i32, offset: i32): i32;
|
16
|
+
const(value: i32): i32;
|
17
|
+
}
|
18
|
+
|
19
|
+
f64: {
|
20
|
+
load(pointer: i32, align: i32, offset: i32): i32;
|
21
|
+
store(pointer: i32, value: f64, align: i32, offset: i32): f64;
|
18
22
|
}
|
19
23
|
}
|
20
24
|
|
21
|
-
// randomInt(): i32;
|
22
25
|
randomByte(): i32;
|
23
26
|
|
24
27
|
type(x: any): bytestring;
|
25
28
|
rawType(x: any): i32;
|
26
|
-
TYPES:
|
29
|
+
TYPES: {
|
30
|
+
number: i32;
|
31
|
+
boolean: i32;
|
32
|
+
string: i32;
|
33
|
+
undefined: i32;
|
34
|
+
object: i32;
|
35
|
+
function: i32;
|
36
|
+
symbol: i32;
|
37
|
+
bigint: i32;
|
38
|
+
|
39
|
+
_array: i32;
|
40
|
+
_regexp: i32;
|
41
|
+
_bytestring: i32;
|
42
|
+
_date: i32;
|
43
|
+
}
|
27
44
|
|
28
45
|
fastOr(...args: any): boolean;
|
29
46
|
fastAnd(...args: any): boolean;
|
package/compiler/builtins.js
CHANGED
@@ -216,7 +216,7 @@ export const BuiltinFuncs = function() {
|
|
216
216
|
};
|
217
217
|
|
218
218
|
|
219
|
-
this.
|
219
|
+
this.__Porffor_print = {
|
220
220
|
params: [ valtypeBinary, Valtype.i32 ],
|
221
221
|
typedParams: true,
|
222
222
|
locals: [ Valtype.i32, Valtype.i32 ],
|
@@ -368,10 +368,7 @@ export const BuiltinFuncs = function() {
|
|
368
368
|
[ Opcodes.local_get, 0 ],
|
369
369
|
[ Opcodes.call, importedFuncs.print ],
|
370
370
|
]
|
371
|
-
}, Blocktype.void)
|
372
|
-
|
373
|
-
...char('\n'),
|
374
|
-
[ Opcodes.call, importedFuncs.printChar ]
|
371
|
+
}, Blocktype.void)
|
375
372
|
]
|
376
373
|
};
|
377
374
|
|
package/compiler/codegen.js
CHANGED
@@ -201,7 +201,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
201
201
|
}
|
202
202
|
|
203
203
|
let inst = Opcodes[asm[0].replace('.', '_')];
|
204
|
-
if (
|
204
|
+
if (inst == null) throw new Error(`inline asm: inst ${asm[0]} not found`);
|
205
205
|
|
206
206
|
if (!Array.isArray(inst)) inst = [ inst ];
|
207
207
|
const immediates = asm.slice(1).map(x => {
|
@@ -210,7 +210,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
210
210
|
return int;
|
211
211
|
});
|
212
212
|
|
213
|
-
out.push([ ...inst, ...immediates ]);
|
213
|
+
out.push([ ...inst, ...immediates.flatMap(x => signedLEB128(x)) ]);
|
214
214
|
}
|
215
215
|
|
216
216
|
return out;
|
@@ -460,7 +460,7 @@ const concatStrings = (scope, left, right, global, name, assign = false, bytestr
|
|
460
460
|
const rightLength = localTmp(scope, 'concat_right_length', Valtype.i32);
|
461
461
|
const leftLength = localTmp(scope, 'concat_left_length', Valtype.i32);
|
462
462
|
|
463
|
-
if (assign) {
|
463
|
+
if (assign && Prefs.aotPointerOpt) {
|
464
464
|
const pointer = scope.arrays?.get(name ?? '$undeclared');
|
465
465
|
|
466
466
|
return [
|
@@ -1472,7 +1472,7 @@ const countLeftover = wasm => {
|
|
1472
1472
|
if (depth === 0)
|
1473
1473
|
if ([Opcodes.throw, Opcodes.drop, Opcodes.local_set, Opcodes.global_set].includes(inst[0])) count--;
|
1474
1474
|
else if ([null, Opcodes.i32_eqz, Opcodes.i64_eqz, Opcodes.f64_ceil, Opcodes.f64_floor, Opcodes.f64_trunc, Opcodes.f64_nearest, Opcodes.f64_sqrt, Opcodes.local_tee, Opcodes.i32_wrap_i64, Opcodes.i64_extend_i32_s, Opcodes.i64_extend_i32_u, Opcodes.f32_demote_f64, Opcodes.f64_promote_f32, Opcodes.f64_convert_i32_s, Opcodes.f64_convert_i32_u, Opcodes.i32_clz, Opcodes.i32_ctz, Opcodes.i32_popcnt, Opcodes.f64_neg, Opcodes.end, Opcodes.i32_trunc_sat_f64_s[0], Opcodes.i32x4_extract_lane, Opcodes.i16x8_extract_lane, Opcodes.i32_load, Opcodes.i64_load, Opcodes.f64_load, Opcodes.v128_load, Opcodes.i32_load16_u, Opcodes.i32_load16_s, Opcodes.i32_load8_u, Opcodes.i32_load8_s, Opcodes.memory_grow].includes(inst[0]) && (inst[0] !== 0xfc || inst[1] < 0x0a)) {}
|
1475
|
-
else if ([Opcodes.local_get, Opcodes.global_get, Opcodes.f64_const, Opcodes.i32_const, Opcodes.i64_const, Opcodes.v128_const].includes(inst[0])) count++;
|
1475
|
+
else if ([Opcodes.local_get, Opcodes.global_get, Opcodes.f64_const, Opcodes.i32_const, Opcodes.i64_const, Opcodes.v128_const, Opcodes.memory_size].includes(inst[0])) count++;
|
1476
1476
|
else if ([Opcodes.i32_store, Opcodes.i64_store, Opcodes.f64_store, Opcodes.i32_store16, Opcodes.i32_store8].includes(inst[0])) count -= 2;
|
1477
1477
|
else if (Opcodes.memory_copy[0] === inst[0] && Opcodes.memory_copy[1] === inst[1]) count -= 3;
|
1478
1478
|
else if (inst[0] === Opcodes.return) count = 0;
|
@@ -1646,18 +1646,25 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1646
1646
|
// megahack for /regex/.func()
|
1647
1647
|
const funcName = decl.callee.property.name;
|
1648
1648
|
if (decl.callee.object.regex && Object.hasOwn(Rhemyn, funcName)) {
|
1649
|
-
const
|
1649
|
+
const regex = decl.callee.object.regex.pattern;
|
1650
|
+
const rhemynName = `regex_${funcName}_${regex}`;
|
1650
1651
|
|
1651
|
-
funcIndex[
|
1652
|
-
|
1652
|
+
if (!funcIndex[rhemynName]) {
|
1653
|
+
const func = Rhemyn[funcName](regex, currentFuncIndex++, rhemynName);
|
1653
1654
|
|
1655
|
+
funcIndex[func.name] = func.index;
|
1656
|
+
funcs.push(func);
|
1657
|
+
}
|
1658
|
+
|
1659
|
+
const idx = funcIndex[rhemynName];
|
1654
1660
|
return [
|
1655
1661
|
// make string arg
|
1656
1662
|
...generate(scope, decl.arguments[0]),
|
1663
|
+
Opcodes.i32_to_u,
|
1664
|
+
...getNodeType(scope, decl.arguments[0]),
|
1657
1665
|
|
1658
1666
|
// call regex func
|
1659
|
-
Opcodes.
|
1660
|
-
[ Opcodes.call, func.index ],
|
1667
|
+
[ Opcodes.call, idx ],
|
1661
1668
|
Opcodes.i32_from_u,
|
1662
1669
|
|
1663
1670
|
...number(TYPES.boolean, Valtype.i32),
|
@@ -1697,6 +1704,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1697
1704
|
|
1698
1705
|
protoBC[type] = generateCall(scope, {
|
1699
1706
|
callee: {
|
1707
|
+
type: 'Identifier',
|
1700
1708
|
name: x
|
1701
1709
|
},
|
1702
1710
|
arguments: [ target, ...decl.arguments ],
|
@@ -1819,20 +1827,20 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1819
1827
|
idx = funcIndex[name];
|
1820
1828
|
|
1821
1829
|
// infer arguments types from builtins params
|
1822
|
-
const func = funcs.find(x => x.name === name);
|
1823
|
-
for (let i = 0; i < decl.arguments.length; i++) {
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
}
|
1830
|
+
// const func = funcs.find(x => x.name === name);
|
1831
|
+
// for (let i = 0; i < decl.arguments.length; i++) {
|
1832
|
+
// const arg = decl.arguments[i];
|
1833
|
+
// if (!arg.name) continue;
|
1834
|
+
|
1835
|
+
// const local = scope.locals[arg.name];
|
1836
|
+
// if (!local) continue;
|
1837
|
+
|
1838
|
+
// local.type = func.params[i];
|
1839
|
+
// if (local.type === Valtype.v128) {
|
1840
|
+
// // specify vec subtype inferred from last vec type in function name
|
1841
|
+
// local.vecType = name.split('_').reverse().find(x => x.includes('x'));
|
1842
|
+
// }
|
1843
|
+
// }
|
1836
1844
|
}
|
1837
1845
|
|
1838
1846
|
if (idx === undefined && internalConstrs[name]) return internalConstrs[name].generate(scope, decl, _global, _name);
|
@@ -1845,28 +1853,25 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1845
1853
|
if (idx === undefined && name.startsWith('__Porffor_wasm_')) {
|
1846
1854
|
const wasmOps = {
|
1847
1855
|
// pointer, align, offset
|
1848
|
-
i32_load: { imms: 2, args:
|
1856
|
+
i32_load: { imms: 2, args: [ true ], returns: 1 },
|
1849
1857
|
// pointer, value, align, offset
|
1850
|
-
i32_store: { imms: 2, args:
|
1858
|
+
i32_store: { imms: 2, args: [ true, true ], returns: 0 },
|
1851
1859
|
// pointer, align, offset
|
1852
|
-
i32_load8_u: { imms: 2, args:
|
1860
|
+
i32_load8_u: { imms: 2, args: [ true ], returns: 1 },
|
1853
1861
|
// pointer, value, align, offset
|
1854
|
-
i32_store8: { imms: 2, args:
|
1862
|
+
i32_store8: { imms: 2, args: [ true, true ], returns: 0 },
|
1855
1863
|
// pointer, align, offset
|
1856
|
-
i32_load16_u: { imms: 2, args:
|
1864
|
+
i32_load16_u: { imms: 2, args: [ true ], returns: 1 },
|
1857
1865
|
// pointer, value, align, offset
|
1858
|
-
i32_store16: { imms: 2, args:
|
1866
|
+
i32_store16: { imms: 2, args: [ true, true ], returns: 0 },
|
1859
1867
|
|
1860
1868
|
// pointer, align, offset
|
1861
|
-
f64_load: { imms: 2, args:
|
1869
|
+
f64_load: { imms: 2, args: [ true ], returns: 0 }, // 0 due to not i32
|
1862
1870
|
// pointer, value, align, offset
|
1863
|
-
f64_store: { imms: 2, args:
|
1871
|
+
f64_store: { imms: 2, args: [ true, false ], returns: 0 },
|
1864
1872
|
|
1865
1873
|
// value
|
1866
|
-
i32_const: { imms: 1, args:
|
1867
|
-
|
1868
|
-
// a, b
|
1869
|
-
i32_or: { imms: 0, args: 2, returns: 1 },
|
1874
|
+
i32_const: { imms: 1, args: [], returns: 1 },
|
1870
1875
|
};
|
1871
1876
|
|
1872
1877
|
const opName = name.slice('__Porffor_wasm_'.length);
|
@@ -1875,13 +1880,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
1875
1880
|
const op = wasmOps[opName];
|
1876
1881
|
|
1877
1882
|
const argOut = [];
|
1878
|
-
for (let i = 0; i < op.args; i++) argOut.push(
|
1883
|
+
for (let i = 0; i < op.args.length; i++) argOut.push(
|
1879
1884
|
...generate(scope, decl.arguments[i]),
|
1880
|
-
Opcodes.i32_to
|
1885
|
+
...(op.args[i] ? [ Opcodes.i32_to ] : [])
|
1881
1886
|
);
|
1882
1887
|
|
1883
1888
|
// literals only
|
1884
|
-
const imms = decl.arguments.slice(op.args).map(x => x.value);
|
1889
|
+
const imms = decl.arguments.slice(op.args.length).map(x => x.value);
|
1885
1890
|
|
1886
1891
|
return [
|
1887
1892
|
...argOut,
|
@@ -2204,6 +2209,7 @@ const generateVar = (scope, decl) => {
|
|
2204
2209
|
|
2205
2210
|
// global variable if in top scope (main) and var ..., or if wanted
|
2206
2211
|
const global = topLevel || decl._bare; // decl.kind === 'var';
|
2212
|
+
const target = global ? globals : scope.locals;
|
2207
2213
|
|
2208
2214
|
for (const x of decl.declarations) {
|
2209
2215
|
const name = mapName(x.id.name);
|
@@ -2225,17 +2231,29 @@ const generateVar = (scope, decl) => {
|
|
2225
2231
|
continue; // always ignore
|
2226
2232
|
}
|
2227
2233
|
|
2234
|
+
// // generate init before allocating var
|
2235
|
+
// let generated;
|
2236
|
+
// if (x.init) generated = generate(scope, x.init, global, name);
|
2237
|
+
|
2228
2238
|
const typed = typedInput && x.id.typeAnnotation;
|
2229
|
-
let idx = allocVar(scope, name, global, !typed);
|
2239
|
+
let idx = allocVar(scope, name, global, !(typed && extractTypeAnnotation(x.id).type != null));
|
2230
2240
|
|
2231
2241
|
if (typed) {
|
2232
2242
|
addVarMetadata(scope, name, global, extractTypeAnnotation(x.id));
|
2233
2243
|
}
|
2234
2244
|
|
2235
2245
|
if (x.init) {
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2246
|
+
const generated = generate(scope, x.init, global, name);
|
2247
|
+
if (scope.arrays?.get(name) != null) {
|
2248
|
+
// hack to set local as pointer before
|
2249
|
+
out.push(...number(scope.arrays.get(name)), [ global ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
2250
|
+
if (generated.at(-1) == Opcodes.i32_from_u) generated.pop();
|
2251
|
+
generated.pop();
|
2252
|
+
out = out.concat(generated);
|
2253
|
+
} else {
|
2254
|
+
out = out.concat(generated);
|
2255
|
+
out.push([ global ? Opcodes.global_set : Opcodes.local_set, idx ]);
|
2256
|
+
}
|
2239
2257
|
out.push(...setType(scope, name, getNodeType(scope, x.init)));
|
2240
2258
|
}
|
2241
2259
|
|
@@ -2262,6 +2280,8 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2262
2280
|
return [];
|
2263
2281
|
}
|
2264
2282
|
|
2283
|
+
const op = decl.operator.slice(0, -1) || '=';
|
2284
|
+
|
2265
2285
|
// hack: .length setter
|
2266
2286
|
if (decl.left.type === 'MemberExpression' && decl.left.property.name === 'length') {
|
2267
2287
|
const name = decl.left.object.name;
|
@@ -2270,14 +2290,20 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2270
2290
|
const aotPointer = Prefs.aotPointerOpt && pointer != null;
|
2271
2291
|
|
2272
2292
|
const newValueTmp = localTmp(scope, '__length_setter_tmp');
|
2293
|
+
const pointerTmp = op === '=' ? null : localTmp(scope, '__member_setter_ptr_tmp', Valtype.i32);
|
2273
2294
|
|
2274
2295
|
return [
|
2275
2296
|
...(aotPointer ? number(0, Valtype.i32) : [
|
2276
2297
|
...generate(scope, decl.left.object),
|
2277
2298
|
Opcodes.i32_to_u
|
2278
2299
|
]),
|
2300
|
+
...(!pointerTmp ? [] : [ [ Opcodes.local_tee, pointerTmp ] ]),
|
2279
2301
|
|
2280
|
-
...generate(scope, decl.right),
|
2302
|
+
...(op === '=' ? generate(scope, decl.right) : performOp(scope, op, [
|
2303
|
+
[ Opcodes.local_get, pointerTmp ],
|
2304
|
+
[ Opcodes.i32_load, Math.log2(ValtypeSize.i32) - 1, 0 ],
|
2305
|
+
Opcodes.i32_from_u
|
2306
|
+
], generate(scope, decl.right), number(TYPES.number, Valtype.i32), getNodeType(scope, decl.right))),
|
2281
2307
|
[ Opcodes.local_tee, newValueTmp ],
|
2282
2308
|
|
2283
2309
|
Opcodes.i32_to_u,
|
@@ -2287,8 +2313,6 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
2287
2313
|
];
|
2288
2314
|
}
|
2289
2315
|
|
2290
|
-
const op = decl.operator.slice(0, -1) || '=';
|
2291
|
-
|
2292
2316
|
// arr[i]
|
2293
2317
|
if (decl.left.type === 'MemberExpression' && decl.left.computed) {
|
2294
2318
|
const name = decl.left.object.name;
|
@@ -3092,12 +3116,14 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3092
3116
|
// todo: can we just have 1 undeclared array? probably not? but this is not really memory efficient
|
3093
3117
|
const uniqueName = name === '$undeclared' ? name + Math.random().toString().slice(2) : name;
|
3094
3118
|
|
3095
|
-
if (Prefs.scopedPageNames) scope.arrays.set(name, allocPage(scope, `${
|
3119
|
+
if (Prefs.scopedPageNames) scope.arrays.set(name, allocPage(scope, `${getAllocType(itemType)}: ${scope.name}/${uniqueName}`, itemType) * pageSize);
|
3096
3120
|
else scope.arrays.set(name, allocPage(scope, `${getAllocType(itemType)}: ${uniqueName}`, itemType) * pageSize);
|
3097
3121
|
}
|
3098
3122
|
|
3099
3123
|
const pointer = scope.arrays.get(name);
|
3100
3124
|
|
3125
|
+
const local = global ? globals[name] : scope.locals[name];
|
3126
|
+
|
3101
3127
|
const useRawElements = !!decl.rawElements;
|
3102
3128
|
const elements = useRawElements ? decl.rawElements : decl.elements;
|
3103
3129
|
|
@@ -3130,11 +3156,22 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3130
3156
|
return [ out, pointer ];
|
3131
3157
|
}
|
3132
3158
|
|
3159
|
+
const pointerTmp = local != null ? localTmp(scope, '#makearray_pointer_tmp', Valtype.i32) : null;
|
3160
|
+
if (pointerTmp != null) {
|
3161
|
+
out.push(
|
3162
|
+
[ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
|
3163
|
+
Opcodes.i32_to_u,
|
3164
|
+
[ Opcodes.local_set, pointerTmp ]
|
3165
|
+
);
|
3166
|
+
}
|
3167
|
+
|
3168
|
+
const pointerWasm = pointerTmp != null ? [ [ Opcodes.local_get, pointerTmp ] ] : number(pointer, Valtype.i32);
|
3169
|
+
|
3133
3170
|
// store length as 0th array
|
3134
3171
|
out.push(
|
3135
|
-
...
|
3172
|
+
...pointerWasm,
|
3136
3173
|
...number(length, Valtype.i32),
|
3137
|
-
[ Opcodes.i32_store, Math.log2(ValtypeSize.i32) - 1,
|
3174
|
+
[ Opcodes.i32_store, Math.log2(ValtypeSize.i32) - 1, 0 ]
|
3138
3175
|
);
|
3139
3176
|
|
3140
3177
|
const storeOp = StoreOps[itemType];
|
@@ -3143,14 +3180,14 @@ const makeArray = (scope, decl, global = false, name = '$undeclared', initEmpty
|
|
3143
3180
|
if (elements[i] == null) continue;
|
3144
3181
|
|
3145
3182
|
out.push(
|
3146
|
-
...
|
3183
|
+
...pointerWasm,
|
3147
3184
|
...(useRawElements ? number(elements[i], Valtype[valtype]) : generate(scope, elements[i])),
|
3148
|
-
[ storeOp, (Math.log2(ValtypeSize[itemType]) || 1) - 1, ...unsignedLEB128(
|
3185
|
+
[ storeOp, (Math.log2(ValtypeSize[itemType]) || 1) - 1, ...unsignedLEB128(ValtypeSize.i32 + i * ValtypeSize[itemType]) ]
|
3149
3186
|
);
|
3150
3187
|
}
|
3151
3188
|
|
3152
3189
|
// local value as pointer
|
3153
|
-
out.push(...
|
3190
|
+
out.push(...pointerWasm, Opcodes.i32_from_u);
|
3154
3191
|
|
3155
3192
|
return [ out, pointer ];
|
3156
3193
|
};
|
@@ -3505,6 +3542,8 @@ const internalConstrs = {
|
|
3505
3542
|
);
|
3506
3543
|
}
|
3507
3544
|
|
3545
|
+
out.push(Opcodes.i32_from_u);
|
3546
|
+
|
3508
3547
|
return out;
|
3509
3548
|
},
|
3510
3549
|
type: TYPES.boolean,
|
@@ -3523,6 +3562,8 @@ const internalConstrs = {
|
|
3523
3562
|
);
|
3524
3563
|
}
|
3525
3564
|
|
3565
|
+
out.push(Opcodes.i32_from_u);
|
3566
|
+
|
3526
3567
|
return out;
|
3527
3568
|
},
|
3528
3569
|
type: TYPES.boolean,
|
@@ -3577,6 +3618,39 @@ const internalConstrs = {
|
|
3577
3618
|
type: TYPES.number,
|
3578
3619
|
notConstr: true,
|
3579
3620
|
length: 2
|
3621
|
+
},
|
3622
|
+
|
3623
|
+
__console_log: {
|
3624
|
+
generate: (scope, decl) => {
|
3625
|
+
const out = [];
|
3626
|
+
|
3627
|
+
for (let i = 0; i < decl.arguments.length; i++) {
|
3628
|
+
out.push(
|
3629
|
+
...generateCall(scope, {
|
3630
|
+
callee: {
|
3631
|
+
type: 'Identifier',
|
3632
|
+
name: '__Porffor_print'
|
3633
|
+
},
|
3634
|
+
arguments: [ decl.arguments[i] ]
|
3635
|
+
}),
|
3636
|
+
|
3637
|
+
// print space
|
3638
|
+
...number(32),
|
3639
|
+
[ Opcodes.call, importedFuncs.printChar ]
|
3640
|
+
);
|
3641
|
+
}
|
3642
|
+
|
3643
|
+
// print newline
|
3644
|
+
out.push(
|
3645
|
+
...number(10),
|
3646
|
+
[ Opcodes.call, importedFuncs.printChar ]
|
3647
|
+
);
|
3648
|
+
|
3649
|
+
return out;
|
3650
|
+
},
|
3651
|
+
type: TYPES.undefined,
|
3652
|
+
notConstr: true,
|
3653
|
+
length: 0
|
3580
3654
|
}
|
3581
3655
|
};
|
3582
3656
|
|
@@ -3611,7 +3685,7 @@ export default program => {
|
|
3611
3685
|
|
3612
3686
|
globalThis.valtype = 'f64';
|
3613
3687
|
|
3614
|
-
const valtypeOpt = process.argv.find(x => x.startsWith('
|
3688
|
+
const valtypeOpt = process.argv.find(x => x.startsWith('--valtype='));
|
3615
3689
|
if (valtypeOpt) valtype = valtypeOpt.split('=')[1];
|
3616
3690
|
|
3617
3691
|
globalThis.valtypeBinary = Valtype[valtype];
|
@@ -3619,7 +3693,7 @@ export default program => {
|
|
3619
3693
|
const valtypeInd = ['i32', 'i64', 'f64'].indexOf(valtype);
|
3620
3694
|
|
3621
3695
|
globalThis.pageSize = PageSize;
|
3622
|
-
const pageSizeOpt = process.argv.find(x => x.startsWith('
|
3696
|
+
const pageSizeOpt = process.argv.find(x => x.startsWith('--page-size='));
|
3623
3697
|
if (pageSizeOpt) pageSize = parseInt(pageSizeOpt.split('=')[1]) * 1024;
|
3624
3698
|
|
3625
3699
|
// set generic opcodes for current valtype
|