porffor 0.19.12 → 0.19.14

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
@@ -628,8 +628,8 @@ _time_out = _time.tv_nsec / 1000000. + _time.tv_sec * 1000.;`);
628
628
  }
629
629
 
630
630
  if (!cified.has(func.name) && func.name !== f.name) {
631
- cify(func);
632
631
  cified.add(func.name);
632
+ cify(func);
633
633
  }
634
634
 
635
635
  let args = [];
@@ -35,7 +35,9 @@ export class StaticAllocator {
35
35
  }
36
36
 
37
37
  alloc({ scope, pages }, name, { itemType }) {
38
- const reason = `${this.allocType(itemType)}: ${Prefs.scopedPageNames ? (scope.name + '/') : ''}${name}`;
38
+ let scopeName = scope.name;
39
+ if (globalThis.precompile && scopeName === 'main') scopeName = globalThis.precompile;
40
+ const reason = `${this.allocType(itemType)}: ${Prefs.scopedPageNames ? (scopeName + '/') : ''}${name}`;
39
41
 
40
42
  if (pages.has(reason)) return number(this.ptr(pages.get(reason).ind), Valtype.i32);
41
43
 
@@ -137,5 +137,16 @@ ${[...s1].map((x, i) => ` Porffor.wasm.i32.store16(outPtr, ${x.charCodeAt(0)},
137
137
  arg('anchor', 'a', 'name');
138
138
  arg('link', 'a', 'href');
139
139
 
140
+ const prototypeAlias = (regular, annex) => `export const __String_prototype_${annex} = (_this: string) => {
141
+ return __String_prototype_${regular}(_this);
142
+ };
143
+ export const __ByteString_prototype_${annex} = (_this: bytestring) => {
144
+ return __ByteString_prototype_${regular}(_this);
145
+ };
146
+ `;
147
+
148
+ prototypeAlias('trimStart', 'trimLeft');
149
+ prototypeAlias('trimEnd', 'trimRight');
150
+
140
151
  return out;
141
152
  };
@@ -1,6 +1,540 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
+ export const __Porffor_printString = (arg: bytestring|string) => {
4
+ let ptr: i32 = Porffor.wasm`local.get ${arg}`;
5
+ if (Porffor.rawType(arg) == Porffor.TYPES.bytestring) {
6
+ const end: i32 = ptr + arg.length;
7
+ while (ptr < end) {
8
+ printChar(Porffor.wasm.i32.load8_u(ptr++, 0, 4));
9
+ }
10
+ } else { // regular string
11
+ const end: i32 = ptr + arg.length * 2;
12
+ while (ptr < end) {
13
+ printChar(Porffor.wasm.i32.load16_u(ptr, 0, 4));
14
+ ptr += 2;
15
+ }
16
+ }
17
+ };
18
+
19
+ export const __Porffor_printHexDigit = (arg: number) => {
20
+ switch (arg) {
21
+ case 0xf: printStatic('f'); return;
22
+ case 0xe: printStatic('e'); return;
23
+ case 0xd: printStatic('d'); return;
24
+ case 0xc: printStatic('c'); return;
25
+ case 0xb: printStatic('b'); return;
26
+ case 0xa: printStatic('a'); return;
27
+
28
+ default: print(arg);
29
+ }
30
+ };
31
+
32
+ export const __Porffor_print = (arg: any, colors: boolean = true) => {
33
+ // todo: Symbol.toStringTag could reduce duplication here
34
+
35
+ const t: i32 = Porffor.rawType(arg);
36
+ switch (t) {
37
+ case Porffor.TYPES.number:
38
+ if (colors) printStatic('\x1b[33m'); // yellow
39
+ print(arg);
40
+ if (colors) printStatic('\x1b[m');
41
+ return;
42
+
43
+ case Porffor.TYPES.boolean:
44
+ if (colors) printStatic('\x1b[33m'); // yellow
45
+ if (arg) {
46
+ printStatic('true');
47
+ } else {
48
+ printStatic('false');
49
+ }
50
+ if (colors) printStatic('\x1b[m');
51
+ return;
52
+
53
+ case Porffor.TYPES.bytestring:
54
+ case Porffor.TYPES.string:
55
+ if (colors) printStatic('\x1b[32m'); // green
56
+ printStatic("'");
57
+
58
+ __Porffor_printString(arg);
59
+
60
+ printStatic("'");
61
+ if (colors) printStatic('\x1b[m');
62
+ return;
63
+
64
+ case Porffor.TYPES.array:
65
+ const arrLen: i32 = arg.length - 1;
66
+ if (arrLen == -1) {
67
+ printStatic('[]');
68
+ } else {
69
+ printStatic('[ ');
70
+ for (let i: i32 = 0; i <= arrLen; i++) {
71
+ __Porffor_print(arg[i], colors);
72
+ if (i != arrLen) printStatic(', ');
73
+ }
74
+ printStatic(' ]');
75
+ }
76
+ return;
77
+
78
+ case Porffor.TYPES.empty:
79
+ case Porffor.TYPES.undefined:
80
+ if (colors) printStatic('\x1b[2m'); // dim
81
+ printStatic('undefined');
82
+ if (colors) printStatic('\x1b[0m');
83
+ return;
84
+
85
+ case Porffor.TYPES.object:
86
+ if (arg) {
87
+ if (colors) printStatic('\x1b[34m'); // blue
88
+ printStatic('[Object]');
89
+ } else {
90
+ if (colors) printStatic('\x1b[1m'); // bold
91
+ printStatic('null');
92
+ }
93
+
94
+ if (colors) printStatic('\x1b[m');
95
+ return;
96
+
97
+ case Porffor.TYPES.function:
98
+ // todo: this actually doesn't work because we don't have function name information at runtime
99
+ printStatic('[Function ');
100
+ __Porffor_printString(arg.name);
101
+ printStatic(']');
102
+ return;
103
+
104
+ case Porffor.TYPES.date:
105
+ if (colors) printStatic('\x1b[35m'); // purple
106
+ __Porffor_printString(__Date_prototype_toISOString(arg));
107
+ if (colors) printStatic('\x1b[m');
108
+ return;
109
+
110
+ case Porffor.TYPES.symbol:
111
+ if (colors) printStatic('\x1b[32m'); // green
112
+ __Porffor_printString(__Symbol_prototype_toString(arg));
113
+ if (colors) printStatic('\x1b[m');
114
+ return;
115
+
116
+ case Porffor.TYPES.uint8array: {
117
+ const arrLen: i32 = arg.length - 1;
118
+ printStatic('Uint8Array(');
119
+ print(arrLen + 1);
120
+ printStatic(') [ ');
121
+ for (let i: i32 = 0; i <= arrLen; i++) {
122
+ __Porffor_print(arg[i], colors);
123
+ if (i != arrLen) printStatic(', ');
124
+ }
125
+ printStatic(' ]');
126
+ return;
127
+ }
128
+ case Porffor.TYPES.int8array: {
129
+ const arrLen: i32 = arg.length - 1;
130
+ printStatic('Int8Array(');
131
+ print(arrLen + 1);
132
+ printStatic(') [ ');
133
+ for (let i: i32 = 0; i <= arrLen; i++) {
134
+ __Porffor_print(arg[i], colors);
135
+ if (i != arrLen) printStatic(', ');
136
+ }
137
+ printStatic(' ]');
138
+ return;
139
+ }
140
+ case Porffor.TYPES.uint8clampedarray: {
141
+ const arrLen: i32 = arg.length - 1;
142
+ printStatic('Uint8ClampedArray(');
143
+ print(arrLen + 1);
144
+ printStatic(') [ ');
145
+ for (let i: i32 = 0; i <= arrLen; i++) {
146
+ __Porffor_print(arg[i], colors);
147
+ if (i != arrLen) printStatic(', ');
148
+ }
149
+ printStatic(' ]');
150
+ return;
151
+ }
152
+ case Porffor.TYPES.uint16array: {
153
+ const arrLen: i32 = arg.length - 1;
154
+ printStatic('Uint16Array(');
155
+ print(arrLen + 1);
156
+ printStatic(') [ ');
157
+ for (let i: i32 = 0; i <= arrLen; i++) {
158
+ __Porffor_print(arg[i], colors);
159
+ if (i != arrLen) printStatic(', ');
160
+ }
161
+ printStatic(' ]');
162
+ return;
163
+ }
164
+ case Porffor.TYPES.int16array: {
165
+ const arrLen: i32 = arg.length - 1;
166
+ printStatic('Int16Array(');
167
+ print(arrLen + 1);
168
+ printStatic(') [ ');
169
+ for (let i: i32 = 0; i <= arrLen; i++) {
170
+ __Porffor_print(arg[i], colors);
171
+ if (i != arrLen) printStatic(', ');
172
+ }
173
+ printStatic(' ]');
174
+ return;
175
+ }
176
+ case Porffor.TYPES.uint32array: {
177
+ const arrLen: i32 = arg.length - 1;
178
+ printStatic('Uint32Array(');
179
+ print(arrLen + 1);
180
+ printStatic(') [ ');
181
+ for (let i: i32 = 0; i <= arrLen; i++) {
182
+ __Porffor_print(arg[i], colors);
183
+ if (i != arrLen) printStatic(', ');
184
+ }
185
+ printStatic(' ]');
186
+ return;
187
+ }
188
+ case Porffor.TYPES.int32array: {
189
+ const arrLen: i32 = arg.length - 1;
190
+ printStatic('Int32Array(');
191
+ print(arrLen + 1);
192
+ printStatic(') [ ');
193
+ for (let i: i32 = 0; i <= arrLen; i++) {
194
+ __Porffor_print(arg[i], colors);
195
+ if (i != arrLen) printStatic(', ');
196
+ }
197
+ printStatic(' ]');
198
+ return;
199
+ }
200
+ case Porffor.TYPES.float32array: {
201
+ const arrLen: i32 = arg.length - 1;
202
+ printStatic('Float32Array(');
203
+ print(arrLen + 1);
204
+ printStatic(') [ ');
205
+ for (let i: i32 = 0; i <= arrLen; i++) {
206
+ __Porffor_print(arg[i], colors);
207
+ if (i != arrLen) printStatic(', ');
208
+ }
209
+ printStatic(' ]');
210
+ return;
211
+ }
212
+ case Porffor.TYPES.float64array: {
213
+ const arrLen: i32 = arg.length - 1;
214
+ printStatic('Float64Array(');
215
+ print(arrLen + 1);
216
+ printStatic(') [ ');
217
+ for (let i: i32 = 0; i <= arrLen; i++) {
218
+ __Porffor_print(arg[i], colors);
219
+ if (i != arrLen) printStatic(', ');
220
+ }
221
+ printStatic(' ]');
222
+ return;
223
+ }
224
+
225
+ case Porffor.TYPES.sharedarraybuffer:
226
+ case Porffor.TYPES.arraybuffer: {
227
+ if (t == Porffor.TYPES.sharedarraybuffer) printStatic('SharedArrayBuffer');
228
+ else printStatic('ArrayBuffer');
229
+ printStatic(' {\n');
230
+
231
+ if (colors) printStatic('\x1b[34m'); // blue
232
+ printStatic(' [Uint8Contents]');
233
+ if (colors) printStatic('\x1b[m');
234
+ printStatic('): <');
235
+
236
+ const buffer = new Uint8Array(arg);
237
+ const bufferLen = buffer.length - 1;
238
+ for (let i = 0; i <= bufferLen; i++) {
239
+ const ele = buffer[i];
240
+ __Porffor_printHexDigit((ele & 0xF0) / 16);
241
+ __Porffor_printHexDigit(ele & 0xF);
242
+ if (i != bufferLen) printStatic(' ');
243
+ }
244
+
245
+ printStatic('>,\n byteLength: ');
246
+ if (colors) printStatic('\x1b[33m'); // yellow
247
+ print(arg.byteLength);
248
+ if (colors) printStatic('\x1b[m');
249
+ printStatic('\n}');
250
+ return;
251
+ }
252
+
253
+ case Porffor.TYPES.dataview: {
254
+ printStatic('DataView {\n');
255
+ printStatic(' byteLength: ');
256
+ __Porffor_print(arg.byteLength, colors);
257
+ printStatic(',\n byteOffset: ');
258
+ __Porffor_print(arg.byteOffset, colors);
259
+ printStatic(',\n buffer: ');
260
+ __Porffor_print(arg.buffer, colors);
261
+ printStatic('\n}');
262
+ return;
263
+ }
264
+
265
+ case Porffor.TYPES.weakmap:
266
+ case Porffor.TYPES.map: {
267
+ if (t == Porffor.TYPES.weakmap) printStatic('WeakMap');
268
+ else printStatic('Map');
269
+ printStatic('(');
270
+
271
+ const map = __Map_prototype_keys(arg);
272
+ const mapLen: i32 = map.length - 1;
273
+ print(mapLen + 1);
274
+ printStatic(') { ');
275
+
276
+ for (let i: i32 = 0; i < mapLen; i++) {
277
+ const key = map[i];
278
+ __Porffor_print(key);
279
+ printStatic(' => ');
280
+ __Porffor_print(__Map_prototype_get(arg, key), colors);
281
+ if (i != mapLen) printStatic(', ');
282
+ }
283
+
284
+ printStatic(' }');
285
+ return;
286
+ }
287
+
288
+ case Porffor.TYPES.weakset:
289
+ case Porffor.TYPES.set: {
290
+ if (t == Porffor.TYPES.weakset) printStatic('WeakSet');
291
+ else printStatic('Set');
292
+ printStatic('(');
293
+
294
+ const set = __Set_prototype_values(arg);
295
+ const setLen: i32 = set.length - 1;
296
+ print(setLen + 1);
297
+ printStatic(') { ');
298
+
299
+ for (let i: i32 = 0; i <= setLen; i++) {
300
+ __Porffor_print(set[i], colors);
301
+ if (i != setLen) printStatic(', ');
302
+ }
303
+
304
+ printStatic(' }');
305
+ return;
306
+ }
307
+
308
+ case Porffor.TYPES.weakref:
309
+ printStatic('WeakRef {}');
310
+ return;
311
+
312
+ case Porffor.TYPES.regexp:
313
+ // todo: we currently have no way of getting the source text, so this falls back
314
+
315
+ default:
316
+ __Porffor_printString(arg.toString());
317
+ return;
318
+ }
319
+ };
320
+
321
+ let tabLevel = 0;
322
+ export const __Porffor_consoleIndent = () => {
323
+ for (let i = 0; i < tabLevel; i++) {
324
+ printStatic('\t');
325
+ }
326
+ };
327
+
3
328
  export const __console_clear = () => {
4
- const clear: bytestring = '\x1b[1;1H\x1b[J';
5
- Porffor.print(clear);
329
+ printStatic('\x1b[1;1H\x1b[J');
330
+ tabLevel = 0;
331
+ };
332
+
333
+ export const __Porffor_consolePrint = (arg: any) => {
334
+ switch (Porffor.rawType(arg)) {
335
+ case Porffor.TYPES.bytestring:
336
+ case Porffor.TYPES.string:
337
+ __Porffor_printString(arg);
338
+ return;
339
+
340
+ default:
341
+ __Porffor_print(arg);
342
+ }
343
+ };
344
+
345
+ export const __console_group = (label: bytestring) => {
346
+ if (Porffor.rawType(label) != Porffor.TYPES.undefined) {
347
+ __Porffor_consoleIndent();
348
+ __Porffor_consolePrint(label);
349
+ }
350
+
351
+ tabLevel++;
352
+ };
353
+
354
+ export const __console_groupCollapsed = (label: bytestring) => __console_group(label);
355
+
356
+ export const __console_groupEnd = () => {
357
+ tabLevel--;
358
+ if (tabLevel < 0) tabLevel = 0;
359
+ };
360
+
361
+ export const __console_log = (...args: any[]) => {
362
+ const argLen: i32 = args.length - 1;
363
+ for (let i = 0; i <= argLen; i++) {
364
+ __Porffor_consoleIndent();
365
+ __Porffor_consolePrint(args[i]);
366
+
367
+ if (i != argLen) printStatic(' ');
368
+ }
369
+
370
+ printStatic('\n');
371
+ };
372
+
373
+ export const __console_debug = (...args: any[]) => {
374
+ const argLen: i32 = args.length - 1;
375
+ for (let i = 0; i <= argLen; i++) {
376
+ __Porffor_consoleIndent();
377
+ __Porffor_consolePrint(args[i]);
378
+
379
+ if (i != argLen) printStatic(' ');
380
+ }
381
+
382
+ printStatic('\n');
383
+ };
384
+
385
+ export const __console_info = (...args: any[]) => {
386
+ const argLen: i32 = args.length - 1;
387
+ for (let i = 0; i <= argLen; i++) {
388
+ __Porffor_consoleIndent();
389
+ __Porffor_consolePrint(args[i]);
390
+
391
+ if (i != argLen) printStatic(' ');
392
+ }
393
+
394
+ printStatic('\n');
395
+ };
396
+
397
+ export const __console_warn = (...args: any[]) => {
398
+ const argLen: i32 = args.length - 1;
399
+ for (let i = 0; i <= argLen; i++) {
400
+ __Porffor_consoleIndent();
401
+ __Porffor_consolePrint(args[i]);
402
+
403
+ if (i != argLen) printStatic(' ');
404
+ }
405
+
406
+ printStatic('\n');
407
+ };
408
+
409
+ export const __console_error = (...args: any[]) => {
410
+ const argLen: i32 = args.length - 1;
411
+ for (let i = 0; i <= argLen; i++) {
412
+ __Porffor_consoleIndent();
413
+ __Porffor_consolePrint(args[i]);
414
+
415
+ if (i != argLen) printStatic(' ');
416
+ }
417
+
418
+ printStatic('\n');
419
+ };
420
+
421
+ export const __console_assert = (assertion: any, ...args: any[]) => {
422
+ if (assertion) return;
423
+
424
+ __Porffor_consoleIndent();
425
+ printStatic('Assertion failed');
426
+ if (args.length != 0) {
427
+ printStatic(': ');
428
+ }
429
+
430
+ const argLen: i32 = args.length - 1;
431
+ for (let i = 0; i <= argLen; i++) {
432
+ __Porffor_consolePrint(args[i]);
433
+ if (i != argLen) printStatic(' ');
434
+ }
435
+
436
+ printStatic('\n');
437
+ };
438
+
439
+ export const __Porffor_dirObject = (obj: any, colors: boolean, depth: i32, showHidden: boolean) => {
440
+ if (Porffor.rawType(obj) != Porffor.TYPES.object || depth == 0) {
441
+ __Porffor_print(obj, colors);
442
+ return;
443
+ }
444
+
445
+ printStatic('{ ');
446
+
447
+ const keys = __Map_prototype_keys(obj);
448
+ const keysLen = keys.length - 1;
449
+ for (let i = 0; i <= keysLen; i++) {
450
+ const key = keys[i];
451
+ __Porffor_consolePrint(key);
452
+ printStatic(': ');
453
+
454
+ const value = __Map_prototype_get(obj, key);
455
+ __Porffor_dirObject(value, colors, depth - 1, showHidden);
456
+
457
+ if (i != keysLen) printStatic(',');
458
+ }
459
+
460
+ printStatic(' }');
461
+ };
462
+
463
+ export const __console_dir = (obj: any, options: any) => {
464
+ let colors: boolean = true;
465
+ let depth: i32 = 2;
466
+
467
+ // todo: we currently have no concept of enumerable or nonenumerable properties, so this does nothing
468
+ let showHidden: boolean = false;
469
+
470
+ if (options) {
471
+ colors = options.colors;
472
+ depth = options.depth;
473
+ showHidden = options.showHidden;
474
+ }
475
+
476
+ __Porffor_consoleIndent();
477
+ __Porffor_dirObject(obj, colors, depth, showHidden);
478
+ printStatic('\n');
479
+ };
480
+
481
+ export const __console_dirxml = (obj: any) => __console_dir(obj);
482
+
483
+ const countMap = new Map();
484
+ export const __console_count = (label: any) => {
485
+ label ??= 'default';
486
+ const val = (countMap.get(label) ?? 0) + 1;
487
+ countMap.set(label, val);
488
+
489
+ __Porffor_consoleIndent();
490
+ __Porffor_consolePrint(label);
491
+ printStatic(': ');
492
+ print(val);
493
+ printStatic('\n');
494
+ };
495
+
496
+ export const __console_countReset = (label: any) => {
497
+ label ??= 'default';
498
+ countMap.set(label, -1);
499
+ __console_count(label);
500
+ };
501
+
502
+ const timeMap = new Map();
503
+ export const __console_time = (label: any) => {
504
+ label ??= 'default';
505
+
506
+ // warn if label already exists
507
+ if (timeMap.has(label)) {
508
+ printStatic("Warning: Timer '");
509
+ __Porffor_consolePrint(label);
510
+ printStatic("' already exists for console.time()\n");
511
+ }
512
+
513
+ timeMap.set(label, performance.now());
514
+ };
515
+
516
+ export const __console_timeLog = (label: any) => {
517
+ label ??= 'default';
518
+ __Porffor_consoleIndent();
519
+
520
+ const val = timeMap.get(label);
521
+ if (!val) {
522
+ printStatic("Timer '");
523
+ __Porffor_consolePrint(label);
524
+ printStatic("' does not exist\n");
525
+ return;
526
+ }
527
+
528
+ __Porffor_consolePrint(label);
529
+ printStatic(': ');
530
+
531
+ print(performance.now() - val);
532
+ printStatic(' ms\n');
533
+ };
534
+
535
+ export const __console_timeEnd = (label: any) => {
536
+ label ??= 'default';
537
+
538
+ __console_timeLog(label);
539
+ timeMap.delete(label);
6
540
  };
