summaryrefslogtreecommitdiff
path: root/print.c
diff options
context:
space:
mode:
authorPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-22 20:34:21 +0000
committerPeter Mikkelsen <petermikkelsen10@gmail.com>2022-01-22 20:34:21 +0000
commitf28544ec25ceee5fe2b783f1980cdf19caf0e977 (patch)
treef4a0658fc30b6c1ea1e7acde8e17985c479a3fce /print.c
parent09d3d9272193a809cca535019f34cc5e7a5d4953 (diff)
Implement fgh and gh trains
Diffstat (limited to 'print.c')
-rw-r--r--print.c54
1 files changed, 36 insertions, 18 deletions
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("<non printable function type %d>", f.type);
+ break;
+ }
+ return result;
+}
+
void
strdims(Rune *s, int *width, int *height)
{