porffor 0.37.15 → 0.37.17
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/2c.js +68 -8
- package/compiler/builtins_precompiled.js +238 -238
- package/compiler/codegen.js +61 -3
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/codegen.js
CHANGED
@@ -1015,7 +1015,7 @@ const asmFunc = (name, { wasm, params = [], typedParams = false, locals: localTy
|
|
1015
1015
|
const existing = funcByName(name);
|
1016
1016
|
if (existing) return existing;
|
1017
1017
|
|
1018
|
-
const nameParam = i => localNames[i] ??
|
1018
|
+
const nameParam = i => localNames[i] ?? `l${i}`;
|
1019
1019
|
|
1020
1020
|
const allLocals = params.concat(localTypes);
|
1021
1021
|
const locals = {};
|
@@ -1398,6 +1398,11 @@ const getNodeType = (scope, node) => {
|
|
1398
1398
|
return TYPES.number;
|
1399
1399
|
}
|
1400
1400
|
|
1401
|
+
if (node.type === 'TemplateLiteral') {
|
1402
|
+
// could be normal string but shrug
|
1403
|
+
return TYPES.bytestring;
|
1404
|
+
}
|
1405
|
+
|
1401
1406
|
if (node.type === 'TaggedTemplateExpression') {
|
1402
1407
|
// hack
|
1403
1408
|
switch (node.tag.name) {
|
@@ -2932,6 +2937,59 @@ const setLocalWithType = (scope, name, isGlobal, decl, tee = false, overrideType
|
|
2932
2937
|
};
|
2933
2938
|
|
2934
2939
|
const generateVarDstr = (scope, kind, pattern, init, defaultValue, global) => {
|
2940
|
+
// statically analyzed ffi dlopen hack to let 2c handle it
|
2941
|
+
if (init && init.type === 'CallExpression' && init.callee.name === '__Porffor_dlopen') {
|
2942
|
+
if (Prefs.target !== 'native' && !Prefs.native) throw new Error('Porffor.dlopen is only supported for native target (use --native)');
|
2943
|
+
|
2944
|
+
// disable pgo if using ffi (lol)
|
2945
|
+
Prefs.pgo = false;
|
2946
|
+
|
2947
|
+
try {
|
2948
|
+
let usedNames = [];
|
2949
|
+
for (const x of pattern.properties) {
|
2950
|
+
const name = x.key.name;
|
2951
|
+
usedNames.push(name);
|
2952
|
+
}
|
2953
|
+
|
2954
|
+
let path = init.arguments[0].value;
|
2955
|
+
let symbols = {};
|
2956
|
+
|
2957
|
+
for (const x of init.arguments[1].properties) {
|
2958
|
+
const name = x.key.name;
|
2959
|
+
if (!usedNames.includes(name)) continue;
|
2960
|
+
|
2961
|
+
let parameters, result;
|
2962
|
+
for (const y of x.value.properties) {
|
2963
|
+
switch (y.key.name) {
|
2964
|
+
case 'parameters':
|
2965
|
+
parameters = y.value.elements.map(z => z.value);
|
2966
|
+
break;
|
2967
|
+
|
2968
|
+
case 'result':
|
2969
|
+
result = y.value.value;
|
2970
|
+
break;
|
2971
|
+
}
|
2972
|
+
}
|
2973
|
+
|
2974
|
+
symbols[name] = { parameters, result };
|
2975
|
+
|
2976
|
+
// mock ffi function
|
2977
|
+
asmFunc(name, {
|
2978
|
+
wasm: [],
|
2979
|
+
params: parameters.map(x => Valtype.i32),
|
2980
|
+
returns: result ? [ Valtype.i32 ] : [],
|
2981
|
+
returnType: TYPES.number
|
2982
|
+
})
|
2983
|
+
}
|
2984
|
+
|
2985
|
+
return [ [ null, 'dlopen', path, symbols ] ];
|
2986
|
+
} catch (e) {
|
2987
|
+
console.error('bad Porffor.dlopen syntax');
|
2988
|
+
throw e;
|
2989
|
+
}
|
2990
|
+
}
|
2991
|
+
|
2992
|
+
|
2935
2993
|
const topLevel = scope.name === 'main';
|
2936
2994
|
|
2937
2995
|
if (typeof pattern === 'string') {
|
@@ -3502,7 +3560,7 @@ const generateAssign = (scope, decl, _global, _name, valueUnused = false) => {
|
|
3502
3560
|
[TYPES.undefined]: internalThrow(scope, 'TypeError', 'Cannot set property of undefined', true),
|
3503
3561
|
|
3504
3562
|
// default: internalThrow(scope, 'TypeError', `Cannot assign member with this type`)
|
3505
|
-
default: [
|
3563
|
+
default: () => [
|
3506
3564
|
...objectWasm,
|
3507
3565
|
Opcodes.i32_to_u,
|
3508
3566
|
...(op === '=' ? [] : [ [ Opcodes.local_tee, localTmp(scope, '#objset_object', Valtype.i32) ] ]),
|
@@ -5185,7 +5243,7 @@ const countParams = (func, name = undefined) => {
|
|
5185
5243
|
name ??= func.name;
|
5186
5244
|
let params = func.params.length;
|
5187
5245
|
if (func.constr) params -= 4;
|
5188
|
-
if (!
|
5246
|
+
if (!func.internal || builtinFuncs[name]?.typedParams) params = Math.floor(params / 2);
|
5189
5247
|
|
5190
5248
|
return func.argc = params;
|
5191
5249
|
};
|
package/package.json
CHANGED