summary refs log tree commit diff stats
path: root/lib/pure/htmlgen.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/htmlgen.nim')
0 files changed, 0 insertions, 0 deletions
)' href='/ahoang/Nim/commit/tests/compilerapi/tcompilerapi.nim?h=devel&id=a58c982a494fbc8712067828f53b5c58ab6b3279'>a58c982a4 ^
06122ff71 ^
795044ed2 ^
06122ff71 ^




a58c982a4 ^
06122ff71 ^


a58c982a4 ^
2a4c09ff8 ^
688c54d8f ^
06122ff71 ^









a58c982a4 ^

688c54d8f ^




a58c982a4 ^

06122ff71 ^

a58c982a4 ^












1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


                                               
         

  
   
                   




                                                      
                                                             


                 
                                      
                                                                                  
                                                                       









                                                                           

                                 




                                                                            

                                                 

                          












                                                            
discard """
  output: '''top level statements are executed!
2.0
my secret
11
12
'''
  joinable: "false"
"""

## Example program that demonstrates how to use the
## compiler as an API to embed into your own projects.

import "../../compiler" / [ast, vmdef, vm, nimeval, llstream]
import std / [os]

proc main() =
  let std = findNimStdLibCompileTime()
  var intr = createInterpreter("myscript.nim",[std, parentDir(currentSourcePath)])
  intr.implementRoutine("*", "exposed", "addFloats", proc (a: VmArgs) =
    setResult(a, getFloat(a, 0) + getFloat(a, 1) + getFloat(a, 2))
  )

  intr.evalScript()

  let foreignProc = selectRoutine(intr, "hostProgramRunsThis")
  if foreignProc == nil:
    quit "script does not export a proc of the name: 'hostProgramRunsThis'"
  let res = intr.callRoutine(foreignProc, [newFloatNode(nkFloatLit, 0.9),
                                           newFloatNode(nkFloatLit, 0.1)])
  doAssert res.kind == nkFloatLit
  echo res.floatVal

  let foreignValue = selectUniqueSymbol(intr, "hostProgramWantsThis")
  if foreignValue == nil:
    quit "script does not export a global of the name: hostProgramWantsThis"
  let val = intr.getGlobalValue(foreignValue)
  doAssert val.kind in {nkStrLit..nkTripleStrLit}
  echo val.strVal
  destroyInterpreter(intr)

main()

block issue9180:
  proc evalString(code: string, moduleName = "script.nim") =
    let stream = llStreamOpen(code)
    let std = findNimStdLibCompileTime()
    var intr = createInterpreter(moduleName, [std])
    intr.evalScript(stream)
    destroyInterpreter(intr)
    llStreamClose(stream)

  evalString("echo 10+1")
  evalString("echo 10+2")