Documentation
¶
Overview ¶
Package types defines the core type system and Object interface for Nxlang
Index ¶
- Constants
- Variables
- func ToBool(obj Object) bool
- func ToByte(obj Object) (Byte, *Error)
- func ToChar(obj Object) (Char, *Error)
- func ToFloat(obj Object) (Float, *Error)
- func ToInt(obj Object) (Int, *Error)
- func ToUint(obj Object) (UInt, *Error)
- type Bool
- type BoundMethod
- type Byte
- type Char
- type Class
- type Error
- func NewCustomError(typeName string, message string, line int, column int, filename string) *Error
- func NewError(message string, line int, column int, filename string) *Error
- func NewErrorWithCode(message string, line int, column int, filename string, code string) *Error
- func NewErrorWithStack(message string, line int, column int, filename string, stack []StackFrame) *Error
- type Float
- type Function
- type Instance
- type Int
- type Interface
- type NativeFunction
- type Null
- type Object
- type Ref
- type StackFrame
- type String
- type SuperReference
- type TypeWrapper
- type UInt
- type Undefined
Constants ¶
const ( TypeUndefined = 0x00 TypeNull = 0x01 TypeBool = 0x02 TypeByte = 0x03 TypeChar = 0x04 TypeInt = 0x05 TypeUInt = 0x06 TypeFloat = 0x07 TypeString = 0x08 TypeArray = 0x10 TypeMap = 0x11 TypeOrderedMap = 0x12 TypeStack = 0x13 TypeQueue = 0x14 TypeSeq = 0x15 TypeFunction = 0x20 TypeClosure = 0x21 TypeNativeFunc = 0x22 TypeClass = 0x30 TypeObject = 0x31 TypeInterface = 0x32 TypeBoundMethod = 0x33 TypeSuperReference = 0x34 TypeRef = 0x35 // Object reference type TypeObjectType = 0x36 // Type object (for int, float, string etc. with static methods) TypeError = 0x40 TypeMutex = 0x50 TypeRWMutex = 0x51 TypeThread = 0x52 TypeFile = 0x60 TypeReader = 0x61 TypeWriter = 0x62 TypeStringBuilder = 0x63 TypeBytesBuffer = 0x64 )
Fixed type code constants (no iota for cross-version compatibility)
Variables ¶
var NullValue = &Null{}
var UndefinedValue = &Undefined{}
Functions ¶
Types ¶
type BoundMethod ¶
type BoundMethod struct {
Instance *Instance // The instance this method is bound to
Method *Function // The actual function to call
}
BoundMethod represents a method bound to a specific instance
func (*BoundMethod) Equals ¶
func (bm *BoundMethod) Equals(other Object) bool
func (*BoundMethod) ToStr ¶
func (bm *BoundMethod) ToStr() string
func (*BoundMethod) TypeCode ¶
func (bm *BoundMethod) TypeCode() uint8
func (*BoundMethod) TypeName ¶
func (bm *BoundMethod) TypeName() string
type Class ¶
type Class struct {
Name string
SuperClass *Class
Methods map[string]*Function // Map of method name to function
StaticFields map[string]Object // Static properties of the class
StaticMethods map[string]*Function // Map of static method name to function
}
Class represents a compiled class definition
type Error ¶
type Error struct {
Message string
Line int
Column int
Filename string
Code string // Code snippet where the error occurred
Stack []StackFrame // Call stack trace
ErrorType string // Custom error type name
Properties map[string]Object // Custom properties for user-defined errors
Methods map[string]*Function // Custom methods for user-defined errors
}
Error represents a runtime error in Nxlang
func NewCustomError ¶
NewCustomError creates a new custom Error instance with the given type name
func NewErrorWithCode ¶
NewErrorWithCode creates a new Error instance with code snippet
func NewErrorWithStack ¶
func NewErrorWithStack(message string, line int, column int, filename string, stack []StackFrame) *Error
NewErrorWithStack creates a new Error instance with call stack trace
type Function ¶
type Function struct {
Name string
NumLocals int
NumParameters int
IsVariadic bool
IsStatic bool // Whether this is a static method
AccessModifier uint8 // 0=public, 1=private, 2=protected
IsGetter bool // Whether this is a getter property
IsSetter bool // Whether this is a setter property
OwnerClass *Class // The class that owns this method (for methods only)
DefaultValues []int // Indices of default values in constant pool
Instructions []byte
ConstantPool []bytecode.Constant // Constant pool this function belongs to
}
Function represents a compiled function
type NativeFunction ¶
NativeFunction represents a native Go function callable from Nxlang
func (*NativeFunction) Equals ¶
func (nf *NativeFunction) Equals(other Object) bool
func (*NativeFunction) ToStr ¶
func (nf *NativeFunction) ToStr() string
func (*NativeFunction) TypeCode ¶
func (nf *NativeFunction) TypeCode() uint8
func (*NativeFunction) TypeName ¶
func (nf *NativeFunction) TypeName() string
type Object ¶
type Object interface {
// TypeCode returns the fixed type code for this object
TypeCode() uint8
// TypeName returns the human-readable type name
TypeName() string
// ToStr returns the string representation of the object
ToStr() string
// Equals checks if this object is equal to another object
Equals(other Object) bool
}
Object is the core interface implemented by all Nxlang values
type Ref ¶
type Ref struct {
Value Object // The value held by this reference (exported for VM access)
}
Ref represents a reference to any Nxlang object, allowing indirect modification
type StackFrame ¶
StackFrame represents a single frame in the call stack
type SuperReference ¶
type SuperReference struct {
Instance *Instance // The current instance
Super *Class // The superclass
}
SuperReference represents a reference to superclass with bound instance
func (*SuperReference) Equals ¶
func (sr *SuperReference) Equals(other Object) bool
func (*SuperReference) ToStr ¶
func (sr *SuperReference) ToStr() string
func (*SuperReference) TypeCode ¶
func (sr *SuperReference) TypeCode() uint8
func (*SuperReference) TypeName ¶
func (sr *SuperReference) TypeName() string
type TypeWrapper ¶
type TypeWrapper struct {
Name string // Type name (e.g., "int", "float")
ConvertFn func(args ...Object) Object // Conversion function when called as type(x)
StaticMethods map[string]*NativeFunction // Static methods accessible via type.method()
}
TypeWrapper represents a type with static methods (e.g., int, float, string) It can be called as a function (for type conversion) and have static methods accessed
func (*TypeWrapper) Call ¶
func (t *TypeWrapper) Call(args ...Object) Object
Call invokes the type conversion function
func (*TypeWrapper) Equals ¶
func (t *TypeWrapper) Equals(other Object) bool
func (*TypeWrapper) ToStr ¶
func (t *TypeWrapper) ToStr() string
func (*TypeWrapper) TypeCode ¶
func (t *TypeWrapper) TypeCode() uint8
func (*TypeWrapper) TypeName ¶
func (t *TypeWrapper) TypeName() string