summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/llstream.nim4
-rw-r--r--compiler/nimeval.nim24
2 files changed, 25 insertions, 3 deletions
diff --git a/compiler/llstream.nim b/compiler/llstream.nim
index 8f57cda82..69a6905af 100644
--- a/compiler/llstream.nim
+++ b/compiler/llstream.nim
@@ -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 =
diff --git a/compiler/nimeval.nim b/compiler/nimeval.nim
index 1d7157cdf..f1ac884f7 100644
--- a/compiler/nimeval.nim
+++ b/compiler/nimeval.nim
@@ -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))