Fixed order of output in repl and added a proc for opening a custom repl (#10802)
This commit is contained in:
parent
b9f8528db6
commit
92cd07be8b
2 changed files with 25 additions and 3 deletions
|
|
@ -70,10 +70,10 @@ proc llStreamClose*(s: PLLStream) =
|
||||||
when not declared(readLineFromStdin):
|
when not declared(readLineFromStdin):
|
||||||
# fallback implementation:
|
# fallback implementation:
|
||||||
proc readLineFromStdin(prompt: string, line: var string): bool =
|
proc readLineFromStdin(prompt: string, line: var string): bool =
|
||||||
stdout.write(prompt)
|
stderr.write(prompt)
|
||||||
result = readLine(stdin, line)
|
result = readLine(stdin, line)
|
||||||
if not result:
|
if not result:
|
||||||
stdout.write("\n")
|
stderr.write("\n")
|
||||||
quit(0)
|
quit(0)
|
||||||
|
|
||||||
proc endsWith*(x: string, s: set[char]): bool =
|
proc endsWith*(x: string, s: set[char]): bool =
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
import
|
import
|
||||||
ast, astalgo, modules, passes, condsyms,
|
ast, astalgo, modules, passes, condsyms,
|
||||||
options, sem, semdata, llstream, vm, vmdef,
|
options, sem, semdata, llstream, vm, vmdef,
|
||||||
modulegraphs, idents, os, pathutils
|
modulegraphs, idents, os, pathutils, passaux
|
||||||
|
|
||||||
type
|
type
|
||||||
Interpreter* = ref object ## Use Nim as an interpreter with this object
|
Interpreter* = ref object ## Use Nim as an interpreter with this object
|
||||||
|
|
@ -125,3 +125,25 @@ proc createInterpreter*(scriptName: string;
|
||||||
proc destroyInterpreter*(i: Interpreter) =
|
proc destroyInterpreter*(i: Interpreter) =
|
||||||
## destructor.
|
## destructor.
|
||||||
discard "currently nothing to do."
|
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))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue