From 7421022b6e03e0025ef716237675c37701c4224a Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Sat, 25 Oct 2014 02:13:55 -0400 Subject: [PATCH] better makefile --- Makefile | 11 ++++++--- RTS.c | 20 ++++++++--------- RTS.h | 10 ++++----- parse.c | 11 +++++++++ reader.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tokenize.c | 1 + tokenize.h | 13 ----------- 7 files changed, 101 insertions(+), 31 deletions(-) create mode 100644 parse.c create mode 100644 reader.c diff --git a/Makefile b/Makefile index 7a5e23e..df303a2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ default: tokenize.c RTS.c tokenize.h RTS.h - $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./tokenize.c -lmaa -o tokenize_test; - $(CC) -DNDEBUG -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./RTS.c -o rts_test; + $(MAKE) lib; + $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./tokenize.c -lmaa -o tokenize_test; + $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./RTS.c -o RTS.o; + $(CC) -Wall -Wextra -pedantic -Wpointer-arith -Wmissing-prototypes -Werror -std=c99 -O3 ./reader.c -lmaa -o reader_test -L. -ltokenize -lrts -Wl,-rpath,/home/wes/schream; unsafe: tokenize.c RTS.c tokenize.h RTS.h $(CC) -DNDEBUG -std=c99 -O3 ./tokenize.c -lmaa; @@ -15,7 +17,10 @@ unsafelib: tokenize.c RTS.c tokenize.h RTS.h lib: tokenize.c RTS.c tokenize.h RTS.h $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./tokenize.c - $(CC) -shared -o tokenize.so tokenize.o -lmaa; + $(CC) -shared -o libtokenize.so tokenize.o -lmaa; + $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./RTS.c + $(CC) -shared -o librts.so RTS.o -lmaa; + $(CC) -DLIB -DNDEBUG -c -fpic -Wall -Wextra -pedantic -Wpointer-arith -Werror -std=c99 -O3 ./RTS.c; $(CC) -shared -o RTS.so RTS.o; diff --git a/RTS.c b/RTS.c index 356da7a..9ae5975 100644 --- a/RTS.c +++ b/RTS.c @@ -31,24 +31,24 @@ box_value(svalue_variants_t value, svalue_t val; switch (type) { - case INT: + case RTS_INT: val.value.integer = value.integer; val.type_tag = type; break; - case FLOAT: + case RTS_FLOAT: val.value.floating = value.floating; val.type_tag = type; break; - case DOUBLE: + case RTS_DOUBLE: val.value.doublev = value.doublev; val.type_tag = type; - case STRING: + case RTS_STRING: val.value.string = value.string; val.type_tag = type; case PAIR: val.value.pair = value.pair; val.type_tag = type; - case CLOSURE: + case RTS_CLOSURE: val.value.closure = value.closure; val.type_tag = type; } @@ -61,7 +61,7 @@ box_int(int x) { CHECK(val); svalue_variants_t value_val; value_val.integer = x; - *val = box_value(value_val, INT); + *val = box_value(value_val, RTS_INT); return val; } @@ -71,7 +71,7 @@ box_float(float x) { CHECK(val); svalue_variants_t value_val; value_val.floating = x; - *val = box_value(value_val, FLOAT); + *val = box_value(value_val, RTS_FLOAT); return val; } @@ -81,7 +81,7 @@ box_double(double x) { CHECK(val); svalue_variants_t value_val; value_val.doublev = x; - *val = box_value(value_val, DOUBLE); + *val = box_value(value_val, RTS_DOUBLE); return val; } @@ -96,7 +96,7 @@ box_string(char *chars, size_t n) { svalue_variants_t value_val; value_val.string = strval; - *val = box_value(value_val, STRING); + *val = box_value(value_val, RTS_STRING); return val; } @@ -106,7 +106,7 @@ box_closure(sc_closure_t *closure) { CHECK(val); svalue_variants_t value_val; value_val.closure = closure; - *val = box_value(value_val, CLOSURE); + *val = box_value(value_val, RTS_CLOSURE); return val; } diff --git a/RTS.h b/RTS.h index 6e1672f..27a6c7e 100644 --- a/RTS.h +++ b/RTS.h @@ -27,11 +27,11 @@ typedef /* The tag values for each different type */ typedef enum { - INT = 0, - FLOAT = 1, - DOUBLE = 2, - STRING = 3, - CLOSURE = 4, + RTS_INT = 0, + RTS_FLOAT = 1, + RTS_DOUBLE = 2, + RTS_STRING = 3, + RTS_CLOSURE = 4, PAIR = 5 } stype_t; diff --git a/parse.c b/parse.c new file mode 100644 index 0000000..4feac7d --- /dev/null +++ b/parse.c @@ -0,0 +1,11 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "error.h" +#include "maa.h" +#include "tokenize.h" diff --git a/reader.c b/reader.c new file mode 100644 index 0000000..6804a62 --- /dev/null +++ b/reader.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include "error.h" +#include "maa.h" +#include "tokenize.h" +#include "RTS.h" + +svalue_t* +read_scm(source_t); + +svalue_t* +read_scm(source_t source_code) { + size_t nbytes = read(STDIN_FILENO, source_code, 111000); + if (nbytes == 0) { + exit(EXIT_FAILURE); + } + + token_stream toks = tokenize(source_code, 0, nbytes); + token_t current_tok; + while (toks.length > 0) { + current_tok = peek_token(&toks); + switch (current_tok.token_type) { + case SYMBOL: + printf("symbol: %s\n", current_tok.token.symbol); + break; + case IDENTIFIER: + printf("identifer: %s\n", current_tok.token.identifier); + break; + case INTEGER: + printf("integer: %s\n", current_tok.token.integer); + break; + case FLOATING: + printf("floating: %s\n", current_tok.token.floating); + break; + case QUOTE: + printf("quote: '\n"); + break; + case WSPACE: + printf("whitespace\n"); + break; + case PAREN: + printf("paren: %s\n", current_tok.token.parenthesis); + break; + case EMPTY: + printf("this should not be empty\n"); + break; + case STRING: + printf("string: %s\n", current_tok.token.string); + break; + default: + printf("oops, there was an unknown token, check valgrind or gdb\n"); + } + pop_token(&toks); + } + return box_int(12); +} + +int main(void) { + return 0; +} diff --git a/tokenize.c b/tokenize.c index 6c58580..97db918 100644 --- a/tokenize.c +++ b/tokenize.c @@ -532,6 +532,7 @@ int main(void) { } pop_token(&toks); } + release_tokens(&toks); return 0; } #endif diff --git a/tokenize.h b/tokenize.h index c2633f3..d40b0af 100644 --- a/tokenize.h +++ b/tokenize.h @@ -53,19 +53,6 @@ tokenize(source_t, uint32_t, const uint32_t); bool release_tokens(token_stream*); - -static uint32_t -match_int(source_t, uint32_t, const uint32_t); - -static uint32_t -match_float(source_t, uint32_t, const uint32_t); - -static uint32_t -match_identifier(source_t, uint32_t, const uint32_t); - -static uint32_t -match_symbol(source_t, uint32_t, const uint32_t); - int free_token(const void *, const void *);