Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimeval: calling evalScript more than once has no effect #9184

Closed
timotheecour opened this issue Oct 4, 2018 · 1 comment
Closed

nimeval: calling evalScript more than once has no effect #9184

timotheecour opened this issue Oct 4, 2018 · 1 comment

Comments

@timotheecour
Copy link
Member

import compiler / [ast, vmdef, vm, nimeval, llstream]
from os import getEnv

when defined(case1):
  proc evalString(code: string, moduleName = "script.nim"):auto=
    let stream = llStreamOpen(code)
    defer: llStreamClose(stream)
    let path = getEnv("nimc_D") & "/lib/"
    # let path = findNimStdLibCompileTime()
    var intr = createInterpreter(moduleName, [path])
    defer: destroyInterpreter(intr)
    intr.evalScript(stream)

  evalString("echo 1")
  evalString("echo 2")

when defined(case2):
  proc evalString(code: string, moduleName = "script.nim"):auto=
    let stream = llStreamOpen(code)
    defer: llStreamClose(stream)
    let path = getEnv("nimc_D") & "/lib/"
    # let path = findNimStdLibCompileTime()
    var intr = createInterpreter(moduleName, [path])
    defer: destroyInterpreter(intr)
    for i in 0..<10:
      intr.evalScript(stream)

  evalString("echo 5")
nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r -d:case1 --path:/Users/timothee/git_clone//nim//Nim/ bugs/nimeval/t03_n_is_not_nil.nim
1
???(0, 0) Error: internal error: n is not nil

=> that's just #9180 (not the issue I'm concerned with in this bug)

nim c --nimcache:/tmp/nim//nimcache/ -o:/tmp/nim//app -r -d:case2 --path:/Users/timothee/git_clone//nim//Nim/ bugs/nimeval/t03_n_is_not_nil.nim
5

=> that's another bug (this issue): nim shows no error but instead only runs the script once

@timotheecour
Copy link
Member Author

actually what's happening here is that the stream is exhausted after the 1st intr.evalScript(stream) so subsequent calls have no effect as is expected (using an actual modules instead of a stream shows multiple executions); closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant