porffor 0.2.0-08a272e → 0.2.0-09999e8
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 +9 -12
- package/compiler/codeGen.js +6 -8
- package/compiler/opt.js +1 -1
- package/compiler/sections.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Porffor <sup><sub>/ˈpɔrfɔr/ *(poor-for)*</sup></sub>
|
2
|
-
A from-scratch experimental **AOT** optimizing JS
|
2
|
+
A from-scratch experimental **AOT** optimizing JS -> Wasm/C engine/compiler/runtime in JS. Not serious/intended for (real) use. (this is a straight forward, honest readme)<br>
|
3
3
|
Age: ~6 months (very on and off)
|
4
4
|
|
5
5
|
## Design
|
@@ -118,7 +118,7 @@ No particular order and no guarentees, just what could happen soon™
|
|
118
118
|
- Objects
|
119
119
|
- Basic object expressions (eg `{}`, `{ a: 0 }`)
|
120
120
|
- Wasm
|
121
|
-
- *Basic* Wasm engine (interpreter) in
|
121
|
+
- *Basic* Wasm engine (interpreter) in js
|
122
122
|
- More math operators (`**`, etc)
|
123
123
|
- `do { ... } while (...)`
|
124
124
|
- Rewrite `console.log` to work with strings/arrays
|
@@ -188,7 +188,7 @@ Porffor can run Test262 via some hacks/transforms which remove unsupported featu
|
|
188
188
|
- `wasmSpec.js`: "enums"/info from wasm spec
|
189
189
|
- `wrap.js`: wrapper for compiler which instantiates and produces nice exports
|
190
190
|
|
191
|
-
- `runner`: contains utils for running
|
191
|
+
- `runner`: contains utils for running js with the compiler
|
192
192
|
- `index.js`: the main file, you probably want to use this
|
193
193
|
- `info.js`: runs with extra info printed
|
194
194
|
- `repl.js`: basic repl (uses `node:repl`)
|
@@ -220,14 +220,11 @@ You can also use Deno (`deno run -A ...` instead of `node ...`), or Bun (`bun ..
|
|
220
220
|
- `-target=native` only:
|
221
221
|
- `-compiler=clang` to set compiler binary (path/name) to use to compile
|
222
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
223
|
- `-valtype=i32|i64|f64` (default: `f64`) to set valtype
|
227
224
|
- `-O0` to disable opt
|
228
225
|
- `-O1` (default) to enable basic opt (simplify insts, treeshake wasm imports)
|
229
|
-
- `-O2` to enable advanced opt (inlining)
|
230
|
-
- `-O3` to enable advanceder opt (precompute const math)
|
226
|
+
- `-O2` to enable advanced opt (inlining)
|
227
|
+
- `-O3` to enable advanceder opt (precompute const math)
|
231
228
|
- `-no-run` to not run wasm output, just compile
|
232
229
|
- `-opt-log` to log some opts
|
233
230
|
- `-code-log` to log some codegen (you probably want `-funcs`)
|
@@ -241,20 +238,20 @@ You can also use Deno (`deno run -A ...` instead of `node ...`), or Bun (`bun ..
|
|
241
238
|
- `-compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
|
242
239
|
|
243
240
|
## VSCode extension
|
244
|
-
There is a vscode extension in `porffor-for-vscode` which tweaks
|
241
|
+
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).
|
245
242
|
|
246
243
|
## Isn't this the same as AssemblyScript/other Wasm langs?
|
247
244
|
No. they are not alike at all internally and have very different goals/ideals:
|
248
245
|
- Porffor is made as a generic JS engine, not for Wasm stuff specifically
|
249
|
-
- Porffor
|
250
|
-
- Porffor is
|
246
|
+
- Porffor takes in JS, not a different language or typescript
|
247
|
+
- Porffor is made in pure JS and compiles itself, not using Binaryen/etc
|
251
248
|
- (Also I didn't know it existed when I started this, lol)
|
252
249
|
|
253
250
|
## FAQ
|
254
251
|
|
255
252
|
### 1. Why the name?
|
256
253
|
`purple` in Welsh is `porffor`. Why purple?
|
257
|
-
- No other
|
254
|
+
- No other js engine is purple colored
|
258
255
|
- Purple is pretty cool
|
259
256
|
- Purple apparently represents "ambition", which is.. one word to describe this project
|
260
257
|
- The hard to speak name is also the noise your brain makes in reaction to this idea!
|
package/compiler/codeGen.js
CHANGED
@@ -1759,12 +1759,11 @@ const extractTypeAnnotation = decl => {
|
|
1759
1759
|
elementType = extractTypeAnnotation(a.elementType).type;
|
1760
1760
|
}
|
1761
1761
|
|
1762
|
-
const typeName = type;
|
1763
1762
|
type = typeAnnoToPorfType(type);
|
1764
1763
|
|
1765
1764
|
// if (decl.name) console.log(decl.name, { type, elementType });
|
1766
1765
|
|
1767
|
-
return { type,
|
1766
|
+
return { type, elementType };
|
1768
1767
|
};
|
1769
1768
|
|
1770
1769
|
const generateVar = (scope, decl) => {
|
@@ -1794,11 +1793,6 @@ const generateVar = (scope, decl) => {
|
|
1794
1793
|
}
|
1795
1794
|
|
1796
1795
|
let idx = allocVar(scope, name, global);
|
1797
|
-
|
1798
|
-
if (typedInput && x.id.typeAnnotation) {
|
1799
|
-
addVarMetadata(scope, name, global, extractTypeAnnotation(x.id));
|
1800
|
-
}
|
1801
|
-
|
1802
1796
|
if (x.init) {
|
1803
1797
|
out = out.concat(generate(scope, x.init, global, name));
|
1804
1798
|
|
@@ -1808,6 +1802,10 @@ const generateVar = (scope, decl) => {
|
|
1808
1802
|
|
1809
1803
|
// hack: this follows spec properly but is mostly unneeded 😅
|
1810
1804
|
// out.push(...setType(scope, name, x.init ? getNodeType(scope, x.init) : TYPES.undefined));
|
1805
|
+
|
1806
|
+
if (typedInput && x.id.typeAnnotation) {
|
1807
|
+
addVarMetadata(scope, name, global, extractTypeAnnotation(x.id));
|
1808
|
+
}
|
1811
1809
|
}
|
1812
1810
|
|
1813
1811
|
return out;
|
@@ -2582,7 +2580,7 @@ export const generateMember = (scope, decl, _global, _name) => {
|
|
2582
2580
|
|
2583
2581
|
// // todo: we should only do this for strings but we don't know at compile-time :(
|
2584
2582
|
// hack: this is naughty and will break things!
|
2585
|
-
let newOut = number(0,
|
2583
|
+
let newOut = number(0, Valtype.f64), newPointer = -1;
|
2586
2584
|
if (pages.hasString) {
|
2587
2585
|
0, [ newOut, newPointer ] = makeArray(scope, {
|
2588
2586
|
rawElements: new Array(1)
|
package/compiler/opt.js
CHANGED
@@ -235,7 +235,7 @@ export default (funcs, globals, pages) => {
|
|
235
235
|
}
|
236
236
|
|
237
237
|
// remove setting last type if it is never gotten
|
238
|
-
if (!f.gotLastType && inst[0] === Opcodes.local_set && inst[1] === lastType
|
238
|
+
if (!f.gotLastType && inst[0] === Opcodes.local_set && inst[1] === lastType.idx) {
|
239
239
|
// replace this inst with drop
|
240
240
|
wasm.splice(i, 1, [ Opcodes.drop ]); // remove this and last inst
|
241
241
|
if (i > 0) i--;
|
package/compiler/sections.js
CHANGED
@@ -150,7 +150,7 @@ export default (funcs, globals, tags, pages, data, flags) => {
|
|
150
150
|
|
151
151
|
if (typeCount !== 0) localDecl.push(encodeLocal(typeCount, lastType));
|
152
152
|
|
153
|
-
return encodeVector([ ...encodeVector(localDecl), ...x.wasm.flat().filter(x => x
|
153
|
+
return encodeVector([ ...encodeVector(localDecl), ...x.wasm.flat().filter(x => x <= 0xff), Opcodes.end ]);
|
154
154
|
}))
|
155
155
|
);
|
156
156
|
|
package/package.json
CHANGED