porffor 0.2.0-c1d7382 → 0.2.0-c1ed50d
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 +64 -45
- 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} +63 -15
- 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 +151 -0
- package/compiler/builtins/crypto.ts +120 -0
- package/compiler/builtins/date.ts +734 -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 +42 -0
- package/compiler/builtins/string.ts +1055 -0
- package/compiler/builtins/tostring.ts +45 -0
- package/compiler/builtins.js +453 -273
- package/compiler/{codeGen.js → codegen.js} +878 -337
- package/compiler/embedding.js +22 -22
- package/compiler/encoding.js +108 -10
- package/compiler/generated_builtins.js +974 -0
- package/compiler/index.js +27 -35
- package/compiler/log.js +6 -3
- package/compiler/opt.js +50 -36
- package/compiler/parse.js +35 -27
- package/compiler/precompile.js +123 -0
- package/compiler/prefs.js +26 -0
- package/compiler/prototype.js +13 -28
- package/compiler/types.js +37 -0
- package/compiler/wasmSpec.js +28 -8
- package/compiler/wrap.js +51 -46
- package/package.json +9 -5
- package/porf +2 -0
- package/rhemyn/compile.js +5 -3
- 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 +35 -9
- package/runner/profiler.js +102 -0
- package/runner/repl.js +40 -7
- package/runner/sizes.js +37 -37
- package/compiler/builtins/base64.js +0 -92
- package/filesize.cmd +0 -2
- 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 -661
- 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
@@ -77,10 +77,15 @@ Please note that further examples below will just use `./porf`, you need to use
|
|
77
77
|
- Literal callees only in calls (eg `print()` works, `a = print; a()` does not)
|
78
78
|
- No `eval()` etc (since it is AOT)
|
79
79
|
|
80
|
-
##
|
80
|
+
## Sub-engines
|
81
|
+
|
82
|
+
### Asur
|
83
|
+
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.
|
84
|
+
|
85
|
+
### Rhemyn
|
81
86
|
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
87
|
|
83
|
-
|
88
|
+
### 2c
|
84
89
|
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
90
|
|
86
91
|
## Supported
|
@@ -145,20 +150,25 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
|
|
145
150
|
- `for...of` (arrays and strings)
|
146
151
|
- Array member setting (`arr[0] = 2`, `arr[0] += 2`, etc)
|
147
152
|
- Array constructor (`Array(5)`, `new Array(1, 2, 3)`)
|
153
|
+
- Labelled statements (`foo: while (...)`)
|
154
|
+
- `do...while`
|
148
155
|
|
149
156
|
### Built-ins
|
150
157
|
|
151
158
|
- `NaN` and `Infinity` (f64 only)
|
152
159
|
- `isNaN()` and `isFinite()` (f64 only)
|
153
160
|
- 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)
|
154
|
-
- Some `Math` funcs (`
|
161
|
+
- Some `Math` funcs (`sqrt`, `abs`, `floor`, `sign`, `round`, `trunc`, `clz32`, `fround`, `random`) (f64 only)
|
155
162
|
- Basic `globalThis` support
|
156
163
|
- Basic `Boolean` and `Number`
|
157
164
|
- Basic `eval` for literals
|
158
165
|
- `Math.random()` using self-made xorshift128+ PRNG
|
159
|
-
- Some of `performance` (`now()`)
|
166
|
+
- Some of `performance` (`now()`, `timeOrigin`)
|
160
167
|
- Some of `Array.prototype` (`at`, `push`, `pop`, `shift`, `fill`)
|
168
|
+
- Some of `Array` (`of`, `isArray`)
|
161
169
|
- Some of `String.prototype` (`at`, `charAt`, `charCodeAt`)
|
170
|
+
- Some of `crypto` (`randomUUID`)
|
171
|
+
- `escape`
|
162
172
|
|
163
173
|
### Custom
|
164
174
|
|
@@ -167,44 +177,6 @@ These include some early (stage 1/0) and/or dead (last commit years ago) proposa
|
|
167
177
|
- Intrinsic functions (see below)
|
168
178
|
- Inlining wasm via ``asm`...``\` "macro"
|
169
179
|
|
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
180
|
## Performance
|
209
181
|
*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
182
|
|
@@ -241,7 +213,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
241
213
|
## Codebase
|
242
214
|
- `compiler`: contains the compiler itself
|
243
215
|
- `builtins.js`: all built-ins of the engine (spec, custom. vars, funcs)
|
244
|
-
- `
|
216
|
+
- `codegen.js`: code (wasm) generation, ast -> wasm. The bulk of the effort
|
245
217
|
- `decompile.js`: basic wasm decompiler for debug info
|
246
218
|
- `embedding.js`: utils for embedding consts
|
247
219
|
- `encoding.js`: utils for encoding things as bytes as wasm expects
|
@@ -249,7 +221,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
249
221
|
- `index.js`: doing all the compiler steps, takes code in, wasm out
|
250
222
|
- `opt.js`: self-made wasm bytecode optimizer
|
251
223
|
- `parse.js`: parser simply wrapping acorn
|
252
|
-
- `
|
224
|
+
- `assemble.js`: assembles wasm ops and metadata into a wasm module/file
|
253
225
|
- `wasmSpec.js`: "enums"/info from wasm spec
|
254
226
|
- `wrap.js`: wrapper for compiler which instantiates and produces nice exports
|
255
227
|
|
@@ -271,8 +243,55 @@ Basically none right now (other than giving people headaches). Potential ideas:
|
|
271
243
|
- Compiling JS to native binaries. This is still very early!
|
272
244
|
- More in future probably?
|
273
245
|
|
246
|
+
## Todo
|
247
|
+
No particular order and no guarentees, just what could happen soon™
|
248
|
+
|
249
|
+
- Arrays
|
250
|
+
- More of `Array` prototype
|
251
|
+
- Arrays/strings inside arrays
|
252
|
+
- Destructuring
|
253
|
+
- Objects
|
254
|
+
- Basic object expressions (eg `{}`, `{ a: 0 }`)
|
255
|
+
- Asur
|
256
|
+
- Support memory
|
257
|
+
- Support exceptions
|
258
|
+
- More math operators (`**`, etc)
|
259
|
+
- Typed export inputs (array)
|
260
|
+
- Exceptions
|
261
|
+
- Rewrite to use actual strings (optional?)
|
262
|
+
- `try { } finally { }`
|
263
|
+
- Rethrowing inside catch
|
264
|
+
- Optimizations
|
265
|
+
- Rewrite local indexes per func for smallest local header and remove unused idxs
|
266
|
+
- Smarter inline selection (snapshots?)
|
267
|
+
- Remove const ifs (`if (true)`, etc)
|
268
|
+
- Memory alignment
|
269
|
+
- Add general pref for always using "fast" (non-short circuiting) or/and
|
270
|
+
- Runtime
|
271
|
+
- WASI target
|
272
|
+
- Run precompiled Wasm file if given
|
273
|
+
- Docs
|
274
|
+
- Update codebase readme section
|
275
|
+
- REPL
|
276
|
+
- Basic polyfill of `node:repl` for non-Node runtimes to work
|
277
|
+
- Cool proposals
|
278
|
+
- [Optional Chaining Assignment](https://github.com/tc39/proposal-optional-chaining-assignment)
|
279
|
+
- [Modulus and Additional Integer Math](https://github.com/tc39/proposal-integer-and-modulus-math)
|
280
|
+
- [Array Equality](https://github.com/tc39/proposal-array-equality)
|
281
|
+
- [Declarations in Conditionals](https://github.com/tc39/proposal-Declarations-in-Conditionals)
|
282
|
+
- [Seeded Pseudo-Random Numbers](https://github.com/tc39/proposal-seeded-random)
|
283
|
+
- [`do` expressions](https://github.com/tc39/proposal-do-expressions)
|
284
|
+
- [String Trim Characters](https://github.com/Kingwl/proposal-string-trim-characters)
|
285
|
+
- Posts
|
286
|
+
- Inlining investigation
|
287
|
+
- JS -> Native
|
288
|
+
- Precompiled TS built-ins
|
289
|
+
- Asur
|
290
|
+
- `escape()` optimization
|
291
|
+
- Self hosted testing?
|
292
|
+
|
274
293
|
## VSCode extension
|
275
|
-
There is a vscode extension in `
|
294
|
+
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
295
|
|
277
296
|
## Isn't this the same as AssemblyScript/other Wasm langs?
|
278
297
|
No. they are not alike at all internally and have very different goals/ideals:
|
package/asur/README.md
ADDED