Sign in

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

    RuntimeFunction

    typealias (RuntimeFunctionContext) -> RuntimeValue as RuntimeFunction
    新的函数类型定义 - 统一的上下文访问

    ClosureInterpreter

    pub(all) struct ClosureInterpreter {
    extern_fns : Map[String, (RuntimeFunctionContext) -> RuntimeValue]
    embedded_fns : Map[String, (RuntimeFunctionContext) -> RuntimeValue]
    embedded_methods : Map[String, Map[String, (RuntimeFunctionContext) -> RuntimeValue]]
    env : RuntimeEnvironment
    state : InterpreterState
    modules : Map[String, RuntimeModule]
    }
    支持引用系统和泛型的解释器

    ClosureInterpreter::add_embedded_fn

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

    ClosureInterpreter::add_embedded_method

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

    ClosureInterpreter::add_extern_fn

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

    ClosureInterpreter::bind_function_parameters

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

    ClosureInterpreter::bind_function_parameters_runtime

    ClosureInterpreter::call_closure

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

    ClosureInterpreter::constants_equal

    检查两个常量是否相等

    ClosureInterpreter::constants_equal_expr

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

    ClosureInterpreter::execute_function_call

    处理用户定义函数的调用,包括作用域管理和参数绑定

    ClosureInterpreter::execute_match

    执行match表达式的模式匹配

    ClosureInterpreter::execute_match_runtime

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

    ClosureInterpreter::get_function_type_string

    fn ClosureInterpreter::get_function_type_string(self : ClosureInterpreter, value : RuntimeValue) -> String
    将RuntimeValue转换为字符串表示(带解释器支持,用于正确的类型推导)

    ClosureInterpreter::is_known_function

    fn ClosureInterpreter::is_known_function(self : ClosureInterpreter, name : String) -> Bool
    检查函数是否为已知函数(存在于任何函数映射中)

    ClosureInterpreter::new

    fn ClosureInterpreter::new(core? : Bool) -> ClosureInterpreter

    ClosureInterpreter::pattern_matches

    检查值是否匹配模式

    ClosureInterpreter::pattern_to_value

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

    ClosureInterpreter::pop_scope

    fn ClosureInterpreter::pop_scope(self : ClosureInterpreter) -> Unit
    销毁当前作用域

    ClosureInterpreter::push_scope

    fn ClosureInterpreter::push_scope(self : ClosureInterpreter) -> Unit
    创建新的作用域

    ClosureInterpreter::start

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

    ClosureInterpreter::stop

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

    ClosureInterpreter::top_visit

    ClosureInterpreter::value_in_range

    检查值是否在范围内

    ClosureInterpreter::visit

    新的优化版本:直接返回 RuntimeValue

    InterpreterState

    pub(all) enum InterpreterState {
    Running
    Stopped
    }
    解释器状态

    ModuleMeta

    pub struct ModuleMeta {
    name : String
    version : String?
    deps : Map[String, String]?
    readme : String?
    repository : String?
    license : String?
    keywords : Array[String]?
    description : String?
    source : String?
    }
    模块元数据
    impl Show for ModuleMeta

    ModuleMeta::new

    fn ModuleMeta::new(name : String, version? : String, readme? : String, repository? : String, license? : String, keywords? : Array[String], description? : String, source? : String, deps? : Map[String, String]) -> ModuleMeta
    模块元数据构造函数

    RuntimeArgument

    pub(all) struct RuntimeArgument {
    value : RuntimeValue
    kind :
    ArgumentKind

    }

    RuntimeEnvironment

    pub(all) struct RuntimeEnvironment {
    traits : Map[String,
    TraitDecl
    ]
    fn_aliases : Map[String, String]
    type_definitions : Map[String,
    TypeDecl
    ]
    struct_methods : Map[String, Map[String,
    Func
    ]]
    type_environment : TypeEnvironment
    values : Map[String, RuntimeValue]
    mutable_vars : Map[String, Bool]
    parent : RuntimeEnvironment?
    deps : Map[String, RuntimeModule]
    }

    RuntimeEnvironment::copy

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

    RuntimeEnvironment::create_closure_env

    fn RuntimeEnvironment::create_closure_env(self : RuntimeEnvironment) -> RuntimeEnvironment
    为闭包创建捕获环境 - 实现正确的变量捕获语义

    RuntimeEnvironment::current_scope

    fn RuntimeEnvironment::current_scope(self : RuntimeEnvironment) -> Map[String, RuntimeValue]
    获取当前变量作用域

    RuntimeEnvironment::define_struct_method

    fn RuntimeEnvironment::define_struct_method(self : RuntimeEnvironment, type_name : String, method_name : String, func :
    Func
    ) -> Unit

    RuntimeEnvironment::find

    fn RuntimeEnvironment::find(self : RuntimeEnvironment, name : String) -> RuntimeValue
    在解释器中查找变量

    RuntimeEnvironment::find_fn_alias

    fn RuntimeEnvironment::find_fn_alias(self : RuntimeEnvironment, name : String) -> String

    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::top_func_def_to_closure

    处理函数声明体,创建Lambda函数并注册到环境中

    RuntimeEnvironment::update

    fn RuntimeEnvironment::update(self : RuntimeEnvironment, name : String, new_value : RuntimeValue) -> Unit
    在可变变量数组中查找并更新指定变量

    RuntimeEnvironment::with_ident

    fn[T] RuntimeEnvironment::with_ident(self : RuntimeEnvironment, long_ident :
    LongIdent
    , func : (RuntimeEnvironment, String) -> T) -> T

    RuntimeFunctionContext

    pub(all) struct RuntimeFunctionContext {
    context : ClosureInterpreter
    arguments : Array[RuntimeArgument]
    }
    Runtime函数执行上下文 - 统一所有函数的执行环境

    RuntimeModule

    pub(all) struct RuntimeModule {
    meta : ModuleMeta
    env : RuntimeEnvironment
    }

    RuntimeModule::new

    fn RuntimeModule::new(pkg : String, builder : (RuntimeEnvironment, (String) -> RuntimeValue) -> Map[String, RuntimeValue]) -> RuntimeModule

    RuntimeValue

    pub(all) enum RuntimeValue {
    Unit
    Bool(Bool)
    Int(Int)
    UInt(UInt)
    Int64(Int64)
    UInt64(UInt64)
    Float(Float)
    Double(Double)
    BigInt(
    BigInt
    )
    Char(Char)
    Byte(Byte)
    String(String)
    Tuple(Array[RuntimeValue])
    Array(Array[RuntimeValue])
    Map(Map[RuntimeValue, RuntimeValue])
    Struct(Ref[Map[String, RuntimeValue]])
    Closure(
    Func
    , RuntimeEnvironment)
    Constructor(String, Array[RuntimeValue])
    Break(RuntimeValue?)
    Continue(Array[RuntimeValue])
    Return(RuntimeValue)
    Exception(String)
    TraitObject(RuntimeValue, String)
    }
    运行时值 - 解释器实际操作的数据类型
    impl Add for RuntimeValue
    impl Eq for RuntimeValue

    RuntimeValue::from_expr

    将@syntax.Expr转换为RuntimeValue

    RuntimeValue::from_option

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

    RuntimeValue::is_mutable

    fn RuntimeValue::is_mutable(self : RuntimeValue) -> Bool
    检查值是否为可变类型

    RuntimeValue::is_reference

    fn RuntimeValue::is_reference(self : RuntimeValue) -> Bool
    检查值是否为引用类型

    RuntimeValue::to_expr

    将RuntimeValue转换为表达式(用于输出)

    TypeEnvironment

    pub struct TypeEnvironment {
    type_bindings : Map[String, String]
    parent : TypeEnvironment?
    }
    泛型类型环境 - 跟踪类型变量绑定

    array_methods

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

    compare

    fn[T : Compare + Eq] compare(left : T, right : T, op : String) ->
    Constant

    error

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

    eval_double_op

    fn eval_double_op(left : Double, right : Double, op : String) ->
    Constant

    eval_float_op

    fn eval_float_op(left : Double, right : Double, op : String) ->
    Constant

    eval_int64_op

    fn eval_int64_op(left : Int64, right : Int64, op : String) ->
    Constant

    eval_int_op

    fn eval_int_op(left : Int, right : Int, op : String) ->
    Constant

    eval_uint64_op

    fn eval_uint64_op(left : UInt64, right : UInt64, op : String) ->
    Constant

    eval_uint_op

    fn eval_uint_op(left : UInt, right : UInt, op : String) ->
    Constant

    infer_type_from_constant

    fn infer_type_from_constant(c :
    Constant
    ) -> String
    从常量推导类型

    int_embedded_code

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

    int_methods

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

    is_comparison_op

    fn is_comparison_op(op : String) -> Bool

    option_methods

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

    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 之间的中缀运算 - 消除对 constant_infix 的依赖

    string_embedded_code

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

    string_methods

    let string_methods : Map[String, (RuntimeFunctionContext) -> RuntimeValue]

    type_to_string

    fn type_to_string(ty :
    Type
    ) -> String