summary refs log tree commit diff stats
path: root/compiler/vm.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-01-17 01:18:57 +0100
committerAraq <rumpf_a@web.de>2014-01-17 01:18:57 +0100
commitfc452787e7bba3301642c012fe8e2cdea243993b (patch)
tree07356b86db49e3d3f7afcc265c1089dfd61469b9 /compiler/vm.nim
parenta1713bc2f95ddfa6b042315196607f7d5a01d135 (diff)
downloadNim-fc452787e7bba3301642c012fe8e2cdea243993b.tar.gz
better html generator for the tester; fixes some VM bugs
Diffstat (limited to 'compiler/vm.nim')
-rw-r--r--compiler/vm.nim33
1 files changed, 22 insertions, 11 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim
index a670e5bd0..9ed18d29e 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -172,7 +172,9 @@ proc asgnComplex(x, y: PNode) =
   else:
     if x.kind notin {nkEmpty..nkNilLit}:
       let y = y.copyValue
-      for i in countup(0, sonsLen(y) - 1): addSon(x, y.sons[i])
+      for i in countup(0, sonsLen(y) - 1): 
+        if i < x.len: x.sons[i] = y.sons[i]
+        else: addSon(x, y.sons[i])
 
 template getstr(a: expr): expr =
   (if a.kind in {nkStrLit..nkTripleStrLit}: a.strVal else: $chr(int(a.intVal)))
@@ -319,8 +321,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
       decodeB(nkIntLit)
       regs[ra].intVal = regs[rb].intVal
     of opcAsgnStr:
-      decodeB(nkStrLit)
-      regs[ra].strVal = regs[rb].strVal
+      if regs[instr.regB].kind == nkNilLit:
+        decodeB(nkNilLit)
+      else:
+        decodeB(nkStrLit)
+        regs[ra].strVal = regs[rb].strVal
     of opcAsgnFloat:
       decodeB(nkFloatLit)
       regs[ra].floatVal = regs[rb].floatVal
@@ -336,6 +341,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
       # a = b[c]
       let rb = instr.regB
       let rc = instr.regC
+      if regs[rc].intVal > high(int):
+        stackTrace(c, tos, pc, errIndexOutOfBounds)
       let idx = regs[rc].intVal.int
       # XXX what if the array is not 0-based? -> codegen should insert a sub
       assert regs[rb].kind != nkMetaNode
@@ -373,7 +380,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
       let rb = instr.regB
       let rc = instr.regC
       # XXX this creates a wrong alias
-      #Message(c.debug[pc], warnUser, $regs[rb].len & " " & $rc)
+      #Message(c.debug[pc], warnUser, $regs[rb].safeLen & " " & $rc)
       asgnComplex(regs[ra], regs[rb].sons[rc])
     of opcWrObj:
       # a.b = c
@@ -427,8 +434,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
       regs[ra].intVal = regs[rb].skipMeta.len - imm
     of opcLenStr:
       decodeBImm(nkIntLit)
-      assert regs[rb].kind in {nkStrLit..nkTripleStrLit}
-      regs[ra].intVal = regs[rb].strVal.len - imm
+      if regs[rb].kind == nkNilLit:
+        stackTrace(c, tos, pc, errNilAccess)
+      else:
+        assert regs[rb].kind in {nkStrLit..nkTripleStrLit}
+        regs[ra].intVal = regs[rb].strVal.len - imm
     of opcIncl:
       decodeB(nkCurly)
       if not inSet(regs[ra], regs[rb]): addSon(regs[ra], copyTree(regs[rb]))
@@ -738,11 +748,11 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
       inc pc
       ensureKind(nkBracket)
       let instr2 = c.code[pc]
-      let rb = instr2.regA
+      let count = regs[instr2.regA].intVal.int
       regs[ra].typ = typ
-      newSeq(regs[ra].sons, rb)
-      for i in 0 .. <rb:
-        regs[ra].sons[i] = getNullValue(typ, regs[ra].info)
+      newSeq(regs[ra].sons, count)
+      for i in 0 .. <count:
+        regs[ra].sons[i] = getNullValue(typ.sons[0], regs[ra].info)
     of opcNewStr:
       decodeB(nkStrLit)
       regs[ra].strVal = newString(regs[rb].intVal.int)
@@ -1044,7 +1054,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode =
     inc pc
 
 proc fixType(result, n: PNode) {.inline.} =
-  # XXX do it deeply for complex values
+  # XXX do it deeply for complex values; there seems to be no simple
+  # solution except to check it deeply here.
   #if result.typ.isNil: result.typ = n.typ
 
 proc execute(c: PCtx, start: int): PNode =