porffor 0.18.5 → 0.18.7

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
@@ -254,25 +254,18 @@ Basically none right now (other than giving people headaches). Potential ideas:
254
254
  ## Todo
255
255
  No particular order and no guarentees, just what could happen soon™
256
256
 
257
- - Arrays
258
- - Destructuring
259
257
  - Objects
260
258
  - Basic object expressions (eg `{}`, `{ a: 0 }`)
261
259
  - Asur
262
260
  - Support memory
263
261
  - Support exceptions
264
- - More math operators (`**`, etc)
265
- - Typed export inputs (array)
266
262
  - Exceptions
267
- - Rewrite to use actual strings (optional?)
268
263
  - `try { } finally { }`
269
264
  - Rethrowing inside catch
270
265
  - Optimizations
271
266
  - Rewrite local indexes per func for smallest local header and remove unused idxs
272
267
  - Smarter inline selection (snapshots?)
273
- - Remove const ifs (`if (true)`, etc)
274
268
  - Memory alignment
275
- - Add general pref for always using "fast" (non-short circuiting) or/and
276
269
  - Runtime
277
270
  - WASI target
278
271
  - Run precompiled Wasm file if given
@@ -292,6 +285,7 @@ No particular order and no guarentees, just what could happen soon™
292
285
  - Precompiled TS built-ins
293
286
  - Asur
294
287
  - `escape()` optimization
288
+ - PGO
295
289
  - Self hosted testing?
296
290
 
297
291
  ## VSCode extension
@@ -46,6 +46,73 @@ export const __Array_prototype_slice = (_this: any[], start: number, end: number
46
46
  return out;
47
47
  };
48
48
 
49
+ export const __Array_prototype_splice = (_this: any[], index: any, deleteCount: any, ...values: any[]) => {
50
+ const len: i32 = _this.length;
51
+
52
+ if (Porffor.rawType(index) == Porffor.TYPES.undefined) index = len;
53
+ index |= 0;
54
+ if (index < 0) {
55
+ index = len + index;
56
+ if (index < 0) index = 0;
57
+ }
58
+
59
+ if (Porffor.rawType(deleteCount) == Porffor.TYPES.undefined) deleteCount = 1;
60
+ deleteCount |= 0;
61
+ if (deleteCount < 0) deleteCount = 0;
62
+ if (deleteCount > len - index) deleteCount = len - index;
63
+
64
+ const out: any[] = Porffor.allocate();
65
+ out.length = deleteCount;
66
+
67
+ for (let i: i32 = 0; i < deleteCount; i++) {
68
+ out[i] = _this[index + i];
69
+ }
70
+
71
+ _this.length = len - deleteCount;
72
+
73
+ // memory.copy lol
74
+ Porffor.wasm`
75
+ ;; dst = ptr(this) + index * sizeof element + sizeof length
76
+ local.get ${_this}
77
+ i32.to_u
78
+ local.get ${index}
79
+ i32.to_u
80
+ i32.const 9
81
+ i32.mul
82
+ i32.add
83
+ i32.const 4
84
+ i32.add
85
+
86
+ local #splice_ptr i32
87
+ local.tee #splice_ptr
88
+
89
+ ;; src = dst + deletecount * sizeof element
90
+ local.get #splice_ptr
91
+ local.get ${deleteCount}
92
+ i32.to_u
93
+ i32.const 9
94
+ i32.mul
95
+ i32.add
96
+
97
+ ;; size = (length - deleteCount - index) * sizeof element
98
+ local.get ${len}
99
+ i32.to_u
100
+ local.get ${deleteCount}
101
+ i32.to_u
102
+ i32.sub
103
+ local.get ${index}
104
+ i32.to_u
105
+ i32.sub
106
+ i32.const 9
107
+ i32.mul
108
+
109
+ memory.copy 0 0`;
110
+
111
+ return out;
112
+ };
113
+
114
+ // todo: unshift
115
+
49
116
  // @porf-typed-array
50
117
  export const __Array_prototype_fill = (_this: any[], value: any, start: any, end: any) => {
51
118
  const len: i32 = _this.length;
@@ -199,14 +199,8 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
199
199
  return out;
200
200
  },
201
201
 
202
- __Porffor_bs: str => [
203
- ...makeString(scope, str, global, name, true),
204
- ...(name ? setType(scope, name, TYPES.bytestring) : setLastType(scope, TYPES.bytestring))
205
- ],
206
- __Porffor_s: str => [
207
- ...makeString(scope, str, global, name, false),
208
- ...(name ? setType(scope, name, TYPES.string) : setLastType(scope, TYPES.string))
209
- ],
202
+ __Porffor_bs: str => makeString(scope, str, global, name, true),
203
+ __Porffor_s: str => makeString(scope, str, global, name, false)
210
204
  };
211
205
 
212
206
  const func = decl.tag.name;
@@ -1383,7 +1377,11 @@ const getNodeType = (scope, node) => {
1383
1377
 
1384
1378
  if (node.type === 'TaggedTemplateExpression') {
1385
1379
  // hack
1386
- if (node.tag.name.startsWith('__Porffor_')) return TYPES.number;
1380
+ switch (node.tag.name) {
1381
+ case '__Porffor_wasm': return TYPES.number;
1382
+ case '__Porffor_bs': return TYPES.bytestring;
1383
+ case '__Porffor_s': return TYPES.string;
1384
+ }
1387
1385
  }
1388
1386
 
1389
1387
  if (scope.locals['#last_type']) return getLastType(scope);
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.18.5+76c57fd23",
4
+ "version": "0.18.7+0637c8011",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},
package/runner/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
- globalThis.version = '0.18.5+76c57fd23';
3
+ globalThis.version = '0.18.7+0637c8011';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {