From 617cc1dc6d34f5cdd64758419322fc1165d74868 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 20 Nov 2021 11:46:14 +1100 Subject: [PATCH] oceani: pass a file to print_value() and related functions. print_type receives a file, and a type can contain values, so print_value() should take a file too. Ideally print_exec() would as well, as the value of a function is an exec. Maybe another day. Signed-off-by: NeilBrown --- csrc/oceani.mdc | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/csrc/oceani.mdc b/csrc/oceani.mdc index f41e8fd..e3c8291 100644 --- a/csrc/oceani.mdc +++ b/csrc/oceani.mdc @@ -446,7 +446,7 @@ Named type are stored in a simple linked list. Objects of each type are int size, align; void (*init)(struct type *type, struct value *val); void (*prepare_type)(struct parse_context *c, struct type *type, int parse_time); - void (*print)(struct type *type, struct value *val); + void (*print)(struct type *type, struct value *val, FILE *f); void (*print_type)(struct type *type, FILE *f); int (*cmp_order)(struct type *t1, struct type *t2, struct value *v1, struct value *v2); @@ -543,12 +543,12 @@ Named type are stored in a simple linked list. Objects of each type are return -1; // NOTEST } - static void print_value(struct type *type, struct value *v) + static void print_value(struct type *type, struct value *v, FILE *f) { if (type && type->print) - type->print(type, v); + type->print(type, v, f); else - printf("*Unknown*"); // NOTEST + fprintf(f, "*Unknown*"); // NOTEST } ###### forward decls @@ -561,7 +561,7 @@ Named type are stored in a simple linked list. Objects of each type are struct value *vold, struct value *vnew); static int value_cmp(struct type *tl, struct type *tr, struct value *left, struct value *right); - static void print_value(struct type *type, struct value *v); + static void print_value(struct type *type, struct value *v, FILE *f); ###### free context types @@ -732,23 +732,23 @@ A separate function encoding these cases will simplify some code later. return cmp; } - static void _print_value(struct type *type, struct value *v) + static void _print_value(struct type *type, struct value *v, FILE *f) { switch (type->vtype) { case Vnone: // NOTEST - printf("*no-value*"); break; // NOTEST + fprintf(f, "*no-value*"); break; // NOTEST case Vlabel: // NOTEST - printf("*label-%p*", v->label); break; // NOTEST + fprintf(f, "*label-%p*", v->label); break; // NOTEST case Vstr: - printf("%.*s", v->str.len, v->str.txt); break; + fprintf(f, "%.*s", v->str.len, v->str.txt); break; case Vbool: - printf("%s", v->bool ? "True":"False"); break; + fprintf(f, "%s", v->bool ? "True":"False"); break; case Vnum: { mpf_t fl; mpf_init2(fl, 20); mpf_set_q(fl, v->num); - gmp_printf("%Fg", fl); + gmp_fprintf(f, "%Fg", fl); mpf_clear(fl); break; } @@ -2389,11 +2389,11 @@ function will be needed. fprintf(f, " = "); if (fl->type == Tstr) fprintf(f, "\""); // UNTESTED - print_value(fl->type, fl->init); + print_value(fl->type, fl->init, f); if (fl->type == Tstr) fprintf(f, "\""); // UNTESTED } - printf("\n"); + fprintf(f, "\n"); } } @@ -2521,7 +2521,7 @@ further detailed when Expression Lists are introduced. args, NULL, 0, NULL); } - static void function_print(struct type *type, struct value *val) + static void function_print(struct type *type, struct value *val, FILE *f) { print_exec(val->function, 1, 0); } @@ -2708,7 +2708,7 @@ an executable. struct val *v = cast(val, e); if (v->vtype == Tstr) printf("\""); - print_value(v->vtype, &v->val); + print_value(v->vtype, &v->val, stdout); if (v->vtype == Tstr) printf("\""); break; @@ -3957,7 +3957,7 @@ printed. b2 = cast(binode, b->right); for (; b2; b2 = cast(binode, b2->right)) { left = interp_exec(c, b2->left, <ype); - print_value(ltype, &left); + print_value(ltype, &left, stdout); free_value(ltype, &left); if (b2->right) putchar(' '); @@ -4803,7 +4803,7 @@ searching through for the Nth constant for decreasing N. printf(" = "); if (v->type == Tstr) printf("\""); - print_value(v->type, val); + print_value(v->type, val, stdout); if (v->type == Tstr) printf("\""); printf("\n"); @@ -4898,7 +4898,7 @@ is a bit more interesting at this level. if (brackets) print_exec(val->function, 0, brackets); else - print_value(v->type, val); + print_value(v->type, val, stdout); printf("/* frame size %d */\n", v->type->function.local_size); target -= 1; } -- 2.43.0