Temporary fix for not closing over function arguments
This commit is contained in:
parent
13cc641e7b
commit
39d1eab234
|
@ -450,9 +450,13 @@ proc detectClosureVariable(self: Compiler, name: var Name, depth: int = self.sco
|
||||||
if self.closedOver.len() >= 16777216:
|
if self.closedOver.len() >= 16777216:
|
||||||
self.error("too many consecutive closed-over variables (max is 16777215)")
|
self.error("too many consecutive closed-over variables (max is 16777215)")
|
||||||
name.isClosedOver = true
|
name.isClosedOver = true
|
||||||
self.chunk.code[name.codePos] = StoreClosure.uint8()
|
if not name.isFunctionArgument:
|
||||||
for i, b in self.closedOver.high().toTriple():
|
# We handle closed-over function arguments later
|
||||||
self.chunk.code[name.codePos + i + 1] = b
|
self.chunk.code[name.codePos] = StoreClosure.uint8()
|
||||||
|
for i, b in self.closedOver.high().toTriple():
|
||||||
|
self.chunk.code[name.codePos + i + 1] = b
|
||||||
|
else:
|
||||||
|
self.error("it is currently not possible to close over function arguments")
|
||||||
|
|
||||||
|
|
||||||
proc compareTypes(self: Compiler, a, b: Type): bool =
|
proc compareTypes(self: Compiler, a, b: Type): bool =
|
||||||
|
@ -1006,7 +1010,7 @@ proc generateCall(self: Compiler, fn: Name, args: seq[Expression]) =
|
||||||
for argument in reversed(args):
|
for argument in reversed(args):
|
||||||
# We pass the arguments in reverse
|
# We pass the arguments in reverse
|
||||||
# because of how stack semantics
|
# because of how stack semantics
|
||||||
# work. They'll be fixed at runtime
|
# work. They'll be fixed at runtime
|
||||||
self.expression(argument)
|
self.expression(argument)
|
||||||
# Creates a new call frame and jumps
|
# Creates a new call frame and jumps
|
||||||
# to the function's first instruction
|
# to the function's first instruction
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn makeClosure(n: int): fn: int {
|
fn makeClosure(n: int): fn: int {
|
||||||
var n = n;
|
# let n = n; # Workaround
|
||||||
fn inner: int {
|
fn inner: int {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue