porffor 0.2.0-09999e8 → 0.2.0-31c2539

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
@@ -1,5 +1,5 @@
1
1
  # Porffor &nbsp;<sup><sub>/ˈpɔrfɔr/ &nbsp;*(poor-for)*</sup></sub>
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>
2
+ A from-scratch experimental **AOT** optimizing JS/TS -> 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 js
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 js with the compiler
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,11 +220,14 @@ 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
223
226
  - `-valtype=i32|i64|f64` (default: `f64`) to set valtype
224
227
  - `-O0` to disable opt
225
228
  - `-O1` (default) to enable basic opt (simplify insts, treeshake wasm imports)
226
- - `-O2` to enable advanced opt (inlining)
227
- - `-O3` to enable advanceder opt (precompute const math)
229
+ - `-O2` to enable advanced opt (inlining). unstable
230
+ - `-O3` to enable advanceder opt (precompute const math). unstable
228
231
  - `-no-run` to not run wasm output, just compile
229
232
  - `-opt-log` to log some opts
230
233
  - `-code-log` to log some codegen (you probably want `-funcs`)
@@ -238,20 +241,20 @@ You can also use Deno (`deno run -A ...` instead of `node ...`), or Bun (`bun ..
238
241
  - `-compile-hints` to enable V8 compilation hints (experimental + doesn't seem to do much?)
239
242
 
240
243
  ## VSCode extension
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).
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).
242
245
 
243
246
  ## Isn't this the same as AssemblyScript/other Wasm langs?
244
247
  No. they are not alike at all internally and have very different goals/ideals:
245
248
  - Porffor is made as a generic JS engine, not for Wasm stuff specifically
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
249
+ - Porffor primarily consumes JS
250
+ - Porffor is written in pure JS and compiles itself, not using Binaryen/etc
248
251
  - (Also I didn't know it existed when I started this, lol)
249
252
 
250
253
  ## FAQ
251
254
 
252
255
  ### 1. Why the name?
253
256
  `purple` in Welsh is `porffor`. Why purple?
254
- - No other js engine is purple colored
257
+ - No other JS engine is purple colored
255
258
  - Purple is pretty cool
256
259
  - Purple apparently represents "ambition", which is.. one word to describe this project
257
260
  - The hard to speak name is also the noise your brain makes in reaction to this idea!
@@ -1759,11 +1759,12 @@ const extractTypeAnnotation = decl => {
1759
1759
  elementType = extractTypeAnnotation(a.elementType).type;
1760
1760
  }
1761
1761
 
1762
+ const typeName = type;
1762
1763
  type = typeAnnoToPorfType(type);
1763
1764
 
1764
1765
  // if (decl.name) console.log(decl.name, { type, elementType });
1765
1766
 
1766
- return { type, elementType };
1767
+ return { type, typeName, elementType };
1767
1768
  };
1768
1769
 
1769
1770
  const generateVar = (scope, decl) => {
@@ -1793,6 +1794,11 @@ const generateVar = (scope, decl) => {
1793
1794
  }
1794
1795
 
1795
1796
  let idx = allocVar(scope, name, global);
1797
+
1798
+ if (typedInput && x.id.typeAnnotation) {
1799
+ addVarMetadata(scope, name, global, extractTypeAnnotation(x.id));
1800
+ }
1801
+
1796
1802
  if (x.init) {
1797
1803
  out = out.concat(generate(scope, x.init, global, name));
1798
1804
 
@@ -1802,10 +1808,6 @@ const generateVar = (scope, decl) => {
1802
1808
 
1803
1809
  // hack: this follows spec properly but is mostly unneeded 😅
1804
1810
  // 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
- }
1809
1811
  }
1810
1812
 
1811
1813
  return out;
@@ -2580,7 +2582,7 @@ export const generateMember = (scope, decl, _global, _name) => {
2580
2582
 
2581
2583
  // // todo: we should only do this for strings but we don't know at compile-time :(
2582
2584
  // hack: this is naughty and will break things!
2583
- let newOut = number(0, Valtype.f64), newPointer = -1;
2585
+ let newOut = number(0, valtypeBinary), newPointer = -1;
2584
2586
  if (pages.hasString) {
2585
2587
  0, [ newOut, newPointer ] = makeArray(scope, {
2586
2588
  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.idx) {
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--;
@@ -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 <= 0xff), Opcodes.end ]);
153
+ return encodeVector([ ...encodeVector(localDecl), ...x.wasm.flat().filter(x => x != null && x <= 0xff), Opcodes.end ]);
154
154
  }))
155
155
  );
156
156
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "porffor",
3
3
  "description": "a basic experimental wip aot optimizing js -> wasm engine/compiler/runtime in js",
4
- "version": "0.2.0-09999e8",
4
+ "version": "0.2.0-31c2539",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "dependencies": {