From 1320299fc0097eff92369c33814abc0bd57c7e03 Mon Sep 17 00:00:00 2001 From: Joshua Weinstein Date: Mon, 11 Jun 2018 01:06:42 -0700 Subject: [PATCH] finished repl --- Makefile | 5 +++++ include/IOUtil.h | 13 ++++++++++++- src/flow/WindData.c | 4 ++-- src/main/Main.c | 9 +++++++-- src/util/IOUtil.c | 21 +++++++++++++++++++++ 5 files changed, 47 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fb9e6b1..2daba88 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,11 @@ LD_FLAGS := MEM_FLAGS := -DWindData_BUF_SIZE=$(WIND_MEM_BUF) -DWindData_LOAD_SIZE=$(WIND_MEM_LOAD) -DWindComp_BUF_SIZE=$(WIND_MEM_COMP) CC_FLAGS := -c -Wall -I$(INC_DIR) $(MEM_FLAGS) +# Cleans old and rebuilds all object files +build: + make clean + make all + clean: rm -rf bin rm -rf lib diff --git a/include/IOUtil.h b/include/IOUtil.h index 8d2789f..ce8b9b5 100644 --- a/include/IOUtil.h +++ b/include/IOUtil.h @@ -4,13 +4,24 @@ #include "WindData.h" #include "WindState.h" #include "WindComp.h" +#include "WindRun.h" + +#define IOUtil_REPL_PROMPT "wind> " + +#ifndef IOUtil_REPL_SIZE +#define IOUtil_REPL_SIZE 512 +#endif // Prints a byte-marked sequence of Wind Values from start to end. int IOUtil_print(const unsigned char* start, const unsigned char* end); - +// Prints debug info about the state and data of Wind. +// Allows visualization of the buffers, error, state, command void IOUtil_debug(void); +// Starts a read eval print loop. +void IOUtil_repl(void); + #endif diff --git a/src/flow/WindData.c b/src/flow/WindData.c index 3d78ad3..f64154d 100644 --- a/src/flow/WindData.c +++ b/src/flow/WindData.c @@ -104,7 +104,7 @@ void WindData_active_set(unsigned char* place) void WindData_active_write(void* data, size_t length) { - unsigned char* writer = WindData_ACTIVE_B ? WindData_B1 : WindData_B0_PTR; + unsigned char* writer = WindData_ACTIVE_B ? WindData_B1_PTR : WindData_B0_PTR; if(length > (WindData_ACTIVE_B ? WindData_B1_END : WindData_B0_END) - writer) { fprintf(stderr, "%s\n", "Memory Error: Ran out of load buffer memory, exiting."); @@ -191,7 +191,7 @@ void WindData_inactive_set(unsigned char* place) void WindData_inactive_write(void* data, size_t length) { - unsigned char* writer = !WindData_ACTIVE_B ? WindData_B1 : WindData_B0_PTR; + unsigned char* writer = !WindData_ACTIVE_B ? WindData_B1_PTR : WindData_B0_PTR; if(length > (!WindData_ACTIVE_B ? WindData_B1_END : WindData_B0_END) - writer) { fprintf(stderr, "%s\n", "Memory Error: Ran out of load buffer memory, exiting."); diff --git a/src/main/Main.c b/src/main/Main.c index 681e761..21182ac 100644 --- a/src/main/Main.c +++ b/src/main/Main.c @@ -7,9 +7,14 @@ int main(int argc, char const *argv[]) { - if(argc != 3) + if(argc == 1) { - fprintf(stderr, "Error, need exactly two command line arguments, got %d\n", argc - 1); + IOUtil_repl(); + exit(0); + } + if(argc > 3) + { + fprintf(stderr, "Error, need two or no command line arguments, got %d\n", argc - 1); exit(1); } else if(!strcmp(argv[1], "-c")) diff --git a/src/util/IOUtil.c b/src/util/IOUtil.c index 608209f..a1fb03d 100644 --- a/src/util/IOUtil.c +++ b/src/util/IOUtil.c @@ -93,3 +93,24 @@ void IOUtil_debug(void) printf("]\n"); puts("________________________"); } + +void IOUtil_repl(void) +{ + int running = 1; + char replBuf[IOUtil_REPL_SIZE]; + while(running) + { + printf(IOUtil_REPL_PROMPT); + if(fgets(replBuf, IOUtil_REPL_SIZE, stdin) != NULL) + { + if(replBuf[0] == 'e' && replBuf[1] == 'x' && replBuf[2] == 'i' && replBuf[3] == 't') + { + return; + } + else + { + WindRun_code(replBuf); + } + } + } +}