bite the bullet and make 'initStackBottom' a compilerproc
This commit is contained in:
parent
776920dc71
commit
ee98c76d2e
3 changed files with 18 additions and 16 deletions
|
|
@ -792,8 +792,9 @@ proc getFileHeader(cfilenoext: string): PRope =
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
const
|
const
|
||||||
CommonMainBody =
|
CommonMainBody =
|
||||||
" nim__datInit();$n" &
|
"#initStackBottom();$n" &
|
||||||
" systemInit();$n" &
|
"\tnim__datInit();$n" &
|
||||||
|
"\tsystemInit();$n" &
|
||||||
"$1" &
|
"$1" &
|
||||||
"$2"
|
"$2"
|
||||||
PosixNimMain =
|
PosixNimMain =
|
||||||
|
|
@ -803,27 +804,27 @@ proc genMainProc(m: BModule) =
|
||||||
"N_CDECL(void, NimMain)(void) {$n" &
|
"N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
PosixCMain = "int main(int argc, char** args, char** env) {$n" &
|
||||||
" cmdLine = args;$n" & " cmdCount = argc;$n" & " gEnv = env;$n" &
|
"\tcmdLine = args;$n" & "\tcmdCount = argc;$n" & "\tgEnv = env;$n" &
|
||||||
" NimMain();$n" & " return nim_program_result;$n" & "}$n"
|
"\tNimMain();$n" & "\treturn nim_program_result;$n" & "}$n"
|
||||||
StandaloneCMain = "int main(void) {$n" &
|
StandaloneCMain = "int main(void) {$n" &
|
||||||
" NimMain();$n" &
|
"\tNimMain();$n" &
|
||||||
" return 0;$n" & "}$n"
|
"\treturn 0;$n" & "}$n"
|
||||||
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
WinNimMain = "N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
WinCMain = "N_STDCALL(int, WinMain)(HINSTANCE hCurInstance, $n" &
|
||||||
" HINSTANCE hPrevInstance, $n" &
|
" HINSTANCE hPrevInstance, $n" &
|
||||||
" LPSTR lpCmdLine, int nCmdShow) {$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" &
|
WinNimDllMain = "N_LIB_EXPORT N_CDECL(void, NimMain)(void) {$n" &
|
||||||
CommonMainBody & "}$n"
|
CommonMainBody & "}$n"
|
||||||
WinCDllMain =
|
WinCDllMain =
|
||||||
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" &
|
"BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, $n" &
|
||||||
" LPVOID lpvReserved) {$n" & " NimMain();$n" &
|
" LPVOID lpvReserved) {$n" & "\tNimMain();$n" &
|
||||||
" return 1;$n" & "}$n"
|
"\treturn 1;$n" & "}$n"
|
||||||
PosixNimDllMain = WinNimDllMain
|
PosixNimDllMain = WinNimDllMain
|
||||||
PosixCDllMain =
|
PosixCDllMain =
|
||||||
"void NIM_POSIX_INIT NimMainInit(void) {$n" &
|
"void NIM_POSIX_INIT NimMainInit(void) {$n" &
|
||||||
" NimMain();$n}$n"
|
"\tNimMain();$n}$n"
|
||||||
var nimMain, otherMain: TFormatStr
|
var nimMain, otherMain: TFormatStr
|
||||||
if platform.targetOS == osWindows and
|
if platform.targetOS == osWindows and
|
||||||
gGlobalOptions * {optGenGuiApp, optGenDynLib} != {}:
|
gGlobalOptions * {optGenGuiApp, optGenDynLib} != {}:
|
||||||
|
|
@ -847,7 +848,7 @@ proc genMainProc(m: BModule) =
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
appcg(m, m.s[cfsProcs], nimMain, [
|
appcg(m, m.s[cfsProcs], nimMain, [
|
||||||
gBreakpoints, mainModInit, toRope(m.labels)])
|
gBreakpoints, mainModInit, toRope(m.labels)])
|
||||||
if not (optNoMain in gGlobalOptions):
|
if optNoMain notin gGlobalOptions:
|
||||||
appcg(m, m.s[cfsProcs], otherMain, [])
|
appcg(m, m.s[cfsProcs], otherMain, [])
|
||||||
|
|
||||||
proc getInitName(m: PSym): PRope =
|
proc getInitName(m: PSym): PRope =
|
||||||
|
|
|
||||||
|
|
@ -1680,11 +1680,11 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
||||||
when not defined(boehmgc) and not defined(useMalloc):
|
when not defined(boehmgc) and not defined(useMalloc):
|
||||||
proc initAllocator() {.inline.}
|
proc initAllocator() {.inline.}
|
||||||
|
|
||||||
when not defined(nogc):
|
proc initStackBottom() {.inline, compilerproc.} =
|
||||||
proc initStackBottom() {.inline.} =
|
|
||||||
# WARNING: This is very fragile! An array size of 8 does not work on my
|
# 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
|
# Linux 64bit system. Very strange, but we are at the will of GCC's
|
||||||
# optimizer...
|
# optimizer...
|
||||||
|
when defined(setStackBottom):
|
||||||
var locals {.volatile.}: pointer
|
var locals {.volatile.}: pointer
|
||||||
locals = addr(locals)
|
locals = addr(locals)
|
||||||
setStackBottom(locals)
|
setStackBottom(locals)
|
||||||
|
|
|
||||||
|
|
@ -639,6 +639,7 @@ when not defined(useNimRtl):
|
||||||
else:
|
else:
|
||||||
var a = cast[TAddress](theStackBottom) # and not PageMask - PageSize*2
|
var a = cast[TAddress](theStackBottom) # and not PageMask - PageSize*2
|
||||||
var b = cast[TAddress](gch.stackBottom)
|
var b = cast[TAddress](gch.stackBottom)
|
||||||
|
#c_fprintf(c_stdout, "old: %p new: %p;\n",gch.stackBottom,theStackBottom)
|
||||||
when stackIncreases:
|
when stackIncreases:
|
||||||
gch.stackBottom = cast[pointer](min(a, b))
|
gch.stackBottom = cast[pointer](min(a, b))
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue