porffor 0.28.1 → 0.28.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/compiler/builtins/console.ts +73 -134
- package/compiler/builtins_precompiled.js +263 -257
- package/compiler/codegen.js +181 -34
- package/compiler/opt.js +42 -10
- package/compiler/precompile.js +3 -1
- package/package.json +1 -1
- package/runner/index.js +1 -1
@@ -89,8 +89,29 @@ export const __Porffor_miniLog = (arg: any) => {
|
|
89
89
|
export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
90
90
|
// todo: Symbol.toStringTag could reduce duplication here
|
91
91
|
|
92
|
-
|
93
|
-
|
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
|
+
printStatic('(');
|
98
|
+
print(arrLen + 1);
|
99
|
+
printStatic(') ');
|
100
|
+
}
|
101
|
+
|
102
|
+
if (arrLen == -1) {
|
103
|
+
printStatic('[]');
|
104
|
+
} else {
|
105
|
+
printStatic('[ ');
|
106
|
+
for (let i: i32 = 0; i <= arrLen; i++) {
|
107
|
+
__Porffor_print(arg[i], colors);
|
108
|
+
if (i != arrLen) printStatic(', ');
|
109
|
+
}
|
110
|
+
printStatic(' ]');
|
111
|
+
}
|
112
|
+
};
|
113
|
+
|
114
|
+
switch (Porffor.rawType(arg)) {
|
94
115
|
case Porffor.TYPES.number:
|
95
116
|
if (colors) printStatic('\x1b[33m'); // yellow
|
96
117
|
print(arg);
|
@@ -118,20 +139,6 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
118
139
|
if (colors) printStatic('\x1b[0m');
|
119
140
|
return;
|
120
141
|
|
121
|
-
case Porffor.TYPES.array:
|
122
|
-
const arrLen: i32 = arg.length - 1;
|
123
|
-
if (arrLen == -1) {
|
124
|
-
printStatic('[]');
|
125
|
-
} else {
|
126
|
-
printStatic('[ ');
|
127
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
128
|
-
__Porffor_print(arg[i], colors);
|
129
|
-
if (i != arrLen) printStatic(', ');
|
130
|
-
}
|
131
|
-
printStatic(' ]');
|
132
|
-
}
|
133
|
-
return;
|
134
|
-
|
135
142
|
case Porffor.TYPES.empty:
|
136
143
|
case Porffor.TYPES.undefined:
|
137
144
|
if (colors) printStatic('\x1b[2m'); // dim
|
@@ -185,118 +192,58 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
185
192
|
if (colors) printStatic('\x1b[0m');
|
186
193
|
return;
|
187
194
|
|
188
|
-
case Porffor.TYPES.
|
189
|
-
|
190
|
-
printStatic('Uint8Array(');
|
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(' ]');
|
195
|
+
case Porffor.TYPES.array:
|
196
|
+
__Porffor_printArray(arg, colors, false);
|
198
197
|
return;
|
199
|
-
|
200
|
-
case Porffor.TYPES.
|
201
|
-
|
202
|
-
|
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(' ]');
|
198
|
+
|
199
|
+
case Porffor.TYPES.uint8array:
|
200
|
+
printStatic('Uint8Array');
|
201
|
+
__Porffor_printArray(arg, colors, true);
|
210
202
|
return;
|
211
|
-
|
212
|
-
case Porffor.TYPES.
|
213
|
-
|
214
|
-
|
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(' ]');
|
203
|
+
|
204
|
+
case Porffor.TYPES.int8array:
|
205
|
+
printStatic('Int8Array');
|
206
|
+
__Porffor_printArray(arg, colors, true);
|
222
207
|
return;
|
223
|
-
|
224
|
-
case Porffor.TYPES.
|
225
|
-
|
226
|
-
|
227
|
-
print(arrLen + 1);
|
228
|
-
printStatic(') [ ');
|
229
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
230
|
-
__Porffor_print(arg[i], colors);
|
231
|
-
if (i != arrLen) printStatic(', ');
|
232
|
-
}
|
233
|
-
printStatic(' ]');
|
208
|
+
|
209
|
+
case Porffor.TYPES.uint8clampedarray:
|
210
|
+
printStatic('Uint8ClampedArray');
|
211
|
+
__Porffor_printArray(arg, colors, true);
|
234
212
|
return;
|
235
|
-
|
236
|
-
case Porffor.TYPES.
|
237
|
-
|
238
|
-
|
239
|
-
print(arrLen + 1);
|
240
|
-
printStatic(') [ ');
|
241
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
242
|
-
__Porffor_print(arg[i], colors);
|
243
|
-
if (i != arrLen) printStatic(', ');
|
244
|
-
}
|
245
|
-
printStatic(' ]');
|
213
|
+
|
214
|
+
case Porffor.TYPES.uint16array:
|
215
|
+
printStatic('Uint16Array');
|
216
|
+
__Porffor_printArray(arg, colors, true);
|
246
217
|
return;
|
247
|
-
|
248
|
-
case Porffor.TYPES.
|
249
|
-
|
250
|
-
|
251
|
-
print(arrLen + 1);
|
252
|
-
printStatic(') [ ');
|
253
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
254
|
-
__Porffor_print(arg[i], colors);
|
255
|
-
if (i != arrLen) printStatic(', ');
|
256
|
-
}
|
257
|
-
printStatic(' ]');
|
218
|
+
|
219
|
+
case Porffor.TYPES.int16array:
|
220
|
+
printStatic('Int16Array');
|
221
|
+
__Porffor_printArray(arg, colors, true);
|
258
222
|
return;
|
259
|
-
|
260
|
-
case Porffor.TYPES.
|
261
|
-
|
262
|
-
|
263
|
-
print(arrLen + 1);
|
264
|
-
printStatic(') [ ');
|
265
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
266
|
-
__Porffor_print(arg[i], colors);
|
267
|
-
if (i != arrLen) printStatic(', ');
|
268
|
-
}
|
269
|
-
printStatic(' ]');
|
223
|
+
|
224
|
+
case Porffor.TYPES.uint32array:
|
225
|
+
printStatic('Uint32Array');
|
226
|
+
__Porffor_printArray(arg, colors, true);
|
270
227
|
return;
|
271
|
-
|
272
|
-
case Porffor.TYPES.
|
273
|
-
|
274
|
-
|
275
|
-
print(arrLen + 1);
|
276
|
-
printStatic(') [ ');
|
277
|
-
for (let i: i32 = 0; i <= arrLen; i++) {
|
278
|
-
__Porffor_print(arg[i], colors);
|
279
|
-
if (i != arrLen) printStatic(', ');
|
280
|
-
}
|
281
|
-
printStatic(' ]');
|
228
|
+
|
229
|
+
case Porffor.TYPES.int32array:
|
230
|
+
printStatic('Int32Array');
|
231
|
+
__Porffor_printArray(arg, colors, true);
|
282
232
|
return;
|
283
|
-
|
284
|
-
case Porffor.TYPES.
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
}
|
293
|
-
printStatic(' ]');
|
233
|
+
|
234
|
+
case Porffor.TYPES.float32array:
|
235
|
+
printStatic('Float32Array');
|
236
|
+
__Porffor_printArray(arg, colors, true);
|
237
|
+
return;
|
238
|
+
|
239
|
+
case Porffor.TYPES.float64array:
|
240
|
+
printStatic('Float64Array');
|
241
|
+
__Porffor_printArray(arg, colors, true);
|
294
242
|
return;
|
295
|
-
}
|
296
243
|
|
297
244
|
case Porffor.TYPES.sharedarraybuffer:
|
298
|
-
case Porffor.TYPES.arraybuffer:
|
299
|
-
if (
|
245
|
+
case Porffor.TYPES.arraybuffer:
|
246
|
+
if (Porffor.rawType(arg) == Porffor.TYPES.sharedarraybuffer) printStatic('SharedArrayBuffer');
|
300
247
|
else printStatic('ArrayBuffer');
|
301
248
|
printStatic(' {\n');
|
302
249
|
|
@@ -320,9 +267,8 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
320
267
|
if (colors) printStatic('\x1b[0m');
|
321
268
|
printStatic('\n}');
|
322
269
|
return;
|
323
|
-
}
|
324
270
|
|
325
|
-
case Porffor.TYPES.dataview:
|
271
|
+
case Porffor.TYPES.dataview:
|
326
272
|
printStatic('DataView {\n');
|
327
273
|
printStatic(' byteLength: ');
|
328
274
|
__Porffor_print(arg.byteLength, colors);
|
@@ -332,11 +278,10 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
332
278
|
__Porffor_print(arg.buffer, colors);
|
333
279
|
printStatic('\n}');
|
334
280
|
return;
|
335
|
-
}
|
336
281
|
|
337
282
|
case Porffor.TYPES.weakmap:
|
338
|
-
case Porffor.TYPES.map:
|
339
|
-
if (
|
283
|
+
case Porffor.TYPES.map:
|
284
|
+
if (Porffor.rawType(arg) == Porffor.TYPES.weakmap) printStatic('WeakMap');
|
340
285
|
else printStatic('Map');
|
341
286
|
printStatic('(');
|
342
287
|
|
@@ -355,11 +300,10 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
355
300
|
|
356
301
|
printStatic(' }');
|
357
302
|
return;
|
358
|
-
}
|
359
303
|
|
360
304
|
case Porffor.TYPES.weakset:
|
361
|
-
case Porffor.TYPES.set:
|
362
|
-
if (
|
305
|
+
case Porffor.TYPES.set:
|
306
|
+
if (Porffor.rawType(arg) == Porffor.TYPES.weakset) printStatic('WeakSet');
|
363
307
|
else printStatic('Set');
|
364
308
|
printStatic('(');
|
365
309
|
|
@@ -375,7 +319,6 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
|
|
375
319
|
|
376
320
|
printStatic(' }');
|
377
321
|
return;
|
378
|
-
}
|
379
322
|
|
380
323
|
case Porffor.TYPES.weakref:
|
381
324
|
printStatic('WeakRef {}');
|
@@ -403,15 +346,11 @@ export const __console_clear = () => {
|
|
403
346
|
};
|
404
347
|
|
405
348
|
export const __Porffor_consolePrint = (arg: any) => {
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
__Porffor_printString(arg);
|
410
|
-
return;
|
411
|
-
|
412
|
-
default:
|
413
|
-
__Porffor_print(arg);
|
349
|
+
if (Porffor.fastOr(Porffor.rawType(arg) == Porffor.TYPES.bytestring, Porffor.rawType(arg) == Porffor.TYPES.string)) {
|
350
|
+
__Porffor_printString(arg);
|
351
|
+
return;
|
414
352
|
}
|
353
|
+
__Porffor_print(arg);
|
415
354
|
};
|
416
355
|
|
417
356
|
export const __console_group = (label: bytestring) => {
|