Merge pull request #2734 from def-/stdin-fix
Clean up stdin file reading of compiler.
This commit is contained in:
commit
d7c0b269cb
5 changed files with 25 additions and 22 deletions
|
|
@ -63,7 +63,7 @@ proc commandCompileToC =
|
||||||
compileProject()
|
compileProject()
|
||||||
cgenWriteModules()
|
cgenWriteModules()
|
||||||
if gCmd != cmdRun:
|
if gCmd != cmdRun:
|
||||||
extccomp.callCCompiler(if gProjectName == "-": "stdinfile" else: changeFileExt(gProjectFull, ""))
|
extccomp.callCCompiler(changeFileExt(gProjectFull, ""))
|
||||||
|
|
||||||
if isServing:
|
if isServing:
|
||||||
# caas will keep track only of the compilation commands
|
# caas will keep track only of the compilation commands
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
ast, astalgo, magicsys, crc, rodread, msgs, cgendata, sigmatch, options,
|
ast, astalgo, magicsys, crc, rodread, msgs, cgendata, sigmatch, options,
|
||||||
idents, os, lexer, idgen, passes, syntaxes
|
idents, os, lexer, idgen, passes, syntaxes, llstream
|
||||||
|
|
||||||
type
|
type
|
||||||
TNeedRecompile* = enum Maybe, No, Yes, Probing, Recompiled
|
TNeedRecompile* = enum Maybe, No, Yes, Probing, Recompiled
|
||||||
|
|
@ -116,7 +116,7 @@ proc newModule(fileIdx: int32): PSym =
|
||||||
result.kind = skModule
|
result.kind = skModule
|
||||||
let filename = fileIdx.toFullPath
|
let filename = fileIdx.toFullPath
|
||||||
result.name = getIdent(splitFile(filename).name)
|
result.name = getIdent(splitFile(filename).name)
|
||||||
if result.name.s != "-" and not isNimIdentifier(result.name.s):
|
if not isNimIdentifier(result.name.s):
|
||||||
rawMessage(errInvalidModuleName, result.name.s)
|
rawMessage(errInvalidModuleName, result.name.s)
|
||||||
|
|
||||||
result.info = newLineInfo(fileIdx, 1, 1)
|
result.info = newLineInfo(fileIdx, 1, 1)
|
||||||
|
|
@ -148,6 +148,9 @@ proc compileModule*(fileIdx: int32, flags: TSymFlags): PSym =
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
result.id = getID()
|
result.id = getID()
|
||||||
|
if sfMainModule in flags and gProjectIsStdin:
|
||||||
|
processModule(result, llStreamOpen(stdin), rd)
|
||||||
|
else:
|
||||||
processModule(result, nil, rd)
|
processModule(result, nil, rd)
|
||||||
if optCaasEnabled in gGlobalOptions:
|
if optCaasEnabled in gGlobalOptions:
|
||||||
gMemCacheData[fileIdx].compiledAt = gLastCmdTime
|
gMemCacheData[fileIdx].compiledAt = gLastCmdTime
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,12 @@ proc handleCmdLine() =
|
||||||
else:
|
else:
|
||||||
# Process command line arguments:
|
# Process command line arguments:
|
||||||
processCmdLine(passCmd1, "")
|
processCmdLine(passCmd1, "")
|
||||||
if gProjectName != "":
|
if gProjectName == "-":
|
||||||
|
gProjectName = "stdinfile"
|
||||||
|
gProjectFull = "stdinfile"
|
||||||
|
gProjectPath = getCurrentDir()
|
||||||
|
gProjectIsStdin = true
|
||||||
|
elif gProjectName != "":
|
||||||
try:
|
try:
|
||||||
gProjectFull = canonicalizePath(gProjectName)
|
gProjectFull = canonicalizePath(gProjectName)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
@ -61,8 +66,6 @@ proc handleCmdLine() =
|
||||||
if gCmd == cmdRun:
|
if gCmd == cmdRun:
|
||||||
tccgen.run(commands.arguments)
|
tccgen.run(commands.arguments)
|
||||||
if optRun in gGlobalOptions:
|
if optRun in gGlobalOptions:
|
||||||
if gProjectName == "-":
|
|
||||||
gProjectFull = "stdinfile"
|
|
||||||
if gCmd == cmdCompileToJS:
|
if gCmd == cmdCompileToJS:
|
||||||
var ex: string
|
var ex: string
|
||||||
if options.outFile.len > 0:
|
if options.outFile.len > 0:
|
||||||
|
|
|
||||||
|
|
@ -149,6 +149,7 @@ var
|
||||||
gProjectName* = "" # holds a name like 'nimrod'
|
gProjectName* = "" # holds a name like 'nimrod'
|
||||||
gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
|
gProjectPath* = "" # holds a path like /home/alice/projects/nimrod/compiler/
|
||||||
gProjectFull* = "" # projectPath/projectName
|
gProjectFull* = "" # projectPath/projectName
|
||||||
|
gProjectIsStdin* = false # whether we're compiling from stdin
|
||||||
gProjectMainIdx*: int32 # the canonical path id of the main module
|
gProjectMainIdx*: int32 # the canonical path id of the main module
|
||||||
nimcacheDir* = ""
|
nimcacheDir* = ""
|
||||||
command* = "" # the main command (e.g. cc, check, scan, etc)
|
command* = "" # the main command (e.g. cc, check, scan, etc)
|
||||||
|
|
|
||||||
|
|
@ -170,10 +170,6 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
|
||||||
openPasses(a, module)
|
openPasses(a, module)
|
||||||
if stream == nil:
|
if stream == nil:
|
||||||
let filename = fileIdx.toFullPathConsiderDirty
|
let filename = fileIdx.toFullPathConsiderDirty
|
||||||
if module.name.s == "-":
|
|
||||||
module.name.s = "stdinfile"
|
|
||||||
s = llStreamOpen(stdin)
|
|
||||||
else:
|
|
||||||
s = llStreamOpen(filename, fmRead)
|
s = llStreamOpen(filename, fmRead)
|
||||||
if s == nil:
|
if s == nil:
|
||||||
rawMessage(errCannotOpenFile, filename)
|
rawMessage(errCannotOpenFile, filename)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue