porffor 0.18.12 → 0.18.13

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.
@@ -694,6 +694,25 @@ export const __Date_parse = (string: bytestring): number => {
694
694
  };
695
695
 
696
696
 
697
+ // dark wasm magic for a basic allocator, sorry.
698
+ export const __Porffor_date_allocate = (): Date => {
699
+ const hack: bytestring = '';
700
+
701
+ if (hack.length == 0) {
702
+ hack.length = Porffor.wasm`
703
+ i32.const 1
704
+ memory.grow 0
705
+ i32.const 65536
706
+ i32.mul
707
+ i32.from_u`;
708
+ }
709
+
710
+ const ptr: number = hack.length;
711
+ hack.length = ptr + 8;
712
+
713
+ return ptr;
714
+ };
715
+
697
716
  export const __Porffor_date_read = (ptr: Date): number => Porffor.wasm.f64.load(ptr, 0, 0);
698
717
  export const __Porffor_date_write = (ptr: Date, val: number) => {
699
718
  Porffor.wasm.f64.store(ptr, val, 0, 0);
@@ -2011,7 +2030,7 @@ export const Date = function (v0: unknown, v1: unknown, v2: unknown, v3: unknown
2011
2030
  }
2012
2031
 
2013
2032
  // 6. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%Date.prototype%", « [[DateValue]] »).
2014
- const O: Date = Porffor.allocateBytes(8);
2033
+ const O: Date = __Porffor_date_allocate();
2015
2034
 
2016
2035
  // 7. Set O.[[DateValue]] to dv.
2017
2036
  __Porffor_date_write(O, dv);
@@ -796,6 +796,15 @@ export const BuiltinFuncs = function() {
796
796
  locals: [124,127],
797
797
  localNames: ["string","string#type","chr","#last_type"],
798
798
  };
799
+ this.__Porffor_date_allocate = {
800
+ wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: __Porffor_date_allocate/hack', 'i8') * pageSize, 124),[34,0],[252,3],[40,1,0],[184],[68,0,0,0,0,0,0,0,0],[97],[4,64],[32,0],[252,3],[65,1],[64,0],[65,128,128,4],[108],[184],[34,1],[252,3],[54,1,0],[11],[32,0],[252,3],[40,1,0],[184],[33,2],[32,0],[252,3],[32,2],[68,0,0,0,0,0,0,32,64],[160],[34,1],[252,3],[54,1,0],[32,2],[65,0],[15]],
801
+ params: [],
802
+ typedParams: true,
803
+ returns: [124,127],
804
+ typedReturns: true,
805
+ locals: [124,124,124],
806
+ localNames: ["hack","__length_setter_tmp","ptr"],
807
+ };
799
808
  this.__Porffor_date_read = {
800
809
  wasm: (scope, {}) => [[32,0],[252,2],[43,0,0],[65,0],[15]],
801
810
  params: [124,127],
@@ -1275,7 +1284,7 @@ export const BuiltinFuncs = function() {
1275
1284
  localNames: ["_this","_this#type","#last_type"],
1276
1285
  };
1277
1286
  this.Date = {
1278
- wasm: (scope, {builtin,}) => [[32,-1],[184],[65,1],[33,14],[33,15],[32,14],[33,16],[2,124],[32,16],[65,194,0],[70],[4,64,"TYPESWITCH|undefined"],[32,15],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,16],[65,210,0],[70],[4,64,"TYPESWITCH|ByteString"],[32,15],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,15],[68,0,0,0,0,0,0,0,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],[16, builtin('__Date_now')],[34,14],[16, builtin('__ecma262_ToDateString')],[34,14],[15],[11],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[32,2],[32,3],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,4],[32,5],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,6],[32,7],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,8],[32,9],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,10],[32,11],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,12],[32,13],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[33,17],[68,0,0,0,0,0,0,0,0],[33,18],[32,17],[68,0,0,0,0,0,0,0,0],[97],[4,64],[16, builtin('__Date_now')],[33,14],[33,18],[5],[32,17],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[33,19],[32,1],[33,20],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[33,21],[68,0,0,0,0,0,0,0,0],[33,22],[32,21],[68,0,0,0,0,0,0,51,64],[97],[4,64],[32,19],[32,20],[16, builtin('__Porffor_date_read')],[33,14],[33,22],[5],[32,21],[68,0,0,0,0,0,128,80,64],[97],[32,21],[68,0,0,0,0,0,128,84,64],[97],[114],[4,64],[32,19],[32,20],[16, builtin('__Date_parse')],[33,14],[33,22],[5],[65,0],[32,19],[16, builtin('Number')],[33,22],[11],[11],[32,22],[65,0],[16, builtin('__ecma262_TimeClip')],[33,14],[33,18],[5],[65,0],[32,0],[16, builtin('Number')],[33,23],[65,0],[32,2],[16, builtin('Number')],[33,24],[68,0,0,0,0,0,0,240,63],[33,25],[32,17],[68,0,0,0,0,0,0,0,64],[100],[4,64],[65,0],[32,4],[16, builtin('Number')],[33,25],[11],[68,0,0,0,0,0,0,0,0],[33,26],[32,17],[68,0,0,0,0,0,0,8,64],[100],[4,64],[65,0],[32,6],[16, builtin('Number')],[33,26],[11],[68,0,0,0,0,0,0,0,0],[33,27],[32,17],[68,0,0,0,0,0,0,16,64],[100],[4,64],[65,0],[32,8],[16, builtin('Number')],[33,27],[11],[68,0,0,0,0,0,0,0,0],[33,28],[32,17],[68,0,0,0,0,0,0,20,64],[100],[4,64],[65,0],[32,10],[16, builtin('Number')],[33,28],[11],[68,0,0,0,0,0,0,0,0],[33,29],[32,17],[68,0,0,0,0,0,0,24,64],[100],[4,64],[65,0],[32,12],[16, builtin('Number')],[33,29],[11],[32,23],[65,0],[16, builtin('__ecma262_MakeFullYear')],[33,14],[34,30],[65,0],[32,24],[65,0],[32,25],[65,0],[16, builtin('__ecma262_MakeDay')],[34,14],[32,26],[65,0],[32,27],[65,0],[32,28],[65,0],[32,29],[65,0],[16, builtin('__ecma262_MakeTime')],[34,14],[16, builtin('__ecma262_MakeDate')],[33,14],[34,31],[65,0],[16, builtin('__ecma262_UTC')],[34,14],[16, builtin('__ecma262_TimeClip')],[33,14],[33,18],[11],[11],[65,8],[16, builtin('__Porffor_allocateBytes')],[183],[34,32],[65,19],[32,18],[65,0],[16, builtin('__Porffor_date_write')],[33,14],[26],[32,32],[65,19],[15]],
1287
+ wasm: (scope, {builtin,}) => [[32,-1],[184],[65,1],[33,14],[33,15],[32,14],[33,16],[2,124],[32,16],[65,194,0],[70],[4,64,"TYPESWITCH|undefined"],[32,15],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,16],[65,210,0],[70],[4,64,"TYPESWITCH|ByteString"],[32,15],[252,3],[40,1,0],[69],[184],[12,1],[11],[32,15],[68,0,0,0,0,0,0,0,0],[97],[184],[11,"TYPESWITCH_end"],[252,3],[4,64],[16, builtin('__Date_now')],[34,14],[16, builtin('__ecma262_ToDateString')],[34,14],[15],[11],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[32,2],[32,3],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,4],[32,5],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,6],[32,7],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,8],[32,9],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,10],[32,11],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[32,12],[32,13],[16, builtin('__Porffor_rawType')],[68,0,0,0,0,0,0,8,64],[98],[184],[160],[33,17],[68,0,0,0,0,0,0,0,0],[33,18],[32,17],[68,0,0,0,0,0,0,0,0],[97],[4,64],[16, builtin('__Date_now')],[33,14],[33,18],[5],[32,17],[68,0,0,0,0,0,0,240,63],[97],[4,64],[32,0],[33,19],[32,1],[33,20],[32,0],[32,1],[16, builtin('__Porffor_rawType')],[33,21],[68,0,0,0,0,0,0,0,0],[33,22],[32,21],[68,0,0,0,0,0,0,51,64],[97],[4,64],[32,19],[32,20],[16, builtin('__Porffor_date_read')],[33,14],[33,22],[5],[32,21],[68,0,0,0,0,0,128,80,64],[97],[32,21],[68,0,0,0,0,0,128,84,64],[97],[114],[4,64],[32,19],[32,20],[16, builtin('__Date_parse')],[33,14],[33,22],[5],[65,0],[32,19],[16, builtin('Number')],[33,22],[11],[11],[32,22],[65,0],[16, builtin('__ecma262_TimeClip')],[33,14],[33,18],[5],[65,0],[32,0],[16, builtin('Number')],[33,23],[65,0],[32,2],[16, builtin('Number')],[33,24],[68,0,0,0,0,0,0,240,63],[33,25],[32,17],[68,0,0,0,0,0,0,0,64],[100],[4,64],[65,0],[32,4],[16, builtin('Number')],[33,25],[11],[68,0,0,0,0,0,0,0,0],[33,26],[32,17],[68,0,0,0,0,0,0,8,64],[100],[4,64],[65,0],[32,6],[16, builtin('Number')],[33,26],[11],[68,0,0,0,0,0,0,0,0],[33,27],[32,17],[68,0,0,0,0,0,0,16,64],[100],[4,64],[65,0],[32,8],[16, builtin('Number')],[33,27],[11],[68,0,0,0,0,0,0,0,0],[33,28],[32,17],[68,0,0,0,0,0,0,20,64],[100],[4,64],[65,0],[32,10],[16, builtin('Number')],[33,28],[11],[68,0,0,0,0,0,0,0,0],[33,29],[32,17],[68,0,0,0,0,0,0,24,64],[100],[4,64],[65,0],[32,12],[16, builtin('Number')],[33,29],[11],[32,23],[65,0],[16, builtin('__ecma262_MakeFullYear')],[33,14],[34,30],[65,0],[32,24],[65,0],[32,25],[65,0],[16, builtin('__ecma262_MakeDay')],[34,14],[32,26],[65,0],[32,27],[65,0],[32,28],[65,0],[32,29],[65,0],[16, builtin('__ecma262_MakeTime')],[34,14],[16, builtin('__ecma262_MakeDate')],[33,14],[34,31],[65,0],[16, builtin('__ecma262_UTC')],[34,14],[16, builtin('__ecma262_TimeClip')],[33,14],[33,18],[11],[11],[16, builtin('__Porffor_date_allocate')],[33,14],[34,32],[65,19],[32,18],[65,0],[16, builtin('__Porffor_date_write')],[33,14],[26],[32,32],[65,19],[15]],
1279
1288
  params: [124,127,124,127,124,127,124,127,124,127,124,127,124,127],
1280
1289
  typedParams: true,
1281
1290
  returns: [124,127],
package/compiler/wrap.js CHANGED
@@ -147,6 +147,36 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
147
147
  times.push(performance.now() - t1);
148
148
  if (Prefs.profileCompiler) console.log(bold(`compiled in ${times[0].toFixed(2)}ms`));
149
149
 
150
+ const printDecomp = (middleIndex, func, funcs, globals, exceptions) => {
151
+ console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
152
+ console.log('\x1B[4m' + func.name + '\x1B[0m');
153
+
154
+ const surrounding = Prefs.backtraceSurrounding ?? 5;
155
+ let min = middleIndex - surrounding;
156
+ let max = middleIndex + surrounding + 1;
157
+ if (Prefs.backtraceEntireFunc || middleIndex == -1) {
158
+ min = 0;
159
+ max = func.wasm.length;
160
+ }
161
+
162
+ const decomp = decompile(func.wasm.slice(min, max), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
163
+
164
+ const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
165
+ let longest = 0;
166
+ for (let j = 0; j < decomp.length; j++) {
167
+ longest = Math.max(longest, noAnsi(decomp[j]).length);
168
+ }
169
+
170
+ if (middleIndex != -1) {
171
+ const middle = Math.floor(decomp.length / 2);
172
+ decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
173
+ }
174
+
175
+ if (min != 0) console.log('\x1B[90m...\x1B[0m');
176
+ console.log(decomp.join('\n'));
177
+ if (max >= func.wasm.length) console.log('\x1B[90m...\x1B[0m\n');
178
+ }
179
+
150
180
  const backtrace = (funcInd, blobOffset) => {
151
181
  if (funcInd == null || blobOffset == null ||
152
182
  Number.isNaN(funcInd) || Number.isNaN(blobOffset)) return false;
@@ -188,7 +218,10 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
188
218
  if (!mismatch) break;
189
219
  }
190
220
 
191
- if (i === wasm.length) return false;
221
+ if (i === wasm.length) {
222
+ printDecomp(-1, func, funcs, globals, exceptions);
223
+ return false;
224
+ }
192
225
 
193
226
  const offset = (blobOffset - i) + encodeVector(localDecl).length;
194
227
 
@@ -199,30 +232,14 @@ export default (source, flags = [ 'module' ], customImports = {}, print = str =>
199
232
  if (cumLen === offset) break;
200
233
  }
201
234
 
202
- if (cumLen !== offset) return false;
203
-
204
- i -= 1;
205
-
206
- console.log(`\x1B[35m\x1B[1mporffor backtrace\u001b[0m`);
207
-
208
- console.log('\x1B[4m' + func.name + '\x1B[0m');
209
-
210
- const surrounding = 6;
211
-
212
- const decomp = decompile(func.wasm.slice(i - surrounding, i + surrounding + 1), '', 0, func.locals, func.params, func.returns, funcs, globals, exceptions).slice(0, -1).split('\n');
213
-
214
- const noAnsi = s => s.replace(/\u001b\[[0-9]+m/g, '');
215
- let longest = 0;
216
- for (let j = 0; j < decomp.length; j++) {
217
- longest = Math.max(longest, noAnsi(decomp[j]).length);
235
+ if (cumLen !== offset) {
236
+ printDecomp(-1, func, funcs, globals, exceptions);
237
+ return false;
218
238
  }
219
239
 
220
- const middle = Math.floor(decomp.length / 2);
221
- decomp[middle] = `\x1B[47m\x1B[30m${noAnsi(decomp[middle])}${'\u00a0'.repeat(longest - noAnsi(decomp[middle]).length)}\x1B[0m`;
240
+ i -= 1;
222
241
 
223
- console.log('\x1B[90m...\x1B[0m');
224
- console.log(decomp.join('\n'));
225
- console.log('\x1B[90m...\x1B[0m\n');
242
+ printDecomp(i, func, funcs, globals, exceptions);
226
243
 
227
244
  return true;
228
245
  };
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.12+a6989c4b7",
4
+ "version": "0.18.13+5501d0132",
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.12+a6989c4b7';
3
+ globalThis.version = '0.18.13+5501d0132';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {