porffor 0.2.0-67434d5 → 0.2.0-6922552

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/parse.js CHANGED
@@ -9,8 +9,10 @@ if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
9
9
  globalThis.process = { argv: ['', '', ...Deno.args], stdout: { write: str => Deno.writeAllSync(Deno.stdout, textEncoder.encode(str)) } };
10
10
  }
11
11
 
12
+ const file = process.argv.slice(2).find(x => x[0] !== '-');
13
+
12
14
  // should we try to support types (while parsing)
13
- const types = Prefs.parseTypes;
15
+ const types = Prefs.parseTypes || file?.endsWith('.ts');
14
16
  globalThis.typedInput = types && Prefs.optTypes;
15
17
 
16
18
  // todo: review which to use by default
@@ -70,7 +70,7 @@ const compile = async (file, [ _funcs, _globals ]) => {
70
70
  if (y[0] === Opcodes.const && (n[0] === Opcodes.local_set || n[0] === Opcodes.local_tee)) {
71
71
  const l = locals[n[1]];
72
72
  if (!l) continue;
73
- if (![TYPES.string, TYPES._array, TYPES._bytestring].includes(l.metadata?.type)) continue;
73
+ if (![TYPES.string, TYPES.array, TYPES.bytestring].includes(l.metadata?.type)) continue;
74
74
  if (!x.pages) continue;
75
75
 
76
76
  const pageName = [...x.pages.keys()].find(z => z.endsWith(l.name));
@@ -93,9 +93,14 @@ const precompile = async () => {
93
93
  let funcs = [], globals = [];
94
94
  for (const file of fs.readdirSync(dir)) {
95
95
  if (file.endsWith('.d.ts')) continue;
96
+ console.log(file);
97
+
96
98
  await compile(join(dir, file), [ funcs, globals ]);
97
99
  }
98
100
 
101
+ // const a = funcs.find(x => x.name === '__ecma262_ToUTCDTSF');
102
+ // console.log(Object.values(a.locals).slice(a.params.length));
103
+
99
104
  // ${x.pages && x.pages.size > 0 ? ` pages: ${JSON.stringify(Object.fromEntries(x.pages.entries()))},` : ''}
100
105
  // ${x.used && x.used.length > 0 ? ` used: ${JSON.stringify(x.used)},` : ''}
101
106
 
package/compiler/prefs.js CHANGED
@@ -1,4 +1,4 @@
1
- const onByDefault = [ 'bytestring', 'aotPointerOpt', 'treeshakeWasmImports' ];
1
+ const onByDefault = [ 'bytestring', 'aotPointerOpt', 'treeshakeWasmImports', 'alwaysMemory' ];
2
2
 
3
3
  let cache = {};
4
4
  const obj = new Proxy({}, {
@@ -14,7 +14,7 @@ export const PrototypeFuncs = function() {
14
14
  if (Prefs.zeroChecks) zeroChecks = Prefs.zeroChecks.split('=')[1].split(',').reduce((acc, x) => { acc[x.toLowerCase()] = true; return acc; }, {});
15
15
  else zeroChecks = {};
16
16
 
17
- this[TYPES._array] = {
17
+ this[TYPES.array] = {
18
18
  // lX = local accessor of X ({ get, set }), iX = local index of X, wX = wasm ops of X
19
19
  at: (pointer, length, wIndex, iTmp) => [
20
20
  ...wIndex,
@@ -253,10 +253,10 @@ export const PrototypeFuncs = function() {
253
253
  ]
254
254
  };
255
255
 
256
- this[TYPES._array].at.local = Valtype.i32;
257
- this[TYPES._array].push.noArgRetLength = true;
258
- this[TYPES._array].fill.local = valtypeBinary;
259
- this[TYPES._array].fill.returnType = TYPES._array;
256
+ this[TYPES.array].at.local = Valtype.i32;
257
+ this[TYPES.array].push.noArgRetLength = true;
258
+ this[TYPES.array].fill.local = valtypeBinary;
259
+ this[TYPES.array].fill.returnType = TYPES.array;
260
260
 
261
261
  this[TYPES.string] = {
262
262
  at: (pointer, length, wIndex, iTmp, _, arrayShell) => {
@@ -476,7 +476,7 @@ export const PrototypeFuncs = function() {
476
476
  this[TYPES.string].isWellFormed.returnType = TYPES.boolean;
477
477
 
478
478
  if (Prefs.bytestring) {
479
- this[TYPES._bytestring] = {
479
+ this[TYPES.bytestring] = {
480
480
  at: (pointer, length, wIndex, iTmp, _, arrayShell) => {
481
481
  const [ newOut, newPointer ] = arrayShell(1, 'i8');
482
482
 
@@ -606,14 +606,14 @@ export const PrototypeFuncs = function() {
606
606
  }
607
607
  };
608
608
 
609
- this[TYPES._bytestring].at.local = Valtype.i32;
610
- this[TYPES._bytestring].at.returnType = TYPES._bytestring;
611
- this[TYPES._bytestring].charAt.returnType = TYPES._bytestring;
612
- this[TYPES._bytestring].charCodeAt.local = Valtype.i32;
613
- this[TYPES._bytestring].charCodeAt.noPointerCache = zeroChecks.charcodeat;
609
+ this[TYPES.bytestring].at.local = Valtype.i32;
610
+ this[TYPES.bytestring].at.returnType = TYPES.bytestring;
611
+ this[TYPES.bytestring].charAt.returnType = TYPES.bytestring;
612
+ this[TYPES.bytestring].charCodeAt.local = Valtype.i32;
613
+ this[TYPES.bytestring].charCodeAt.noPointerCache = zeroChecks.charcodeat;
614
614
 
615
- this[TYPES._bytestring].isWellFormed.local = Valtype.i32;
616
- this[TYPES._bytestring].isWellFormed.local2 = Valtype.i32;
617
- this[TYPES._bytestring].isWellFormed.returnType = TYPES.boolean;
615
+ this[TYPES.bytestring].isWellFormed.local = Valtype.i32;
616
+ this[TYPES.bytestring].isWellFormed.local2 = Valtype.i32;
617
+ this[TYPES.bytestring].isWellFormed.returnType = TYPES.boolean;
618
618
  }
619
619
  };
package/compiler/types.js CHANGED
@@ -24,7 +24,7 @@ export const INTERNAL_TYPE_BASE = 0x10;
24
24
  let internalTypeIndex = INTERNAL_TYPE_BASE;
25
25
  const registerInternalType = name => {
26
26
  const n = internalTypeIndex++;
27
- TYPES['_' + name.toLowerCase()] = n;
27
+ TYPES[name.toLowerCase()] = n;
28
28
  TYPE_NAMES[n] = name;
29
29
  };
30
30
 
package/compiler/wrap.js CHANGED
@@ -178,7 +178,7 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
178
178
  return {[func.name]() {}}[func.name];
179
179
  }
180
180
 
181
- case TYPES._array: {
181
+ case TYPES.array: {
182
182
  const pointer = ret;
183
183
  const length = (new Int32Array(memory.buffer, pointer, 1))[0];
184
184
 
@@ -188,14 +188,14 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
188
188
  return Array.from(new Float64Array(buf));
189
189
  }
190
190
 
191
- case TYPES._bytestring: {
191
+ case TYPES.bytestring: {
192
192
  const pointer = ret;
193
193
  const length = (new Int32Array(memory.buffer, pointer, 1))[0];
194
194
 
195
195
  return Array.from(new Uint8Array(memory.buffer, pointer + 4, length)).map(x => String.fromCharCode(x)).join('');
196
196
  }
197
197
 
198
- case TYPES._date: {
198
+ case TYPES.date: {
199
199
  const pointer = ret;
200
200
  const value = (new Float64Array(memory.buffer, pointer, 1))[0];
201
201
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.2.0-67434d5",
4
+ "version": "0.2.0-6922552",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {
package/runner/index.js CHANGED
@@ -38,19 +38,21 @@ if (process.argv.includes('--help')) {
38
38
  console.log(` \x1B[1m\x1B[${color}m${cmd}\x1B[0m${' '.repeat(20 - cmd.length - (desc.startsWith('🧪') ? 3 : 0))}${desc}`);
39
39
  }
40
40
 
41
- // options
42
- console.log(`\n\u001b[4mCommands\x1B[0m`);
43
- for (const [ cmd, [ color, desc ] ] of Object.entries({
44
- run: [ 34, 'Run a JS file' ],
45
- wasm: [ 34, 'Compile a JS file to a Wasm binary\n' ],
46
- c: [ 31, 'Compile a JS file to C source code' ],
47
- native: [ 31, 'Compile a JS file to a native binary\n' ],
48
- profile: [ 33, 'Profile a JS file' ],
49
- debug: [ 33, 'Debug a JS file' ],
50
- 'debug-wasm': [ 33, 'Debug the compiled Wasm of a JS file' ]
51
- })) {
52
- console.log(` \x1B[1m\x1B[${color}m${cmd}\x1B[0m${' '.repeat(20 - cmd.length - (desc.startsWith('🧪') ? 3 : 0))}${desc}`);
53
- }
41
+ // console.log();
42
+
43
+ // // options
44
+ // console.log(`\n\u001b[4mCommands\x1B[0m`);
45
+ // for (const [ cmd, [ color, desc ] ] of Object.entries({
46
+ // run: [ 34, 'Run a JS file' ],
47
+ // wasm: [ 34, 'Compile a JS file to a Wasm binary\n' ],
48
+ // c: [ 31, 'Compile a JS file to C source code' ],
49
+ // native: [ 31, 'Compile a JS file to a native binary\n' ],
50
+ // profile: [ 33, 'Profile a JS file' ],
51
+ // debug: [ 33, 'Debug a JS file' ],
52
+ // 'debug-wasm': [ 33, 'Debug the compiled Wasm of a JS file' ]
53
+ // })) {
54
+ // console.log(` \x1B[1m\x1B[${color}m${cmd}\x1B[0m${' '.repeat(20 - cmd.length - (desc.startsWith('🧪') ? 3 : 0))}${desc}`);
55
+ // }
54
56
 
55
57
  console.log();
56
58
  process.exit(0);
package/fib.js DELETED
@@ -1,10 +0,0 @@
1
- const fib = n => {
2
- if (n < 2) {
3
- return n;
4
- } else {
5
- return fib(n - 1) + fib(n - 2);
6
- }
7
- };
8
-
9
- console.log(fib(7));
10
-