Skip to content

Commit

Permalink
work on repl and continuous running
Browse files Browse the repository at this point in the history
  • Loading branch information
jweinst1 committed Jun 11, 2018
1 parent 1320299 commit 433b69a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
8 changes: 7 additions & 1 deletion include/WindRun.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ int WindRun_load(const char** code);
// When found, does a goto to TRANS_TO_LOAD to switch state.
int WindRun_command(const char** code);

// Top level function that takes a stream and runs textual source code on it.
// Runs the code as a complete portion of source code.
// Will execute any lasting commands and print any errors once
// the end of the string is reached.
void WindRun_code(const char* code);

// Runs the code as continuous incoming stream of code chunks
// Does not force lasting commands or print errors once a single code chunk is done.
void WindRun_continuous(const char* code);

#endif
30 changes: 27 additions & 3 deletions src/code/WindRun.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ int WindRun_load(const char** code)
}
break;
case '\0':
// source code ends
goto TRANS_TO_EXEC;
return 1;
default:
WindState_write_err("Expected argument or value, found '%c'", **code);
return 0;
Expand Down Expand Up @@ -316,7 +315,8 @@ int WindRun_command(const char** code)
break;

case '\0':
goto TRANS_TO_LOAD;
if(WindState_has_cmd()) goto TRANS_TO_LOAD;
else return 1;
default:
WindState_write_err("Expected command symbol, found '%c'", **code);
return 0;
Expand Down Expand Up @@ -358,3 +358,27 @@ void WindRun_code(const char* code)
return;
}
}

void WindRun_continuous(const char* code)
{
while(*code)
{
if(WindState_has_err())
{
WindState_print_err();
return;
}
switch(WindState_get_mode())
{
case WindMode_command:
WindRun_command(&code);
break;
case WindMode_load:
WindRun_load(&code);
break;
case WindMode_exec:
WindRun_exec(&code);
break;
}
}
}
2 changes: 1 addition & 1 deletion src/util/IOUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void IOUtil_repl(void)
}
else
{
WindRun_code(replBuf);
WindRun_continuous(replBuf);
}
}
}
Expand Down

0 comments on commit 433b69a

Please sign in to comment.