diff options
author | Araq <rumpf_a@web.de> | 2012-06-24 20:00:25 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-06-24 20:00:25 +0200 |
commit | ee98c76d2e43eb2ff8e9bae38ac66f84bba6fb28 (patch) | |
tree | 800cb42d7d4ae1522f17e1a664eb0585e322f2d4 | |
parent | 776920dc7140550706117cd3ab3ebaed91ea1748 (diff) | |
download | Nim-ee98c76d2e43eb2ff8e9bae38ac66f84bba6fb28.tar.gz |
bite the bullet and make 'initStackBottom' a compilerproc
-rwxr-xr-x | compiler/cgen.nim | 23 | ||||
-rwxr-xr-x | lib/system.nim | 10 | ||||
-rwxr-xr-x | lib/system/gc.nim | 1 |
3 files changed, 18 insertions, 16 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 51f538a97..9044b8f26 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -792,8 +792,9 @@ proc getFileHeader(cfilenoext: string): PRope = proc genMainProc(m: BModule) = const CommonMainBody = - " nim__datInit();$n" & - " systemInit();$n" & + "#initStackBottom();$n" & + "\tnim__datInit();$n" & + "\tsystemInit();$n" & "$1" & "$2" PosixNimMain = @@ -803,27 +804,27 @@ proc genMainProc(m: BModule) = "N_CDECL(void, NimMain)(void) {$n" & CommonMainBody & "}$n" PosixCMain = "int main(int argc, char** args, char** env) {$n" & - " cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" & - " NimMain();$n" & " return nim_program_result;$n" & "}$n" + "\tcmdLine = args;$n" & "\tcmdCount = argc;$n" & "\tgEnv = env;$n" & + "\tNimMain();$n" & "\treturn nim_program_result;$n" & "}$n" StandaloneCMain = "int main(void) {$n" & - " NimMain();$n" & - " return 0;$n" & "}$n" + "\tNimMain();$n" & + "\treturn 0;$n" & "}$n" WinNimMain = "N_CDECL(void, NimMain)(void) {$n" & CommonMainBody & "}$n" WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" & " HINSTANCE hPrevInstance, $n" & " LPSTR lpCmdLine, int nCmdShow) {$n" & - " NimMain();$n" & " return nim_program_result;$n" & "}$n" + "\tNimMain();$n" & "\treturn nim_program_result;$n" & "}$n" WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n" & CommonMainBody & "}$n" WinCDllMain = "BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" & - " LPVOID lpvReserved) {$n" & " NimMain();$n" & - " return 1;$n" & "}$n" + " LPVOID lpvReserved) {$n" & "\tNimMain();$n" & + "\treturn 1;$n" & "}$n" PosixNimDllMain = WinNimDllMain PosixCDllMain = "void NIM_POSIX_INIT NimMainInit(void) {$n" & - " NimMain();$n}$n" + "\tNimMain();$n}$n" var nimMain, otherMain: TFormatStr if platform.targetOS == osWindows and gGlobalOptions * {optGenGuiApp, optGenDynLib} != {}: @@ -847,7 +848,7 @@ proc genMainProc(m: BModule) = inc(m.labels) appcg(m, m.s[cfsProcs], nimMain, [ gBreakpoints, mainModInit, toRope(m.labels)]) - if not (optNoMain in gGlobalOptions): + if optNoMain notin gGlobalOptions: appcg(m, m.s[cfsProcs], otherMain, []) proc getInitName(m: PSym): PRope = diff --git a/lib/system.nim b/lib/system.nim index eb3531b60..8f5b5da5e 100755 --- a/lib/system.nim +++ b/lib/system.nim @@ -1680,11 +1680,11 @@ when not defined(EcmaScript) and not defined(NimrodVM): when not defined(boehmgc) and not defined(useMalloc): proc initAllocator() {.inline.} - when not defined(nogc): - proc initStackBottom() {.inline.} = - # WARNING: This is very fragile! An array size of 8 does not work on my - # Linux 64bit system. Very strange, but we are at the will of GCC's - # optimizer... + proc initStackBottom() {.inline, compilerproc.} = + # WARNING: This is very fragile! An array size of 8 does not work on my + # Linux 64bit system. Very strange, but we are at the will of GCC's + # optimizer... + when defined(setStackBottom): var locals {.volatile.}: pointer locals = addr(locals) setStackBottom(locals) diff --git a/lib/system/gc.nim b/lib/system/gc.nim index ea30754a6..d2f756cd7 100755 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -639,6 +639,7 @@ when not defined(useNimRtl): else: var a = cast[TAddress](theStackBottom) # and not PageMask - PageSize*2 var b = cast[TAddress](gch.stackBottom) + #c_fprintf(c_stdout, "old: %p new: %p;\n",gch.stackBottom,theStackBottom) when stackIncreases: gch.stackBottom = cast[pointer](min(a, b)) else: |