Skip to content

Marimo

marimo

PrintfFunctions dataclass

Bases: InterpreterFunctions

Source code in xdsl/frontend/listlang/marimo.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@register_impls
class PrintfFunctions(InterpreterFunctions):
    def _format_arg(self, fmt_val: Any, arg: Any) -> str:
        if isa(fmt_val.type, builtin.I1):
            return "true" if arg else "false"
        return str(arg)

    @impl(PrintFormatOp)
    def run_println(
        self, interpreter: Interpreter, op: PrintFormatOp, args: tuple[Any, ...]
    ):
        pretty_args = tuple(
            self._format_arg(fmt_val, arg)
            for fmt_val, arg in zip(op.format_vals, args, strict=True)
        )

        print(
            op.format_str.data.format(*pretty_args),
            file=interpreter.file,
            end="",
        )
        return ()

run_println(interpreter: Interpreter, op: PrintFormatOp, args: tuple[Any, ...])

Source code in xdsl/frontend/listlang/marimo.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@impl(PrintFormatOp)
def run_println(
    self, interpreter: Interpreter, op: PrintFormatOp, args: tuple[Any, ...]
):
    pretty_args = tuple(
        self._format_arg(fmt_val, arg)
        for fmt_val, arg in zip(op.format_vals, args, strict=True)
    )

    print(
        op.format_str.data.format(*pretty_args),
        file=interpreter.file,
        end="",
    )
    return ()

interp(module: builtin.ModuleOp) -> str

Source code in xdsl/frontend/listlang/marimo.py
39
40
41
42
43
44
45
46
47
48
49
def interp(module: builtin.ModuleOp) -> str:
    _io = StringIO()

    _i = Interpreter(module=module, file=_io)
    _i.register_implementations(ArithFunctions())
    _i.register_implementations(ScfFunctions())
    _i.register_implementations(PrintfFunctions())
    _i.register_implementations(TensorFunctions())
    _i.run_ssacfg_region(module.body, ())

    return _io.getvalue()

rust_md(code: str) -> mo.Html

Source code in xdsl/frontend/listlang/marimo.py
52
53
def rust_md(code: str) -> mo.Html:
    return mo.md("`" * 3 + "rust\n" + code + "\n" + "`" * 3)