compile functions
This commit is contained in:
@@ -5,22 +5,24 @@ import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"monkey/ast"
|
||||
"monkey/code"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type ObjectType string
|
||||
|
||||
const (
|
||||
INTEGER_OBJ = "INTEGER"
|
||||
BOOLEAN_OBJ = "BOOLEAN"
|
||||
NULL_OBJ = "NULL"
|
||||
RETURN_VALUE_OBJ = "RETURN_VALUE"
|
||||
ERROR_OBJ = "ERROR"
|
||||
FUNCTION_OBJ = "FUNCTION"
|
||||
STRING_OBJ = "STRING"
|
||||
BUILTIN_OBJ = "BUILTIN"
|
||||
ARRAY_OBJ = "ARRAY"
|
||||
HASH_OBJ = "HASH"
|
||||
INTEGER_OBJ = "INTEGER"
|
||||
BOOLEAN_OBJ = "BOOLEAN"
|
||||
NULL_OBJ = "NULL"
|
||||
RETURN_VALUE_OBJ = "RETURN_VALUE"
|
||||
ERROR_OBJ = "ERROR"
|
||||
FUNCTION_OBJ = "FUNCTION"
|
||||
STRING_OBJ = "STRING"
|
||||
BUILTIN_OBJ = "BUILTIN"
|
||||
ARRAY_OBJ = "ARRAY"
|
||||
HASH_OBJ = "HASH"
|
||||
COMPILED_FUNCTION_OBJ = "COMPILED_FUNCTION_OBJ "
|
||||
)
|
||||
|
||||
type Object interface {
|
||||
@@ -32,6 +34,10 @@ type Integer struct {
|
||||
Value int64
|
||||
}
|
||||
|
||||
type CompiledFunction struct {
|
||||
Instructions code.Instructions
|
||||
}
|
||||
|
||||
func (i *Integer) Type() ObjectType {
|
||||
return INTEGER_OBJ
|
||||
}
|
||||
@@ -219,3 +225,11 @@ func (h *Hash) Inspect() string {
|
||||
|
||||
return out.String()
|
||||
}
|
||||
|
||||
func (cf *CompiledFunction) Type() ObjectType {
|
||||
return COMPILED_FUNCTION_OBJ
|
||||
}
|
||||
|
||||
func (cf *CompiledFunction) Inspect() string {
|
||||
return fmt.Sprintf("CompiledFunction[%p]", cf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user