porffor 0.58.2 → 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 +8 -11
- package/compiler/index.js +17 -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)
|
@@ -1760,7 +1758,7 @@ const getNodeType = (scope, node) => {
|
|
1760
1758
|
const out = typeof ret === 'number' ? [ number(ret, Valtype.i32) ] : ret;
|
1761
1759
|
if (guess != null) out.guess = typeof guess === 'number' ? [ number(guess, Valtype.i32) ] : guess;
|
1762
1760
|
|
1763
|
-
typeUsed(scope, knownType(scope, out));
|
1761
|
+
if (!node._doNotMarkTypeUsed) typeUsed(scope, knownType(scope, out));
|
1764
1762
|
return out;
|
1765
1763
|
};
|
1766
1764
|
|
@@ -2595,7 +2593,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2595
2593
|
args = args.slice(0, paramCount - 1);
|
2596
2594
|
args.push({
|
2597
2595
|
type: 'ArrayExpression',
|
2598
|
-
elements: restArgs
|
2596
|
+
elements: restArgs,
|
2597
|
+
_doNotMarkTypeUsed: true
|
2599
2598
|
});
|
2600
2599
|
}
|
2601
2600
|
}
|
@@ -3269,7 +3268,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3269
3268
|
|
3270
3269
|
if (defaultValue) {
|
3271
3270
|
out.push(
|
3272
|
-
...typeIsOneOf(getType(scope, name), [ TYPES.undefined
|
3271
|
+
...typeIsOneOf(getType(scope, name), [ TYPES.undefined ]),
|
3273
3272
|
[ Opcodes.if, Blocktype.void ],
|
3274
3273
|
...generate(scope, defaultValue, global, name),
|
3275
3274
|
[ global ? Opcodes.global_set : Opcodes.local_set, idx ],
|
@@ -3417,7 +3416,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3417
3416
|
out = out.concat([
|
3418
3417
|
// check tmp is valid object
|
3419
3418
|
// not undefined or empty type
|
3420
|
-
...typeIsOneOf(getType(scope, tmpName), [ TYPES.undefined
|
3419
|
+
...typeIsOneOf(getType(scope, tmpName), [ TYPES.undefined ]),
|
3421
3420
|
|
3422
3421
|
// not null
|
3423
3422
|
...getType(scope, tmpName),
|
@@ -4312,7 +4311,7 @@ const generateUnary = (scope, decl) => {
|
|
4312
4311
|
[ TYPES.number, () => makeString(scope, 'number') ],
|
4313
4312
|
[ TYPES.boolean, () => makeString(scope, 'boolean') ],
|
4314
4313
|
[ [ TYPES.string, TYPES.bytestring ], () => makeString(scope, 'string') ],
|
4315
|
-
[
|
4314
|
+
[ TYPES.undefined, () => makeString(scope, 'undefined') ],
|
4316
4315
|
[ TYPES.function, () => makeString(scope, 'function') ],
|
4317
4316
|
[ TYPES.symbol, () => makeString(scope, 'symbol') ],
|
4318
4317
|
|
@@ -6726,8 +6725,6 @@ const generateFunc = (scope, decl, forceNoExpr = false) => {
|
|
6726
6725
|
[ Opcodes.i32_ne ],
|
6727
6726
|
[ Opcodes.if, Blocktype.void ],
|
6728
6727
|
[ Opcodes.local_get, func.locals[name].idx + 1 ],
|
6729
|
-
number(TYPE_FLAGS.parity, Valtype.i32),
|
6730
|
-
[ Opcodes.i32_or ],
|
6731
6728
|
number(TYPES.undefined, Valtype.i32),
|
6732
6729
|
[ Opcodes.i32_eq ],
|
6733
6730
|
|
@@ -7160,7 +7157,7 @@ export default program => {
|
|
7160
7157
|
data = [];
|
7161
7158
|
currentFuncIndex = importedFuncs.length;
|
7162
7159
|
typeswitchDepth = 0;
|
7163
|
-
usedTypes = new Set([ TYPES.
|
7160
|
+
usedTypes = new Set([ TYPES.undefined, TYPES.number, TYPES.boolean, TYPES.function ]);
|
7164
7161
|
coctc = new Map();
|
7165
7162
|
globalInfer = new Map();
|
7166
7163
|
|
package/compiler/index.js
CHANGED
@@ -253,11 +253,19 @@ export default (code, module = undefined) => {
|
|
253
253
|
const compiler = (Prefs.compiler ?? process.env.CC ?? 'cc').split(' ');
|
254
254
|
const cO = Prefs._cO ?? 'O3';
|
255
255
|
|
256
|
-
const
|
257
|
-
|
256
|
+
const args = [
|
257
|
+
...compiler,
|
258
|
+
'-xc', '-', // use stdin as c source in
|
259
|
+
'-o', outFile ?? (process.platform === 'win32' ? 'out.exe' : 'out'), // set path for output
|
258
260
|
|
259
|
-
|
260
|
-
|
261
|
+
// default cc args, always
|
262
|
+
'-lm', // link math.h
|
263
|
+
'-fno-exceptions', // disable exceptions
|
264
|
+
'-fno-ident', '-ffunction-sections', '-fdata-sections', // remove unneeded binary sections
|
265
|
+
'-' + cO
|
266
|
+
];
|
267
|
+
|
268
|
+
if (Prefs.clangFast) args.push('-flto=thin', '-march=native', '-ffast-math', '-fno-asynchronous-unwind-tables');
|
261
269
|
|
262
270
|
if (Prefs.s) args.push('-s');
|
263
271
|
|
@@ -269,12 +277,12 @@ export default (code, module = undefined) => {
|
|
269
277
|
if (logProgress) progressStart(`compiling C to native (using ${compiler})...`);
|
270
278
|
const t5 = performance.now();
|
271
279
|
|
272
|
-
fs.writeFileSync(tmpfile, c);
|
273
|
-
|
274
280
|
// obvious command escape is obvious
|
275
|
-
execSync(args.join(' '), {
|
276
|
-
|
277
|
-
|
281
|
+
execSync(args.join(' '), {
|
282
|
+
stdio: [ 'pipe', 'inherit', 'inherit' ],
|
283
|
+
input: c,
|
284
|
+
encoding: 'utf8'
|
285
|
+
});
|
278
286
|
|
279
287
|
if (logProgress) progressStart(`compiled C to native (using ${compiler})`, t5);
|
280
288
|
|
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"
|