This commit is contained in:
2025-07-26 01:49:52 +02:00
parent 969bcb5fb2
commit 36f475df48
3 changed files with 60 additions and 41 deletions

View File

@@ -86,6 +86,10 @@
html-opt-elem("span", attrs, content) html-opt-elem("span", attrs, content)
} }
#let html-div(attrs, content) = {
html-opt-elem("div", attrs, content)
}
#let html-bold(content) = { #let html-bold(content) = {
context if is-html() { context if is-html() {
html.elem("b", content) html.elem("b", content)
@@ -98,12 +102,16 @@
html-span((class:class, style: style), content) html-span((class:class, style: style), content)
} }
#let html-style-div(class:"", style, content) = {
html-div((class:class, style: style), content)
}
#let slink(target, link-text) = text(fill: blue)[ #let slink(target, link-text) = text(fill: blue)[
#underline[#link(target, link-text)] #link(target, link-text)
] ]
#let flink(target, link-text) = text(fill: blue)[ #let flink(target, link-text) = text(fill: blue)[
#underline[#link(target, link-text)] #link(target, link-text)
#footnote[#text(fill: blue)[#link(target)]] #footnote[#text(fill: blue)[#link(target)]]
] ]
@@ -239,12 +247,13 @@
}] }]
} }
// TODO: move to component
#let table-of-contents() = { #let table-of-contents() = {
html-style(class:"table-of-contents", "", box( html-style(class:"table-of-contents", "", box(
stroke: black, stroke: 1.2pt+black,
radius: 2pt, radius: 2pt,
inset: 3%, inset: 3%,
[Table of contents\ [#underline[Table of contents]\
#let idx = state("stupid-gen-page-state", 0); #let idx = state("stupid-gen-page-state", 0);
#context gen-tree-from-headings(query(heading), #context gen-tree-from-headings(query(heading),

View File

@@ -31,29 +31,28 @@
#set text(font: "DejaVu Sans Mono", size: default-font-size) #set text(font: "DejaVu Sans Mono", size: default-font-size)
#show raw: it => if type(it.lang) == str and it.lang != "" and is-nano == false { #show raw: it => if is-nano == true {
// TODO: after typst fix html exporter breaking line :sob:
// context html-frame(context
box(
stroke: black,
radius: 2pt,
inset: if is-html() { 1.4pt } else { 5pt },
outset: 0pt,
baseline: 3.1pt,
text(it)
)
} else if is-nano == true {
html-code(text(it)) html-code(text(it))
} else { } else {
box( if it.block {
stroke: black, html-style-div("margin-top:4pt;",
radius: 2pt, block(
inset: if is-html() { 1.4pt } else { 5pt }, stroke: black,
outset: 0pt, radius: 2pt,
baseline: 3.1pt, inset: if is-html() { 1.4pt } else { 5pt },
text(it) outset: 0pt,
) it
))
} else {
box(
stroke: black,
radius: 2pt,
inset: if is-html() { 1.4pt } else { 5pt },
outset: 0pt,
baseline: 3.1pt,
it
)
}
} }
#show box: it => { #show box: it => {
@@ -64,16 +63,15 @@
} }
} }
#show underline: it => { #show block: it => {
context if is-html() { context if is-html() {
// TODO: NOOO html.elem("div", attrs: (style: css-style(it)))[#it.body]
html.elem("u", it.body)
} else { } else {
it it
} }
} }
#show heading: it => if is-nano { it } else { underline[#it #v(3pt)] } #show heading: it => if is-nano { it } else { underline(it + v(3pt)) }
#set underline(stroke: 1pt, offset: 2pt) #set underline(stroke: 1pt, offset: 2pt)
@@ -81,6 +79,8 @@
#show footnote.entry: it => if is-web or is-nano { [] } else { it } #show footnote.entry: it => if is-web or is-nano { [] } else { it }
#context if is-html() and not is-nano { #context if is-html() and not is-nano {
let link-color = "3f51b5";
html.elem("style", " html.elem("style", "
@font-face { @font-face {
font-family: 'DejaVu Sans Mono'; font-family: 'DejaVu Sans Mono';
@@ -164,6 +164,16 @@ html.elem("style", "
margin-bottom: 0px; margin-bottom: 0px;
display: inline; display: inline;
} }
a {
color: #"+link-color+";
text-decoration: none;
}
a:visited {
color: #"+link-color+";
text-decoration: none;
}
") ")
} }

