porffor 0.17.0-9c7bd8098 → 0.17.0-bf4206d7b

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.
@@ -2,17 +2,18 @@
2
2
  import type {} from './porffor.d.ts';
3
3
 
4
4
  export const btoa = (input: bytestring): bytestring => {
5
+ // todo: throw on invalid chars
6
+
5
7
  const keyStr: bytestring = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
6
8
  const keyStrPtr: i32 = Porffor.wasm`local.get ${keyStr}`;
7
9
 
8
10
  let len: i32 = input.length;
9
11
  let output: bytestring = '';
10
- output.length = 4 * (len / 3 + !!(len % 3));
11
12
 
12
13
  let i: i32 = Porffor.wasm`local.get ${input}`,
13
14
  j: i32 = Porffor.wasm`local.get ${output}`;
14
15
 
15
- // todo/perf: add some per 6 char variant using bitwise magic
16
+ // todo/perf: add some per 6 char variant using bitwise magic?
16
17
 
17
18
  const endPtr = i + len;
18
19
  while (i < endPtr) {
@@ -38,40 +39,43 @@ export const btoa = (input: bytestring): bytestring => {
38
39
  Porffor.wasm.i32.store8(j++, Porffor.wasm.i32.load8_u(keyStrPtr + enc4, 0, 4), 0, 4);
39
40
  }
40
41
 
42
+ output.length = j - Porffor.wasm`local.get ${output}`;
41
43
  return output;
42
44
  };
43
45
 
44
- // todo: impl atob by converting below to "porf ts"
45
- /* var atob = function (input) {
46
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
46
+ export const atob = (input: bytestring): bytestring => {
47
+ // todo: throw on non-base64 chars
48
+
49
+ const lut: bytestring = '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@>@@@?456789:;<=@@@@@@@\x00\x01\x02\x03\x04\x05\x06\x07\b\t\n\x0B\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19@@@@@@\x1A\x1B\x1C\x1D\x1E\x1F !"#$%&\'()*+,-./0123';
50
+ const lutPtr: i32 = Porffor.wasm`local.get ${lut}`;
51
+
52
+ let output: bytestring = '';
47
53
 
48
- let output = "";
49
- let chr1, chr2, chr3;
50
- let enc1, enc2, enc3, enc4;
51
- let i = 0;
54
+ let i: i32 = Porffor.wasm`local.get ${input}`,
55
+ j: i32 = Porffor.wasm`local.get ${output}`;
52
56
 
53
- while (i < input.length) {
54
- enc1 = keyStr.indexOf(input.charAt(i++));
55
- enc2 = keyStr.indexOf(input.charAt(i++));
56
- enc3 = keyStr.indexOf(input.charAt(i++));
57
- enc4 = keyStr.indexOf(input.charAt(i++));
57
+ const endPtr = i + input.length;
58
+ while (i < endPtr) {
59
+ const enc1: i32 = Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4);
60
+ const enc2: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
61
+ const enc3: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
62
+ const enc4: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
58
63
 
59
- chr1 = (enc1 << 2) | (enc2 >> 4);
60
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
61
- chr3 = ((enc3 & 3) << 6) | enc4;
64
+ const chr1: i32 = (enc1 << 2) | (enc2 == -1 ? 0 : (enc2 >> 4));
65
+ const chr2: i32 = ((enc2 & 15) << 4) | (enc3 == -1 ? 0 : (enc3 >> 2));
66
+ const chr3: i32 = ((enc3 & 3) << 6) | (enc4 == -1 ? 0 : enc4);
62
67
 
63
- // output += String.fromCharCode(chr1);
64
- Porffor.bytestring.appendCharCode(output, chr1);
68
+ Porffor.wasm.i32.store8(j++, chr1, 0, 4);
65
69
 
66
70
  if (enc3 != 64) {
67
- // output += String.fromCharCode(chr2);
68
- Porffor.bytestring.appendCharCode(output, chr2);
71
+ Porffor.wasm.i32.store8(j++, chr2, 0, 4);
69
72
  }
73
+
70
74
  if (enc4 != 64) {
71
- // output += String.fromCharCode(chr3);
72
- Porffor.bytestring.appendCharCode(output, chr3);
75
+ Porffor.wasm.i32.store8(j++, chr3, 0, 4);
73
76
  }
74
77
  }
75
78
 
79
+ output.length = j - Porffor.wasm`local.get ${output}`;
76
80
  return output;
77
- }; */
81
+ };
@@ -409,15 +409,25 @@ export const BuiltinFuncs = function() {
409
409
  data: [{"bytes":[1,0,0,0,44],"offset":0}],
410
410
  };
411
411
  this.btoa = {
412
- wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: btoa/keyStr', 'i8') * pageSize, 127),[34,2],[33,3],[32,0],[40,1,0],[33,4],...number(allocPage(scope, 'bytestring: btoa/output', 'i8') * pageSize, 127),[34,5],[65,4],[32,4],[65,3],[109],[32,4],[65,3],[111],[106],[108],[34,6],[54,1,0],[32,0],[33,7],[32,5],[33,8],[32,7],[32,4],[106],[33,9],[65,0],[33,10],[3,64],[32,7],[32,9],[72],[4,64],[32,7],[32,7],[65,1],[106],[33,7],[45,0,4],[33,11],[32,7],[32,9],[72],[4,127],[32,7],[32,7],[65,1],[106],[33,7],[45,0,4],[65,0],[33,13],[5],[65,127],[65,0],[33,13],[11],[33,12],[32,7],[32,9],[72],[4,127],[32,7],[32,7],[65,1],[106],[33,7],[45,0,4],[65,0],[33,13],[5],[65,127],[65,0],[33,13],[11],[33,14],[32,11],[65,2],[117],[33,15],[32,11],[65,3],[113],[65,4],[116],[32,12],[65,127],[70],[4,127],[65,0],[65,0],[33,13],[5],[32,12],[65,4],[117],[65,0],[33,13],[11],[114],[33,16],[32,12],[65,15],[113],[65,2],[116],[32,14],[65,127],[70],[4,127],[65,0],[65,0],[33,13],[5],[32,14],[65,6],[117],[65,0],[33,13],[11],[114],[33,17],[32,14],[65,63],[113],[33,18],[32,12],[65,127],[70],[4,64],[65,192,0],[33,17],[65,192,0],[33,18],[5],[32,14],[65,127],[70],[4,64],[65,192,0],[33,18],[11],[11],[32,8],[32,8],[65,1],[106],[33,8],[32,3],[32,15],[106],[45,0,4],[58,0,4],[32,8],[32,8],[65,1],[106],[33,8],[32,3],[32,16],[106],[45,0,4],[58,0,4],[32,8],[32,8],[65,1],[106],[33,8],[32,3],[32,17],[106],[45,0,4],[58,0,4],[32,8],[32,8],[65,1],[106],[33,8],[32,3],[32,18],[106],[45,0,4],[58,0,4],[12,1],[11],[11],[32,5],[15]],
412
+ wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: btoa/keyStr', 'i8') * pageSize, 127),[34,2],[33,3],[32,0],[40,1,0],[33,4],...number(allocPage(scope, 'bytestring: btoa/output', 'i8') * pageSize, 127),[33,5],[32,0],[33,6],[32,5],[33,7],[32,6],[32,4],[106],[33,8],[65,0],[33,9],[3,64],[32,6],[32,8],[72],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[33,10],[32,6],[32,8],[72],[4,127],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[65,0],[33,12],[5],[65,127],[65,0],[33,12],[11],[33,11],[32,6],[32,8],[72],[4,127],[32,6],[32,6],[65,1],[106],[33,6],[45,0,4],[65,0],[33,12],[5],[65,127],[65,0],[33,12],[11],[33,13],[32,10],[65,2],[117],[33,14],[32,10],[65,3],[113],[65,4],[116],[32,11],[65,127],[70],[4,127],[65,0],[65,0],[33,12],[5],[32,11],[65,4],[117],[65,0],[33,12],[11],[114],[33,15],[32,11],[65,15],[113],[65,2],[116],[32,13],[65,127],[70],[4,127],[65,0],[65,0],[33,12],[5],[32,13],[65,6],[117],[65,0],[33,12],[11],[114],[33,16],[32,13],[65,63],[113],[33,17],[32,11],[65,127],[70],[4,64],[65,192,0],[33,16],[65,192,0],[33,17],[5],[32,13],[65,127],[70],[4,64],[65,192,0],[33,17],[11],[11],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,14],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,15],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,16],[106],[45,0,4],[58,0,4],[32,7],[32,7],[65,1],[106],[33,7],[32,3],[32,17],[106],[45,0,4],[58,0,4],[12,1],[11],[11],[32,5],[32,7],[32,5],[107],[34,18],[54,1,0],[32,5],[15]],
413
413
  params: [127,127],
414
414
  typedParams: true,
415
415
  returns: [127],
416
416
  returnType: 18,
417
417
  locals: [127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],
418
- localNames: ["input","input#type","keyStr","keyStrPtr","len","output","__length_setter_tmp","i","j","endPtr","endPtr#type","chr1","chr2","#last_type","chr3","enc1","enc2","enc3","enc4"],
418
+ localNames: ["input","input#type","keyStr","keyStrPtr","len","output","i","j","endPtr","endPtr#type","chr1","chr2","#last_type","chr3","enc1","enc2","enc3","enc4","__length_setter_tmp"],
419
419
  data: [{"bytes":[65,0,0,0,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47,61],"offset":0}],
420
420
  };
