add exit() to repl
This commit is contained in:
parent
7e2c515de6
commit
04391ebbaa
14
kuroko.c
14
kuroko.c
@ -23,6 +23,12 @@
|
|||||||
#include "vm.h"
|
#include "vm.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
static int exitRepl = 0;
|
||||||
|
static KrkValue exitFunc(int argc, KrkValue argv[]) {
|
||||||
|
exitRepl = 1;
|
||||||
|
return NONE_VAL();
|
||||||
|
}
|
||||||
|
|
||||||
static int pasteEnabled = 0;
|
static int pasteEnabled = 0;
|
||||||
static KrkValue paste(int argc, KrkValue argv[]) {
|
static KrkValue paste(int argc, KrkValue argv[]) {
|
||||||
pasteEnabled = !pasteEnabled;
|
pasteEnabled = !pasteEnabled;
|
||||||
@ -59,9 +65,7 @@ int main(int argc, char * argv[]) {
|
|||||||
KrkValue result = INTEGER_VAL(0);
|
KrkValue result = INTEGER_VAL(0);
|
||||||
|
|
||||||
if (optind == argc) {
|
if (optind == argc) {
|
||||||
/* Run the repl */
|
krk_defineNative(&vm.globals, "exit", exitFunc);
|
||||||
int exit = 0;
|
|
||||||
|
|
||||||
krk_defineNative(&vm.globals, "paste", paste);
|
krk_defineNative(&vm.globals, "paste", paste);
|
||||||
|
|
||||||
/* Set ^D to send EOF */
|
/* Set ^D to send EOF */
|
||||||
@ -71,7 +75,7 @@ int main(int argc, char * argv[]) {
|
|||||||
/* TODO: Add tab completion for globals, known fields/methods... */
|
/* TODO: Add tab completion for globals, known fields/methods... */
|
||||||
//rline_exp_set_tab_complete_func(tab_complete_func);
|
//rline_exp_set_tab_complete_func(tab_complete_func);
|
||||||
|
|
||||||
while (!exit) {
|
while (!exitRepl) {
|
||||||
size_t lineCapacity = 8;
|
size_t lineCapacity = 8;
|
||||||
size_t lineCount = 0;
|
size_t lineCount = 0;
|
||||||
char ** lines = ALLOCATE(char *, lineCapacity);
|
char ** lines = ALLOCATE(char *, lineCapacity);
|
||||||
@ -105,7 +109,7 @@ int main(int argc, char * argv[]) {
|
|||||||
rline_scroll = 0;
|
rline_scroll = 0;
|
||||||
if (rline(buf, 4096) == 0) {
|
if (rline(buf, 4096) == 0) {
|
||||||
valid = 0;
|
valid = 0;
|
||||||
exit = 1;
|
exitRepl = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (buf[strlen(buf)-1] != '\n') {
|
if (buf[strlen(buf)-1] != '\n') {
|
||||||
|
Loading…
Reference in New Issue
Block a user