Fixed order of output in repl and added a proc for opening a custom repl (#10802)

This commit is contained in:
sealmove
2019-03-10 21:02:47 +02:00
committed by Andreas Rumpf
parent b9f8528db6
commit 92cd07be8b
2 changed files with 25 additions and 3 deletions

View File

@@ -70,10 +70,10 @@ proc llStreamClose*(s: PLLStream) =
when not declared(readLineFromStdin):
# fallback implementation:
proc readLineFromStdin(prompt: string, line: var string): bool =
stdout.write(prompt)
stderr.write(prompt)
result = readLine(stdin, line)
if not result:
stdout.write("\n")
stderr.write("\n")
quit(0)
proc endsWith*(x: string, s: set[char]): bool =

View File

@@ -11,7 +11,7 @@
import
ast, astalgo, modules, passes, condsyms,
options, sem, semdata, llstream, vm, vmdef,
modulegraphs, idents, os, pathutils
modulegraphs, idents, os, pathutils, passaux
type
Interpreter* = ref object ## Use Nim as an interpreter with this object
@@ -125,3 +125,25 @@ proc createInterpreter*(scriptName: string;
proc destroyInterpreter*(i: Interpreter) =
## destructor.
discard "currently nothing to do."
proc runRepl*(r: TLLRepl; searchPaths: openArray[string]) =
var conf = newConfigRef()
var cache = newIdentCache()
var graph = newModuleGraph(cache, conf)
for p in searchPaths:
conf.searchPaths.add(AbsoluteDir p)
if conf.libpath.isEmpty: conf.libpath = AbsoluteDir p
conf.cmd = cmdInteractive
conf.errorMax = high(int)
initDefines(conf.symbols)
defineSymbol(conf.symbols, "nimscript")
when hasFFI: defineSymbol(graph.config.symbols, "nimffi")
registerPass(graph, verbosePass)
registerPass(graph, semPass)
registerPass(graph, evalPass)
var m = graph.makeStdinModule()
incl(m.flags, sfMainModule)
graph.compileSystemModule()
processModule(graph, m, llStreamOpenStdIn(r))