porffor 0.2.0-08a272e → 0.2.0-15592d6

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
@@ -10,6 +10,65 @@ Porffor is a very unique JS engine, due many wildly different approaches. It is
10
10
 
11
11
  Porffor is primarily built from scratch, the only thing that is not is the parser (using [Acorn](https://github.com/acornjs/acorn)). Binaryen/etc is not used, we make final wasm binaries ourself. You could imagine it as compiling a language which is a sub (some things unsupported) and super (new/custom apis) set of javascript. Not based on any particular spec version, focusing on function/working over spec compliance.
12
12
 
13
+ ## Usage
14
+ Expect nothing to work! Only very limited JS is currently supported. See files in `bench` for examples.
15
+
16
+ ### Setup
17
+ 1. Clone this repo (`git clone https://github.com/CanadaHonk/porffor.git`)
18
+ 2. `npm install` - for parser(s)
19
+
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`
24
+
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.
26
+
27
+ ### Trying a REPL
28
+ **`./porf`**. Just run it with no script file argument.
29
+
30
+ ### Compiling to native binaries
31
+ > [!WARNING]
32
+ > Compiling to native binaries uses [2c](#2c), Porffor's own Wasm -> C compiler, which is experimental.
33
+
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.
35
+
36
+ ### Compiling to C
37
+ > [!WARNING]
38
+ > Compiling to C uses [2c](#2c), Porffor's own Wasm -> C compiler, which is experimental.
39
+
40
+ **`./porf c path/to/script.js (out.c)`**. When not including an output file, it will be printed to stdout instead.
41
+
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
+
45
+ ### 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
56
+ - `-O0` to disable opt
57
+ - `-O1` (default) to enable basic opt (simplify insts, treeshake wasm imports)
58
+ - `-O2` to enable advanced opt (inlining). unstable
59
+ - `-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?)
71
+
13
72
  ## Limitations
14
73
  - No full object support yet
15
74
  - Little built-ins/prototype
@@ -121,7 +180,7 @@ No particular order and no guarentees, just what could happen soon™
121
180
  - *Basic* Wasm engine (interpreter) in JS
122
181
  - More math operators (`**`, etc)
123
182
  - `do { ... } while (...)`
124
- - Rewrite `console.log` to work with strings/arrays
183
+ - Typed export inputs (array)
125
184
  - Exceptions
126
185
  - Rewrite to use actual strings (optional?)
127
186
  - `try { } finally { }`
@@ -130,7 +189,10 @@ No particular order and no guarentees, just what could happen soon™
130
189
  - Rewrite local indexes per func for smallest local header and remove unused idxs
131
190
  - Smarter inline selection (snapshots?)
132
191
  - Remove const ifs (`if (true)`, etc)
133
- - Use type(script) information to remove unneeded typechecker code
192
+ - Memory alignment
193
+ - Runtime
194
+ - WASI target
195
+ - Run precompiled Wasm file if given
134
196
  - Cool proposals
135
197
  - [Optional Chaining Assignment](https://github.com/tc39/proposal-optional-chaining-assignment)
136
198
  - [Modulus and Additional Integer Math](https://github.com/tc39/proposal-integer-and-modulus-math)
@@ -139,11 +201,12 @@ No particular order and no guarentees, just what could happen soon™
139
201
  - [Seeded Pseudo-Random Numbers](https://github.com/tc39/proposal-seeded-random)
140
202
  - [`do` expressions](https://github.com/tc39/proposal-do-expressions)
141
203
  - [String Trim Characters](https://github.com/Kingwl/proposal-string-trim-characters)
204
+ - Posts
205
+ - Inlining investigation
206
+ - Self hosted testing?
142
207
 
143
208
  ## Performance
144
- *For the things it supports most of the time*, Porffor is blazingly fast compared to most interpreters, and common engines running without JIT. For those with JIT, it is not that much slower like a traditional interpreter would be; mostly the same or a bit faster/slower depending on what.
145
-
146
- ![Screenshot of comparison chart](https://github.com/CanadaHonk/porffor/assets/19228318/76c75264-cc68-4be1-8891-c06dc389d97a)
209
+ *For the features it supports most of the time*, Porffor is *blazingly fast* compared to most interpreters and common engines running without JIT. For those with JIT, it is usually slower by default, but can catch up with compiler arguments and typed input, even more so when compiling to native binaries.
147
210
 
148
211
  ## Optimizations
149
212
  Mostly for reducing size. I do not really care about compiler perf/time as long as it is reasonable. We do not use/rely on external opt tools (`wasm-opt`, etc), instead doing optimization inside the compiler itself creating even smaller code sizes than `wasm-opt` itself can produce as we have more internal information.
@@ -165,10 +228,12 @@ Mostly for reducing size. I do not really care about compiler perf/time as long
165
228
  - Remove unneeded blocks (no `br`s inside)
166
229
  - Remove unused imports
167
230
  - Use data segments for initing arrays/strings
231
+ - (Likely more not documented yet, todo)
168
232
 
169
233
  ### Wasm module
170
234
  - Type cache/index (no repeated types)
171
235
  - No main func if empty (and other exports)
236
+ - No tags if unused/optimized out
172
237
 
173
238
  ## Test262
174
239
  Porffor can run Test262 via some hacks/transforms which remove unsupported features whilst still doing the same asserts (eg simpler error messages using literals only). It currently passes >10% (see latest commit desc for latest and details). Use `node test262` to test, it will also show a difference of overall results between the last commit and current results.
@@ -201,47 +266,13 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
201
266
  - `test262`: test262 runner and utils
202
267
 
203
268
  ## Usecases
204
- Basically none (other than giving people headaches). Potential ideas to come?
205
-
206
- ## Usage
207
- Basically nothing will work :). See files in `test` for examples.
208
-
209
- 1. Clone repo
210
- 2. `npm install`
211
- 3. `node test` to run tests (some will fail)
212
- 4. `node runner path/to/code.js` to run a file (or `node runner` to use wip repl)
213
-
214
- You can also use Deno (`deno run -A ...` instead of `node ...`), or Bun (`bun ...` instead of `node ...`).
215
-
216
- ### Options
217
- - `-target=wasm|c|native` (default: `wasm`) to set target output (native compiles c output to binary, see args below)
218
- - `-target=c|native` only:
219
- - `-o=out.c|out.exe|out` to set file to output c or binary
220
- - `-target=native` only:
221
- - `-compiler=clang` to set compiler binary (path/name) to use to compile
222
- - `-cO=O3` to set compiler opt argument
223
- - `-parser=acorn|@babel/parser|meriyah|hermes-parser` (default: `acorn`) to set which parser to use
224
- - `-parse-types` to enable parsing type annotations/typescript. if `-parser` is unset, changes default to `@babel/parser`. does not type check
225
- - `-opt-types` to perform optimizations using type annotations as compiler hints. does not type check
226
- - `-valtype=i32|i64|f64` (default: `f64`) to set valtype
227
- - `-O0` to disable opt
228
- - `-O1` (default) to enable basic opt (simplify insts, treeshake wasm imports)
229
- - `-O2` to enable advanced opt (inlining). unstable
230
- - `-O3` to enable advanceder opt (precompute const math). unstable
231
- - `-no-run` to not run wasm output, just compile
232
- - `-opt-log` to log some opts
233
- - `-code-log` to log some codegen (you probably want `-funcs`)
234
- - `-regex-log` to log some regex
235
- - `-funcs` to log funcs
236
- - `-ast-log` to log AST
237
- - `-opt-funcs` to log funcs after opt
238
- - `-sections` to log sections as hex
239
- - `-opt-no-inline` to not inline any funcs
240
- - `-tail-call` to enable tail calls (experimental + not widely implemented)
241
- - `-compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
269
+ Basically none right now (other than giving people headaches). Potential ideas:
270
+ - Safety. As Porffor is written in JS, a memory-safe language\*, and compiles JS to Wasm, a fully sandboxed environment\*, it is quite safe. (\* These rely on the underlying implementations being secure. You could also run Wasm, or even Porffor itself, with an interpreter instead of a JIT for bonus security points too.)
271
+ - Compiling JS to native binaries. This is still very early!
272
+ - More in future probably?
242
273
 
243
274
  ## VSCode extension
244
- There is a vscode extension in `porffor-for-vscode` which tweaks JS syntax highlighting to be nicer with porffor features (eg highlighting wasm inside of inline asm).
275
+ 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).
245
276
 
246
277
  ## Isn't this the same as AssemblyScript/other Wasm langs?
247
278
  No. they are not alike at all internally and have very different goals/ideals: