made tests green again

This commit is contained in:
Araq 2012-09-18 00:36:48 +02:00
commit a71c5f98ea
5 changed files with 19 additions and 12 deletions

View file

@ -1427,7 +1427,7 @@ proc buildCall(n: PNode): PNode =
elif n.kind in nkCallKinds and n.sons[0].kind == nkDotExpr: elif n.kind in nkCallKinds and n.sons[0].kind == nkDotExpr:
# x.y(a) -> y(x, a) # x.y(a) -> y(x, a)
let a = n.sons[0] let a = n.sons[0]
result = newNodeI(nkDotCall, n.info, n.len+1) result = newNodeI(nkCall, n.info, n.len+1)
result.sons[0] = a.sons[1] result.sons[0] = a.sons[1]
result.sons[1] = a.sons[0] result.sons[1] = a.sons[0]
for i in 1 .. <n.len: result.sons[i+1] = n.sons[i] for i in 1 .. <n.len: result.sons[i+1] = n.sons[i]

View file

@ -19,7 +19,7 @@
type type
TSemGenericFlag = enum TSemGenericFlag = enum
withinBind, withinTypeDesc withinBind, withinTypeDesc, withinMixin
TSemGenericFlags = set[TSemGenericFlag] TSemGenericFlags = set[TSemGenericFlag]
proc getIdentNode(n: PNode): PNode = proc getIdentNode(n: PNode): PNode =
@ -80,13 +80,15 @@ proc semGenericStmt(c: PContext, n: PNode,
of nkIdent, nkAccQuoted: of nkIdent, nkAccQuoted:
var s = SymtabGet(c.Tab, n.ident) var s = SymtabGet(c.Tab, n.ident)
if s == nil: if s == nil:
if withinMixin notin flags:
localError(n.info, errUndeclaredIdentifier, n.ident.s) localError(n.info, errUndeclaredIdentifier, n.ident.s)
else: else:
if withinBind in flags or s.id in toBind: if withinBind in flags or s.id in toBind:
result = symChoice(c, n, s, scClosed) result = symChoice(c, n, s, scClosed)
else: result = semGenericStmtSymbol(c, n, s) else: result = semGenericStmtSymbol(c, n, s)
of nkDotExpr: of nkDotExpr:
var s = QualifiedLookUp(c, n, {checkUndeclared}) let luf = if withinMixin notin flags: {checkUndeclared} else: {}
var s = QualifiedLookUp(c, n, luf)
if s != nil: result = semGenericStmtSymbol(c, n, s) if s != nil: result = semGenericStmtSymbol(c, n, s)
# XXX for example: ``result.add`` -- ``add`` needs to be looked up here... # XXX for example: ``result.add`` -- ``add`` needs to be looked up here...
of nkEmpty, nkSym..nkNilLit: of nkEmpty, nkSym..nkNilLit:
@ -98,7 +100,8 @@ proc semGenericStmt(c: PContext, n: PNode,
of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkCommand, nkCallStrLit: of nkCall, nkHiddenCallConv, nkInfix, nkPrefix, nkCommand, nkCallStrLit:
# check if it is an expression macro: # check if it is an expression macro:
checkMinSonsLen(n, 1) checkMinSonsLen(n, 1)
var s = qualifiedLookup(c, n.sons[0], {checkUndeclared}) let luf = if withinMixin notin flags: {checkUndeclared} else: {}
var s = qualifiedLookup(c, n.sons[0], luf)
var first = 0 var first = 0
var isDefinedMagic = false var isDefinedMagic = false
if s != nil: if s != nil:
@ -143,7 +146,8 @@ proc semGenericStmt(c: PContext, n: PNode,
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}) let luf = if withinMixin notin flags: {checkUndeclared} else: {}
var s = qualifiedLookup(c, a, luf)
if s != nil and macroToExpand(s): if s != nil and macroToExpand(s):
result = semMacroStmt(c, n, {}, false) result = semMacroStmt(c, n, {}, false)
for i in countup(0, sonsLen(result)-1): for i in countup(0, sonsLen(result)-1):
@ -151,6 +155,9 @@ proc semGenericStmt(c: PContext, n: PNode,
of nkIfStmt: of nkIfStmt:
for i in countup(0, sonsLen(n)-1): for i in countup(0, sonsLen(n)-1):
n.sons[i] = semGenericStmtScope(c, n.sons[i], flags, toBind) n.sons[i] = semGenericStmtScope(c, n.sons[i], flags, toBind)
of nkWhenStmt:
for i in countup(0, sonsLen(n)-1):
n.sons[i] = semGenericStmt(c, n.sons[i], flags+{withinMixin}, toBind)
of nkWhileStmt: of nkWhileStmt:
openScope(c.tab) openScope(c.tab)
for i in countup(0, sonsLen(n)-1): for i in countup(0, sonsLen(n)-1):

View file

@ -41,7 +41,7 @@ proc binarySearch*[T](a: openarray[T], key: T): int =
var mid = (result + b) div 2 var mid = (result + b) div 2
if a[mid] < key: result = mid + 1 if a[mid] < key: result = mid + 1
else: b = mid else: b = mid
if result >= len(x) or a[result] != key: result = -1 if result >= len(a) or a[result] != key: result = -1
proc smartBinarySearch*[T](a: openArray[T], key: T): int = proc smartBinarySearch*[T](a: openArray[T], key: T): int =
## ``a.len`` must be a power of 2 for this to work. ## ``a.len`` must be a power of 2 for this to work.

View file

@ -1673,6 +1673,10 @@ template newException*(exceptn: typeDesc, message: string): expr =
e.msg = message e.msg = message
e e
proc getTypeInfo*[T](x: T): pointer {.magic: "GetTypeInfo".}
## get type information for `x`. Ordinary code should not use this, but
## the `typeinfo` module instead.
when not defined(EcmaScript) and not defined(NimrodVM): when not defined(EcmaScript) and not defined(NimrodVM):
{.push stack_trace: off, profiler:off.} {.push stack_trace: off, profiler:off.}
@ -2202,10 +2206,6 @@ proc `[]=`*[T](s: var seq[T], x: TSlice[int], b: openArray[T]) =
else: else:
spliceImpl(s, a, L, b) spliceImpl(s, a, L, b)
proc getTypeInfo*[T](x: T): pointer {.magic: "GetTypeInfo".}
## get type information for `x`. Ordinary code should not use this, but
## the `typeinfo` module instead.
proc slurp*(filename: string): string {.magic: "Slurp".} proc slurp*(filename: string): string {.magic: "Slurp".}
proc staticRead*(filename: string): string {.magic: "Slurp".} proc staticRead*(filename: string): string {.magic: "Slurp".}
## compile-time ``readFile`` proc for easy `resource`:idx: embedding: ## compile-time ``readFile`` proc for easy `resource`:idx: embedding:

View file

@ -1,6 +1,6 @@
discard """ discard """
file: "system.nim" file: "system.nim"
line: 646 line: 643
errormsg: "type mismatch" errormsg: "type mismatch"
""" """