421
+ this.atob = {
422
+ wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: atob/lut', 'i8') * pageSize, 127),[34,2],[33,3],...number(allocPage(scope, 'bytestring: atob/output', 'i8') * pageSize, 127),[33,4],[32,0],[33,5],[32,4],[33,6],[32,5],[32,0],[40,1,0],[106],[33,7],[65,0],[33,8],[3,64],[32,5],[32,7],[72],[4,64],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[33,9],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,10],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,12],[32,5],[32,7],[72],[4,127],[32,3],[32,5],[32,5],[65,1],[106],[33,5],[45,0,4],[106],[45,0,4],[65,0],[33,11],[5],[65,127],[65,0],[33,11],[11],[33,13],[32,9],[65,2],[116],[32,10],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,10],[65,4],[117],[65,0],[33,11],[11],[114],[33,14],[32,10],[65,15],[113],[65,4],[116],[32,12],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,12],[65,2],[117],[65,0],[33,11],[11],[114],[33,15],[32,12],[65,3],[113],[65,6],[116],[32,13],[65,127],[70],[4,127],[65,0],[65,0],[33,11],[5],[32,13],[65,0],[33,11],[11],[114],[33,16],[32,6],[32,6],[65,1],[106],[33,6],[32,14],[58,0,4],[32,12],[65,192,0],[71],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[32,15],[58,0,4],[11],[32,13],[65,192,0],[71],[4,64],[32,6],[32,6],[65,1],[106],[33,6],[32,16],[58,0,4],[11],[12,1],[11],[11],[32,4],[32,6],[32,4],[107],[34,17],[54,1,0],[32,4],[15]],
423
+ params: [127,127],
424
+ typedParams: true,
425
+ returns: [127],
426
+ returnType: 18,
427
+ locals: [127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127],
428
+ localNames: ["input","input#type","lut","lutPtr","output","i","j","endPtr","endPtr#type","enc1","enc2","#last_type","enc3","enc4","chr1","chr2","chr3","__length_setter_tmp"],
429
+ data: [{"bytes":[123,0,0,0,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,64,62,64,64,64,63,52,53,54,55,56,57,58,59,60,61,64,64,64,64,64,64,64,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,64,64,64,64,64,64,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],"offset":0}],
430
+ };
421
431
  this.__Boolean_prototype_toString = {
422
432
  wasm: (scope, {allocPage,}) => [...number(allocPage(scope, 'bytestring: __Boolean_prototype_toString/out', 'i8') * pageSize, 124),[33,2],[32,0],[252,3],[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],[33,2],[5],[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],[33,2],[11],[32,2],[65,18],[15]],
423
433
  params: [124,127],
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.17.0-9c7bd8098",
4
+ "version": "0.17.0-bf4206d7b",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},