With a sufficiently ugly hack, all things are possible... 
    
    
    import strutils
    
    static:
      
      proc getNimCompilerCmdLine(): string =
        return staticRead("/proc/self/cmdline").replace('\0', ' ')
      
      const nimCompilerCmdLine = getNimCompilerCmdLine()
      
      proc getNimCompilerBackend(): string =
        result = nimCompilerCmdLine.split(' ')[1].toLowerAscii()
        if result == "compile": result = "c"
      
      proc forceNimCompilerBackend(newBackend: string) =
        let currentBackend = getNimCompilerBackend()
        if currentBackend == newBackend.toLowerAscii(): return
        var splitRestartCmdLine = nimCompilerCmdLine.split(' ')
        splitRestartCmdLine[1] = newBackend & " --forceBuild"
        let restartCmdLine = splitRestartCmdLine.join(" ")
        echo "Restarting the compiler with: `" & restartCmdLine & "`"
        echo '{'
        let restartEx = gorgeEx(restartCmdLine)
        echo restartEx.output
        echo '}'
        quit restartEx.exitCode
      
      forceNimCompilerBackend("js")
    
    
    echo "This is printed at run-time."
    
    

Reply via email to