porffor 0.55.5 → 0.55.7
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/codegen.js +13 -8
- package/compiler/index.js +2 -2
- package/package.json +1 -1
- package/r.js +6 -2
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -2134,12 +2134,13 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2134
2134
|
funcs.push(func);
|
2135
2135
|
}
|
2136
2136
|
|
2137
|
+
const arg = decl.arguments[0] ?? DEFAULT_VALUE();
|
2137
2138
|
const idx = funcIndex[rhemynName];
|
2138
2139
|
return [
|
2139
2140
|
// make string arg
|
2140
|
-
...generate(scope,
|
2141
|
+
...generate(scope, arg),
|
2141
2142
|
Opcodes.i32_to_u,
|
2142
|
-
...getNodeType(scope,
|
2143
|
+
...getNodeType(scope, arg),
|
2143
2144
|
|
2144
2145
|
// call regex func
|
2145
2146
|
[ Opcodes.call, idx ],
|
@@ -2150,7 +2151,6 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2150
2151
|
}
|
2151
2152
|
|
2152
2153
|
protoName = decl.callee.property.name;
|
2153
|
-
|
2154
2154
|
target = decl.callee.object;
|
2155
2155
|
}
|
2156
2156
|
|
@@ -2163,6 +2163,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2163
2163
|
type: 'CallExpression',
|
2164
2164
|
callee: target,
|
2165
2165
|
arguments: decl.arguments.slice(1),
|
2166
|
+
optional: decl.optional,
|
2166
2167
|
_thisWasm: [
|
2167
2168
|
...generate(scope, decl.arguments[0] ?? DEFAULT_VALUE()),
|
2168
2169
|
[ Opcodes.local_tee, valTmp ],
|
@@ -2269,6 +2270,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2269
2270
|
|
2270
2271
|
protoBC[type] = () => generate(scope, {
|
2271
2272
|
type: 'CallExpression',
|
2273
|
+
optional: decl.optional,
|
2272
2274
|
callee: {
|
2273
2275
|
type: 'Identifier',
|
2274
2276
|
name: x
|
@@ -2370,7 +2372,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2370
2372
|
...protoBC,
|
2371
2373
|
|
2372
2374
|
// TODO: error better
|
2373
|
-
default:
|
2375
|
+
default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
|
2376
|
+
: internalThrow(scope, 'TypeError', `'${protoName}' proto func tried to be called on a type without an impl`, !unusedValue)
|
2374
2377
|
}, unusedValue ? Blocktype.void : valtypeBinary),
|
2375
2378
|
...(unusedValue ? [ number(UNDEFINED) ] : [])
|
2376
2379
|
];
|
@@ -2392,7 +2395,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2392
2395
|
...protoBC,
|
2393
2396
|
|
2394
2397
|
// TODO: error better
|
2395
|
-
default:
|
2398
|
+
default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
|
2399
|
+
: def
|
2396
2400
|
}, valtypeBinary)
|
2397
2401
|
];
|
2398
2402
|
}
|
@@ -2580,7 +2584,8 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
|
|
2580
2584
|
...setLastType(scope)
|
2581
2585
|
],
|
2582
2586
|
|
2583
|
-
default:
|
2587
|
+
default: decl.optional ? withType(scope, [ number(UNDEFINED) ], TYPES.undefined)
|
2588
|
+
: internalThrow(scope, 'TypeError', `${unhackName(name)} is not a function`, Valtype.f64)
|
2584
2589
|
}, Valtype.f64),
|
2585
2590
|
...(valtypeBinary === Valtype.i32 && scope.returns[0] !== Valtype.f64 ? [ [ Opcodes.f64_convert_i32_s ] ] : [])
|
2586
2591
|
];
|
@@ -3180,7 +3185,7 @@ const setDefaultFuncName = (decl, name) => {
|
|
3180
3185
|
if (decl.type === 'ClassExpression') {
|
3181
3186
|
// check if it has a name definition
|
3182
3187
|
for (const x of decl.body.body) {
|
3183
|
-
if (x.key.name === 'name') return;
|
3188
|
+
if (x.static && x.key.name === 'name') return;
|
3184
3189
|
}
|
3185
3190
|
}
|
3186
3191
|
|
@@ -3258,7 +3263,7 @@ const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
|
3258
3263
|
const [ _func, out ] = generateFunc(scope, init, true);
|
3259
3264
|
|
3260
3265
|
const funcName = init.id?.name;
|
3261
|
-
if (name !== funcName) {
|
3266
|
+
if (name !== funcName && funcIndex[funcName]) {
|
3262
3267
|
funcIndex[name] = funcIndex[funcName];
|
3263
3268
|
delete funcIndex[funcName];
|
3264
3269
|
}
|
package/compiler/index.js
CHANGED
@@ -67,7 +67,7 @@ export default (code, module = undefined) => {
|
|
67
67
|
let target = Prefs.target ?? 'wasm';
|
68
68
|
if (Prefs.native) target = 'native';
|
69
69
|
|
70
|
-
|
70
|
+
let outFile = Prefs.o;
|
71
71
|
const logProgress = Prefs.profileCompiler || (Prefs.target && outFile && !Prefs.native && globalThis.file);
|
72
72
|
|
73
73
|
globalThis.valtype = Prefs.valtype ?? 'f64';
|
@@ -243,7 +243,7 @@ export default (code, module = undefined) => {
|
|
243
243
|
outFile ??= Prefs.native ? './porffor_tmp' : file.split('/').at(-1).split('.')[0];
|
244
244
|
|
245
245
|
let compiler = Prefs.compiler ?? 'clang';
|
246
|
-
const cO = Prefs._cO ?? '
|
246
|
+
const cO = Prefs._cO ?? 'O3';
|
247
247
|
|
248
248
|
if (compiler === 'zig') compiler = [ 'zig', 'cc' ];
|
249
249
|
else compiler = [ compiler ];
|
package/package.json
CHANGED
package/r.js
CHANGED