diff options
author | Araq <rumpf_a@web.de> | 2012-09-08 15:43:21 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-09-08 15:43:21 +0200 |
commit | b64eeeb4303953f9fe1135cb9c3c61e23ec55afa (patch) | |
tree | 0f994de4a02afd9bed14dafcac24a3dd2df99d0d /tests | |
parent | 355ae07b8f3362af4e90770477d344dcd2fef594 (diff) | |
download | Nim-b64eeeb4303953f9fe1135cb9c3c61e23ec55afa.tar.gz |
term rewriting improvements
Diffstat (limited to 'tests')
-rw-r--r-- | tests/patterns/tmatrix.nim | 26 | ||||
-rw-r--r-- | tests/patterns/tnoendlessrec.nim | 10 | ||||
-rw-r--r-- | tests/patterns/tstar.nim | 2 | ||||
-rw-r--r-- | tests/reject/tdisallowif.nim | 4 | ||||
-rwxr-xr-x | tests/reject/ttypenoval.nim | 2 | ||||
-rw-r--r-- | tests/run/tpatterns.nim | 2 |
6 files changed, 41 insertions, 5 deletions
diff --git a/tests/patterns/tmatrix.nim b/tests/patterns/tmatrix.nim new file mode 100644 index 000000000..067c4cd5a --- /dev/null +++ b/tests/patterns/tmatrix.nim @@ -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 diff --git a/tests/patterns/tnoendlessrec.nim b/tests/patterns/tnoendlessrec.nim new file mode 100644 index 000000000..53891bcc0 --- /dev/null +++ b/tests/patterns/tnoendlessrec.nim @@ -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) diff --git a/tests/patterns/tstar.nim b/tests/patterns/tstar.nim index 55d841c3a..ac3373214 100644 --- a/tests/patterns/tstar.nim +++ b/tests/patterns/tstar.nim @@ -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" diff --git a/tests/reject/tdisallowif.nim b/tests/reject/tdisallowif.nim index 002bc7491..f7bb7098b 100644 --- a/tests/reject/tdisallowif.nim +++ b/tests/reject/tdisallowif.nim @@ -4,8 +4,8 @@ discard """ """ template optZero{x+x}(x: int): int = x*3 -template andthen{x*3}(x: int): int = x*4 -template optSubstr1{x = substr(x, a, b)}(x: string, a, b: int) = setlen(x, b+1) +template andthen{`*`(x,3)}(x: int): int = x*4 +template optSubstr1{x = substr(x, 0, b)}(x: string, b: int) = setlen(x, b+1) template disallowIf{ if cond: action diff --git a/tests/reject/ttypenoval.nim b/tests/reject/ttypenoval.nim index 6362407ef..214b35e29 100755 --- a/tests/reject/ttypenoval.nim +++ b/tests/reject/ttypenoval.nim @@ -1,7 +1,7 @@ discard """ file: "ttypenoval.nim" line: 38 - errormsg: "type mismatch: got (typedesc{int}) but expected 'int'" + errormsg: "type mismatch: got (typedesc[int]) but expected 'int'" """ # A min-heap. diff --git a/tests/run/tpatterns.nim b/tests/run/tpatterns.nim index 4a83d167c..6bc8772e3 100644 --- a/tests/run/tpatterns.nim +++ b/tests/run/tpatterns.nim @@ -4,7 +4,7 @@ hel''' """ template optZero{x+x}(x: int): int = x*3 -template andthen{x*3}(x: int): int = x*4 +template andthen{`*`(x,3)}(x: int): int = x*4 template optSubstr1{x = substr(x, a, b)}(x: string, a, b: int) = setlen(x, b+1) var y = 12 |