first steps for overloading support of passing blocks; bugfix: test results of 'compile' are not overwritten

This commit is contained in:
Araq 2012-09-11 08:09:34 +02:00
commit 64c638a9dc
12 changed files with 70 additions and 39 deletions

View file

@ -228,7 +228,7 @@ proc processMergeInfo(L: var TBaseLexer, m: BModule) =
when not defined(nimhygiene): when not defined(nimhygiene):
{.pragma: inject.} {.pragma: inject.}
template withCFile(cfilename: string, body: stmt) = template withCFile(cfilename: string, body: stmt) {.immediate.} =
var s = LLStreamOpen(cfilename, fmRead) var s = LLStreamOpen(cfilename, fmRead)
if s == nil: return if s == nil: return
var L {.inject.}: TBaseLexer var L {.inject.}: TBaseLexer

View file

@ -87,7 +87,7 @@ proc genSimpleBlock(p: BProc, stmts: PNode) {.inline.} =
genStmts(p, stmts) genStmts(p, stmts)
endBlock(p) endBlock(p)
template preserveBreakIdx(body: stmt): stmt = template preserveBreakIdx(body: stmt): stmt {.immediate.} =
var oldBreakIdx = p.breakIdx var oldBreakIdx = p.breakIdx
body body
p.breakIdx = oldBreakIdx p.breakIdx = oldBreakIdx

View file

@ -50,7 +50,7 @@ type
# When adding new compilers, the cmake sources could be a good reference: # When adding new compilers, the cmake sources could be a good reference:
# http://cmake.org/gitweb?p=cmake.git;a=tree;f=Modules/Platform; # http://cmake.org/gitweb?p=cmake.git;a=tree;f=Modules/Platform;
template compiler(name: expr, settings: stmt):stmt = template compiler(name: expr, settings: stmt): stmt {.immediate.} =
proc name: TInfoCC {.compileTime.} = settings proc name: TInfoCC {.compileTime.} = settings
compiler gcc: compiler gcc:

View file

