32 lines
966 B
Nim
32 lines
966 B
Nim
type
|
|
LineEditorChoice = enum
|
|
leBasic, leRdstdin
|
|
ReadlineInterruptedException* = object of CatchableError
|
|
|
|
# choose debug options here
|
|
const debugVM* = false
|
|
const debugScanner* = false
|
|
const debugCompiler* = false
|
|
const debugDumpChunk* = false
|
|
const assertionsVM* = false # sanity checks in the VM, such as the stack being empty at the end
|
|
const assertionsCompiler* = false # sanity checks in the compiler
|
|
const profileInstructions* = false # if true, the time spent on every opcode is measured
|
|
|
|
# choose a line editor for the repl
|
|
const lineEditor = leRdstdin
|
|
|
|
when lineEditor == leRdstdin:
|
|
import rdstdin
|
|
|
|
proc konLineEditor*: string =
|
|
proc ctrlc =
|
|
raise newException(ReadlineInterruptedException, "Ctrl+C/D pressed.")
|
|
when lineEditor == leBasic:
|
|
write stdout, "\r-> "
|
|
result = stdin.readLine()
|
|
when lineEditor == leRdstdin:
|
|
var line: string
|
|
let ok = readLineFromStdin("-> ", line)
|
|
if not ok:
|
|
ctrlc()
|
|
return line |