From 6ecce2941e3c05822dffb8ea80715225f9053855 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Tue, 9 Jun 2015 23:57:41 +0200 Subject: [PATCH 1/2] macros: exprStructuralEquivalent for EqNimrodNode Previously NimNode comparison in macros way returning false for anything else than nil literal. --- compiler/vm.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/vm.nim b/compiler/vm.nim index e49bed522b..9f0d0bfcec 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -682,11 +682,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = of opcLtu: decodeBC(rkInt) regs[ra].intVal = ord(regs[rb].intVal <% regs[rc].intVal) - of opcEqRef, opcEqNimrodNode: + of opcEqRef: decodeBC(rkInt) regs[ra].intVal = ord((regs[rb].node.kind == nkNilLit and regs[rc].node.kind == nkNilLit) or regs[rb].node == regs[rc].node) + of opcEqNimrodNode: + decodeBC(rkInt) + regs[ra].intVal = + ord(exprStructuralEquivalent(regs[rb].node, regs[rc].node)) of opcXor: decodeBC(rkInt) regs[ra].intVal = ord(regs[rb].intVal != regs[rc].intVal) From b49c75c82a5588ea6a3f14c9cb966ad87d99637e Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Wed, 10 Jun 2015 00:17:48 +0200 Subject: [PATCH 2/2] macros: Add test for node comparsion --- tests/macros/tnodecompare.nim | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/macros/tnodecompare.nim diff --git a/tests/macros/tnodecompare.nim b/tests/macros/tnodecompare.nim new file mode 100644 index 0000000000..ef25ae370c --- /dev/null +++ b/tests/macros/tnodecompare.nim @@ -0,0 +1,39 @@ +discard """ +output: '''1 +0 +1 +0 +1 +0 +1 +0''' +""" + +import macros + +macro test(a: typed, b: typed): expr = + newLit(a == b) + +echo test(1, 1) +echo test(1, 2) + +type + Obj = object of RootObj + Other = object of RootObj + +echo test(Obj, Obj) +echo test(Obj, Other) + +var a, b: int + +echo test(a, a) +echo test(a, b) + +macro test2: expr = + newLit(bindSym"Obj" == bindSym"Obj") + +macro test3: expr = + newLit(bindSym"Obj" == bindSym"Other") + +echo test2() +echo test3()