@ -1356,18 +1356,14 @@ proc semBlockExpr(c: PContext, n: PNode): PNode =
closeScope(c.tab) closeScope(c.tab)
Dec(c.p.nestedBlockCounter) Dec(c.p.nestedBlockCounter)
proc semMacroStmt(c: PContext, n: PNode, semCheck = true): PNode = proc semMacroStmt(c: PContext, n: PNode, flags: TExprFlags,
# XXX why no overloading here? semCheck = true): PNode =
checkMinSonsLen(n, 2) checkMinSonsLen(n, 2)
var a: PNode var a: PNode
if isCallExpr(n.sons[0]): a = n.sons[0].sons[0] if isCallExpr(n.sons[0]): a = n.sons[0].sons[0]
else: a = n.sons[0] else: a = n.sons[0]
var s = qualifiedLookup(c, a, {checkUndeclared}) var s = qualifiedLookup(c, a, {checkUndeclared})
if s != nil: if s != nil:
case s.kind
of skMacro:
result = semMacroExpr(c, n, n, s, semCheck)
of skTemplate:
# transform # transform
# nkMacroStmt(nkCall(a...), stmt, b...) # nkMacroStmt(nkCall(a...), stmt, b...)
# to # to
@ -1377,7 +1373,21 @@ proc semMacroStmt(c: PContext, n: PNode, semCheck = true): PNode =
if isCallExpr(n.sons[0]): if isCallExpr(n.sons[0]):
for i in countup(1, sonsLen(n.sons[0]) - 1): for i in countup(1, sonsLen(n.sons[0]) - 1):
addSon(result, n.sons[0].sons[i]) addSon(result, n.sons[0].sons[i])
for i in countup(1, sonsLen(n) - 1): addSon(result, n.sons[i]) # for sigmatch this need to have a type; we use 'void':
for i in countup(1, sonsLen(n) - 1):
n.sons[i].typ = newTypeS(tyEmpty, c)
addSon(result, n.sons[i])
case s.kind
of skMacro:
if sfImmediate notin s.flags:
result = semDirectOp(c, result, flags)
else:
result = semMacroExpr(c, result, n, s, semCheck)
of skTemplate:
if sfImmediate notin s.flags:
result = semDirectOp(c, result, flags)
else:
result = semTemplateExpr(c, result, s, semCheck) result = semTemplateExpr(c, result, s, semCheck)
else: else:
LocalError(n.info, errXisNoMacroOrTemplate, s.name.s) LocalError(n.info, errXisNoMacroOrTemplate, s.name.s)
@ -1494,7 +1504,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
else: else:
result = semIndirectOp(c, n, flags) result = semIndirectOp(c, n, flags)
of nkMacroStmt: of nkMacroStmt:
result = semMacroStmt(c, n) result = semMacroStmt(c, n, flags)
of nkWhenExpr: of nkWhenExpr:
result = semWhen(c, n, false) result = semWhen(c, n, false)
result = semExpr(c, result) result = semExpr(c, result)

View file

@ -40,6 +40,9 @@ proc semGenericStmtScope(c: PContext, n: PNode,
result = semGenericStmt(c, n, flags, toBind) result = semGenericStmt(c, n, flags, toBind)
closeScope(c.tab) closeScope(c.tab)
template macroToExpand(s: expr): expr =
s.kind in {skMacro, skTemplate} and (s.typ.len == 1 or sfImmediate in s.flags)
proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode = proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
incl(s.flags, sfUsed) incl(s.flags, sfUsed)
case s.kind case s.kind
@ -49,9 +52,15 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
of skProc, skMethod, skIterator, skConverter: of skProc, skMethod, skIterator, skConverter:
result = symChoice(c, n, s, scOpen) result = symChoice(c, n, s, scOpen)
of skTemplate: of skTemplate:
if macroToExpand(s):
result = semTemplateExpr(c, n, s, false) result = semTemplateExpr(c, n, s, false)
else:
result = symChoice(c, n, s, scOpen)
of skMacro: of skMacro:
if macroToExpand(s):
result = semMacroExpr(c, n, n, s, false) result = semMacroExpr(c, n, n, s, false)
else:
result = symChoice(c, n, s, scOpen)
of skGenericParam: of skGenericParam:
result = newSymNode(s, n.info) result = newSymNode(s, n.info)
of skParam: of skParam:
@ -97,9 +106,17 @@ proc semGenericStmt(c: PContext, n: PNode,
incl(s.flags, sfUsed) incl(s.flags, sfUsed)
case s.kind case s.kind
of skMacro: of skMacro:
if macroToExpand(s):
result = semMacroExpr(c, n, n, s, false) result = semMacroExpr(c, n, n, s, false)
else:
n.sons[0] = symChoice(c, n.sons[0], s, scOpen)
result = n
of skTemplate: of skTemplate:
if macroToExpand(s):
result = semTemplateExpr(c, n, s, false) result = semTemplateExpr(c, n, s, false)
else:
n.sons[0] = symChoice(c, n.sons[0], s, scOpen)
result = n
# BUGFIX: we must not return here, we need to do first phase of # BUGFIX: we must not return here, we need to do first phase of
# symbol lookup ... # symbol lookup ...
of skUnknown, skParam: of skUnknown, skParam:
@ -121,7 +138,13 @@ proc semGenericStmt(c: PContext, n: PNode,
for i in countup(first, sonsLen(result) - 1): for i in countup(first, sonsLen(result) - 1):
result.sons[i] = semGenericStmt(c, result.sons[i], flags, toBind) result.sons[i] = semGenericStmt(c, result.sons[i], flags, toBind)
of nkMacroStmt: of nkMacroStmt:
result = semMacroStmt(c, n, false) checkMinSonsLen(n, 2)
var a: PNode
if isCallExpr(n.sons[0]): a = n.sons[0].sons[0]
else: a = n.sons[0]
var s = qualifiedLookup(c, a, {})
if s != nil and macroToExpand(s):
result = semMacroStmt(c, n, {}, false)
for i in countup(0, sonsLen(result)-1): for i in countup(0, sonsLen(result)-1):
result.sons[i] = semGenericStmt(c, result.sons[i], flags, toBind) result.sons[i] = semGenericStmt(c, result.sons[i], flags, toBind)
of nkIfStmt: of nkIfStmt:

View file

@ -701,7 +701,7 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
else: else:
result = false result = false
template IfFastObjectTypeCheckFailed(a, b: PType, body: stmt) = template IfFastObjectTypeCheckFailed(a, b: PType, body: stmt) {.immediate.} =
if tfFromGeneric notin a.flags + b.flags: if tfFromGeneric notin a.flags + b.flags:
# fast case: id comparison suffices: # fast case: id comparison suffices:
result = a.id == b.id result = a.id == b.id

View file

@ -257,7 +257,6 @@ proc tests(args: string) =
exec("nimrod cc --taintMode:on tests/tester") exec("nimrod cc --taintMode:on tests/tester")
exec(getCurrentDir() / "tests/tester".exe & " reject") exec(getCurrentDir() / "tests/tester".exe & " reject")
exec(getCurrentDir() / "tests/tester".exe & " compile") exec(getCurrentDir() / "tests/tester".exe & " compile")
exec(getCurrentDir() / "tests/tester".exe & " examples")
exec(getCurrentDir() / "tests/tester".exe & " run") exec(getCurrentDir() / "tests/tester".exe & " run")
exec(getCurrentDir() / "tests/tester".exe & " merge") exec(getCurrentDir() / "tests/tester".exe & " merge")

View file

@ -388,7 +388,8 @@ proc getSockName*(socket: TSocket): TPort =
proc selectWrite*(writefds: var seq[TSocket], timeout = 500): int proc selectWrite*(writefds: var seq[TSocket], timeout = 500): int
template acceptAddrPlain(noClientRet, successRet: expr, sslImplementation: stmt): stmt = template acceptAddrPlain(noClientRet, successRet: expr,
sslImplementation: stmt): stmt {.immediate.} =
assert(client != nil) assert(client != nil)
var sockAddress: Tsockaddr_in var sockAddress: Tsockaddr_in
var addrLen = sizeof(sockAddress).TSockLen var addrLen = sizeof(sockAddress).TSockLen

View file

@ -39,12 +39,12 @@ type
f: cstring f: cstring
num, i, lineLen: int num, i, lineLen: int
template call(x: stmt) = template call(x: stmt) {.immediate.} =
p.i = i p.i = i
x x
i = p.i i = p.i
template callNoLineLenTracking(x: stmt) = template callNoLineLenTracking(x: stmt) {.immediate.} =
let oldLineLen = p.lineLen let oldLineLen = p.lineLen
p.i = i p.i = i
x x

View file

@ -18,7 +18,7 @@ const
resultsFile = "testresults.html" resultsFile = "testresults.html"
jsonFile = "testresults.json" jsonFile = "testresults.json"
Usage = "usage: tester [--print] " & Usage = "usage: tester [--print] " &
"reject|compile|examples|run|" & "reject|compile|run|" &
"merge|special|rodfiles| [nimrod options]\n" & "merge|special|rodfiles| [nimrod options]\n" &
" or: tester test|comp|rej singleTest" " or: tester test|comp|rej singleTest"
@ -65,7 +65,7 @@ proc extractSpec(filename: string): string =
when not defined(nimhygiene): when not defined(nimhygiene):
{.pragma: inject.} {.pragma: inject.}
template parseSpecAux(fillResult: stmt) = template parseSpecAux(fillResult: stmt) {.immediate.} =
var ss = newStringStream(extractSpec(filename)) var ss = newStringStream(extractSpec(filename))
var p {.inject.}: TCfgParser var p {.inject.}: TCfgParser
open(p, ss, filename, 1) open(p, ss, filename, 1)
@ -125,7 +125,7 @@ proc callCompiler(cmdTemplate, filename, options: string): TSpec =
var x = newStringOfCap(120) var x = newStringOfCap(120)
while outp.readLine(x.TaintedString) or running(p): while outp.readLine(x.TaintedString) or running(p):
if x =~ pegOfInterest: if x =~ pegOfInterest:
# `s` should contain the last error/warning message # `err` should contain the last error/warning message
err = x err = x
elif x =~ pegSuccess: elif x =~ pegSuccess:
suc = x suc = x
@ -360,12 +360,10 @@ proc main() =
of "compile": of "compile":
compile(r, "tests/compile/t*.nim", p.cmdLineRest.string) compile(r, "tests/compile/t*.nim", p.cmdLineRest.string)
compile(r, "tests/ecmas.nim", p.cmdLineRest.string) compile(r, "tests/ecmas.nim", p.cmdLineRest.string)
compileSpecialTests(r, p.cmdLineRest.string)
writeResults(compileJson, r)
of "examples":
compileExample(r, "lib/pure/*.nim", p.cmdLineRest.string) compileExample(r, "lib/pure/*.nim", p.cmdLineRest.string)
compileExample(r, "examples/*.nim", p.cmdLineRest.string) compileExample(r, "examples/*.nim", p.cmdLineRest.string)
compileExample(r, "examples/gtk/*.nim", p.cmdLineRest.string) compileExample(r, "examples/gtk/*.nim", p.cmdLineRest.string)
compileSpecialTests(r, p.cmdLineRest.string)
writeResults(compileJson, r) writeResults(compileJson, r)
of "run": of "run":
run(r, "tests/run", p.cmdLineRest.string) run(r, "tests/run", p.cmdLineRest.string)

View file

@ -22,7 +22,7 @@ file: ticker
[Documentation] [Documentation]
doc: "endb;intern;apis;lib;manual;tut1;tut2;nimrodc;overview;filters;trmacros" doc: "endb;intern;apis;lib;manual;tut1;tut2;nimrodc;overview;filters;trmacros"
doc: "tools;c2nim;niminst;nimgrep" doc: "tools;c2nim;niminst;nimgrep;gc"
pdf: "manual;lib;tut1;tut2;nimrodc;c2nim;niminst;gc" pdf: "manual;lib;tut1;tut2;nimrodc;c2nim;niminst;gc"
srcdoc: "core/macros;pure/marshal;core/typeinfo;core/unsigned" srcdoc: "core/macros;pure/marshal;core/typeinfo;core/unsigned"
srcdoc: "impure/graphics;impure/re;pure/sockets" srcdoc: "impure/graphics;impure/re;pure/sockets"