Files
monkey/internal/object/closure.go
Chuck Smith 07fd82b261
Some checks failed
Build / build (push) Successful in 10m29s
Publish Image / publish (push) Failing after 31s
Test / build (push) Failing after 6m34s
optimizations
2024-04-02 14:08:08 -04:00

55 lines
841 B
Go

package object
import (
"fmt"
"monkey/internal/code"
)
type CompiledFunction struct {
Instructions code.Instructions
NumLocals int
NumParameters int
}
func (cf *CompiledFunction) Bool() bool {
return true
}
func (cf *CompiledFunction) Type() Type {
return CFunctionType
}
func (cf *CompiledFunction) Inspect() string {
return fmt.Sprintf("CompiledFunction[%p]", cf)
}
func (cf CompiledFunction) Compare(other Object) int {
return -1
}
func (cf *CompiledFunction) String() string {
return cf.Inspect()
}
type Closure struct {
BaseObject
Fn *CompiledFunction
Free []Object
}
func (c *Closure) Bool() bool {
return true
}
func (c *Closure) Type() Type {
return ClosureType
}
func (c *Closure) Inspect() string {
return fmt.Sprintf("Closure[%p]", c)
}
func (c *Closure) String() string {
return c.Inspect()
}