void print(Value x) { if (is_nil(x)) prints("nil"); else if (is_eof(x)) printf("#eof"); else if (is_fixnum(x)) printf("%d", as_fixnum(x)); else if (is_bool(x)) printf("%s", as_bool(x) ? "true" : "false"); else if (is_char(x)) printf("'%c'", as_char(x)); else if (is_pair(x)) print_list(x); else if (is_symbol(x)) prints(as_symbol(x)->value); else if (is_string(x)) print_string(as_string(x)); else if (is_procedure(x)) printf("#<procedure %s>", as_procedure(x)->name->value); else if (is_module(x)) printf("#<module>"); else if (is_type(x)) printf("#<type %s>", as_type(x)->name->value); else if (is_ptr(x)) printf("#<object %p>", as_ptr(x)); else if (is_undefined(x)) printf("#undefined"); else printf("#ufo"); }
void print(FILE *stream, Value v) { switch (get_tag(v)) { case TAG_FIXNUM: fprintf(stream, "%d", as_fixnum(v)); break; case TAG_REF: switch (get_type(v)) { case PRIMITIVE: fprintf(stream, "#<procedure %s>", ((Primitive *) as_ref(v))->name); break; case STRING: print_string(stream, v.ptr); break; case CONS: print_list(stream, v); break; case SYMBOL: print_symbol(stream, v.ptr); break; case FIXNUM: fprintf(stream, "~boxed fixnum?!~"); break; case CLOSURE: fprintf(stream, "~closure~"); break; case NIL: fprintf(stream, "()"); break; case VECTOR: fprintf(stream, "~vector~"); break; case VBLOCK: fprintf(stream, "~vblock~"); break; case HTABLE: fprintf(stream, "~htable~"); break; case HBLOCK: fprintf(stream, "~hblock~"); break; case STATIC_ENV: fprintf(stream, "~static-env~"); break; case FRAME: fprintf(stream, "~frame~"); break; case THUNK: fprintf(stream, "~thunk~"); break; case RAW: fprintf(stream, "~raw~"); break; } break; case TAG_NIL: fprintf(stream, "()"); break; } }