summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJason Beetham <beefers331@gmail.com>2021-10-17 08:24:43 -0600
committerGitHub <noreply@github.com>2021-10-17 16:24:43 +0200
commitf0af4a36b932af3932b611c1f728ebfbfe3a2749 (patch)
tree7b8d374f704b5525a27ff4cb8d071f8edd248d11
parentf77dea01fd980734a3ed4acb812575827540aff9 (diff)
downloadNim-f0af4a36b932af3932b611c1f728ebfbfe3a2749.tar.gz
Added setGlobalValue to VM api (#19007)
-rw-r--r--compiler/nimeval.nim4
-rw-r--r--compiler/vm.nim5
2 files changed, 9 insertions, 0 deletions
diff --git a/compiler/nimeval.nim b/compiler/nimeval.nim
index 577c7b586..82e2f0812 100644
--- a/compiler/nimeval.nim
+++ b/compiler/nimeval.nim
@@ -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
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 9fa25efbe..1b443aff1 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -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) =