interpreter

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 9 Imported by: 0

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(ctx *Context, node ast.Node) object.Value

Types

type Breakpoint

type Breakpoint struct {
	File    string
	Line    int
	Column  int
	Enabled bool
}

type Context

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

func DefaultContext

func DefaultContext() *Context

func (*Context) Fork

func (c *Context) Fork() *Context

func (*Context) Get

func (c *Context) Get(name string) (object.Value, bool)

type DebugCommand

type DebugCommand struct{}

type DebugState

type DebugState struct{}

type Debugger

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

type Environment

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

func NewEnvironment

func NewEnvironment() *Environment

func (*Environment) Assign

func (e *Environment) Assign(name string, obj object.Value) error

Assign 重新赋值变量

func (*Environment) Declare

func (e *Environment) Declare(name string, obj object.Value, scope token.Token) error

Declare 声明新变量

func (*Environment) Fork

func (e *Environment) Fork() *Environment

func (*Environment) GetScope

func (e *Environment) GetScope(name string) (token.Token, bool)

GetScope 获取变量的作用域

func (*Environment) GetValue added in v0.3.0

func (e *Environment) GetValue(name string) (object.Value, bool)

GetValue 获取变量值,按优先级查找:const -> let -> var

func (*Environment) GetVariableInfo

func (e *Environment) GetVariableInfo(name string) (*VariableInfo, bool)

GetVariableInfo 获取变量的完整信息

func (*Environment) IsDeclared

func (e *Environment) IsDeclared(name string) bool

IsDeclared 检查变量是否已声明

func (*Environment) IsReadOnly

func (e *Environment) IsReadOnly(name string) bool

IsReadOnly 检查变量是否为只读

func (*Environment) Set

func (e *Environment) Set(name string, obj object.Value) object.Value

Set 设置变量值(兼容旧接口)

func (*Environment) SetWithScope

func (e *Environment) SetWithScope(name string, obj object.Value, scope token.Token, readOnly bool) object.Value

SetWithScope 根据作用域设置变量

type FunctionEvaluatorImpl

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

FunctionEvaluatorImpl 函数求值器实现

func NewFunctionEvaluator

func NewFunctionEvaluator(interpreter *Interpreter) *FunctionEvaluatorImpl

NewFunctionEvaluator 创建函数求值器

func (*FunctionEvaluatorImpl) EvaluateFunction

func (fe *FunctionEvaluatorImpl) EvaluateFunction(funcDecl *ast.FuncDecl, args []interface{}) (interface{}, error)

EvaluateFunction 求值函数

type Interpreter

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

func NewInterpreter

func NewInterpreter(env *Environment) *Interpreter

func (*Interpreter) Eval

func (interp *Interpreter) Eval(node ast.Node) ast.Node

type ReturnValue added in v0.3.0

type ReturnValue struct {
	Value object.Value
}

func (*ReturnValue) Interface added in v0.3.0

func (r *ReturnValue) Interface() any

func (*ReturnValue) Text added in v0.3.0

func (r *ReturnValue) Text() string

func (*ReturnValue) Type added in v0.3.0

func (r *ReturnValue) Type() object.Type

type Variable

type Variable struct {
	Name     string
	DeclType object.Type
	Value    object.Value
	Scope    token.Token
	Node     ast.Node
}

func (*Variable) Assign

func (v *Variable) Assign(newValue object.Value) error

func (*Variable) CanAssign

func (v *Variable) CanAssign(newValue object.Value) bool

type VariableInfo

type VariableInfo struct {
	Value    object.Value
	Scope    token.Token // CONST, VAR, LET
	ReadOnly bool        // 是否为只读(const 变量)
}

VariableInfo 存储变量的详细信息

type WarpValue added in v0.3.0

type WarpValue struct {
	AST ast.Node
}

func (*WarpValue) Interface added in v0.3.0

func (w *WarpValue) Interface() any

func (*WarpValue) Text added in v0.3.0

func (w *WarpValue) Text() string

func (*WarpValue) Type added in v0.3.0

func (w *WarpValue) Type() object.Type

Jump to

Keyboard shortcuts

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