made some tests green

This commit is contained in:
Araq 2012-09-12 08:43:24 +02:00
commit 8178cd4fab
21 changed files with 42 additions and 39 deletions

View file

@ -707,7 +707,7 @@ proc semExprNoType(c: PContext, n: PNode): PNode =
result = isCallExpr(n) and n.sons[0].kind == nkSym and result = isCallExpr(n) and n.sons[0].kind == nkSym and
sfDiscardable in n.sons[0].sym.flags sfDiscardable in n.sons[0].sym.flags
result = semExpr(c, n) result = semExpr(c, n)
if result.typ != nil and result.typ.kind != tyStmt: if result.typ != nil and result.typ.kind notin {tyStmt, tyEmpty}:
if gCmd == cmdInteractive: if gCmd == cmdInteractive:
result = buildEchoStmt(c, result) result = buildEchoStmt(c, result)
elif not ImplicitelyDiscardable(result) and result.typ.kind != tyError: elif not ImplicitelyDiscardable(result) and result.typ.kind != tyError:

View file

@ -31,19 +31,19 @@ var
checkpoints: seq[string] = @[] checkpoints: seq[string] = @[]
template TestSetupIMPL*: stmt {.dirty.} = nil template TestSetupIMPL*: stmt {.immediate, dirty.} = nil
template TestTeardownIMPL*: stmt {.dirty.} = nil template TestTeardownIMPL*: stmt {.immediate, dirty.} = nil
proc shouldRun(testName: string): bool = proc shouldRun(testName: string): bool =
result = true result = true
template suite*(name: expr, body: stmt): stmt {.dirty.} = template suite*(name: expr, body: stmt): stmt {.immediate, dirty.} =
block: block:
template setup*(setupBody: stmt): stmt {.dirty.} = template setup*(setupBody: stmt): stmt {.immediate, dirty.} =
template TestSetupIMPL: stmt {.dirty.} = setupBody template TestSetupIMPL: stmt {.immediate, dirty.} = setupBody
template teardown*(teardownBody: stmt): stmt {.dirty.} = template teardown*(teardownBody: stmt): stmt {.immediate, dirty.} =
template TestTeardownIMPL: stmt {.dirty.} = teardownBody template TestTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
body body
@ -59,7 +59,7 @@ proc testDone(name: string, s: TTestStatus) =
else: else:
echo "[", $s, "] ", name, "\n" echo "[", $s, "] ", name, "\n"
template test*(name: expr, body: stmt): stmt {.dirty.} = template test*(name: expr, body: stmt): stmt {.immediate, dirty.} =
bind shouldRun, checkpoints, testDone bind shouldRun, checkpoints, testDone
if shouldRun(name): if shouldRun(name):
@ -148,7 +148,7 @@ macro check*(conditions: stmt): stmt {.immediate.} =
var ast = conditions.treeRepr var ast = conditions.treeRepr
error conditions.lineinfo & ": Malformed check statement:\n" & ast error conditions.lineinfo & ": Malformed check statement:\n" & ast
template require*(conditions: stmt): stmt {.dirty.} = template require*(conditions: stmt): stmt {.immediate, dirty.} =
block: block:
const AbortOnError {.inject.} = true const AbortOnError {.inject.} = true
check conditions check conditions

View file

@ -245,9 +245,7 @@ when not defined(useNimRtl):
# We jump through some hops here to ensure that Nimrod thread procs can have # We jump through some hops here to ensure that Nimrod thread procs can have
# the Nimrod calling convention. This is needed because thread procs are # the Nimrod calling convention. This is needed because thread procs are
# ``stdcall`` on Windows and ``noconv`` on UNIX. Alternative would be to just # ``stdcall`` on Windows and ``noconv`` on UNIX. Alternative would be to just
# use ``stdcall`` since it is mapped to ``noconv`` on UNIX anyway. However, # use ``stdcall`` since it is mapped to ``noconv`` on UNIX anyway.
# the current approach will likely result in less problems later when we have
# GC'ed closures in Nimrod.
type type
TThread* {.pure, final.}[TArg] = TThread* {.pure, final.}[TArg] =
@ -265,7 +263,7 @@ type
when not defined(boehmgc) and not hasSharedHeap: when not defined(boehmgc) and not hasSharedHeap:
proc deallocOsPages() proc deallocOsPages()
template ThreadProcWrapperBody(closure: expr) = template ThreadProcWrapperBody(closure: expr) {.immediate.} =
when defined(globalsSlot): ThreadVarSetValue(globalsSlot, closure) when defined(globalsSlot): ThreadVarSetValue(globalsSlot, closure)
var t = cast[ptr TThread[TArg]](closure) var t = cast[ptr TThread[TArg]](closure)
when useStackMaskHack: when useStackMaskHack:

View file

