Merge pull request #2894 from nanoant/patch/macros-real-node-compare
Real node compare for macros
This commit is contained in:
commit
70e157d79e
2 changed files with 44 additions and 1 deletions
|
|
@ -682,11 +682,15 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
|
||||||
of opcLtu:
|
of opcLtu:
|
||||||
decodeBC(rkInt)
|
decodeBC(rkInt)
|
||||||
regs[ra].intVal = ord(regs[rb].intVal <% regs[rc].intVal)
|
regs[ra].intVal = ord(regs[rb].intVal <% regs[rc].intVal)
|
||||||
of opcEqRef, opcEqNimrodNode:
|
of opcEqRef:
|
||||||
decodeBC(rkInt)
|
decodeBC(rkInt)
|
||||||
regs[ra].intVal = ord((regs[rb].node.kind == nkNilLit and
|
regs[ra].intVal = ord((regs[rb].node.kind == nkNilLit and
|
||||||
regs[rc].node.kind == nkNilLit) or
|
regs[rc].node.kind == nkNilLit) or
|
||||||
regs[rb].node == regs[rc].node)
|
regs[rb].node == regs[rc].node)
|
||||||
|
of opcEqNimrodNode:
|
||||||
|
decodeBC(rkInt)
|
||||||
|
regs[ra].intVal =
|
||||||
|
ord(exprStructuralEquivalent(regs[rb].node, regs[rc].node))
|
||||||
of opcXor:
|
of opcXor:
|
||||||
decodeBC(rkInt)
|
decodeBC(rkInt)
|
||||||
regs[ra].intVal = ord(regs[rb].intVal != regs[rc].intVal)
|
regs[ra].intVal = ord(regs[rb].intVal != regs[rc].intVal)
|
||||||
|
|
|
||||||
39
tests/macros/tnodecompare.nim
Normal file
39
tests/macros/tnodecompare.nim
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue