porffor 0.16.0-fa3914030 → 0.17.0-418ce1445

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.
@@ -7,12 +7,11 @@ export const btoa = (input: bytestring): bytestring => {
7
7
 
8
8
  let len: i32 = input.length;
9
9
  let output: bytestring = '';
10
- output.length = 4 * (len / 3 + !!(len % 3));
11
10
 
12
11
  let i: i32 = Porffor.wasm`local.get ${input}`,
13
12
  j: i32 = Porffor.wasm`local.get ${output}`;
14
13
 
15
- // todo/perf: add some per 6 char variant using bitwise magic
14
+ // todo/perf: add some per 6 char variant using bitwise magic?
16
15
 
17
16
  const endPtr = i + len;
18
17
  while (i < endPtr) {
@@ -38,40 +37,43 @@ export const btoa = (input: bytestring): bytestring => {
38
37
  Porffor.wasm.i32.store8(j++, Porffor.wasm.i32.load8_u(keyStrPtr + enc4, 0, 4), 0, 4);
39
38
  }
40
39
 
40
+ output.length = j - Porffor.wasm`local.get ${output}`;
41
41
  return output;
42
42
  };
43
43
 
44
44
  // todo: impl atob by converting below to "porf ts"
45
- /* var atob = function (input) {
46
- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
45
+ export const atob = (input: bytestring): bytestring => {
46
+ // todo: handle non-base64 chars properly
47
+ 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';
48
+ const lutPtr: i32 = Porffor.wasm`local.get ${lut}`;
47
49
 
48
- let output = "";
49
- let chr1, chr2, chr3;
50
- let enc1, enc2, enc3, enc4;
51
- let i = 0;
50
+ let output: bytestring = '';
51
+
52
+ let i: i32 = Porffor.wasm`local.get ${input}`,
53
+ j: i32 = Porffor.wasm`local.get ${output}`;
52
54
 
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++));
55
+ const endPtr = i + input.length;
56
+ while (i < endPtr) {
57
+ const enc1: i32 = Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4);
58
+ const enc2: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
59
+ const enc3: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
60
+ const enc4: i32 = i < endPtr ? Porffor.wasm.i32.load8_u(lutPtr + Porffor.wasm.i32.load8_u(i++, 0, 4), 0, 4) : -1;
58
61
 
59
- chr1 = (enc1 << 2) | (enc2 >> 4);
60
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
61
- chr3 = ((enc3 & 3) << 6) | enc4;
62
+ const chr1: i32 = (enc1 << 2) | (enc2 == -1 ? 0 : (enc2 >> 4));
63
+ const chr2: i32 = ((enc2 & 15) << 4) | (enc3 == -1 ? 0 : (enc3 >> 2));
64
+ const chr3: i32 = ((enc3 & 3) << 6) | (enc4 == -1 ? 0 : enc4);
62
65
 
63
- // output += String.fromCharCode(chr1);
64
- Porffor.bytestring.appendCharCode(output, chr1);
66
+ Porffor.wasm.i32.store8(j++, chr1, 0, 4);
65
67
 
66
68
  if (enc3 != 64) {
67
- // output += String.fromCharCode(chr2);
68
- Porffor.bytestring.appendCharCode(output, chr2);
69
+ Porffor.wasm.i32.store8(j++, chr2, 0, 4);
69
70
  }
71
+
70
72
  if (enc4 != 64) {
71
- // output += String.fromCharCode(chr3);
72
- Porffor.bytestring.appendCharCode(output, chr3);
73
+ Porffor.wasm.i32.store8(j++, chr3, 0, 4);
73
74
  }
74
75
  }
75
76
 
77
+ output.length = j - Porffor.wasm`local.get ${output}`;
76
78
  return output;
77
- }; */
79
+ };
@@ -150,7 +150,7 @@ export const BuiltinVars = function() {
150
150
  this.Math = number(1);
151
151
 
152
152
  // wintercg(tm)
153
- this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.16.0`, false, '__navigator_userAgent');
153
+ this.__navigator_userAgent = (scope, { makeString }) => makeString(scope, `Porffor/0.17.0`, false, '__navigator_userAgent');
154
154
  this.__navigator_userAgent.type = Prefs.bytestring ? TYPES.bytestring : TYPES.string;
155
155
 
156
156
  for (const x in TYPES) {
@@ -1826,7 +1826,7 @@ const generateCall = (scope, decl, _global, _name, unusedValue = false) => {
1826
1826
  if (indirectMode === 'strict') {
1827
1827
  return typeSwitch(scope, getNodeType(scope, decl.callee), {
1828
1828
  [TYPES.function]: [
1829
- ...argWasm,
1829
+ ...out,
1830
1830
  [ global ? Opcodes.global_get : Opcodes.local_get, local.idx ],
1831
1831
  Opcodes.i32_to_u,
1832
1832
  [ Opcodes.call_indirect, args.length, 0 ],
@@ -3665,6 +3665,9 @@ const generateFunc = (scope, decl) => {
3665
3665
  index: currentFuncIndex++
3666
3666
  };
3667
3667
 
3668
+ funcIndex[name] = func.index;
3669
+ funcs.push(func);
3670
+
3668
3671
  if (typedInput && decl.returnType) {
3669
3672
  const { type } = extractTypeAnnotation(decl.returnType);
3670
3673
  // if (type != null && !Prefs.indirectCalls) {
@@ -3674,12 +3677,26 @@ const generateFunc = (scope, decl) => {
3674
3677
  }
3675
3678
  }
3676
3679
 
3680
+ const defaultValues = {};
3677
3681
  for (let i = 0; i < params.length; i++) {
3678
- const name = params[i].name;
3682
+ let name;
3683
+ const x = params[i];
3684
+ switch (x.type) {
3685
+ case 'Identifier': {
3686
+ name = x.name;
3687
+ break;
3688
+ }
3689
+
3690
+ case 'AssignmentPattern': {
3691
+ name = x.left.name;
3692
+ defaultValues[name] = x.right;
3693
+ break;
3694
+ }
3695
+ }
3696
+
3679
3697
  // if (name == null) return todo('non-identifier args are not supported');
3680
3698
 
3681
3699
  allocVar(func, name, false);
3682
-
3683
3700
  if (typedInput && params[i].typeAnnotation) {
3684
3701
  addVarMetadata(func, name, false, extractTypeAnnotation(params[i]));
3685
3702
  }
@@ -3696,11 +3713,22 @@ const generateFunc = (scope, decl) => {
3696
3713
  };
3697
3714
  }
3698
3715
 
3699
- funcIndex[name] = func.index;
3700
- funcs.push(func);
3716
+ const prelude = [];
3717
+ for (const x in defaultValues) {
3718
+ prelude.push(
3719
+ ...getType(func, x),
3720
+ ...number(TYPES.undefined, Valtype.i32),
3721
+ [ Opcodes.i32_eq ],
3722
+ [ Opcodes.if, Blocktype.void ],
3723
+ ...generate(func, defaultValues[x], false, x),
3724
+ [ Opcodes.local_set, func.locals[x].idx ],
3701
3725
 
3702
- const wasm = generate(func, body);
3703
- func.wasm = wasm;
3726
+ ...setType(func, x, getNodeType(scope, defaultValues[x])),
3727
+ [ Opcodes.end ]
3728
+ );
3729
+ }
3730
+
3731
+ const wasm = func.wasm = prelude.concat(generate(func, body));
3704
3732
 
3705
3733
  if (name === 'main') func.gotLastType = true;
3706
3734
 
@@ -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.16.0-fa3914030",
4
+ "version": "0.17.0-418ce1445",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "scripts": {},