This commit is contained in:
Andreas Rumpf 2017-02-03 17:35:58 +01:00
commit 26fb6cb073
3 changed files with 45 additions and 6 deletions

View file

@ -559,7 +559,8 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
if regs[rb].node.kind == nkRefTy: if regs[rb].node.kind == nkRefTy:
regs[ra].node = regs[rb].node.sons[0] regs[ra].node = regs[rb].node.sons[0]
else: else:
stackTrace(c, tos, pc, errGenerated, "limited VM support for pointers") ensureKind(rkNode)
regs[ra].node = regs[rb].node
else: else:
stackTrace(c, tos, pc, errNilAccess) stackTrace(c, tos, pc, errNilAccess)
of opcWrDeref: of opcWrDeref:

View file

@ -0,0 +1,38 @@
discard """
nimout: '''0
0
0
{hallo: 123, welt: 456}'''
"""
import tables
# bug #5327
type
MyType* = object
counter: int
proc foo(t: var MyType) =
echo t.counter
proc bar(t: MyType) =
echo t.counter
static:
var myValue: MyType
myValue.foo # works nicely
var refValue: ref MyType
refValue.new
refValue[].foo # fails to compile
refValue[].bar # works again nicely
static:
var otherTable = newTable[string, string]()
otherTable["hallo"] = "123"
otherTable["welt"] = "456"
echo otherTable

View file

@ -1,5 +1,5 @@
discard """ discard """
msg: '''2 nimout: '''2
3 3
4:2 4:2
Got Hi Got Hi
@ -13,7 +13,7 @@ import macros, tables, strtabs
var ZOOT{.compileTime.} = initTable[int, int](2) var ZOOT{.compileTime.} = initTable[int, int](2)
var iii {.compiletime.} = 1 var iii {.compiletime.} = 1
macro zoo:stmt= macro zoo: untyped =
ZOOT[iii] = iii*2 ZOOT[iii] = iii*2
inc iii inc iii
echo iii echo iii
@ -22,7 +22,7 @@ zoo
zoo zoo
macro tupleUnpack: stmt = macro tupleUnpack: untyped =
var (y,z) = (4, 2) var (y,z) = (4, 2)
echo y, ":", z echo y, ":", z
@ -32,14 +32,14 @@ tupleUnpack
var x {.compileTime.}: StringTableRef var x {.compileTime.}: StringTableRef
macro addStuff(stuff, body: expr): stmt {.immediate.} = macro addStuff(stuff, body: untyped): untyped =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
if x.isNil: if x.isNil:
x = newStringTable(modeStyleInsensitive) x = newStringTable(modeStyleInsensitive)
x[$stuff] = "" x[$stuff] = ""
macro dump(): stmt = macro dump(): untyped =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
for y in x.keys: echo "Got ", y for y in x.keys: echo "Got ", y