fixed some newly introduced bugs
This commit is contained in:
parent
57f184cf48
commit
2359b8b107
9 changed files with 91 additions and 45 deletions
35
tests/accept/compile/tdumpast2.nim
Normal file
35
tests/accept/compile/tdumpast2.nim
Normal file
|
|
@ -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
|
||||
|
||||
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue