From 2d7839c26426c7a785996d384112631b8a8360e7 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 11 Aug 2017 17:25:14 +0000 Subject: [PATCH] WIP --- include/cyclone/runtime.h | 1 + runtime.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/cyclone/runtime.h b/include/cyclone/runtime.h index 4645409f..24144920 100644 --- a/include/cyclone/runtime.h +++ b/include/cyclone/runtime.h @@ -266,6 +266,7 @@ object Cyc_io_flush_output_port(void *data, object port); object Cyc_io_read_char(void *data, object cont, object port); object Cyc_io_peek_char(void *data, object cont, object port); object Cyc_io_read_line(void *data, object cont, object port); +void Cyc_io_read_token(void *data, object cont, object port); /**@}*/ diff --git a/runtime.c b/runtime.c index e2cadebd..daa48dc4 100644 --- a/runtime.c +++ b/runtime.c @@ -5706,7 +5706,22 @@ void _read_line_comment(port_type *p) void _read_multiline_comment(port_type *p) {} void _read_whitespace(port_type *p) {} -void Cyc_read(void *data, object cont, object port) +void _read_error(void *data, port_type *p, const char *msg) +{ +/* TODO: need equivalent of this: +(define (parse-error msg lnum cnum) + (error + (string-append + "Error (line " + (number->string lnum) + ", char " + (number->string cnum) + "): " + msg))) +*/ +} + +void Cyc_read_token(void *data, object cont, object port) { Cyc_check_port(data, port); port_type *p = (port_type *)port; @@ -5743,7 +5758,14 @@ void Cyc_read(void *data, object cont, object port) if (c == ';') { _read_line_comment(p); // TODO: but then what, want to go back + } else if (c == '\n') { + p->line_num++; + } else if (isspace(c)) { + _read_whitespace(p); + } else { + _read_error(data, p, "Unhandled input sequence"); } + // Want to use buffer instead of copying chars each time, but // need a solution when another read is required, since that would // overwrite buffer