porffor 0.55.24 → 0.55.25

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  import { read_ieee754_binary64, read_signedLEB128, read_unsignedLEB128 } from './encoding.js';
2
- import { Blocktype, Opcodes, Valtype } from './wasmSpec.js';
2
+ import { Blocktype, Opcodes, Valtype, PageSize } from './wasmSpec.js';
3
3
  import { operatorOpcode } from './expression.js';
4
4
  import { log } from './log.js';
5
5
  import './prefs.js';
@@ -218,7 +218,7 @@ export default ({ funcs, globals, tags, data, exceptions, pages }) => {
218
218
  if (pages.size > 0) {
219
219
  includes.set('stdlib.h', true);
220
220
  prepend.set('_memory', `char* _memory; u32 _memoryPages = ${pages.size};\n`);
221
- prependMain.set('_initMemory', `_memory = malloc(_memoryPages * ${pageSize});\n`);
221
+ prependMain.set('_initMemory', `_memory = malloc(_memoryPages * ${PageSize});\n`);
222
222
  if (Prefs['2cMemcpy']) includes.set('string.h', true);
223
223
  }
224
224
 
@@ -1,9 +1,8 @@
1
- import { PageSize } from './wasmSpec.js';
2
1
  import './prefs.js';
3
2
 
4
3
  const pagePtr = ind => {
5
4
  if (ind === 0) return 16;
6
- return ind * PageSize;
5
+ return ind * pageSize;
7
6
  };
8
7
 
9
8
  export const nameToReason = (scope, name) => {
@@ -37,7 +36,7 @@ export const allocBytes = ({ scope, pages }, reason, bytes) => {
37
36
  return allocs.get(reason);
38
37
  }
39
38
 
40
- let bin = bins.find(x => (PageSize - x.used) >= bytes);
39
+ let bin = bins.find(x => (pageSize - x.used) >= bytes);
41
40
  if (!bin) {
42
41
  // new bin
43
42
  const page = pages.size;
@@ -1,6 +1,6 @@
1
1
  import * as PrecompiledBuiltins from './builtins_precompiled.js';
2
2
  import ObjectBuiltins from './builtins_objects.js';
3
- import { Blocktype, Opcodes, Valtype, ValtypeSize } from './wasmSpec.js';
3
+ import { PageSize, Blocktype, Opcodes, Valtype } from './wasmSpec.js';
4
4
  import { TYPES, TYPE_NAMES } from './types.js';
5
5
  import { number, unsignedLEB128 } from './encoding.js';
6
6
  import './prefs.js';
@@ -778,7 +778,7 @@ export const BuiltinFuncs = function() {
778
778
  wasm: [
779
779
  number(1, Valtype.i32),
780
780
  [ Opcodes.memory_grow, 0 ],
781
- number(pageSize, Valtype.i32),
781
+ number(PageSize, Valtype.i32),
782
782
  [ Opcodes.i32_mul ]
783
783
  ]
784
784
  },
@@ -787,23 +787,23 @@ export const BuiltinFuncs = function() {
787
787
  locals: [],
788
788
  globals: [ Valtype.i32, Valtype.i32 ],
789
789
  globalNames: [ 'chunkPtr', 'chunkOffset' ],
790
- globalInits: [ 0, 100 * pageSize ],
790
+ globalInits: [ 0, 100 * PageSize ],
791
791
  returns: [ Valtype.i32 ],
792
792
  returnType: TYPES.number,
793
793
  wasm: [
794
794
  // if chunkOffset >= chunks:
795
795
  [ Opcodes.global_get, 1 ],
796
- number(pageSize * (Prefs.allocatorChunks ?? 16), Valtype.i32),
796
+ number(PageSize * (Prefs.allocatorChunks ?? 16), Valtype.i32),
797
797
  [ Opcodes.i32_ge_s ],
798
798
  [ Opcodes.if, Valtype.i32 ],
799
799
  // chunkOffset = 1 page
800
- number(1 * pageSize, Valtype.i32),
800
+ number(pageSize, Valtype.i32),
801
801
  [ Opcodes.global_set, 1 ],
802
802
 
803
803
  // return chunkPtr = allocated
804
804
  number(Prefs.allocatorChunks ?? 16, Valtype.i32),
805
805
  [ Opcodes.memory_grow, 0 ],
806
- number(pageSize, Valtype.i32),
806
+ number(PageSize, Valtype.i32),
807
807
  [ Opcodes.i32_mul ],
808
808
  [ Opcodes.global_set, 0 ],
809
809
  [ Opcodes.global_get, 0 ],
@@ -1,4 +1,4 @@
1
- import { Blocktype, Opcodes, PageSize, Valtype } from './wasmSpec.js';
1
+ import { Blocktype, Opcodes, Valtype } from './wasmSpec.js';
2
2
  import { TYPES } from './types.js';
3
3
  import { number } from './encoding.js';
4
4
 
@@ -3545,7 +3545,7 @@ const coctcOffset = prop => {
3545
3545
 
3546
3546
  let offset = coctc.get(prop);
3547
3547
  if (offset == null) {
3548
- offset = (coctc.lastOffset ?? 60000) - 9;
3548
+ offset = (coctc.lastOffset ?? Prefs.coctcOffset ?? 16300) - 9;
3549
3549
  if (offset < 0) return 0;
3550
3550
 
3551
3551
  coctc.lastOffset = offset;
package/compiler/index.js CHANGED
@@ -73,7 +73,8 @@ export default (code, module = undefined) => {
73
73
  globalThis.valtype = Prefs.valtype ?? 'f64';
74
74
  globalThis.valtypeBinary = Valtype[valtype];
75
75
 
76
- globalThis.pageSize = (parseInt(Prefs.valtype) * 1024) || PageSize;
76
+ // use smaller page sizes internally (65536 / 4 = 16384)
77
+ globalThis.pageSize = Prefs.pageSize ?? (PageSize / 4);
77
78
 
78
79
  // change some prefs by default for c/native
79
80
  if (target !== 'wasm') {
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.55.24",
4
+ "version": "0.55.25",
5
5
  "author": "Oliver Medhurst <honk@goose.icu>",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.55.24';
3
+ globalThis.version = '0.55.25';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
package/runner/repl.js CHANGED
@@ -34,10 +34,9 @@ console.log(`Welcome to \x1B[1m\x1B[35mPorffor\x1B[0m \x1B[2m(${globalThis.versi
34
34
  console.log();
35
35
 
36
36
  let lastMemory, lastPages;
37
- const PageSize = 65536;
38
37
  const memoryToString = mem => {
39
38
  let out = '';
40
- const wasmPages = mem.buffer.byteLength / PageSize;
39
+ const wasmPages = mem.buffer.byteLength / 65536;
41
40
 
42
41
  out += `\x1B[1mallocated ${mem.buffer.byteLength / 1024}KiB\x1B[0m (using ${wasmPages} Wasm page${wasmPages === 1 ? '' : 's'})\n\n`;
43
42