Skip to content

Commit

Permalink
finished repl
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 11, 2018
1 parent 685c751 commit 1320299
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion include/IOUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/flow/WindData.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand Down
9 changes: 7 additions & 2 deletions src/main/Main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
21 changes: 21 additions & 0 deletions src/util/IOUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}

0 comments on commit 1320299

Please sign in to comment.