porffor 0.14.0-f67c123a1 → 0.16.0-08983b6b1

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.
Files changed (45) hide show
  1. package/CONTRIBUTING.md +16 -10
  2. package/README.md +14 -30
  3. package/asur/index.js +1 -1
  4. package/compiler/2c.js +172 -59
  5. package/compiler/allocators.js +128 -0
  6. package/compiler/assemble.js +37 -5
  7. package/compiler/builtins/annexb_string.ts +1 -0
  8. package/compiler/builtins/array.ts +154 -7
  9. package/compiler/builtins/base64.ts +1 -0
  10. package/compiler/builtins/boolean.ts +3 -1
  11. package/compiler/builtins/console.ts +6 -0
  12. package/compiler/builtins/crypto.ts +1 -0
  13. package/compiler/builtins/date.ts +5 -30
  14. package/compiler/builtins/error.js +22 -0
  15. package/compiler/builtins/escape.ts +1 -2
  16. package/compiler/builtins/function.ts +2 -0
  17. package/compiler/builtins/int.ts +2 -0
  18. package/compiler/builtins/math.ts +410 -0
  19. package/compiler/builtins/number.ts +12 -21
  20. package/compiler/builtins/object.ts +2 -0
  21. package/compiler/builtins/porffor.d.ts +18 -0
  22. package/compiler/builtins/set.ts +22 -12
  23. package/compiler/builtins/string.ts +1 -0
  24. package/compiler/builtins/string_f64.ts +10 -0
  25. package/compiler/builtins/symbol.ts +62 -0
  26. package/compiler/builtins/z_ecma262.ts +62 -0
  27. package/compiler/builtins.js +50 -12
  28. package/compiler/codegen.js +826 -552
  29. package/compiler/cyclone.js +535 -0
  30. package/compiler/decompile.js +7 -1
  31. package/compiler/generated_builtins.js +635 -84
  32. package/compiler/havoc.js +93 -0
  33. package/compiler/index.js +108 -15
  34. package/compiler/opt.js +10 -44
  35. package/compiler/parse.js +3 -9
  36. package/compiler/pgo.js +212 -0
  37. package/compiler/precompile.js +17 -11
  38. package/compiler/prefs.js +13 -5
  39. package/compiler/prototype.js +200 -186
  40. package/compiler/wasmSpec.js +2 -2
  41. package/compiler/wrap.js +128 -44
  42. package/package.json +3 -5
  43. package/runner/index.js +31 -15
  44. package/runner/repl.js +18 -2
  45. /package/runner/{profiler.js → profile.js} +0 -0
@@ -18,15 +18,15 @@ const compile = async (file, [ _funcs, _globals ]) => {
18
18
  first = source.slice(0, source.indexOf('\n'));
19
19
  }
20
20
 
21
- let args = ['--bytestring', '--todo-time=compile', '--no-aot-pointer-opt', '--no-treeshake-wasm-imports', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--parse-types', '--opt-types'];
21
+ let args = ['--bytestring', '--todo-time=compile', '--truthy=no_nan_negative', '--no-treeshake-wasm-imports', '--no-rm-unused-types', '--scoped-page-names', '--funsafe-no-unlikely-proto-checks', '--fast-length', '--parse-types', '--opt-types'];
22
22
  if (first.startsWith('// @porf')) {
23
- args = args.concat(first.slice('// @porf '.length).split(' '));
23
+ args = first.slice('// @porf '.length).split(' ').concat(args);
24
24
  }
25
25
  process.argv = argv.concat(args);
26
26
 
27
27
  const porfCompile = (await import(`./index.js?_=${Date.now()}`)).default;
28
28
 
29
- let { funcs, globals, data, exceptions } = porfCompile(source, ['module']);
29
+ let { funcs, globals, data, exceptions } = porfCompile(source, ['module', 'typed']);
30
30
 
31
31
  const allocated = new Set();
32
32
 
@@ -35,14 +35,17 @@ const compile = async (file, [ _funcs, _globals ]) => {
35
35
  if (x.data) {
36
36
  x.data = x.data.map(x => data[x]);
37
37
  for (const y in x.data) {
38
- x.data[y].offset -= x.data[0].offset;
38
+ if (x.data[y].offset != null) x.data[y].offset -= x.data[0].offset;
39
39
  }
40
40
  }
41
- if (x.exceptions) x.exceptions = x.exceptions.map(x => {
42
- const obj = exceptions[x];
43
- if (obj) obj.exceptId = x;
44
- return obj;
45
- }).filter(x => x);
41
+
42
+ if (x.exceptions) {
43
+ x.exceptions = x.exceptions.map(x => {
44
+ const obj = exceptions[x];
45
+ if (obj) obj.exceptId = x;
46
+ return obj;
47
+ }).filter(x => x);
48
+ }
46
49
 
47
50
  const locals = Object.keys(x.locals).reduce((acc, y) => {
48
51
  acc[x.locals[y].idx] = { ...x.locals[y], name: y };
@@ -87,6 +90,8 @@ const compile = async (file, [ _funcs, _globals ]) => {
87
90
  };
88
91
 
89
92
  const precompile = async () => {
93
+ if (globalThis._porf_loadParser) await globalThis._porf_loadParser('@babel/parser');
94
+
90
95
  const dir = join(__dirname, 'builtins');
91
96
 
92
97
  let funcs = [], globals = [];
@@ -111,8 +116,9 @@ ${funcs.map(x => {
111
116
  ${x.returnType != null ? `returnType: ${JSON.stringify(x.returnType)}` : 'typedReturns: true'},
112
117
  locals: ${JSON.stringify(Object.values(x.locals).slice(x.params.length).map(x => x.type))},
113
118
  localNames: ${JSON.stringify(Object.keys(x.locals))},
114
- ${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)}` : ''}
115
- };`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n')
119
+ ${x.data && x.data.length > 0 ? ` data: ${JSON.stringify(x.data)},` : ''}
120
+ ${x.table ? ` table: true` : ''}
121
+ };`.replaceAll('\n\n', '\n').replaceAll('\n\n', '\n').replaceAll('\n\n', '\n');
116
122
  }).join('\n')}
117
123
  };`;
118
124
  };
package/compiler/prefs.js CHANGED
@@ -1,12 +1,11 @@
1
- const onByDefault = [ 'bytestring', 'aotPointerOpt', 'treeshakeWasmImports', 'alwaysMemory' ];
1
+ const onByDefault = [ 'bytestring', 'treeshakeWasmImports', 'alwaysMemory', 'indirectCalls', 'optUnused', 'data', 'rmUnusedTypes' ];
2
2
 
3
3
  let cache = {};
4
4
  const obj = new Proxy({}, {
5
5
  get(_, p) {
6
- // intentionally misses with undefined values cached
7
- if (cache[p]) return cache[p];
6
+ if (cache[p] != null) return cache[p];
8
7
 
9
- return cache[p] = (() => {
8
+ const ret = (() => {
10
9
  // fooBar -> foo-bar
11
10
  const name = p[0] === '_' ? p : p.replace(/[A-Z]/g, c => `-${c.toLowerCase()}`);
12
11
  const prefix = name.length === 1 ? '-' : '--';
@@ -19,9 +18,18 @@ const obj = new Proxy({}, {
19
18
  if (onByDefault.includes(p)) return true;
20
19
  return undefined;
21
20
  })();
21
+
22
+ // do not cache in web demo as args are changed live
23
+ if (!globalThis.document) cache[p] = ret;
24
+ return ret;
25
+ },
26
+
27
+ set(_, p, v) {
28
+ cache[p] = v;
29
+ return true;
22
30
  }
23
31
  });
24
32
 
25
- obj.uncache = () => cache = {};
33
+ export const uncache = () => cache = {};
26
34
 
27
35
  export default obj;