Start writing the REPL in Wren.
It doesn't actually execute code yet, but it: - Supports left and right arrow keys for moving the cursor. - Ctrl-C, Ctrl-D, Ctrl-A, and Ctrl-E for navigating. - Syntax highlights the line (!). The next step is to do a rough parse so that we can tell if the line is an expression, statement, or needs more input. That will tell us whether we need to interpret it at the top level (statement) and not worry about a result, evaluate it as an expression and print the result, or read more lines.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "io.wren.inc"
|
||||
#include "os.wren.inc"
|
||||
#include "repl.wren.inc"
|
||||
#include "scheduler.wren.inc"
|
||||
#include "timer.wren.inc"
|
||||
|
||||
@@ -162,6 +163,8 @@ static ModuleRegistry modules[] =
|
||||
STATIC_METHOD("allArguments", processAllArguments)
|
||||
END_CLASS
|
||||
END_MODULE
|
||||
MODULE(repl)
|
||||
END_MODULE
|
||||
MODULE(scheduler)
|
||||
CLASS(Scheduler)
|
||||
STATIC_METHOD("captureMethods_()", schedulerCaptureMethods)
|
||||
|
||||
+3
-19
@@ -6,8 +6,6 @@
|
||||
#include "scheduler.h"
|
||||
#include "vm.h"
|
||||
|
||||
#define MAX_LINE_LENGTH 1024 // TODO: Something less arbitrary.
|
||||
|
||||
// The single VM instance that the CLI uses.
|
||||
static WrenVM* vm;
|
||||
|
||||
@@ -259,23 +257,9 @@ int runRepl()
|
||||
printf("\\\\/\"-\n");
|
||||
printf(" \\_/ wren v%s\n", WREN_VERSION_STRING);
|
||||
|
||||
char line[MAX_LINE_LENGTH];
|
||||
|
||||
for (;;)
|
||||
{
|
||||
printf("> ");
|
||||
|
||||
if (!fgets(line, MAX_LINE_LENGTH, stdin))
|
||||
{
|
||||
printf("\n");
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO: Handle failure.
|
||||
wrenInterpret(vm, line);
|
||||
|
||||
// TODO: Automatically print the result of expressions.
|
||||
}
|
||||
wrenInterpret(vm, "import \"repl\"\n");
|
||||
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
|
||||
freeVM();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user