moon2dart

    MoonBit → Dart transpiler — 让 MoonBit 代码跑在 Flutter 上

    transpiler
    dart
    moonbit
    flutter
    code-generation
    Download zip
    Author
    Version
    0.8.0
    License
    Apache-2.0
    Last updated
    5 hours ago
    Downloads
    3

    #walkzzz/moon2dart

    MoonBit → Dart transpiler — 让 MoonBit 代码跑在 Flutter 上。

    #快速开始

    ///|
    let prog = [
    @ast.DFn(
    "add",
    [("a", @ast.MInt), ("b", @ast.MInt)],
    @ast.MInt,
    @ast.EBinOp("+", @ast.EVar("a"), @ast.EVar("b")),
    ),
    ]

    ///|
    let dart_code = @moon2dart.transpile(prog)

    #API

    • transpile(Array[@ast.MoonDecl]) -> String — 转换为 Dart 代码
    • transpile_decl(@ast.MoonDecl) -> String — 转换单个声明
    • transpile_expr(@ast.MoonExpr) -> String — 转换表达式
    • transpile_type(@ast.MoonType) -> String — 类型映射

    #支持后端

    wasm / wasm-gc / js / native

    #许可证

    Apache-2.0

    reverse_transpile

    fn reverse_transpile(decls : Array[
    DartDecl
    ]) -> String

    反向转换 — Dart AST 声明数组 → MoonBit 源码字符串。

    reverse_transpile_decl

    fn reverse_transpile_decl(d :
    DartDecl
    ) -> String

    便捷:Dart 声明 → MoonBit 声明字符串。

    reverse_transpile_expr

    fn reverse_transpile_expr(e :
    DartExpr
    ) -> String

    便捷:Dart 表达式 → MoonBit 表达式字符串。

    reverse_transpile_source

    fn reverse_transpile_source(src : String) -> String

    反向转换管线 — Dart 源码字符串 → MoonBit 源码字符串。

    reverse_transpile_type

    fn reverse_transpile_type(t :
    DartType
    ) -> String

    便捷:Dart 类型 → MoonBit 类型字符串。

    transpile

    fn transpile(decls : Array[
    MoonDecl
    ]) -> String

    transpile 编排入口 — 将 MoonBit AST 声明数组转为 Dart 代码字符串。

    transpile_decl

    fn transpile_decl(decl :
    MoonDecl
    ) -> String

    便捷:转换单个声明为 Dart 代码字符串。

    transpile_expr

    fn transpile_expr(expr :
    MoonExpr
    ) -> String

    便捷:转换表达式为 Dart 代码字符串。

    transpile_flutter

    fn transpile_flutter(decls : Array[
    MoonDecl
    ]) -> String

    Flutter 转换入口 — 将 MoonBit AST 声明数组转为完整 Flutter 应用代码。

    transpile_source

    fn transpile_source(src : String) -> String

    单文件转换管线 — MoonBit 源码字符串 → Dart 代码字符串。

    管线:source → Lexer::tokenize → Parser::parse_program → emit_dart_program

    transpile_source_flutter

    fn transpile_source_flutter(src : String) -> String

    单文件 Flutter 转换管线 — MoonBit 源码字符串 → Flutter 应用代码字符串。

    transpile_source_pure

    fn transpile_source_pure(src : String) -> String

    单文件转换管线(纯子集模式,跳过 FFI 声明)。

    transpile_source_with_lib

    fn transpile_source_with_lib(src : String, lib_name : String) -> String

    单文件转换管线(可指定 FFI 库名)。

    transpile_type

    fn transpile_type(t :
    MoonType
    ) -> String

    便捷:MoonBit 类型 → Dart 类型字符串。

    transpile_with_lib

    fn transpile_with_lib(decls : Array[
    MoonDecl
    ], lib_name : String) -> String

    transpile 编排入口(可指定 FFI 库名)。

    Source Files