porffor 0.25.1 → 0.25.2

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.
@@ -1189,7 +1189,7 @@ const generateBinaryExp = (scope, decl, _global, _name) => {
1189
1189
  const asmFuncToAsm = (scope, func) => {
1190
1190
  return func(scope, {
1191
1191
  TYPES, TYPE_NAMES, typeSwitch, makeArray, makeString, allocPage, internalThrow,
1192
- getNodeType, generateIdent,
1192
+ getNodeType, generate, generateIdent,
1193
1193
  builtin: n => {
1194
1194
  let idx = funcIndex[n] ?? importedFuncs[n];
1195
1195
  if (idx == null && builtinFuncs[n]) {
@@ -3962,7 +3962,7 @@ const generateForIn = (scope, decl) => {
3962
3962
  depth.push('if');
3963
3963
  depth.push('forin');
3964
3964
  depth.push('block');
3965
- depth.push('block');
3965
+ depth.push('if');
3966
3966
 
3967
3967
  // setup local for left
3968
3968
  generate(scope, decl.left);
@@ -3984,6 +3984,7 @@ const generateForIn = (scope, decl) => {
3984
3984
  [TYPES.object]: [
3985
3985
  [ Opcodes.loop, Blocktype.void ],
3986
3986
 
3987
+ // read key
3987
3988
  [ Opcodes.local_get, pointer ],
3988
3989
  [ Opcodes.i32_load, 0, 5 ],
3989
3990
  [ Opcodes.local_tee, localTmp(scope, '#forin_tmp', Valtype.i32) ],
@@ -4009,11 +4010,18 @@ const generateForIn = (scope, decl) => {
4009
4010
  [ isGlobal ? Opcodes.global_set : Opcodes.local_set, local.idx ],
4010
4011
 
4011
4012
  [ Opcodes.block, Blocktype.void ],
4012
- [ Opcodes.block, Blocktype.void ],
4013
+
4014
+ // todo/perf: do not read key for non-enumerables
4015
+ // only run body if entry is enumerable
4016
+ [ Opcodes.local_get, pointer ],
4017
+ [ Opcodes.i32_load8_u, 0, 17 ],
4018
+ [ Opcodes.i32_const, 0b0100 ],
4019
+ [ Opcodes.i32_and ],
4020
+ [ Opcodes.if, Blocktype.void ],
4013
4021
  ...generate(scope, decl.body),
4014
4022
  [ Opcodes.end ],
4015
4023
 
4016
- // increment iter pointer by 14
4024
+ // increment pointer by 14
4017
4025
  [ Opcodes.local_get, pointer ],
4018
4026
  ...number(14, Valtype.i32),
4019
4027
  [ Opcodes.i32_add ],
@@ -4122,7 +4130,7 @@ const generateBreak = (scope, decl) => {
4122
4130
  while: 2, // loop > if (wanted branch) (we are here)
4123
4131
  dowhile: 2, // loop > block (wanted branch) > block (we are here)
4124
4132
  forof: 2, // loop > block (wanted branch) > block (we are here)
4125
- forin: 2, // loop > block (wanted branch) > block (we are here)
4133
+ forin: 2, // loop > block (wanted branch) > if (we are here)
4126
4134
  if: 1, // break inside if, branch 0 to skip the rest of the if
4127
4135
  switch: 1
4128
4136
  })[type];
@@ -4145,7 +4153,7 @@ const generateContinue = (scope, decl) => {
4145
4153
  while: 1, // loop (wanted branch) > if (we are here)
4146
4154
  dowhile: 3, // loop > block > block (wanted branch) (we are here)
4147
4155
  forof: 3, // loop > block > block (wanted branch) (we are here)
4148
- forin: 3 // loop > block > block (wanted branch) (we are here)
4156
+ forin: 3 // loop > block > if (wanted branch) (we are here)
4149
4157
  })[type];
4150
4158
 
4151
4159
  return [
@@ -204,9 +204,10 @@ ${funcs.map(x => {
204
204
  .replace(/\["global",(.*?),"(.*?)",(.*?)\]/g, (_, opcode, name, valtype) => `...glbl(${opcode}, '${name}', ${valtype})`)
205
205
  .replace(/\"local","(.*?)",(.*?)\]/g, (_, name, valtype) => `loc('${name}', ${valtype})]`)
206
206
  .replace(/\[16,"(.*?)"]/g, (_, name) => `[16, ...builtin('${name}')]`)
207
- .replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(scope, '${constructor}', \`${message}\`)`);
207
+ .replace(/\["throw","(.*?)","(.*?)"\]/g, (_, constructor, message) => `...internalThrow(scope, '${constructor}', \`${message}\`)`)
208
+ .replace(/\["get object","(.*?)"\]/g, (_, objName) => `...generateIdent(scope, { name: '${objName}' })`);
208
209
 
209
- return `(scope, {${`${str.includes('allocPage(') ? 'allocPage,' : ''}${str.includes('glbl(') ? 'glbl,' : ''}${str.includes('loc(') ? 'loc,' : ''}${str.includes('builtin(') ? 'builtin,' : ''}${str.includes('internalThrow(') ? 'internalThrow,' : ''}`.slice(0, -1)}}) => ` + str;
210
+ return `(scope, {${`${str.includes('allocPage(') ? 'allocPage,' : ''}${str.includes('glbl(') ? 'glbl,' : ''}${str.includes('loc(') ? 'loc,' : ''}${str.includes('builtin(') ? 'builtin,' : ''}${str.includes('internalThrow(') ? 'internalThrow,' : ''}${str.includes('generateIdent(') ? 'generateIdent,' : ''}`.slice(0, -1)}}) => ` + str;
210
211
  };
211
212
 
212
213
  const locals = Object.entries(x.locals).sort((a,b) => a[1].idx - b[1].idx)
package/compiler/wrap.js CHANGED
@@ -69,7 +69,10 @@ const porfToJSValue = ({ memory, funcs, pages }, value, type) => {
69
69
 
70
70
  const vValue = read(Float64Array, memory, value + offset + 4, 1)[0];
71
71
  const vType = tail >>> 8;
72
- const v = porfToJSValue({ memory, funcs, pages }, vValue, vType);
72
+
73
+ // do not recursive call forever for direct circular
74
+ const v = vValue === value && vType === type ? out :
75
+ porfToJSValue({ memory, funcs, pages }, vValue, vType);
73
76
 
74
77
  const flags = tail & 0xff;
75
78
 
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.25.1+b0893a7c3",
4
+ "version": "0.25.2+bd0735a02",
5
5
  "author": "CanadaHonk",
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.25.1+b0893a7c3';
3
+ globalThis.version = '0.25.2+bd0735a02';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {
@@ -26,18 +26,20 @@ if (process.argv.includes('--help')) {
26
26
  console.log(`\x1B[1m\x1B[35mPorffor\x1B[0m is a JavaScript engine/runtime/compiler. \x1B[90m(${globalThis.version})\x1B[0m`);
27
27
 
28
28
  // basic usage
29
- console.log(`Usage: \x1B[1mporf [command] path/to/script.js [...prefs] [...args]\x1B[0m`);
29
+ console.log(`Usage: \x1B[1mporf [command] [...prefs] path/to/script.js [...args]\x1B[0m`);
30
30
 
31
31
  // commands
32
32
  console.log(`\n\x1B[1mCommands:\x1B[0m`);
33
33
  for (const [ cmd, [ color, desc ] ] of Object.entries({
34
34
  run: [ 34, 'Run a JS file' ],
35
35
  wasm: [ 34, 'Compile a JS file to a Wasm binary\n' ],
36
+
36
37
  c: [ 31, 'Compile a JS file to C source code' ],
37
38
  native: [ 31, 'Compile a JS file to a native binary\n' ],
39
+
38
40
  profile: [ 33, 'Profile a JS file' ],
39
41
  debug: [ 33, 'Debug a JS file' ],
40
- 'debug-wasm': [ 33, 'Debug the compiled Wasm of a JS file' ]
42
+ 'debug-wasm': [ 33, 'Debug the compiled Wasm of a JS file' ],
41
43
  })) {
42
44
  console.log(` \x1B[1m\x1B[${color}m${cmd}\x1B[0m${' '.repeat(20 - cmd.length - (desc.startsWith('🧪') ? 3 : 0))}${desc}`);
43
45
  }
package/todo.txt DELETED
@@ -1,2 +0,0 @@
1
- - retain previous attrs if they are undefined (configurable, other attrs?, set/get) in defineProperty
2
- - make missing objects