the compiler can now deal with multiple modules of the same name
This commit is contained in:
parent
c085a1b4f0
commit
a0b82db402
13 changed files with 74 additions and 18 deletions
|
|
@ -992,12 +992,15 @@ proc genMainProc(m: BModule) =
|
||||||
gBreakpoints, mainModInit, toRope(m.labels)])
|
gBreakpoints, mainModInit, toRope(m.labels)])
|
||||||
if optNoMain notin gGlobalOptions:
|
if optNoMain notin gGlobalOptions:
|
||||||
appcg(m, m.s[cfsProcs], otherMain, [])
|
appcg(m, m.s[cfsProcs], otherMain, [])
|
||||||
|
|
||||||
proc getInitName(m: PSym): PRope =
|
|
||||||
result = ropeff("$1Init", "@$1Init", [toRope(m.name.s)])
|
|
||||||
|
|
||||||
proc getDatInitName(m: PSym): PRope =
|
proc getSomeInitName(m: PSym, suffix: string): PRope =
|
||||||
result = ropeff("$1DatInit", "@$1DatInit", [toRope(m.name.s)])
|
if {sfSystemModule, sfMainModule} * m.flags == {}:
|
||||||
|
result = m.info.toFullPath.getPackageName.mangle.toRope
|
||||||
|
result.app m.name.s
|
||||||
|
result.app suffix
|
||||||
|
|
||||||
|
proc getInitName(m: PSym): PRope = getSomeInitName(m, "Init")
|
||||||
|
proc getDatInitName(m: PSym): PRope = getSomeInitName(m, "DatInit")
|
||||||
|
|
||||||
proc registerModuleToMain(m: PSym) =
|
proc registerModuleToMain(m: PSym) =
|
||||||
var
|
var
|
||||||
|
|
@ -1167,7 +1170,7 @@ proc resetCgenModules* =
|
||||||
for m in cgenModules(): resetModule(m)
|
for m in cgenModules(): resetModule(m)
|
||||||
|
|
||||||
proc rawNewModule(module: PSym): BModule =
|
proc rawNewModule(module: PSym): BModule =
|
||||||
result = rawNewModule(module, module.filename)
|
result = rawNewModule(module, module.position.int32.toFullPath)
|
||||||
|
|
||||||
proc newModule(module: PSym): BModule =
|
proc newModule(module: PSym): BModule =
|
||||||
# we should create only one cgen module for each module sym
|
# we should create only one cgen module for each module sym
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ proc getModuleName*(n: PNode): string =
|
||||||
proc checkModuleName*(n: PNode): int32 =
|
proc checkModuleName*(n: PNode): int32 =
|
||||||
# This returns the full canonical path for a given module import
|
# This returns the full canonical path for a given module import
|
||||||
let modulename = n.getModuleName
|
let modulename = n.getModuleName
|
||||||
let fullPath = findModule(modulename)
|
let fullPath = findModule(modulename, n.info.toFullPath)
|
||||||
if fullPath.len == 0:
|
if fullPath.len == 0:
|
||||||
LocalError(n.info, errCannotOpenFile, modulename)
|
LocalError(n.info, errCannotOpenFile, modulename)
|
||||||
result = InvalidFileIDX
|
result = InvalidFileIDX
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,5 @@ const
|
||||||
VersionPatch* = 3
|
VersionPatch* = 3
|
||||||
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch
|
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch
|
||||||
|
|
||||||
RodFileVersion* = "1212" # modify this if the rod-format changes!
|
RodFileVersion* = "1214" # modify this if the rod-format changes!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ proc getGeneratedPath: string =
|
||||||
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
|
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
|
||||||
genSubDir
|
genSubDir
|
||||||
|
|
||||||
proc getPackageName(path: string): string =
|
proc getPackageName*(path: string): string =
|
||||||
var q = 1
|
var q = 1
|
||||||
var b = 0
|
var b = 0
|
||||||
if path[len(path)-1] in {dirsep, altsep}: q = 2
|
if path[len(path)-1] in {dirsep, altsep}: q = 2
|
||||||
|
|
@ -221,10 +221,11 @@ proc getPackageName(path: string): string =
|
||||||
case x.normalize
|
case x.normalize
|
||||||
of "lib", "src", "source", "package", "pckg", "library": b = i
|
of "lib", "src", "source", "package", "pckg", "library": b = i
|
||||||
else: return x
|
else: return x
|
||||||
|
result = ""
|
||||||
|
|
||||||
proc withPackageName*(path: string): string =
|
proc withPackageName*(path: string): string =
|
||||||
let x = path.getPackageName
|
let x = path.getPackageName
|
||||||
if x.isNil:
|
if x.len == 0:
|
||||||
result = path
|
result = path
|
||||||
else:
|
else:
|
||||||
let (p, file, ext) = path.splitFile
|
let (p, file, ext) = path.splitFile
|
||||||
|
|
@ -282,9 +283,13 @@ proc FindFile*(f: string): string {.procvar.} =
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
result = f.toLower.rawFindFile2
|
result = f.toLower.rawFindFile2
|
||||||
|
|
||||||
proc findModule*(modulename: string): string {.inline.} =
|
proc findModule*(modulename, currentModule: string): string =
|
||||||
# returns path to module
|
# returns path to module
|
||||||
result = FindFile(AddFileExt(modulename, nimExt))
|
let m = addFileExt(modulename, nimExt)
|
||||||
|
let currentPath = currentModule.splitFile.dir
|
||||||
|
result = currentPath / m
|
||||||
|
if not existsFile(result):
|
||||||
|
result = FindFile(m)
|
||||||
|
|
||||||
proc libCandidates*(s: string, dest: var seq[string]) =
|
proc libCandidates*(s: string, dest: var seq[string]) =
|
||||||
var le = strutils.find(s, '(')
|
var le = strutils.find(s, '(')
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ type
|
||||||
memfile: TMemFile # unfortunately there is no point in time where we
|
memfile: TMemFile # unfortunately there is no point in time where we
|
||||||
# can close this! XXX
|
# can close this! XXX
|
||||||
methods*: TSymSeq
|
methods*: TSymSeq
|
||||||
|
origFile: string
|
||||||
inViewMode: bool
|
inViewMode: bool
|
||||||
|
|
||||||
PRodReader* = ref TRodReader
|
PRodReader* = ref TRodReader
|
||||||
|
|
@ -558,6 +559,9 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
||||||
inc(r.pos) # skip ':'
|
inc(r.pos) # skip ':'
|
||||||
r.moduleID = decodeVInt(r.s, r.pos)
|
r.moduleID = decodeVInt(r.s, r.pos)
|
||||||
setID(r.moduleID)
|
setID(r.moduleID)
|
||||||
|
of "ORIGFILE":
|
||||||
|
inc(r.pos)
|
||||||
|
r.origFile = decodeStr(r.s, r.pos)
|
||||||
of "OPTIONS":
|
of "OPTIONS":
|
||||||
inc(r.pos) # skip ':'
|
inc(r.pos) # skip ':'
|
||||||
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
||||||
|
|
@ -585,7 +589,7 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
||||||
inc(r.line)
|
inc(r.line)
|
||||||
while r.s[r.pos] != ')':
|
while r.s[r.pos] != ')':
|
||||||
let relativePath = decodeStr(r.s, r.pos)
|
let relativePath = decodeStr(r.s, r.pos)
|
||||||
let resolvedPath = relativePath.findModule
|
let resolvedPath = relativePath.findModule(r.origFile)
|
||||||
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
||||||
r.files.add(finalPath.fileInfoIdx)
|
r.files.add(finalPath.fileInfoIdx)
|
||||||
inc(r.pos) # skip #10
|
inc(r.pos) # skip #10
|
||||||
|
|
@ -1036,6 +1040,10 @@ proc viewFile(rodfile: string) =
|
||||||
r.moduleID = decodeVInt(r.s, r.pos)
|
r.moduleID = decodeVInt(r.s, r.pos)
|
||||||
setID(r.moduleID)
|
setID(r.moduleID)
|
||||||
outf.writeln("ID:", $r.moduleID)
|
outf.writeln("ID:", $r.moduleID)
|
||||||
|
of "ORIGFILE":
|
||||||
|
inc(r.pos)
|
||||||
|
r.origFile = decodeStr(r.s, r.pos)
|
||||||
|
outf.writeln("ORIGFILE:", r.origFile)
|
||||||
of "OPTIONS":
|
of "OPTIONS":
|
||||||
inc(r.pos) # skip ':'
|
inc(r.pos) # skip ':'
|
||||||
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
||||||
|
|
@ -1058,13 +1066,13 @@ proc viewFile(rodfile: string) =
|
||||||
outf.write(" ", w)
|
outf.write(" ", w)
|
||||||
if r.s[r.pos] == ' ': inc(r.pos)
|
if r.s[r.pos] == ' ': inc(r.pos)
|
||||||
outf.write("\n")
|
outf.write("\n")
|
||||||
of "FILES":
|
of "FILES":
|
||||||
inc(r.pos, 2) # skip "(\10"
|
inc(r.pos, 2) # skip "(\10"
|
||||||
inc(r.line)
|
inc(r.line)
|
||||||
outf.write("FILES(\n")
|
outf.write("FILES(\n")
|
||||||
while r.s[r.pos] != ')':
|
while r.s[r.pos] != ')':
|
||||||
let relativePath = decodeStr(r.s, r.pos)
|
let relativePath = decodeStr(r.s, r.pos)
|
||||||
let resolvedPath = relativePath.findModule
|
let resolvedPath = relativePath.findModule(r.origFile)
|
||||||
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
||||||
r.files.add(finalPath.fileInfoIdx)
|
r.files.add(finalPath.fileInfoIdx)
|
||||||
inc(r.pos) # skip #10
|
inc(r.pos) # skip #10
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ type
|
||||||
sstack: TSymSeq # a stack of symbols to process
|
sstack: TSymSeq # a stack of symbols to process
|
||||||
tstack: TTypeSeq # a stack of types to process
|
tstack: TTypeSeq # a stack of types to process
|
||||||
files: TStringSeq
|
files: TStringSeq
|
||||||
|
origFile: string
|
||||||
|
|
||||||
PRodWriter = ref TRodWriter
|
PRodWriter = ref TRodWriter
|
||||||
|
|
||||||
|
|
@ -81,6 +82,7 @@ proc newRodWriter(crc: TCrc32, module: PSym): PRodWriter =
|
||||||
result.converters = ""
|
result.converters = ""
|
||||||
result.methods = ""
|
result.methods = ""
|
||||||
result.init = ""
|
result.init = ""
|
||||||
|
result.origFile = module.info.toFilename
|
||||||
result.data = newStringOfCap(12_000)
|
result.data = newStringOfCap(12_000)
|
||||||
|
|
||||||
proc addModDep(w: PRodWriter, dep: string) =
|
proc addModDep(w: PRodWriter, dep: string) =
|
||||||
|
|
@ -91,7 +93,7 @@ const
|
||||||
rodNL = "\x0A"
|
rodNL = "\x0A"
|
||||||
|
|
||||||
proc addInclDep(w: PRodWriter, dep: string) =
|
proc addInclDep(w: PRodWriter, dep: string) =
|
||||||
var resolved = dep.findModule
|
var resolved = dep.findModule(w.module.info.toFullPath)
|
||||||
encodeVInt(fileIdx(w, dep), w.inclDeps)
|
encodeVInt(fileIdx(w, dep), w.inclDeps)
|
||||||
add(w.inclDeps, " ")
|
add(w.inclDeps, " ")
|
||||||
encodeVInt(crcFromFile(resolved), w.inclDeps)
|
encodeVInt(crcFromFile(resolved), w.inclDeps)
|
||||||
|
|
@ -434,6 +436,11 @@ proc writeRod(w: PRodWriter) =
|
||||||
encodeVInt(w.module.id, id)
|
encodeVInt(w.module.id, id)
|
||||||
f.write(id)
|
f.write(id)
|
||||||
f.write(rodNL)
|
f.write(rodNL)
|
||||||
|
|
||||||
|
var orig = "ORIGFILE:"
|
||||||
|
encodeStr(w.origFile, orig)
|
||||||
|
f.write(orig)
|
||||||
|
f.write(rodNL)
|
||||||
|
|
||||||
var crc = "CRC:"
|
var crc = "CRC:"
|
||||||
encodeVInt(w.crc, crc)
|
encodeVInt(w.crc, crc)
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,8 @@ directory structure looks like this::
|
||||||
|
|
||||||
And ``main`` imports ``x``, ``foo/x`` is imported. If ``other`` imports ``x``
|
And ``main`` imports ``x``, ``foo/x`` is imported. If ``other`` imports ``x``
|
||||||
then both ``$lib/x.nim`` and ``$lib/bar/x.nim`` match and so the compiler
|
then both ``$lib/x.nim`` and ``$lib/bar/x.nim`` match and so the compiler
|
||||||
rejects it.
|
should reject it. Currently however this check is not implemented and instead
|
||||||
|
the first matching file is used.
|
||||||
|
|
||||||
|
|
||||||
Generated C code directory
|
Generated C code directory
|
||||||
|
|
|
||||||
16
tests/manyloc/packages/noconflicts.nim
Normal file
16
tests/manyloc/packages/noconflicts.nim
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
discard """
|
||||||
|
output: '''package1/strutils
|
||||||
|
package2/strutils
|
||||||
|
noconflicts
|
||||||
|
new os.nim'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import package1/strutils as su1
|
||||||
|
import package2.strutils as su2
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
su1.foo()
|
||||||
|
su2.foo()
|
||||||
|
echo "noconflicts"
|
||||||
|
yay()
|
||||||
1
tests/manyloc/packages/noconflicts.nimrod.cfg
Normal file
1
tests/manyloc/packages/noconflicts.nimrod.cfg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Mark noconflicts as project file
|
||||||
5
tests/manyloc/packages/os.nim
Normal file
5
tests/manyloc/packages/os.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
# Overrides lib/pure/os.nim
|
||||||
|
|
||||||
|
proc yay* = echo "new os.nim"
|
||||||
|
|
||||||
5
tests/manyloc/packages/package1/strutils.nim
Normal file
5
tests/manyloc/packages/package1/strutils.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
# Overrides lib/pure/os.nim
|
||||||
|
|
||||||
|
proc foo* = echo "package1/strutils"
|
||||||
|
|
||||||
5
tests/manyloc/packages/package2/strutils.nim
Normal file
5
tests/manyloc/packages/package2/strutils.nim
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
|
||||||
|
# Overrides lib/pure/os.nim
|
||||||
|
|
||||||
|
proc foo* = echo "package2/strutils"
|
||||||
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -1,7 +1,7 @@
|
||||||
version 0.9.4
|
version 0.9.4
|
||||||
=============
|
=============
|
||||||
|
|
||||||
- change search path algorithm to care about packages
|
- add the code from the talk to examples or run tests
|
||||||
- new VM:
|
- new VM:
|
||||||
- implement the glue to replace evals.nim
|
- implement the glue to replace evals.nim
|
||||||
- implement missing magics
|
- implement missing magics
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue