diff --git a/README.md b/README.md index 48ebe40..b561fb2 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,14 @@ git clone https://github.com/japl-lang/japl ### Running the build script +NOTE: as of now, you will need version 0.1.0 of the nimble package `jale` installed: + +```bash +git clone https://github.com/japl-lang/jale --branch 0.1.0 +cd jale +nimble install +``` + As a next step, you need to run JABT (YES, Just Another Build Tool). This will generate the required configuration files, compile the JAPL runtime and run tests (unless `--skip-tests` is used). There are some settings that can be tweaked with command-line options (or environment variables), for more information, run `python3 build.py --help`. To compile the JAPL runtime, you'll first need to move into the project's directory you cloned before, so run `cd japl`, then `python3 build.py ./src` and wait for it to complete. You should now find an executable named `japl` (or `japl.exe` on windows) inside the `src` folder. diff --git a/src/japl.nim b/src/japl.nim index 396984c..0f6c846 100644 --- a/src/japl.nim +++ b/src/japl.nim @@ -25,6 +25,18 @@ import types/japlNil import types/typeutils import types/methods +import jale/editor +import jale/templates +import jale/plugin/defaults +import jale/plugin/history +import jale/plugin/editor_history + +proc getLineEditor: LineEditor = + result = newLineEditor() + result.prompt = "=> " + result.populateDefaults() # setup default keybindings + let hist = result.plugHistory() # create history object + result.bindHistory(hist) # set default history keybindings proc repl(bytecodeVM: VM) = var bytecodeVM = bytecodeVM @@ -34,18 +46,12 @@ proc repl(bytecodeVM: VM) = let nimDetails = &"[Nim {NimVersion} on {hostOs} ({hostCPU})]" echo nimDetails var source = "" - while true: - try: - stdout.write("=> ") - source = stdin.readLine() - except IOError: - echo "" - bytecodeVM.freeVM() - break - except KeyboardInterrupt: - echo "" - bytecodeVM.freeVM() - break + let lineEditor = getLineEditor() + var keep = true + lineEditor.bindEvent(jeQuit): + keep = false + while keep: + source = lineEditor.read() if source == "//clear" or source == "// clear": echo "\x1Bc" & JAPL_VERSION_STRING echo nimDetails @@ -60,6 +66,7 @@ proc repl(bytecodeVM: VM) = if not bytecodeVM.lastPop.isNil(): echo stringify(bytecodeVM.lastPop) bytecodeVM.lastPop = cast[ptr Nil](bytecodeVM.cached[2]) + bytecodeVM.freeVM() proc main(file: var string = "", fromString: bool = false, interactive: bool = false) =