porffor 0.16.0-a2e115b05 → 0.16.0-a7bc359af

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/runner/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  #!/usr/bin/env node
2
-
3
- import compile from '../compiler/wrap.js';
4
2
  import fs from 'node:fs';
5
3
 
6
4
  const start = performance.now();
@@ -59,12 +57,22 @@ if (process.argv.includes('--help')) {
59
57
  }
60
58
 
61
59
  let file = process.argv.slice(2).find(x => x[0] !== '-');
62
- if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(file)) {
60
+ if (['precompile', 'run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(file)) {
63
61
  // remove this arg
64
62
  process.argv.splice(process.argv.indexOf(file), 1);
65
63
 
64
+ if (file === 'precompile') {
65
+ await import('../compiler/precompile.js');
66
+ await new Promise(() => {}); // do nothing for the rest of this file
67
+ }
68
+
66
69
  if (file === 'profile') {
67
- await import('./profiler.js');
70
+ await import('./profile.js');
71
+ await new Promise(() => {}); // do nothing for the rest of this file
72
+ }
73
+
74
+ if (file === 'debug') {
75
+ await import('./debug.js');
68
76
  await new Promise(() => {}); // do nothing for the rest of this file
69
77
  }
70
78
 
@@ -76,11 +84,6 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
76
84
  process.argv.push('--asur', '--wasm-debug');
77
85
  }
78
86
 
79
- if (file === 'debug') {
80
- await import('./debug.js');
81
- await new Promise(() => {}); // do nothing for the rest of this file
82
- }
83
-
84
87
  file = process.argv.slice(2).find(x => x[0] !== '-');
85
88
 
86
89
  const nonOptOutFile = process.argv.slice(process.argv.indexOf(file) + 1).find(x => x[0] !== '-');
@@ -89,6 +92,8 @@ if (['run', 'wasm', 'native', 'c', 'profile', 'debug', 'debug-wasm'].includes(fi
89
92
  }
90
93
  }
91
94
 
95
+ globalThis.file = file;
96
+
92
97
  if (!file) {
93
98
  if (process.argv.includes('-v') || process.argv.includes('--version')) {
94
99
  // just print version
@@ -103,6 +108,8 @@ if (!file) {
103
108
 
104
109
  const source = fs.readFileSync(file, 'utf8');
105
110
 
111
+ const compile = (await import('../compiler/wrap.js')).default;
112
+
106
113
  let cache = '';
107
114
  const print = str => {
108
115
  /* cache += str;
@@ -115,17 +122,20 @@ const print = str => {
115
122
  process.stdout.write(str);
116
123
  };
117
124
 
125
+ let runStart;
118
126
  try {
119
127
  if (process.argv.includes('-b')) {
120
128
  const { wasm, exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
121
129
 
130
+ runStart = performance.now();
122
131
  if (!process.argv.includes('--no-run')) exports.main();
123
132
 
124
133
  console.log(`\n\nwasm size: ${wasm.byteLength} bytes`);
125
134
  } else {
126
135
  const { exports } = await compile(source, process.argv.includes('--module') ? [ 'module' ] : [], {}, print);
127
136
 
128
- if (!process.argv.includes('-no-run')) exports.main();
137
+ runStart = performance.now();
138
+ if (!process.argv.includes('--no-run')) exports.main();
129
139
  }
130
140
  // if (cache) process.stdout.write(cache);
131
141
  } catch (e) {
@@ -133,4 +143,4 @@ try {
133
143
  console.error(process.argv.includes('-i') ? e : `${e.constructor.name}: ${e.message}`);
134
144
  }
135
145
 
136
- if (process.argv.includes('-t')) console.log(`${process.argv.includes('-b') ? '' : '\n\n'}total time: ${(performance.now() - start).toFixed(2)}ms`);
146
+ 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`);
File without changes