From 6ed5b9f6d3fdeeed8ecd43b18bae642ec1ec24b1 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Wed, 9 Feb 2022 01:16:03 +0000 Subject: Add much better memory handling (We now track and free Datum * structs) --- print.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'print.c') diff --git a/print.c b/print.c index 45bca53..232fc54 100644 --- a/print.c +++ b/print.c @@ -11,28 +11,28 @@ Rune *printborder(Rune *, int *, int, int); Rune *strline(Rune *, int); Rune * -ppdatum(Datum d) +ppdatum(Datum *d) { Rune *result; - switch(d.tag){ - case ArrayTag: result = pparray(d.array); break; + switch(d->tag){ + case ArrayTag: result = pparray(d->array); break; case BoundFunctionTag: - case FunctionTag: result = ppfunction(d.func); break; - case HybridTag: result = runesmprint("%C", primhybridnames[d.func.code]); 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 LParTag: result = runesmprint("(%S", ppdatums(d.stmt.toks, d.stmt.ntoks)); break; + case DyadicOpTag: result = ppoperator(d->operator); break; + case LParTag: result = runesmprint("(%S", ppdatums(d->stmt.toks, d->stmt.ntoks)); break; case RParTag: result = runestrdup(L")"); break; case ArrowTag: result = runestrdup(L"←"); break; - case AssignmentTag: result = runesmprint("(%S)←", ppdatums(d.stmt.toks, d.stmt.ntoks)); break; - case NameTag: result = runestrdup(d.name); break; - default: result = runesmprint("", d.tag); + case AssignmentTag: result = runesmprint("(%S)←", ppdatums(d->stmt.toks, d->stmt.ntoks)); break; + case NameTag: result = runestrdup(d->name); break; + default: result = runesmprint("", d->tag); } return result; } Rune * -ppdatums(Datum *ds, int n) +ppdatums(Datum **ds, int n) { int i; Rune *res = runesmprint(""); @@ -54,7 +54,7 @@ pparray(Array *a) for(int i = 0; i < a->rank-1; i++) rowcount *= a->shape[i]; } - Rune **rowstrs = mallocz(sizeof(Rune *) * rowcount, 1); + Rune **rowstrs = emallocz(sizeof(Rune *) * rowcount, 1); int boxing = !simplearray(a); char *align = a->type == AtypeArray ? "-" : ""; @@ -90,8 +90,8 @@ pparray(Array *a) } int lastdim = a->rank ? a->shape[a->rank-1] : 1; - int *widths = mallocz(sizeof(int) * lastdim, 1); - int *heights = mallocz(sizeof(int) * rowcount, 1); + int *widths = emallocz(sizeof(int) * lastdim, 1); + int *heights = emallocz(sizeof(int) * rowcount, 1); for(int i = 0; i < a->size; i++){ int w,h; strdims(elemstrs[i], &w, &h); @@ -179,8 +179,8 @@ pparray(Array *a) Rune * ppoperator(Operator op) { - Rune *left = op.left ? ppdatum(*op.left) : runestrdup(L""); - Rune *right = op.right ? ppdatum(*op.right) : runestrdup(L""); + Rune *left = op.left ? ppdatum(op.left) : runestrdup(L""); + Rune *right = op.right ? ppdatum(op.right) : runestrdup(L""); Rune *res; if(op.type == OperatortypeDop) res = runesmprint("(%S{%S}%S)", left, op.dop, right); -- cgit v1.2.3