@ -22,7 +22,7 @@ template `?<|` (a, b: expr) =
compileTimeAssert isPartOf(a, b) == arMaybe compileTimeAssert isPartOf(a, b) == arMaybe
type type
TA = object TA {.inheritable.} = object
TC = object of TA TC = object of TA
arr: array[0..3, int] arr: array[0..3, int]
le, ri: ref TC le, ri: ref TC

View file

@ -5,7 +5,7 @@
## Copyright (c) 2011 FWA. All rights reserved. ## Copyright (c) 2011 FWA. All rights reserved.
type type
TGen[T] = object TGen[T] = object of TObject
x, y: T x, y: T
TSpef[T] = object of TGen[T] TSpef[T] = object of TGen[T]

View file

@ -5,7 +5,7 @@
## Copyright (c) 2011 FWA. All rights reserved. ## Copyright (c) 2011 FWA. All rights reserved.
type type
TGen[T] = object TGen[T] = object {.inheritable.}
TSpef = object of TGen[string] TSpef = object of TGen[string]

View file

@ -7,7 +7,7 @@ type
Features: seq[Feature] # Read-Only Features: seq[Feature] # Read-Only
PNode* = ref Node PNode* = ref Node
Node = object Node = object {.inheritable.}
attributes*: seq[PAttr] attributes*: seq[PAttr]
childNodes*: seq[PNode] childNodes*: seq[PNode]
FLocalName: string # Read-only FLocalName: string # Read-only

View file

@ -8,8 +8,9 @@ template plus(a, b: expr): expr =
macro call(e: expr): expr = macro call(e: expr): expr =
result = newCall("foo", newStrLitNode("bar")) result = newCall("foo", newStrLitNode("bar"))
macro dumpAST(n: stmt): stmt = macro dumpAST(n: stmt): stmt {.immediate.} =
# dump AST as a side-effect and return the inner node # dump AST as a side-effect and return the inner node
let n = callsite()
echo n.lispRepr echo n.lispRepr
echo n.treeRepr echo n.treeRepr

View file

@ -21,8 +21,9 @@ proc dumpit(n: PNimrodNode): string {.compileTime.} =
add(result, dumpit(n[j])) add(result, dumpit(n[j]))
add(result, ")") add(result, ")")
macro dumpAST(n: stmt): stmt = macro dumpAST(n: stmt): stmt {.immediate.} =
# dump AST as a side-effect and return the inner node # dump AST as a side-effect and return the inner node
let n = callsite()
echo dumpit(n) echo dumpit(n)
result = n[1] result = n[1]

View file

@ -5,7 +5,7 @@ proc testProc: string {.compileTime.} =
result = result & "" result = result & ""
when true: when true:
macro test(n: stmt): stmt = macro test(n: stmt): stmt {.immediate.} =
result = newNimNode(nnkStmtList) result = newNimNode(nnkStmtList)
echo "#", testProc(), "#" echo "#", testProc(), "#"
test: test:

View file

@ -15,7 +15,8 @@ proc fac[T](x: T): T =
if x <= 1: return 1 if x <= 1: return 1
else: return x.`*`(fac(x-1)) else: return x.`*`(fac(x-1))
macro macrotest(n: expr): stmt = macro macrotest(n: expr): stmt {.immediate.} =
let n = callsite()
expectKind(n, nnkCall) expectKind(n, nnkCall)
expectMinLen(n, 2) expectMinLen(n, 2)
result = newNimNode(nnkStmtList, n) result = newNimNode(nnkStmtList, n)
@ -23,7 +24,8 @@ macro macrotest(n: expr): stmt =
result.add(newCall("write", n[1], n[i])) result.add(newCall("write", n[1], n[i]))
result.add(newCall("writeln", n[1], newStrLitNode(""))) result.add(newCall("writeln", n[1], newStrLitNode("")))
macro debug(n: expr): stmt = macro debug(n: expr): stmt {.immediate.} =
let n = callsite()
result = newNimNode(nnkStmtList, n) result = newNimNode(nnkStmtList, n)
for i in 1..n.len-1: for i in 1..n.len-1:
result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i]))) result.add(newCall("write", newIdentNode("stdout"), toStrLit(n[i])))

View file

@ -2,7 +2,7 @@ import macros
from uri import `/` from uri import `/`
macro test*(a: stmt): stmt = macro test*(a: stmt): stmt {.immediate.} =
var nodes: tuple[a, b: int] var nodes: tuple[a, b: int]
nodes.a = 4 nodes.a = 4
nodes[1] = 45 nodes[1] = 45

View file

@ -1,5 +1,5 @@
import macros import macros
macro case_token(n: stmt): stmt = macro case_token(n: stmt): stmt {.immediate.} =
# creates a lexical analyzer from regular expressions # creates a lexical analyzer from regular expressions
# ... (implementation is an exercise for the reader :-) # ... (implementation is an exercise for the reader :-)
nil nil

