From 741835bc499cec46e5c5fd73fbd15af1a0f3a933 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 11 Jun 2015 22:13:46 -0400 Subject: [PATCH] Return the "void" object from I/O functions Primarily need this to prevent duplicate output in the REPL when calling functions such as (write). --- cyclone.h | 4 ---- runtime.c | 19 +++++++++++-------- runtime.h | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cyclone.h b/cyclone.h index 04d94a66..2d61eb68 100644 --- a/cyclone.h +++ b/cyclone.h @@ -87,10 +87,6 @@ typedef long tag_type; #define boolean_tag 15 #define cvar_tag 16 #define vector_tag 17 -/* TODO: need a type to return from things like - (if #f #t) and (write 1) so the REPL will not print - anything for them: - void_tag */ #define nil NULL #define eq(x,y) (x == y) diff --git a/runtime.c b/runtime.c index 63a1bcae..5d55f005 100644 --- a/runtime.c +++ b/runtime.c @@ -68,6 +68,9 @@ const object boolean_f = &f_boolean; static symbol_type Cyc_191procedure_symbol = {symbol_tag, "procedure", nil}; const object quote_Cyc_191procedure = &Cyc_191procedure_symbol; +static symbol_type Cyc_void_symbol = {symbol_tag, "", nil}; +const object quote_void = &Cyc_void_symbol; + /* Symbol Table */ /* Notes for the symbol table @@ -323,8 +326,8 @@ object Cyc_display(object x, FILE *port) {object tmp = nil; object has_cycle = boolean_f; int i = 0; - if (nullp(x)) {fprintf(port, "()"); return x;} - if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return x;} + if (nullp(x)) {fprintf(port, "()"); return quote_void;} + if (obj_is_char(x)) {fprintf(port, "%c", obj_obj2char(x)); return quote_void;} switch (type_of(x)) {case closure0_tag: case closure1_tag: @@ -403,7 +406,7 @@ object Cyc_display(object x, FILE *port) break; default: fprintf(port, "Cyc_display: bad tag x=%ld\n", ((closure)x)->tag); getchar(); exit(0);} - return x;} + return quote_void;} object dispatch_write_va(int argc, object clo, object cont, object x, ...) { object result; @@ -437,8 +440,8 @@ static object _Cyc_write(object x, FILE *port) {object tmp = nil; object has_cycle = boolean_f; int i = 0; - if (nullp(x)) {fprintf(port, "()"); return x;} - if (obj_is_char(x)) {fprintf(port, "#\\%c", obj_obj2char(x)); return x;} + if (nullp(x)) {fprintf(port, "()"); return quote_void;} + if (obj_is_char(x)) {fprintf(port, "#\\%c", obj_obj2char(x)); return quote_void;} switch (type_of(x)) {case string_tag: fprintf(port, "\"%s\"", ((string_type *) x)->str); @@ -476,7 +479,7 @@ static object _Cyc_write(object x, FILE *port) break; default: Cyc_display(x, port);} - return x;} + return quote_void;} object Cyc_write(object x, FILE *port) {object y = _Cyc_write(x, port); @@ -486,11 +489,11 @@ object Cyc_write(object x, FILE *port) object Cyc_write_char(object c, object port) { if (obj_is_char(c)) { - fprintf(((port_type *)port)->fp, "%c", obj_obj2char(c)); return c; + fprintf(((port_type *)port)->fp, "%c", obj_obj2char(c)); } else { Cyc_rt_raise2("Argument is not a character", c); } - return c; + return quote_void; } /* Some of these non-consing functions have been optimized from CPS. */ diff --git a/runtime.h b/runtime.h index 21a92634..cb5fd961 100644 --- a/runtime.h +++ b/runtime.h @@ -224,6 +224,7 @@ extern jmp_buf jmp_main; /* Where to jump to. */ extern const object boolean_t; extern const object boolean_f; extern const object quote_Cyc_191procedure; +extern const object quote_void; /* This section is auto-generated via --autogen */ extern const object primitive_Cyc_91global_91vars;