diff options
author | Zahary Karadjov <zahary@gmail.com> | 2014-02-18 02:46:49 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2014-02-18 02:46:49 +0200 |
commit | f13a836972abd29d5362ac4cc949aa8e0470f962 (patch) | |
tree | 073fb599f5c0d06302273d5620f6f3f2a858bd7c /compiler | |
parent | cda92048ba9408d356e0023543fcfb45ea357da8 (diff) | |
parent | 15953dfed952cf2a54f6466b335abcbf676de141 (diff) | |
download | Nim-f13a836972abd29d5362ac4cc949aa8e0470f962.tar.gz |
Merge branch 'devel' of gh:/Araq/Nimrod into devel
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 35 |
2 files changed, 27 insertions, 10 deletions
diff --git a/compiler/vm.nim b/compiler/vm.nim index 81e712047..0929e072b 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1025,7 +1025,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): PNode = regs[ra].sons[0].flags.incl nfIsRef of opcNCopyNimNode: decodeB(nkMetaNode) - setMeta(regs[ra], copyNode(regs[rb])) + setMeta(regs[ra], copyNode(regs[rb].skipMeta)) of opcNCopyNimTree: decodeB(nkMetaNode) setMeta(regs[ra], copyTree(regs[rb])) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index a6d044e24..206cca0d7 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -321,9 +321,18 @@ proc genAndOr(c: PCtx; n: PNode; opc: TOpcode; dest: var TDest) = c.gen(n.sons[2], dest) c.patch(L1) +proc nilLiteral(n: PNode): PNode = + if n.kind == nkNilLit and n.typ.sym != nil and + n.typ.sym.magic == mPNimrodNode: + let nilo = newNodeIT(nkNilLit, n.info, n.typ) + result = newNodeIT(nkMetaNode, n.info, n.typ) + result.add nilo + else: + result = n + proc rawGenLiteral(c: PCtx; n: PNode): int = result = c.constants.len - c.constants.add n + c.constants.add n.nilLiteral internalAssert result < 0x7fff proc sameConstant*(a, b: PNode): bool = @@ -907,17 +916,20 @@ proc requiresCopy(n: PNode): bool = proc unneededIndirection(n: PNode): bool = n.typ.skipTypes(abstractInst-{tyTypeDesc}).kind == tyRef -proc skipDeref(n: PNode): PNode = - if n.kind in {nkDerefExpr, nkHiddenDeref} and unneededIndirection(n.sons[0]): - result = n.sons[0] - else: - result = n - proc genAddrDeref(c: PCtx; n: PNode; dest: var TDest; opc: TOpcode; flags: TGenFlags) = # a nop for certain types let flags = if opc == opcAddr: flags+{gfAddrOf} else: flags - if unneededIndirection(n.sons[0]): + # consider: + # proc foo(f: var ref int) = + # f = new(int) + # proc blah() = + # var x: ref int + # foo x + # + # The type of 'f' is 'var ref int' and of 'x' is 'ref int'. Hence for + # nkAddr we must not use 'unneededIndirection', but for deref we use it. + if opc != opcAddr and unneededIndirection(n.sons[0]): gen(c, n.sons[0], dest, flags) else: let tmp = c.genx(n.sons[0], flags) @@ -1109,7 +1121,12 @@ proc getNullValue(typ: PType, info: TLineInfo): PNode = result = newNodeIT(nkFloatLit, info, t) of tyVar, tyPointer, tyPtr, tyCString, tySequence, tyString, tyExpr, tyStmt, tyTypeDesc, tyStatic, tyRef: - result = newNodeIT(nkNilLit, info, t) + if t.sym != nil and t.sym.magic == mPNimrodNode: + let nilo = newNodeIT(nkNilLit, info, t) + result = newNodeIT(nkMetaNode, info, t) + result.add nilo + else: + result = newNodeIT(nkNilLit, info, t) of tyProc: if t.callConv != ccClosure: result = newNodeIT(nkNilLit, info, t) |