Added nimscript support to repl (#10834)

* added nimscript support to repl
* added bool parameter to runRepl en/disabling nimscript support
This commit is contained in:
sealmove 2019-03-13 11:21:24 +02:00 • committed by Andreas Rumpf
commit ab872be476

View file

@ -11,7 +11,8 @@
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, passaux modulegraphs, idents, os, pathutils, passaux,
scriptconfig
type type
Interpreter* = ref object ## Use Nim as an interpreter with this object Interpreter* = ref object ## Use Nim as an interpreter with this object
@ -126,7 +127,9 @@ proc destroyInterpreter*(i: Interpreter) =
## destructor. ## destructor.
discard "currently nothing to do." discard "currently nothing to do."
proc runRepl*(r: TLLRepl; searchPaths: openArray[string]) = proc runRepl*(r: TLLRepl;
searchPaths: openArray[string];
supportNimscript: bool) =
var conf = newConfigRef() var conf = newConfigRef()
var cache = newIdentCache() var cache = newIdentCache()
var graph = newModuleGraph(cache, conf) var graph = newModuleGraph(cache, conf)
@ -139,11 +142,13 @@ proc runRepl*(r: TLLRepl; searchPaths: openArray[string]) =
conf.errorMax = high(int) conf.errorMax = high(int)
initDefines(conf.symbols) initDefines(conf.symbols)
defineSymbol(conf.symbols, "nimscript") defineSymbol(conf.symbols, "nimscript")
if supportNimscript: defineSymbol(conf.symbols, "nimconfig")
when hasFFI: defineSymbol(graph.config.symbols, "nimffi") when hasFFI: defineSymbol(graph.config.symbols, "nimffi")
registerPass(graph, verbosePass) registerPass(graph, verbosePass)
registerPass(graph, semPass) registerPass(graph, semPass)
registerPass(graph, evalPass) registerPass(graph, evalPass)
var m = graph.makeStdinModule() var m = graph.makeStdinModule()
incl(m.flags, sfMainModule) incl(m.flags, sfMainModule)
if supportNimscript: graph.vm = setupVM(m, cache, "stdin", graph)
graph.compileSystemModule() graph.compileSystemModule()
processModule(graph, m, llStreamOpenStdIn(r)) processModule(graph, m, llStreamOpenStdIn(r))