porffor 0.56.1 → 0.56.3

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.
package/bun.lock CHANGED
@@ -4,7 +4,7 @@
4
4
  "": {
5
5
  "name": "porffor",
6
6
  "dependencies": {
7
- "acorn": "^8.14.0",
7
+ "acorn": "^8.14.1",
8
8
  "node-repl-polyfill": "github:CanadaHonk/node-repl-polyfill",
9
9
  },
10
10
  "optionalDependencies": {
@@ -23,7 +23,7 @@
23
23
 
24
24
  "@babel/types": ["@babel/types@7.26.9", "", { "dependencies": { "@babel/helper-string-parser": "^7.25.9", "@babel/helper-validator-identifier": "^7.25.9" } }, "sha512-Y3IR1cRnOxOCDvMmNiym7XpXQ93iGDDPHx+Zj+NM+rg0fBaShfQLkg+hKPaZCEvg5N/LeCo4+Rj/i3FuJsIQaw=="],
25
25
 
26
- "acorn": ["acorn@8.14.0", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
26
+ "acorn": ["acorn@8.14.1", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg=="],
27
27
 
28
28
  "hermes-estree": ["hermes-estree@0.18.2", "", {}, "sha512-KoLsoWXJ5o81nit1wSyEZnWUGy9cBna9iYMZBR7skKh7okYAYKqQ9/OczwpMHn/cH0hKDyblulGsJ7FknlfVxQ=="],
29
29
 
package/compiler/2c.js CHANGED
@@ -728,8 +728,7 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
728
728
  break;
729
729
 
730
730
  case Opcodes.drop:
731
- // line(vals.pop());
732
- vals.pop();
731
+ if (vals.length > 0) line(`(void) ${vals.pop()}`);
733
732
  break;
734
733
 
735
734
  case Opcodes.block:
@@ -29,6 +29,8 @@ export const allocPage = ({ scope, pages }, name) => {
29
29
  };
30
30
 
31
31
  export const allocBytes = ({ scope, pages }, reason, bytes) => {
32
+ bytes += 2; // overallocate by 2 bytes to ensure null termination
33
+
32
34
  const allocs = pages.allocs ??= new Map();
33
35
  const bins = pages.bins ??= [];
34
36
 
@@ -522,10 +522,6 @@ export const __Porffor_object_accessorSet = (entryPtr: i32): Function|undefined
522
522
 
523
523
  export const __Porffor_object_lookup = (obj: any, target: any, targetHash: i32): i32 => {
524
524
  if (Porffor.wasm`local.get ${obj}` == 0) return -1;
525
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) {
526
- obj = __Porffor_object_underlying(obj);
527
- if (Porffor.wasm`local.get ${obj+1}` != Porffor.TYPES.object) return -1;
528
- }
529
525
 
530
526
  let ptr: i32 = Porffor.wasm`local.get ${obj}` + 8;
531
527
  const endPtr: i32 = ptr + Porffor.wasm.i32.load16_u(obj, 0, 0) * 18;
@@ -616,6 +612,7 @@ local.get ${obj+1}
616
612
  return`;
617
613
  }
618
614
 
615
+ if (Porffor.type(obj) != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
619
616
  let lastProto: any = obj;
620
617
  while (true) {
621
618
  if ((entryPtr = __Porffor_object_lookup(obj, key, hash)) != -1) break;
@@ -630,6 +627,7 @@ local.set ${obj}
630
627
  i32.load8_u 0 3
631
628
  local.set ${obj+1}`;
632
629
  } else obj = __Porffor_object_getPrototype(obj);
630
+ if (Porffor.type(obj) != Porffor.TYPES.object) obj = __Porffor_object_underlying(obj);
633
631
 
634
632
  if (Porffor.fastOr(obj == null, Porffor.wasm`local.get ${obj}` == Porffor.wasm`local.get ${lastProto}`)) break;
635
633
  lastProto = obj;
@@ -691,11 +689,13 @@ export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
691
689
  // check prototype chain for setter
692
690
  let proto: any = __Porffor_object_getPrototype(obj);
693
691
  if (proto != null) {
692
+ if (Porffor.type(proto) != Porffor.TYPES.object) proto = __Porffor_object_underlying(proto);
694
693
  let lastProto: any = proto;
695
694
  while (true) {
696
695
  if ((entryPtr = __Porffor_object_lookup(proto, key, hash)) != -1) break;
697
696
 
698
697
  proto = __Porffor_object_getPrototype(proto);
698
+ if (Porffor.type(proto) != Porffor.TYPES.object) proto = __Porffor_object_underlying(proto);
699
699
  if (Porffor.fastOr(proto == null, Porffor.wasm`local.get ${proto}` == Porffor.wasm`local.get ${lastProto}`)) break;
700
700
  lastProto = proto;
701
701
  }
@@ -795,11 +795,14 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
795
795
  // check prototype chain for setter
796
796
  let proto: any = __Porffor_object_getPrototype(obj);
797
797
  if (proto != null) {
798
+ if (Porffor.type(proto) != Porffor.TYPES.object) proto = __Porffor_object_underlying(proto);
799
+
798
800
  let lastProto: any = proto;
799
801
  while (true) {
800
802
  if ((entryPtr = __Porffor_object_lookup(proto, key, hash)) != -1) break;
801
803
 
802
804
  proto = __Porffor_object_getPrototype(proto);
805
+ if (Porffor.type(proto) != Porffor.TYPES.object) proto = __Porffor_object_underlying(proto);
803
806
  if (Porffor.fastOr(proto == null, Porffor.wasm`local.get ${proto}` == Porffor.wasm`local.get ${lastProto}`)) break;
804
807
  lastProto = proto;
805
808
  }
@@ -1,34 +1,29 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
3
  export const __Porffor_compareStrings = (a: any, b: any): boolean => {
4
- let at: i32 = Porffor.type(a);
5
- let bt: i32 = Porffor.type(b);
6
-
7
- if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
4
+ if ((Porffor.type(a) | 0b10000000) != Porffor.TYPES.bytestring) {
8
5
  // a is not string or bytestring
9
6
  // check if it is bad type or value
10
7
  if (Porffor.fastOr(
11
8
  a == null,
12
9
 
13
- at == Porffor.TYPES.symbol,
14
- at == Porffor.TYPES.boolean
10
+ Porffor.type(a) == Porffor.TYPES.symbol,
11
+ Porffor.type(a) == Porffor.TYPES.boolean
15
12
  )) return false;
16
13
 
17
- // todo/perf: just use a.toString()?
18
14
  a = ecma262.ToString(a);
19
15
  }
20
16
 
21
- if ((bt | 0b10000000) != Porffor.TYPES.bytestring) {
17
+ if ((Porffor.type(b) | 0b10000000) != Porffor.TYPES.bytestring) {
22
18
  // b is not string or bytestring
23
19
  // check if it is bad type or value
24
20
  if (Porffor.fastOr(
25
21
  b == null,
26
22
 
27
- bt == Porffor.TYPES.symbol,
28
- bt == Porffor.TYPES.boolean
23
+ Porffor.type(b) == Porffor.TYPES.symbol,
24
+ Porffor.type(b) == Porffor.TYPES.boolean
29
25
  )) return false;
30
26
 
31
- // todo/perf: just use b.toString()?
32
27
  b = ecma262.ToString(b);
33
28
  }
34
29
 
@@ -36,18 +31,13 @@ export const __Porffor_compareStrings = (a: any, b: any): boolean => {
36
31
  };
37
32
 
38
33
  export const __Porffor_concatStrings = (a: any, b: any): any => {
39
- let at: i32 = Porffor.type(a);
40
- let bt: i32 = Porffor.type(b);
41
-
42
- if ((at | 0b10000000) != Porffor.TYPES.bytestring) {
34
+ if ((Porffor.type(a) | 0b10000000) != Porffor.TYPES.bytestring) {
43
35
  // a is not string or bytestring
44
- // todo/perf: just use a.toString()?
45
36
  a = ecma262.ToString(a);
46
37
  }
47
38
 
48
- if ((bt | 0b10000000) != Porffor.TYPES.bytestring) {
39
+ if ((Porffor.type(b) | 0b10000000) != Porffor.TYPES.bytestring) {
49
40
  // b is not string or bytestring
50
- // todo/perf: just use b.toString()?
51
41
  b = ecma262.ToString(b);
52
42
  }
53
43
 
@@ -345,6 +345,7 @@ export const __Object_getOwnPropertyDescriptor = (obj: any, prop: any): object|u
345
345
  if (obj == null) throw new TypeError('Argument is nullish, expected object');
346
346
  const p: any = ecma262.ToPropertyKey(prop);
347
347
 
348
+ obj = __Porffor_object_underlying(obj);
348
349
  const entryPtr: i32 = Porffor.object.lookup(obj, p, __Porffor_object_hash(p));
349
350
  if (entryPtr == -1) {
350
351
  if (Porffor.type(obj) == Porffor.TYPES.function) {
@@ -26,7 +26,7 @@ export const String = function (...args: any[]): string|bytestring|StringObject
26
26
  // 4. Return StringCreate(s, ? GetPrototypeFromConstructor(NewTarget, "%String.prototype%")).
27
27
 
28
28
  // force bytestrings to strings
29
- if (Porffor.type(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s, s.length);
29
+ if (Porffor.type(s) == Porffor.TYPES.bytestring) s = Porffor.bytestringToString(s);
30
30
 
31
31
  return s as StringObject;
32
32
  };
@@ -72,10 +72,7 @@ export const BuiltinVars = function(ctx) {
72
72
  this.null.type = TYPES.object;
73
73
 
74
74
  this.NaN = [ number(NaN) ];
75
- this.NaN.floatOnly = true;
76
-
77
75
  this.Infinity = [ number(Infinity) ];
78
- this.Infinity.floatOnly = true;
79
76
 
80
77
  for (const x in TYPES) {
81
78
  this['__Porffor_TYPES_' + x] = () => [ number(TYPES[x]) ];
@@ -101,7 +98,6 @@ export const BuiltinVars = function(ctx) {
101
98
 
102
99
  export const BuiltinFuncs = function() {
103
100
  this.isNaN = {
104
- floatOnly: true,
105
101
  params: [ valtypeBinary ],
106
102
  locals: [],
107
103
  returns: [ valtypeBinary ],
@@ -116,7 +112,6 @@ export const BuiltinFuncs = function() {
116
112
  this.__Number_isNaN = this.isNaN;
117
113
 
118
114
  this.isFinite = {
119
- floatOnly: true,
120
115
  params: [ valtypeBinary ],
121
116
  locals: [ valtypeBinary ],
122
117
  returns: [ valtypeBinary ],
@@ -135,7 +130,6 @@ export const BuiltinFuncs = function() {
135
130
 
136
131
  // todo: should be false for +-Infinity
137
132
  this.__Number_isInteger = {
138
- floatOnly: true,
139
133
  params: [ valtypeBinary ],
140
134
  locals: [],
141
135
  returns: [ valtypeBinary ],
@@ -150,7 +144,6 @@ export const BuiltinFuncs = function() {
150
144
  };
151
145
 
152
146
  this.__Number_isSafeInteger = {
153
- floatOnly: true,
154
147
  params: [ valtypeBinary ],
155
148
  locals: [],
156
149
  returns: [ valtypeBinary ],
@@ -209,7 +202,6 @@ export const BuiltinFuncs = function() {
209
202
  };
210
203
 
211
204
  this.__Math_fround = {
212
- floatOnly: true,
213
205
  params: [ valtypeBinary ],
214
206
  locals: [],
215
207
  returns: [ valtypeBinary ],
@@ -223,7 +215,6 @@ export const BuiltinFuncs = function() {
223
215
 
224
216
  // todo: this does not overflow correctly
225
217
  this.__Math_imul = {
226
- floatOnly: true,
227
218
  params: [ valtypeBinary, valtypeBinary ],
228
219
  locals: [],
229
220
  returns: [ valtypeBinary ],
@@ -503,7 +494,6 @@ export const BuiltinFuncs = function() {
503
494
  if (!prng) throw new Error(`unknown prng algo: ${Prefs.prng}`);
504
495
 
505
496
  this.__Math_random = {
506
- floatOnly: true,
507
497
  params: [],
508
498
  locals: prng.locals,
509
499
  localNames: [ 's1', 's0' ],
@@ -514,23 +504,6 @@ export const BuiltinFuncs = function() {
514
504
  returnType: TYPES.number,
515
505
  wasm: [
516
506
  ...prng.wasm,
517
-
518
- // you thought it was over? now we need the result as a f64 between 0-1 :)
519
-
520
- // should we >> 12 here?
521
- // it feels like it but it breaks values
522
-
523
- // | 0x3FF0000000000000
524
- // [ Opcodes.i64_const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf8, 0x3f ],
525
- // [ Opcodes.i64_or ],
526
-
527
- // bit cast as f64
528
- // [ Opcodes.f64_reinterpret_i64 ],
529
-
530
- // - 1
531
- // number(1),
532
- // [ Opcodes.f64_sub ],
533
-
534
507
  ...(prng.returns === Valtype.i64 ? [
535
508
  number((1 << 53) - 1, Valtype.i64),
536
509
  [ Opcodes.i64_and ],
@@ -581,7 +554,6 @@ export const BuiltinFuncs = function() {
581
554
  };
582
555
 
583
556
  this.__Math_radians = {
584
- floatOnly: true,
585
557
  params: [ valtypeBinary ],
586
558
  locals: [],
587
559
  returns: [ valtypeBinary ],
@@ -594,7 +566,6 @@ export const BuiltinFuncs = function() {
594
566
  };
595
567
 
596
568
  this.__Math_degrees = {
597
- floatOnly: true,
598
569
  params: [ valtypeBinary ],
599
570
  locals: [],
600
571
  returns: [ valtypeBinary ],
@@ -607,7 +578,6 @@ export const BuiltinFuncs = function() {
607
578
  };
608
579
 
609
580
  this.__Math_clamp = {
610
- floatOnly: true,
611
581
  params: [ valtypeBinary, valtypeBinary, valtypeBinary ],
612
582
  locals: [],
613
583
  localNames: [ 'x', 'lower', 'upper' ],
@@ -623,7 +593,6 @@ export const BuiltinFuncs = function() {
623
593
  };
624
594
 
625
595
  this.__Math_scale = {
626
- floatOnly: true,
627
596
  params: [ valtypeBinary, valtypeBinary, valtypeBinary, valtypeBinary, valtypeBinary ],
628
597
  locals: [],
629
598
  localNames: [ 'x', 'inLow', 'inHigh', 'outLow', 'outHigh' ],
@@ -654,7 +623,6 @@ export const BuiltinFuncs = function() {
654
623
 
655
624
  // todo: fix for -0
656
625
  this.__Math_signbit = {
657
- floatOnly: true,
658
626
  params: [ valtypeBinary ],
659
627
  locals: [],
660
628
  returns: [ valtypeBinary ],
@@ -701,13 +669,8 @@ export const BuiltinFuncs = function() {
701
669
  returns: [],
702
670
  returnType: TYPES.undefined,
703
671
  wasm: [
704
- // dst
705
672
  [ Opcodes.local_get, 1 ],
706
-
707
- // src
708
673
  [ Opcodes.local_get, 0 ],
709
-
710
- // size = pageSize
711
674
  number(pageSize, Valtype.i32),
712
675
  [ ...Opcodes.memory_copy, 0x00, 0x00 ],
713
676
  ]
@@ -805,21 +768,20 @@ export const BuiltinFuncs = function() {
805
768
  };
806
769
 
807
770
  this.__Porffor_bytestringToString = {
808
- params: [ Valtype.i32, Valtype.i32 ],
809
- locals: [ Valtype.i32, Valtype.i32 ],
771
+ params: [ Valtype.i32 ],
772
+ locals: [ Valtype.i32, Valtype.i32, Valtype.i32 ],
810
773
  localNames: [ 'src', 'len', 'counter', 'dst' ],
811
774
  returns: [ Valtype.i32 ],
812
775
  returnType: TYPES.string,
813
- wasm: [
814
- // dst = grow memory by 1 page
815
- [ Opcodes.i32_const, 1 ],
816
- [ Opcodes.memory_grow, 0 ],
817
- number(65536, Valtype.i32),
818
- [ Opcodes.i32_mul ],
776
+ wasm: (scope, { builtin }) => [
777
+ // dst = allocate
778
+ [ Opcodes.call, builtin('__Porffor_allocate') ],
819
779
  [ Opcodes.local_tee, 3 ],
820
780
 
821
- // dst.length = len
822
- [ Opcodes.local_get, 1 ],
781
+ // dst.length = src.length
782
+ [ Opcodes.local_get, 0 ],
783
+ [ Opcodes.i32_load, 0, 0 ],
784
+ [ Opcodes.local_tee, 1 ],
823
785
  [ Opcodes.i32_store, 0, 0 ],
824
786
 
825
787
  [ Opcodes.loop, Blocktype.void ],