porffor 0.34.9 → 0.34.11

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.
@@ -103,9 +103,6 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
103
103
  importDelta = importedFuncs.length - importFuncs.length;
104
104
  }
105
105
 
106
- // fix call indexes for non-imports
107
- // also fix call_indirect types
108
- // also encode call indexes
109
106
  for (const f of funcs) {
110
107
  f.asmIndex = f.index - importDelta;
111
108
  }
@@ -320,7 +317,8 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
320
317
  // encode call ops as unsigned leb128 from raw number
321
318
  if ((o[0] === Opcodes.call /* || o[0] === Opcodes.return_call */) && o[1] >= importedFuncs.length) {
322
319
  const n = o[1] - importDelta;
323
- o = [ o[0] ];
320
+ // o = [ o[0] ];
321
+ o = [ Opcodes.call ];
324
322
  unsignedLEB128_into(n, o);
325
323
  }
326
324
 
@@ -377,8 +375,7 @@ export default (funcs, globals, tags, pages, data, flags, noTreeshake = false) =
377
375
  encodeVector(data.map(x => {
378
376
  if (Prefs.d && x.bytes.length > PageSize) log.warning('assemble', `data (${x.page}) has more bytes than Wasm page size! (${x.bytes.length})`);
379
377
 
380
- const bytes = encodeVector(x.bytes);
381
-
378
+ const bytes = unsignedLEB128(x.bytes.length).concat(x.bytes);
382
379
  if (x.page != null) {
383
380
  // type: active
384
381
  let offset = pages.get(x.page).ind * pageSize;
@@ -5,8 +5,13 @@ export const __Porffor_object_getObject = (obj: any): any => {
5
5
  let underlying: object = underlyingFuncObjs.get(funcI32);
6
6
  if (underlying == null) {
7
7
  underlying = {};
8
- underlying.prototype = {};
9
- underlying.prototype.constructor = obj;
8
+
9
+ const proto = {};
10
+ const key1: bytestring = 'prototype';
11
+ __Porffor_object_expr_initWithFlags(underlying, key1, proto, 0b1000);
12
+
13
+ const key2: bytestring = 'constructor';
14
+ __Porffor_object_expr_initWithFlags(proto, key2, obj, 0b1010);
10
15
 
11
16
  underlyingFuncObjs.set(funcI32, underlying);
12
17
  }
@@ -572,6 +572,30 @@ export const __Porffor_object_expr_init = (obj: any, key: any, value: any): void
572
572
  0, 12);
573
573
  };
574
574
 
575
+ export const __Porffor_object_expr_initWithFlags = (obj: any, key: any, value: any, flags: i32): void => {
576
+ if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
577
+ let entryPtr: i32 = __Porffor_object_lookup(obj, key);
578
+ if (entryPtr == -1) {
579
+ // add new entry
580
+ // bump size +1
581
+ const size: i32 = Porffor.wasm.i32.load(obj, 0, 0);
582
+ Porffor.wasm.i32.store(obj, size + 1, 0, 0);
583
+
584
+ // entryPtr = current end of object
585
+ entryPtr = Porffor.wasm`local.get ${obj}` + 5 + size * 14;
586
+
587
+ __Porffor_object_writeKey(entryPtr, key);
588
+ }
589
+
590
+ // write new value value (lol)
591
+ Porffor.wasm.f64.store(entryPtr, value, 0, 4);
592
+
593
+ // write new tail (value type + flags)
594
+ Porffor.wasm.i32.store16(entryPtr,
595
+ flags + (Porffor.wasm`local.get ${value+1}` << 8),
596
+ 0, 12);
597
+ };
598
+
575
599
  // used for { get foo() {} }
576
600
  export const __Porffor_object_expr_get = (obj: any, key: any, get: any): void => {
577
601
  if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) obj = __Porffor_object_getObject(obj);
@@ -1746,9 +1746,7 @@ export const __ecma262_ToDateString = (tv: number) => {
1746
1746
  out.length = 0;
1747
1747
 
1748
1748
  // 1. If tv is NaN, return "Invalid Date".
1749
- if (Number.isNaN(tv)) {
1750
- return out = 'Invalid Date';
1751
- }
1749
+ if (Number.isNaN(tv)) return out = 'Invalid Date';
1752
1750
 
1753
1751
  // 2. Let t be LocalTime(tv).
1754
1752
  const t: number = __ecma262_LocalTime(tv);
@@ -1788,10 +1786,7 @@ export const __Date_prototype_toTimeString = (_this: Date) => {
1788
1786
  let out: bytestring = Porffor.allocateBytes(27);
1789
1787
  out.length = 0;
1790
1788
 
1791
- if (Number.isNaN(tv)) {
1792
- out = 'Invalid Date';
1793
- return out;
1794
- }
1789
+ if (Number.isNaN(tv)) return out = 'Invalid Date';
1795
1790
 
1796
1791
  // 5. Let t be LocalTime(tv).
1797
1792
  const t: number = __ecma262_LocalTime(tv);
@@ -1816,10 +1811,7 @@ export const __Date_prototype_toDateString = (_this: Date) => {
1816
1811
  let out: bytestring = Porffor.allocateBytes(20);
1817
1812
  out.length = 0;
1818
1813
 
1819
- if (Number.isNaN(tv)) {
1820
- out = 'Invalid Date';
1821
- return out;
1822
- }
1814
+ if (Number.isNaN(tv)) return out = 'Invalid Date';
1823
1815
 
1824
1816
  // 5. Let t be LocalTime(tv).
1825
1817
  const t: number = __ecma262_LocalTime(tv);
@@ -1495,6 +1495,41 @@ export const __ByteString_prototype_localeCompare = (_this: bytestring, compareS
1495
1495
  };
1496
1496
 
1497
1497
 
1498
+ export const __String_prototype_isWellFormed = (_this: string) => {
1499
+ let ptr: i32 = Porffor.wasm`local.get ${_this}`;
1500
+ const endPtr: i32 = ptr + _this.length * 2;
1501
+ while (ptr < endPtr) {
1502
+ const c1: i32 = Porffor.wasm.i32.load16_u(ptr, 0, 4);
1503
+
1504
+ if (Porffor.fastAnd(c1 >= 0xDC00, c1 <= 0xDFFF)) {
1505
+ // lone trailing surrogate, bad
1506
+ return false;
1507
+ }
1508
+
1509
+ if (Porffor.fastAnd(c1 >= 0xD800, c1 <= 0xDBFF)) {
1510
+ // leading surrogate, peek if next is trailing
1511
+ const c2: i32 = ptr + 2 < endPtr ? Porffor.wasm.i32.load16_u(ptr + 2, 0, 4) : 0;
1512
+
1513
+ if (Porffor.fastAnd(c2 >= 0xDC00, c2 <= 0xDFFF)) {
1514
+ // next is trailing surrogate, skip it too
1515
+ ptr += 2;
1516
+ } else {
1517
+ // lone leading surrogate, bad
1518
+ return false;
1519
+ }
1520
+ }
1521
+
1522
+ ptr += 2;
1523
+ }
1524
+
1525
+ return true;
1526
+ };
1527
+
1528
+ export const __ByteString_prototype_isWellFormed = (_this: bytestring) => {
1529
+ // bytestrings cannot have surrogates, so always true
1530
+ return true;
1531
+ };
1532
+
1498
1533
  export const __String_prototype_toWellFormed = (_this: string) => {
1499
1534
  let out: string = Porffor.allocate();
1500
1535
  Porffor.clone(_this, out);
@@ -3,10 +3,10 @@ import { number } from './embedding.js';
3
3
 
4
4
  export const BuiltinFuncs = function() {
5
5
  this.__Porffor_object_getObject = {
6
- wasm:(_,{glbl,builtin,internalThrow})=>[[32,1],[184],[68,6],[97],[4,64],[32,0],[33,2],...glbl(35,'underlyingFuncObjs',124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[16,builtin('__Map_prototype_get')],[26],[34,3],[68,0],[97],[4,64],[16,builtin('__Porffor_allocate')],[184],[34,3],[33,9],[16,builtin('__Porffor_allocate')],[34,11],[65,9],[54,1,0],[32,11],[65,240,0],[58,0,4],[32,11],[65,242,0],[58,0,5],[32,11],[65,239,0],[58,0,6],[32,11],[65,244,0],[58,0,7],[32,11],[65,239,0],[58,0,8],[32,11],[65,244,0],[58,0,9],[32,11],[65,249,0],[58,0,10],[32,11],[65,240,0],[58,0,11],[32,11],[65,229,0],[58,0,12],[32,11],[184],[33,10],[32,9],[252,3],[65,7],[32,10],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[16,builtin('__Porffor_allocate')],[184],[65,7],[16,builtin('__Porffor_object_set')],[26],[26],[32,3],[33,9],[65,128,128,4],[34,11],[65,9],[54,1,0],[32,11],[65,240,0],[58,0,4],[32,11],[65,242,0],[58,0,5],[32,11],[65,239,0],[58,0,6],[32,11],[65,244,0],[58,0,7],[32,11],[65,239,0],[58,0,8],[32,11],[65,244,0],[58,0,9],[32,11],[65,249,0],[58,0,10],[32,11],[65,240,0],[58,0,11],[32,11],[65,229,0],[58,0,12],[32,11],[184],[33,13],[32,9],[252,3],[65,7],[32,13],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[16,builtin('__Porffor_object_get')],[33,6],[33,9],[16,builtin('__Porffor_allocate')],[34,11],[65,11],[54,1,0],[32,11],[65,227,0],[58,0,4],[32,11],[65,239,0],[58,0,5],[32,11],[65,238,0],[58,0,6],[32,11],[65,243,0],[58,0,7],[32,11],[65,244,0],[58,0,8],[32,11],[65,242,0],[58,0,9],[32,11],[65,245,0],[58,0,10],[32,11],[65,227,0],[58,0,11],[32,11],[65,244,0],[58,0,12],[32,11],[65,239,0],[58,0,13],[32,11],[65,242,0],[58,0,14],[32,11],[184],[33,10],[32,6],[33,16],[2,124],[32,16],[65,6],[70],[4,64,"TYPESWITCH|Function"],[32,9],[252,3],[32,6],[32,10],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[32,0],[32,1],[16,builtin('__Porffor_object_set')],[26],[12,1],[11],[32,16],[65,7],[70],[4,64,"TYPESWITCH|Object"],[32,9],[252,3],[32,6],[32,10],[65,195,1],[16,builtin('__ecma262_ToPropertyKey')],[33,12],[252,3],[32,12],[32,0],[32,1],[16,builtin('__Porffor_object_set')],[26],[12,1],[11],[32,16],[65,208,0],[70],[4,64,"TYPESWITCH|Array"],[32,9],[252,3],[32,10],[252,3],[65,9],[108],[106],[34,8],[32,0],[34,7],[57,0,4],[32,8],[32,1],[58,0,12],[32,7],[12,1],[11],[32,16],[65,216,0],[70],[4,64,"TYPESWITCH|Uint8Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[252,3],[58,0,4],[32,7],[12,1],[11],[32,16],[65,217,0],[70],[4,64,"TYPESWITCH|Int8Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[252,2],[58,0,4],[32,7],[12,1],[11],[32,16],[65,218,0],[70],[4,64,"TYPESWITCH|Uint8ClampedArray"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[106],[32,0],[34,7],[68,0],[165],[68,255],[164],[252,3],[58,0,4],[32,7],[12,1],[11],[32,16],[65,219,0],[70],[4,64,"TYPESWITCH|Uint16Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,2],[108],[106],[32,0],[34,7],[252,3],[59,0,4],[32,7],[12,1],[11],[32,16],[65,220,0],[70],[4,64,"TYPESWITCH|Int16Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,2],[108],[106],[32,0],[34,7],[252,2],[59,0,4],[32,7],[12,1],[11],[32,16],[65,221,0],[70],[4,64,"TYPESWITCH|Uint32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[252,3],[54,0,4],[32,7],[12,1],[11],[32,16],[65,222,0],[70],[4,64,"TYPESWITCH|Int32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[252,2],[54,0,4],[32,7],[12,1],[11],[32,16],[65,223,0],[70],[4,64,"TYPESWITCH|Float32Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,4],[108],[106],[32,0],[34,7],[182],[56,0,4],[32,7],[12,1],[11],[32,16],[65,224,0],[70],[4,64,"TYPESWITCH|Float64Array"],[32,9],[252,3],[40,0,4],[32,10],[252,3],[65,8],[108],[106],[32,0],[34,7],[57,0,4],[32,7],[12,1],[11],[32,16],[65,128,1],[70],[4,64,"TYPESWITCH|undefined"],...internalThrow(_,'TypeError',`Cannot set property of undefined`),[68,0],[12,1],[11],[32,0],[11,"TYPESWITCH_end"],[26],...glbl(35,'underlyingFuncObjs',124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[32,3],[65,7],[16,builtin('__Map_prototype_set')],[33,6],[26],[11],[32,3],[65,7],[15],[11],[32,0],[32,1],[15]],
6
+ wasm:(_,{allocPage,glbl,builtin})=>[[32,1],[184],[68,6],[97],[4,64],[32,0],[33,2],...glbl(35,'underlyingFuncObjs',124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[16,builtin('__Map_prototype_get')],[26],[34,3],[68,0],[97],[4,64],[16,builtin('__Porffor_allocate')],[184],[33,3],[16,builtin('__Porffor_allocate')],[184],[33,7],[65,7],[33,8],...number(allocPage(_,'bytestring: __Porffor_object_getObject/key1','i8'),124),[33,9],[32,3],[252,2],[65,7],[32,9],[252,2],[65,195,1],[32,7],[32,8],[65,8],[65,1],[16,builtin('__Porffor_object_expr_initWithFlags')],[33,6],[183],[26],...number(allocPage(_,'bytestring: __Porffor_object_getObject/key2','i8'),124),[33,10],[32,7],[252,2],[32,8],[32,10],[252,2],[65,195,1],[32,0],[32,1],[65,10],[65,1],[16,builtin('__Porffor_object_expr_initWithFlags')],[33,6],[183],[26],...glbl(35,'underlyingFuncObjs',124),[33,4],[65,20],[33,5],[32,4],[32,5],[32,2],[65,1],[32,3],[65,7],[16,builtin('__Map_prototype_set')],[33,6],[26],[11],[32,3],[65,7],[15],[11],[32,0],[32,1],[15]],
7
7
  params:[124,127],typedParams:1,returns:[124,127],typedReturns:1,
8
- locals:[124,124,124,127,127,124,127,124,124,127,127,124,127,127,127],localNames:["obj","obj#type","funcI32","underlying","#proto_target","#proto_target#type","#last_type","#member_setter_val_tmp","#member_setter_ptr_tmp","#member_obj","#member_prop_assign","#makearray_pointer_tmp","#swap","#member_prop","#loadArray_offset","#member_allocd","#typeswitch_tmp1"],
9
- globalInits:{underlyingFuncObjs:(_,{glbl,builtin})=>[[68,1],[65,6],[16,builtin('__Porffor_allocate')],[184],[65,7],[68,0],[65,128,1],[16,builtin('Map')],[26],...glbl(36,'underlyingFuncObjs',124)]},
8
+ locals:[124,124,124,127,127,124,127,124,124],localNames:["obj","obj#type","funcI32","underlying","#proto_target","#proto_target#type","#last_type","proto","proto#type","key1","key2"],
9
+ globalInits:{underlyingFuncObjs:(_,{glbl,builtin})=>[[68,1],[65,6],[16,builtin('__Porffor_allocate')],[184],[65,7],[68,0],[65,128,1],[16,builtin('Map')],[26],...glbl(36,'underlyingFuncObjs',124)]},data:{"bytestring: __Porffor_object_getObject/key1":[9,0,0,0,112,114,111,116,111,116,121,112,101],"bytestring: __Porffor_object_getObject/key2":[11,0,0,0,99,111,110,115,116,114,117,99,116,111,114]},
10
10
  };
11
11
  this.__Porffor_strcmp = {
12
12
  wasm:()=>[[32,0],[32,2],[70],[4,64],[65,1],[65,2],[15],[11],[32,0],[40,0,0],[33,4],[32,2],[40,0,0],[33,5],[32,4],[32,5],[71],[4,64],[65,0],[65,2],[15],[11],[32,1],[65,195,1],[70],[4,64],[32,3],[65,195,1],[70],[4,64],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[106],[45,0,4],[32,2],[32,6],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[106],[45,0,4],[32,2],[32,6],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[11],[5],[32,3],[65,195,1],[70],[4,64],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[65,2],[108],[106],[47,0,4],[32,2],[32,6],[106],[45,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[5],[65,0],[33,6],[3,64],[32,6],[32,4],[72],[4,64],[32,0],[32,6],[65,2],[108],[106],[47,0,4],[32,2],[32,6],[65,2],[108],[106],[47,0,4],[71],[4,64],[65,0],[65,2],[15],[11],[32,6],[65,1],[106],[33,6],[12,1],[11],[11],[65,1],[65,2],[15],[11],[11],[65,0],[65,128,1],[15]],
@@ -105,6 +105,11 @@ wasm:(_,{builtin})=>[[32,1],[65,7],[71],[4,64],[32,0],[184],[32,1],[16,builtin('
105
105
  params:[127,127,127,127,124,127],typedParams:1,returns:[127,127],typedReturns:1,
106
106
  locals:[127,127,127],localNames:["obj","obj#type","key","key#type","value","value#type","#last_type","entryPtr","size"],
107
107
  };
108
+ this.__Porffor_object_expr_initWithFlags = {
109
+ wasm:(_,{builtin})=>[[32,1],[65,7],[71],[4,64],[32,0],[184],[32,1],[16,builtin('__Porffor_object_getObject')],[33,8],[252,2],[34,0],[32,8],[33,1],[26],[11],[32,0],[32,1],[32,2],[32,3],[16,builtin('__Porffor_object_lookup')],[26],[34,9],[65,127],[70],[4,64],[32,0],[40,0,0],[33,10],[32,0],[32,10],[65,1],[106],[54,0,0],[32,0],[65,5],[106],[32,10],[65,14],[108],[106],[34,9],[65,1],[32,2],[32,3],[16,builtin('__Porffor_object_writeKey')],[33,8],[26],[11],[32,9],[32,4],[57,0,4],[32,9],[32,6],[32,5],[65,8],[116],[106],[59,0,12],[65,0],[65,128,1],[15]],
110
+ params:[127,127,127,127,124,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
111
+ locals:[127,127,127],localNames:["obj","obj#type","key","key#type","value","value#type","flags","flags#type","#last_type","entryPtr","size"],
112
+ };
108
113
  this.__Porffor_object_expr_get = {
109
114
  wasm:(_,{builtin})=>[[32,1],[65,7],[71],[4,64],[32,0],[184],[32,1],[16,builtin('__Porffor_object_getObject')],[33,6],[252,2],[34,0],[32,6],[33,1],[26],[11],[32,0],[32,1],[32,2],[32,3],[16,builtin('__Porffor_object_lookup')],[26],[33,7],[65,0],[33,8],[65,128,1],[33,9],[32,7],[65,127],[70],[4,64],[32,0],[40,0,0],[33,10],[32,0],[32,10],[65,1],[106],[54,0,0],[32,0],[65,5],[106],[32,10],[65,14],[108],[106],[34,7],[65,1],[32,2],[32,3],[16,builtin('__Porffor_object_writeKey')],[33,6],[26],[5],[32,7],[65,1],[16,builtin('__Porffor_object_accessorSet')],[33,9],[33,8],[11],[32,7],[32,4],[32,5],[32,8],[32,9],[16,builtin('__Porffor_object_packAccessor')],[33,6],[57,0,4],[32,7],[65,15],[65,1],[65,8],[116],[106],[59,0,12],[65,0],[65,128,1],[15]],
110
115
  params:[127,127,127,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
@@ -2248,6 +2253,16 @@ wasm:(_,{builtin,internalThrow})=>[[32,2],[184],[32,3],[16,builtin('__ecma262_To
2248
2253
  params:[127,127,127,127],typedParams:1,returns:[127,127],typedReturns:1,
2249
2254
  locals:[127,127,127,127,127,127,127,127,127,127,127],localNames:["_this","_this#type","compareString","compareString#type","#last_type","thisLen","compareLen","maxLen","i","a","__proto_length_cache","__proto_pointer_cache","__charCodeAt_tmp","b","#typeswitch_tmp1"],
2250
2255
  };
2256
+ this.__String_prototype_isWellFormed = {
2257
+ wasm:()=>[[32,0],[34,2],[32,0],[40,1,0],[65,2],[108],[106],[33,3],[3,64],[32,2],[32,3],[72],[4,64],[32,2],[47,0,4],[34,4],[65,128,184,3],[78],[32,4],[65,255,191,3],[76],[113],[4,64],[65,0],[65,2],[15],[11],[32,4],[65,128,176,3],[78],[32,4],[65,255,183,3],[76],[113],[4,64],[32,2],[65,2],[106],[32,3],[72],[4,127],[32,2],[65,2],[106],[47,0,4],[65,1],[33,6],[5],[65,0],[65,1],[33,6],[11],[34,5],[65,128,184,3],[78],[32,5],[65,255,191,3],[76],[113],[4,64],[32,2],[65,2],[106],[33,2],[5],[65,0],[65,2],[15],[11],[11],[32,2],[65,2],[106],[33,2],[12,1],[11],[11],[65,1],[65,2],[15]],
2258
+ params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
2259
+ locals:[127,127,127,127,127],localNames:["_this","_this#type","ptr","endPtr","c1","c2","#last_type"],
2260
+ };
2261
+ this.__ByteString_prototype_isWellFormed = {
2262
+ wasm:()=>[[65,1],[65,2],[15]],
2263
+ params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
2264
+ locals:[],localNames:["_this","_this#type"],
2265
+ };
2251
2266
  this.__String_prototype_toWellFormed = {
2252
2267
  wasm:(_,{builtin})=>[[16,builtin('__Porffor_allocate')],[33,2],[32,0],[32,2],[16,builtin('__Porffor_clone')],[32,2],[34,3],[32,2],[40,1,0],[65,2],[108],[106],[33,4],[3,64],[32,3],[32,4],[72],[4,64],[32,3],[47,0,4],[34,5],[65,128,184,3],[78],[32,5],[65,255,191,3],[76],[113],[4,64],[32,3],[65,253,255,3],[59,0,4],[11],[32,5],[65,128,176,3],[78],[32,5],[65,255,183,3],[76],[113],[4,64],[32,3],[65,2],[106],[32,4],[72],[4,127],[32,3],[65,2],[106],[47,0,4],[65,1],[33,7],[5],[65,0],[65,1],[33,7],[11],[34,6],[65,128,184,3],[78],[32,6],[65,255,191,3],[76],[113],[4,64],[32,3],[65,2],[106],[33,3],[5],[32,3],[65,253,255,3],[59,0,4],[11],[11],[32,3],[65,2],[106],[33,3],[12,1],[11],[11],[32,2],[65,195,0],[15]],
2253
2268
  params:[127,127],typedParams:1,returns:[127,127],typedReturns:1,
@@ -102,7 +102,7 @@ const generate = (scope, decl, global = false, name = undefined, valueUnused = f
102
102
  return cacheAst(decl, generateNew(scope, decl, global, name));
103
103
 
104
104
  case 'ThisExpression':
105
- return cacheAst(decl, generateThis(scope, decl, global, name));
105
+ return cacheAst(decl, generateThis(scope, decl));
106
106
 
107
107
  case 'Literal':
108
108
  return cacheAst(decl, generateLiteral(scope, decl, global, name));
@@ -2629,7 +2629,7 @@ const generateNew = (scope, decl, _global, _name) => generateCall(scope, {
2629
2629
  _new: true
2630
2630
  }, _global, _name);
2631
2631
 
2632
- const generateThis = (scope, decl, _global, _name) => {
2632
+ const generateThis = (scope, decl) => {
2633
2633
  if (!scope.constr) {
2634
2634
  // this in a non-constructor context is a reference to globalThis
2635
2635
  return [
@@ -2639,7 +2639,7 @@ const generateThis = (scope, decl, _global, _name) => {
2639
2639
  }
2640
2640
 
2641
2641
  // opt: do not check for pure constructors
2642
- if (scope._onlyConstr) return [
2642
+ if (scope._onlyConstr || scope._onlyThisMethod || decl._noGlobalThis) return [
2643
2643
  [ Opcodes.local_get, scope.locals['#this'].idx ],
2644
2644
  ...setLastType(scope, [ [ Opcodes.local_get, scope.locals['#this#type'].idx ] ])
2645
2645
  ];
@@ -5163,7 +5163,7 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
5163
5163
 
5164
5164
  for (const x of decl.properties) {
5165
5165
  // method, shorthand are made into useful values by parser for us :)
5166
- const { type, argument, computed, kind, key, value } = x;
5166
+ let { type, argument, computed, kind, key, value } = x;
5167
5167
 
5168
5168
  if (type === 'SpreadElement') {
5169
5169
  out.push(
@@ -5189,6 +5189,18 @@ const generateObject = (scope, decl, global = false, name = '$undeclared') => {
5189
5189
  value: key.name
5190
5190
  };
5191
5191
 
5192
+ if (isFuncType(value.type)) {
5193
+ let id = value.id;
5194
+
5195
+ // todo: support computed names properly
5196
+ if (typeof k.value === 'string') id ??= {
5197
+ type: 'Identifier',
5198
+ name: k.value
5199
+ };
5200
+
5201
+ value = { ...value, id };
5202
+ }
5203
+
5192
5204
  out.push(
5193
5205
  [ Opcodes.local_get, tmp ],
5194
5206
  ...number(TYPES.object, Valtype.i32),
@@ -5695,7 +5707,7 @@ const generateClass = (scope, decl) => {
5695
5707
  body: []
5696
5708
  }
5697
5709
  }),
5698
- id: root,
5710
+ id: root
5699
5711
  };
5700
5712
 
5701
5713
  const [ func, out ] = generateFunc(scope, {
@@ -5759,11 +5771,28 @@ const generateClass = (scope, decl) => {
5759
5771
  outArr = func.wasm;
5760
5772
  outOp = 'unshift';
5761
5773
  object = {
5762
- type: 'ThisExpression'
5774
+ type: 'ThisExpression',
5775
+ _noGlobalThis: true
5763
5776
  };
5764
5777
  outScope = func;
5765
5778
  }
5766
5779
 
5780
+ if (isFuncType(value.type) && type === 'MethodDefinition') {
5781
+ let id = value.id;
5782
+
5783
+ // todo: support computed names properly
5784
+ if (typeof k.value === 'string') id ??= {
5785
+ type: 'Identifier',
5786
+ name: k.value
5787
+ };
5788
+
5789
+ value = {
5790
+ ...value,
5791
+ id,
5792
+ _onlyThisMethod: true
5793
+ };
5794
+ }
5795
+
5767
5796
  outArr[outOp](
5768
5797
  ...generate(outScope, object),
5769
5798
  Opcodes.i32_to_u,
@@ -5884,7 +5913,7 @@ const generateFunc = (scope, decl, outUnused = false) => {
5884
5913
  (decl.type && decl.type !== 'ArrowFunctionExpression' && decl.type !== 'Program') &&
5885
5914
  // not async or generator
5886
5915
  !decl.async && !decl.generator,
5887
- _onlyConstr: decl._onlyConstr,
5916
+ _onlyConstr: decl._onlyConstr, _onlyThisMethod: decl._onlyThisMethod,
5888
5917
  strict: scope.strict,
5889
5918
 
5890
5919
  generate() {
@@ -5941,7 +5970,7 @@ const generateFunc = (scope, decl, outUnused = false) => {
5941
5970
  // todo: wrap in try and reject thrown value once supported
5942
5971
  }
5943
5972
 
5944
- if (!globalThis.precompile && func.constr) {
5973
+ if (!globalThis.precompile && func.constr && !func._onlyThisMethod) {
5945
5974
  wasm.unshift(
5946
5975
  // opt: do not check for pure constructors
5947
5976
  ...(func._onlyConstr ? [] : [
@@ -5951,7 +5980,7 @@ const generateFunc = (scope, decl, outUnused = false) => {
5951
5980
  [ Opcodes.if, Blocktype.void ],
5952
5981
  ]),
5953
5982
  // set prototype of this ;)
5954
- ...generate(func, setObjProp({ type: 'ThisExpression' }, '__proto__', getObjProp(func.name, 'prototype'))),
5983
+ ...generate(func, setObjProp({ type: 'ThisExpression', _noGlobalThis: true }, '__proto__', getObjProp(func.name, 'prototype'))),
5955
5984
  ...(func._onlyConstr ? [] : [ [ Opcodes.end ] ])
5956
5985
  );
5957
5986
  }
@@ -99,7 +99,7 @@ export default (wasm, name = '', ind = 0, locals = {}, params = [], returns = []
99
99
 
100
100
  if (inst[0] === Opcodes.call || inst[0] === Opcodes.return_call) {
101
101
  const idx = inst[1];
102
- const callFunc = funcs.find(x => (x.asmIndex ?? x.index) === idx);
102
+ const callFunc = funcs.find(x => x.index === idx);
103
103
  if (callFunc) out += ` ;; $${callFunc.name} ${makeSignature(callFunc.params, callFunc.returns)}`;
104
104
  if (globalThis.importFuncs && idx < importFuncs.length) {
105
105
  const importFunc = importFuncs[idx];
@@ -59,6 +59,7 @@ const compile = async (file, _funcs) => {
59
59
  const paramOverrides = {
60
60
  __Porffor_object_set: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
61
61
  __Porffor_object_expr_init: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32 ],
62
+ __Porffor_object_expr_initWithFlags: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32, Valtype.i32, Valtype.i32 ],
62
63
  __Porffor_object_define: [ Valtype.i32, Valtype.i32, Valtype.i32, Valtype.i32, Valtype.f64, Valtype.i32, Valtype.i32, Valtype.i32 ],
63
64
  };
64
65
 
@@ -296,80 +296,6 @@ export const PrototypeFuncs = function() {
296
296
  // load current string ind {arg}
297
297
  [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
298
298
  Opcodes.i32_from_u
299
- ],
300
-
301
- isWellFormed: (pointer, length, _1, _2, iTmp, iTmp2) => [
302
- // note: we cannot presume it begins as 0 in case it was used previously
303
- ...pointer,
304
- [ Opcodes.local_set, iTmp ],
305
-
306
- // use cached length as end pointer
307
- ...length.getCachedI32(),
308
- ...number(ValtypeSize.i16, Valtype.i32),
309
- [ Opcodes.i32_mul ],
310
- ...pointer,
311
- [ Opcodes.i32_add ],
312
- ...length.setCachedI32(),
313
-
314
- [ Opcodes.loop, Blocktype.void ],
315
-
316
- [ Opcodes.block, Blocktype.void ],
317
-
318
- [ Opcodes.local_get, iTmp ],
319
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 ],
320
- [ Opcodes.local_set, iTmp2 ],
321
-
322
- // if not surrogate, continue
323
- [ Opcodes.local_get, iTmp2 ],
324
- ...number(0xF800, Valtype.i32),
325
- [ Opcodes.i32_and ],
326
- ...number(0xD800, Valtype.i32),
327
- [ Opcodes.i32_ne ],
328
- [ Opcodes.br_if, 0 ],
329
-
330
- // if not leading surrogate, return false
331
- [ Opcodes.local_get, iTmp2 ],
332
- ...number(0xDC00, Valtype.i32),
333
- [ Opcodes.i32_ge_s ],
334
- [ Opcodes.if, Blocktype.void ],
335
- ...number(0),
336
- [ Opcodes.br, 3 ],
337
- [ Opcodes.end ],
338
-
339
- // if not followed by trailing surrogate, return false
340
- [ Opcodes.local_get, iTmp ],
341
- [ Opcodes.i32_load16_u, Math.log2(ValtypeSize.i16) - 1, ValtypeSize.i32 + ValtypeSize.i16 ],
342
- ...number(0xFC00, Valtype.i32),
343
- [ Opcodes.i32_and ],
344
- ...number(0xDC00, Valtype.i32),
345
- [ Opcodes.i32_ne ],
346
- [ Opcodes.if, Blocktype.void ],
347
- ...number(0),
348
- [ Opcodes.br, 3 ],
349
- [ Opcodes.end ],
350
-
351
- // bump index again since gone through two valid chars
352
- [ Opcodes.local_get, iTmp ],
353
- ...number(ValtypeSize.i16, Valtype.i32),
354
- [ Opcodes.i32_add ],
355
- [ Opcodes.local_set, iTmp ],
356
-
357
- [ Opcodes.end ],
358
-
359
- // bump pointer and loop if not at the end
360
- [ Opcodes.local_get, iTmp ],
361
- ...number(ValtypeSize.i16, Valtype.i32),
362
- [ Opcodes.i32_add ],
363
- [ Opcodes.local_tee, iTmp ],
364
-
365
- ...length.getCachedI32(), // end pointer
366
- [ Opcodes.i32_ne ],
367
- [ Opcodes.br_if, 0 ],
368
-
369
- [ Opcodes.end ],
370
-
371
- // return true
372
- ...number(1)
373
299
  ]
374
300
  };
375
301
 
@@ -380,10 +306,6 @@ export const PrototypeFuncs = function() {
380
306
  this[TYPES.string].charCodeAt.local = Valtype.i32;
381
307
  this[TYPES.string].charCodeAt.noPointerCache = zeroChecks.charcodeat;
382
308
 
383
- this[TYPES.string].isWellFormed.local = Valtype.i32;
384
- this[TYPES.string].isWellFormed.local2 = Valtype.i32;
385
- this[TYPES.string].isWellFormed.returnType = TYPES.boolean;
386
-
387
309
  if (Prefs.bytestring) {
388
310
  this[TYPES.bytestring] = {
389
311
  at: (pointer, length, wIndex, wType, iTmp, _, arrayShell) => {
@@ -499,11 +421,6 @@ export const PrototypeFuncs = function() {
499
421
  // load current string ind {arg}
500
422
  [ Opcodes.i32_load8_u, 0, ValtypeSize.i32 ],
501
423
  Opcodes.i32_from_u
502
- ],
503
-
504
- isWellFormed: () => [
505
- // we know it must be true as it is a bytestring lol
506
- ...number(1)
507
424
  ]
508
425
  };
509
426
 
@@ -513,9 +430,5 @@ export const PrototypeFuncs = function() {
513
430
  this[TYPES.bytestring].charCodeAt.returnType = TYPES.number;
514
431
  this[TYPES.bytestring].charCodeAt.local = Valtype.i32;
515
432
  this[TYPES.bytestring].charCodeAt.noPointerCache = zeroChecks.charcodeat;
516
-
517
- this[TYPES.bytestring].isWellFormed.local = Valtype.i32;
518
- this[TYPES.bytestring].isWellFormed.local2 = Valtype.i32;
519
- this[TYPES.bytestring].isWellFormed.returnType = TYPES.boolean;
520
433
  }
521
434
  };
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.34.9+9dbf4dfbb",
4
+ "version": "0.34.11+f7ca044b2",
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.34.9+9dbf4dfbb';
3
+ globalThis.version = '0.34.11+f7ca044b2';
4
4
 
5
5
  // deno compat
6
6
  if (typeof process === 'undefined' && typeof Deno !== 'undefined') {