porffor 0.2.0-b9abe0d → 0.2.0-bae0c5b

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/README.md CHANGED
@@ -14,60 +14,75 @@ Porffor is primarily built from scratch, the only thing that is not is the parse
14
14
  Expect nothing to work! Only very limited JS is currently supported. See files in `bench` for examples.
15
15
 
16
16
  ### Setup
17
- 1. Clone this repo (`git clone https://github.com/CanadaHonk/porffor.git`)
18
- 2. `npm install` - for parser(s)
17
+ **`npm install -g porffor`**. It's that easy (hopefully) :)
19
18
 
20
- ### Running a file
21
- The repos comes with easy alias files for Unix and Windows, which you can use like so:
22
- - Unix: `./porf path/to/script.js`
23
- - Windows: `.\porf path/to/script.js`
19
+ ### Trying a REPL
20
+ **`porf`**. Just run it with no script file argument.
24
21
 
25
- Please note that further examples below will just use `./porf`, you need to use `.\porf` on Windows. You can also swap out `node` in the alias to use another runtime like Deno (`deno run -A`) or Bun (`bun ...`), or just use it yourself (eg `node runner/index.js ...`, `bun runner/index.js ...`). Node and Bun should work great, Deno support is WIP.
22
+ ### Running a JS file
23
+ **`porf path/to/script.js`**
26
24
 
27
- ### Trying a REPL
28
- **`./porf`**. Just run it with no script file argument.
25
+ ### Compiling to Wasm
26
+ **`porf wasm path/to/script.js out.wasm`**. Currently it does not use an import standard like WASI, so it is mostly unusable on its own.
29
27
 
30
28
  ### Compiling to native binaries
31
29
  > [!WARNING]
