porffor 0.2.0-dcc06c8 → 0.2.0-de394c3
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/LICENSE +20 -20
- package/README.md +113 -62
- package/asur/README.md +2 -0
- package/asur/index.js +1262 -0
- package/byg/index.js +237 -0
- package/compiler/2c.js +1 -1
- package/compiler/{sections.js → assemble.js} +58 -11
- package/compiler/builtins/annexb_string.js +72 -0
- package/compiler/builtins/annexb_string.ts +19 -0
- package/compiler/builtins/array.ts +145 -0
- package/compiler/builtins/base64.ts +103 -40
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +1370 -0
- package/compiler/builtins/escape.ts +141 -0
- package/compiler/builtins/int.ts +147 -0
- package/compiler/builtins/number.ts +527 -0
- package/compiler/builtins/porffor.d.ts +33 -1
- package/compiler/builtins/string.ts +1055 -0
- package/compiler/builtins/tostring.ts +45 -0
- package/compiler/builtins.js +454 -243
- package/compiler/{codeGen.js → codegen.js} +833 -290
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +1259 -0
- package/compiler/index.js +16 -14
- package/compiler/log.js +6 -3
- package/compiler/opt.js +23 -22
- package/compiler/parse.js +31 -25
- package/compiler/precompile.js +66 -22
- package/compiler/prefs.js +5 -1
- package/compiler/prototype.js +4 -20
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +28 -8
- package/compiler/wrap.js +51 -47
- package/fib.js +7 -0
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +3 -2
- package/rhemyn/parse.js +323 -320
- package/rhemyn/test/parse.js +58 -58
- package/runner/compare.js +34 -34
- package/runner/debug.js +122 -0
- package/runner/index.js +48 -9
- package/runner/profiler.js +102 -0
- package/runner/repl.js +40 -7
- package/runner/sizes.js +37 -37
- package/demo.js +0 -3
- package/demo.ts +0 -1
- package/filesize.cmd +0 -2
- package/hello +0 -0
- package/runner/info.js +0 -89
- package/runner/profile.js +0 -46
- package/runner/results.json +0 -1
- package/runner/transform.js +0 -15
- package/tmp.c +0 -152
- package/util/enum.js +0 -20
package/LICENSE
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2023 CanadaHonk
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 CanadaHonk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
21
|
SOFTWARE.
|
package/README.md
CHANGED
@@ -14,33 +14,47 @@ 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
|
-
|
18
|
-
2. `npm install` - for parser(s)
|
17
|
+
**`npm install -g porffor`**. It's that easy (hopefully) :)
|
19
18
|
|
20
|
-
###
|
21
|
-
|
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
|
-
|
22
|
+
### Running a JS file
|
23
|
+
**`porf path/to/script.js`**
|
26
24
|
|
27
|
-
###
|
28
|
-
|
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
|
-
|
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
|
-
|
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
60
|
- `-target=wasm|c|native` (default: `wasm`) to set target output (native compiles c output to binary, see args below)
|
@@ -69,6 +83,13 @@ Please note that further examples below will just use `./porf`, you need to use
|
|
69
83
|
- `-tail-call` to enable tail calls (experimental + not widely implemented)
|
70
84
|
- `-compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
|
71
85
|
|
86
|
+
### Running in the repo
|
87
|
+
The repo comes with easy alias files for Unix and Windows, which you can use like so:
|
88
|
+
- Unix: `./porf path/to/script.js`
|
89
|
+
- Windows: `.\porf path/to/script.js`
|
90
|
+
|
91
|
+
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.
|
92
|
+
|
72
93
|
## Limitations
|
73
94
|
- No full object support yet
|
74
95
|
- Little built-ins/prototype
|
@@ -77,10 +98,15 @@ Please note that further examples below will just use `./porf`, you need to use
|
|
77
98
|
- Literal callees only in calls (eg `print()` works, `a = print; a()` does not)
|
78
99
|
- No `eval()` etc (since it is AOT)
|
79
100
|
|
80
|
-
##
|
101
|
+
## Sub-engines
|
102
|
+
|
103
|
+
### Asur
|
104
|
+
Asur is Porffor's own Wasm engine; it is an intentionally simple interpreter written in JS. It is very WIP. See [its readme](asur/README.md) for more details.
|
105
|
+
|
106
|
+
### Rhemyn
|
81
107
|
Rhemyn is Porffor's own regex engine; it compiles literal regex to Wasm bytecode AOT (remind you of anything?). It is quite basic and WIP. See [its readme](rhemyn/README.md) for more details.
|
82
108
|
|
83
|
-
|
109
|
+
### 2c
|
84
110
|
2c is Porffor's own Wasm -> C compiler, using generated Wasm bytecode and internal info to generate specific and efficient/fast C code. Little boilerplate/preluded code or required external files, just for CLI binaries (not like wasm2c very much).
|
85
111
|
|
86
112
|
## Supported
|
@@ -145,20 +171,29 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
|
|
145
171
|
- `for...of` (arrays and strings)
|
146
172
|
- Array member setting (`arr[0] = 2`, `arr[0] += 2`, etc)
|
147
173
|
- Array constructor (`Array(5)`, `new Array(1, 2, 3)`)
|
174
|
+
- Labelled statements (`foo: while (...)`)
|
175
|
+
- `do...while` loops
|
148
176
|
|
149
177
|
### Built-ins
|
150
178
|
|
151
|
-
- `NaN` and `Infinity`
|
152
|
-
- `isNaN()` and `isFinite()`
|
153
|
-
- Most of `Number` (`MAX_VALUE`, `MIN_VALUE`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY`, `EPSILON`, `NaN`, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`)
|
154
|
-
- Some `Math` funcs (`
|
179
|
+
- `NaN` and `Infinity`
|
180
|
+
- `isNaN()` and `isFinite()`
|
181
|
+
- Most of `Number` (`MAX_VALUE`, `MIN_VALUE`, `MAX_SAFE_INTEGER`, `MIN_SAFE_INTEGER`, `POSITIVE_INFINITY`, `NEGATIVE_INFINITY`, `EPSILON`, `NaN`, `isNaN`, `isFinite`, `isInteger`, `isSafeInteger`)
|
182
|
+
- Some `Math` funcs (`sqrt`, `abs`, `floor`, `sign`, `round`, `trunc`, `clz32`, `fround`, `random`)
|
155
183
|
- Basic `globalThis` support
|
156
184
|
- Basic `Boolean` and `Number`
|
157
185
|
- Basic `eval` for literals
|
158
186
|
- `Math.random()` using self-made xorshift128+ PRNG
|
159
|
-
- Some of `performance` (`now()`)
|
160
|
-
- Some of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`)
|
161
|
-
- Some of `
|
187
|
+
- Some of `performance` (`now()`, `timeOrigin`)
|
188
|
+
- Some of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`, `slice`, `indexOf`, `lastIndexOf`, `includes`, `with`, `reverse`, `toReversed`)
|
189
|
+
- Some of `Array` (`of`, `isArray`)
|
190
|
+
- 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`, )
|
191
|
+
- Some of `crypto` (`randomUUID`)
|
192
|
+
- `escape`
|
193
|
+
- `btoa`
|
194
|
+
- Most of `Number.prototype` (`toString`, `toFixed`, `toExponential`)
|
195
|
+
- `parseInt`
|
196
|
+
- Spec-compliant `Date`
|
162
197
|
|
163
198
|
### Custom
|
164
199
|
|
@@ -167,44 +202,6 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
|
|
167
202
|
- Intrinsic functions (see below)
|
168
203
|
- Inlining wasm via ``asm`...``\` "macro"
|
169
204
|
|
170
|
-
## Todo
|
171
|
-
No particular order and no guarentees, just what could happen soon™
|
172
|
-
|
173
|
-
- Arrays
|
174
|
-
- More of `Array` prototype
|
175
|
-
- Arrays/strings inside arrays
|
176
|
-
- Destructuring
|
177
|
-
- Objects
|
178
|
-
- Basic object expressions (eg `{}`, `{ a: 0 }`)
|
179
|
-
- Wasm
|
180
|
-
- *Basic* Wasm engine (interpreter) in JS
|
181
|
-
- More math operators (`**`, etc)
|
182
|
-
- `do { ... } while (...)`
|
183
|
-
- Typed export inputs (array)
|
184
|
-
- Exceptions
|
185
|
-
- Rewrite to use actual strings (optional?)
|
186
|
-
- `try { } finally { }`
|
187
|
-
- Rethrowing inside catch
|
188
|
-
- Optimizations
|
189
|
-
- Rewrite local indexes per func for smallest local header and remove unused idxs
|
190
|
-
- Smarter inline selection (snapshots?)
|
191
|
-
- Remove const ifs (`if (true)`, etc)
|
192
|
-
- Memory alignment
|
193
|
-
- Runtime
|
194
|
-
- WASI target
|
195
|
-
- Run precompiled Wasm file if given
|
196
|
-
- Cool proposals
|
197
|
-
- [Optional Chaining Assignment](https://github.com/tc39/proposal-optional-chaining-assignment)
|
198
|
-
- [Modulus and Additional Integer Math](https://github.com/tc39/proposal-integer-and-modulus-math)
|
199
|
-
- [Array Equality](https://github.com/tc39/proposal-array-equality)
|
200
|
-
- [Declarations in Conditionals](https://github.com/tc39/proposal-Declarations-in-Conditionals)
|
201
|
-
- [Seeded Pseudo-Random Numbers](https://github.com/tc39/proposal-seeded-random)
|
202
|
-
- [`do` expressions](https://github.com/tc39/proposal-do-expressions)
|
203
|
-
- [String Trim Characters](https://github.com/Kingwl/proposal-string-trim-characters)
|
204
|
-
- Posts
|
205
|
-
- Inlining investigation
|
206
|
-
- Self hosted testing?
|
207
|
-
|
208
205
|
## Performance
|
209
206
|
*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.
|
210
207
|
|
@@ -241,7 +238,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
241
238
|
## Codebase
|
242
239
|
- `compiler`: contains the compiler itself
|
243
240
|
- `builtins.js`: all built-ins of the engine (spec, custom. vars, funcs)
|
244
|
-
- `
|
241
|
+
- `codegen.js`: code (wasm) generation, ast -> wasm. The bulk of the effort
|
245
242
|
- `decompile.js`: basic wasm decompiler for debug info
|
246
243
|
- `embedding.js`: utils for embedding consts
|
247
244
|
- `encoding.js`: utils for encoding things as bytes as wasm expects
|
@@ -249,7 +246,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
249
246
|
- `index.js`: doing all the compiler steps, takes code in, wasm out
|
250
247
|
- `opt.js`: self-made wasm bytecode optimizer
|
251
248
|
- `parse.js`: parser simply wrapping acorn
|
252
|
-
- `
|
249
|
+
- `assemble.js`: assembles wasm ops and metadata into a wasm module/file
|
253
250
|
- `wasmSpec.js`: "enums"/info from wasm spec
|
254
251
|
- `wrap.js`: wrapper for compiler which instantiates and produces nice exports
|
255
252
|
|
@@ -271,9 +268,63 @@ Basically none right now (other than giving people headaches). Potential ideas:
|
|
271
268
|
- Compiling JS to native binaries. This is still very early!
|
272
269
|
- More in future probably?
|
273
270
|
|
271
|
+
## Todo
|
272
|
+
No particular order and no guarentees, just what could happen soon™
|
273
|
+
|
274
|
+
- Arrays
|
275
|
+
- More of `Array` prototype
|
276
|
+
- Arrays/strings inside arrays
|
277
|
+
- Destructuring
|
278
|
+
- Objects
|
279
|
+
- Basic object expressions (eg `{}`, `{ a: 0 }`)
|
280
|
+
- Asur
|
281
|
+
- Support memory
|
282
|
+
- Support exceptions
|
283
|
+
- More math operators (`**`, etc)
|
284
|
+
- Typed export inputs (array)
|
285
|
+
- Exceptions
|
286
|
+
- Rewrite to use actual strings (optional?)
|
287
|
+
- `try { } finally { }`
|
288
|
+
- Rethrowing inside catch
|
289
|
+
- Optimizations
|
290
|
+
- Rewrite local indexes per func for smallest local header and remove unused idxs
|
291
|
+
- Smarter inline selection (snapshots?)
|
292
|
+
- Remove const ifs (`if (true)`, etc)
|
293
|
+
- Memory alignment
|
294
|
+
- Add general pref for always using "fast" (non-short circuiting) or/and
|
295
|
+
- Runtime
|
296
|
+
- WASI target
|
297
|
+
- Run precompiled Wasm file if given
|
298
|
+
- Docs
|
299
|
+
- Update codebase readme section
|
300
|
+
- Cool proposals
|
301
|
+
- [Optional Chaining Assignment](https://github.com/tc39/proposal-optional-chaining-assignment)
|
302
|
+
- [Modulus and Additional Integer Math](https://github.com/tc39/proposal-integer-and-modulus-math)
|
303
|
+
- [Array Equality](https://github.com/tc39/proposal-array-equality)
|
304
|
+
- [Declarations in Conditionals](https://github.com/tc39/proposal-Declarations-in-Conditionals)
|
305
|
+
- [Seeded Pseudo-Random Numbers](https://github.com/tc39/proposal-seeded-random)
|
306
|
+
- [`do` expressions](https://github.com/tc39/proposal-do-expressions)
|
307
|
+
- [String Trim Characters](https://github.com/Kingwl/proposal-string-trim-characters)
|
308
|
+
- Posts
|
309
|
+
- Inlining investigation
|
310
|
+
- JS -> Native
|
311
|
+
- Precompiled TS built-ins
|
312
|
+
- Asur
|
313
|
+
- `escape()` optimization
|
314
|
+
- Self hosted testing?
|
315
|
+
|
274
316
|
## VSCode extension
|
275
317
|
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).
|
276
318
|
|
319
|
+
## Wasm proposals used
|
320
|
+
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.
|
321
|
+
|
322
|
+
- Multi-value **(required)**
|
323
|
+
- Non-trapping float-to-int conversions **(required)**
|
324
|
+
- Bulk memory operations (required, but uncommonly used)
|
325
|
+
- Exception handling (optional, for errors)
|
326
|
+
- Tail calls (opt-in, off by default)
|
327
|
+
|
277
328
|
## Isn't this the same as AssemblyScript/other Wasm langs?
|
278
329
|
No. they are not alike at all internally and have very different goals/ideals:
|
279
330
|
- Porffor is made as a generic JS engine, not for Wasm stuff specifically
|
package/asur/README.md
ADDED