import "../../compiler" / [ast, vmdef, vm, nimeval, llstream]
    import std / [os]
    
    when isMainModule:
      const moduleName = "script.nim"
      let std = findNimStdLibCompileTime()
      let intr = createInterpreter(moduleName, [std, std / "pure", std / 
"core"])
      
      proc evalString(code: string) =
        let stream = llStreamOpen(code)
        intr.evalScript(stream)
        llStreamClose(stream)
      
      evalString("echo 10+1")
      evalString("proc add*(a,b:int):int = a+b")
      evalString("echo add(3,4)")
      
      destroyInterpreter(intr)
    
    
    
    Run

When the code run, it give following message: 
    
    
    11
    script.nim(1, 9) Error: type mismatch: got <int literal(3), int literal(4)>
    but expected one of:
    proc add(x: var string; y: char)
      first type mismatch at position: 1
      required type for x: var string
      but expression '3' is of type: int literal(3)
    proc add(x: var string; y: string)
      first type mismatch at position: 1
      required type for x: var string
      but expression '3' is of type: int literal(3)
    proc add[T](x: var seq[T]; y: T)
      first type mismatch at position: 1
      required type for x: var seq[T]
      but expression '3' is of type: int literal(3)
    proc add[T](x: var seq[T]; y: openArray[T])
      first type mismatch at position: 1
      required type for x: var seq[T]
      but expression '3' is of type: int literal(3)
    
    expression: add(3, 4)
    
    
    Run

When run to evalString("echo add(3,4)"), the interpreter doesn't found the proc 
add.

Reply via email to