object

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2025 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

object/object.go

src/object/error_trace.go

Index

Constants

View Source
const (
	INTEGER_OBJ      = "INTEGER"
	FLOAT_OBJ        = "FLOAT"
	BOOLEAN_OBJ      = "BOOLEAN"
	NONE_OBJ         = "NONE"
	RETURN_VALUE_OBJ = "RETURN_VALUE"
	ERROR_OBJ        = "ERROR"
	FUNCTION_OBJ     = "FUNCTION"
	STRING_OBJ       = "STRING"
	ARRAY_OBJ        = "ARRAY"
	BUILTIN_OBJ      = "BUILTIN"
	HASH_OBJ         = "HASH"
	TUPLE_OBJ        = "TUPLE"
	GRIMOIRE_OBJ     = "GRIMOIRE"
	INSTANCE_OBJ     = "INSTANCE"
	NAMESPACE_OBJ    = "NAMESPACE"
)
View Source
const (
	CUSTOM_ERROR_OBJ = "USER DEFINED ERROR"
)

Variables

View Source
var (
	STOP = &Stop{}
	SKIP = &Skip{}
)
View Source
var NONE = &None{}

Functions

This section is empty.

Types

type Array

type Array struct {
	Elements []Object
}

func (*Array) Inspect

func (ao *Array) Inspect() string

func (*Array) Type

func (ao *Array) Type() ObjectType

type Boolean

type Boolean struct {
	Value bool
}

func (*Boolean) HashKey

func (b *Boolean) HashKey() HashKey

func (*Boolean) Inspect

func (b *Boolean) Inspect() string

func (*Boolean) Type

func (b *Boolean) Type() ObjectType

type BoundMethod

type BoundMethod struct {
	Instance *Instance
	Method   *Function
	Name     string
}

func (*BoundMethod) Inspect

func (bm *BoundMethod) Inspect() string

func (*BoundMethod) Type

func (bm *BoundMethod) Type() ObjectType

type Builtin

type Builtin struct {
	Fn BuiltinFunction
}

func (*Builtin) Inspect

func (b *Builtin) Inspect() string

func (*Builtin) Type

func (b *Builtin) Type() ObjectType

type BuiltinFunction

type BuiltinFunction func(args ...Object) Object

type CustomError

type CustomError struct {
	Name      string            // Name of the error type (e.g., "ValueError")
	Message   string            // Error message
	Details   map[string]Object // Additional details (optional)
	ErrorType *Grimoire         // The grimoire (class) this error belongs to (renamed to avoid conflict)
	Instance  *Instance         // Instance of the error (if applicable)
}

CustomError represents a user-defined error in the language.

func NewCustomError

func NewCustomError(name, message string) *CustomError

NewCustomError creates a new CustomError object.

func (*CustomError) AddDetail

func (ce *CustomError) AddDetail(key string, value Object)

AddDetail adds a key-value pair to the error's details.

func (*CustomError) Inspect

func (ce *CustomError) Inspect() string

Inspect returns a string representation of the error (implements the Object interface).

func (*CustomError) Type

func (ce *CustomError) Type() ObjectType

Type returns the type of the object (implements the Object interface).

type Environment

type Environment struct {
	// contains filtered or unexported fields
}

environment.go

func NewEnclosedEnvironment

func NewEnclosedEnvironment(outer *Environment) *Environment

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Clone added in v0.1.6

func (e *Environment) Clone() *Environment

Clone creates a deep copy of the environment to prevent shared references

func (*Environment) Get

func (e *Environment) Get(name string) (Object, bool)

func (*Environment) GetDebugConfig added in v0.1.6

func (e *Environment) GetDebugConfig() *debug.Config

GetDebugConfig returns the debug configuration

func (*Environment) GetNames

func (e *Environment) GetNames() []string

func (*Environment) GetOuter

func (e *Environment) GetOuter() *Environment

func (*Environment) Set

func (e *Environment) Set(name string, val Object) Object

func (*Environment) SetDebugConfig added in v0.1.6

func (e *Environment) SetDebugConfig(config *debug.Config)

SetDebugConfig sets the debug configuration for this environment

type Error

type Error struct {
	Message string
}

func (*Error) Inspect

func (e *Error) Inspect() string

func (*Error) Type

func (e *Error) Type() ObjectType

type ErrorWithTrace added in v0.1.6

type ErrorWithTrace struct {
	ErrorType     ObjectType // Changed from Type to ErrorType to avoid conflict
	Message       string
	Position      SourcePosition
	Cause         *ErrorWithTrace
	Stack         []StackTraceEntry
	CustomDetails map[string]Object
}

ErrorWithTrace extends the basic error with stack trace and source position information

func (*ErrorWithTrace) AddDetail added in v0.1.6

func (e *ErrorWithTrace) AddDetail(key string, value Object) *ErrorWithTrace

