thread var emulation should work again
This commit is contained in:
parent
ee98c76d2e
commit
5a838d3e06
4 changed files with 20 additions and 9 deletions
|
|
@ -792,11 +792,11 @@ proc getFileHeader(cfilenoext: string): PRope =
|
||||||
proc genMainProc(m: BModule) =
|
proc genMainProc(m: BModule) =
|
||||||
const
|
const
|
||||||
CommonMainBody =
|
CommonMainBody =
|
||||||
"#initStackBottom();$n" &
|
"$1" &
|
||||||
"\tnim__datInit();$n" &
|
"\tnim__datInit();$n" &
|
||||||
"\tsystemInit();$n" &
|
"\tsystemInit();$n" &
|
||||||
"$1" &
|
"$2" &
|
||||||
"$2"
|
"$3"
|
||||||
PosixNimMain =
|
PosixNimMain =
|
||||||
"int cmdCount;$n" &
|
"int cmdCount;$n" &
|
||||||
"char** cmdLine;$n" &
|
"char** cmdLine;$n" &
|
||||||
|
|
@ -845,8 +845,11 @@ proc genMainProc(m: BModule) =
|
||||||
nimMain = PosixNimMain
|
nimMain = PosixNimMain
|
||||||
otherMain = PosixCMain
|
otherMain = PosixCMain
|
||||||
if gBreakpoints != nil: discard cgsym(m, "dbgRegisterBreakpoint")
|
if gBreakpoints != nil: discard cgsym(m, "dbgRegisterBreakpoint")
|
||||||
|
|
||||||
|
let initStackBottomCall = if emulatedThreadVars(): "".toRope
|
||||||
|
else: ropecg(m, "\t#initStackBottom();$n")
|
||||||
inc(m.labels)
|
inc(m.labels)
|
||||||
appcg(m, m.s[cfsProcs], nimMain, [
|
appcg(m, m.s[cfsProcs], nimMain, [initStackBottomCall,
|
||||||
gBreakpoints, mainModInit, toRope(m.labels)])
|
gBreakpoints, mainModInit, toRope(m.labels)])
|
||||||
if optNoMain notin gGlobalOptions:
|
if optNoMain notin gGlobalOptions:
|
||||||
appcg(m, m.s[cfsProcs], otherMain, [])
|
appcg(m, m.s[cfsProcs], otherMain, [])
|
||||||
|
|
|
||||||
|
|
@ -632,6 +632,7 @@ else:
|
||||||
const stackIncreases = false
|
const stackIncreases = false
|
||||||
|
|
||||||
when not defined(useNimRtl):
|
when not defined(useNimRtl):
|
||||||
|
{.push stack_trace: off.}
|
||||||
proc setStackBottom(theStackBottom: pointer) =
|
proc setStackBottom(theStackBottom: pointer) =
|
||||||
#c_fprintf(c_stdout, "stack bottom: %p;\n", theStackBottom)
|
#c_fprintf(c_stdout, "stack bottom: %p;\n", theStackBottom)
|
||||||
# the first init must be the one that defines the stack bottom:
|
# the first init must be the one that defines the stack bottom:
|
||||||
|
|
@ -644,6 +645,7 @@ when not defined(useNimRtl):
|
||||||
gch.stackBottom = cast[pointer](min(a, b))
|
gch.stackBottom = cast[pointer](min(a, b))
|
||||||
else:
|
else:
|
||||||
gch.stackBottom = cast[pointer](max(a, b))
|
gch.stackBottom = cast[pointer](max(a, b))
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
proc stackSize(): int {.noinline.} =
|
proc stackSize(): int {.noinline.} =
|
||||||
var stackTop {.volatile.}: pointer
|
var stackTop {.volatile.}: pointer
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,10 @@ type
|
||||||
PLiteral = ref TLiteral
|
PLiteral = ref TLiteral
|
||||||
TLiteral = object of TExpr
|
TLiteral = object of TExpr
|
||||||
x: int
|
x: int
|
||||||
|
op1: string
|
||||||
TPlusExpr = object of TExpr
|
TPlusExpr = object of TExpr
|
||||||
a, b: ref TExpr
|
a, b: ref TExpr
|
||||||
|
op2: string
|
||||||
|
|
||||||
method eval(e: ref TExpr): int =
|
method eval(e: ref TExpr): int =
|
||||||
# override this base method
|
# override this base method
|
||||||
|
|
@ -27,16 +29,21 @@ proc newLit(x: int): ref TLiteral =
|
||||||
new(result)
|
new(result)
|
||||||
{.watchpoint: result.}
|
{.watchpoint: result.}
|
||||||
result.x = x
|
result.x = x
|
||||||
|
result.op1 = $getOccupiedMem()
|
||||||
|
|
||||||
proc newPlus(a, b: ref TExpr): ref TPlusExpr =
|
proc newPlus(a, b: ref TExpr): ref TPlusExpr =
|
||||||
new(result)
|
new(result)
|
||||||
{.watchpoint: result.}
|
{.watchpoint: result.}
|
||||||
result.a = a
|
result.a = a
|
||||||
result.b = b
|
result.b = b
|
||||||
|
result.op2 = $getOccupiedMem()
|
||||||
|
|
||||||
for i in 0..100_000:
|
for i in 0..100_000:
|
||||||
if eval(newPlus(newPlus(newLit(1), newLit(2)), newLit(4))) != 7:
|
var s: array[0..11, ref TExpr]
|
||||||
|
for j in 0..high(s):
|
||||||
|
s[j] = newPlus(newPlus(newLit(j), newLit(2)), newLit(4))
|
||||||
|
if eval(s[j]) != j+6:
|
||||||
quit "error: wrong result"
|
quit "error: wrong result"
|
||||||
if getOccupiedMem() > 3000_000: quit("still a leak!")
|
if getOccupiedMem() > 500_000: quit("still a leak!")
|
||||||
|
|
||||||
echo "no leak: ", getOccupiedMem()
|
echo "no leak: ", getOccupiedMem()
|
||||||
|
|
|
||||||
3
todo.txt
3
todo.txt
|
|
@ -2,8 +2,6 @@ version 0.9.0
|
||||||
=============
|
=============
|
||||||
|
|
||||||
Debug GC session:
|
Debug GC session:
|
||||||
- bug: stress testing basic method example (eval example)
|
|
||||||
without ``-d:release`` leaks memory?
|
|
||||||
- test sequence of closures; especially that the GC does not leak for those!
|
- test sequence of closures; especially that the GC does not leak for those!
|
||||||
|
|
||||||
New pragmas:
|
New pragmas:
|
||||||
|
|
@ -14,6 +12,7 @@ New pragmas:
|
||||||
- make templates hygienic by default: try to gensym() everything in the 'block'
|
- make templates hygienic by default: try to gensym() everything in the 'block'
|
||||||
of a template; find a better solution for gensym instead of `*ident`
|
of a template; find a better solution for gensym instead of `*ident`
|
||||||
- ``=`` should be overloadable; requires specialization for ``=``
|
- ``=`` should be overloadable; requires specialization for ``=``
|
||||||
|
- optimize genericAssign in the code generator
|
||||||
- fix remaining closure bugs:
|
- fix remaining closure bugs:
|
||||||
- make toplevel but in a scope vars local; make procs there inner procs
|
- make toplevel but in a scope vars local; make procs there inner procs
|
||||||
- fix evals.nim with closures
|
- fix evals.nim with closures
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue