Files
monkey/internal/object/closure.go
Chuck Smith 12d43c9835
Some checks failed
Publish Image / publish (push) Waiting to run
Test / build (push) Waiting to run
Build / build (push) Has been cancelled
Refactor Type to be an int
2024-03-29 11:01:15 -04:00

50 lines
760 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) String() string {
return cf.Inspect()
}
type Closure struct {
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()
}