Skip to content

Commit

Permalink
source_string: omit ending nil/undef in source dumps
Browse files Browse the repository at this point in the history
message (a nil nil) => message (a )
  • Loading branch information
Reini Urban committed Apr 17, 2013
1 parent 12898db commit 0663ca6
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions core/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,28 @@ PN potion_source_name(Potion *P, PN cl, PN self) {
}

PN potion_source_string(Potion *P, PN cl, PN self) {
int i, n;
int i, n, cut = 0;
vPN(Source) t = (struct PNSource *)self;
PN out = potion_byte_str(P, potion_ast_names[t->part]);
n = potion_ast_sizes[t->part];
for (i = 0; i < n; i++) {
pn_printf(P, out, " ");
if (i == 0 && n > 1) pn_printf(P, out, "(");
else if (i > 0) {
if (t->a[i] == PN_NIL) { // omit subsequent nil
if (!cut) cut = PN_STR_LEN(out);
}
else cut = 0;
}
potion_bytes_obj_string(P, out, t->a[i]);
if (i == n - 1 && n > 1) pn_printf(P, out, ")");
if (i == n - 1 && n > 1) {
if (cut > 0) {
vPN(Bytes) b = (struct PNBytes *)potion_fwd(out);
b->len = cut;
b->chars[cut] = '\0';
}
pn_printf(P, out, ")");
}
}
return PN_STR_B(out);
}
Expand Down

0 comments on commit 0663ca6

Please sign in to comment.