From f28544ec25ceee5fe2b783f1980cdf19caf0e977 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Sat, 22 Jan 2022 20:34:21 +0000 Subject: Implement fgh and gh trains --- print.c | 54 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 18 deletions(-) (limited to 'print.c') diff --git a/print.c b/print.c index e0619a6..564956b 100644 --- a/print.c +++ b/print.c @@ -16,27 +16,11 @@ ppdatum(Datum d) Rune *result; switch(d.tag){ case ArrayTag: result = pparray(d.array); break; - case FunctionTag: - if(d.func.type == FunctypePrim) - result = runesmprint("%C", primfuncnames[d.func.code]); - else if(d.func.type == FunctypeDfn) - result = runesmprint("{%S}", d.func.dfn); - else if(d.func.type == FunctypeOp) - result = runesmprint("%S", ppoperator(d.func.operator)); - else - result = runesmprint("%S", d.func.quad->name); - break; + case FunctionTag: result = ppfunction(d.func); break; case HybridTag: result = runesmprint("%C", primhybridnames[d.func.code]); break; case MonadicOpTag: case DyadicOpTag: result = ppoperator(d.operator); break; - case BoundFunctionTag: - if(d.func.type == FunctypePrim) - result = runesmprint("%S∘%C", pparray(d.func.left), primfuncnames[d.func.code]); - else if(d.func.type == FunctypeDfn) - result = runesmprint("%S∘{%S}", pparray(d.func.left), d.func.dfn); - else - result = runesmprint("%S∘%S", pparray(d.func.left), ppoperator(d.func.operator)); - break; + case BoundFunctionTag: result = runesmprint("%S∘%S", pparray(d.func.left), ppfunction(d.func)); break; case LParTag: result = runestrdup(L"("); break; case RParTag: result = runestrdup(L")"); break; case ArrowTag: result = runestrdup(L"←"); break; @@ -207,6 +191,40 @@ ppoperator(Operator op) return res; } +Rune * +ppfunction(Function f) +{ + Rune *result; + switch(f.type){ + case FunctypePrim: + result = runesmprint("%C", primfuncnames[f.code]); + break; + case FunctypeDfn: + result = runesmprint("{%S}", f.dfn); + break; + case FunctypeOp: + result = runesmprint("%S", ppoperator(f.operator)); + break; + case FunctypeQuad: + result = runesmprint("%S", f.quad->name); + break; + case FunctypeTrain: + result = runesmprint(""); + for(int i = 0; i < f.train.nfuncs; i++){ + Rune *tmp = result; + Rune *fun = ppfunction(f.train.funcs[i]); + result = runesmprint("%S%S", tmp, fun); + free(tmp); + free(fun); + } + break; + default: + result = runesmprint("", f.type); + break; + } + return result; +} + void strdims(Rune *s, int *width, int *height) { -- cgit v1.2.3