diff options
Diffstat (limited to 'compiler/nimeval.nim')
-rw-r--r-- | compiler/nimeval.nim | 24 |
1 files changed, 23 insertions, 1 deletions
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)) |