compile functions
Some checks failed
Build / build (push) Failing after 1m57s
Test / build (push) Successful in 2m15s

This commit is contained in:
Chuck Smith
2024-02-28 16:57:01 -05:00
parent 4185926e3e
commit e56fb40f83
5 changed files with 320 additions and 34 deletions

View File

@@ -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)
}