diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index c0933053..ee13e347 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -13,7 +13,7 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@v3 - - uses: dsherret/rust-toolchain-file@v1 + - uses: dtolnay/rust-toolchain@nightly - name: compare perf run: | git fetch origin main diff --git a/src/hvm.c b/src/hvm.c index 628525de..5ec73c62 100644 --- a/src/hvm.c +++ b/src/hvm.c @@ -2065,84 +2065,69 @@ void pretty_print_numb(Numb word) { } void pretty_print_port(Net* net, Book* book, Port port) { - Port stack[256]; - stack[0] = port; - u32 len = 1; - u32 num = 0; - while (len > 0) { - Port cur = stack[--len]; - switch (get_tag(cur)) { - case CON: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case ERA: { - if (get_val(cur) != 0) { - printf("%c", (char)get_val(cur)); - } else { - printf("*"); - } - break; - } - case VAR: { - Port got = vars_load(net, get_val(cur)); - if (got != NONE) { - stack[len++] = got; - } else { - printf("x%x", get_val(cur)); - } - break; - } - case NUM: { - pretty_print_numb(get_val(cur)); - break; - } - case DUP: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("{"); - stack[len++] = new_port(ERA, (u32)('}')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case OPR: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("$("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case SWI: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("?("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; + switch (get_tag(port)) { + case CON: { + Pair node = node_load(net, get_val(port)); + printf("("); + pretty_print_port(net, book, get_fst(node)); + printf(" "); + pretty_print_port(net, book, get_snd(node)); + printf(")"); + return; + } + case ERA: { + if (get_val(port) != 0) { + printf("%c", (char) get_val(port)); + } else { + printf("*"); } - case REF: { - u32 fid = get_val(cur) & 0xFFFFFFF; - Def* def = &book->defs_buf[fid]; - printf("@%s", def->name); - break; + return; + } + case VAR: { + Port val = vars_load(net, get_val(port)); + if (val != NONE) { + pretty_print_port(net, book, val); + } else { + printf("x%x", get_val(port)); } + return; + } + case NUM: { + pretty_print_numb(get_val(port)); + return; + } + case DUP: { + Pair node = node_load(net, get_val(port)); + printf("{"); + pretty_print_port(net, book, get_fst(node)); + printf(" "); + pretty_print_port(net, book, get_snd(node)); + printf("}"); + return; + } + case OPR: { + Pair node = node_load(net, get_val(port)); + printf("$("); + pretty_print_port(net, book, get_fst(node)); + printf(" "); + pretty_print_port(net, book, get_snd(node)); + printf(")"); + return; + } + case SWI: { + Pair node = node_load(net, get_val(port)); + printf("?("); + pretty_print_port(net, book, get_fst(node)); + printf(" "); + pretty_print_port(net, book, get_snd(node)); + printf(")"); + return; + } + case REF: { + u32 fid = get_val(port) & 0xFFFFFFF; + Def* def = &book->defs_buf[fid]; + printf("@%s", def->name); + return; } } } diff --git a/src/hvm.cu b/src/hvm.cu index 3ecd5cfd..fc3dc135 100644 --- a/src/hvm.cu +++ b/src/hvm.cu @@ -2545,88 +2545,69 @@ __device__ void pretty_print_numb(Numb word) { } __device__ void pretty_print_port(Net* net, Port port) { - Port stack[256]; - stack[0] = port; - u32 len = 1; - while (len > 0) { - if (len > 256) { - printf("ERROR: result too deep to print. This will be fixed soon(TM)"); - --len; - continue; + switch (get_tag(port)) { + case CON: { + Pair node = node_load(net, get_val(port)); + printf("("); + pretty_print_port(net, get_fst(node)); + printf(" "); + pretty_print_port(net, get_snd(node)); + printf(")"); + return; } - Port cur = stack[--len]; - switch (get_tag(cur)) { - case CON: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case ERA: { - if (get_val(cur) != 0) { - printf("%c", (char)get_val(cur)); - } else { - printf("*"); - } - break; - } - case VAR: { - Port got = vars_load(net, get_val(cur)); - if (got != NONE) { - stack[len++] = got; - } else { - printf("x%x", get_val(cur)); - } - break; - } - case NUM: { - pretty_print_numb(get_val(cur)); - break; - } - case DUP: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("{"); - stack[len++] = new_port(ERA, (u32)('}')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case OPR: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("$("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; - } - case SWI: { - Pair node = node_load(net,get_val(cur)); - Port p2 = get_snd(node); - Port p1 = get_fst(node); - printf("?("); - stack[len++] = new_port(ERA, (u32)(')')); - stack[len++] = p2; - stack[len++] = new_port(ERA, (u32)(' ')); - stack[len++] = p1; - break; + case ERA: { + if (get_val(port) != 0) { + printf("%c", (char) get_val(port)); + } else { + printf("*"); } - case REF: { - u32 fid = get_val(cur) & 0xFFFFFFF; - Def* def = &BOOK.defs_buf[fid]; - printf("@%s", def->name); - break; + return; + } + case VAR: { + Port val = vars_load(net, get_val(port)); + if (val != NONE) { + pretty_print_port(net, val); + } else { + printf("x%x", get_val(port)); } + return; + } + case NUM: { + pretty_print_numb(get_val(port)); + return; + } + case DUP: { + Pair node = node_load(net, get_val(port)); + printf("{"); + pretty_print_port(net, get_fst(node)); + printf(" "); + pretty_print_port(net, get_snd(node)); + printf("}"); + return; + } + case OPR: { + Pair node = node_load(net, get_val(port)); + printf("$("); + pretty_print_port(net, get_fst(node)); + printf(" "); + pretty_print_port(net, get_snd(node)); + printf(")"); + return; + } + case SWI: { + Pair node = node_load(net, get_val(port)); + printf("?("); + pretty_print_port(net, get_fst(node)); + printf(" "); + pretty_print_port(net, get_snd(node)); + printf(")"); + return; + } + case REF: { + u32 fid = get_val(port) & 0xFFFFFFF; + Def* def = &BOOK.defs_buf[fid]; + printf("@%s", def->name); + return; } } }