final fixes giving us a working compiler

This commit is contained in:
Zahary Karadjov 2013-05-12 02:19:17 +03:00
commit f317807a89
8 changed files with 19 additions and 22 deletions

View file

@ -12,7 +12,7 @@
import import
os, platform, condsyms, ast, astalgo, idents, semdata, msgs, renderer, os, platform, condsyms, ast, astalgo, idents, semdata, msgs, renderer,
wordrecg, ropes, options, strutils, lists, extccomp, math, magicsys, trees, wordrecg, ropes, options, strutils, lists, extccomp, math, magicsys, trees,
rodread, types rodread, types, lookups
const const
FirstCallConv* = wNimcall FirstCallConv* = wNimcall

View file

@ -30,11 +30,11 @@ proc equalGenericParams(procA, procB: PNode): bool =
if not ExprStructuralEquivalent(a.ast, b.ast): return if not ExprStructuralEquivalent(a.ast, b.ast): return
result = true 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 # 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. # the same the sym in the symbol table is returned, else nil.
var it: TIdentIter var it: TIdentIter
result = initIdentIter(it, c.tab.stack[tos], fn.Name) result = initIdentIter(it, scope.symbols, fn.Name)
if isGenericRoutine(fn): if isGenericRoutine(fn):
# we simply check the AST; this is imprecise but nearly the best what # 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 # 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 fn.ast.sons[paramsPos]) and
equalGenericParams(genR, genF): equalGenericParams(genR, genF):
return return
result = NextIdentIter(it, c.tab.stack[tos]) result = NextIdentIter(it, scope.symbols)
else: else:
while result != nil: while result != nil:
if result.Kind == fn.kind and not isGenericRoutine(result): if result.Kind == fn.kind and not isGenericRoutine(result):
@ -60,7 +60,7 @@ proc SearchForProc*(c: PContext, fn: PSym, tos: int): PSym =
return return
of paramsNotEqual: of paramsNotEqual:
nil nil
result = NextIdentIter(it, c.tab.stack[tos]) result = NextIdentIter(it, scope.symbols)
when false: when false:
proc paramsFitBorrow(child, parent: PNode): bool = proc paramsFitBorrow(child, parent: PNode): bool =
@ -76,16 +76,16 @@ when false:
dcEqOrDistinctOf): return dcEqOrDistinctOf): return
result = true 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 # 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. # for borrowing the sym in the symbol table is returned, else nil.
var it: TIdentIter var it: TIdentIter
for scope in countdown(tos, 0): for scope in walkScopes(startScope):
result = initIdentIter(it, c.tab.stack[scope], fn.Name) result = initIdentIter(it, scope.symbols, fn.Name)
while result != nil: while result != nil:
# watchout! result must not be the same as fn! # watchout! result must not be the same as fn!
if (result.Kind == fn.kind) and (result.id != fn.id): if (result.Kind == fn.kind) and (result.id != fn.id):
if equalGenericParams(result.ast.sons[genericParamsPos], if equalGenericParams(result.ast.sons[genericParamsPos],
fn.ast.sons[genericParamsPos]): fn.ast.sons[genericParamsPos]):
if paramsFitBorrow(fn.typ.n, result.typ.n): return if paramsFitBorrow(fn.typ.n, result.typ.n): return
result = NextIdentIter(it, c.tab.stack[scope]) result = NextIdentIter(it, scope.symbols)

View file

@ -99,7 +99,7 @@ proc commonType*(x, y: PType): PType =
result.addSonSkipIntLit(r) result.addSonSkipIntLit(r)
proc isTopLevel(c: PContext): bool {.inline.} = proc isTopLevel(c: PContext): bool {.inline.} =
result = c.tab.tos <= 2 result = c.scopeDepth <= 2
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym = proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info) 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 c.importTable.addSym(module) # a module knows itself
if sfSystemModule in module.flags: if sfSystemModule in module.flags:
magicsys.SystemModule = module # set global variable! magicsys.SystemModule = module # set global variable!
InitSystem(c.tab) # currently does nothing
else: else:
c.importTable.addSym magicsys.SystemModule # import the "System" identifier c.importTable.addSym magicsys.SystemModule # import the "System" identifier
importAllSymbols(c, magicsys.SystemModule) importAllSymbols(c, magicsys.SystemModule)

View file

@ -198,7 +198,7 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
else: else:
result = explicitGenericInstError(n) 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 # 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. # 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 # New approach: generate fn(x, y, z) where x, y, z have the proper types

View file

@ -1374,7 +1374,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
msgs.gErrorMax = high(int) msgs.gErrorMax = high(int)
# open a scope for temporary symbol inclusions: # open a scope for temporary symbol inclusions:
let oldTos = c.tab.tos let oldTos = c.scopeDepth
openScope(c) openScope(c)
let oldOwnerLen = len(gOwners) let oldOwnerLen = len(gOwners)
let oldGenerics = c.generics let oldGenerics = c.generics
@ -1398,7 +1398,7 @@ proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
c.p = oldProcCon c.p = oldProcCon
msgs.setInfoContextLen(oldContextLen) msgs.setInfoContextLen(oldContextLen)
setlen(gOwners, oldOwnerLen) setlen(gOwners, oldOwnerLen)
while c.tab.tos > oldTos: rawCloseScope(c) while c.scopeDepth > oldTos: rawCloseScope(c)
dec c.InCompilesContext dec c.InCompilesContext
dec msgs.gSilence dec msgs.gSilence
msgs.gErrorCounter = oldErrorCount msgs.gErrorCounter = oldErrorCount

View file

@ -773,7 +773,7 @@ proc addParams(c: PContext, n: PNode, kind: TSymKind) =
proc semBorrow(c: PContext, n: PNode, s: PSym) = proc semBorrow(c: PContext, n: PNode, s: PSym) =
# search for the correct alias: # 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: if b != nil:
# store the alias: # store the alias:
n.sons[bodyPos] = newSymNode(b) 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]) n.sons[patternPos] = semPattern(c, n.sons[patternPos])
if s.kind == skIterator: s.typ.flags.incl(tfIterator) if s.kind == skIterator: s.typ.flags.incl(tfIterator)
var proto = SearchForProc(c, s, c.tab.tos-2) # -2 because we have a scope var proto = SearchForProc(c, outerScope, s)
# open for parameters
if proto == nil: if proto == nil:
s.typ.callConv = lastOptionEntry(c).defaultCC s.typ.callConv = lastOptionEntry(c).defaultCC
# add it here, so that recursive procs are possible: # add it here, so that recursive procs are possible:

View file

@ -410,12 +410,11 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
result = n result = n
if n.sons[bodyPos].kind == nkEmpty: if n.sons[bodyPos].kind == nkEmpty:
LocalError(n.info, errImplOfXexpected, s.name.s) LocalError(n.info, errImplOfXexpected, s.name.s)
let curScope = c.tab.tos - 1 var proto = SearchForProc(c, c.currentScope, s)
var proto = SearchForProc(c, s, curScope)
if proto == nil: if proto == nil:
addInterfaceOverloadableSymAt(c, c.currentScope, s) addInterfaceOverloadableSymAt(c, c.currentScope, s)
else: else:
SymTabReplace(c.tab.stack[curScope], proto, s) SymTabReplace(c.currentScope.symbols, proto, s)
if n.sons[patternPos].kind != nkEmpty: if n.sons[patternPos].kind != nkEmpty:
c.patterns.add(s) c.patterns.add(s)

View file

@ -65,7 +65,7 @@ when not defined(nimhygiene):
template wholeSymTab(cond, section: expr) {.immediate.} = template wholeSymTab(cond, section: expr) {.immediate.} =
var isLocal = true var isLocal = true
for scope in walkScopes(c): for scope in walkScopes(c.currentScope):
if scope == c.topLevelScope: isLocal = false if scope == c.topLevelScope: isLocal = false
for item in items(scope.symbols): for item in items(scope.symbols):
let it {.inject.} = item 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) = proc suggestEverything(c: PContext, n: PNode, outputs: var int) =
# do not produce too many symbols: # do not produce too many symbols:
var isLocal = true var isLocal = true
for scope in walkScopes(c): for scope in walkScopes(c.currentScope):
if scope == c.topLevelScope: isLocal = false if scope == c.topLevelScope: isLocal = false
for it in items(scope.symbols): for it in items(scope.symbols):
if filterSym(it): if filterSym(it):