made some tests green

This commit is contained in:
Araq
2012-09-12 08:43:24 +02:00
parent d48d3d0bd1
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
sfDiscardable in n.sons[0].sym.flags
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:
result = buildEchoStmt(c, result)
elif not ImplicitelyDiscardable(result) and result.typ.kind != tyError:

View File

@@ -31,19 +31,19 @@ var
checkpoints: seq[string] = @[]
template TestSetupIMPL*: stmt {.dirty.} = nil
template TestTeardownIMPL*: stmt {.dirty.} = nil
template TestSetupIMPL*: stmt {.immediate, dirty.} = nil
template TestTeardownIMPL*: stmt {.immediate, dirty.} = nil
proc shouldRun(testName: string): bool =
result = true
template suite*(name: expr, body: stmt): stmt {.dirty.} =
template suite*(name: expr, body: stmt): stmt {.immediate, dirty.} =
block:
template setup*(setupBody: stmt): stmt {.dirty.} =
template TestSetupIMPL: stmt {.dirty.} = setupBody
template setup*(setupBody: stmt): stmt {.immediate, dirty.} =
template TestSetupIMPL: stmt {.immediate, dirty.} = setupBody
template teardown*(teardownBody: stmt): stmt {.dirty.} =
template TestTeardownIMPL: stmt {.dirty.} = teardownBody
template teardown*(teardownBody: stmt): stmt {.immediate, dirty.} =
template TestTeardownIMPL: stmt {.immediate, dirty.} = teardownBody
body
@@ -59,7 +59,7 @@ proc testDone(name: string, s: TTestStatus) =
else:
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
if shouldRun(name):
@@ -148,7 +148,7 @@ macro check*(conditions: stmt): stmt {.immediate.} =
var ast = conditions.treeRepr
error conditions.lineinfo & ": Malformed check statement:\n" & ast
template require*(conditions: stmt): stmt {.dirty.} =
template require*(conditions: stmt): stmt {.immediate, dirty.} =
block:
const AbortOnError {.inject.} = true
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
# the Nimrod calling convention. This is needed because thread procs are
# ``stdcall`` on Windows and ``noconv`` on UNIX. Alternative would be to just
# use ``stdcall`` since it is mapped to ``noconv`` on UNIX anyway. However,
# the current approach will likely result in less problems later when we have
# GC'ed closures in Nimrod.
# use ``stdcall`` since it is mapped to ``noconv`` on UNIX anyway.
type
TThread* {.pure, final.}[TArg] =
@@ -265,7 +263,7 @@ type
when not defined(boehmgc) and not hasSharedHeap:
proc deallocOsPages()
template ThreadProcWrapperBody(closure: expr) =
template ThreadProcWrapperBody(closure: expr) {.immediate.} =
when defined(globalsSlot): ThreadVarSetValue(globalsSlot, closure)
var t = cast[ptr TThread[TArg]](closure)
when useStackMaskHack:

View File

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

View File

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

View File

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

View File

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

View File

@@ -8,8 +8,9 @@ template plus(a, b: expr): expr =
macro call(e: expr): expr =
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
let n = callsite()
echo n.lispRepr
echo n.treeRepr

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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