term rewriting improvements
This commit is contained in:
parent
355ae07b8f
commit
b64eeeb430
18 changed files with 284 additions and 144 deletions
26
tests/patterns/tmatrix.nim
Normal file
26
tests/patterns/tmatrix.nim
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
discard """
|
||||
output: "21"
|
||||
"""
|
||||
|
||||
import macros
|
||||
|
||||
type
|
||||
TMat = object
|
||||
dummy: int
|
||||
|
||||
proc `*`(a, b: TMat): TMat = nil
|
||||
proc `+`(a, b: TMat): TMat = nil
|
||||
proc `-`(a, b: TMat): TMat = nil
|
||||
proc `$`(a: TMat): string = result = $a.dummy
|
||||
|
||||
macro optOps{ (`+`|`-`|`*`) *| a }(a: varargs[TMat]): expr =
|
||||
result = newIntLitNode(21)
|
||||
|
||||
#macro optPlus{ `+` * a }(a: varargs[TMat]): expr =
|
||||
# result = newIntLitNode(21)
|
||||
|
||||
var x, y, z: TMat
|
||||
|
||||
echo x + y * z - x
|
||||
|
||||
#echo x + y + z
|
||||
10
tests/patterns/tnoendlessrec.nim
Normal file
10
tests/patterns/tnoendlessrec.nim
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
discard """
|
||||
output: "4"
|
||||
"""
|
||||
|
||||
# test that an endless recursion is avoided:
|
||||
|
||||
template optLen{len(x)}(x: expr): expr = len(x)
|
||||
|
||||
var s = "lala"
|
||||
echo len(s)
|
||||
|
|
@ -10,7 +10,7 @@ proc `&&`(s: varargs[string]): string =
|
|||
for i in 1..len(s)-1: result.add s[i]
|
||||
inc calls
|
||||
|
||||
template optConc{ `&&` * a }(a: expr): expr = &&a
|
||||
template optConc{ `&&` * a }(a: varargs[string]): expr = &&a
|
||||
|
||||
let space = " "
|
||||
echo "my" && (space & "awe" && "some " ) && "concat"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue