the compiler is now aware of packages

This commit is contained in:
Araq 2014-03-02 23:46:20 +01:00
commit 614557994e
5 changed files with 18 additions and 25 deletions

View file

@ -481,6 +481,7 @@ type
skStub, # symbol is a stub and not yet loaded from the ROD skStub, # symbol is a stub and not yet loaded from the ROD
# file (it is loaded on demand, which may # file (it is loaded on demand, which may
# mean: never) # mean: never)
skPackage # symbol is a package (used for canonicalization)
TSymKinds* = set[TSymKind] TSymKinds* = set[TSymKind]
const const

View file

@ -1044,8 +1044,10 @@ proc genMainProc(m: BModule) =
appcg(m, m.s[cfsProcs], otherMain, []) appcg(m, m.s[cfsProcs], otherMain, [])
proc getSomeInitName(m: PSym, suffix: string): PRope = proc getSomeInitName(m: PSym, suffix: string): PRope =
assert m.kind == skModule
assert m.owner.kind == skPackage
if {sfSystemModule, sfMainModule} * m.flags == {}: if {sfSystemModule, sfMainModule} * m.flags == {}:
result = m.info.toFullPath.getPackageName.mangle.toRope result = m.owner.name.s.mangle.toRope
result.app m.name.s result.app m.name.s
result.app suffix result.app suffix

View file

@ -1,7 +1,7 @@
# #
# #
# The Nimrod Compiler # The Nimrod Compiler
# (c) Copyright 2013 Andreas Rumpf # (c) Copyright 2014 Andreas Rumpf
# #
# See the file "copying.txt", included in this # See the file "copying.txt", included in this
# distribution, for details about the copyright. # distribution, for details about the copyright.
@ -20,7 +20,7 @@ type
TModuleInMemory* = object TModuleInMemory* = object
compiledAt*: float compiledAt*: float
crc*: TCrc32 crc*: TCrc32
deps*: seq[int32] ## XXX: slurped files are not currently tracked deps*: seq[int32] ## XXX: slurped files are currently not tracked
needsRecompile*: TNeedRecompile needsRecompile*: TNeedRecompile
crcStatus*: TCrcStatus crcStatus*: TCrcStatus
@ -83,7 +83,7 @@ proc resetAllModules* =
for i in 0..gCompiledModules.high: for i in 0..gCompiledModules.high:
if gCompiledModules[i] != nil: if gCompiledModules[i] != nil:
resetModule(i.int32) resetModule(i.int32)
resetPackageCache()
# for m in cgenModules(): echo "CGEN MODULE FOUND" # for m in cgenModules(): echo "CGEN MODULE FOUND"
proc checkDepMem(fileIdx: int32): TNeedRecompile = proc checkDepMem(fileIdx: int32): TNeedRecompile =
@ -120,8 +120,9 @@ proc newModule(fileIdx: int32): PSym =
if not isNimrodIdentifier(result.name.s): if not isNimrodIdentifier(result.name.s):
rawMessage(errInvalidModuleName, result.name.s) rawMessage(errInvalidModuleName, result.name.s)
result.owner = result # a module belongs to itself
result.info = newLineInfo(fileIdx, 1, 1) result.info = newLineInfo(fileIdx, 1, 1)
result.owner = newSym(skPackage, getIdent(getPackageName(filename)), nil,
result.info)
result.position = fileIdx result.position = fileIdx
growCache gMemCacheData, fileIdx growCache gMemCacheData, fileIdx

View file

@ -209,10 +209,15 @@ proc getGeneratedPath: string =
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir / result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
genSubDir genSubDir
var packageCache = newStringTable(when FileSystemCaseSensitive: template newPackageCache(): expr =
modeCaseInsensitive newStringTable(when FileSystemCaseSensitive:
else: modeCaseInsensitive
modeCaseSensitive) else:
modeCaseSensitive)
var packageCache = newPackageCache()
proc resetPackageCache*() = packageCache = newPackageCache()
iterator myParentDirs(p: string): string = iterator myParentDirs(p: string): string =
# XXX os's parentDirs is stupid (multiple yields) and triggers an old bug... # XXX os's parentDirs is stupid (multiple yields) and triggers an old bug...
@ -240,21 +245,6 @@ proc getPackageName*(path: string): string =
packageCache[d] = result packageCache[d] = result
dec parents dec parents
if parents <= 0: break if parents <= 0: break
when false:
var q = 1
var b = 0
if path[len(path)-1] in {DirSep, AltSep}: q = 2
for i in countdown(len(path)-q, 0):
if path[i] in {DirSep, AltSep}:
if b == 0: b = i
else:
let x = path.substr(i+1, b-1)
case x.normalize
of "lib", "src", "source", "package", "pckg", "library", "private":
b = i
else:
return x.replace('.', '_')
result = ""
proc withPackageName*(path: string): string = proc withPackageName*(path: string): string =
let x = path.getPackageName let x = path.getPackageName

View file

@ -2,7 +2,6 @@ version 0.9.4
============= =============
- fix gensym capture bug - fix gensym capture bug
- make the compiler aware of packages
- vm - vm
- at least try to get the basic type zoo ops right - at least try to get the basic type zoo ops right
- optimize opcAsgnStr - optimize opcAsgnStr