diff options
-rw-r--r-- | compiler/pragmas.nim | 2 | ||||
-rw-r--r-- | compiler/procfind.nim | 16 | ||||
-rw-r--r-- | compiler/sem.nim | 3 | ||||
-rw-r--r-- | compiler/semcall.nim | 2 | ||||
-rw-r--r-- | compiler/semexprs.nim | 4 | ||||
-rw-r--r-- | compiler/semstmts.nim | 5 | ||||
-rw-r--r-- | compiler/semtempl.nim | 5 | ||||
-rw-r--r-- | compiler/suggest.nim | 4 |
8 files changed, 19 insertions, 22 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index e623acd06..937d9c9eb 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -12,7 +12,7 @@ import os, platform, condsyms, ast, astalgo, idents, semdata, msgs, renderer, wordrecg, ropes, options, strutils, lists, extccomp, math, magicsys, trees, - rodread, types + rodread, types, lookups const FirstCallConv* = wNimcall diff --git a/compiler/procfind.nim b/compiler/procfind.nim index 2db6247e1..e41567816 100644 --- a/compiler/procfind.nim +++ b/compiler/procfind.nim @@ -30,11 +30,11 @@ proc equalGenericParams(procA, procB: PNode): bool = if not ExprStructuralEquivalent(a.ast, b.ast): return result = true -proc SearchForProc*(c: PContext, fn: PSym, tos: int): PSym = +proc SearchForProc*(c: PContext, scope: PScope, fn: PSym): PSym = # Searchs for the fn in the symbol table. If the parameter lists are exactly # the same the sym in the symbol table is returned, else nil. var it: TIdentIter - result = initIdentIter(it, c.tab.stack[tos], fn.Name) + result = initIdentIter(it, scope.symbols, fn.Name) if isGenericRoutine(fn): # we simply check the AST; this is imprecise but nearly the best what # can be done; this doesn't work either though as type constraints are @@ -48,7 +48,7 @@ proc SearchForProc*(c: PContext, fn: PSym, tos: int): PSym = fn.ast.sons[paramsPos]) and equalGenericParams(genR, genF): return - result = NextIdentIter(it, c.tab.stack[tos]) + result = NextIdentIter(it, scope.symbols) else: while result != nil: if result.Kind == fn.kind and not isGenericRoutine(result): @@ -60,7 +60,7 @@ proc SearchForProc*(c: PContext, fn: PSym, tos: int): PSym = return of paramsNotEqual: nil - result = NextIdentIter(it, c.tab.stack[tos]) + result = NextIdentIter(it, scope.symbols) when false: proc paramsFitBorrow(child, parent: PNode): bool = @@ -76,16 +76,16 @@ when false: dcEqOrDistinctOf): return result = true - proc SearchForBorrowProc*(c: PContext, fn: PSym, tos: int): PSym = + proc SearchForBorrowProc*(c: PContext, startScope: PScope, fn: PSym): PSym = # Searchs for the fn in the symbol table. If the parameter lists are suitable # for borrowing the sym in the symbol table is returned, else nil. var it: TIdentIter - for scope in countdown(tos, 0): - result = initIdentIter(it, c.tab.stack[scope], fn.Name) + for scope in walkScopes(startScope): + result = initIdentIter(it, scope.symbols, fn.Name) while result != nil: # watchout! result must not be the same as fn! if (result.Kind == fn.kind) and (result.id != fn.id): if equalGenericParams(result.ast.sons[genericParamsPos], fn.ast.sons[genericParamsPos]): if paramsFitBorrow(fn.typ.n, result.typ.n): return - result = NextIdentIter(it, c.tab.stack[scope]) + result = NextIdentIter(it, scope.symbols) diff --git a/compiler/sem.nim b/compiler/sem.nim index 21ba64a85..70e7d8673 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -99,7 +99,7 @@ proc commonType*(x, y: PType): PType = result.addSonSkipIntLit(r) proc isTopLevel(c: PContext): bool {.inline.} = - result = c.tab.tos <= 2 + result = c.scopeDepth <= 2 proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym = result = newSym(kind, considerAcc(n), getCurrOwner(), n.info) @@ -251,7 +251,6 @@ proc myOpen(module: PSym): PPassContext = c.importTable.addSym(module) # a module knows itself if sfSystemModule in module.flags: magicsys.SystemModule = module # set global variable! - InitSystem(c.tab) # currently does nothing else: c.importTable.addSym magicsys.SystemModule # import the "System" identifier importAllSymbols(c, magicsys.SystemModule) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index be41299ad..2f058ad0b 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -198,7 +198,7 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = else: result = explicitGenericInstError(n) -proc SearchForBorrowProc(c: PContext, fn: PSym, tos: int): PSym = +proc SearchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym = # Searchs for the fn in the symbol table. If the parameter lists are suitable # for borrowing the sym in the symbol table is returned, else nil. # New approach: generate fn(x, y, z) where x, y, z have the proper types diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 8977fd93d..4bae934a5 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1374,7 +1374,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = msgs.gErrorMax = high(int) # open a scope for temporary symbol inclusions: - let oldTos = c.tab.tos + let oldTos = c.scopeDepth openScope(c) let oldOwnerLen = len(gOwners) let oldGenerics = c.generics @@ -1398,7 +1398,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = c.p = oldProcCon msgs.setInfoContextLen(oldContextLen) setlen(gOwners, oldOwnerLen) - while c.tab.tos > oldTos: rawCloseScope(c) + while c.scopeDepth > oldTos: rawCloseScope(c) dec c.InCompilesContext dec msgs.gSilence msgs.gErrorCounter = oldErrorCount diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index fc98ff703..b16dbde58 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -773,7 +773,7 @@ proc addParams(c: PContext, n: PNode, kind: TSymKind) = proc semBorrow(c: PContext, n: PNode, s: PSym) = # search for the correct alias: - var b = SearchForBorrowProc(c, s, c.tab.tos - 2) + var b = SearchForBorrowProc(c, c.currentScope.parent, s) if b != nil: # store the alias: n.sons[bodyPos] = newSymNode(b) @@ -919,8 +919,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, n.sons[patternPos] = semPattern(c, n.sons[patternPos]) if s.kind == skIterator: s.typ.flags.incl(tfIterator) - var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope - # open for parameters + var proto = SearchForProc(c, outerScope, s) if proto == nil: s.typ.callConv = lastOptionEntry(c).defaultCC # add it here, so that recursive procs are possible: diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 7f6b85631..0405ba9d1 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -410,12 +410,11 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = result = n if n.sons[bodyPos].kind == nkEmpty: LocalError(n.info, errImplOfXexpected, s.name.s) - let curScope = c.tab.tos - 1 - var proto = SearchForProc(c, s, curScope) + var proto = SearchForProc(c, c.currentScope, s) if proto == nil: addInterfaceOverloadableSymAt(c, c.currentScope, s) else: - SymTabReplace(c.tab.stack[curScope], proto, s) + SymTabReplace(c.currentScope.symbols, proto, s) if n.sons[patternPos].kind != nkEmpty: c.patterns.add(s) diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 8e6d6b6fa..a5a7fcd66 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -65,7 +65,7 @@ when not defined(nimhygiene): template wholeSymTab(cond, section: expr) {.immediate.} = var isLocal = true - for scope in walkScopes(c): + for scope in walkScopes(c.currentScope): if scope == c.topLevelScope: isLocal = false for item in items(scope.symbols): let it {.inject.} = item @@ -126,7 +126,7 @@ proc suggestOperations(c: PContext, n: PNode, typ: PType, outputs: var int) = proc suggestEverything(c: PContext, n: PNode, outputs: var int) = # do not produce too many symbols: var isLocal = true - for scope in walkScopes(c): + for scope in walkScopes(c.currentScope): if scope == c.topLevelScope: isLocal = false for it in items(scope.symbols): if filterSym(it): |