porffor 0.47.0 → 0.47.2

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.
@@ -1547,6 +1547,15 @@ export const __Porffor_bytestring_appendChar = (str: bytestring, char: i32): i32
1547
1547
  return 1;
1548
1548
  };
1549
1549
 
1550
+ export const __Porffor_bytestring_append2Char = (str: bytestring, char1: i32, char2: i32): i32 => {
1551
+ const len: i32 = str.length;
1552
+ Porffor.wasm.i32.store8(Porffor.wasm`local.get ${str}` + len, char1, 0, 4);
1553
+ Porffor.wasm.i32.store8(Porffor.wasm`local.get ${str}` + len + 1, char2, 0, 4);
1554
+ str.length = len + 2;
1555
+ return 1;
1556
+ };
1557
+
1558
+
1550
1559
  // fast appending padded number
1551
1560
  export const __Porffor_bytestring_appendPadNum = (str: bytestring, num: number, len: number): i32 => {
1552
1561
  let numStr: bytestring = Number.prototype.toFixed(num, 0);
@@ -1,3 +1,5 @@
1
+ import type {} from './porffor.d.ts';
2
+
1
3
  export const __Porffor_Generator = (values: any[]): __Porffor_Generator => {
2
4
  const gen: __Porffor_Generator = values;
3
5
  return gen;
@@ -0,0 +1,90 @@
1
+ import type {} from './porffor.d.ts';
2
+
3
+ export const __Porffor_json_serialize = (value: any): bytestring => {
4
+ // todo: many niche things (toJSON, prim objects, etc) are not implemented yet
5
+ // somewhat modelled after 25.5.2.2 SerializeJSONProperty: https://tc39.es/ecma262/#sec-serializejsonproperty
6
+ let out: bytestring = Porffor.allocate();
7
+
8
+ if (value === null) return out = 'null';
9
+ if (value === true) return out = 'true';
10
+ if (value === false) return out = 'false';
11
+
12
+ const t: i32 = Porffor.rawType(value);
13
+ if ((t | 0b10000000) == Porffor.TYPES.bytestring) { // string
14
+ out = '"'; // starting "
15
+
16
+ const len: i32 = value.length;
17
+ for (let i: i32 = 0; i < len; i++) {
18
+ const c: i32 = value.charCodeAt(i);
19
+ if (c < 0x20) {
20
+ if (c == 0x08) {
21
+ Porffor.bytestring.append2Char(out, 92, 98); // \b
22
+ continue;
23
+ }
24
+
25
+ if (c == 0x09) {
26
+ Porffor.bytestring.append2Char(out, 92, 116); // \t
27
+ continue;
28
+ }
29
+
30
+ if (c == 0x0a) {
31
+ Porffor.bytestring.append2Char(out, 92, 110); // \n
32
+ continue;
33
+ }
34
+
35
+ if (c == 0x0c) {
36
+ Porffor.bytestring.append2Char(out, 92, 102); // \f
37
+ continue;
38
+ }
39
+
40
+ if (c == 0x0d) {
41
+ Porffor.bytestring.append2Char(out, 92, 114); // \r
42
+ continue;
43
+ }
44
+
45
+ // \u00FF
46
+ Porffor.bytestring.append2Char(out, 92, 117); // \u
47
+ Porffor.bytestring.append2Char(out, 48, 48); // 00
48
+
49
+ Porffor.printHexDigit((c & 0xf0) / 0x10);
50
+ Porffor.printHexDigit(c & 0x0f);
51
+ continue;
52
+ }
53
+
54
+ if (c == 0x22) { // "
55
+ Porffor.bytestring.append2Char(out, 92, 34); // \"
56
+ continue;
57
+ }
58
+
59
+ if (c == 0x5c) { // \
60
+ Porffor.bytestring.append2Char(out, 92, 92); // \\
61
+ continue;
62
+ }
63
+
64
+ // todo: support non-bytestrings
65
+ Porffor.bytestring.appendChar(out, c);
66
+ }
67
+
68
+ Porffor.bytestring.appendChar(out, 34); // final "
69
+ }
70
+
71
+ if (Porffor.fastOr(
72
+ t == Porffor.TYPES.number,
73
+ t == Porffor.TYPES.numberobject
74
+ )) { // number
75
+ if (Number.isFinite(value)) return out = __Number_prototype_toString(value, 10);
76
+ return out = 'null';
77
+ }
78
+
79
+ // todo: array
80
+ // todo: object
81
+
82
+ return out;
83
+ };
84
+
85
+ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
86
+ // todo: replacer
87
+ // todo: space
88
+
89
+ return __Porffor_json_serialize(value);
90
+ };
@@ -85,6 +85,7 @@ type PorfforGlobal = {
85
85
  // defined in date.ts
86
86
  appendStr(str: bytestring, appendage: bytestring): i32;
87
87
  appendChar(str: bytestring, char: i32): i32;
88
+ append2Char(str: bytestring, char1: i32, char2: i32): i32;
88
89
  appendPadNum(str: bytestring, num: number, len: number): i32;
89
90
  }
90
91
 
@@ -1452,6 +1452,12 @@ params:[124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
1452
1452
  locals:[124,124,127],localNames:["str","str#type","char","char#type","len","__length_setter_tmp","__member_setter_ptr_tmp"],
1453
1453
  usedTypes:[195],
1454
1454
  }
1455
+ this.__Porffor_bytestring_append2Char = {
1456
+ wasm:()=>[[32,0],[252,3],[40,1,0],[184],[33,6],[32,0],[32,6],[160],[252,2],[32,2],[252,2],[58,0,4],[32,0],[32,6],[160],[68,1],[160],[252,2],[32,4],[252,2],[58,0,4],[32,0],[252,3],[34,8],[32,6],[68,2],[160],[34,7],[252,3],[54,1,0],[68,1],[65,1],[15]],
1457
+ params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
1458
+ locals:[124,124,127],localNames:["str","str#type","char1","char1#type","char2","char2#type","len","__length_setter_tmp","__member_setter_ptr_tmp"],
1459
+ usedTypes:[195],
1460
+ }
1455
1461
  this.__Porffor_bytestring_appendPadNum = {
1456
1462
  wasm:(_,{builtin})=>[[32,2],[65,1],[68,0],[65,1],[16,builtin('__Number_prototype_toFixed')],[33,7],[33,6],[32,0],[32,0],[252,3],[40,1,0],[184],[160],[33,8],[32,6],[252,3],[40,1,0],[184],[33,9],[32,8],[32,4],[32,9],[161],[160],[33,10],[3,64],[32,8],[32,10],[99],[4,64],[32,8],[32,8],[68,1],[160],[33,8],[252,2],[65,48],[58,0,4],[12,1],[11],[11],[32,6],[34,11],[32,9],[160],[33,12],[3,64],[32,11],[32,12],[99],[4,64],[32,8],[32,8],[68,1],[160],[33,8],[252,2],[32,11],[32,11],[68,1],[160],[33,11],[252,2],[45,0,4],[58,0,4],[12,1],[11],[11],[32,0],[252,3],[34,14],[32,8],[32,0],[161],[34,13],[252,3],[54,1,0],[68,1],[65,1],[15]],
1457
1463
  params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
@@ -1804,6 +1810,19 @@ locals:[124,124,127,127],localNames:["vals","vals#type","value","value#type","#a
1804
1810
  usedTypes:[36,80],
1805
1811
  usesTag:1,
1806
1812
  }
1813
+ this.__Porffor_json_serialize = {
1814
+ wasm:(_,{t,allocPage,builtin,internalThrow})=>[[16,builtin('__Porffor_allocate')],[183],[33,2],[32,0],[68,0],[97],[32,1],[65,128,1],[114],[65,7],[65,128,1],[114],[70],[113],[4,64],...number(allocPage(_,'bytestring: __Porffor_json_serialize/out','i8'),124),[34,2],[65,195,1],[15],[11],[32,0],[68,1],[97],[32,1],[65,128,1],[114],[65,2],[65,128,1],[114],[70],[113],[4,64],[32,2],[252,3],[34,3],[65,4],[54,1,0],[32,3],[65,244,0],[58,0,4],[32,3],[65,242,0],[58,0,5],[32,3],[65,245,0],[58,0,6],[32,3],[65,229,0],[58,0,7],[32,3],[184],[34,2],[65,195,1],[15],[11],[32,0],[68,0],[97],[32,1],[65,128,1],[114],[65,2],[65,128,1],[114],[70],[113],[4,64],[32,2],[252,3],[34,3],[65,5],[54,1,0],[32,3],[65,230,0],[58,0,4],[32,3],[65,225,0],[58,0,5],[32,3],[65,236,0],[58,0,6],[32,3],[65,243,0],[58,0,7],[32,3],[65,229,0],[58,0,8],[32,3],[184],[34,2],[65,195,1],[15],[11],[32,1],[184],[34,4],[68,128],[16,builtin('f64_|')],[68,195],[97],[4,64],[32,2],[252,3],[34,3],[65,1],[54,1,0],[32,3],[65,34],[58,0,4],[32,3],[184],[33,2],[32,0],[252,3],[40,1,0],[184],[33,5],[68,0],[33,6],[3,64],[32,6],[32,5],[99],[4,64],[2,64],[32,0],[252,3],[40,1,0],[33,8],[32,1],[33,10],[2,124],...t([39],()=>[[32,10],[65,39],[70],[4,64],[32,6],[252,2],[65,2],[108],[32,0],[252,3],[106],[47,0,4],[184],[65,1],[33,12],[12,1],[11]]),...t([67],()=>[[32,10],[65,195,0],[70],[4,64],[32,6],[252,2],[65,2],[108],[32,0],[252,3],[106],[47,0,4],[184],[65,1],[33,12],[12,1],[11]]),...t([195],()=>[[32,10],[65,195,1],[70],[4,64],[32,6],[252,2],[32,0],[252,3],[106],[45,0,4],[184],[65,1],[33,12],[12,1],[11]]),...internalThrow(_,'TypeError',`'charCodeAt' proto func tried to be called on a type without an impl`),[68,0],[11],[34,7],[68,32],[99],[4,64],[32,7],[68,8],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,98],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,2],[11],[32,7],[68,9],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,116],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,2],[11],[32,7],[68,10],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,110],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,2],[11],[32,7],[68,12],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,102],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,2],[11],[32,7],[68,13],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,114],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,2],[11],[32,2],[65,195,1],[68,92],[65,1],[68,117],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[32,2],[65,195,1],[68,48],[65,1],[68,48],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[32,7],[68,240],[16,builtin('f64_&')],[68,16],[163],[65,1],[16,builtin('__Porffor_printHexDigit')],[33,12],[26],[32,7],[68,15],[16,builtin('f64_&')],[65,1],[16,builtin('__Porffor_printHexDigit')],[33,12],[26],[12,1],[11],[32,7],[68,34],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,34],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,1],[11],[32,7],[68,92],[97],[4,64],[32,2],[65,195,1],[68,92],[65,1],[68,92],[65,1],[16,builtin('__Porffor_bytestring_append2Char')],[33,12],[26],[12,1],[11],[32,2],[65,195,1],[32,7],[65,1],[16,builtin('__Porffor_bytestring_appendChar')],[33,12],[26],[11],[32,6],[68,1],[160],[33,6],[12,1],[11],[11],[32,2],[65,195,1],[68,34],[65,1],[16,builtin('__Porffor_bytestring_appendChar')],[33,12],[26],[11],[32,4],[68,1],[97],[32,4],[68,38],[97],[114],[4,64],[32,0],[16,builtin('__Number_isFinite')],[252,3],[4,64],[32,0],[32,1],[68,10],[65,1],[16,builtin('__Number_prototype_toString')],[33,12],[34,2],[32,12],[15],[11],[32,2],[252,3],[34,3],[65,4],[54,1,0],[32,3],[65,238,0],[58,0,4],[32,3],[65,245,0],[58,0,5],[32,3],[65,236,0],[58,0,6],[32,3],[65,236,0],[58,0,7],[32,3],[184],[34,2],[65,195,1],[15],[11],[32,2],[65,195,1],[15]],
1815
+ params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
1816
+ locals:[124,127,124,124,124,124,127,127,127,127,127],localNames:["value","value#type","out","#makearray_pointer_tmp","t","len","i","c","__proto_length_cache","__proto_pointer_cache","#typeswitch_tmp1","__charCodeAt_tmp","#last_type"],
1817
+ usedTypes:[7,195],
1818
+ data:{"bytestring: __Porffor_json_serialize/out":[4,0,0,0,110,117,108,108]},
1819
+ usesTag:1,
1820
+ }
1821
+ this.__JSON_stringify = {
1822
+ wasm:(_,{builtin})=>[[32,0],[32,1],[16,builtin('__Porffor_json_serialize')],[34,6],[15]],
1823
+ params:[124,127,124,127,124,127],typedParams:1,returns:[124,127],typedReturns:1,
1824
+ locals:[127],localNames:["value","value#type","replacer","replacer#type","space","space#type","#last_type"],
1825
+ }
1807
1826
  this.__Math_exp = {
1808
1827
  wasm:(_,{builtin})=>[[32,0],[16,builtin('__Number_isFinite')],[68,0],[97],[4,64],[32,0],[68,"Infinity"],[154],[97],[4,64],[68,0],[65,1],[15],[11],[32,0],[65,1],[15],[11],[32,0],[68,0],[99],[4,64],[68,1],[32,0],[154],[65,1],[16,builtin('__Math_exp')],[33,2],[163],[65,1],[15],[11],[32,0],[68,0.6931471805599453],[163],[16,builtin('__Math_floor')],[33,3],[32,0],[32,3],[68,0.6931471805599453],[162],[161],[34,4],[33,5],[68,1],[32,4],[160],[33,6],[68,2],[33,7],[3,64],[32,5],[16,builtin('__Math_abs')],[68,1e-15],[100],[4,64],[32,5],[32,4],[32,7],[163],[162],[33,5],[32,6],[32,5],[160],[33,6],[32,7],[68,1],[160],[33,7],[12,1],[11],[11],[3,64],[32,3],[32,3],[68,1],[161],[33,3],[68,0],[100],[4,64],[32,6],[68,2],[162],[33,6],[12,1],[11],[11],[32,6],[65,1],[15]],
1809
1828
  params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
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.47.0+bfae421aa",
4
+ "version": "0.47.2",
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.47.0+bfae421aa';
3
+ globalThis.version = '0.47.2';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {