Skip to content

Commit

Permalink
Added setGlobalValue to VM api (#19007)
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 authored Oct 17, 2021
1 parent f77dea0 commit f0af4a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/nimeval.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ proc callRoutine*(i: Interpreter; routine: PSym; args: openArray[PNode]): PNode
proc getGlobalValue*(i: Interpreter; letOrVar: PSym): PNode =
result = vm.getGlobalValue(PCtx i.graph.vm, letOrVar)

proc setGlobalValue*(i: Interpreter; letOrVar: PSym, val: PNode) =
## Sets a global value to a given PNode, does not do any type checking.
vm.setGlobalValue(PCtx i.graph.vm, letOrVar, val)

proc implementRoutine*(i: Interpreter; pkg, module, name: string;
impl: proc (a: VmArgs) {.closure, gcsafe.}) =
assert i != nil
Expand Down
5 changes: 5 additions & 0 deletions compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,11 @@ proc getGlobalValue*(c: PCtx; s: PSym): PNode =
internalAssert c.config, s.kind in {skLet, skVar} and sfGlobal in s.flags
result = c.globals[s.position-1]

proc setGlobalValue*(c: PCtx; s: PSym, val: PNode) =
## Does not do type checking so ensure the `val` matches the `s.typ`
internalAssert c.config, s.kind in {skLet, skVar} and sfGlobal in s.flags
c.globals[s.position-1] = val

include vmops

proc setupGlobalCtx*(module: PSym; graph: ModuleGraph; idgen: IdGenerator) =
Expand Down

0 comments on commit f0af4a3

Please sign in to comment.