From 17cace280ca927a97adc21314141947210fe17b5 Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 18 Jun 2015 15:05:44 +0200 Subject: [PATCH] fixes #2297, fixes #2946 --- compiler/lowerings.nim | 20 ++++++++++ compiler/vm.nim | 12 ------ compiler/vmdef.nim | 2 +- compiler/vmgen.nim | 7 +--- tests/vm/tconsttable2.nim | 81 +++++++++++++++++++++++++++++++++++++++ tests/vm/tswap.nim | 24 ++++++++++++ 6 files changed, 127 insertions(+), 19 deletions(-) create mode 100644 tests/vm/tconsttable2.nim create mode 100644 tests/vm/tswap.nim diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index b6b01d558..b4319b246 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -63,6 +63,26 @@ proc lowerTupleUnpacking*(n: PNode; owner: PSym): PNode = if n.sons[i].kind == nkSym: v.addVar(n.sons[i]) result.add newAsgnStmt(n.sons[i], newTupleAccess(tempAsNode, i)) +proc lowerSwap*(n: PNode; owner: PSym): PNode = + result = newNodeI(nkStmtList, n.info) + # note: cannot use 'skTemp' here cause we really need the copy for the VM :-( + var temp = newSym(skVar, getIdent(genPrefix), owner, n.info) + temp.typ = n.sons[1].typ + incl(temp.flags, sfFromGeneric) + + var v = newNodeI(nkVarSection, n.info) + let tempAsNode = newSymNode(temp) + + var vpart = newNodeI(nkIdentDefs, v.info, 3) + vpart.sons[0] = tempAsNode + vpart.sons[1] = ast.emptyNode + vpart.sons[2] = n[1] + addSon(v, vpart) + + result.add(v) + result.add newFastAsgnStmt(n[1], n[2]) + result.add newFastAsgnStmt(n[2], tempAsNode) + proc createObj*(owner: PSym, info: TLineInfo): PType = result = newType(tyObject, owner) rawAddSon(result, nil) diff --git a/compiler/vm.nim b/compiler/vm.nim index 9f0d0bfce..826356c68 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1051,18 +1051,6 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = # set to default value: for i in oldLen ..