porffor 0.60.10 → 0.60.11
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_precompiled.js +1071 -1071
- package/compiler/codegen.js +17 -25
- package/compiler/precompile.js +2 -2
- package/foo.js +9 -28
- package/package.json +1 -1
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -73,17 +73,6 @@ export const allocStr = (scope, str, bytestring) => {
|
|
73
73
|
return allocBytes(scope, str, bytes);
|
74
74
|
};
|
75
75
|
|
76
|
-
const todo = (scope, msg, expectsValue = undefined) => {
|
77
|
-
msg = `todo: ${msg}`;
|
78
|
-
|
79
|
-
switch (Prefs.todoTime ?? 'runtime') {
|
80
|
-
case 'compile':
|
81
|
-
throw new Error(msg);
|
82
|
-
|
83
|
-
case 'runtime':
|
84
|
-
return internalThrow(scope, 'Error', msg, expectsValue);
|
85
|
-
}
|
86
|
-
};
|
87
76
|
|
88
77
|
const isFuncType = type =>
|
89
78
|
type === 'FunctionDeclaration' || type === 'FunctionExpression' || type === 'ArrowFunctionExpression' ||
|
@@ -443,7 +432,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
443
432
|
return cacheAst(decl, generateTaggedTemplate(scope, decl, global, name, valueUnused));
|
444
433
|
|
445
434
|
case 'ExportNamedDeclaration':
|
446
|
-
if (!decl.declaration) return
|
435
|
+
if (!decl.declaration) return internalThrow(scope, 'Error', 'porffor: unsupported export declaration', true);
|
447
436
|
|
448
437
|
const funcsBefore = funcs.map(x => x.name);
|
449
438
|
generate(scope, decl.declaration);
|
@@ -469,6 +458,12 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
469
458
|
if (Prefs.d) log.warning('codegen', 'with is not supported, treating as expression');
|
470
459
|
return cacheAst(decl, generate(scope, decl.body));
|
471
460
|
|
461
|
+
case 'PrivateIdentifier':
|
462
|
+
return cacheAst(decl, generate(scope, {
|
463
|
+
type: 'Literal',
|
464
|
+
value: privateIDName(decl.name)
|
465
|
+
}));
|
466
|
+
|
472
467
|
case 'TSEnumDeclaration':
|
473
468
|
return cacheAst(decl, generateEnum(scope, decl));
|
474
469
|
|
@@ -479,7 +474,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
|
|
479
474
|
return cacheAst(decl, [ number(UNDEFINED) ]);
|
480
475
|
}
|
481
476
|
|
482
|
-
return cacheAst(decl,
|
477
|
+
return cacheAst(decl, internalThrow(scope, 'Error', `porffor: no generation for ${decl.type}`, true));
|
483
478
|
}
|
484
479
|
};
|
485
480
|
|
@@ -905,8 +900,6 @@ const performLogicOp = (scope, op, left, right, leftType, rightType) => {
|
|
905
900
|
'??': nullish
|
906
901
|
};
|
907
902
|
|
908
|
-
if (!checks[op]) return todo(scope, `logic operator ${op} not implemented yet`, true);
|
909
|
-
|
910
903
|
// generic structure for {a} OP {b}
|
911
904
|
// _ = {a}; if (OP_CHECK) {b} else _
|
912
905
|
|
@@ -1286,7 +1279,6 @@ const performOp = (scope, op, left, right, leftType, rightType) => {
|
|
1286
1279
|
|
1287
1280
|
// some complex ops are implemented in funcs
|
1288
1281
|
if (typeof ops === 'function') return finalize(asmFuncToAsm(scope, ops, { left, right }));
|
1289
|
-
if (!ops) return todo(scope, `operator ${op} not implemented yet`, true);
|
1290
1282
|
if (!Array.isArray(ops)) ops = [ ops ];
|
1291
1283
|
ops = [ ops ];
|
1292
1284
|
|
@@ -1950,6 +1942,13 @@ const getNodeType = (scope, node) => {
|
|
1950
1942
|
return getNodeType(scope, node.body);
|
1951
1943
|
}
|
1952
1944
|
|
1945
|
+
if (node.type === 'PrivateIdentifier') {
|
1946
|
+
return getNodeType(scope, {
|
1947
|
+
type: 'Literal',
|
1948
|
+
value: privateIDName(node.name)
|
1949
|
+
});
|
1950
|
+
}
|
1951
|
+
|
1953
1952
|
if (node.type.endsWith('Statement') || node.type.endsWith('Declaration')) {
|
1954
1953
|
return TYPES.undefined;
|
1955
1954
|
}
|
@@ -2021,8 +2020,6 @@ const generateLiteral = (scope, decl, global, name) => {
|
|
2021
2020
|
]
|
2022
2021
|
});
|
2023
2022
|
}
|
2024
|
-
|
2025
|
-
return todo(scope, `cannot generate literal of type ${typeof decl.value}`, true);
|
2026
2023
|
};
|
2027
2024
|
|
2028
2025
|
const generateExp = (scope, decl) => {
|
@@ -3525,8 +3522,6 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3525
3522
|
]
|
3526
3523
|
}, undefined, global)
|
3527
3524
|
);
|
3528
|
-
} else {
|
3529
|
-
return todo(scope, `${prop.type} is not supported in object patterns`);
|
3530
3525
|
}
|
3531
3526
|
}
|
3532
3527
|
|
@@ -3567,8 +3562,6 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3567
3562
|
}),
|
3568
3563
|
[ Opcodes.drop ]
|
3569
3564
|
];
|
3570
|
-
|
3571
|
-
return todo(scope, `variable declarators of type ${pattern.type} are not supported yet`);
|
3572
3565
|
}
|
3573
3566
|
|
3574
3567
|
const generateVar = (scope, decl) => {
|
@@ -4437,8 +4430,6 @@ const generateUnary = (scope, decl) => {
|
|
4437
4430
|
return out;
|
4438
4431
|
}
|
4439
4432
|
}
|
4440
|
-
|
4441
|
-
return todo(scope, `unary operator ${decl.operator} not implemented yet`, true);
|
4442
4433
|
};
|
4443
4434
|
|
4444
4435
|
const generateUpdate = (scope, decl, _global, _name, valueUnused = false) => {
|
@@ -5564,7 +5555,8 @@ const generateMeta = (scope, decl) => {
|
|
5564
5555
|
return [ number(UNDEFINED) ];
|
5565
5556
|
}
|
5566
5557
|
|
5567
|
-
|
5558
|
+
// todo: import.meta
|
5559
|
+
return internalThrow(scope, 'Error', `porffor: meta property ${decl.meta.name}.${decl.property.name} is not supported yet`, true);
|
5568
5560
|
};
|
5569
5561
|
|
5570
5562
|
const compileBytes = (val, itemType) => {
|
package/compiler/precompile.js
CHANGED
@@ -57,7 +57,7 @@ const compile = async (file, _funcs) => {
|
|
57
57
|
first = source.slice(0, source.indexOf('\n'));
|
58
58
|
}
|
59
59
|
|
60
|
-
let args = ['--module', '--
|
60
|
+
let args = ['--module', '--truthy=no_nan_negative', '--no-rm-unused-types', '--fast-length', '--parse-types', '--opt-types', '--no-passive-data', '--active-data', '--no-treeshake-wasm-imports', '--no-coctc'];
|
61
61
|
if (first.startsWith('// @porf')) {
|
62
62
|
args = first.slice('// @porf '.length).split(' ').concat(args);
|
63
63
|
}
|
@@ -278,7 +278,7 @@ ${funcs.map(x => {
|
|
278
278
|
const name = x.name.includes('#') ? `['${x.name}']` : `.${x.name}`;
|
279
279
|
|
280
280
|
const returnTypes = [...(x.returnTypes ?? [])].filter(x => ![ TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ].includes(x));
|
281
|
-
return `x${name}
|
281
|
+
return `x${name}={
|
282
282
|
wasm:${rewriteWasm(x.wasm)},
|
283
283
|
params:${JSON.stringify(x.params)},typedParams:1,returns:${JSON.stringify(x.returns)},${x.returnType != null ? `returnType:${JSON.stringify(x.returnType)},` : ''}${returnTypes.length > 0 ? `returnTypes:${JSON.stringify(returnTypes)},` : ''}jsLength:${x.jsLength},
|
284
284
|
locals:${JSON.stringify(locals.slice(x.params.length).map(x => x[1].type))},localNames:${JSON.stringify(locals.map(x => x[0]))},
|
package/foo.js
CHANGED
@@ -1,34 +1,15 @@
|
|
1
|
-
|
2
|
-
const ITER = 50_000_000; // 50 million iterations
|
3
|
-
const key = "a";
|
1
|
+
let count = 0;
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
// --- Benchmark "in" ---
|
10
|
-
const t1 = Date.now();
|
11
|
-
for (let i = 0; i < ITER; i++) {
|
12
|
-
if (key in o) {
|
13
|
-
// noop
|
3
|
+
class Class {
|
4
|
+
#method() {
|
5
|
+
count += 1;
|
14
6
|
}
|
15
|
-
}
|
16
|
-
console.log(`in: ${Date.now() - t1}ms`);
|
17
7
|
|
18
|
-
|
19
|
-
|
20
|
-
for (let i = 0; i < ITER; i++) {
|
21
|
-
if (Object.hasOwn(o, key)) {
|
22
|
-
// noop
|
8
|
+
static isNameIn(value) {
|
9
|
+
return #method in value;
|
23
10
|
}
|
24
11
|
}
|
25
|
-
console.log(`Object.hasOwn: ${Date.now() - t2}ms`);
|
26
12
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (o[key] !== undefined) {
|
31
|
-
// noop
|
32
|
-
}
|
33
|
-
}
|
34
|
-
console.log(`o[k]: ${Date.now() - t3}ms`);
|
13
|
+
console.log(Class.isNameIn({}), false);
|
14
|
+
console.log(Class.isNameIn(new Class()), true);
|
15
|
+
console.log(count, 0);
|
package/package.json
CHANGED