diff options
author | Peter Mikkelsen <peter@pmikkelsen.com> | 2022-02-09 01:16:03 +0000 |
---|---|---|
committer | Peter Mikkelsen <peter@pmikkelsen.com> | 2022-02-09 01:16:03 +0000 |
commit | 6ed5b9f6d3fdeeed8ecd43b18bae642ec1ec24b1 (patch) | |
tree | cee3f787af7fb7e8b892fb661f63dc9248cd5f61 /print.c | |
parent | 8fd005f6185ac76ed0ac2495bd97ee817b472040 (diff) |
Add much better memory handling (We now track and free Datum * structs)
Diffstat (limited to 'print.c')
-rw-r--r-- | print.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -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("<not printable %d>", 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("<not printable %d>", 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); |