Files
monkey/object/closure.go
Chuck Smith 6d234099d1
Some checks failed
Build / build (push) Successful in 11m16s
Test / build (push) Failing after 17m0s
type checking and error handling for builtins improved.
2024-03-25 16:18:08 -04:00

50 lines
771 B
Go

package object
import (
"fmt"
"monkey/code"
)
type CompiledFunction struct {
Instructions code.Instructions
NumLocals int
NumParameters int
}
func (cf *CompiledFunction) Bool() bool {
return true
}
func (cf *CompiledFunction) Type() ObjectType {
return COMPILED_FUNCTION_OBJ
}
func (cf *CompiledFunction) Inspect() string {
return fmt.Sprintf("CompiledFunction[%p]", cf)
}
func (cf *CompiledFunction) String() string {
return cf.Inspect()
}
type Closure struct {
Fn *CompiledFunction
Free []Object
}
func (c *Closure) Bool() bool {
return true
}
func (c *Closure) Type() ObjectType {
return CLOSURE_OBJ
}
func (c *Closure) Inspect() string {
return fmt.Sprintf("Closure[%p]", c)
}
func (c *Closure) String() string {
return c.Inspect()
}