porffor 0.14.0-f67c123a1 → 0.16.0-0c4120280

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 (43) hide show
  1. package/CONTRIBUTING.md +15 -9
  2. package/README.md +9 -13
  3. package/asur/index.js +1 -1
  4. package/compiler/2c.js +104 -51
  5. package/compiler/assemble.js +30 -4
  6. package/compiler/builtins/annexb_string.ts +1 -0
  7. package/compiler/builtins/array.ts +84 -4
  8. package/compiler/builtins/base64.ts +1 -0
  9. package/compiler/builtins/boolean.ts +3 -1
  10. package/compiler/builtins/console.ts +6 -0
  11. package/compiler/builtins/crypto.ts +1 -0
  12. package/compiler/builtins/date.ts +2 -0
  13. package/compiler/builtins/error.js +22 -0
  14. package/compiler/builtins/escape.ts +1 -2
  15. package/compiler/builtins/function.ts +2 -0
  16. package/compiler/builtins/int.ts +2 -0
  17. package/compiler/builtins/math.ts +410 -0
  18. package/compiler/builtins/number.ts +2 -0
  19. package/compiler/builtins/object.ts +2 -0
  20. package/compiler/builtins/porffor.d.ts +11 -0
  21. package/compiler/builtins/set.ts +20 -7
  22. package/compiler/builtins/string.ts +1 -0
  23. package/compiler/builtins/symbol.ts +62 -0
  24. package/compiler/builtins.js +50 -12
  25. package/compiler/codegen.js +579 -279
  26. package/compiler/cyclone.js +535 -0
  27. package/compiler/decompile.js +7 -1
  28. package/compiler/generated_builtins.js +555 -60
  29. package/compiler/havoc.js +93 -0
  30. package/compiler/index.js +93 -14
  31. package/compiler/opt.js +3 -39
  32. package/compiler/parse.js +2 -2
  33. package/compiler/pgo.js +207 -0
  34. package/compiler/precompile.js +5 -4
  35. package/compiler/prefs.js +12 -3
  36. package/compiler/prototype.js +180 -157
  37. package/compiler/wrap.js +127 -44
  38. package/no_pgo.txt +923 -0
  39. package/package.json +2 -2
  40. package/pgo.txt +916 -0
  41. package/runner/index.js +18 -12
  42. package/runner/repl.js +18 -2
  43. /package/runner/{profiler.js → profile.js} +0 -0
package/runner/index.js CHANGED
@@ -25,7 +25,7 @@ if (process.argv.includes('--help')) {
25
25
  console.log(`Usage: \x1B[1mporf [command] path/to/script.js [...prefs] [...args]\x1B[0m`);
26
26
 
27
27
  // commands
28
- console.log(`\n\u001b[4mCommands\x1B[0m`);
28
+ console.log(`\n\x1B[1mCommands:\x1B[0m`);
29
29
  for (const [ cmd, [ color, desc ] ] of Object.entries({
30
30
  run: [ 34, 'Run a JS file' ],
31
31
  wasm: [ 34, 'Compile a JS file to a Wasm binary\n' ],
@@ -60,9 +60,16 @@ if (process.argv.includes('--help')) {
60
60
 
61
61
  let file = process.argv.slice(2).find(x => x[0] !== '-');
62
62
  if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(file)) {
63
+ // remove this arg
64
+ process.argv.splice(process.argv.indexOf(file), 1);
65
+
63
66
  if (file === 'profile') {
64
- process.argv.splice(process.argv.indexOf(file), 1);
65
- await import('./profiler.js');
67
+ await import('./profile.js');
68
+ await new Promise(() => {}); // do nothing for the rest of this file
69
+ }
70
+
71
+ if (file === 'debug') {
72
+ await import('./debug.js');
66
73
  await new Promise(() => {}); // do nothing for the rest of this file
67
74
  }
68
75
 
@@ -74,13 +81,7 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
74
81
  process.argv.push('--asur', '--wasm-debug');
75
82
  }
76
83
 
77
- if (file === 'debug') {
78
- process.argv.splice(process.argv.indexOf(file), 1);
79
- await import('./debug.js');
80
- await new Promise(() => {}); // do nothing for the rest of this file
81
- }
82
-
83
- file = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
84
+ file = process.argv.slice(2).find(x => x[0] !== '-');
84
85
 
85
86
  const nonOptOutFile = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
86
87
  if (nonOptOutFile) {
@@ -88,6 +89,8 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
88
89
  }
89
90
  }
90
91
 
92
+ globalThis.file = file;
93
+
91
94
  if (!file) {
92
95
  if (process.argv.includes('-v') || process.argv.includes('--version')) {
93
96
  // just print version
@@ -114,17 +117,20 @@ const print = str => {
114
117
  process.stdout.write(str);
115
118
  };
116
119
 
120
+ let runStart;
117
121
  try {
118
122
  if (process.argv.includes('-b')) {
119
123
  const { wasm, exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
120
124
 
125
+ runStart = performance.now();
121
126
  if (!process.argv.includes('--no-run')) exports.main();
122
127
 
123
128
  console.log(`\n\nwasm size: ${wasm.byteLength} bytes`);
124
129
  } else {
125
130
  const { exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
126
131
 
127
- if (!process.argv.includes('-no-run')) exports.main();
132
+ runStart = performance.now();
133
+ if (!process.argv.includes('--no-run')) exports.main();
128
134
  }
129
135
  // if (cache) process.stdout.write(cache);
130
136
  } catch (e) {
@@ -132,4 +138,4 @@ try {
132
138
  console.error(process.argv.includes('-i') ? e : `${e.constructor.name}: ${e.message}`);
133
139
  }
134
140
 
135
- if (process.argv.includes('-t')) console.log(`${process.argv.includes('-b') ? '' : '\n\n'}total time: ${(performance.now() - start).toFixed(2)}ms`);
141
+ if (process.argv.includes('-t')) console.log(`${process.argv.includes('-b') ? '' : '\n\n'}total time: ${(performance.now() - start).toFixed(2)}ms\nexecution time: ${(performance.now() - runStart).toFixed(2)}ms`);
package/runner/repl.js CHANGED
@@ -1,6 +1,11 @@
1
+ import { TYPE_NAMES } from '../compiler/types.js';
1
2
  import compile from '../compiler/wrap.js';
2
3
  import version from './version.js';
3
4
 
5
+ import util from 'node:util';
6
+
7
+ process.argv.push('--no-opt-unused');
8
+
4
9
  let repl;
5
10
  try {
6
11
  // try importing node:repl
@@ -86,10 +91,21 @@ const run = async (source, _context, _filename, callback, run = true) => {
86
91
  lastPages = [...pages.keys()];
87
92
  }
88
93
 
89
- const ret = run ? exports.main() : undefined;
90
- callback(null, ret);
94
+ let ret = run ? exports.main() : undefined;
95
+ let value, type;
96
+ if (ret?.type != null) {
97
+ value = ret.value;
98
+ type = ret.type;
99
+ ret = ret.js;
100
+ }
101
+
102
+ console.log(util.inspect(ret, false, 2, true), (value != null ? `\x1B[34m\x1B[3m(value: ${value}, type: ${TYPE_NAMES[type]})\x1B[0m` : ''));
103
+
104
+ // callback(null, ret);
91
105
 
92
106
  prev = prev + ';\n' + source.trim();
107
+
108
+ callback();
93
109
  };
94
110
 
95
111
  const replServer = repl.start({ prompt: '> ', eval: run });
File without changes