View File

@@ -71,23 +71,23 @@
#section[ #section[
An example is Cranelift's ISLE DSL: An example is Cranelift's ISLE DSL:
#blocking-code(```lisp ```lisp
;; x ^ x == 0. ;; x ^ x == 0.
(rule (simplify (bxor (ty_int ty) x x)) (rule (simplify (bxor (ty_int ty) x x))
(subsume (iconst_u ty 0))) (subsume (iconst_u ty 0)))
```) ```
] ]
#section[ #section[
Another example is tinygrad's pattern system: Another example is tinygrad's pattern system:
#blocking-code(```python ```python
(UPat(Ops.AND, src=( (UPat(Ops.AND, src=(
UPat.var("x"), UPat.var("x"),
UPat(Ops.SHL, src=( UPat(Ops.SHL, src=(
UPat.const(1), UPat.const(1),
UPat.var("b")))), UPat.var("b")))),
lambda x,b: UOp(Ops.BIT_TEST, src=(x, b))) lambda x,b: UOp(Ops.BIT_TEST, src=(x, b)))
```) ```
Fun fact: tinygrad actually decompiles the python code inside the second element of the pair, and runs multiple optimization passes on that. Fun fact: tinygrad actually decompiles the python code inside the second element of the pair, and runs multiple optimization passes on that.
] ]
@@ -136,7 +136,7 @@
#section[ #section[
== Examples == Examples
MLIR's `pdl` dialect can be used to replace `arith.addi` with `my.add` like this: MLIR's `pdl` dialect can be used to replace `arith.addi` with `my.add` like this:
#blocking-code(```llvm ```llvm
pdl.pattern @replace_addi_with_my_add : benefit(1) { pdl.pattern @replace_addi_with_my_add : benefit(1) {
%arg0 = pdl.operand %arg0 = pdl.operand
%arg1 = pdl.operand %arg1 = pdl.operand
@@ -147,7 +147,7 @@
pdl.replace %op with %new_op pdl.replace %op with %new_op
} }
} }
```) ```
] ]
#section[ #section[
@@ -264,7 +264,7 @@
The main problem is ordering the patterns. The main problem is ordering the patterns.
As an example, consider these three patterns: As an example, consider these three patterns:
#blocking-code(```lisp ```lisp
;; A ;; A
(add x:Const y) => (add y x) (add x:Const y) => (add y x)
@@ -273,19 +273,19 @@
;; C ;; C
(add x 1) => (inc x) (add x 1) => (inc x)
```) ```
] ]
#section[ #section[
Now what should the compiler do when it sees this: Now what should the compiler do when it sees this:
#blocking-code(```lisp ```lisp
(sub (add 5 1) 2) (sub (add 5 1) 2)
```) ```
] ]
#section[ #section[
All three patterns would match: All three patterns would match:
#blocking-code(```lisp ```lisp
;; apply A ;; apply A
(sub (add 5 1) 2) => (sub (add 1 5) 2) (sub (add 5 1) 2) => (sub (add 1 5) 2)
;; only B applies now ;; only B applies now
@@ -299,7 +299,7 @@
;; atlernatively apply C ;; atlernatively apply C
(sub (add 5 1) 2) => (sub (inc 5) 2) (sub (add 5 1) 2) => (sub (inc 5) 2)
;; nothing applies anymore ;; nothing applies anymore
```) ```
] ]
#section[ #section[