Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused type checks #120

Merged
merged 14 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
207 changes: 73 additions & 134 deletions compiler/builtins/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,29 @@ export const __Porffor_miniLog = (arg: any) => {
export const __Porffor_print = (arg: any, colors: boolean = true) => {
// todo: Symbol.toStringTag could reduce duplication here

const t: i32 = Porffor.rawType(arg);
CanadaHonk marked this conversation as resolved.
Show resolved Hide resolved
switch (t) {
// note: this doesn't have access to the upper scope!! do not use any variables from up there
const __Porffor_printArray = (arg: any, colors: boolean, length: boolean = false) => {
CanadaHonk marked this conversation as resolved.
Show resolved Hide resolved
const arrLen: i32 = arg.length - 1;

if (length) {
printStatic('(');
print(arrLen + 1);
printStatic(') ');
}

if (arrLen == -1) {
printStatic('[]');
} else {
printStatic('[ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');
}
};

switch (Porffor.rawType(arg)) {
case Porffor.TYPES.number:
if (colors) printStatic('\x1b[33m'); // yellow
print(arg);
Expand Down Expand Up @@ -118,20 +139,6 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
if (colors) printStatic('\x1b[0m');
return;

case Porffor.TYPES.array:
const arrLen: i32 = arg.length - 1;
if (arrLen == -1) {
printStatic('[]');
} else {
printStatic('[ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');
}
return;

case Porffor.TYPES.empty:
case Porffor.TYPES.undefined:
if (colors) printStatic('\x1b[2m'); // dim
Expand Down Expand Up @@ -185,118 +192,58 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
if (colors) printStatic('\x1b[0m');
return;

case Porffor.TYPES.uint8array: {
const arrLen: i32 = arg.length - 1;
printStatic('Uint8Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');
case Porffor.TYPES.array:
__Porffor_printArray(arg, colors, false);
return;
}
case Porffor.TYPES.int8array: {
const arrLen: i32 = arg.length - 1;
printStatic('Int8Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.uint8array:
printStatic('Uint8Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.uint8clampedarray: {
const arrLen: i32 = arg.length - 1;
printStatic('Uint8ClampedArray(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.int8array:
printStatic('Int8Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.uint16array: {
const arrLen: i32 = arg.length - 1;
printStatic('Uint16Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.uint8clampedarray:
printStatic('Uint8ClampedArray');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.int16array: {
const arrLen: i32 = arg.length - 1;
printStatic('Int16Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.uint16array:
printStatic('Uint16Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.uint32array: {
const arrLen: i32 = arg.length - 1;
printStatic('Uint32Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.int16array:
printStatic('Int16Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.int32array: {
const arrLen: i32 = arg.length - 1;
printStatic('Int32Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.uint32array:
printStatic('Uint32Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.float32array: {
const arrLen: i32 = arg.length - 1;
printStatic('Float32Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.int32array:
printStatic('Int32Array');
__Porffor_printArray(arg, colors, true);
return;
}
case Porffor.TYPES.float64array: {
const arrLen: i32 = arg.length - 1;
printStatic('Float64Array(');
print(arrLen + 1);
printStatic(') [ ');
for (let i: i32 = 0; i <= arrLen; i++) {
__Porffor_print(arg[i], colors);
if (i != arrLen) printStatic(', ');
}
printStatic(' ]');

case Porffor.TYPES.float32array:
printStatic('Float32Array');
__Porffor_printArray(arg, colors, true);
return;

case Porffor.TYPES.float64array:
printStatic('Float64Array');
__Porffor_printArray(arg, colors, true);
return;
}

case Porffor.TYPES.sharedarraybuffer:
case Porffor.TYPES.arraybuffer: {
if (t == Porffor.TYPES.sharedarraybuffer) printStatic('SharedArrayBuffer');
case Porffor.TYPES.arraybuffer:
if (Porffor.rawType(arg) == Porffor.TYPES.sharedarraybuffer) printStatic('SharedArrayBuffer');
else printStatic('ArrayBuffer');
printStatic(' {\n');

Expand All @@ -320,9 +267,8 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
if (colors) printStatic('\x1b[0m');
printStatic('\n}');
return;
}

case Porffor.TYPES.dataview: {
case Porffor.TYPES.dataview:
printStatic('DataView {\n');
printStatic(' byteLength: ');
__Porffor_print(arg.byteLength, colors);
Expand All @@ -332,11 +278,10 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {
__Porffor_print(arg.buffer, colors);
printStatic('\n}');
return;
}

case Porffor.TYPES.weakmap:
case Porffor.TYPES.map: {
if (t == Porffor.TYPES.weakmap) printStatic('WeakMap');
case Porffor.TYPES.map:
if (Porffor.rawType(arg) == Porffor.TYPES.weakmap) printStatic('WeakMap');
else printStatic('Map');
printStatic('(');

Expand All @@ -355,11 +300,10 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {

printStatic(' }');
return;
}

case Porffor.TYPES.weakset:
case Porffor.TYPES.set: {
if (t == Porffor.TYPES.weakset) printStatic('WeakSet');
case Porffor.TYPES.set:
if (Porffor.rawType(arg) == Porffor.TYPES.weakset) printStatic('WeakSet');
else printStatic('Set');
printStatic('(');

Expand All @@ -375,7 +319,6 @@ export const __Porffor_print = (arg: any, colors: boolean = true) => {

printStatic(' }');
return;
}

case Porffor.TYPES.weakref:
printStatic('WeakRef {}');
Expand Down Expand Up @@ -403,15 +346,11 @@ export const __console_clear = () => {
};

export const __Porffor_consolePrint = (arg: any) => {
switch (Porffor.rawType(arg)) {
case Porffor.TYPES.bytestring:
case Porffor.TYPES.string:
__Porffor_printString(arg);
return;

default:
__Porffor_print(arg);
if (Porffor.fastOr(Porffor.rawType(arg) == Porffor.TYPES.bytestring, Porffor.rawType(arg) == Porffor.TYPES.string)) {
__Porffor_printString(arg);
return;
}
__Porffor_print(arg);
};

export const __console_group = (label: bytestring) => {
Expand Down
520 changes: 263 additions & 257 deletions compiler/builtins_precompiled.js

Large diffs are not rendered by default.

Loading