summary refs log tree commit diff stats
path: root/compiler/nim.nim
blob: 80d9b66b69205c6c661787c242dcef6f235bcac7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-sty
#
#
#           The Nim Compiler
#        (c) Copyright 2015 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

when defined(gcc) and defined(windows):
  when defined(x86):
    {.link: "../icons/nim.res".}
  else:
    {.link: "../icons/nim_icon.o".}

when defined(amd64) and defined(windows) and defined(vcc):
  {.link: "../icons/nim-amd64-windows-vcc.res".}
when defined(i386) and defined(windows) and defined(vcc):
  {.link: "../icons/nim-i386-windows-vcc.res".}

import
  commands, options, msgs,
  extccomp, strutils, os, main, parseopt,
  idents, lineinfos, cmdlinehelper,
  pathutils

include nodejs

when hasTinyCBackend:
  import tccgen

when defined(profiler) or defined(memProfiler):
  {.hint: "Profiling support is turned on!".}
  import nimprof

proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
  var p = parseopt.initOptParser(cmd)
  var argsCount = 0

  config.commandLine.setLen 0
    # bugfix: otherwise, 
lass="w"> parseopt.next(p) case p.kind of cmdEnd: break of cmdLongOption, cmdShortOption: config.commandLine.add " " config.commandLine.addCmdPrefix p.kind config.commandLine.add p.key.quoteShell # quoteShell to be future proof if p.val.len > 0: config.commandLine.add ':' config.commandLine.add p.val.quoteShell if p.key == "": # `-` was passed to indicate main project is stdin p.key = "-" if processArgument(pass, p, argsCount, config): break else: processSwitch(pass, p, config) of cmdArgument: config.commandLine.add " " config.commandLine.add p.key.quoteShell if processArgument(pass, p, argsCount, config): break if pass == passCmd2: if {optRun, optWasNimscript} * config.globalOptions == {} and config.arguments.len > 0 and config.command.normalize notin ["run", "e", "r"]: rawMessage(config, errGenerated, errArgsNeedRunOption) proc handleCmdLine(cache: IdentCache; conf: ConfigRef) = let self = NimProg( supportsStdinFile: true, processCmdLine: processCmdLine, mainCommand: mainCommand ) self.initDefinesProg(conf, "nim_compiler") if paramCount() == 0: writeCommandLineUsage(conf) return self.processCmdLineAndProjectPath(conf) if not self.loadConfigsAndRunMainCommand(cache, conf): return if conf.hasHint(hintGCStats): echo(GC_getStatistics()) #echo(GC_getStatistics()) if conf.errorCounter != 0: return when hasTinyCBackend: if conf.cmd == cmdRun: tccgen.run(conf, conf.arguments) if optRun in conf.globalOptions: var ex = quoteShell conf.absOutFile if conf.cmd == cmdCompileToJS: execExternalProgram(conf, findNodeJs() & " " & ex & ' ' & conf.arguments) else: execExternalProgram(conf, ex & ' ' & conf.arguments) when declared(GC_setMaxPause): GC_setMaxPause 2_000 when compileOption("gc", "v2") or compileOption("gc", "refc"): # the new correct mark&sweet collector is too slow :-/ GC_disableMarkAndSweep() when not defined(selftest): let conf = newConfigRef() handleCmdLine(newIdentCache(), conf) when declared(GC_setMaxPause): echo GC_getStatistics() msgQuit(int8(conf.errorCounter > 0))