Documentation
¶
Overview ¶
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Copyright 2025 The Hulo Authors. All rights reserved. Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.
Index ¶
- Variables
- func Entries(t Type) (map[string]Type, error)
- func ExampleAdvancedConstraintCombination()
- func ExampleCompositeConstraint()
- func ExampleConstrainedGeneric()
- func ExampleConstraintIntegration()
- func ExampleEnumUsage()
- func ExampleGenericTraitConstraintInheritance()
- func ExampleServiceTrait()
- func ExampleStaticMethodsAndInheritance()
- func ExampleTraitGenericInheritanceIntegration()
- func ExampleUnionConstraint()
- func ImplementsTrait(t Type, traitName string) bool
- func Keys(t Type) ([]string, error)
- type ASTConverter
- func (c *ASTConverter) ConvertField(field *ast.Field) (*Field, error)
- func (c *ASTConverter) ConvertModifiers(modifiers []ast.Modifier) []FieldModifier
- func (c *ASTConverter) ConvertParameter(param *ast.Parameter) (*Parameter, error)
- func (c *ASTConverter) ConvertType(node ast.Node) (Type, error)
- func (c *ASTConverter) ConvertValue(node ast.Node) (Value, error)
- type ArrayPattern
- type ArrayType
- type ArrayValue
- type BoolType
- type BoolValue
- type BuiltinFunction
- type ClassConstructor
- func (cc *ClassConstructor) Call(args ...Value) Value
- func (cc *ClassConstructor) In(i int) Type
- func (cc *ClassConstructor) IsNamed() bool
- func (cc *ClassConstructor) Match(args []Value) bool
- func (cc *ClassConstructor) Name() string
- func (cc *ClassConstructor) NumIn() int
- func (cc *ClassConstructor) Signature() []Type
- type ClassInstance
- func (ci *ClassInstance) CallMethod(name string, args []Value, namedArgs map[string]Value) (Value, error)
- func (ci *ClassInstance) GetField(name string) Value
- func (ci *ClassInstance) GetMethod(name string) Method
- func (ci *ClassInstance) Interface() any
- func (ci *ClassInstance) SetField(name string, value Value)
- func (ci *ClassInstance) Text() string
- func (ci *ClassInstance) Type() Type
- type ClassType
- func (ct *ClassType) AddCompositeConstraint(typeParam string, constraints ...Constraint)
- func (ct *ClassType) AddConstraint(typeParam string, constraint Constraint)
- func (ct *ClassType) AddConstructor(ctor Constructor)
- func (ct *ClassType) AddField(name string, filed *Field)
- func (ct *ClassType) AddInterface(iface *TraitType)
- func (ct *ClassType) AddOperator(op Operator, fn *FunctionType)
- func (ct *ClassType) AddOperatorConstraint(typeParam string, op Operator, rightType, returnType Type)
- func (ct *ClassType) AddStaticField(name string, field *Field)
- func (ct *ClassType) AddStaticMethod(name string, method *FunctionType)
- func (ct *ClassType) AddTraitConstraint(typeParam string, trait *TraitType)
- func (ct *ClassType) AddTypeConstraint(typeParam string, targetType Type)
- func (ct *ClassType) AddUnionConstraint(typeParam string, constraints ...Constraint)
- func (ct *ClassType) CheckConstraints(typeArgs []Type) error
- func (ct *ClassType) CheckTraitConstraints(typeArgs []Type) error
- func (ct *ClassType) FieldByName(name string) Type
- func (ct *ClassType) GetConstraint(typeParam string) Constraint
- func (ct *ClassType) GetConstructorByName(name string) Constructor
- func (ct *ClassType) GetConstructors() []Constructor
- func (ct *ClassType) GetInterfaces() []*TraitType
- func (ct *ClassType) GetOverriddenMethod(name string) *FunctionType
- func (ct *ClassType) GetParent() *ClassType
- func (ct *ClassType) GetStaticField(name string) *Field
- func (ct *ClassType) GetStaticMethod(name string) *FunctionType
- func (ct *ClassType) GetStaticValue(name string) Value
- func (ct *ClassType) GetTraitConstraints(typeParam string) []*TraitType
- func (ct *ClassType) HasConstraint(typeParam string) bool
- func (ct *ClassType) Implements(t Type) bool
- func (ct *ClassType) ImplementsTrait(iface *TraitType) bool
- func (ct *ClassType) Instantiate(typeArgs []Type) (*ClassType, error)
- func (ct *ClassType) InstantiateWithTraitConstraints(typeArgs []Type) (*ClassType, error)
- func (ct *ClassType) IsSubclassOf(parentType *ClassType) bool
- func (ct *ClassType) MethodByName(name string) Method
- func (ct *ClassType) New(values ...Value) Value
- func (ct *ClassType) OverrideMethod(name string, method *FunctionType)
- func (ct *ClassType) SetParent(parent *ClassType)
- func (ct *ClassType) SetStaticValue(name string, value Value)
- type CompositeConstraint
- type ConstrainedGenericClass
- type Constraint
- type Constructor
- type ConstructorPattern
- type Converter
- type DecoratorProcessor
- type DecoratorRegistry
- type DecoratorTarget
- type DecoratorType
- type DefaultTypeInference
- func (ti *DefaultTypeInference) CheckConstraintSatisfaction(t Type, constraint Constraint) bool
- func (ti *DefaultTypeInference) InferBidirectional(target Type, source Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromAssignment(targetType Type, sourceType Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromBinaryOp(op Operator, left, right Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromCall(funcType Type, args []Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromConstraints(constraints map[string]Constraint) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromContext(context *TypeContext) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromExpression(expr *ExpressionContext) map[string]Type
- func (ti *DefaultTypeInference) InferFromIndexOp(container, index Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromLiteral(literal Value) Type
- func (ti *DefaultTypeInference) InferFromOverload(overloads []*FunctionType, args []Value) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromPattern(pattern PatternMatch) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromUnaryOp(op Operator, operand Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferFromUsage(usage *TypeUsage) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferRecursive(types []Type) (map[string]Type, error)
- func (ti *DefaultTypeInference) InferTypeArgs(concreteType Type, genericType Type) ([]Type, error)
- func (ti *DefaultTypeInference) InferWithContext(target Type, context *TypeContext) (map[string]Type, error)
- func (ti *DefaultTypeInference) PropagateConstraints(constraints map[string]Constraint, unifier map[string]Type) (map[string]Constraint, error)
- func (ti *DefaultTypeInference) SolveConstraints(constraints map[string]Constraint) (map[string]Type, error)
- func (ti *DefaultTypeInference) SubstituteTypes(t Type, substitutions map[string]Type) Type
- func (ti *DefaultTypeInference) UnifyTypes(t1, t2 Type) (map[string]Type, error)
- type DefaultTypeUtils
- func (tu *DefaultTypeUtils) DeepMutable(t Type) (Type, error)
- func (tu *DefaultTypeUtils) DeepPartial(t Type) (Type, error)
- func (tu *DefaultTypeUtils) DeepReadonly(t Type) (Type, error)
- func (tu *DefaultTypeUtils) DeepRequired(t Type) (Type, error)
- func (tu *DefaultTypeUtils) Entries(t Type) (map[string]Type, error)
- func (tu *DefaultTypeUtils) Exclude(unionType, excludeType Type) (Type, error)
- func (tu *DefaultTypeUtils) Extract(unionType, extractType Type) (Type, error)
- func (tu *DefaultTypeUtils) Filter(t Type, predicate func(Type) bool) (Type, error)
- func (tu *DefaultTypeUtils) If(condition bool, trueType, falseType Type) Type
- func (tu *DefaultTypeUtils) Infer(template Type, constraints map[string]Type) (Type, error)
- func (tu *DefaultTypeUtils) Intersect(t1, t2 Type) (Type, error)
- func (tu *DefaultTypeUtils) Keys(t Type) ([]string, error)
- func (tu *DefaultTypeUtils) Map(t Type, mapper func(Type) Type) (Type, error)
- func (tu *DefaultTypeUtils) Merge(t1, t2 Type) (Type, error)
- func (tu *DefaultTypeUtils) Mutable(t Type) (Type, error)
- func (tu *DefaultTypeUtils) NonNullable(t Type) (Type, error)
- func (tu *DefaultTypeUtils) Omit(t Type, keys ...string) (Type, error)
- func (tu *DefaultTypeUtils) Optional(t Type) Type
- func (tu *DefaultTypeUtils) Partial(t Type) (Type, error)
- func (tu *DefaultTypeUtils) Pick(t Type, keys ...string) (Type, error)
- func (tu *DefaultTypeUtils) Readonly(t Type) (Type, error)
- func (tu *DefaultTypeUtils) Record(keyType, valueType Type) Type
- func (tu *DefaultTypeUtils) Required(t Type) (Type, error)
- func (tu *DefaultTypeUtils) Union(types ...Type) Type
- func (tu *DefaultTypeUtils) Values(t Type) ([]Type, error)
- type EnumType
- func NewADTEnum(name string, variants map[string]map[string]Type) *EnumType
- func NewAssociatedEnum(name string, fields map[string]*Field, valueMap map[string]Value) *EnumType
- func NewEnumType(name string) *EnumType
- func NewExplicitNumericEnum(name string, valueMap map[string]int) *EnumType
- func NewMixedEnum(name string, valueMap map[string]Value) *EnumType
- func NewNumericEnum(name string, valueNames []string) *EnumType
- func NewStringEnum(name string, valueMap map[string]string) *EnumType
- func (e *EnumType) AddField(name string, field *Field)
- func (e *EnumType) AddVariant(variant *EnumVariant)
- func (e *EnumType) AssignableTo(u Type) bool
- func (e *EnumType) ConvertibleTo(u Type) bool
- func (e *EnumType) GetValue(name string) *EnumVariant
- func (e *EnumType) GetValues() []*EnumVariant
- func (e *EnumType) GetVariant(name string) *EnumVariant
- func (e *EnumType) GetVariants() []*EnumVariant
- func (e *EnumType) Implements(u Type) bool
- func (e *EnumType) IsADT() bool
- func (e *EnumType) Kind() ObjKind
- func (e *EnumType) Name() string
- func (e *EnumType) SetADT(discriminant string)
- func (e *EnumType) Text() string
- type EnumVariant
- func (ev *EnumVariant) AddADTFieldType(name string, fieldType Type)
- func (ev *EnumVariant) GetADTField(name string) Value
- func (ev *EnumVariant) GetField(name string) Value
- func (ev *EnumVariant) Interface() any
- func (ev *EnumVariant) Name() string
- func (ev *EnumVariant) SetADTField(name string, value Value)
- func (ev *EnumVariant) SetField(name string, value Value)
- func (ev *EnumVariant) Text() string
- func (ev *EnumVariant) Type() Type
- func (ev *EnumVariant) Value() Value
- type ErrorType
- type ErrorValue
- type ExpressionContext
- type Field
- type FieldModifier
- type Function
- type FunctionBuilder
- func (fb *FunctionBuilder) Build() *FunctionType
- func (fb *FunctionBuilder) WithBody(body *ast.FuncDecl) *FunctionBuilder
- func (fb *FunctionBuilder) WithBuiltin(builtin BuiltinFunction) *FunctionBuilder
- func (fb *FunctionBuilder) WithOptionalParameter(name string, typ Type, defaultValue Value) *FunctionBuilder
- func (fb *FunctionBuilder) WithParameter(name string, typ Type) *FunctionBuilder
- func (fb *FunctionBuilder) WithReturnType(returnType Type) *FunctionBuilder
- func (fb *FunctionBuilder) WithVariadicParameter(name string, typ Type) *FunctionBuilder
- type FunctionCallContext
- type FunctionSignature
- type FunctionType
- func (ft *FunctionType) AppendSignatures(sigs []*FunctionSignature)
- func (ft *FunctionType) AssignableTo(t Type) bool
- func (ft *FunctionType) Call(args []Value, namedArgs map[string]Value, evaluator ...core.FunctionEvaluator) (Value, error)
- func (ft *FunctionType) ConvertibleTo(t Type) bool
- func (ft *FunctionType) Implements(t Type) bool
- func (ft *FunctionType) Kind() ObjKind
- func (ft *FunctionType) MatchSignature(args []Value, namedArgs map[string]Value) (*FunctionSignature, error)
- func (ft *FunctionType) Name() string
- func (ft *FunctionType) Signatures() []*FunctionSignature
- func (ft *FunctionType) Text() string
- type FunctionValue
- type Generic
- type GenericBase
- type InterfaceConstraint
- type IntersectionType
- func (i *IntersectionType) AssignableTo(t Type) bool
- func (i *IntersectionType) ConvertibleTo(t Type) bool
- func (i *IntersectionType) Implements(t Type) bool
- func (i *IntersectionType) Kind() ObjKind
- func (i *IntersectionType) Name() string
- func (i *IntersectionType) New(values ...Value) Value
- func (i *IntersectionType) Text() string
- type KeyValuePair
- type MapType
- type MapValue
- func (m *MapValue) Clear()
- func (m *MapValue) Delete(key Value)
- func (m *MapValue) Get(key Value) Value
- func (m *MapValue) Has(key Value) bool
- func (m *MapValue) Interface() any
- func (m *MapValue) Keys() []Value
- func (m *MapValue) Length() int
- func (m *MapValue) Set(key, value Value)
- func (m *MapValue) Text() string
- func (m *MapValue) Type() Type
- func (m *MapValue) Values() []Value
- type Method
- type NullValue
- type NullableType
- func (n *NullableType) AssignableTo(t Type) bool
- func (n *NullableType) BaseType() Type
- func (n *NullableType) ConvertibleTo(t Type) bool
- func (n *NullableType) Implements(t Type) bool
- func (n *NullableType) Kind() ObjKind
- func (n *NullableType) Name() string
- func (n *NullableType) New(values ...Value) Value
- func (n *NullableType) Text() string
- type NumberType
- type NumberValue
- type ObjKind
- type Object
- type ObjectType
- func (o *ObjectType) AddField(name string, field *Field)
- func (o *ObjectType) AddMethod(name string, signature Method)
- func (t *ObjectType) AssignableTo(u Type) bool
- func (t *ObjectType) ConvertibleTo(u Type) bool
- func (t *ObjectType) Field(i int) Type
- func (t *ObjectType) FieldByName(name string) Type
- func (t *ObjectType) Implements(u Type) bool
- func (t *ObjectType) Kind() ObjKind
- func (t *ObjectType) Method(i int) Method
- func (t *ObjectType) MethodByName(name string) Method
- func (t *ObjectType) Name() string
- func (t *ObjectType) New(values ...Value) Value
- func (t *ObjectType) NumField() int
- func (t *ObjectType) NumMethod() int
- func (t *ObjectType) Text() string
- type Operator
- type OperatorConstraint
- type OperatorOverload
- type Parameter
- type PatternMatch
- type PrimitiveType
- type Registry
- func (r *Registry) LookupFunction(name string) (*FunctionType, bool)
- func (r *Registry) LookupOperator(op Operator, left, right Value) (*OperatorOverload, error)
- func (r *Registry) RegisterFunction(name string, signature *FunctionSignature) error
- func (r *Registry) RegisterOperator(op Operator, left, right, returnType Type, fn *FunctionType)
- type SetType
- type SetValue
- func (sv *SetValue) Add(element Value) error
- func (sv *SetValue) Clear()
- func (sv *SetValue) Contains(element Value) (bool, error)
- func (sv *SetValue) Difference(other *SetValue) (*SetValue, error)
- func (sv *SetValue) Elements() map[string]Value
- func (sv *SetValue) Has(element Value) bool
- func (sv *SetValue) Interface() any
- func (sv *SetValue) Intersect(other *SetValue) (*SetValue, error)
- func (sv *SetValue) IsEmpty() bool
- func (sv *SetValue) Length() int
- func (sv *SetValue) Remove(element Value) error
- func (sv *SetValue) Text() string
- func (sv *SetValue) ToArray() *ArrayValue
- func (sv *SetValue) Type() Type
- func (sv *SetValue) Union(other *SetValue) (*SetValue, error)
- type SourceLocation
- type StringType
- type StringValue
- type TraitImpl
- type TraitRegistry
- type TraitType
- func (t *TraitType) AddDefaultImpl(name string, impl *FunctionType)
- func (t *TraitType) AddField(name string, field *Field)
- func (t *TraitType) AddMethod(name string, method *FunctionType)
- func (t *TraitType) AddOperator(op Operator, fn *FunctionType)
- func (t *TraitType) AssignableTo(u Type) bool
- func (t *TraitType) ConvertibleTo(u Type) bool
- func (t *TraitType) GetDefaultImpl(name string) *FunctionType
- func (t *TraitType) Implements(u Type) bool
- func (t *TraitType) Kind() ObjKind
- func (t *TraitType) Name() string
- func (t *TraitType) Text() string
- type TuplePattern
- type TupleType
- func (t *TupleType) AssignableTo(u Type) bool
- func (t *TupleType) ConvertibleTo(u Type) bool
- func (t *TupleType) ElementTypes() []Type
- func (t *TupleType) FieldNames() []string
- func (t *TupleType) GetElementType(index int) Type
- func (t *TupleType) GetFieldIndex(fieldName string) int
- func (t *TupleType) Implements(u Type) bool
- func (t *TupleType) Kind() ObjKind
- func (t *TupleType) Length() int
- func (t *TupleType) Name() string
- func (t *TupleType) Text() string
- type TupleValue
- func (tv *TupleValue) Destructure() []Value
- func (tv *TupleValue) Elements() []Value
- func (tv *TupleValue) Get(index int) Value
- func (tv *TupleValue) GetByName(fieldName string) Value
- func (tv *TupleValue) Interface() any
- func (tv *TupleValue) Length() int
- func (tv *TupleValue) Set(index int, value Value) error
- func (tv *TupleValue) Text() string
- func (tv *TupleValue) Type() Type
- func (tv *TupleValue) With(index int, value Value) (*TupleValue, error)
- type Type
- func DeepMutable(t Type) (Type, error)
- func DeepPartial(t Type) (Type, error)
- func DeepReadonly(t Type) (Type, error)
- func DeepRequired(t Type) (Type, error)
- func Exclude(unionType, excludeType Type) (Type, error)
- func Extract(unionType, extractType Type) (Type, error)
- func Filter(t Type, predicate func(Type) bool) (Type, error)
- func GetAnyType() Type
- func GetBoolType() Type
- func GetErrorType() Type
- func GetNeverType() Type
- func GetNullType() Type
- func GetNumberType() Type
- func GetStringType() Type
- func GetVoidType() Type
- func If(condition bool, trueType, falseType Type) Type
- func Infer(template Type, constraints map[string]Type) (Type, error)
- func Intersect(t1, t2 Type) (Type, error)
- func Map(t Type, mapper func(Type) Type) (Type, error)
- func Merge(t1, t2 Type) (Type, error)
- func Mutable(t Type) (Type, error)
- func NonNullable(t Type) (Type, error)
- func Omit(t Type, keys ...string) (Type, error)
- func Optional(t Type) Type
- func Partial(t Type) (Type, error)
- func Pick(t Type, keys ...string) (Type, error)
- func Readonly(t Type) (Type, error)
- func Record(keyType, valueType Type) Type
- func Required(t Type) (Type, error)
- func Union(types ...Type) Type
- func Values(t Type) ([]Type, error)
- type TypeContext
- type TypeInference
- type TypeOperator
- type TypeParameter
- func (tp *TypeParameter) AssignableTo(u Type) bool
- func (tp *TypeParameter) ConvertibleTo(u Type) bool
- func (tp *TypeParameter) Implements(u Type) bool
- func (tp *TypeParameter) Kind() ObjKind
- func (tp *TypeParameter) Name() string
- func (tp *TypeParameter) SatisfiesConstraint(constraint Constraint) bool
- func (tp *TypeParameter) Text() string
- type TypeRelation
- type TypeSubstituter
- type TypeUsage
- type TypeUtils
- type UnionConstraint
- type UnionType
- type Value
- type VariablePattern
- type Variance
Constants ¶
This section is empty.
Variables ¶
var ( // 数值类型约束 NumericConstraint = NewInterfaceConstraint(numberType) // 可比较类型约束 ComparableConstraint = NewCompositeConstraint( NewOperatorConstraint(OpEqual, anyType, boolType), NewOperatorConstraint(OpLess, anyType, boolType), NewOperatorConstraint(OpGreater, anyType, boolType), ) // 可序列化类型约束 SerializableConstraint = NewInterfaceConstraint(anyType) // 简化处理 // 字符串类型约束 StringConstraint = NewInterfaceConstraint(stringType) // 布尔类型约束 BoolConstraint = NewInterfaceConstraint(boolType) )
预定义的约束
var ( NULL = &NullValue{} TRUE = &BoolValue{Value: true} FALSE = &BoolValue{Value: false} )
var GlobalDecoratorRegistry = NewDecoratorRegistry()
GlobalDecoratorRegistry 全局装饰器注册表
var GlobalTraitRegistry = NewTraitRegistry()
全局trait注册表
Functions ¶
func ExampleGenericTraitConstraintInheritance ¶
func ExampleGenericTraitConstraintInheritance()
示例:泛型trait约束继承
func ExampleTraitGenericInheritanceIntegration ¶
func ExampleTraitGenericInheritanceIntegration()
示例:trait、泛型和继承联动
Types ¶
type ASTConverter ¶
type ASTConverter struct{}
func (*ASTConverter) ConvertField ¶
func (c *ASTConverter) ConvertField(field *ast.Field) (*Field, error)
ConvertField 转换字段
func (*ASTConverter) ConvertModifiers ¶
func (c *ASTConverter) ConvertModifiers(modifiers []ast.Modifier) []FieldModifier
ConvertModifiers 转换修饰符
func (*ASTConverter) ConvertParameter ¶
func (c *ASTConverter) ConvertParameter(param *ast.Parameter) (*Parameter, error)
ConvertParameter 转换参数
func (*ASTConverter) ConvertType ¶
func (c *ASTConverter) ConvertType(node ast.Node) (Type, error)
ConvertType 将AST节点转换为Type
func (*ASTConverter) ConvertValue ¶
func (c *ASTConverter) ConvertValue(node ast.Node) (Value, error)
ConvertValue 将AST节点转换为Value
type ArrayPattern ¶
type ArrayPattern struct { ArrayType Type Elements []PatternMatch }
ArrayPattern 数组模式
func (*ArrayPattern) Match ¶
func (ap *ArrayPattern) Match(value Value) bool
type ArrayType ¶
type ArrayType struct { *ObjectType // contains filtered or unexported fields }
func NewArrayType ¶
func (*ArrayType) AssignableTo ¶
func (*ArrayType) ConvertibleTo ¶
func (*ArrayType) ElementType ¶
func (*ArrayType) Implements ¶
type ArrayValue ¶
type ArrayValue struct { Elements []Value // contains filtered or unexported fields }
ArrayValue represents an array value.
func NewArrayValue ¶
func NewArrayValue(elementType Type, elements ...Value) *ArrayValue
NewArrayValue creates a new array value with the given elements.
func (*ArrayValue) Append ¶
func (a *ArrayValue) Append(value Value)
Append adds an element to the end of the array.
func (*ArrayValue) Get ¶
func (a *ArrayValue) Get(index int) Value
Get returns the element at the given index.
func (*ArrayValue) Interface ¶
func (a *ArrayValue) Interface() any
func (*ArrayValue) Length ¶
func (a *ArrayValue) Length() int
Length returns the length of the array.
func (*ArrayValue) Set ¶
func (a *ArrayValue) Set(index int, value Value)
Set sets the element at the given index.
func (*ArrayValue) Text ¶
func (a *ArrayValue) Text() string
func (*ArrayValue) Type ¶
func (a *ArrayValue) Type() Type
type BoolType ¶
type BoolType struct {
*ObjectType
}
func NewBoolType ¶
func NewBoolType() *BoolType
type BuiltinFunction ¶
type ClassConstructor ¶
type ClassConstructor struct {
// contains filtered or unexported fields
}
func NewClassConstructor ¶
func NewClassConstructor(name string, clsType *ClassType, signature []Type, isNamed bool) *ClassConstructor
NewClassConstructor 创建新的构造函数
func NewDefaultConstructor ¶
func NewDefaultConstructor(clsType *ClassType) *ClassConstructor
NewDefaultConstructor 创建默认构造函数
func (*ClassConstructor) Call ¶
func (cc *ClassConstructor) Call(args ...Value) Value
func (*ClassConstructor) In ¶
func (cc *ClassConstructor) In(i int) Type
func (*ClassConstructor) IsNamed ¶
func (cc *ClassConstructor) IsNamed() bool
func (*ClassConstructor) Match ¶
func (cc *ClassConstructor) Match(args []Value) bool
func (*ClassConstructor) Name ¶
func (cc *ClassConstructor) Name() string
func (*ClassConstructor) NumIn ¶
func (cc *ClassConstructor) NumIn() int
func (*ClassConstructor) Signature ¶
func (cc *ClassConstructor) Signature() []Type
type ClassInstance ¶
type ClassInstance struct {
// contains filtered or unexported fields
}
func (*ClassInstance) CallMethod ¶
func (ci *ClassInstance) CallMethod(name string, args []Value, namedArgs map[string]Value) (Value, error)
CallMethod 调用方法
func (*ClassInstance) GetField ¶
func (ci *ClassInstance) GetField(name string) Value
func (*ClassInstance) GetMethod ¶
func (ci *ClassInstance) GetMethod(name string) Method
GetMethod 获取方法,支持继承和方法重写
func (*ClassInstance) Interface ¶
func (ci *ClassInstance) Interface() any
func (*ClassInstance) SetField ¶
func (ci *ClassInstance) SetField(name string, value Value)
func (*ClassInstance) Text ¶
func (ci *ClassInstance) Text() string
func (*ClassInstance) Type ¶
func (ci *ClassInstance) Type() Type
type ClassType ¶
type ClassType struct { *ObjectType *GenericBase // 嵌入泛型基础结构 // contains filtered or unexported fields }
func ConvertClassDecl ¶
func NewClassType ¶
func NewGenericClass ¶
func NewGenericClass(name string, typeParams []string, constraints map[string]Constraint) *ClassType
func (*ClassType) AddCompositeConstraint ¶
func (ct *ClassType) AddCompositeConstraint(typeParam string, constraints ...Constraint)
AddCompositeConstraint 添加复合约束(便捷方法)
func (*ClassType) AddConstraint ¶
func (ct *ClassType) AddConstraint(typeParam string, constraint Constraint)
AddConstraint 添加类型参数约束
func (*ClassType) AddConstructor ¶
func (ct *ClassType) AddConstructor(ctor Constructor)
AddConstructor 添加构造函数
func (*ClassType) AddInterface ¶
AddInterface 添加实现的接口
func (*ClassType) AddOperator ¶
func (ct *ClassType) AddOperator(op Operator, fn *FunctionType)
func (*ClassType) AddOperatorConstraint ¶
func (ct *ClassType) AddOperatorConstraint(typeParam string, op Operator, rightType, returnType Type)
AddOperatorConstraint 添加运算符约束(便捷方法)
func (*ClassType) AddStaticField ¶
AddStaticField 添加静态字段
func (*ClassType) AddStaticMethod ¶
func (ct *ClassType) AddStaticMethod(name string, method *FunctionType)
AddStaticMethod 添加静态方法
func (*ClassType) AddTraitConstraint ¶
AddTraitConstraint 为类型参数添加trait约束
func (*ClassType) AddTypeConstraint ¶
AddTypeConstraint 添加类型约束(便捷方法)
func (*ClassType) AddUnionConstraint ¶
func (ct *ClassType) AddUnionConstraint(typeParam string, constraints ...Constraint)
AddUnionConstraint 添加联合约束(便捷方法)
func (*ClassType) CheckConstraints ¶
CheckConstraints 检查类型参数是否满足所有约束
func (*ClassType) CheckTraitConstraints ¶
CheckTraitConstraints 检查类型参数是否满足trait约束
func (*ClassType) FieldByName ¶
FieldByName 重写字段查找,支持继承
func (*ClassType) GetConstraint ¶
func (ct *ClassType) GetConstraint(typeParam string) Constraint
GetConstraint 获取类型参数的约束
func (*ClassType) GetConstructorByName ¶
func (ct *ClassType) GetConstructorByName(name string) Constructor
GetConstructorByName 根据名称获取命名构造函数
func (*ClassType) GetConstructors ¶
func (ct *ClassType) GetConstructors() []Constructor
GetConstructors 获取所有构造函数
func (*ClassType) GetInterfaces ¶
GetInterfaces 获取所有实现的接口
func (*ClassType) GetOverriddenMethod ¶
func (ct *ClassType) GetOverriddenMethod(name string) *FunctionType
GetOverriddenMethod 获取重写的方法
func (*ClassType) GetStaticField ¶
GetStaticField 获取静态字段
func (*ClassType) GetStaticMethod ¶
func (ct *ClassType) GetStaticMethod(name string) *FunctionType
GetStaticMethod 获取静态方法
func (*ClassType) GetStaticValue ¶
GetStaticValue 获取静态字段的值
func (*ClassType) GetTraitConstraints ¶
GetTraitConstraints 获取类型参数的trait约束
func (*ClassType) HasConstraint ¶
HasConstraint 检查类型参数是否有约束
func (*ClassType) Implements ¶
Implements 实现Type接口的Implements方法
func (*ClassType) ImplementsTrait ¶
ImplementsTrait 检查是否实现了指定trait
func (*ClassType) Instantiate ¶
func (*ClassType) InstantiateWithTraitConstraints ¶
重写Instantiate方法以支持trait约束检查
func (*ClassType) IsSubclassOf ¶
IsSubclassOf 检查是否为指定类的子类
func (*ClassType) MethodByName ¶
MethodByName 重写方法查找,支持继承和方法重写
func (*ClassType) OverrideMethod ¶
func (ct *ClassType) OverrideMethod(name string, method *FunctionType)
OverrideMethod 重写方法
func (*ClassType) SetStaticValue ¶
SetStaticValue 设置静态字段的值
type CompositeConstraint ¶
type CompositeConstraint struct {
// contains filtered or unexported fields
}
func NewCompositeConstraint ¶
func NewCompositeConstraint(constraints ...Constraint) *CompositeConstraint
func TypesToCompositeConstraint ¶
func TypesToCompositeConstraint(types ...Type) *CompositeConstraint
从多个Type创建CompositeConstraint的辅助函数
func (*CompositeConstraint) SatisfiedBy ¶
func (cc *CompositeConstraint) SatisfiedBy(t Type) bool
func (*CompositeConstraint) String ¶
func (cc *CompositeConstraint) String() string
type ConstrainedGenericClass ¶
type ConstrainedGenericClass struct { *ClassType // contains filtered or unexported fields }
增强的泛型类,支持Constraint
func NewConstrainedGenericClass ¶
func NewConstrainedGenericClass(name string, typeParams []string, constraints map[string]Constraint) *ConstrainedGenericClass
func (*ConstrainedGenericClass) Instantiate ¶
func (cgc *ConstrainedGenericClass) Instantiate(typeArgs []Type) (*ClassType, error)
type Constraint ¶
type Constructor ¶
type ConstructorPattern ¶
type ConstructorPattern struct { ConstructorName string ConstructorType Type Arguments []PatternMatch }
ConstructorPattern 构造函数模式
func (*ConstructorPattern) Match ¶
func (cp *ConstructorPattern) Match(value Value) bool
type DecoratorProcessor ¶
DecoratorProcessor 装饰器处理器接口
type DecoratorRegistry ¶
type DecoratorRegistry struct {
// contains filtered or unexported fields
}
装饰器注册表
func NewDecoratorRegistry ¶
func NewDecoratorRegistry() *DecoratorRegistry
NewDecoratorRegistry 创建装饰器注册表
func (*DecoratorRegistry) GetDecorator ¶
func (dr *DecoratorRegistry) GetDecorator(name string) *DecoratorType
GetDecorator 获取装饰器
func (*DecoratorRegistry) RegisterDecorator ¶
func (dr *DecoratorRegistry) RegisterDecorator(decorator *DecoratorType)
RegisterDecorator 注册装饰器
type DecoratorTarget ¶
type DecoratorTarget int
装饰器相关类型定义
const ( DecoratorTargetClass DecoratorTarget = iota DecoratorTargetMethod DecoratorTargetField DecoratorTargetFunction DecoratorTargetParameter DecoratorTargetEnum DecoratorTargetTrait )
type DecoratorType ¶
type DecoratorType struct { *ObjectType // contains filtered or unexported fields }
DecoratorType 装饰器类型
func NewDecoratorType ¶
func NewDecoratorType(name string, target DecoratorTarget, processor DecoratorProcessor) *DecoratorType
NewDecoratorType 创建新的装饰器类型
type DefaultTypeInference ¶
type DefaultTypeInference struct {
// contains filtered or unexported fields
}
DefaultTypeInference 默认类型推断实现
func (*DefaultTypeInference) CheckConstraintSatisfaction ¶
func (ti *DefaultTypeInference) CheckConstraintSatisfaction(t Type, constraint Constraint) bool
CheckConstraintSatisfaction 检查约束满足性
func (*DefaultTypeInference) InferBidirectional ¶
func (ti *DefaultTypeInference) InferBidirectional(target Type, source Type) (map[string]Type, error)
InferBidirectional 双向类型推断
func (*DefaultTypeInference) InferFromAssignment ¶
func (ti *DefaultTypeInference) InferFromAssignment(targetType Type, sourceType Type) (map[string]Type, error)
InferFromAssignment 从赋值推断类型
func (*DefaultTypeInference) InferFromBinaryOp ¶
func (ti *DefaultTypeInference) InferFromBinaryOp(op Operator, left, right Type) (map[string]Type, error)
InferFromBinaryOp 从二元操作推断类型
func (*DefaultTypeInference) InferFromCall ¶
InferFromCall 从函数调用推断类型
func (*DefaultTypeInference) InferFromConstraints ¶
func (ti *DefaultTypeInference) InferFromConstraints(constraints map[string]Constraint) (map[string]Type, error)
InferFromConstraints 从约束推断类型
func (*DefaultTypeInference) InferFromContext ¶
func (ti *DefaultTypeInference) InferFromContext(context *TypeContext) (map[string]Type, error)
InferFromContext 从上下文推断类型
func (*DefaultTypeInference) InferFromExpression ¶
func (ti *DefaultTypeInference) InferFromExpression(expr *ExpressionContext) map[string]Type
InferFromExpression 从表达式推断类型(增强版)
func (*DefaultTypeInference) InferFromIndexOp ¶
func (ti *DefaultTypeInference) InferFromIndexOp(container, index Type) (map[string]Type, error)
InferFromIndexOp 从索引操作推断类型
func (*DefaultTypeInference) InferFromLiteral ¶
func (ti *DefaultTypeInference) InferFromLiteral(literal Value) Type
InferFromLiteral 从字面量推断类型
func (*DefaultTypeInference) InferFromOverload ¶
func (ti *DefaultTypeInference) InferFromOverload(overloads []*FunctionType, args []Value) (map[string]Type, error)
InferFromOverload 从重载函数推断类型
func (*DefaultTypeInference) InferFromPattern ¶
func (ti *DefaultTypeInference) InferFromPattern(pattern PatternMatch) (map[string]Type, error)
InferFromPattern 从模式匹配推断类型
func (*DefaultTypeInference) InferFromUnaryOp ¶
func (ti *DefaultTypeInference) InferFromUnaryOp(op Operator, operand Type) (map[string]Type, error)
InferFromUnaryOp 从一元操作推断类型
func (*DefaultTypeInference) InferFromUsage ¶
func (ti *DefaultTypeInference) InferFromUsage(usage *TypeUsage) (map[string]Type, error)
InferFromUsage 从使用场景推断类型
func (*DefaultTypeInference) InferRecursive ¶
func (ti *DefaultTypeInference) InferRecursive(types []Type) (map[string]Type, error)
InferRecursive 递归类型推断
func (*DefaultTypeInference) InferTypeArgs ¶
func (ti *DefaultTypeInference) InferTypeArgs(concreteType Type, genericType Type) ([]Type, error)
InferTypeArgs 从具体类型推断泛型类型参数
func (*DefaultTypeInference) InferWithContext ¶
func (ti *DefaultTypeInference) InferWithContext(target Type, context *TypeContext) (map[string]Type, error)
InferWithContext 带上下文的类型推断
func (*DefaultTypeInference) PropagateConstraints ¶
func (ti *DefaultTypeInference) PropagateConstraints(constraints map[string]Constraint, unifier map[string]Type) (map[string]Constraint, error)
PropagateConstraints 约束传播
func (*DefaultTypeInference) SolveConstraints ¶
func (ti *DefaultTypeInference) SolveConstraints(constraints map[string]Constraint) (map[string]Type, error)
SolveConstraints 求解约束系统
func (*DefaultTypeInference) SubstituteTypes ¶
func (ti *DefaultTypeInference) SubstituteTypes(t Type, substitutions map[string]Type) Type
SubstituteTypes 类型替换
func (*DefaultTypeInference) UnifyTypes ¶
func (ti *DefaultTypeInference) UnifyTypes(t1, t2 Type) (map[string]Type, error)
UnifyTypes 类型统一算法
type DefaultTypeUtils ¶
type DefaultTypeUtils struct{}
DefaultTypeUtils 默认类型工具实现
func (*DefaultTypeUtils) DeepMutable ¶
func (tu *DefaultTypeUtils) DeepMutable(t Type) (Type, error)
DeepMutable<T> - 深度可变
func (*DefaultTypeUtils) DeepPartial ¶
func (tu *DefaultTypeUtils) DeepPartial(t Type) (Type, error)
DeepPartial<T> - 深度可选
func (*DefaultTypeUtils) DeepReadonly ¶
func (tu *DefaultTypeUtils) DeepReadonly(t Type) (Type, error)
DeepReadonly<T> - 深度只读
func (*DefaultTypeUtils) DeepRequired ¶
func (tu *DefaultTypeUtils) DeepRequired(t Type) (Type, error)
DeepRequired<T> - 深度必需
func (*DefaultTypeUtils) Entries ¶
func (tu *DefaultTypeUtils) Entries(t Type) (map[string]Type, error)
Entries<T> - 获取对象类型的键值对
func (*DefaultTypeUtils) Exclude ¶
func (tu *DefaultTypeUtils) Exclude(unionType, excludeType Type) (Type, error)
Exclude<T, U> - 从联合类型中排除指定类型
func (*DefaultTypeUtils) Extract ¶
func (tu *DefaultTypeUtils) Extract(unionType, extractType Type) (Type, error)
Extract<T, U> - 从联合类型中提取指定类型
func (*DefaultTypeUtils) If ¶
func (tu *DefaultTypeUtils) If(condition bool, trueType, falseType Type) Type
If<C, T, F> - 条件类型
func (*DefaultTypeUtils) Intersect ¶
func (tu *DefaultTypeUtils) Intersect(t1, t2 Type) (Type, error)
Intersect<T1, T2> - 类型交集
func (*DefaultTypeUtils) Keys ¶
func (tu *DefaultTypeUtils) Keys(t Type) ([]string, error)
Keys<T> - 获取对象类型的键
func (*DefaultTypeUtils) Merge ¶
func (tu *DefaultTypeUtils) Merge(t1, t2 Type) (Type, error)
Merge<T1, T2> - 合并两个对象类型
func (*DefaultTypeUtils) Mutable ¶
func (tu *DefaultTypeUtils) Mutable(t Type) (Type, error)
Mutable<T> - 使所有字段变为可变
func (*DefaultTypeUtils) NonNullable ¶
func (tu *DefaultTypeUtils) NonNullable(t Type) (Type, error)
NonNullable<T> - 排除 null 和 undefined
func (*DefaultTypeUtils) Omit ¶
func (tu *DefaultTypeUtils) Omit(t Type, keys ...string) (Type, error)
Omit<T, K> - 从对象类型中排除指定字段
func (*DefaultTypeUtils) Optional ¶
func (tu *DefaultTypeUtils) Optional(t Type) Type
Optional<T> - 使类型变为可选(T | undefined)
func (*DefaultTypeUtils) Partial ¶
func (tu *DefaultTypeUtils) Partial(t Type) (Type, error)
Partial<T> - 使所有字段变为可选
func (*DefaultTypeUtils) Pick ¶
func (tu *DefaultTypeUtils) Pick(t Type, keys ...string) (Type, error)
Pick<T, K> - 从对象类型中选择指定字段
func (*DefaultTypeUtils) Readonly ¶
func (tu *DefaultTypeUtils) Readonly(t Type) (Type, error)
Readonly<T> - 使所有字段变为只读
func (*DefaultTypeUtils) Record ¶
func (tu *DefaultTypeUtils) Record(keyType, valueType Type) Type
Record<K, V> - 创建键值对类型
func (*DefaultTypeUtils) Required ¶
func (tu *DefaultTypeUtils) Required(t Type) (Type, error)
Required<T> - 使所有字段变为必需
func (*DefaultTypeUtils) Union ¶
func (tu *DefaultTypeUtils) Union(types ...Type) Type
Union - 创建联合类型
type EnumType ¶
type EnumType struct { *ObjectType // contains filtered or unexported fields }
EnumType 表示枚举类型
func NewADTEnum ¶
创建Rust风格的代数数据类型枚举
func NewAssociatedEnum ¶
创建Dart风格的关联值枚举
func NewEnumType ¶
func NewExplicitNumericEnum ¶
创建显式数字枚举
func (*EnumType) AssignableTo ¶
func (*EnumType) ConvertibleTo ¶
func (*EnumType) GetValue ¶
func (e *EnumType) GetValue(name string) *EnumVariant
GetValue 获取枚举变体(别名,保持向后兼容性)
func (*EnumType) GetValues ¶
func (e *EnumType) GetValues() []*EnumVariant
GetValues 获取所有枚举变体(别名,保持向后兼容性)
func (*EnumType) GetVariant ¶
func (e *EnumType) GetVariant(name string) *EnumVariant
GetVariant 获取枚举变体
func (*EnumType) Implements ¶
type EnumVariant ¶
type EnumVariant struct {
// contains filtered or unexported fields
}
EnumVariant 表示枚举变体
func NewEnumVariant ¶
func NewEnumVariant(name string, value Value) *EnumVariant
func (*EnumVariant) AddADTFieldType ¶
func (ev *EnumVariant) AddADTFieldType(name string, fieldType Type)
AddADTFieldType 添加ADT字段类型(Rust风格)
func (*EnumVariant) GetADTField ¶
func (ev *EnumVariant) GetADTField(name string) Value
GetADTField 获取ADT字段值(Rust风格)
func (*EnumVariant) GetField ¶
func (ev *EnumVariant) GetField(name string) Value
GetField 获取关联字段值(Dart风格)
func (*EnumVariant) Interface ¶
func (ev *EnumVariant) Interface() any
func (*EnumVariant) Name ¶
func (ev *EnumVariant) Name() string
func (*EnumVariant) SetADTField ¶
func (ev *EnumVariant) SetADTField(name string, value Value)
SetADTField 设置ADT字段值(Rust风格)
func (*EnumVariant) SetField ¶
func (ev *EnumVariant) SetField(name string, value Value)
SetField 设置关联字段值(Dart风格)
func (*EnumVariant) Text ¶
func (ev *EnumVariant) Text() string
func (*EnumVariant) Type ¶
func (ev *EnumVariant) Type() Type
func (*EnumVariant) Value ¶
func (ev *EnumVariant) Value() Value
type ErrorType ¶
type ErrorType struct {
*ObjectType
}
func NewErrorType ¶
func NewErrorType() *ErrorType
type ErrorValue ¶
type ErrorValue struct {
Value string
}
ErrorValue represents the error value.
func (*ErrorValue) Interface ¶
func (e *ErrorValue) Interface() any
func (*ErrorValue) Text ¶
func (e *ErrorValue) Text() string
func (*ErrorValue) Type ¶
func (e *ErrorValue) Type() Type
type ExpressionContext ¶
ExpressionContext 表达式上下文
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
func (*Field) AddModifier ¶
func (f *Field) AddModifier(mod FieldModifier) *Field
func (*Field) HasModifier ¶
func (f *Field) HasModifier(mod FieldModifier) bool
func (*Field) IsRequired ¶
func (*Field) SetDefaultValue ¶
SetDefaultValue 设置字段的默认值
type FieldModifier ¶
type FieldModifier int
const ( FieldModifierNone FieldModifier = iota // none FieldModifierRequired // required FieldModifierOptional // ? FieldModifierReadonly // readonly FieldModifierStatic // static FieldModifierPub // pub )
func (FieldModifier) String ¶
func (i FieldModifier) String() string
type Function ¶
type Function interface { Signature() []Type Call(args ...Value) Value Match(args []Value) bool // NumIn returns a function type's input parameter count. // It panics if the type's Kind is not Func. NumIn() int // In returns the type of a function type's i'th input parameter. // It panics if the type's Kind is not Func. // It panics if i is not in the range [0, NumIn()). In(i int) Type }
type FunctionBuilder ¶ added in v0.3.0
type FunctionBuilder struct {
// contains filtered or unexported fields
}
FunctionBuilder 函数构建器
func NewFunctionBuilder ¶ added in v0.3.0
func NewFunctionBuilder(name string) *FunctionBuilder
NewFunctionBuilder 创建一个新的函数构建器
func (*FunctionBuilder) Build ¶ added in v0.3.0
func (fb *FunctionBuilder) Build() *FunctionType
Build 构建FunctionType
func (*FunctionBuilder) WithBody ¶ added in v0.3.0
func (fb *FunctionBuilder) WithBody(body *ast.FuncDecl) *FunctionBuilder
WithBody 设置函数体(用于非内置函数)
func (*FunctionBuilder) WithBuiltin ¶ added in v0.3.0
func (fb *FunctionBuilder) WithBuiltin(builtin BuiltinFunction) *FunctionBuilder
WithBuiltin 设置内置函数实现
func (*FunctionBuilder) WithOptionalParameter ¶ added in v0.3.0
func (fb *FunctionBuilder) WithOptionalParameter(name string, typ Type, defaultValue Value) *FunctionBuilder
WithOptionalParameter 添加可选参数
func (*FunctionBuilder) WithParameter ¶ added in v0.3.0
func (fb *FunctionBuilder) WithParameter(name string, typ Type) *FunctionBuilder
WithParameter 添加位置参数
func (*FunctionBuilder) WithReturnType ¶ added in v0.3.0
func (fb *FunctionBuilder) WithReturnType(returnType Type) *FunctionBuilder
WithReturnType 设置返回类型
func (*FunctionBuilder) WithVariadicParameter ¶ added in v0.3.0
func (fb *FunctionBuilder) WithVariadicParameter(name string, typ Type) *FunctionBuilder
WithVariadicParameter 设置可变参数
type FunctionCallContext ¶
FunctionCallContext 函数调用上下文
type FunctionSignature ¶
type FunctionSignature struct {
// contains filtered or unexported fields
}
type FunctionType ¶
type FunctionType struct { *GenericBase // 嵌入泛型基础结构 // contains filtered or unexported fields }
func NewGenericFunction ¶
func NewGenericFunction(name string, typeParams []string, constraints map[string]Constraint) *FunctionType
func (*FunctionType) AppendSignatures ¶ added in v0.3.0
func (ft *FunctionType) AppendSignatures(sigs []*FunctionSignature)
func (*FunctionType) AssignableTo ¶
func (ft *FunctionType) AssignableTo(t Type) bool
func (*FunctionType) Call ¶
func (ft *FunctionType) Call(args []Value, namedArgs map[string]Value, evaluator ...core.FunctionEvaluator) (Value, error)
func (*FunctionType) ConvertibleTo ¶
func (ft *FunctionType) ConvertibleTo(t Type) bool
func (*FunctionType) Implements ¶
func (ft *FunctionType) Implements(t Type) bool
func (*FunctionType) Kind ¶
func (ft *FunctionType) Kind() ObjKind
func (*FunctionType) MatchSignature ¶
func (ft *FunctionType) MatchSignature(args []Value, namedArgs map[string]Value) (*FunctionSignature, error)
func (*FunctionType) Name ¶
func (ft *FunctionType) Name() string
func (*FunctionType) Signatures ¶ added in v0.3.0
func (ft *FunctionType) Signatures() []*FunctionSignature
func (*FunctionType) Text ¶
func (ft *FunctionType) Text() string
type FunctionValue ¶
type FunctionValue struct {
// contains filtered or unexported fields
}
FunctionValue represents a function value.
func NewFunctionValue ¶
func NewFunctionValue(functionType *FunctionType) *FunctionValue
NewFunctionValue creates a new function value.
func (*FunctionValue) Interface ¶
func (f *FunctionValue) Interface() any
func (*FunctionValue) Text ¶
func (f *FunctionValue) Text() string
func (*FunctionValue) Type ¶
func (f *FunctionValue) Type() Type
type Generic ¶
type Generic interface { Type // 泛型相关方法 IsGeneric() bool TypeParameters() []string Constraints() map[string]Constraint Instantiate(typeArgs []Type) (Type, error) CheckConstraints(typeArgs []Type) error }
Generic 统一的泛型接口
type GenericBase ¶
type GenericBase struct {
// contains filtered or unexported fields
}
GenericBase 泛型基础结构,可以被其他类型嵌入
func NewGenericBase ¶
func NewGenericBase(typeParams []string, constraints map[string]Constraint) *GenericBase
func (*GenericBase) CheckConstraints ¶
func (gb *GenericBase) CheckConstraints(typeArgs []Type) error
func (*GenericBase) Constraints ¶
func (gb *GenericBase) Constraints() map[string]Constraint
func (*GenericBase) IsGeneric ¶
func (gb *GenericBase) IsGeneric() bool
func (*GenericBase) TypeParameters ¶
func (gb *GenericBase) TypeParameters() []string
type InterfaceConstraint ¶
type InterfaceConstraint struct {
// contains filtered or unexported fields
}
func NewInterfaceConstraint ¶
func NewInterfaceConstraint(interfaceType Type) *InterfaceConstraint
func (*InterfaceConstraint) SatisfiedBy ¶
func (ic *InterfaceConstraint) SatisfiedBy(t Type) bool
func (*InterfaceConstraint) String ¶
func (ic *InterfaceConstraint) String() string
type IntersectionType ¶
type IntersectionType struct {
// contains filtered or unexported fields
}
func NewIntersectionType ¶
func NewIntersectionType(types ...Type) *IntersectionType
func (*IntersectionType) AssignableTo ¶
func (i *IntersectionType) AssignableTo(t Type) bool
func (*IntersectionType) ConvertibleTo ¶
func (i *IntersectionType) ConvertibleTo(t Type) bool
func (*IntersectionType) Implements ¶
func (i *IntersectionType) Implements(t Type) bool
func (*IntersectionType) Kind ¶
func (i *IntersectionType) Kind() ObjKind
func (*IntersectionType) Name ¶
func (i *IntersectionType) Name() string
func (*IntersectionType) New ¶
func (i *IntersectionType) New(values ...Value) Value
func (*IntersectionType) Text ¶
func (i *IntersectionType) Text() string
type KeyValuePair ¶
KeyValuePair represents a key-value pair in a map.
type MapType ¶
type MapType struct { *ObjectType // contains filtered or unexported fields }
func NewMapType ¶
func (*MapType) AssignableTo ¶
func (*MapType) ConvertibleTo ¶
func (*MapType) Implements ¶
type MapValue ¶
type MapValue struct { Pairs []*KeyValuePair // contains filtered or unexported fields }
MapValue represents a map value.
func NewMapValue ¶
NewMapValue creates a new map value with the given key and value types.
type NullableType ¶
type NullableType struct {
// contains filtered or unexported fields
}
NullableType represents a nullable type (e.g., T?)
func NewNullableType ¶
func NewNullableType(baseType Type) *NullableType
func (*NullableType) AssignableTo ¶
func (n *NullableType) AssignableTo(t Type) bool
func (*NullableType) BaseType ¶
func (n *NullableType) BaseType() Type
func (*NullableType) ConvertibleTo ¶
func (n *NullableType) ConvertibleTo(t Type) bool
func (*NullableType) Implements ¶
func (n *NullableType) Implements(t Type) bool
func (*NullableType) Kind ¶
func (n *NullableType) Kind() ObjKind
func (*NullableType) Name ¶
func (n *NullableType) Name() string
func (*NullableType) New ¶
func (n *NullableType) New(values ...Value) Value
func (*NullableType) Text ¶
func (n *NullableType) Text() string
type NumberType ¶
type NumberType struct {
*ObjectType
}
func NewNumberType ¶
func NewNumberType() *NumberType
type NumberValue ¶
NumberValue represents the number value.
func NewNumberValue ¶
func NewNumberValue(value string) *NumberValue
NewNumberValue creates a new number value from the given string.
func (*NumberValue) Clone ¶ added in v0.3.0
func (n *NumberValue) Clone() *NumberValue
func (*NumberValue) Interface ¶
func (n *NumberValue) Interface() any
func (*NumberValue) Text ¶
func (n *NumberValue) Text() string
func (*NumberValue) Type ¶
func (n *NumberValue) Type() Type
type ObjKind ¶
type ObjKind int
const ( O_NUM ObjKind = iota // num O_STR // str O_BOOL // bool O_SYMBOL // symbol O_ARR // arr O_TUPLE // tuple O_SET // set O_OBJ // object O_MAP // map O_FUNC // func O_NULL // null O_ANY // any O_VOID // void O_NEVER // never O_ERROR // error O_TRAIT // trait O_CLASS // class O_ENUM // enum O_BUILTIN O_LITERAL O_RET O_QUOTE // A | B O_UNION // union // A & B O_INTERSECTION // intersection // T? O_NULLABLE // nullable // Decorators O_DECORATOR // decorator // Generic types O_TYPE_PARAM // type_param )
type ObjectType ¶
type ObjectType struct {
// contains filtered or unexported fields
}
func NewObjectType ¶
func NewObjectType(name string, kind ObjKind) *ObjectType
func (*ObjectType) AddField ¶
func (o *ObjectType) AddField(name string, field *Field)
func (*ObjectType) AddMethod ¶
func (o *ObjectType) AddMethod(name string, signature Method)
func (*ObjectType) AssignableTo ¶
func (t *ObjectType) AssignableTo(u Type) bool
func (*ObjectType) ConvertibleTo ¶
func (t *ObjectType) ConvertibleTo(u Type) bool
func (*ObjectType) Field ¶
func (t *ObjectType) Field(i int) Type
func (*ObjectType) FieldByName ¶
func (t *ObjectType) FieldByName(name string) Type
func (*ObjectType) Implements ¶
func (t *ObjectType) Implements(u Type) bool
func (*ObjectType) Kind ¶
func (t *ObjectType) Kind() ObjKind
func (*ObjectType) Method ¶
func (t *ObjectType) Method(i int) Method
func (*ObjectType) MethodByName ¶
func (t *ObjectType) MethodByName(name string) Method
func (*ObjectType) Name ¶
func (t *ObjectType) Name() string
func (*ObjectType) New ¶
func (t *ObjectType) New(values ...Value) Value
func (*ObjectType) NumField ¶
func (t *ObjectType) NumField() int
func (*ObjectType) NumMethod ¶
func (t *ObjectType) NumMethod() int
func (*ObjectType) Text ¶
func (t *ObjectType) Text() string
type Operator ¶
type Operator int
const ( OpIllegal Operator = iota OpAdd // + OpSub // - OpMul // * OpDiv // / OpMod // % OpConcat // .. OpAnd // && OpOr // || OpEqual // == OpNot // ! OpLess // < OpLessEqual // <= OpGreater // > OpGreaterEqual // >= OpAssign // = OpIndex // [] OpCall // () Opa // a"" Opb // b"" Opc // c"" Opd // d"" Ope // e"" Opf // f"" Opg // g"" Oph // h"" Opi // i"" Opj // j"" Opk // k"" Opl // l"" Opm // m"" Opn // n"" Opo // o"" Opp // p"" Opq // q"" Opr // r"" Ops // s"" Ott // t"" Opu // u"" Opv // v"" Opw // w"" Opz // z"" OpA // A"" OpB // B"" OpC // C"" OpD // D"" OpE // E"" OpF // F"" OpG // G"" OpH // H"" OpI // I"" OpJ // J"" OpK // K"" OpL // L"" OpM // M"" OpN // N"" OpO // O"" OpP // P"" OpQ // Q"" OpR // R"" OpS // S"" OpT // T"" OpU // U"" OpV // V"" OpW // W"" OpX // X"" OpY // Y"" OpZ // Z"" )
type OperatorConstraint ¶
type OperatorConstraint struct {
// contains filtered or unexported fields
}
func NewOperatorConstraint ¶
func NewOperatorConstraint(op Operator, rightType, returnType Type) *OperatorConstraint
func NewOperatorConstraintSimple ¶
func NewOperatorConstraintSimple(op Operator) *OperatorConstraint
func (*OperatorConstraint) SatisfiedBy ¶
func (oc *OperatorConstraint) SatisfiedBy(t Type) bool
func (*OperatorConstraint) String ¶
func (oc *OperatorConstraint) String() string
type OperatorOverload ¶
type OperatorOverload struct {
// contains filtered or unexported fields
}
type Parameter ¶
type Parameter struct {
// contains filtered or unexported fields
}
func NewOptionalParameter ¶ added in v0.3.0
NewOptionalParameter 创建一个可选参数
func NewParameter ¶ added in v0.3.0
NewParameter 创建一个新的参数
func NewVariadicParameter ¶ added in v0.3.0
NewVariadicParameter 创建一个可变参数
type PrimitiveType ¶
type PrimitiveType struct {
// contains filtered or unexported fields
}
func NewPrimitiveType ¶
func NewPrimitiveType(name string, kind ObjKind) *PrimitiveType
func (*PrimitiveType) AssignableTo ¶
func (pt *PrimitiveType) AssignableTo(u Type) bool
func (*PrimitiveType) ConvertibleTo ¶
func (pt *PrimitiveType) ConvertibleTo(u Type) bool
func (*PrimitiveType) Implements ¶
func (pt *PrimitiveType) Implements(u Type) bool
func (*PrimitiveType) Kind ¶
func (pt *PrimitiveType) Kind() ObjKind
func (*PrimitiveType) Name ¶
func (pt *PrimitiveType) Name() string
func (*PrimitiveType) Text ¶
func (pt *PrimitiveType) Text() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func NewRegistry ¶
func NewRegistry() *Registry
func (*Registry) LookupFunction ¶
func (r *Registry) LookupFunction(name string) (*FunctionType, bool)
func (*Registry) LookupOperator ¶
func (r *Registry) LookupOperator(op Operator, left, right Value) (*OperatorOverload, error)
func (*Registry) RegisterFunction ¶
func (r *Registry) RegisterFunction(name string, signature *FunctionSignature) error
func (*Registry) RegisterOperator ¶
func (r *Registry) RegisterOperator(op Operator, left, right, returnType Type, fn *FunctionType)
type SetType ¶
type SetType struct { *ObjectType // contains filtered or unexported fields }
SetType 表示集合类型
func NewSetType ¶
func (*SetType) AssignableTo ¶
func (*SetType) ConvertibleTo ¶
func (*SetType) ElementType ¶
func (*SetType) Implements ¶
type SetValue ¶
type SetValue struct {
// contains filtered or unexported fields
}
SetValue 表示集合值
func NewSetValue ¶
func (*SetValue) Difference ¶
Difference 差集运算
type SourceLocation ¶
type StringType ¶
type StringType struct {
*ObjectType
}
func NewStringType ¶
func NewStringType() *StringType
type StringValue ¶
type StringValue struct {
Value string
}
StringValue represents the string value.
func (*StringValue) Clone ¶ added in v0.3.0
func (s *StringValue) Clone() *StringValue
func (*StringValue) Interface ¶
func (s *StringValue) Interface() any
func (*StringValue) Text ¶
func (s *StringValue) Text() string
func (*StringValue) Type ¶
func (s *StringValue) Type() Type
type TraitImpl ¶
type TraitImpl struct {
// contains filtered or unexported fields
}
TraitImpl 表示trait的实现
func NewTraitImpl ¶
func (*TraitImpl) AddMethod ¶
func (ti *TraitImpl) AddMethod(name string, method *FunctionType)
func (*TraitImpl) AddOperator ¶
func (ti *TraitImpl) AddOperator(op Operator, fn *FunctionType)
func (*TraitImpl) GetMethod ¶
func (ti *TraitImpl) GetMethod(name string) *FunctionType
GetMethod 获取方法实现,优先返回自定义实现,否则返回默认实现
type TraitRegistry ¶
type TraitRegistry struct {
// contains filtered or unexported fields
}
TraitRegistry trait注册表
func NewTraitRegistry ¶
func NewTraitRegistry() *TraitRegistry
func (*TraitRegistry) GetImpl ¶
func (tr *TraitRegistry) GetImpl(traitName, typeName string) []*TraitImpl
func (*TraitRegistry) GetTrait ¶
func (tr *TraitRegistry) GetTrait(name string) *TraitType
func (*TraitRegistry) RegisterImpl ¶
func (tr *TraitRegistry) RegisterImpl(impl *TraitImpl)
func (*TraitRegistry) RegisterTrait ¶
func (tr *TraitRegistry) RegisterTrait(trait *TraitType)
type TraitType ¶
type TraitType struct { *ObjectType // contains filtered or unexported fields }
TraitType 表示trait类型
func ConvertTraitDecl ¶
ConvertTraitDecl 转换trait声明
func NewTraitType ¶
func (*TraitType) AddDefaultImpl ¶
func (t *TraitType) AddDefaultImpl(name string, impl *FunctionType)
AddDefaultImpl 添加默认实现
func (*TraitType) AddMethod ¶
func (t *TraitType) AddMethod(name string, method *FunctionType)
AddMethod 添加trait方法
func (*TraitType) AddOperator ¶
func (t *TraitType) AddOperator(op Operator, fn *FunctionType)
AddOperator 添加trait运算符
func (*TraitType) AssignableTo ¶
func (*TraitType) ConvertibleTo ¶
func (*TraitType) GetDefaultImpl ¶
func (t *TraitType) GetDefaultImpl(name string) *FunctionType
GetDefaultImpl 获取默认实现
func (*TraitType) Implements ¶
type TuplePattern ¶
type TuplePattern struct { TupleType *TupleType Elements []PatternMatch }
TuplePattern 元组模式
func (*TuplePattern) Match ¶
func (tp *TuplePattern) Match(value Value) bool
type TupleType ¶
type TupleType struct { *ObjectType // contains filtered or unexported fields }
TupleType 表示元组类型
func NewNamedTupleType ¶
func NewTupleType ¶
func NewTupleTypeWithMethods ¶
创建元组类型的工厂函数
func (*TupleType) AssignableTo ¶
func (*TupleType) ConvertibleTo ¶
func (*TupleType) ElementTypes ¶
func (*TupleType) FieldNames ¶
func (*TupleType) GetElementType ¶
GetElementType 获取指定位置的元素类型
func (*TupleType) GetFieldIndex ¶
GetFieldIndex 根据字段名获取索引
func (*TupleType) Implements ¶
type TupleValue ¶
type TupleValue struct {
// contains filtered or unexported fields
}
TupleValue 表示元组值
func NewTupleValue ¶
func NewTupleValue(tupleType *TupleType, elements ...Value) *TupleValue
func (*TupleValue) Elements ¶
func (tv *TupleValue) Elements() []Value
func (*TupleValue) GetByName ¶
func (tv *TupleValue) GetByName(fieldName string) Value
GetByName 通过字段名获取元素
func (*TupleValue) Interface ¶
func (tv *TupleValue) Interface() any
func (*TupleValue) Length ¶
func (tv *TupleValue) Length() int
func (*TupleValue) Text ¶
func (tv *TupleValue) Text() string
func (*TupleValue) Type ¶
func (tv *TupleValue) Type() Type
func (*TupleValue) With ¶
func (tv *TupleValue) With(index int, value Value) (*TupleValue, error)
With 创建新的元组,更新指定位置的元素
type Type ¶
type Type interface { Name() string Text() string Kind() ObjKind // Implements reports whether the type implements the interface type u. Implements(u Type) bool AssignableTo(u Type) bool ConvertibleTo(u Type) bool }
func DeepMutable ¶
func DeepPartial ¶
func DeepReadonly ¶
func DeepRequired ¶
func GetAnyType ¶ added in v0.3.0
func GetAnyType() Type
func GetBoolType ¶ added in v0.3.0
func GetBoolType() Type
func GetErrorType ¶ added in v0.3.0
func GetErrorType() Type
func GetNeverType ¶ added in v0.3.0
func GetNeverType() Type
func GetNullType ¶ added in v0.3.0
func GetNullType() Type
func GetNumberType ¶ added in v0.3.0
func GetNumberType() Type
func GetStringType ¶ added in v0.3.0
func GetStringType() Type
func GetVoidType ¶ added in v0.3.0
func GetVoidType() Type
func NonNullable ¶
type TypeContext ¶
type TypeContext struct { Variables map[string]Type // 变量类型 FunctionCalls []*FunctionCallContext // 函数调用 Expressions []*ExpressionContext // 表达式 Constraints map[string]Constraint // 约束 Hints map[string]Type // 类型提示 }
TypeContext 表示类型推断上下文
type TypeInference ¶
type TypeInference interface { // InferTypeArgs 从具体类型推断泛型类型参数 InferTypeArgs(concreteType Type, genericType Type) ([]Type, error) // InferFromUsage 从使用场景推断类型 InferFromUsage(usage *TypeUsage) (map[string]Type, error) // InferFromConstraints 从约束推断类型 InferFromConstraints(constraints map[string]Constraint) (map[string]Type, error) // InferFromAssignment 从赋值推断类型 InferFromAssignment(targetType Type, sourceType Type) (map[string]Type, error) // InferFromContext 从上下文推断类型 InferFromContext(context *TypeContext) (map[string]Type, error) // InferBidirectional 双向类型推断 InferBidirectional(target Type, source Type) (map[string]Type, error) // InferFromPattern 从模式匹配推断类型 InferFromPattern(pattern PatternMatch) (map[string]Type, error) // SolveConstraints 求解约束系统 SolveConstraints(constraints map[string]Constraint) (map[string]Type, error) // InferFromOverload 从重载函数推断类型 InferFromOverload(overloads []*FunctionType, args []Value) (map[string]Type, error) // UnifyTypes 类型统一算法 UnifyTypes(t1, t2 Type) (map[string]Type, error) // PropagateConstraints 约束传播 PropagateConstraints(constraints map[string]Constraint, unifier map[string]Type) (map[string]Constraint, error) // InferRecursive 递归类型推断 InferRecursive(types []Type) (map[string]Type, error) // InferWithContext 带上下文的类型推断 InferWithContext(target Type, context *TypeContext) (map[string]Type, error) // SubstituteTypes 类型替换 SubstituteTypes(t Type, substitutions map[string]Type) Type // CheckConstraintSatisfaction 检查约束满足性 CheckConstraintSatisfaction(t Type, constraint Constraint) bool // InferFromLiteral 从字面量推断类型 InferFromLiteral(literal Value) Type // InferFromExpression 从表达式推断类型(增强版) InferFromExpression(expr *ExpressionContext) map[string]Type // InferFromBinaryOp 从二元操作推断类型 InferFromBinaryOp(op Operator, left, right Type) (map[string]Type, error) // InferFromUnaryOp 从一元操作推断类型 InferFromUnaryOp(op Operator, operand Type) (map[string]Type, error) // InferFromIndexOp 从索引操作推断类型 InferFromIndexOp(container, index Type) (map[string]Type, error) // InferFromCall 从函数调用推断类型 InferFromCall(funcType Type, args []Type) (map[string]Type, error) }
TypeInference 类型推断接口
type TypeOperator ¶
type TypeOperator interface { // Unify returns the most specific type that is a supertype of both types. Unify(other Type) (Type, error) // Intersect returns the most specific type that is a subtype of both types. Intersect(other Type) (Type, error) // Union returns the most specific type that is a supertype of both types. Union(other Type) Type }
TypeOperator represents the operator between two types.
type TypeParameter ¶
type TypeParameter struct {
// contains filtered or unexported fields
}
func NewTypeParameter ¶
func NewTypeParameter(name string, constraints map[string]Constraint) *TypeParameter
func (*TypeParameter) AssignableTo ¶
func (tp *TypeParameter) AssignableTo(u Type) bool
func (*TypeParameter) ConvertibleTo ¶
func (tp *TypeParameter) ConvertibleTo(u Type) bool
func (*TypeParameter) Implements ¶
func (tp *TypeParameter) Implements(u Type) bool
func (*TypeParameter) Kind ¶
func (tp *TypeParameter) Kind() ObjKind
func (*TypeParameter) Name ¶
func (tp *TypeParameter) Name() string
func (*TypeParameter) SatisfiesConstraint ¶
func (tp *TypeParameter) SatisfiesConstraint(constraint Constraint) bool
SatisfiesConstraint 检查类型参数是否满足约束
func (*TypeParameter) Text ¶
func (tp *TypeParameter) Text() string
type TypeRelation ¶
type TypeRelation interface { // IsAssignableTo reports whether a type can be assigned to the type u. IsAssignableTo(u Type) bool // IsSubtypeOf reports whether a type is a subtype of the type u. IsSubtypeOf(u Type) bool // IsSupertypeOf reports whether a type is a supertype of the type u. IsSupertypeOf(u Type) bool // IsCompatibleWith reports whether a type is compatible with the type u. IsCompatibleWith(u Type) bool }
TypeRelation represents the relation between two types.
type TypeSubstituter ¶
TODO
type TypeUsage ¶
type TypeUsage struct { Context string // 使用上下文 Arguments []Type // 参数类型 ReturnType Type // 返回类型 Constraints map[string]Constraint // 约束信息 Hints map[string]Type // 类型提示 }
TypeUsage 表示类型使用场景
type TypeUtils ¶
type TypeUtils interface { // 基础类型工具 Partial(t Type) (Type, error) Required(t Type) (Type, error) Optional(t Type) Type Readonly(t Type) (Type, error) Mutable(t Type) (Type, error) // 对象类型工具 Pick(t Type, keys ...string) (Type, error) Omit(t Type, keys ...string) (Type, error) Record(keyType, valueType Type) Type // 联合类型工具 Exclude(unionType, excludeType Type) (Type, error) Extract(unionType, extractType Type) (Type, error) NonNullable(t Type) (Type, error) // 条件类型工具 If(condition bool, trueType, falseType Type) Type Infer(template Type, constraints map[string]Type) (Type, error) // 映射类型工具 Map(t Type, mapper func(Type) Type) (Type, error) Filter(t Type, predicate func(Type) bool) (Type, error) // 高级类型工具 DeepPartial(t Type) (Type, error) DeepRequired(t Type) (Type, error) DeepReadonly(t Type) (Type, error) DeepMutable(t Type) (Type, error) // 类型组合工具 Merge(t1, t2 Type) (Type, error) Intersect(t1, t2 Type) (Type, error) Union(types ...Type) Type // 类型查询工具 Keys(t Type) ([]string, error) Values(t Type) ([]Type, error) Entries(t Type) (map[string]Type, error) }
TypeUtils 类型工具接口
var GlobalTypeUtils TypeUtils = NewTypeUtils()
全局类型工具实例
type UnionConstraint ¶
type UnionConstraint struct {
// contains filtered or unexported fields
}
func NewUnionConstraint ¶
func NewUnionConstraint(constraints ...Constraint) *UnionConstraint
func TypesToUnionConstraint ¶
func TypesToUnionConstraint(types ...Type) *UnionConstraint
从多个Type创建UnionConstraint的辅助函数
func (*UnionConstraint) SatisfiedBy ¶
func (uc *UnionConstraint) SatisfiedBy(t Type) bool
func (*UnionConstraint) String ¶
func (uc *UnionConstraint) String() string
type UnionType ¶
type UnionType struct {
// contains filtered or unexported fields
}
func NewUnionType ¶
func (*UnionType) AssignableTo ¶
func (*UnionType) ConvertibleTo ¶
func (*UnionType) Implements ¶
type VariablePattern ¶
VariablePattern 变量模式
func (*VariablePattern) Match ¶
func (vp *VariablePattern) Match(value Value) bool