View file

@ -1,7 +1,7 @@
# Covariance is not type safe: # Covariance is not type safe:
type type
TA = object TA = object of TObject
a: int a: int
TB = object of TA TB = object of TA
b: array[0..5000_000, int] b: array[0..5000_000, int]

View file

@ -1,7 +1,7 @@
# Tests the object implementation # Tests the object implementation
type type
TPoint2d = object TPoint2d {.inheritable.} = object
x, y: int x, y: int
TPoint3d = object of TPoint2d TPoint3d = object of TPoint2d

View file

@ -1,5 +1,5 @@
type type
TBase = object TBase = object of TObject
x, y: int x, y: int
TSubclassKind = enum ka, kb, kc, kd, ke, kf TSubclassKind = enum ka, kb, kc, kd, ke, kf

View file

@ -3,7 +3,7 @@ discard """
""" """
type type
TA = object TA = object of TObject
x, y: int x, y: int
TB = object of TA TB = object of TA

View file

@ -9,7 +9,7 @@ const bitsPerUnit = 8*sizeof(int)
type type
TRadixNodeKind = enum rnLinear, rnFull, rnLeafBits, rnLeafLinear TRadixNodeKind = enum rnLinear, rnFull, rnLeafBits, rnLeafLinear
PRadixNode = ptr TRadixNode PRadixNode = ptr TRadixNode
TRadixNode {.pure.} = object TRadixNode {.pure, inheritable.} = object
kind: TRadixNodeKind kind: TRadixNodeKind
TRadixNodeLinear = object of TRadixNode TRadixNodeLinear = object of TRadixNode
len: int8 len: int8
@ -78,7 +78,7 @@ proc exclLeaf(r: PRadixNode, a: int) =
return return
else: assert(false) else: assert(false)
proc in_Operator*(r: PRadixNode, a: TAddress): bool = proc contains*(r: PRadixNode, a: TAddress): bool =
if r == nil: return false if r == nil: return false
var x = searchInner(r, a shr 24 and 0xff) var x = searchInner(r, a shr 24 and 0xff)
if x == nil: return false if x == nil: return false

View file

@ -3,7 +3,7 @@
type type
TRadixNodeKind = enum rnLinear, rnFull, rnLeaf TRadixNodeKind = enum rnLinear, rnFull, rnLeaf
PRadixNode = ref TRadixNode PRadixNode = ref TRadixNode
TRadixNode = object TRadixNode = object {.inheritable.}
kind: TRadixNodeKind kind: TRadixNodeKind
TRadixNodeLinear = object of TRadixNode TRadixNodeLinear = object of TRadixNode
len: int8 len: int8
@ -47,7 +47,7 @@ proc search(r: PRadixNode, s: string): PRadixNode =
inc(j) inc(j)
inc(i) inc(i)
proc in_Operator*(r: PRadixNode, s: string): bool = proc contains*(r: PRadixNode, s: string): bool =
return search(r, s) != nil return search(r, s) != nil
proc testOrincl*(r: var PRadixNode, s: string): bool = proc testOrincl*(r: var PRadixNode, s: string): bool =

View file

@ -1,7 +1,8 @@
template withOpenFile(f: expr, filename: string, mode: TFileMode, template withOpenFile(f: expr, filename: string, mode: TFileMode,
actions: stmt): stmt = actions: stmt): stmt {.immediate.} =
block: block:
# test that 'f' is implicitely 'injecting':
var f: TFile var f: TFile
if open(f, filename, mode): if open(f, filename, mode):
try: try:
@ -15,11 +16,11 @@ withOpenFile(txt, "ttempl3.txt", fmWrite):
writeln(txt, "line 1") writeln(txt, "line 1")
txt.writeln("line 2") txt.writeln("line 2")
# Test zero argument template:
template ha: expr = myVar[0]
var var
myVar: array[0..1, int] myVar: array[0..1, int]
# Test zero argument template:
template ha: expr = myVar[0]
ha = 1 ha = 1
echo(ha) echo(ha)
@ -32,7 +33,7 @@ var `hu "XYZ"` = "yay"
echo prefix(XYZ) echo prefix(XYZ)
template typedef(name: expr, typ: typeDesc) {.immediate.} = template typedef(name: expr, typ: typeDesc) {.immediate, dirty.} =
type type
`T name`* = typ `T name`* = typ
`P name`* = ref `T name` `P name`* = ref `T name`

View file

@ -11,7 +11,7 @@ var x = if 4 != 5:
else: else:
"no" "no"
macro mymacro(n: expr): expr = result = n[0] macro mymacro(n: expr): stmt {.immediate.} = nil
mymacro: mymacro:
echo "test" echo "test"