made more tests green; fixes #201
This commit is contained in:
parent
8178cd4fab
commit
a59abdf8e4
13 changed files with 43 additions and 30 deletions
|
|
@ -111,21 +111,24 @@ proc semAfterMacroCall(c: PContext, n: PNode, s: PSym): PNode =
|
||||||
GlobalError(s.info, errTemplateInstantiationTooNested)
|
GlobalError(s.info, errTemplateInstantiationTooNested)
|
||||||
|
|
||||||
result = n
|
result = n
|
||||||
case s.typ.sons[0].kind
|
if s.typ.sons[0] == nil:
|
||||||
of tyExpr:
|
|
||||||
# BUGFIX: we cannot expect a type here, because module aliases would not
|
|
||||||
# work then (see the ``tmodulealias`` test)
|
|
||||||
# semExprWithType(c, result)
|
|
||||||
result = semExpr(c, result)
|
|
||||||
of tyStmt:
|
|
||||||
result = semStmt(c, result)
|
result = semStmt(c, result)
|
||||||
of tyTypeDesc:
|
|
||||||
if n.kind == nkStmtList: result.kind = nkStmtListType
|
|
||||||
result.typ = semTypeNode(c, result, nil)
|
|
||||||
else:
|
else:
|
||||||
result = semExpr(c, result)
|
case s.typ.sons[0].kind
|
||||||
result = fitNode(c, s.typ.sons[0], result)
|
of tyExpr:
|
||||||
#GlobalError(s.info, errInvalidParamKindX, typeToString(s.typ.sons[0]))
|
# BUGFIX: we cannot expect a type here, because module aliases would not
|
||||||
|
# work then (see the ``tmodulealias`` test)
|
||||||
|
# semExprWithType(c, result)
|
||||||
|
result = semExpr(c, result)
|
||||||
|
of tyStmt:
|
||||||
|
result = semStmt(c, result)
|
||||||
|
of tyTypeDesc:
|
||||||
|
if n.kind == nkStmtList: result.kind = nkStmtListType
|
||||||
|
result.typ = semTypeNode(c, result, nil)
|
||||||
|
else:
|
||||||
|
result = semExpr(c, result)
|
||||||
|
result = fitNode(c, s.typ.sons[0], result)
|
||||||
|
#GlobalError(s.info, errInvalidParamKindX, typeToString(s.typ.sons[0]))
|
||||||
dec(evalTemplateCounter)
|
dec(evalTemplateCounter)
|
||||||
|
|
||||||
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ proc instantiateBody(c: PContext, n: PNode, result: PSym) =
|
||||||
# add it here, so that recursive generic procs are possible:
|
# add it here, so that recursive generic procs are possible:
|
||||||
addDecl(c, result)
|
addDecl(c, result)
|
||||||
pushProcCon(c, result)
|
pushProcCon(c, result)
|
||||||
if result.kind in {skProc, skMethod, skConverter}:
|
if result.kind in {skProc, skMethod, skConverter, skMacro}:
|
||||||
addResult(c, result.typ.sons[0], n.info, result.kind)
|
addResult(c, result.typ.sons[0], n.info, result.kind)
|
||||||
addResultNode(c, n)
|
addResultNode(c, n)
|
||||||
var b = semStmtScope(c, n.sons[bodyPos])
|
var b = semStmtScope(c, n.sons[bodyPos])
|
||||||
|
|
@ -184,8 +184,9 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
pragma(c, result, n.sons[pragmasPos], allRoutinePragmas)
|
pragma(c, result, n.sons[pragmasPos], allRoutinePragmas)
|
||||||
if isNil(n.sons[bodyPos]):
|
if isNil(n.sons[bodyPos]):
|
||||||
n.sons[bodyPos] = copyTree(fn.getBody)
|
n.sons[bodyPos] = copyTree(fn.getBody)
|
||||||
instantiateBody(c, n, result)
|
if fn.kind != skTemplate:
|
||||||
sideEffectsCheck(c, result)
|
instantiateBody(c, n, result)
|
||||||
|
sideEffectsCheck(c, result)
|
||||||
else:
|
else:
|
||||||
result = oldPrc
|
result = oldPrc
|
||||||
popInfoContext()
|
popInfoContext()
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,7 @@ proc card*[A](s: TOrderedSet[A]): int {.inline.} =
|
||||||
## alias for `len`.
|
## alias for `len`.
|
||||||
result = s.counter
|
result = s.counter
|
||||||
|
|
||||||
template forAllOrderedPairs(yieldStmt: stmt) {.dirty.} =
|
template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} =
|
||||||
var h = s.first
|
var h = s.first
|
||||||
while h >= 0:
|
while h >= 0:
|
||||||
var nxt = s.data[h].next
|
var nxt = s.data[h].next
|
||||||
|
|
|
||||||
|
|
@ -202,7 +202,7 @@ proc len*[A, B](t: TOrderedTable[A, B]): int {.inline.} =
|
||||||
## returns the number of keys in `t`.
|
## returns the number of keys in `t`.
|
||||||
result = t.counter
|
result = t.counter
|
||||||
|
|
||||||
template forAllOrderedPairs(yieldStmt: stmt) {.dirty.} =
|
template forAllOrderedPairs(yieldStmt: stmt) {.dirty, immediate.} =
|
||||||
var h = t.first
|
var h = t.first
|
||||||
while h >= 0:
|
while h >= 0:
|
||||||
var nxt = t.data[h].next
|
var nxt = t.data[h].next
|
||||||
|
|
|
||||||
|
|
@ -180,12 +180,12 @@ proc rawRecv(q: PRawChannel, data: pointer, typ: PNimType) =
|
||||||
storeAux(data, addr(q.data[q.rd * typ.size]), typ, q, mLoad)
|
storeAux(data, addr(q.data[q.rd * typ.size]), typ, q, mLoad)
|
||||||
q.rd = (q.rd + 1) and q.mask
|
q.rd = (q.rd + 1) and q.mask
|
||||||
|
|
||||||
template lockChannel(q: expr, action: stmt) =
|
template lockChannel(q: expr, action: stmt) {.immediate.} =
|
||||||
acquireSys(q.lock)
|
acquireSys(q.lock)
|
||||||
action
|
action
|
||||||
releaseSys(q.lock)
|
releaseSys(q.lock)
|
||||||
|
|
||||||
template sendImpl(q: expr) =
|
template sendImpl(q: expr) {.immediate.} =
|
||||||
if q.mask == ChannelDeadMask:
|
if q.mask == ChannelDeadMask:
|
||||||
raise newException(EDeadThread, "cannot send message; thread died")
|
raise newException(EDeadThread, "cannot send message; thread died")
|
||||||
acquireSys(q.lock)
|
acquireSys(q.lock)
|
||||||
|
|
|
||||||
|
|
@ -66,12 +66,12 @@ proc setItem[T,D] (AKey: T, AValue: D, ANode: PNode[T,D]): ref TItem[T,D] {.inli
|
||||||
proc cmp[T:Int8|Int16|Int32|Int64|Int] (a,b: T): T {.inline.} =
|
proc cmp[T:Int8|Int16|Int32|Int64|Int] (a,b: T): T {.inline.} =
|
||||||
return a-b
|
return a-b
|
||||||
|
|
||||||
template binSearchImpl *(docmp: expr) =
|
template binSearchImpl *(docmp: expr) {.immediate.} =
|
||||||
var bFound = false
|
var bFound = false
|
||||||
result = 0
|
result = 0
|
||||||
var H = haystack.len -1
|
var H = haystack.len -1
|
||||||
while result <= H :
|
while result <= H :
|
||||||
var I = (result + H) shr 1
|
var I {.inject.} = (result + H) shr 1
|
||||||
var SW = docmp
|
var SW = docmp
|
||||||
if SW < 0: result = I + 1
|
if SW < 0: result = I + 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,12 @@
|
||||||
|
|
||||||
template tmp[T](x: var seq[T]) =
|
template tmp[T](x: var seq[T]) =
|
||||||
var yz: T
|
#var yz: T # XXX doesn't work yet
|
||||||
x = @[1, 2, 3]
|
x = @[1, 2, 3]
|
||||||
|
|
||||||
|
macro tmp2[T](x: var seq[T]): stmt =
|
||||||
|
nil
|
||||||
|
|
||||||
var y: seq[int]
|
var y: seq[int]
|
||||||
tmp(y)
|
tmp(y)
|
||||||
|
tmp(y)
|
||||||
echo y.repr
|
echo y.repr
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
|
discard """
|
||||||
|
output: "123100"
|
||||||
|
"""
|
||||||
|
|
||||||
template hygienic(val: expr) =
|
template hygienic(val: expr) =
|
||||||
var `*x` = val
|
var x = val
|
||||||
stdout.write `*x`
|
stdout.write x
|
||||||
|
|
||||||
var x = 100
|
var x = 100
|
||||||
|
|
||||||
|
|
@ -8,7 +8,7 @@ type
|
||||||
TA = tuple[a: int]
|
TA = tuple[a: int]
|
||||||
PA = ref TA
|
PA = ref TA
|
||||||
|
|
||||||
macro test*(a: stmt): stmt =
|
macro test*(a: stmt): stmt {.immediate.} =
|
||||||
var val: PA
|
var val: PA
|
||||||
new(val)
|
new(val)
|
||||||
val.a = 4
|
val.a = 4
|
||||||
|
|
@ -16,7 +16,7 @@ macro test*(a: stmt): stmt =
|
||||||
test:
|
test:
|
||||||
"hi"
|
"hi"
|
||||||
|
|
||||||
macro test2*(a: stmt): stmt =
|
macro test2*(a: stmt): stmt {.immediate.} =
|
||||||
proc testproc(recurse: int) =
|
proc testproc(recurse: int) =
|
||||||
echo "Thats weird"
|
echo "Thats weird"
|
||||||
var o : PNimrodNode = nil
|
var o : PNimrodNode = nil
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
import
|
import
|
||||||
macros, strutils
|
macros, strutils
|
||||||
|
|
||||||
macro test_macro*(n: stmt): stmt =
|
macro test_macro*(n: stmt): stmt {.immediate.} =
|
||||||
result = newNimNode(nnkStmtList)
|
result = newNimNode(nnkStmtList)
|
||||||
var ass : PNimrodNode = newNimNode(nnkAsgn)
|
var ass : PNimrodNode = newNimNode(nnkAsgn)
|
||||||
add(ass, newIdentNode("str"))
|
add(ass, newIdentNode("str"))
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ discard """
|
||||||
import
|
import
|
||||||
macros, strutils
|
macros, strutils
|
||||||
|
|
||||||
macro outterMacro*(n: stmt): stmt =
|
macro outterMacro*(n: stmt): stmt {.immediate.} =
|
||||||
let n = callsite()
|
let n = callsite()
|
||||||
var j : string = "hi"
|
var j : string = "hi"
|
||||||
proc innerProc(i: int): string =
|
proc innerProc(i: int): string =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''true'''
|
output: '''true'''
|
||||||
cmd: "nimrod cc --gc:none --hints:on $# $#"
|
cmd: "nimrod cc --hints:on $# $#"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import hashes, sets
|
import hashes, sets
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -76,6 +76,7 @@ version 0.9.XX
|
||||||
per default?
|
per default?
|
||||||
- 'const' objects including case objects
|
- 'const' objects including case objects
|
||||||
- 'export' feature
|
- 'export' feature
|
||||||
|
- from buggymodule import * except optBroken, optBroken2
|
||||||
- think about ``{:}.toTable[int, string]()``
|
- think about ``{:}.toTable[int, string]()``
|
||||||
- mocking support with ``tyProxy`` that does:
|
- mocking support with ``tyProxy`` that does:
|
||||||
o.p(x) --> p(o, x) --> myMacro(p, o, x)
|
o.p(x) --> p(o, x) --> myMacro(p, o, x)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue