porffor 0.37.11 → 0.37.13
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 +2 -2
- package/compiler/assemble.js +1 -1
- package/compiler/codegen.js +6 -0
- package/compiler/index.js +1 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
package/compiler/2c.js
CHANGED
@@ -213,7 +213,7 @@ export default ({ funcs, globals, tags, data, exceptions, pages }) => {
|
|
213
213
|
}
|
214
214
|
|
215
215
|
if (pages.size > 0) {
|
216
|
-
prepend.set('_memory', `char _memory[${pages.size * pageSize}];\n`);
|
216
|
+
prepend.set('_memory', `static char _memory[${pages.size * pageSize}];\n`);
|
217
217
|
if (Prefs['2cMemcpy']) includes.set('string.h', true);
|
218
218
|
}
|
219
219
|
|
@@ -224,7 +224,7 @@ export default ({ funcs, globals, tags, data, exceptions, pages }) => {
|
|
224
224
|
prependMain.set('_data', activeData.map(x => `memcpy(_memory + ${dataOffset(x)}, (unsigned char[]){${x.bytes.join(',')}}, ${x.bytes.length});`).join('\n '));
|
225
225
|
includes.set('string.h', true);
|
226
226
|
} else {
|
227
|
-
prependMain.set('_data', activeData.map(x => x.bytes.reduce((acc, y, i) => acc + `_memory[${dataOffset(x) + i}]=(u8)${y}
|
227
|
+
prependMain.set('_data', activeData.map(x => x.bytes.reduce((acc, y, i) => acc + (y === 0 ? '' : `_memory[${dataOffset(x) + i}]=(u8)${y};`), '')).join('\n '));
|
228
228
|
}
|
229
229
|
}
|
230
230
|
|
package/compiler/assemble.js
CHANGED
@@ -158,7 +158,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
|
|
158
158
|
bytes.push(argc % 256, (argc / 256 | 0) % 256);
|
159
159
|
|
160
160
|
// userland exposed .length
|
161
|
-
let length = argc;
|
161
|
+
let length = func.jsLength ?? argc;
|
162
162
|
// remove _this from internal prototype funcs
|
163
163
|
if (func.internal && name.includes('_prototype_')) length--;
|
164
164
|
|
package/compiler/codegen.js
CHANGED
@@ -5191,6 +5191,8 @@ const countParams = (func, name = undefined) => {
|
|
5191
5191
|
};
|
5192
5192
|
|
5193
5193
|
const countLength = (func, name = undefined) => {
|
5194
|
+
if (func && func.jsLength != null) return func.jsLength;
|
5195
|
+
|
5194
5196
|
name ??= func.name;
|
5195
5197
|
|
5196
5198
|
let count = countParams(func, name);
|
@@ -5983,12 +5985,14 @@ const generateFunc = (scope, decl) => {
|
|
5983
5985
|
const prelude = [];
|
5984
5986
|
const defaultValues = {};
|
5985
5987
|
const destructuredArgs = {};
|
5988
|
+
let jsLength = 0;
|
5986
5989
|
for (let i = 0; i < params.length; i++) {
|
5987
5990
|
let name;
|
5988
5991
|
const x = params[i];
|
5989
5992
|
switch (x.type) {
|
5990
5993
|
case 'Identifier': {
|
5991
5994
|
name = x.name;
|
5995
|
+
jsLength++;
|
5992
5996
|
break;
|
5993
5997
|
}
|
5994
5998
|
|
@@ -6014,6 +6018,7 @@ const generateFunc = (scope, decl) => {
|
|
6014
6018
|
default:
|
6015
6019
|
name = '#arg_dstr' + i;
|
6016
6020
|
destructuredArgs[name] = x;
|
6021
|
+
jsLength++;
|
6017
6022
|
break;
|
6018
6023
|
}
|
6019
6024
|
|
@@ -6044,6 +6049,7 @@ const generateFunc = (scope, decl) => {
|
|
6044
6049
|
}
|
6045
6050
|
|
6046
6051
|
func.params = Object.values(func.locals).map(x => x.type);
|
6052
|
+
func.jsLength = jsLength;
|
6047
6053
|
|
6048
6054
|
// force generate for main
|
6049
6055
|
if (name === 'main') func.generate();
|
package/compiler/index.js
CHANGED
@@ -256,7 +256,7 @@ export default (code, flags) => {
|
|
256
256
|
if (logProgress) {
|
257
257
|
const total = performance.now();
|
258
258
|
progressClear();
|
259
|
-
console.log(`\u001b[90m[${total.toFixed(0)}ms]\u001b[0m \u001b[
|
259
|
+
console.log(`\u001b[90m[${total.toFixed(0)}ms]\u001b[0m \u001b[32mcompiled ${globalThis.file} \u001b[90m->\u001b[0m \u001b[92m${outFile}\u001b[90m (${(fs.statSync(outFile).size / 1000).toFixed(1)}KB)\u001b[0m`);
|
260
260
|
}
|
261
261
|
|
262
262
|
process.exit();
|
package/package.json
CHANGED