porffor 0.2.0-eaee2da → 0.2.0-eeb45f8

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.
@@ -1260,7 +1260,9 @@ const getNodeType = (scope, node) => {
1260
1260
  // hack: if something.length, number type
1261
1261
  if (node.property.name === 'length') return TYPES.number;
1262
1262
 
1263
- // we cannot guess
1263
+ if (scope.locals['#last_type']) return [ getLastType(scope) ];
1264
+
1265
+ // presume
1264
1266
  return TYPES.number;
1265
1267
  }
1266
1268
 
@@ -2401,7 +2403,7 @@ const generateForOf = (scope, decl) => {
2401
2403
  // // todo: we should only do this for strings but we don't know at compile-time :(
2402
2404
  // hack: this is naughty and will break things!
2403
2405
  let newOut = number(0, Valtype.f64), newPointer = -1;
2404
- if (pages.hasString) {
2406
+ if (pages.hasAnyString) {
2405
2407
  0, [ newOut, newPointer ] = makeArray(scope, {
2406
2408
  rawElements: new Array(1)
2407
2409
  }, isGlobal, leftName, true, 'i16');
@@ -2594,6 +2596,8 @@ const allocPage = (reason, type) => {
2594
2596
 
2595
2597
  if (reason.startsWith('array:')) pages.hasArray = true;
2596
2598
  if (reason.startsWith('string:')) pages.hasString = true;
2599
+ if (reason.startsWith('bytestring:')) pages.hasByteString = true;
2600
+ if (reason.includes('string:')) pages.hasAnyString = true;
2597
2601
 
2598
2602
  const ind = pages.size;
2599
2603
  pages.set(reason, { ind, type });
@@ -2771,10 +2775,13 @@ export const generateMember = (scope, decl, _global, _name) => {
2771
2775
  ];
2772
2776
  }
2773
2777
 
2778
+ const object = generate(scope, decl.object);
2779
+ const property = generate(scope, decl.property);
2780
+
2774
2781
  // // todo: we should only do this for strings but we don't know at compile-time :(
2775
2782
  // hack: this is naughty and will break things!
2776
2783
  let newOut = number(0, valtypeBinary), newPointer = -1;
2777
- if (pages.hasString) {
2784
+ if (pages.hasAnyString) {
2778
2785
  0, [ newOut, newPointer ] = makeArray(scope, {
2779
2786
  rawElements: new Array(1)
2780
2787
  }, _global, _name, true, 'i16');
@@ -2783,7 +2790,7 @@ export const generateMember = (scope, decl, _global, _name) => {
2783
2790
  return typeSwitch(scope, getNodeType(scope, decl.object), {
2784
2791
  [TYPES._array]: [
2785
2792
  // get index as valtype
2786
- ...generate(scope, decl.property),
2793
+ ...property,
2787
2794
 
2788
2795
  // convert to i32 and turn into byte offset by * valtypeSize (4 for i32, 8 for i64/f64)
2789
2796
  Opcodes.i32_to_u,
@@ -2791,7 +2798,7 @@ export const generateMember = (scope, decl, _global, _name) => {
2791
2798
  [ Opcodes.i32_mul ],
2792
2799
 
2793
2800
  ...(aotPointer ? [] : [
2794
- ...generate(scope, decl.object),
2801
+ ...object,
2795
2802
  Opcodes.i32_to_u,
2796
2803
  [ Opcodes.i32_add ]
2797
2804
  ]),
@@ -2810,14 +2817,14 @@ export const generateMember = (scope, decl, _global, _name) => {
2810
2817
 
2811
2818
  ...number(0, Valtype.i32), // base 0 for store later
2812
2819
 
2813
- ...generate(scope, decl.property),
2814
-
2820
+ ...property,
2815
2821
  Opcodes.i32_to_u,
2822
+
2816
2823
  ...number(ValtypeSize.i16, Valtype.i32),
2817
2824
  [ Opcodes.i32_mul ],
2818
2825
 
2819
2826
  ...(aotPointer ? [] : [
2820
- ...generate(scope, decl.object),
2827
+ ...object,
2821
2828
  Opcodes.i32_to_u,
2822
2829
  [ Opcodes.i32_add ]
2823
2830
  ]),
@@ -2834,6 +2841,34 @@ export const generateMember = (scope, decl, _global, _name) => {
2834
2841
  ...number(TYPES.string, Valtype.i32),
2835
2842
  setLastType(scope)
2836
2843
  ],
2844
+ [TYPES._bytestring]: [
2845
+ // setup new/out array
2846
+ ...newOut,
2847
+ [ Opcodes.drop ],
2848
+
2849
+ ...number(0, Valtype.i32), // base 0 for store later
2850
+
2851
+ ...property,
2852
+ Opcodes.i32_to_u,
2853
+
2854
+ ...(aotPointer ? [] : [
2855
+ ...object,
2856
+ Opcodes.i32_to_u,
2857
+ [ Opcodes.i32_add ]
2858
+ ]),
2859
+
2860
+ // load current string ind {arg}
2861
+ [ Opcodes.i32_load8_u, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128((aotPointer ? pointer : 0) + ValtypeSize.i32) ],
2862
+
2863
+ // store to new string ind 0
2864
+ [ Opcodes.i32_store8, Math.log2(ValtypeSize.i16) - 1, ...unsignedLEB128(newPointer + ValtypeSize.i32) ],
2865
+
2866
+ // return new string (page)
2867
+ ...number(newPointer),
2868
+
2869
+ ...number(TYPES._bytestring, Valtype.i32),
2870
+ setLastType(scope)
2871
+ ],
2837
2872
 
2838
2873
  default: [ [ Opcodes.unreachable ] ]
2839
2874
  });
@@ -2915,10 +2950,8 @@ const generateFunc = (scope, decl) => {
2915
2950
  const func = {
2916
2951
  name,
2917
2952
  params: Object.values(innerScope.locals).slice(0, params.length * 2).map(x => x.type),
2918
- returns: innerScope.returns,
2919
- locals: innerScope.locals,
2920
- throws: innerScope.throws,
2921
- index: currentFuncIndex++
2953
+ index: currentFuncIndex++,
2954
+ ...innerScope
2922
2955
  };
2923
2956
  funcIndex[name] = func.index;
2924
2957
 
package/compiler/opt.js CHANGED
@@ -192,6 +192,7 @@ export default (funcs, globals, pages, tags) => {
192
192
  let missing = false;
193
193
  if (type === 'Array') missing = !pages.hasArray;
194
194
  if (type === 'String') missing = !pages.hasString;
195
+ if (type === 'ByteString') missing = !pages.hasByteString;
195
196
 
196
197
  if (missing) {
197
198
  let j = i, depth = 0;
package/compiler/wrap.js CHANGED
@@ -49,6 +49,9 @@ export default async (source, flags = [ 'module' ], customImports = {}, print =
49
49
  }
50
50
  });
51
51
  } catch (e) {
52
+ // only backtrace for runner, not test262/etc
53
+ if (!process.argv[1].includes('/runner')) throw e;
54
+
52
55
  const funcInd = parseInt(e.message.match(/function #([0-9]+) /)[1]);
53
56
  const blobOffset = parseInt(e.message.split('@')[1]);
54
57
 
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.2.0-eaee2da",
4
+ "version": "0.2.0-eeb45f8",
5
5
  "author": "CanadaHonk",
6
6
  "license": "MIT",
7
7
  "dependencies": {