support for multiple modules of the same name; niminst supports 'platforms'; minor bugfixes

This commit is contained in:
Araq 2013-09-24 16:07:07 +02:00
commit 8b5aa221ad
14 changed files with 132 additions and 48 deletions

View file

@ -1210,7 +1210,7 @@ proc writeHeader(m: BModule) =
writeRope(result, m.filename)
proc getCFile(m: BModule): string =
result = changeFileExt(completeCFilePath(m.cfilename), cExt)
result = changeFileExt(completeCFilePath(m.cfilename.withPackageName), cExt)
proc myOpenCached(module: PSym, rd: PRodReader): PPassContext =
assert optSymbolFiles in gGlobalOptions

View file

@ -162,10 +162,11 @@ var
gNestedEvals: int # count the recursive calls to ``evalAux`` to prevent
# endless recursion
proc evalWhile(c: PEvalContext, n: PNode): PNode =
while true:
proc evalWhile(c: PEvalContext, n: PNode): PNode =
while true:
evalX(n.sons[0], {})
if getOrdValue(result) == 0: break
if getOrdValue(result) == 0:
result = emptyNode; break
result = evalAux(c, n.sons[1], {})
case result.kind
of nkBreakStmt:
@ -304,7 +305,7 @@ proc allocSlot(c: PStackFrame; sym: PSym): int =
setLen(c.slots, max(result+1, c.slots.len))
proc setSlot(c: PStackFrame, sym: PSym, val: PNode) =
assert sym.owner == c.prc
assert sym.owner == c.prc or sfFromGeneric in sym.flags
let idx = allocSlot(c, sym)
c.slots[idx] = val
@ -377,7 +378,7 @@ proc evalVariable(c: PStackFrame, sym: PSym, flags: TEvalFlags): PNode =
#result = emptyNode
proc evalGlobalVar(c: PEvalContext, s: PSym, flags: TEvalFlags): PNode =
if sfCompileTime in s.flags or c.mode == emRepl:
if sfCompileTime in s.flags or c.mode == emRepl or s.kind == skForVar:
result = IdNodeTableGet(c.globals, s)
if result != nil:
if not aliasNeeded(result, flags):
@ -549,7 +550,9 @@ proc evalSym(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
of skProc, skConverter, skMacro, skType:
result = n
#result = s.getBody
of skVar, skLet, skForVar, skTemp, skResult:
of skForVar:
result = evalGlobalVar(c, s, flags)
of skVar, skLet, skTemp, skResult:
if sfGlobal notin s.flags:
result = evalVariable(c.tos, s, flags)
else:
@ -1396,7 +1399,7 @@ proc evalAux(c: PEvalContext, n: PNode, flags: TEvalFlags): PNode =
of nkChckRangeF, nkChckRange64, nkChckRange: result = evalRangeChck(c, n)
of nkStringToCString: result = evalConvStrToCStr(c, n)
of nkCStringToString: result = evalConvCStrToStr(c, n)
of nkStmtListExpr, nkStmtList, nkModule:
of nkStmtListExpr, nkStmtList:
for i in countup(0, sonsLen(n) - 1):
result = evalAux(c, n.sons[i], flags)
case result.kind
@ -1455,7 +1458,7 @@ proc evalConstExprAux*(p: PEvalContext, module, prc: PSym, e: PNode): PNode =
proc setupMacroParam(x: PNode): PNode =
result = x
if result.kind == nkHiddenStdConv: result = result.sons[1]
if result.kind in {nkHiddenSubConv, nkHiddenStdConv}: result = result.sons[1]
proc evalMacroCall(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode =
# XXX GlobalError() is ugly here, but I don't know a better solution for now

View file

@ -298,13 +298,13 @@ const
gpp()]
const
hExt* = "h"
hExt* = ".h"
var
cCompiler* = ccGcc # the used compiler
cExt* = "c" # extension of generated C/C++ files
# (can be changed to .cpp later)
cExt* = ".c" # extension of generated C/C++ files
# (can be changed to .cpp later)
cIncludes*: seq[string] = @[] # directories to search for included files
cLibs*: seq[string] = @[] # directories to search for lib files
@ -518,7 +518,7 @@ proc footprint(filename: string): TCrc32 =
getCompileCFileCmd(filename, true)
proc externalFileChanged(filename: string): bool =
var crcFile = toGeneratedFile(filename, "crc")
var crcFile = toGeneratedFile(filename.withPackageName, "crc")
var currentCrc = int(footprint(filename))
var f: TFile
if open(f, crcFile, fmRead):

View file

@ -1,8 +1,16 @@
[Project]
Name: "Nimrod"
Version: "$version"
OS: "windows;linux;macosx;solaris;freebsd;netbsd;openbsd"
CPU: "i386;amd64;powerpc64;arm" # ;sparc
Platforms: """
windows: i386;amd64
linux: i386;amd64;powerpc64;arm;sparc;mips
macosx: i386;amd64;powerpc64
solaris: i386;amd64;sparc
freebsd: i386;amd64
netbsd: i386;amd64
openbsd: i386;amd64
haiku: i386;amd64
"""
Authors: "Andreas Rumpf"
Description: """This is the Nimrod Compiler. Nimrod is a new statically typed,

View file

@ -208,7 +208,19 @@ proc removeTrailingDirSep*(path: string): string =
proc getGeneratedPath: string =
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
genSubDir
proc withPackageName*(path: string): string =
var x = path
while true:
x = parentDir(x)
if x.len == 0: break
case x.normalize
of "lib", "src", "source", "package", "pckg", "library": discard
else:
let (path, file, ext) = path.splitFile
return (path / (x & '_' & file)) & ext
result = path
proc toGeneratedFile*(path, ext: string): string =
## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod"
var (head, tail) = splitPath(path)

View file

@ -1440,7 +1440,7 @@ proc parseSection(p: var TParser, kind: TNodeKind,
skipComment(p, result)
while sameInd(p):
case p.tok.tokType
of tkSymbol, tkAccent:
of tkSymbol, tkAccent, tkParLe:
var a = defparser(p)
skipComment(p, a)
addSon(result, a)

View file

@ -818,7 +818,7 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
gMods[fileIdx].reason = rrNone # we need to set it here to avoid cycles
result = rrNone
var r: PRodReader = nil
var rodfile = toGeneratedFile(filename, RodExt)
var rodfile = toGeneratedFile(filename.withPackageName, RodExt)
r = newRodReader(rodfile, crc, fileIdx)
if r == nil:
result = (if ExistsFile(rodfile): rrRodInvalid else: rrRodDoesNotExist)

View file

@ -421,7 +421,8 @@ proc addStmt(w: PRodWriter, n: PNode) =
proc writeRod(w: PRodWriter) =
processStacks(w, true)
var f: TFile
if not open(f, completeGeneratedFilePath(changeFileExt(w.filename, "rod")),
if not open(f, completeGeneratedFilePath(changeFileExt(
w.filename.withPackageName, RodExt)),
fmWrite):
#echo "couldn't write rod file for: ", w.filename
return

View file

@ -890,7 +890,7 @@ proc evalStaticExpr*(module: PSym, e: PNode, prc: PSym): PNode =
proc setupMacroParam(x: PNode): PNode =
result = x
if result.kind == nkHiddenStdConv: result = result.sons[1]
if result.kind in {nkHiddenSubConv, nkHiddenStdConv}: result = result.sons[1]
proc evalMacroCall(c: PEvalContext, n, nOrig: PNode, sym: PSym): PNode =
# XXX GlobalError() is ugly here, but I don't know a better solution for now