mirror of
https://github.com/alex-s168/website.git
synced 2025-09-10 01:05:07 +02:00
c
This commit is contained in:
17
common.typ
17
common.typ
@@ -86,6 +86,10 @@
|
||||
html-opt-elem("span", attrs, content)
|
||||
}
|
||||
|
||||
#let html-div(attrs, content) = {
|
||||
html-opt-elem("div", attrs, content)
|
||||
}
|
||||
|
||||
#let html-bold(content) = {
|
||||
context if is-html() {
|
||||
html.elem("b", content)
|
||||
@@ -98,12 +102,16 @@
|
||||
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)[
|
||||
#underline[#link(target, link-text)]
|
||||
#link(target, link-text)
|
||||
]
|
||||
|
||||
#let flink(target, link-text) = text(fill: blue)[
|
||||
#underline[#link(target, link-text)]
|
||||
#link(target, link-text)
|
||||
#footnote[#text(fill: blue)[#link(target)]]
|
||||
]
|
||||
|
||||
@@ -239,12 +247,13 @@
|
||||
}]
|
||||
}
|
||||
|
||||
// TODO: move to component
|
||||
#let table-of-contents() = {
|
||||
html-style(class:"table-of-contents", "", box(
|
||||
stroke: black,
|
||||
stroke: 1.2pt+black,
|
||||
radius: 2pt,
|
||||
inset: 3%,
|
||||
[Table of contents\
|
||||
[#underline[Table of contents]\
|
||||
#let idx = state("stupid-gen-page-state", 0);
|
||||
|
||||
#context gen-tree-from-headings(query(heading),
|
||||
|
@@ -31,29 +31,28 @@
|
||||
|
||||
#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 {
|
||||
// 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 {
|
||||
#show raw: it => if is-nano == true {
|
||||
html-code(text(it))
|
||||
} else {
|
||||
box(
|
||||
stroke: black,
|
||||
radius: 2pt,
|
||||
inset: if is-html() { 1.4pt } else { 5pt },
|
||||
outset: 0pt,
|
||||
baseline: 3.1pt,
|
||||
text(it)
|
||||
)
|
||||
if it.block {
|
||||
html-style-div("margin-top:4pt;",
|
||||
block(
|
||||
stroke: black,
|
||||
radius: 2pt,
|
||||
inset: if is-html() { 1.4pt } else { 5pt },
|
||||
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 => {
|
||||
@@ -64,16 +63,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
#show underline: it => {
|
||||
#show block: it => {
|
||||
context if is-html() {
|
||||
// TODO: NOOO
|
||||
html.elem("u", it.body)
|
||||
html.elem("div", attrs: (style: css-style(it)))[#it.body]
|
||||
} else {
|
||||
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)
|
||||
|
||||
@@ -81,6 +79,8 @@
|
||||
#show footnote.entry: it => if is-web or is-nano { [] } else { it }
|
||||
|
||||
#context if is-html() and not is-nano {
|
||||
let link-color = "3f51b5";
|
||||
|
||||
html.elem("style", "
|
||||
@font-face {
|
||||
font-family: 'DejaVu Sans Mono';
|
||||
@@ -164,6 +164,16 @@ html.elem("style", "
|
||||
margin-bottom: 0px;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #"+link-color+";
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #"+link-color+";
|
||||
text-decoration: none;
|
||||
}
|
||||
")
|
||||
}
|
||||
|
||||
|
@@ -71,23 +71,23 @@
|
||||
|
||||
#section[
|
||||
An example is Cranelift's ISLE DSL:
|
||||
#blocking-code(```lisp
|
||||
```lisp
|
||||
;; x ^ x == 0.
|
||||
(rule (simplify (bxor (ty_int ty) x x))
|
||||
(subsume (iconst_u ty 0)))
|
||||
```)
|
||||
```
|
||||
]
|
||||
|
||||
#section[
|
||||
Another example is tinygrad's pattern system:
|
||||
#blocking-code(```python
|
||||
```python
|
||||
(UPat(Ops.AND, src=(
|
||||
UPat.var("x"),
|
||||
UPat(Ops.SHL, src=(
|
||||
UPat.const(1),
|
||||
UPat.var("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.
|
||||
]
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
#section[
|
||||
== Examples
|
||||
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) {
|
||||
%arg0 = pdl.operand
|
||||
%arg1 = pdl.operand
|
||||
@@ -147,7 +147,7 @@
|
||||
pdl.replace %op with %new_op
|
||||
}
|
||||
}
|
||||
```)
|
||||
```
|
||||
]
|
||||
|
||||
#section[
|
||||
@@ -264,7 +264,7 @@
|
||||
The main problem is ordering the patterns.
|
||||
|
||||
As an example, consider these three patterns:
|
||||
#blocking-code(```lisp
|
||||
```lisp
|
||||
;; A
|
||||
(add x:Const y) => (add y x)
|
||||
|
||||
@@ -273,19 +273,19 @@
|
||||
|
||||
;; C
|
||||
(add x 1) => (inc x)
|
||||
```)
|
||||
```
|
||||
]
|
||||
|
||||
#section[
|
||||
Now what should the compiler do when it sees this:
|
||||
#blocking-code(```lisp
|
||||
```lisp
|
||||
(sub (add 5 1) 2)
|
||||
```)
|
||||
```
|
||||
]
|
||||
|
||||
#section[
|
||||
All three patterns would match:
|
||||
#blocking-code(```lisp
|
||||
```lisp
|
||||
;; apply A
|
||||
(sub (add 5 1) 2) => (sub (add 1 5) 2)
|
||||
;; only B applies now
|
||||
@@ -299,7 +299,7 @@
|
||||
;; atlernatively apply C
|
||||
(sub (add 5 1) 2) => (sub (inc 5) 2)
|
||||
;; nothing applies anymore
|
||||
```)
|
||||
```
|
||||
]
|
||||
|
||||
#section[
|
||||
|
Reference in New Issue
Block a user