moon2dart

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

    transpiler
    dart
    moonbit
    flutter
    code-generation
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    11 days ago
    Downloads
    34

    #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 — Dart AST declarations to MoonBit source string

    reverse_transpile_decl

    fn reverse_transpile_decl(d :
    DartDecl
    ) -> String

    便捷:Dart 声明 → MoonBit 声明字符串 | Convenience: Dart declaration to MoonBit declaration string

    reverse_transpile_expr

    fn reverse_transpile_expr(e :
    DartExpr
    ) -> String

    便捷:Dart 表达式 → MoonBit 表达式字符串 | Convenience: Dart expression to MoonBit expression string

    reverse_transpile_source

    fn reverse_transpile_source(src : String) -> String raise
    Moon2DartError

    反向转换管线 — Dart 源码字符串 → MoonBit 源码字符串 | Reverse pipeline — Dart source string to MoonBit source string

    reverse_transpile_type

    fn reverse_transpile_type(t :
    DartType
    ) -> String

    便捷:Dart 类型 → MoonBit 类型字符串 | Convenience: Dart type to MoonBit type string

    transpile

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

    transpile 编排入口 — 将 MoonBit AST 声明数组转为 Dart 代码字符串 | Transpile orchestration entry — convert MoonBit AST declarations to Dart code string

    transpile_decl

    fn transpile_decl(decl :
    MoonDecl
    ) -> String

    便捷:转换单个声明为 Dart 代码字符串 | Convenience: transpile a single declaration to Dart code string

    transpile_expr

    fn transpile_expr(expr :
    MoonExpr
    ) -> String

    便捷:转换表达式为 Dart 代码字符串 | Convenience: transpile an expression to Dart code string

    transpile_flutter

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

    Flutter 转换入口 — 将 MoonBit AST 声明数组转为完整 Flutter 应用代码 | Flutter transpile entry — convert MoonBit AST declarations to full Flutter app code

    transpile_source

    fn transpile_source(src : String) -> String raise
    Moon2DartError

    单文件转换管线 — MoonBit 源码字符串 → Dart 代码字符串 | Single-file pipeline — MoonBit source string to Dart code string 管线:source → Lexer::tokenize → Parser::parse_program → emit_dart_program | Pipeline: source → Lexer::tokenize → Parser::parse_program → emit_dart_program

    transpile_source_flutter

    fn transpile_source_flutter(src : String) -> String raise
    Moon2DartError

    单文件 Flutter 转换管线 — MoonBit 源码字符串 → Flutter 应用代码字符串 | Single-file Flutter pipeline — MoonBit source string to Flutter app code string

    transpile_source_pure

    fn transpile_source_pure(src : String) -> String raise
    Moon2DartError

    单文件转换管线(纯子集模式,跳过 FFI 声明)| Single-file pipeline (pure subset mode, skips FFI declarations)

    transpile_source_strict

    fn transpile_source_strict(src : String) -> String raise
    Moon2DartError

    严格模式转换管线 — L4 类型 raise 错误,L3 类型保留诊断注释 | Strict mode pipeline — L4 types raise error, L3 types keep diagnostic comments

    transpile_source_with_lib

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

    单文件转换管线(可指定 FFI 库名)| Single-file pipeline (with configurable FFI library name)

    transpile_type

    fn transpile_type(t :
    MoonType
    ) -> String

    便捷:MoonBit 类型 → Dart 类型字符串 | Convenience: MoonBit type to Dart type string

    transpile_with_lib

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

    transpile 编排入口(可指定 FFI 库名)| Transpile orchestration entry (with configurable FFI library name)