You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Gift: cover {
msg: Stringpad: Int
}
please: func (f: Func) { f() }
main: func {
g:= ("One", 0)
please(||
g = ("Two", 0)
please(||
g = ("Three", 0)
)
)
g msg println()
}
Expected behaviour
Print "Three"
Current behavior
Print "Two" and writes to a random memory location.. which is really really bad. C compiler only emits a warning (Gift* vs Gift**)
Explanation
Each closure is a struct of thunk (address of the actual C function) and context (optional pointer to context struct).
When calling closures, context needs to be created (on the stack). If a variable is assigned to in a closure, it's captured "by reference", which means we pass the address to the closure instead of the value.
Currently, when creating context, variables that are captured byref are always passed with &someVariable, even if they're in a closure that has itself captured them byref. That means the inner closure gets the address of the pointer to the address of the actual variable. Hence the random memory write.
The text was updated successfully, but these errors were encountered:
Hey @davidhesselbom! Hmm no, looks like a different issue but it shouldn't be a hard fix.
Sorry about being the worst maintainer ever in the history of open source projects btw, just doing some selfish bugfixes because our engine for Jaakan is written in ooc.
Sample:
Expected behaviour
Print "Three"
Current behavior
Print "Two" and writes to a random memory location.. which is really really bad. C compiler only emits a warning (
Gift*
vsGift**
)Explanation
Each closure is a struct of
thunk
(address of the actual C function) andcontext
(optional pointer to context struct).When calling closures,
context
needs to be created (on the stack). If a variable is assigned to in a closure, it's captured "by reference", which means we pass the address to the closure instead of the value.Currently, when creating context, variables that are captured byref are always passed with
&someVariable
, even if they're in a closure that has itself captured them byref. That means the inner closure gets the address of the pointer to the address of the actual variable. Hence the random memory write.The text was updated successfully, but these errors were encountered: