functions now capture variables :D

This commit is contained in:
Neemek 2026-07-09 23:21:41 +02:00
parent 43e450c207
commit d315a53fbd
Signed by: neemek
GPG key ID: 84FFE4D7D40AB25E
5 changed files with 49 additions and 11 deletions

View file

@ -587,6 +587,7 @@ func (c *Compiler) compile(tree Node) error {
n.yield,
c.Chunk,
nil,
nil,
}
// restore old chunk and ip
@ -958,6 +959,13 @@ func (c *Compiler) deduceSignature(tree Node) (TypeSignature, error) {
}
return nil, c.error(fmt.Sprintf("unimplemented result type deduction for unary %s", n.UnaryOperation), n)
case BlockNodeType:
n := tree.(*BlockNode)
if len(n.statements) == 0 {
return &NilSignature{}, nil
}
return c.deduceSignature(n.statements[len(n.statements)-1])
default:
return nil, c.error(fmt.Sprintf("impossible to deduce signature of %s", tree.Type()), tree)
}