porffor 0.56.7 → 0.57.0

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/compiler/2c.js CHANGED
@@ -175,7 +175,9 @@ const removeBrackets = str => {
175
175
  return str.startsWith('(') && str.endsWith(')') && !str.startsWith('(*') ? str.slice(1, -1) : str;
176
176
  };
177
177
 
178
- export default ({ funcs, globals, tags, data, exceptions, pages }) => {
178
+ export default ({ funcs, globals, data, pages }) => {
179
+ if (Prefs.secure) log.warning('2c', `native/c targets are not sandboxed or proven to be safe (--secure)`);
180
+
179
181
  const invOperatorOpcode = Object.values(operatorOpcode).reduce((acc, x) => {
180
182
  for (const k in x) {
181
183
  acc[x[k]] = k;
@@ -794,6 +796,7 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
794
796
  }
795
797
 
796
798
  case Opcodes.throw: {
799
+ // only supports stack exception mode
797
800
  // todo: allow catching
798
801
  const type = vals.pop();
799
802
  const val = vals.pop();
@@ -603,7 +603,7 @@ local.set ${obj+1}`;
603
603
  } else obj = __Porffor_object_getHiddenPrototype(trueType);
604
604
 
605
605
  // todo/opt: put this behind comptime flag if only __proto__ is used
606
- if (hash == -406948493) if (key == '__proto__') {
606
+ if (hash == -406948493) if (Porffor.strcmp(key, '__proto__')) {
607
607
  // get prototype
608
608
  Porffor.wasm`
609
609
  local.get ${obj}
@@ -679,7 +679,7 @@ export const __Porffor_object_set = (obj: any, key: any, value: any): any => {
679
679
  let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
680
680
  let flags: i32;
681
681
  if (entryPtr == -1) {
682
- if (hash == -406948493) if (key == '__proto__') {
682
+ if (hash == -406948493) if (Porffor.strcmp(key, '__proto__')) {
683
683
  // set prototype
684
684
  __Porffor_object_setPrototype(obj, value);
685
685
  return value;
@@ -785,7 +785,7 @@ export const __Porffor_object_setStrict = (obj: any, key: any, value: any): any
785
785
  let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
786
786
  let flags: i32;
787
787
  if (entryPtr == -1) {
788
- if (hash == -406948493) if (key == '__proto__') {
788
+ if (hash == -406948493) if (Porffor.strcmp(key, '__proto__')) {
789
789
  // set prototype
790
790
  __Porffor_object_setPrototype(obj, value);
791
791
  return value;
@@ -1063,7 +1063,7 @@ export const __Porffor_object_expr_init = (obj: any, key: any, value: any): void
1063
1063
  const hash: i32 = __Porffor_object_hash(key);
1064
1064
  let entryPtr: i32 = __Porffor_object_lookup(obj, key, hash);
1065
1065
  if (entryPtr == -1) {
1066
- if (hash == -406948493) if (key == '__proto__') {
1066
+ if (hash == -406948493) if (Porffor.strcmp(key, '__proto__')) {
1067
1067
  // set prototype
1068
1068
  __Porffor_object_setPrototype(obj, value);
1069
1069
  return value;
@@ -86,31 +86,28 @@ export const __Porffor_miniLog = (arg: any) => {
86
86
  Porffor.printStatic('\n');
87
87
  };
88
88
 
89
- export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
90
- // todo: Symbol.toStringTag could reduce duplication here
91
-
92
- // note: this doesn't have access to the upper scope!! do not use any variables from up there
93
- const __Porffor_printArray = (arg: any, colors: boolean, length: boolean = false) => {
94
- const arrLen: i32 = arg.length - 1;
95
-
96
- if (length) {
97
- Porffor.printStatic('(');
98
- print(arrLen + 1);
99
- Porffor.printStatic(') ');
100
- }
89
+ export const __Porffor_printArray = (arg: any[]|Uint8Array|Int8Array|Uint8ClampedArray|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array, colors: boolean, length: boolean = false) => {
90
+ const arrLen: i32 = arg.length;
91
+ if (length) {
92
+ Porffor.printStatic('(');
93
+ print(arrLen);
94
+ Porffor.printStatic(') ');
95
+ }
101
96
 
102
- if (arrLen == -1) {
103
- Porffor.printStatic('[]');
104
- } else {
105
- Porffor.printStatic('[ ');
106
- for (let i: i32 = 0; i <= arrLen; i++) {
107
- __Porffor_print(arg[i], colors);
108
- if (i != arrLen) Porffor.printStatic(', ');
109
- }
110
- Porffor.printStatic(' ]');
97
+ if (arrLen == 0) {
98
+ Porffor.printStatic('[]');
99
+ } else {
100
+ Porffor.printStatic('[ ');
101
+ for (let i: i32 = 0; i < arrLen; i++) {
102
+ __Porffor_print(arg[i], colors);
103
+ if (i != arrLen - 1) Porffor.printStatic(', ');
111
104
  }
112
- };
105
+ Porffor.printStatic(' ]');
106
+ }
107
+ };
113
108
 
109
+ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
110
+ // todo: Symbol.toStringTag could reduce duplication here
114
111
  switch (Porffor.type(arg)) {
115
112
  case Porffor.TYPES.number:
116
113
  if (colors) Porffor.printStatic('\x1b[33m'); // yellow
@@ -4,7 +4,7 @@ export const __Function_prototype_toString = (_this: Function) => {
4
4
  const out: bytestring = Porffor.allocate();
5
5
 
6
6
  Porffor.bytestring.appendStr(out, 'function ');
7
- Porffor.bytestring.appendStr(out, _this.name);
7
+ Porffor.bytestring.appendStr(out, __Porffor_funcLut_name(_this));
8
8
  Porffor.bytestring.appendStr(out, '() { [native code] }');
9
9
  return out;
10
10
  };
@@ -1,7 +1,5 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- const descStore: any[] = [];
4
-
5
3
  // 20.4.1.1 Symbol ([ description ])
6
4
  // https://tc39.es/ecma262/#sec-symbol-description
7
5
  export const Symbol = (description: any): Symbol => {
@@ -17,11 +15,28 @@ export const Symbol = (description: any): Symbol => {
17
15
  }
18
16
 
19
17
  // 4. Return a new Symbol whose [[Description]] is descString.
20
- return Porffor.array.fastPush(descStore, descString) as Symbol;
18
+ Porffor.wasm`
19
+ local symbol i32
20
+ i32.const 16
21
+ call __Porffor_allocateBytes
22
+ local.tee symbol
23
+ local.get ${descString}
24
+ f64.store 0 0
25
+ local.get symbol
26
+ local.get ${descString+1}
27
+ i32.store8 0 8`;
28
+
29
+ return symbol;
21
30
  };
22
31
 
23
32
  export const __Symbol_prototype_description$get = (_this: Symbol) => {
24
- return descStore[Porffor.wasm`local.get ${_this}` - 1];
33
+ Porffor.wasm`local.get ${_this}
34
+ i32.to_u
35
+ f64.load 0 0
36
+ local.get ${_this}
37
+ i32.to_u
38
+ i32.load8_u 0 8
39
+ return`;
25
40
  };
26
41
 
27
42
  export const __Symbol_prototype_toString = (_this: Symbol) => {