README

oboard/moonbit-eval/interpreter/core does not have a README file

#
RuntimeFunction

type RuntimeFunction = (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow

新的函数类型定义 - 统一的上下文访问

#
ControlFlow

pub suberror ControlFlow {
Raise(RuntimeValue)
Continue(Array[RuntimeValue])
Break(RuntimeValue)
Return(RuntimeValue)
Error(String)
}

#
ClosureInterpreter

pub(all) struct ClosureInterpreter {
extern_fns : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]
embedded_fns : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]
embedded_methods : Map[String, Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]]
main_pkg : RuntimePackage
current_pkg : RuntimePackage
call_stack : Array[RuntimeLocation]
}

支持引用系统和泛型的解释器

#
ClosureInterpreter::add_embedded_fn

fn ClosureInterpreter::add_embedded_fn(self : ClosureInterpreter, name : String, f : (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow) -> Unit

#
ClosureInterpreter::add_embedded_method

fn ClosureInterpreter::add_embedded_method(self : ClosureInterpreter, type_name : String, method_name : String, f : (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow) -> Unit

#
ClosureInterpreter::add_extern_fn

fn ClosureInterpreter::add_extern_fn(self : ClosureInterpreter, name : String, f : (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow) -> Unit

#
ClosureInterpreter::bind_function_parameters

支持所有参数类型:位置参数、标签参数、可选参数、问号可选参数、丢弃参数

#
ClosureInterpreter::call

调用闭包函数,使用已求值的运行时参数

#
ClosureInterpreter::call_closure

调用闭包函数,恢复捕获的环境

#
ClosureInterpreter::constants_equal

检查两个常量是否相等

#
ClosureInterpreter::constants_equal_expr

检查两个表达式是否相等(用于构造函数匹配)

#
ClosureInterpreter::create_function

#
ClosureInterpreter::define_struct_method

fn ClosureInterpreter::define_struct_method(self : ClosureInterpreter, pkg : RuntimePackage, type_name : String, method_name : String, func :
Func
) -> Unit

处理函数定义

#
ClosureInterpreter::error

fn[A] ClosureInterpreter::error(self : ClosureInterpreter, msg : String) -> A raise ControlFlow

#
ClosureInterpreter::find_pkg

fn ClosureInterpreter::find_pkg(self : ClosureInterpreter, pkg_name : String) -> RuntimePackage

#
ClosureInterpreter::format_patterns

格式化模式列表为可读字符串

#
ClosureInterpreter::get_function_type_string

fn ClosureInterpreter::get_function_type_string(self : ClosureInterpreter, func :
Func
) -> String

转换为字符串表示(带解释器支持,用于正确的类型推导)

#
ClosureInterpreter::infer_pattern_type

fn ClosureInterpreter::infer_pattern_type(_ : ClosureInterpreter, pattern :
Pattern
) -> String?

从模式中推导类型

#
ClosureInterpreter::interp_string

处理字符串插值

#
ClosureInterpreter::is_known_function

fn ClosureInterpreter::is_known_function(self : ClosureInterpreter, name : String) -> Bool

检查函数是否为已知函数(存在于任何函数映射中)

#
ClosureInterpreter::load_module

fn ClosureInterpreter::load_module(self : ClosureInterpreter, mod : RuntimeModule) -> Unit

#
ClosureInterpreter::load_package

fn ClosureInterpreter::load_package(self : ClosureInterpreter, pkg : RuntimePackage, target? : String) -> Unit

#
ClosureInterpreter::lookup_current_function

fn ClosureInterpreter::lookup_current_function(self : ClosureInterpreter) -> String

查找当前调用的函数名

#
ClosureInterpreter::match_case

检查模式是否匹配给定的运行时值

#
ClosureInterpreter::new

#
ClosureInterpreter::parse_error_type

#
ClosureInterpreter::parse_type

#
ClosureInterpreter::pattern_match

执行match表达式的模式匹配(返回RuntimeValue)

#
ClosureInterpreter::pattern_to_runtime_value

将模式转换为运行时值(用于范围检查等)

#
ClosureInterpreter::pop_scope

fn ClosureInterpreter::pop_scope(self : ClosureInterpreter) -> Unit

销毁当前作用域

#
ClosureInterpreter::push_scope

fn ClosureInterpreter::push_scope(self : ClosureInterpreter, loc : RuntimeLocation) -> Unit

创建新的作用域

#
ClosureInterpreter::runtime_value_in_range

检查 RuntimeValue 是否在指定范围内

#
ClosureInterpreter::top_eval

fn ClosureInterpreter::top_eval(self : ClosureInterpreter, code : String) -> Unit

#
ClosureInterpreter::top_func_def_to_closure

fn ClosureInterpreter::top_func_def_to_closure(self : ClosureInterpreter, pkg : RuntimePackage, func :
Impl
, name? : String) -> (String?, RuntimeValue)

处理函数声明体,创建Lambda函数

#
ClosureInterpreter::top_visit

#
ClosureInterpreter::visit

fn ClosureInterpreter::visit(self : ClosureInterpreter, node :
Expr
, expected_type? : String) -> RuntimeValue raise ControlFlow

带期望类型的访问语法树节点

#
ClosureInterpreter::visit_interp

处理字符串插值表达式 (Interp)

#
ClosureInterpreter::visit_multiline_string

处理多行字符串

#
ClosureInterpreter::visit_scoped

#
ClosureInterpreter::with_ident

fn[T] ClosureInterpreter::with_ident(self : ClosureInterpreter, long_ident :
LongIdent
, func : (RuntimePackage, String) -> T raise?) -> T raise?

#
ConstructorField

pub(all) struct ConstructorField {
name : String?
value : RuntimeValue
mutable : Bool
}

构造器字段 - 支持带标签和可变性

#
ConstructorValue

pub(all) struct ConstructorValue {
name : String
fields : Array[ConstructorField]
}

构造器值 - 包含构造器名称和字段

#
ModuleInfo

pub(all) struct ModuleInfo {
name : String
version : String?
deps : Map[String, String]?
readme : String?
repository : String?
license : String?
keywords : Array[String]?
description : String?
source : String?
} derive(ToJson,
Debug
,
FromJson
)

包元数据

#
ModuleInfo::get_zip_url

fn ModuleInfo::get_zip_url(self : ModuleInfo) -> String

#
ModuleInfo::new

fn ModuleInfo::new(name : String, version? : String, readme? : String, repository? : String, license? : String, keywords? : Array[String], description? : String, source? : String, deps? : Map[String, String]) -> ModuleInfo

模块元数据构造函数

#
RuntimeArgument

pub(all) struct RuntimeArgument {
val : RuntimeValue
kind : RuntimeArgumentKind
}

#
RuntimeArgumentKind

pub(all) enum RuntimeArgumentKind {
Positional
Labelled(String)
LabelledOption(String)
}

#
RuntimeEnvironment

pub(all) struct RuntimeEnvironment {
values : Map[String, RuntimeValue]
mutable_vars : Map[String, Bool]
parent : RuntimeEnvironment?
} derive(ToJson)

#
RuntimeEnvironment::copy

深拷贝环境 - 完全复制所有内容

#
RuntimeEnvironment::create_closure_env

fn RuntimeEnvironment::create_closure_env(self : RuntimeEnvironment) -> RuntimeEnvironment

为闭包创建捕获环境 - 实现正确的变量捕获语义

#
RuntimeEnvironment::find

fn RuntimeEnvironment::find(self : RuntimeEnvironment, name : String) -> RuntimeValue?

在解释器中查找变量

#
RuntimeEnvironment::new

fn RuntimeEnvironment::new(parent? : RuntimeEnvironment, values? : Map[String, RuntimeValue]) -> RuntimeEnvironment

#
RuntimeEnvironment::set

fn RuntimeEnvironment::set(self : RuntimeEnvironment, name : String, value : RuntimeValue) -> Unit

设置不可变变量

#
RuntimeEnvironment::set_mutable_variable

fn RuntimeEnvironment::set_mutable_variable(self : RuntimeEnvironment, name : String, value : RuntimeValue) -> Unit

设置可变变量

#
RuntimeEnvironment::update

fn RuntimeEnvironment::update(self : RuntimeEnvironment, name : String, new_value : RuntimeValue) -> Unit

在可变变量数组中查找并更新指定变量

#
RuntimeErrorType

pub(all) enum RuntimeErrorType {
ErrorType(RuntimeType)
DefaultErrorType
NoErrorType
Noraise
MaybeError(RuntimeType)
} derive(ToJson)

#
RuntimeFunctionContext

pub(all) struct RuntimeFunctionContext {
context : ClosureInterpreter
pkg : RuntimePackage
args : FixedArray[RuntimeArgument]
}

Runtime函数执行上下文 - 统一所有函数的执行环境

#
RuntimeFunctionContext::named

fn RuntimeFunctionContext::named(ctx : RuntimeFunctionContext, name : String) -> RuntimeValue?

#
RuntimeLocation

pub enum RuntimeLocation {
FunctionCall(String)
ControlFlow(String)
LetMut(String)
} derive(
Debug
)

#
RuntimeModule

pub(all) struct RuntimeModule {
meta : ModuleInfo
pkgs : Map[String, RuntimePackage]
} derive(ToJson)

#
RuntimePackage

pub(all) struct RuntimePackage {
name : String
traits : Map[String, TraitDecl]
fn_aliases : Map[String, RuntimeValue]
type_aliases : Map[String, WithType[TypeDecl]]
trait_aliases : Map[String, WithType[TraitDecl]]
stubs : Map[String, String]
type_definitions : Map[String, TypeDecl]
type_derived_traits : Map[String, Array[String]]
struct_constrs : Map[String, String]
constructors : Map[String, String]
struct_methods : Map[String, Map[String, RuntimeValue]]
trait_methods : Map[String, Map[String, RuntimeValue]]
values : Map[String, RuntimeValue]
env : RuntimeEnvironment
deps : Map[String, RuntimePackage]
files : Map[String, String]
loaded : Bool
} derive(ToJson)

#
RuntimePackage::check_type_constraint

fn RuntimePackage::check_type_constraint(_self : RuntimePackage, value : RuntimeValue, constraint :
Type
) -> Bool

检查运行时值是否满足类型约束

#
RuntimePackage::cons

fn RuntimePackage::cons(self : RuntimePackage, name : String, args : Array[RuntimeValue]) -> RuntimeValue

构造 Constructor

#
RuntimePackage::cons_with_labels

fn RuntimePackage::cons_with_labels(self : RuntimePackage, name : String, labeled_args : Array[(String?, RuntimeValue, Bool)]) -> RuntimeValue

构造带标签参数的 Constructor

#
RuntimePackage::define_trait_method

fn RuntimePackage::define_trait_method(self : RuntimePackage, trait_id : String, method_name : String, func : RuntimeValue) -> Unit

处理trait方法定义

#
RuntimePackage::find

fn RuntimePackage::find(self : RuntimePackage, name : String) -> RuntimeValue?

#
RuntimePackage::find_stub

fn RuntimePackage::find_stub(self : RuntimePackage, name : String) -> String

#
RuntimePackage::is_constructor

fn RuntimePackage::is_constructor(self : RuntimePackage, name : String) -> Bool

检查名称是否为构造函数

#
RuntimePackage::new

fn RuntimePackage::new(pkg : String, deps? : Map[String, RuntimePackage], files? : Map[String, String]) -> RuntimePackage

#
RuntimePackage::set

fn RuntimePackage::set(self : RuntimePackage, name : String, value : RuntimeValue) -> Unit

#
RuntimeType

impl Eq for RuntimeType
impl Show for RuntimeType

#
RuntimeType::any

#
RuntimeType::array

fn RuntimeType::array() -> RuntimeType

#
RuntimeType::array_view

fn RuntimeType::array_view() -> RuntimeType

#
RuntimeType::bigint

fn RuntimeType::bigint() -> RuntimeType

#
RuntimeType::bool

fn RuntimeType::bool() -> RuntimeType

#
RuntimeType::byte

fn RuntimeType::byte() -> RuntimeType

#
RuntimeType::bytes

fn RuntimeType::bytes() -> RuntimeType

#
RuntimeType::char

fn RuntimeType::char() -> RuntimeType

#
RuntimeType::double

fn RuntimeType::double() -> RuntimeType

#
RuntimeType::fixed_array

fn RuntimeType::fixed_array() -> RuntimeType

#
RuntimeType::float

fn RuntimeType::float() -> RuntimeType

#
RuntimeType::hashmap

fn RuntimeType::hashmap() -> RuntimeType

#
RuntimeType::int

#
RuntimeType::int64

fn RuntimeType::int64() -> RuntimeType

#
RuntimeType::iter

fn RuntimeType::iter() -> RuntimeType

#
RuntimeType::json

fn RuntimeType::json() -> RuntimeType

#
RuntimeType::list

fn RuntimeType::list() -> RuntimeType

#
RuntimeType::map

#
RuntimeType::option

fn RuntimeType::option() -> RuntimeType

#
RuntimeType::result

fn RuntimeType::result() -> RuntimeType

#
RuntimeType::string

fn RuntimeType::string() -> RuntimeType

#
RuntimeType::string_builder

fn RuntimeType::string_builder() -> RuntimeType

#
RuntimeType::string_view

fn RuntimeType::string_view() -> RuntimeType

#
RuntimeType::tuple

fn RuntimeType::tuple() -> RuntimeType

#
RuntimeType::uint

fn RuntimeType::uint() -> RuntimeType

#
RuntimeType::uint16

fn RuntimeType::uint16() -> RuntimeType

#
RuntimeType::uint64

fn RuntimeType::uint64() -> RuntimeType

#
RuntimeType::uninitialized_array

fn RuntimeType::uninitialized_array() -> RuntimeType

#
RuntimeValue

pub(all) enum RuntimeValue {
Unit
Bool(Bool)
Int(Int, String?)
UInt(UInt)
UInt16(UInt16)
Int64(Int64)
UInt64(UInt64)
Float(Float)
Double(Double)
BigInt(
BigInt
)
Char(Char)
Byte(Byte)
String(String)
Bytes(Bytes)
StringView(StringView)
StringBuilder(StringBuilder)
HashMap(
HashMap
[RuntimeValue, RuntimeValue])
Tuple(Array[RuntimeValue])
Array(Array[RuntimeValue])
FixedArray(FixedArray[RuntimeValue])
ArrayView(ArrayView[RuntimeValue])
UninitializedArray(UninitializedArray[RuntimeValue])
Map(Map[RuntimeValue, RuntimeValue])
Object(WithType[Map[String, RuntimeValue]])
Fn(WithType[(RuntimeFunctionContext) -> RuntimeValue raise ControlFlow])
Constructor(WithType[ConstructorValue])
Exception(String)
Iter(Iter[RuntimeValue])
Iter2(Iter2[RuntimeValue, RuntimeValue])
Json(Json)
}

运行时值 - 解释器实际操作的数据类型
impl Add for RuntimeValue
impl Eq for RuntimeValue

#
RuntimeValue::from_constant_with_type

fn RuntimeValue::from_constant_with_type(c :
Constant
, expected_type : String?) -> RuntimeValue

带期望类型的常量创建函数

#
RuntimeValue::from_option

fn RuntimeValue::from_option(val : RuntimeValue?) -> RuntimeValue

#
RuntimeValue::from_pattern

将模式转换为值(用于范围匹配)

#
RuntimeValue::from_result

fn RuntimeValue::from_result(val : Result[RuntimeValue, RuntimeValue]) -> RuntimeValue

#
RuntimeValue::get_type

fn RuntimeValue::get_type(self : RuntimeValue) -> RuntimeType

根据运行时值推断类型

#
RuntimeValue::is_mutable

fn RuntimeValue::is_mutable(self : RuntimeValue) -> Bool

检查值是否为可变类型

#
RuntimeValue::is_reference

fn RuntimeValue::is_reference(self : RuntimeValue) -> Bool

检查值是否为引用类型

#
RuntimeValue::iter2

为 RuntimeValue 实现 iter2() 方法,返回双值迭代器 根据 iter2.mbt 中的 iter2_iter_fn,应该返回 Iter,其中每个元素是元组

#
RuntimeValue::overload_array_literal

fn RuntimeValue::overload_array_literal(self : RuntimeValue, expected_type : String) -> RuntimeValue

重载数组字面量 - 支持组合重载如[1,2,3] -> Bytes

#
RuntimeValue::overload_literal

fn RuntimeValue::overload_literal(self : RuntimeValue, expected_type : String) -> RuntimeValue

重载字面量转换 - 将默认类型的RuntimeValue转换为期望的类型 遵循MoonBit重载字面量规则,同时支持模式匹配中的隐式转换

#
TraitDecl

type TraitDecl

Wrapper around @syntax.TraitDecl with placeholder ToJson implementation.

#
TypeDecl

type TypeDecl

Wrapper around @syntax.TypeDecl with placeholder ToJson implementation and optional constructor information introduced since 0.8.0.

#
WithType

pub struct WithType[T] {
val : T
ty : RuntimeType
} derive(ToJson)

带类型信息的值包装器

#
array_methods

let array_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
array_view_methods

let array_view_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
bytes_methods

let bytes_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
check_type_constraint2

fn check_type_constraint2(value : RuntimeType, constraint :
Type
) -> Bool

#
error

#callsite(autofill(loc))
fn[A] error(msg : String, loc~ : SourceLoc) -> A raise ControlFlow

#
extract_type_name

fn extract_type_name(ty :
Type
) -> String

从@syntax.Type中提取简单的类型名

#
fixedarray_methods

let fixedarray_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
fs_methods

let fs_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
fs_package

let fs_package : RuntimePackage

#
hash_map_methods

let hash_map_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
int_embedded_code

let int_embedded_code : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
int_methods

let int_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
iter2_methods

let iter2_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

Iter2 内置方法映射

#
iter_methods

let iter_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
load_package_dir

fn load_package_dir(pkg_name : String, path : String) -> RuntimePackage?

#
manualUnescape

fn manualUnescape(input : StringView, buf : StringBuilder) -> Unit

#
map_methods

let map_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
option_methods

let option_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
parse_code_to_expr

fn parse_code_to_expr(code : String) -> Result[
Expr
, String]

#
parse_code_to_impl

fn parse_code_to_impl(code : String) -> Result[
Impl
, String]

#
runtime_value_infix

fn runtime_value_infix(op : String, lhs : RuntimeValue, rhs : RuntimeValue) -> RuntimeValue

RuntimeValue 之间的中缀运算

#
string_embedded_code

let string_embedded_code : Map[String, (RuntimeFunctionContext) -> RuntimeValue raise ControlFlow]

#
type_to_string

fn type_to_string(ty :
Type
) -> String