summary refs log tree commit diff stats
path: root/tests/accept
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-09-21 00:54:13 +0200
committerAraq <rumpf_a@web.de>2011-09-21 00:54:13 +0200
commit2359b8b1073cfd027ac14a147aba06cc18d61010 (patch)
treea626a08e54311512f40d6ce1a40ffd397dab9cfa /tests/accept
parent57f184cf48a0b522001ab20e2c742d4d6436e14d (diff)
downloadNim-2359b8b1073cfd027ac14a147aba06cc18d61010.tar.gz
fixed some newly introduced bugs
Diffstat (limited to 'tests/accept')
-rw-r--r--tests/accept/compile/tdumpast2.nim35
-rwxr-xr-xtests/accept/compile/toverprc.nim46
2 files changed, 59 insertions, 22 deletions
diff --git a/tests/accept/compile/tdumpast2.nim b/tests/accept/compile/tdumpast2.nim
new file mode 100644
index 000000000..fb31af0ec
--- /dev/null
+++ b/tests/accept/compile/tdumpast2.nim
@@ -0,0 +1,35 @@
+# Dump the contents of a PNimrodNode
+
+import macros
+
+proc dumpit(n: PNimrodNode): string {.compileTime.} = 
+  if n == nil: return "nil"
+  result = $n.kind
+  add(result, "(")
+  case n.kind
+  of nnkEmpty: nil # same as nil node in this representation 
+  of nnkNilLit:                  add(result, "nil")
+  of nnkCharLit..nnkInt64Lit:    add(result, $n.intVal)
+  of nnkFloatLit..nnkFloat64Lit: add(result, $n.floatVal)
+  of nnkStrLit..nnkTripleStrLit: add(result, $n.strVal)
+  of nnkIdent:                   add(result, $n.ident)
+  of nnkSym, nnkNone:            assert false
+  else:
+    add(result, dumpit(n[0]))
+    for j in 1..n.len-1:
+      add(result, ", ")
+      add(result, dumpit(n[j]))
+  add(result, ")")
+  
+macro dumpAST(n: stmt): stmt = 
+  # dump AST as a side-effect and return the inner node
+  echo dumpit(n)
+  result = n[1]
+  
+dumpAST:
+  proc add(x, y: int): int =
+    return x + y
+  
+  proc sub(x, y: int): int = return x - y
+
+
diff --git a/tests/accept/compile/toverprc.nim b/tests/accept/compile/toverprc.nim
index f35528ace..43271b684 100755
--- a/tests/accept/compile/toverprc.nim
+++ b/tests/accept/compile/toverprc.nim
@@ -1,25 +1,27 @@
 # Test overloading of procs when used as function pointers

 

 import strutils

-
-proc parseInt(x: float): int = nil
-proc parseInt(x: bool): int = nil
-proc parseInt(x: float32): int = nil
-proc parseInt(x: int8): int = nil
-proc parseInt(x: TFile): int = nil
-proc parseInt(x: char): int = nil
-proc parseInt(x: int16): int = nil
-
-type
-  TParseInt = proc (x: string): int
-
-var
-  q = TParseInt(parseInt)
-  p: TParseInt = parseInt
-
-proc takeParseInt(x: proc (y: string): int): int = 
-  result = x("123")
-  
-echo "Give a list of numbers (separated by spaces): "
-var x = stdin.readline.split.each(parseInt).max
echo x, " is the maximum!"
echo "another number: ", takeParseInt(parseInt)
-
+

+proc parseInt(x: float): int {.noSideEffect.} = nil

+proc parseInt(x: bool): int {.noSideEffect.} = nil

+proc parseInt(x: float32): int {.noSideEffect.} = nil

+proc parseInt(x: int8): int {.noSideEffect.} = nil

+proc parseInt(x: TFile): int {.noSideEffect.} = nil

+proc parseInt(x: char): int {.noSideEffect.} = nil

+proc parseInt(x: int16): int {.noSideEffect.} = nil

+

+type

+  TParseInt = proc (x: string): int {.noSideEffect.}

+

+var

+  q = TParseInt(parseInt)

+  p: TParseInt = parseInt

+

+proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = 

+  result = x("123")

+  

+echo "Give a list of numbers (separated by spaces): "

+var x = stdin.readline.split.each(parseInt).max

+echo x, " is the maximum!"

+echo "another number: ", takeParseInt(parseInt)

+