porffor 0.60.28 → 0.60.30

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.
@@ -1,6 +1,6 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const __Porffor_printString = (arg: bytestring|string) => {
3
+ export const __Porffor_printString = (arg: bytestring|string): void => {
4
4
  let ptr: i32 = Porffor.wasm`local.get ${arg}`;
5
5
  if (Porffor.type(arg) == Porffor.TYPES.bytestring) {
6
6
  const end: i32 = ptr + arg.length;
@@ -16,7 +16,7 @@ export const __Porffor_printString = (arg: bytestring|string) => {
16
16
  }
17
17
  };
18
18
 
19
- export const __Porffor_printHexDigit = (arg: number) => {
19
+ export const __Porffor_printHexDigit = (arg: number): void => {
20
20
  switch (arg) {
21
21
  case 0xf: Porffor.printStatic('f'); return;
22
22
  case 0xe: Porffor.printStatic('e'); return;
@@ -29,7 +29,7 @@ export const __Porffor_printHexDigit = (arg: number) => {
29
29
  }
30
30
  };
31
31
 
32
- export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0) => {
32
+ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number = 0): void => {
33
33
  const __Porffor_printArray = (arg: any[]|Uint8Array|Int8Array|Uint8ClampedArray|Uint16Array|Int16Array|Uint32Array|Int32Array|Float32Array|Float64Array, colors: boolean, length: boolean = false) => {
34
34
  const arrLen: i32 = arg.length;
35
35
  if (length) {
@@ -299,18 +299,18 @@ export const __Porffor_print = (arg: any, colors: boolean = true, depth: number
299
299
  };
300
300
 
301
301
  let tabLevel: i32 = 0;
302
- export const __Porffor_consoleIndent = () => {
302
+ export const __Porffor_consoleIndent = (): void => {
303
303
  for (let i: i32 = 0; i < tabLevel; i++) {
304
304
  Porffor.printStatic('\t');
305
305
  }
306
306
  };
307
307
 
308
- export const __console_clear = () => {
308
+ export const __console_clear = (): void => {
309
309
  Porffor.printStatic('\x1b[1;1H\x1b[J');
310
310
  tabLevel = 0;
311
311
  };
312
312
 
313
- export const __Porffor_consolePrint = (arg: any) => {
313
+ export const __Porffor_consolePrint = (arg: any): void => {
314
314
  if (Porffor.fastOr(Porffor.type(arg) == Porffor.TYPES.bytestring, Porffor.type(arg) == Porffor.TYPES.string)) {
315
315
  __Porffor_printString(arg);
316
316
  return;
@@ -318,7 +318,7 @@ export const __Porffor_consolePrint = (arg: any) => {
318
318
  __Porffor_print(arg);
319
319
  };
320
320
 
321
- export const __console_group = (label: bytestring) => {
321
+ export const __console_group = (label: bytestring): void => {
322
322
  if (Porffor.type(label) != Porffor.TYPES.undefined) {
323
323
  __Porffor_consoleIndent();
324
324
  __Porffor_consolePrint(label);
@@ -327,14 +327,14 @@ export const __console_group = (label: bytestring) => {
327
327
  tabLevel++;
328
328
  };
329
329
 
330
- export const __console_groupCollapsed = (label: bytestring) => __console_group(label);
330
+ export const __console_groupCollapsed = (label: bytestring): void => __console_group(label);
331
331
 
332
- export const __console_groupEnd = () => {
332
+ export const __console_groupEnd = (): void => {
333
333
  tabLevel--;
334
334
  if (tabLevel < 0) tabLevel = 0;
335
335
  };
336
336
 
337
- export const __console_log = (...args: any[]) => {
337
+ export const __console_log = (...args: any[]): void => {
338
338
  const argLen: i32 = args.length - 1;
339
339
  for (let i: i32 = 0; i <= argLen; i++) {
340
340
  __Porffor_consoleIndent();
@@ -346,7 +346,7 @@ export const __console_log = (...args: any[]) => {
346
346
  Porffor.printStatic('\n');
347
347
  };
348
348
 
349
- export const __console_debug = (...args: any[]) => {
349
+ export const __console_debug = (...args: any[]): void => {
350
350
  const argLen: i32 = args.length - 1;
351
351
  for (let i: i32 = 0; i <= argLen; i++) {
352
352
  __Porffor_consoleIndent();
@@ -358,7 +358,7 @@ export const __console_debug = (...args: any[]) => {
358
358
  Porffor.printStatic('\n');
359
359
  };
360
360
 
361
- export const __console_info = (...args: any[]) => {
361
+ export const __console_info = (...args: any[]): void => {
362
362
  const argLen: i32 = args.length - 1;
363
363
  for (let i: i32 = 0; i <= argLen; i++) {
364
364
  __Porffor_consoleIndent();
@@ -370,7 +370,7 @@ export const __console_info = (...args: any[]) => {
370
370
  Porffor.printStatic('\n');
371
371
  };
372
372
 
373
- export const __console_warn = (...args: any[]) => {
373
+ export const __console_warn = (...args: any[]): void => {
374
374
  const argLen: i32 = args.length - 1;
375
375
  for (let i: i32 = 0; i <= argLen; i++) {
376
376
  __Porffor_consoleIndent();
@@ -382,7 +382,7 @@ export const __console_warn = (...args: any[]) => {
382
382
  Porffor.printStatic('\n');
383
383
  };
384
384
 
385
- export const __console_error = (...args: any[]) => {
385
+ export const __console_error = (...args: any[]): void => {
386
386
  const argLen: i32 = args.length - 1;
387
387
  for (let i: i32 = 0; i <= argLen; i++) {
388
388
  __Porffor_consoleIndent();
@@ -394,7 +394,7 @@ export const __console_error = (...args: any[]) => {
394
394
  Porffor.printStatic('\n');
395
395
  };
396
396
 
397
- export const __console_assert = (assertion: any, ...args: any[]) => {
397
+ export const __console_assert = (assertion: any, ...args: any[]): void => {
398
398
  if (assertion) return;
399
399
 
400
400
  __Porffor_consoleIndent();
@@ -412,7 +412,7 @@ export const __console_assert = (assertion: any, ...args: any[]) => {
412
412
  Porffor.printStatic('\n');
413
413
  };
414
414
 
415
- export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showHidden: boolean) => {
415
+ export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showHidden: boolean): void => {
416
416
  if (Porffor.type(obj) != Porffor.TYPES.object || depth == 0) {
417
417
  __Porffor_print(obj, colors);
418
418
  return;
@@ -436,7 +436,7 @@ export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showH
436
436
  Porffor.printStatic(' }');
437
437
  };
438
438
 
439
- export const __console_dir = (obj: any, options: any) => {
439
+ export const __console_dir = (obj: any, options: any): void => {
440
440
  let colors: boolean = true;
441
441
  let depth: i32 = 2;
442
442
 
@@ -454,10 +454,10 @@ export const __console_dir = (obj: any, options: any) => {
454
454
  Porffor.printStatic('\n');
455
455
  };
456
456
 
457
- export const __console_dirxml = (obj: any) => __console_dir(obj);
457
+ export const __console_dirxml = (obj: any): void => __console_dir(obj);
458
458
 
459
459
  const countMap = new Map();
460
- export const __console_count = (label: any) => {
460
+ export const __console_count = (label: any): void => {
461
461
  label ??= 'default';
462
462
  const val = (countMap.get(label) ?? 0) + 1;
463
463
  countMap.set(label, val);
@@ -469,14 +469,14 @@ export const __console_count = (label: any) => {
469
469
  Porffor.printStatic('\n');
470
470
  };
471
471
 
472
- export const __console_countReset = (label: any) => {
472
+ export const __console_countReset = (label: any): void => {
473
473
  label ??= 'default';
474
474
  countMap.set(label, -1);
475
475
  __console_count(label);
476
476
  };
477
477
 
478
478
  const timeMap = new Map();
479
- export const __console_time = (label: any) => {
479
+ export const __console_time = (label: any): void => {
480
480
  label ??= 'default';
481
481
 
482
482
  // warn if label already exists
@@ -489,7 +489,7 @@ export const __console_time = (label: any) => {
489
489
  timeMap.set(label, performance.now());
490
490
  };
491
491
 
492
- export const __console_timeLog = (label: any) => {
492
+ export const __console_timeLog = (label: any): void => {
493
493
  label ??= 'default';
494
494
  __Porffor_consoleIndent();
495
495
 
@@ -508,14 +508,14 @@ export const __console_timeLog = (label: any) => {
508
508
  Porffor.printStatic(' ms\n');
509
509
  };
510
510
 
511
- export const __console_timeEnd = (label: any) => {
511
+ export const __console_timeEnd = (label: any): void => {
512
512
  label ??= 'default';
513
513
 
514
514
  __console_timeLog(label);
515
515
  timeMap.delete(label);
516
516
  };
517
517
 
518
- export const __Porffor_log = (arg: any) => {
518
+ export const __Porffor_log = (arg: any): void => {
519
519
  __Porffor_consolePrint(arg);
520
520
  Porffor.printStatic('\n');
521
521
  };
@@ -1,169 +1,222 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestring|undefined): bytestring|undefined => {
3
+ export const __Porffor_bytestring_bufferStr = (buffer: i32, str: bytestring): i32 => {
4
+ const len: i32 = str.length;
5
+ let strPtr: i32 = Porffor.wasm`local.get ${str}`;
6
+ let ptr: i32 = Porffor.wasm`local.get ${buffer}`;
7
+ let endPtr: i32 = ptr + len;
8
+
9
+ while (ptr + 4 <= endPtr) {
10
+ Porffor.wasm.i32.store(ptr, Porffor.wasm.i32.load(strPtr, 0, 4), 0, 4);
11
+ ptr += 4;
12
+ strPtr += 4;
13
+ }
14
+
15
+ while (ptr < endPtr) {
16
+ Porffor.wasm.i32.store8(ptr++, Porffor.wasm.i32.load8_u(strPtr++, 0, 4), 0, 4);
17
+ }
18
+
19
+ return ptr;
20
+ };
21
+
22
+ export const __Porffor_bytestring_bufferChar = (buffer: i32, char: i32): i32 => {
23
+ Porffor.wasm.i32.store8(buffer, char, 0, 4);
24
+ return buffer + 1;
25
+ };
26
+
27
+ export const __Porffor_bytestring_buffer2Char = (buffer: i32, char1: i32, char2: i32): i32 => {
28
+ Porffor.wasm.i32.store8(buffer, char1, 0, 4);
29
+ Porffor.wasm.i32.store8(buffer + 1, char2, 0, 4);
30
+ return buffer + 2;
31
+ };
32
+
33
+ export const __Porffor_json_canSerialize = (value: any): boolean => {
34
+ if (Porffor.fastOr(
35
+ value === null,
36
+ value === true,
37
+ value === false,
38
+ (Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring,
39
+ Porffor.type(value) == Porffor.TYPES.stringobject,
40
+ Porffor.type(value) == Porffor.TYPES.number,
41
+ Porffor.type(value) == Porffor.TYPES.numberobject,
42
+ Porffor.type(value) == Porffor.TYPES.array,
43
+ Porffor.type(value) > Porffor.TYPES.function
44
+ )) return true;
45
+
46
+ if (Porffor.type(value) == Porffor.TYPES.bigint) {
47
+ throw new TypeError('Cannot serialize BigInts');
48
+ }
49
+
50
+ return false;
51
+ };
52
+
53
+ export const __Porffor_json_serialize = (_buffer: i32, value: any, depth: i32, space: bytestring|undefined): i32 => {
4
54
  // somewhat modelled after 25.5.2.2 SerializeJSONProperty: https://tc39.es/ecma262/#sec-serializejsonproperty
5
- if (value === null) return 'null';
6
- if (value === true) return 'true';
7
- if (value === false) return 'false';
55
+ let buffer: i32 = Porffor.wasm`local.get ${_buffer}`;
56
+ if (value === null) return __Porffor_bytestring_bufferStr(buffer, 'null');
57
+ if (value === true) return __Porffor_bytestring_bufferStr(buffer, 'true');
58
+ if (value === false) return __Porffor_bytestring_bufferStr(buffer, 'false');
8
59
 
9
60
  if (Porffor.fastOr(
10
61
  (Porffor.type(value) | 0b10000000) == Porffor.TYPES.bytestring,
11
62
  Porffor.type(value) == Porffor.TYPES.stringobject
12
63
  )) { // string
13
- const out: bytestring = Porffor.allocate();
14
- Porffor.bytestring.appendChar(out, 34); // start "
64
+ buffer = __Porffor_bytestring_bufferChar(buffer, 34); // start "
15
65
 
16
66
  const len: i32 = value.length;
17
67
  for (let i: i32 = 0; i < len; i++) {
18
68
  const c: i32 = value.charCodeAt(i);
19
69
  if (c < 0x20) {
20
70
  if (c == 0x08) {
21
- Porffor.bytestring.append2Char(out, 92, 98); // \b
71
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 98); // \b
22
72
  continue;
23
73
  }
24
74
 
25
75
  if (c == 0x09) {
26
- Porffor.bytestring.append2Char(out, 92, 116); // \t
76
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 116); // \t
27
77
  continue;
28
78
  }
29
79
 
30
80
  if (c == 0x0a) {
31
- Porffor.bytestring.append2Char(out, 92, 110); // \n
81
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 110); // \n
32
82
  continue;
33
83
  }
34
84
 
35
85
  if (c == 0x0c) {
36
- Porffor.bytestring.append2Char(out, 92, 102); // \f
86
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 102); // \f
37
87
  continue;
38
88
  }
39
89
 
40
90
  if (c == 0x0d) {
41
- Porffor.bytestring.append2Char(out, 92, 114); // \r
91
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 114); // \r
42
92
  continue;
43
93
  }
44
94
 
45
95
  // \u00FF
46
- Porffor.bytestring.append2Char(out, 92, 117); // \u
47
- Porffor.bytestring.append2Char(out, 48, 48); // 00
96
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 117); // \u
97
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 48, 48); // 00
48
98
 
49
99
  const h1: i32 = (c & 0xf0) / 0x10;
50
100
  const h2: i32 = c & 0x0f;
51
- Porffor.bytestring.appendChar(out, h1 < 10 ? h1 + 48 : h1 + 55); // 0-9 or A-F
52
- Porffor.bytestring.appendChar(out, h2 < 10 ? h2 + 48 : h2 + 55); // 0-9 or A-F
101
+ buffer = __Porffor_bytestring_buffer2Char(buffer, h1 < 10 ? h1 + 48 : h1 + 55, h2 < 10 ? h2 + 48 : h2 + 55); // 0-9 or A-F
53
102
  continue;
54
103
  }
55
104
 
56
105
  if (c == 0x22) { // "
57
- Porffor.bytestring.append2Char(out, 92, 34); // \"
106
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 34); // \"
58
107
  continue;
59
108
  }
60
109
 
61
110
  if (c == 0x5c) { // \
62
- Porffor.bytestring.append2Char(out, 92, 92); // \\
111
+ buffer = __Porffor_bytestring_buffer2Char(buffer, 92, 92); // \\
63
112
  continue;
64
113
  }
65
114
 
66
115
  // todo: support non-bytestrings
67
- Porffor.bytestring.appendChar(out, c);
116
+ buffer = __Porffor_bytestring_bufferChar(buffer, c);
68
117
  }
69
118
 
70
- Porffor.bytestring.appendChar(out, 34); // final "
71
- return out;
119
+ return __Porffor_bytestring_bufferChar(buffer, 34); // final "
72
120
  }
73
121
 
74
122
  if (Porffor.fastOr(
75
123
  Porffor.type(value) == Porffor.TYPES.number,
76
124
  Porffor.type(value) == Porffor.TYPES.numberobject
77
125
  )) { // number
78
- if (Number.isFinite(value)) return value + '';
79
- return 'null';
126
+ if (Number.isFinite(value)) {
127
+ return __Porffor_bytestring_bufferStr(buffer, __Number_prototype_toString(value, 10));
128
+ }
129
+
130
+ return __Porffor_bytestring_bufferStr(buffer, 'null');
80
131
  }
81
132
 
82
133
  if (Porffor.type(value) == Porffor.TYPES.array) {
83
- const out: bytestring = Porffor.allocate();
84
- Porffor.bytestring.appendChar(out, 91); // [
134
+ buffer = __Porffor_bytestring_bufferChar(buffer, 91); // [
85
135
 
86
136
  const hasSpace: boolean = space !== undefined;
87
137
  depth += 1;
88
138
 
89
139
  for (const x of (value as any[])) {
90
140
  if (hasSpace) {
91
- Porffor.bytestring.appendChar(out, 10); // \n
92
- for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space as bytestring);
141
+ buffer = __Porffor_bytestring_bufferChar(buffer, 10); // \n
142
+ for (let i: i32 = 0; i < depth; i++) buffer = __Porffor_bytestring_bufferStr(buffer, space as bytestring);
93
143
  }
94
144
 
95
- Porffor.bytestring.appendStr(out, __Porffor_json_serialize(x, depth, space) ?? 'null');
145
+ if (__Porffor_json_canSerialize(x)) {
146
+ buffer = __Porffor_json_serialize(buffer, x, depth, space);
147
+ } else {
148
+ // non-serializable value, write null
149
+ buffer = __Porffor_bytestring_bufferStr(buffer, 'null');
150
+ }
96
151
 
97
- Porffor.bytestring.appendChar(out, 44); // ,
152
+ buffer = __Porffor_bytestring_bufferChar(buffer, 44); // ,
98
153
  }
99
154
 
100
155
  depth -= 1;
101
156
 
102
- // swap trailing , with ] (or append if empty)
103
- if (out.length > 1) {
157
+ // swap trailing , with ] (or \n or append if empty)
158
+ if ((buffer - _buffer) > 1) {
104
159
  if (hasSpace) {
105
- Porffor.bytestring.appendChar(out, 10); // \n
106
- for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space as bytestring);
107
- Porffor.bytestring.appendChar(out, 93); // ]
108
- } else {
109
- Porffor.wasm.i32.store8(Porffor.wasm`local.get ${out}` + out.length, 93, 0, 3); // ]
160
+ Porffor.wasm.i32.store8(buffer, 10, 0, 3); // \n
161
+ for (let i: i32 = 0; i < depth; i++) buffer = __Porffor_bytestring_bufferStr(buffer, space as bytestring);
162
+ return __Porffor_bytestring_bufferChar(buffer, 93); // ]
110
163
  }
111
- } else {
112
- Porffor.bytestring.appendChar(out, 93); // ]
164
+
165
+ Porffor.wasm.i32.store8(buffer, 93, 0, 3); // ]
166
+ return buffer;
113
167
  }
114
168
 
115
- return out;
169
+ return __Porffor_bytestring_bufferChar(buffer, 93); // ]
116
170
  }
117
171
 
118
172
  if (Porffor.type(value) > 0x06) {
119
173
  // non-function object
120
- const out: bytestring = Porffor.allocate();
121
- Porffor.bytestring.appendChar(out, 123); // {
174
+ buffer = __Porffor_bytestring_bufferChar(buffer, 123); // {
122
175
 
123
176
  const hasSpace: boolean = space !== undefined;
124
177
  depth += 1;
125
178
 
126
- for (const key in (value as object)) {
179
+ for (const key: bytestring in (value as object)) {
127
180
  // skip symbol keys
128
181
  if (Porffor.type(key) == Porffor.TYPES.symbol) continue;
129
182
 
130
- // skip non-serializable values (functions, etc)
131
- const val: bytestring|undefined = __Porffor_json_serialize((value as object)[key], depth, space);
132
- if (val == null) continue;
183
+ const val: any = (value as object)[key];
184
+ if (!__Porffor_json_canSerialize(val)) {
185
+ // skip non-serializable value
186
+ continue;
187
+ }
133
188
 
134
189
  if (hasSpace) {
135
- Porffor.bytestring.appendChar(out, 10); // \n
136
- for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space as bytestring);
190
+ buffer = __Porffor_bytestring_bufferChar(buffer, 10); // \n
191
+ for (let i: i32 = 0; i < depth; i++) buffer = __Porffor_bytestring_bufferStr(buffer, space as bytestring);
137
192
  }
138
193
 
139
- Porffor.bytestring.appendChar(out, 34); // "
140
- Porffor.bytestring.appendStr(out, key);
141
- Porffor.bytestring.appendChar(out, 34); // "
142
-
143
- Porffor.bytestring.appendChar(out, 58); // :
144
- if (hasSpace) Porffor.bytestring.appendChar(out, 32); // space
194
+ buffer = __Porffor_bytestring_bufferChar(buffer, 34); // "
195
+ buffer = __Porffor_bytestring_bufferStr(buffer, key);
196
+ buffer = __Porffor_bytestring_bufferChar(buffer, 34); // "
145
197
 
146
- Porffor.bytestring.appendStr(out, val);
198
+ buffer = __Porffor_bytestring_bufferChar(buffer, 58); // :
199
+ if (hasSpace) buffer = __Porffor_bytestring_bufferChar(buffer, 32); // space
147
200
 
148
- Porffor.bytestring.appendChar(out, 44); // ,
201
+ buffer = __Porffor_json_serialize(buffer, val, depth, space);
202
+ buffer = __Porffor_bytestring_bufferChar(buffer, 44); // ,
149
203
  }
150
204
 
151
205
  depth -= 1;
152
206
 
153
- // swap trailing , with } (or append if empty)
154
- if (out.length > 1) {
207
+ // swap trailing , with } (or \n or append if empty)
208
+ if ((buffer - _buffer) > 1) {
155
209
  if (hasSpace) {
156
- Porffor.bytestring.appendChar(out, 10); // \n
157
- for (let i: i32 = 0; i < depth; i++) Porffor.bytestring.appendStr(out, space as bytestring);
158
- Porffor.bytestring.appendChar(out, 125); // }
159
- } else {
160
- Porffor.wasm.i32.store8(Porffor.wasm`local.get ${out}` + out.length, 125, 0, 3); // }
210
+ Porffor.wasm.i32.store8(buffer, 10, 0, 3); // \n
211
+ for (let i: i32 = 0; i < depth; i++) buffer = __Porffor_bytestring_bufferStr(buffer, space as bytestring);
212
+ return __Porffor_bytestring_bufferChar(buffer, 125); // }
161
213
  }
162
- } else {
163
- Porffor.bytestring.appendChar(out, 125); // }
214
+
215
+ Porffor.wasm.i32.store8(buffer, 125, 0, 3); // }
216
+ return buffer;
164
217
  }
165
218
 
166
- return out;
219
+ return __Porffor_bytestring_bufferChar(buffer, 125); // }
167
220
  }
168
221
 
169
222
  if (Porffor.type(value) == 0x04) {
@@ -171,7 +224,7 @@ export const __Porffor_json_serialize = (value: any, depth: i32, space: bytestri
171
224
  throw new TypeError('Cannot serialize BigInts');
172
225
  }
173
226
 
174
- return undefined;
227
+ return -1;
175
228
  };
176
229
 
177
230
  export const __JSON_stringify = (value: any, replacer: any, space: any) => {
@@ -187,7 +240,7 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
187
240
  if (space < 1) {
188
241
  space = undefined;
189
242
  } else {
190
- const spaceStr: bytestring = Porffor.allocate();
243
+ const spaceStr: bytestring = Porffor.allocateBytes(4 + space);
191
244
  for (let i: i32 = 0; i < space; i++) Porffor.bytestring.appendChar(spaceStr, 32);
192
245
 
193
246
  space = spaceStr;
@@ -209,7 +262,12 @@ export const __JSON_stringify = (value: any, replacer: any, space: any) => {
209
262
  }
210
263
  }
211
264
 
212
- return __Porffor_json_serialize(value, 0, space);
265
+ const buffer: bytestring = Porffor.allocate();
266
+ const out = __Porffor_json_serialize(buffer, value, 0, space);
267
+ if (out == -1) return undefined;
268
+
269
+ buffer.length = out - (buffer as i32);
270
+ return buffer;
213
271
  };
214
272
 
215
273
 
@@ -1411,6 +1411,17 @@ export const BuiltinFuncs = () => {
1411
1411
  ]
1412
1412
  };
1413
1413
 
1414
+ _.__Porffor_memorySize = {
1415
+ params: [],
1416
+ returns: [ Valtype.i32 ],
1417
+ returnType: TYPES.number,
1418
+ wasm: () => [
1419
+ [ Opcodes.memory_size, 0 ],
1420
+ number(PageSize, Valtype.i32),
1421
+ [ Opcodes.i32_mul ]
1422
+ ]
1423
+ };
1424
+
1414
1425
  // allow non-comptime redefinition later in precompiled
1415
1426
  const comptime = (name, returnType, comptime) => {
1416
1427
  let v = {
@@ -1516,7 +1527,7 @@ export const BuiltinFuncs = () => {
1516
1527
  );
1517
1528
 
1518
1529
  // Porffor.call(func, argArray, this, newTarget)
1519
- comptime('__Porffor_call', TYPES.number, (scope, decl, { generate, getNodeType }) => generate(scope, {
1530
+ comptime('__Porffor_call', undefined, (scope, decl, { generate, getNodeType }) => generate(scope, {
1520
1531
  type: 'CallExpression',
1521
1532
  callee: decl.arguments[0],
1522
1533
  arguments: [ {
@@ -1539,21 +1550,23 @@ export const BuiltinFuncs = () => {
1539
1550
  // todo: this breaks console.group, etc - disable this if those are used but edge case for now
1540
1551
  comptime('__console_log', TYPES.undefined, (scope, decl, { generate, getNodeType, knownTypeWithGuess, printStaticStr }) => {
1541
1552
  const slow = () => {
1542
- decl._noInternalConstr = true;
1553
+ decl._noComptime = true;
1543
1554
  return generate(scope, decl);
1544
1555
  };
1545
1556
  const fast = name => {
1546
1557
  return [
1547
- ...generate(scope, {
1558
+ ...(!name ? [ number(UNDEFINED) ] : generate(scope, {
1548
1559
  ...decl,
1549
1560
  callee: {
1550
1561
  type: 'Identifier',
1551
1562
  name
1552
1563
  }
1553
- }),
1564
+ })),
1554
1565
  ...printStaticStr(scope, '\n')
1555
1566
  ];
1556
1567
  };
1568
+
1569
+ if (decl.arguments.length === 0) return fast();
1557
1570
  if (decl.arguments.length !== 1) return slow();
1558
1571
 
1559
1572
  generate(scope, decl.arguments[0]); // generate first to get accurate type