mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 04:44:20 +00:00
final fixes giving us a working compiler
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user