Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation: add helpers for marimo things to be shared across notebooks #3712

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions docs/marimo/linalg_snitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ def _():
return (mo,)


@app.cell
def _():
import xdsl.utils.marimo as xmo
return (xmo,)


@app.cell
def _(mo):
mo.md(
Expand Down Expand Up @@ -360,13 +366,13 @@ def _(mo):


@app.cell
def _(asm_html, mo, riscv_asm_module, riscv_code):
def _(mo, riscv_asm_module, riscv_code, xmo):
riscv_asm = riscv_code(riscv_asm_module)

mo.md(f"""\
**RISC-V Assembly:**

{asm_html(riscv_asm)}
{xmo.asm_html(riscv_asm)}
"""
)
return (riscv_asm,)
Expand Down Expand Up @@ -458,13 +464,13 @@ def _(k, m, mo, n):


@app.cell
def _(asm_html, mo, riscv_code, snitch_asm_module):
def _(mo, riscv_code, snitch_asm_module, xmo):
snitch_asm = riscv_code(snitch_asm_module)

mo.md(f"""\
**Snitch Assembly:**

{asm_html(snitch_asm)}
{xmo.asm_html(snitch_asm)}
"""
)
return (snitch_asm,)
Expand Down Expand Up @@ -666,19 +672,14 @@ def format_row(key: str, *values: str):


@app.cell
def _(ModuleOp, mo):
def _(ModuleOp):
import html as htmllib

def module_html(module: ModuleOp) -> str:
return f"""\
<div style="overflow-y: scroll; height:400px;"><small><code style="white-space: pre-wrap;">{htmllib.escape(str(module))}</code></small></div>
"""

def asm_html(asm: str) -> mo.Html:
return mo.ui.code_editor(
asm, language="python", disabled=True
)
return asm_html, htmllib, module_html
return htmllib, module_html


@app.cell
Expand Down
8 changes: 8 additions & 0 deletions xdsl/utils/marimo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import marimo as mo


def asm_html(asm: str) -> mo.Html:
"""
Returns a Marimo-optimised representation of the assembly code passed in.
"""
return mo.ui.code_editor(asm, language="python", disabled=True)
Loading