55 lines
841 B
Go
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()
|
|
}
|