Skip to content

Commit 2818a49

Browse files
committed
ansi colors
1 parent 38a4f38 commit 2818a49

File tree

1 file changed

+24
-18
lines changed
  • docs/src/lectures/lecture_06

1 file changed

+24
-18
lines changed

docs/src/lectures/lecture_06/lab.md

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,19 @@ In some cases the compiler uses loop unrolling[^1] optimization to speed up loop
124124
nothing #hide
125125
```
126126

127-
```@ansi lab06_intro
128-
@code_llvm debuginfo=:none polynomial(a,x)
129-
@code_llvm debuginfo=:none polynomial(ac,x)
130-
```
131-
132127
More than 2x speedup
133-
```@ansi lab06_intro
128+
```@repl lab06_intro
134129
@btime polynomial($a,$x)
135130
@btime polynomial($ac,$x)
136131
```
137132

133+
```@ansi lab06_intro
134+
@code_llvm debuginfo=:none polynomial(a,x)
135+
@code_llvm debuginfo=:none polynomial(ac,x)
136+
```
137+
138+
139+
138140
### Recursion inlining depth
139141
Inlining[^2] is another compiler optimization that allows us to speed up the code by avoiding function calls. Where applicable compiler can replace `f(args)` directly with the function body of `f`, thus removing the need to modify stack to transfer the control flow to a different place. This is yet another optimization that may improve speed at the expense of binary size.
140142

@@ -201,9 +203,9 @@ Inlining[^2] is another compiler optimization that allows us to speed up the cod
201203
nothing #hide
202204
```
203205

204-
```@ansi lab06_intro
205-
@code_typed debuginfo=:none polynomial(a,x)
206-
```
206+
```@ansi lab06_intro
207+
@code_typed debuginfo=:none polynomial(a,x)
208+
```
207209

208210

209211
## AST manipulation: The first steps to metaprogramming
@@ -290,7 +292,7 @@ Following up on the more general substitution of variables in an expression from
290292
nothing #hide
291293
```
292294
Given a function `replace_i`, which replaces variables `i` for `k` in an expression like the following
293-
```@ansi lab06_meta
295+
```@repl lab06_meta
294296
ex = :(i + i*i + y*i - sin(z))
295297
@test replace_i(ex) == :(k + k*k + y*k - sin(z))
296298
```
@@ -305,16 +307,20 @@ Following up on the more general substitution of variables in an expression from
305307

306308
!!! details
307309
The naive solution
308-
```@ansi lab06_meta
310+
```@repl lab06_meta
309311
sreplace_i(s) = replace(s, 'i' => 'k')
310-
@test Meta.parse(sreplace_i(s)) == replace_i(Meta.parse(s))
311-
```
312-
does not work in this simple case, because it will replace "i" inside the `sin(z)` expression. We can play with regular expressions to obtain something, that is more robust
313-
```@ansi lab06_meta
314-
sreplace_i(s) = replace(s, r"([^\w]|\b)i(?=[^\w]|\z)" => s"\1k")
315-
@test Meta.parse(sreplace_i(s)) == replace_i(Meta.parse(s))
316312
```
317-
however the code may now be harder to read. Thus it is preferable to use the parsed AST when manipulating Julia's code.
313+
314+
```@ansi lab06_meta
315+
@test Meta.parse(sreplace_i(s)) == replace_i(Meta.parse(s))
316+
```
317+
does not work in this simple case, because it will replace "i" inside the `sin(z)` expression. We can play with regular expressions to obtain something, that is more robust
318+
319+
```@ansi lab06_meta
320+
sreplace_i(s) = replace(s, r"([^\w]|\b)i(?=[^\w]|\z)" => s"\1k")
321+
@test Meta.parse(sreplace_i(s)) == replace_i(Meta.parse(s))
322+
```
323+
however the code may now be harder to read. Thus it is preferable to use the parsed AST when manipulating Julia's code.
318324

319325
If the exercises so far did not feel very useful let's focus on one, that is similar to a part of the [`IntervalArithmetics.jl`](https://github.com/JuliaIntervals/IntervalArithmetic.jl) pkg.
320326

0 commit comments

Comments
 (0)