@@ -78,6 +78,15 @@ type PorfforGlobal = {
78
78
  declare global {
79
79
  const Porffor: PorfforGlobal;
80
80
 
81
+ const ecma262: {
82
+ ToIntegerOrInfinity(argument: unknown): number;
83
+ ToString(argument: unknown): bytestring;
84
+ }
85
+
86
+ const print: (arg: any) => void;
87
+ const printChar: (char: number) => void;
88
+ const printStatic: (str: string) => void;
89
+
81
90
  type i32 = number;
82
91
  type i64 = number;
83
92
  type f64 = number;
@@ -1,30 +1,33 @@
1
1
  import type {} from './porffor.d.ts';
2
2
 
3
- export const __Porffor_symbol_descStore = (op: boolean, value: any): any => {
4
- const ptr: bytestring = '';
5
-
6
- if (op) { // write
7
- const size: number = Porffor.wasm.i32.load(ptr, 0, 0);
8
- Porffor.wasm.i32.store(ptr, size + 1, 0, 0)
9
-
10
- // reuse set internals to store description
11
- Porffor.set.write(ptr, size, value);
12
- return size;
13
- } else { // read
14
- return Porffor.set.read(ptr, value);
15
- }
16
- };
3
+ const descStore: any[] = new Array(0);
17
4
 
5
+ // 20.4.1.1 Symbol ([ description ])
6
+ // https://tc39.es/ecma262/#sec-symbol-description
18
7
  export const Symbol = (description: any): Symbol => {
8
+ // 1. If NewTarget is not undefined, throw a TypeError exception.
9
+ // This is an arrow function so happens implicitly
10
+
11
+ // 2. If description is undefined, let descString be undefined.
12
+ let descString: any = undefined;
13
+
14
+ // 3. Else, let descString be ? ToString(description).
15
+ if (Porffor.rawType(description) != Porffor.TYPES.undefined) {
16
+ descString = ecma262.ToString(description);
17
+ }
18
+
19
+ // 4. Return a new Symbol whose [[Description]] is descString.
20
+ let len: i32 = descStore.length;
21
+ descStore[len] = descString;
22
+ descStore.length = ++len;
23
+
19
24
  // 1-based so always truthy as numeric value
20
- const ptr: Symbol = __Porffor_symbol_descStore(true, description) + 1;
21
- return ptr;
25
+ const sym: Symbol = len;
26
+ return sym;
22
27
  };
23
28
 
24
29
  export const __Symbol_prototype_description$get = (_this: Symbol) => {
25
- const description: bytestring =
26
- __Porffor_symbol_descStore(false, Porffor.wasm`local.get ${_this}` - 1);
27
- return description;
30
+ return descStore[Porffor.wasm`local.get ${_this}` - 1];
28
31
  };
29
32
 
30
33
  export const __Symbol_prototype_toString = (_this: Symbol) => {
@@ -39,15 +42,20 @@ export const __Symbol_prototype_toString = (_this: Symbol) => {
39
42
  Porffor.wasm.i32.store8(out, 108, 0, 9);
40
43
  Porffor.wasm.i32.store8(out, 40, 0, 10);
41
44
 
42
- const description: bytestring =
43
- __Porffor_symbol_descStore(false, Porffor.wasm`local.get ${_this}` - 1);
45
+ const description: any = descStore[Porffor.wasm`local.get ${_this}` - 1];
46
+ let descLen: i32 = 0;
47
+ if (description !== undefined) {
48
+ descLen = description.length;
49
+
50
+ print(descLen);
44
51
 
45
- const descLen: i32 = description.length;
46
- let outPtr: i32 = Porffor.wasm`local.get ${out}` + 7;
47
- let descPtr: i32 = Porffor.wasm`local.get ${description}`;
48
- const descPtrEnd: i32 = descPtr + descLen;
49
- while (descPtr < descPtrEnd) {
50
- Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(descPtr++, 0, 4), 0, 4);
52
+ // todo: support regular string
53
+ let outPtr: i32 = Porffor.wasm`local.get ${out}` + 7;
54
+ let descPtr: i32 = Porffor.wasm`local.get ${description}`;
55
+ const descPtrEnd: i32 = descPtr + descLen;
56
+ while (descPtr < descPtrEnd) {
57
+ Porffor.wasm.i32.store8(outPtr++, Porffor.wasm.i32.load8_u(descPtr++, 0, 4), 0, 4);
58
+ }
51
59
  }
52
60
 
53
61
  // )
@@ -64,7 +72,7 @@ export const __Symbol_prototype_valueOf = (_this: Symbol) => {
64
72
  return _this;
65
73
  };
66
74
 
67
- const forStore = new Map();
75
+ const forStore: Map = new Map();
68
76
  export const __Symbol_for = (key: any): Symbol => {
69
77
  if (forStore.has(key)) return forStore.get(key);
70
78
 
@@ -38,7 +38,9 @@ export const __ecma262_ToString = (argument: unknown): bytestring => {
38
38
  if (type == Porffor.TYPES.symbol) throw new TypeError('Cannot convert a Symbol value to a string');
39
39
 
40
40
  // 3. If argument is undefined, return "undefined".
41
- if (type == Porffor.TYPES.undefined) return out = 'undefined';
41
+ if (Porffor.fastOr(
42
+ type == Porffor.TYPES.undefined,
43
+ type == Porffor.TYPES.empty)) return out = 'undefined';
42
44
 
43
45
  // 4. If argument is null, return "null".
44
46
  if (Porffor.fastAnd(