32
30
  > Compiling to native binaries uses [2c](#2c), Porffor's own Wasm -> C compiler, which is experimental.
33
31
 
34
- **`./porf native path/to/script.js out(.exe)`**. You can specify the compiler with `-compiler=clang/zig/gcc`, and which opt level to use with `-cO=O3` (`Ofast` by default). Output binaries are also stripped by default.
32
+ **`porf native path/to/script.js out(.exe)`**. You can specify the compiler with `--compiler=clang/zig/gcc`, and which opt level to use with `--cO=O3` (`Ofast` by default). Output binaries are also stripped by default.
35
33
 
36
34
  ### Compiling to C
37
35
  > [!WARNING]
38
36
  > Compiling to C uses [2c](#2c), Porffor's own Wasm -> C compiler, which is experimental.
39
37
 
40
- **`./porf c path/to/script.js (out.c)`**. When not including an output file, it will be printed to stdout instead.
38
+ **`porf c path/to/script.js (out.c)`**. When not including an output file, it will be printed to stdout instead.
39
+
40
+ ### Profiling a JS file
41
+ > [!WARNING]
42
+ > Very experimental WIP feature!
43
+
44
+ **`porf profile path/to/script.js`**
45
+
46
+ ### Debugging a JS file
47
+ > [!WARNING]
48
+ > Very experimental WIP feature!
49
+
50
+ **`porf debug path/to/script.js`**
51
+
52
+ ### Profiling the generated Wasm of a JS file
53
+ > [!WARNING]
54
+ > Very experimental WIP feature!
55
+
56
+ **`porf debug-wasm path/to/script.js`**
41
57
 
42
- ### Compiling to a Wasm binary
43
- **`./porf compile path/to/script.js out.wasm`**. Currently it does not use an import standard like WASI, so it is mostly unusable.
44
58
 
45
59
  ### Options
46
- - `-target=wasm|c|native` (default: `wasm`) to set target output (native compiles c output to binary, see args below)
47
- - `-target=c|native` only:
48
- - `-o=out.c|out.exe|out` to set file to output c or binary
49
- - `-target=native` only:
50
- - `-compiler=clang` to set compiler binary (path/name) to use to compile
51
- - `-cO=O3` to set compiler opt argument
52
- - `-parser=acorn|@babel/parser|meriyah|hermes-parser` (default: `acorn`) to set which parser to use
53
- - `-parse-types` to enable parsing type annotations/typescript. if `-parser` is unset, changes default to `@babel/parser`. does not type check
54
- - `-opt-types` to perform optimizations using type annotations as compiler hints. does not type check
55
- - `-valtype=i32|i64|f64` (default: `f64`) to set valtype
60
+ - `--parser=acorn|@babel/parser|meriyah|hermes-parser` (default: `acorn`) to set which parser to use
61
+ - `--parse-types` to enable parsing type annotations/typescript. if `-parser` is unset, changes default to `@babel/parser`. does not type check
62
+ - `--opt-types` to perform optimizations using type annotations as compiler hints. does not type check
63
+ - `--valtype=i32|i64|f64` (default: `f64`) to set valtype
56
64
  - `-O0` to disable opt
57
65
  - `-O1` (default) to enable basic opt (simplify insts, treeshake wasm imports)
58
66
  - `-O2` to enable advanced opt (inlining). unstable
59
67
  - `-O3` to enable advanceder opt (precompute const math). unstable
60
- - `-no-run` to not run wasm output, just compile
61
- - `-opt-log` to log some opts
62
- - `-code-log` to log some codegen (you probably want `-funcs`)
63
- - `-regex-log` to log some regex
64
- - `-funcs` to log funcs
65
- - `-ast-log` to log AST
66
- - `-opt-funcs` to log funcs after opt
67
- - `-sections` to log sections as hex
68
- - `-opt-no-inline` to not inline any funcs
69
- - `-tail-call` to enable tail calls (experimental + not widely implemented)
70
- - `-compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
68
+ - `--no-run` to not run wasm output, just compile
69
+ - `--opt-log` to log some opts
70
+ - `--code-log` to log some codegen (you probably want `-funcs`)
71
+ - `--regex-log` to log some regex
72
+ - `--funcs` to log funcs
73
+ - `--ast-log` to log AST
74
+ - `--opt-funcs` to log funcs after opt
75
+ - `--sections` to log sections as hex
76
+ - `--opt-no-inline` to not inline any funcs
77
+ - `--tail-call` to enable tail calls (experimental + not widely implemented)
78
+ - `--compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
79
+
80
+ ### Running in the repo
81
+ The repo comes with easy alias files for Unix and Windows, which you can use like so:
82
+ - Unix: `./porf path/to/script.js`
83
+ - Windows: `.\porf path/to/script.js`
84
+
85
+ Please note that further examples below will just use `./porf`, you need to use `.\porf` on Windows. You can also swap out `node` in the alias to use another runtime like Deno (`deno run -A`) or Bun (`bun ...`), or just use it yourself (eg `node runner/index.js ...`, `bun runner/index.js ...`). Node and Bun should work great, Deno support is WIP.
71
86
 
72
87
  ## Limitations
73
88
  - No full object support yet
@@ -151,23 +166,28 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
151
166
  - Array member setting (`arr[0] = 2`, `arr[0] += 2`, etc)
152
167
  - Array constructor (`Array(5)`, `new Array(1, 2, 3)`)
153
168
  - Labelled statements (`foo: while (...)`)
169
+ - `do...while` loops
154
170
 
155
171
  ### Built-ins
156
172
 
157
- - `NaN` and `Infinity` (f64 only)
158
- - `isNaN()` and `isFinite()` (f64 only)
159
- - Most of `Number` (`MAX_VALUE`, `MIN_VALUE`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY`, `EPSILON`, `NaN`, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`) (some f64 only)
160
- - Some `Math` funcs (`sqrt`, `abs`, `floor`, `sign`, `round`, `trunc`, `clz32`, `fround`, `random`) (f64 only)
173
+ - `NaN` and `Infinity`
174
+ - `isNaN()` and `isFinite()`
175
+ - Most of `Number` (`MAX_VALUE`, `MIN_VALUE`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY`, `EPSILON`, `NaN`, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`)
176
+ - Some `Math` funcs (`sqrt`, `abs`, `floor`, `sign`, `round`, `trunc`, `clz32`, `fround`, `random`)
161
177
  - Basic `globalThis` support
162
178
  - Basic `Boolean` and `Number`
163
179
  - Basic `eval` for literals
164
180
  - `Math.random()` using self-made xorshift128+ PRNG
165
- - Some of `performance` (`now()`)
166
- - Some of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`)
181
+ - Some of `performance` (`now()`, `timeOrigin`)
182
+ - Some of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`, `slice`, `indexOf`, `lastIndexOf`, `includes`, `with`, `reverse`, `toReversed`)
167
183
  - Some of `Array` (`of`, `isArray`)
168
- - Some of `String.prototype` (`at`, `charAt`, `charCodeAt`)
184
+ - Most of `String.prototype` (`at`, `charAt`, `charCodeAt`, `toUpperCase`, `toLowerCase`, `startsWith`, `endsWith`, `indexOf`, `lastIndexOf`, `includes`, `padStart`, `padEnd`, `substring`, `substr`, `slice`, `trimStart`, `trimEnd`, `trim`, `toString`, `big`, `blink`, `bold`, `fixed`, `italics`, `small`, `strike`, `sub`, `sup`, `trimLeft`, `trimRight`, )
169
185
  - Some of `crypto` (`randomUUID`)
170
186
  - `escape`
187
+ - `btoa`
188
+ - Most of `Number.prototype` (`toString`, `toFixed`, `toExponential`)
189
+ - `parseInt`
190
+ - Spec-compliant `Date`
171
191
 
172
192
  ### Custom
173
193
 
@@ -185,7 +205,7 @@ Mostly for reducing size. I do not really care about compiler perf/time as long
185
205
  ### Traditional opts
186
206
  - Inlining functions (WIP, limited)
187
207
  - Inline const math ops
188
- - Tail calls (behind flag `-tail-call`)
208
+ - Tail calls (behind flag `--tail-call`)
189
209
 
190
210
  ### Wasm transforms
191
211
  - `local.set`, `local.get` -> `local.tee`
@@ -271,8 +291,6 @@ No particular order and no guarentees, just what could happen soon™
271
291
  - Run precompiled Wasm file if given
272
292
  - Docs
273
293
  - Update codebase readme section
274
- - REPL
275
- - Basic polyfill of `node:repl` for non-Node runtimes to work
276
294
  - Cool proposals
277
295
  - [Optional Chaining Assignment](https://github.com/tc39/proposal-optional-chaining-assignment)
278
296
  - [Modulus and Additional Integer Math](https://github.com/tc39/proposal-integer-and-modulus-math)
@@ -292,6 +310,15 @@ No particular order and no guarentees, just what could happen soon™
292
310
  ## VSCode extension
293
311
  There is a vscode extension in `vscode-ext` which tweaks JS syntax highlighting to be nicer with porffor features (eg highlighting wasm inside of inline asm).
294
312
 
313
+ ## Wasm proposals used
314
+ Porffor intentionally does not use Wasm proposals which are not commonly implemented yet (eg GC) so it can be used in as many places as possible.
315
+
316
+ - Multi-value **(required)**
317
+ - Non-trapping float-to-int conversions **(required)**
318
+ - Bulk memory operations (required, but uncommonly used)
319
+ - Exception handling (optional, for errors)
320
+ - Tail calls (opt-in, off by default)
321
+
295
322
  ## Isn't this the same as AssemblyScript/other Wasm langs?
296
323
  No. they are not alike at all internally and have very different goals/ideals:
297
324
  - Porffor is made as a generic JS engine, not for Wasm stuff specifically
package/asur/index.js CHANGED
@@ -1244,7 +1244,7 @@ paused = _paused;`);
1244
1244
  });
1245
1245
 
1246
1246
  export const instantiate = async (binary, importImpls) => {
1247
- const _vm = process?.argv?.includes('-wasm-debug') ? await wasmDebugVm() : vm;
1247
+ const _vm = process?.argv?.includes('--wasm-debug') ? await wasmDebugVm() : vm;
1248
1248
 
1249
1249
  const parsed = parse(binary);
1250
1250
  const exports = {};
@@ -154,7 +154,7 @@ export default (funcs, globals, tags, pages, data, flags) => {
154
154
 
155
155
  const exports = funcs.filter(x => x.export).map((x, i) => [ ...encodeString(x.name === 'main' ? 'm' : x.name), ExportDesc.func, x.index ]);
156
156
 
157
- if (Prefs.alwaysMemory && pages.size === 0) pages.set('-always-memory', 0);
157
+ if (Prefs.alwaysMemory && pages.size === 0) pages.set('--always-memory', 0);
158
158
  if (optLevel === 0) pages.set('O0 precaution', 0);
159
159
 
160
160
  const usesMemory = pages.size > 0;