summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2020-03-26 16:18:45 +0100
committerGitHub <noreply@github.com>2020-03-26 15:18:45 +0000
commit2925a47ae6aaa8e93117a29b018582540bf55856 (patch)
tree8c6322832e996d1e27d79840a69ed2e4c7d388e3
parent6162da812af822f739dd00bb1b6c12658a89c669 (diff)
downloadNim-2925a47ae6aaa8e93117a29b018582540bf55856.tar.gz
Fix vm.nim for --gc:arc (#13741)
* koch boot --gc:arc now passes the nim stage

... but generates invalid C code

* Move it closer to where its used

* Try something else

* Poor mans var

* Use UncheckedArray instead
-rw-r--r--compiler/vm.nim16
-rw-r--r--compiler/vmdef.nim14
-rw-r--r--compiler/vmhooks.nim41
3 files changed, 30 insertions, 41 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 8e05c5618..a2c6e686d 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -28,18 +28,6 @@ when hasFFI:
   import evalffi
 
 type
-  TRegisterKind = enum
-    rkNone, rkNode, rkInt, rkFloat, rkRegisterAddr, rkNodeAddr
-  TFullReg = object   # with a custom mark proc, we could use the same
-                      # data representation as LuaJit (tagged NaNs).
-    case kind: TRegisterKind
-    of rkNone: nil
-    of rkInt: intVal: BiggestInt
-    of rkFloat: floatVal: BiggestFloat
-    of rkNode: node: PNode
-    of rkRegisterAddr: regAddr: ptr TFullReg
-    of rkNodeAddr: nodeAddr: ptr PNode
-
   PStackFrame* = ref TStackFrame
   TStackFrame* = object
     prc: PSym                 # current prc; proc that is evaluated
@@ -1206,7 +1194,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
       if prc.offset < -1:
         # it's a callback:
         c.callbacks[-prc.offset-2].value(
-          VmArgs(ra: ra, rb: rb, rc: rc, slots: cast[pointer](regs),
+          VmArgs(ra: ra, rb: rb, rc: rc, slots: cast[ptr UncheckedArray[TFullReg]](addr regs[0]),
                  currentException: c.currentExceptionA,
                  currentLineInfo: c.debug[pc]))
       elif importcCond(prc):
@@ -1525,7 +1513,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
         rc = instr.regC
         idx = int(regs[rb+rc-1].intVal)
         callback = c.callbacks[idx].value
-        args = VmArgs(ra: ra, rb: rb, rc: rc, slots: cast[pointer](regs),
+        args = VmArgs(ra: ra, rb: rb, rc: rc, slots: cast[ptr UncheckedArray[TFullReg]](addr regs[0]),
                 currentException: c.currentExceptionA,
                 currentLineInfo: c.debug[pc])
       callback(args)
diff --git a/compiler/vmdef.nim b/compiler/vmdef.nim
index 176558eac..7b51c626d 100644
--- a/compiler/vmdef.nim
+++ b/compiler/vmdef.nim
@@ -212,6 +212,18 @@ type
     slotTempComplex,  # some complex temporary (s.node field is used)
     slotTempPerm      # slot is temporary but permanent (hack)
 
+  TRegisterKind* = enum
+    rkNone, rkNode, rkInt, rkFloat, rkRegisterAddr, rkNodeAddr
+  TFullReg* = object  # with a custom mark proc, we could use the same
+                      # data representation as LuaJit (tagged NaNs).
+    case kind*: TRegisterKind
+    of rkNone: nil
+    of rkInt: intVal*: BiggestInt
+    of rkFloat: floatVal*: BiggestFloat
+    of rkNode: node*: PNode
+    of rkRegisterAddr: regAddr*: ptr TFullReg
+    of rkNodeAddr: nodeAddr*: ptr PNode
+
   PProc* = ref object
     blocks*: seq[TBlock]    # blocks; temp data structure
     sym*: PSym
@@ -220,7 +232,7 @@ type
 
   VmArgs* = object
     ra*, rb*, rc*: Natural
-    slots*: pointer
+    slots*: ptr UncheckedArray[TFullReg]
     currentException*: PNode
     currentLineInfo*: TLineInfo
   VmCallback* = proc (args: VmArgs) {.closure.}
diff --git a/compiler/vmhooks.nim b/compiler/vmhooks.nim
index 412c93a77..d211d8343 100644
--- a/compiler/vmhooks.nim
+++ b/compiler/vmhooks.nim
@@ -10,10 +10,8 @@
 import pathutils
 
 template setX(k, field) {.dirty.} =
-  var s: seq[TFullReg]
-  move(s, cast[seq[TFullReg]](a.slots))
-  s[a.ra].ensureKind(k)
-  s[a.ra].field = v
+  a.slots[a.ra].ensureKind(k)
+  a.slots[a.ra].field = v
 
 proc setResult*(a: VmArgs; v: BiggestInt) = setX(rkInt, intVal)
 proc setResult*(a: VmArgs; v: BiggestFloat) = setX(rkFloat, floatVal)
@@ -22,45 +20,36 @@ proc setResult*(a: VmArgs; v: bool) =
   setX(rkInt, intVal)
 
 proc setResult*(a: VmArgs; v: string) =
-  var s: seq[TFullReg]
-  move(s, cast[seq[TFullReg]](a.slots))
-  s[a.ra].ensureKind(rkNode)
-  s[a.ra].node = newNode(nkStrLit)
-  s[a.ra].node.strVal = v
+  a.slots[a.ra].ensureKind(rkNode)
+  a.slots[a.ra].node = newNode(nkStrLit)
+  a.slots[a.ra].node.strVal = v
 
 proc setResult*(a: VmArgs; n: PNode) =
-  var s: seq[TFullReg]
-  move(s, cast[seq[TFullReg]](a.slots))
-  s[a.ra].ensureKind(rkNode)
-  s[a.ra].node = n
+  a.slots[a.ra].ensureKind(rkNode)
+  a.slots[a.ra].node = n
 
 proc setResult*(a: VmArgs; v: AbsoluteDir) = setResult(a, v.string)
 
 proc setResult*(a: VmArgs; v: seq[string]) =
-  var s: seq[TFullReg]
-  move(s, cast[seq[TFullReg]](a.slots))
-  s[a.ra].ensureKind(rkNode)
+  a.slots[a.ra].ensureKind(rkNode)
   var n = newNode(nkBracket)
   for x in v: n.add newStrNode(nkStrLit, x)
-  s[a.ra].node = n
+  a.slots[a.ra].node = n
 
 template getX(k, field) {.dirty.} =
   doAssert i < a.rc-1
-  let s = cast[seq[TFullReg]](a.slots)
-  doAssert s[i+a.rb+1].kind == k
-  result = s[i+a.rb+1].field
+  doAssert a.slots[i+a.rb+1].kind == k
+  result = a.slots[i+a.rb+1].field
 
 proc getInt*(a: VmArgs; i: Natural): BiggestInt = getX(rkInt, intVal)
 proc getBool*(a: VmArgs; i: Natural): bool = getInt(a, i) != 0
 proc getFloat*(a: VmArgs; i: Natural): BiggestFloat = getX(rkFloat, floatVal)
 proc getString*(a: VmArgs; i: Natural): string =
   doAssert i < a.rc-1
-  let s = cast[seq[TFullReg]](a.slots)
-  doAssert s[i+a.rb+1].kind == rkNode
-  result = s[i+a.rb+1].node.strVal
+  doAssert a.slots[i+a.rb+1].kind == rkNode
+  result = a.slots[i+a.rb+1].node.strVal
 
 proc getNode*(a: VmArgs; i: Natural): PNode =
   doAssert i < a.rc-1
-  let s = cast[seq[TFullReg]](a.slots)
-  doAssert s[i+a.rb+1].kind == rkNode
-  result = s[i+a.rb+1].node
+  doAssert a.slots[i+a.rb+1].kind == rkNode
+  result = a.slots[i+a.rb+1].node