porffor 0.58.3 → 0.58.4
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/bun.lock +45 -0
- package/compiler/builtins/_internal_object.ts +7 -10
- package/compiler/builtins/console.ts +0 -2
- package/compiler/builtins/error.js +1 -1
- package/compiler/builtins/object_hiddenPrototype.js +1 -1
- package/compiler/builtins/z_ecma262.ts +2 -6
- package/compiler/builtins_precompiled.js +547 -547
- package/compiler/codegen.js +5 -9
- package/compiler/parse.js +13 -5
- package/compiler/precompile.js +1 -1
- package/compiler/types.js +2 -5
- package/compiler/wrap.js +0 -1
- package/jsr.json +1 -1
- package/package.json +3 -2
- package/runtime/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -662,8 +662,6 @@ const generateReturn = (scope, decl) => {
|
|
662
662
|
...(scope.subclass ? [
|
663
663
|
// if subclass and returning undefined, return this
|
664
664
|
[ Opcodes.local_get, localTmp(scope, '#return#type', Valtype.i32) ],
|
665
|
-
number(TYPE_FLAGS.parity, Valtype.i32),
|
666
|
-
[ Opcodes.i32_or ],
|
667
665
|
number(TYPES.undefined, Valtype.i32),
|
668
666
|
[ Opcodes.i32_eq ],
|
669
667
|
[ Opcodes.if, Blocktype.void ],
|
@@ -989,7 +987,7 @@ const nullish = (scope, wasm, type, intIn = false, intOut = false) => {
|
|
989
987
|
...(!useTmp ? [] : [ [ Opcodes.local_set, tmp ] ]),
|
990
988
|
|
991
989
|
...typeSwitch(scope, type, [
|
992
|
-
[
|
990
|
+
[ TYPES.undefined, [
|
993
991
|
// empty
|
994
992
|
...(!useTmp ? [ [ Opcodes.drop ] ] : []),
|
995
993
|
number(1, intOut ? Valtype.i32 : valtypeBinary)
|
@@ -3270,7 +3268,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3270
3268
|
|
3271
3269
|
if (defaultValue) {
|
3272
3270
|
out.push(
|
3273
|
-
...typeIsOneOf(getType(scope, name), [ TYPES.undefined
|
3271
|
+
...typeIsOneOf(getType(scope, name), [ TYPES.undefined ]),
|
3274
3272
|
[ Opcodes.if, Blocktype.void ],
|
3275
3273
|
...generate(scope, defaultValue, global, name),
|
3276
3274
|
[ global ? Opcodes.global_set : Opcodes.local_set, idx ],
|
@@ -3418,7 +3416,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3418
3416
|
out = out.concat([
|
3419
3417
|
// check tmp is valid object
|
3420
3418
|
// not undefined or empty type
|
3421
|
-
...typeIsOneOf(getType(scope, tmpName), [ TYPES.undefined
|
3419
|
+
...typeIsOneOf(getType(scope, tmpName), [ TYPES.undefined ]),
|
3422
3420
|
|
3423
3421
|
// not null
|
3424
3422
|
...getType(scope, tmpName),
|
@@ -4313,7 +4311,7 @@ const generateUnary = (scope, decl) => {
|
|
4313
4311
|
[ TYPES.number, () => makeString(scope, 'number') ],
|
4314
4312
|
[ TYPES.boolean, () => makeString(scope, 'boolean') ],
|
4315
4313
|
[ [ TYPES.string, TYPES.bytestring ], () => makeString(scope, 'string') ],
|
4316
|
-
[
|
4314
|
+
[ TYPES.undefined, () => makeString(scope, 'undefined') ],
|
4317
4315
|
[ TYPES.function, () => makeString(scope, 'function') ],
|
4318
4316
|
[ TYPES.symbol, () => makeString(scope, 'symbol') ],
|
4319
4317
|
|
@@ -6727,8 +6725,6 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6727
6725
|
[ Opcodes.i32_ne ],
|
6728
6726
|
[ Opcodes.if, Blocktype.void ],
|
6729
6727
|
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6730
|
-
number(TYPE_FLAGS.parity, Valtype.i32),
|
6731
|
-
[ Opcodes.i32_or ],
|
6732
6728
|
number(TYPES.undefined, Valtype.i32),
|
6733
6729
|
[ Opcodes.i32_eq ],
|
6734
6730
|
|
@@ -7161,7 +7157,7 @@ export default program => {
|
|
7161
7157
|
data = [];
|
7162
7158
|
currentFuncIndex = importedFuncs.length;
|
7163
7159
|
typeswitchDepth = 0;
|
7164
|
-
usedTypes = new Set([ TYPES.
|
7160
|
+
usedTypes = new Set([ TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ]);
|
7165
7161
|
coctc = new Map();
|
7166
7162
|
globalInfer = new Map();
|
7167
7163
|
|
package/compiler/parse.js
CHANGED
@@ -11,21 +11,24 @@ globalThis.typedInput = types && Prefs.optTypes;
|
|
11
11
|
// - meriyah
|
12
12
|
// - hermes-parser
|
13
13
|
// - @babel/parser
|
14
|
+
// - oxc-parser
|
14
15
|
|
15
16
|
globalThis.parser = '';
|
16
17
|
let parse;
|
17
18
|
const loadParser = async (fallbackParser = 'acorn', forceParser) => {
|
18
19
|
parser = forceParser ?? Prefs.parser ?? fallbackParser;
|
19
|
-
|
20
|
+
const mod = (await import((globalThis.document || globalThis.Deno ? 'https://esm.sh/' : '') + parser));
|
21
|
+
if (mod.parseSync) parse = mod.parseSync;
|
22
|
+
else parse = mod.parse;
|
20
23
|
};
|
21
24
|
globalThis._porf_loadParser = loadParser;
|
22
25
|
await loadParser(types ? '@babel/parser' : undefined);
|
23
26
|
|
24
|
-
if (types && !['@babel/parser', 'hermes-parser'].includes(parser)) log.warning('parse', `passed -parse-types with a parser (${parser}) which does not support`);
|
27
|
+
if (types && !['@babel/parser', 'hermes-parser', 'oxc-parser'].includes(parser)) log.warning('parse', `passed -parse-types with a parser (${parser}) which does not support`);
|
25
28
|
|
26
29
|
export default input => {
|
27
30
|
try {
|
28
|
-
const
|
31
|
+
const options = {
|
29
32
|
// acorn
|
30
33
|
ecmaVersion: 'latest',
|
31
34
|
|
@@ -43,9 +46,14 @@ export default input => {
|
|
43
46
|
ranges: false,
|
44
47
|
tokens: false,
|
45
48
|
comments: false,
|
46
|
-
});
|
47
49
|
|
48
|
-
|
50
|
+
// oxc
|
51
|
+
lang: types ? 'ts' : 'js',
|
52
|
+
showSemanticErrors: true // sorry oxc pals but this default is bad
|
53
|
+
};
|
54
|
+
|
55
|
+
let ast = parser === 'oxc-parser' ? parse('js', input, options) : parse(input, options);
|
56
|
+
if (ast.program) ast = ast.program;
|
49
57
|
|
50
58
|
return ast;
|
51
59
|
} catch (e) {
|
package/compiler/precompile.js
CHANGED
@@ -277,7 +277,7 @@ ${funcs.map(x => {
|
|
277
277
|
// todo: check for other identifier unsafe characters
|
278
278
|
const name = x.name.includes('#') ? `['${x.name}']` : `.${x.name}`;
|
279
279
|
|
280
|
-
const returnTypes = [...(x.returnTypes ?? [])].filter(x => ![ TYPES.
|
280
|
+
const returnTypes = [...(x.returnTypes ?? [])].filter(x => ![ TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ].includes(x));
|
281
281
|
return `this${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)},` : ''}
|
package/compiler/types.js
CHANGED
@@ -6,20 +6,17 @@ export const TYPE_FLAGS = {
|
|
6
6
|
};
|
7
7
|
|
8
8
|
export const TYPES = {
|
9
|
-
|
9
|
+
undefined: 0x00,
|
10
10
|
number: 0x01,
|
11
11
|
boolean: 0x02,
|
12
12
|
string: 0x03 | TYPE_FLAGS.length,
|
13
13
|
bigint: 0x04,
|
14
14
|
symbol: 0x05,
|
15
15
|
function: 0x06,
|
16
|
-
object: 0x07
|
17
|
-
|
18
|
-
undefined: 0x00 | TYPE_FLAGS.parity,
|
16
|
+
object: 0x07
|
19
17
|
};
|
20
18
|
|
21
19
|
export const TYPE_NAMES = {
|
22
|
-
[TYPES.empty]: 'empty',
|
23
20
|
[TYPES.number]: 'Number',
|
24
21
|
[TYPES.boolean]: 'Boolean',
|
25
22
|
[TYPES.string]: 'String',
|
package/compiler/wrap.js
CHANGED
package/jsr.json
CHANGED
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "porffor",
|
3
3
|
"description": "An ahead-of-time JavaScript compiler",
|
4
|
-
"version": "0.58.
|
4
|
+
"version": "0.58.4",
|
5
5
|
"author": "Oliver Medhurst <honk@goose.icu>",
|
6
6
|
"license": "MIT",
|
7
7
|
"scripts": {},
|
@@ -12,7 +12,8 @@
|
|
12
12
|
"optionalDependencies": {
|
13
13
|
"@babel/parser": "^7.24.4",
|
14
14
|
"hermes-parser": "^0.18.2",
|
15
|
-
"meriyah": "^4.3.9"
|
15
|
+
"meriyah": "^4.3.9",
|
16
|
+
"oxc-parser": "^0.72.2"
|
16
17
|
},
|
17
18
|
"bin": {
|
18
19
|
"porf": "./runtime/index.js"
|