func (*ErrorWithTrace) AddStackEntry added in v0.1.6

func (e *ErrorWithTrace) AddStackEntry(functionName string, pos SourcePosition) *ErrorWithTrace

func (*ErrorWithTrace) Inspect added in v0.1.6

func (e *ErrorWithTrace) Inspect() string

func (*ErrorWithTrace) String added in v0.1.6

func (e *ErrorWithTrace) String() string

Optional, so fmt.Println(err) prints same view.

func (*ErrorWithTrace) Type added in v0.1.6

func (e *ErrorWithTrace) Type() ObjectType

To satisfy the Object interface

func (*ErrorWithTrace) WithCause added in v0.1.6

func (e *ErrorWithTrace) WithCause(cause *ErrorWithTrace) *ErrorWithTrace

Added setter methods for fluent API

type Float

type Float struct {
	Value float64
}

func (*Float) Inspect

func (f *Float) Inspect() string

func (*Float) Type

func (f *Float) Type() ObjectType

type Function

type Function struct {
	// Parameters holds function parameters, either simple identifiers or full Parameter nodes
	Parameters  []ast.Expression
	Body        *ast.BlockStatement
	Env         *Environment
	IsAbstract  bool
	IsPrivate   bool
	IsProtected bool
}

func (*Function) Inspect

func (f *Function) Inspect() string

func (*Function) Type

func (f *Function) Type() ObjectType

type Grimoire added in v0.1.6

type Grimoire struct {
	Name       string
	Methods    map[string]*Function
	InitMethod *Function
	Inherits   *Grimoire
	Env        *Environment // Add environment to store the grimoire's scope
	IsArcane   bool
}

Update Object (object.go)

func (*Grimoire) Inspect added in v0.1.6

func (s *Grimoire) Inspect() string

func (*Grimoire) Type added in v0.1.6

func (s *Grimoire) Type() ObjectType

type Hash

type Hash struct {
	Pairs map[HashKey]HashPair
}

func (*Hash) Inspect

func (h *Hash) Inspect() string

func (*Hash) Type

func (h *Hash) Type() ObjectType

type HashKey

type HashKey struct {
	Type  ObjectType
	Value uint64
}

type HashPair

type HashPair struct {
	Key   Object
	Value Object
}

type Hashable

type Hashable interface {
	HashKey() HashKey
}

type Instance

type Instance struct {
	Grimoire *Grimoire
	Env      *Environment
}

Ensure Instance type implements Object

func (*Instance) Inspect

func (i *Instance) Inspect() string

func (*Instance) Type

func (i *Instance) Type() ObjectType

type Integer

type Integer struct {
	Value int64
}

func (*Integer) HashKey

func (i *Integer) HashKey() HashKey

func (*Integer) Inspect

func (i *Integer) Inspect() string

func (*Integer) Type

func (i *Integer) Type() ObjectType

type Namespace

type Namespace struct {
	Env *Environment // Holds all exported members of the imported module
}

func (*Namespace) Inspect

func (n *Namespace) Inspect() string

func (*Namespace) Type

func (n *Namespace) Type() ObjectType

type None

type None struct {
	Value string
}

func (*None) Inspect

func (n *None) Inspect() string

func (*None) Type

func (n *None) Type() ObjectType

type Object

type Object interface {
	Type() ObjectType
	Inspect() string
}

type ObjectType

type ObjectType string

type ReturnValue

type ReturnValue struct {
	Value Object
}

func (*ReturnValue) Inspect

func (rv *ReturnValue) Inspect() string

func (*ReturnValue) Type

func (rv *ReturnValue) Type() ObjectType

type Skip

type Skip struct{}

func (*Skip) Inspect

func (s *Skip) Inspect() string

func (*Skip) Type

func (s *Skip) Type() ObjectType

type SourcePosition added in v0.1.6

type SourcePosition struct {
	Filename string
	Line     int
	Column   int
}

SourcePosition tracks the location of code in source files

func (SourcePosition) String added in v0.1.6

func (sp SourcePosition) String() string

type StackTraceEntry added in v0.1.6

type StackTraceEntry struct {
	FunctionName string
	Position     SourcePosition
}

StackTraceEntry represents a single frame in the error stack trace

func (StackTraceEntry) String added in v0.1.6

func (ste StackTraceEntry) String() string

type Stop

type Stop struct{}

func (*Stop) Inspect

func (s *Stop) Inspect() string

func (*Stop) Type

func (s *Stop) Type() ObjectType

type String

type String struct {
	Value string
}

func (*String) HashKey

func (s *String) HashKey() HashKey

func (*String) Inspect

func (s *String) Inspect() string

func (*String) Type

func (s *String) Type() ObjectType

type Tuple

type Tuple struct {
	Elements []Object
}

func (*Tuple) Inspect

func (t *Tuple) Inspect() string

func (*Tuple) Type

func (t *Tuple) Type() ObjectType

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL