From bdeb41e0aedadf71fe4132affaeca49466329057 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 24 Dec 2016 11:28:25 +0100 Subject: [PATCH] core: Move reader and posix functions from mes.c * mes.c (getchar, ungetchar, peekchar, peek_byte, read_byte, unread_byte, write_byte, read_input_file_env_, read_input_file_env): Remove. * posix.c (getchar, ungetchar, peekchar, peek_byte, read_byte, unread_byte, write_byte): Move from mes.c. * reader (read_input_file_env_, read_input_file_env): Move from mes.c. --- mes.c | 70 +------------------------------------------------------- posix.c | 52 +++++++++++++++++++++++++++++++++++++++++ reader.c | 17 ++++++++++++++ 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/mes.c b/mes.c index 3f11524f..7b12b64d 100644 --- a/mes.c +++ b/mes.c @@ -787,59 +787,6 @@ vector_to_list (SCM v) return x; } -FILE *g_stdin; -int -getchar () -{ - return getc (g_stdin); -} - -int -ungetchar (int c) -{ - return ungetc (c, g_stdin); -} - -int -peekchar () -{ - int c = getchar (); - ungetchar (c); - return c; -} - -SCM -peek_byte () -{ - return MAKE_NUMBER (peekchar ()); -} - -SCM -read_byte () -{ - return MAKE_NUMBER (getchar ()); -} - -SCM -unread_byte (SCM i) -{ - ungetchar (VALUE (i)); - return i; -} - -SCM -write_byte (SCM x) ///((arity . n)) -{ - SCM c = car (x); - SCM p = cdr (x); - int fd = 1; - if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p)); - FILE *f = fd == 1 ? stdout : stderr; - assert (TYPE (c) == NUMBER || TYPE (c) == CHAR); - fputc (VALUE (c), f); - return c; -} - void make_tmps (scm* cells) { @@ -1077,22 +1024,7 @@ lookup_macro (SCM x, SCM a) return cell_f; } -SCM -read_input_file_env_ (SCM e, SCM a) -{ - if (e == cell_nil) return e; - return cons (e, read_input_file_env_ (read_env (a), a)); -} - -SCM -read_input_file_env (SCM a) -{ - r0 = a; - if (assq_ref_cache (cell_symbol_read_input_file, r0) != cell_undefined) - return apply_env (cell_symbol_read_input_file, cell_nil, r0); - return read_input_file_env_ (read_env (r0), r0); -} - +FILE *g_stdin; SCM load_env (SCM a) ///((internal)) { diff --git a/posix.c b/posix.c index 0695a97e..15257c80 100644 --- a/posix.c +++ b/posix.c @@ -20,6 +20,58 @@ #include +int +getchar () +{ + return getc (g_stdin); +} + +int +ungetchar (int c) +{ + return ungetc (c, g_stdin); +} + +int +peekchar () +{ + int c = getchar (); + ungetchar (c); + return c; +} + +SCM +peek_byte () +{ + return MAKE_NUMBER (peekchar ()); +} + +SCM +read_byte () +{ + return MAKE_NUMBER (getchar ()); +} + +SCM +unread_byte (SCM i) +{ + ungetchar (VALUE (i)); + return i; +} + +SCM +write_byte (SCM x) ///((arity . n)) +{ + SCM c = car (x); + SCM p = cdr (x); + int fd = 1; + if (TYPE (p) == PAIR && TYPE (car (p)) == NUMBER) fd = VALUE (car (p)); + FILE *f = fd == 1 ? stdout : stderr; + assert (TYPE (c) == NUMBER || TYPE (c) == CHAR); + fputc (VALUE (c), f); + return c; +} + SCM stderr_ (SCM x) { diff --git a/reader.c b/reader.c index 55afd7d4..864d5b7a 100644 --- a/reader.c +++ b/reader.c @@ -18,6 +18,23 @@ * along with Mes. If not, see . */ + +SCM +read_input_file_env_ (SCM e, SCM a) +{ + if (e == cell_nil) return e; + return cons (e, read_input_file_env_ (read_env (a), a)); +} + +SCM +read_input_file_env (SCM a) +{ + r0 = a; + if (assq_ref_cache (cell_symbol_read_input_file, r0) != cell_undefined) + return apply_env (cell_symbol_read_input_file, cell_nil, r0); + return read_input_file_env_ (read_env (r0), r0); +} + int read_line_comment (int c) {