From dca5508d13249c261d322b499098439b4fc294a9 Mon Sep 17 00:00:00 2001 From: def Date: Sun, 22 Feb 2015 23:03:46 +0100 Subject: [PATCH 1/3] Make compiler read files from stdin Special "-" file as stdin. --- compiler/modules.nim | 2 +- compiler/passes.nim | 6 +++++- compiler/service.nim | 7 ++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/modules.nim b/compiler/modules.nim index db05ccc6cb..a2b739efc7 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -116,7 +116,7 @@ proc newModule(fileIdx: int32): PSym = result.kind = skModule let filename = fileIdx.toFullPath result.name = getIdent(splitFile(filename).name) - if not isNimIdentifier(result.name.s): + if result.name.s != "-" and not isNimIdentifier(result.name.s): rawMessage(errInvalidModuleName, result.name.s) result.info = newLineInfo(fileIdx, 1, 1) diff --git a/compiler/passes.nim b/compiler/passes.nim index f9c3d75f94..1491165021 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -170,7 +170,11 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) = openPasses(a, module) if stream == nil: let filename = fileIdx.toFullPathConsiderDirty - s = llStreamOpen(filename, fmRead) + if module.name.s == "-": + module.name.s = "stdin" + s = llStreamOpen(stdin) + else: + s = llStreamOpen(filename, fmRead) if s == nil: rawMessage(errCannotOpenFile, filename) return diff --git a/compiler/service.nim b/compiler/service.nim index 1d51ef2a10..7cb9d7d297 100644 --- a/compiler/service.nim +++ b/compiler/service.nim @@ -33,7 +33,12 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string) = parseopt.next(p) case p.kind of cmdEnd: break - of cmdLongoption, cmdShortOption: processSwitch(pass, p) + of cmdLongoption, cmdShortOption: + if p.key == " ": + p.key = "-" + if processArgument(pass, p, argsCount): break + else: + processSwitch(pass, p) of cmdArgument: if processArgument(pass, p, argsCount): break if pass == passCmd2: From 6894ac7c0a91c56b41d2eee57551a697c48a1d63 Mon Sep 17 00:00:00 2001 From: def Date: Sat, 28 Feb 2015 22:59:59 +0100 Subject: [PATCH 2/3] Rename stdin fake module name to stdinFile --- compiler/passes.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/passes.nim b/compiler/passes.nim index 1491165021..f8cbceca5b 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -171,7 +171,7 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) = if stream == nil: let filename = fileIdx.toFullPathConsiderDirty if module.name.s == "-": - module.name.s = "stdin" + module.name.s = "stdinFile" s = llStreamOpen(stdin) else: s = llStreamOpen(filename, fmRead) From c37e8035ea7915c1ebe6ba8d5872673dff27ab2c Mon Sep 17 00:00:00 2001 From: def Date: Sat, 28 Feb 2015 23:35:35 +0100 Subject: [PATCH 3/3] When compiling from stdin write binary to stdinfile --- compiler/main.nim | 2 +- compiler/nim.nim | 2 ++ compiler/passes.nim | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/main.nim b/compiler/main.nim index 42a782c027..f7592a891d 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -62,7 +62,7 @@ proc commandCompileToC = compileProject() cgenWriteModules() if gCmd != cmdRun: - extccomp.callCCompiler(changeFileExt(gProjectFull, "")) + extccomp.callCCompiler(if gProjectName == "-": "stdinfile" else: changeFileExt(gProjectFull, "")) if isServing: # caas will keep track only of the compilation commands diff --git a/compiler/nim.nim b/compiler/nim.nim index 215f1986ee..b8ba2c6da9 100644 --- a/compiler/nim.nim +++ b/compiler/nim.nim @@ -61,6 +61,8 @@ proc handleCmdLine() = if gCmd == cmdRun: tccgen.run(commands.arguments) if optRun in gGlobalOptions: + if gProjectName == "-": + gProjectFull = "stdinfile" if gCmd == cmdCompileToJS: var ex: string if options.outFile.len > 0: diff --git a/compiler/passes.nim b/compiler/passes.nim index f8cbceca5b..96088bd880 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -171,7 +171,7 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) = if stream == nil: let filename = fileIdx.toFullPathConsiderDirty if module.name.s == "-": - module.name.s = "stdinFile" + module.name.s = "stdinfile" s = llStreamOpen(stdin) else: s = llStreamOpen(filename, fmRead)