Skip to content

Commit

Permalink
documentation: add helpers for marimo things to be shared across note…
Browse files Browse the repository at this point in the history
…books (#3712)

We want to have more than one notebook, and a consistent way of showing
things in them. I think a helpers file would be a good way to do that.
  • Loading branch information
superlopuh authored Jan 7, 2025
1 parent b943df3 commit a0d424d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
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)

0 comments on commit a0d424d

Please sign in to comment.