interpreter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 12 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.

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) Get

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

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

func (*Environment) GetScope

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

GetScope 获取变量的作用域

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() *Interpreter

func (*Interpreter) Eval

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

func (*Interpreter) EvalModule

func (interp *Interpreter) EvalModule(module core.Module) error

EvalModule 执行模块

func (*Interpreter) ExecuteMain

func (interp *Interpreter) ExecuteMain(mainFile string) error

ExecuteMain 执行主模块

func (*Interpreter) GetEnvironment

func (interp *Interpreter) GetEnvironment() *Environment

GetEnvironment 获取环境

func (*Interpreter) LoadModule

func (interp *Interpreter) LoadModule(modulePath string) (core.Module, error)

LoadModule 加载模块(支持缓存)

type ModuleSystem

type ModuleSystem interface {
	// 加载模块
	LoadModule(path string) (core.Module, error)

	// 解析符号(跨模块查找)
	ResolveSymbol(name string, currentModule string) (Symbol, error)

	// 获取模块
	GetModule(name string) (core.Module, bool)
}

type Symbol

type Symbol struct {
	Name   string
	Value  object.Value
	Type   object.Type
	Module string // 所属模块
	Kind   SymbolKind
}

Symbol 表示一个符号

type SymbolKind

type SymbolKind int
const (
	SymbolValue SymbolKind = iota
	SymbolType
	SymbolFunction
	SymbolModule
)

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 存储变量的详细信息

Jump to

Keyboard shortcuts

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