Skip to content

Commit 399a058

Browse files
committed
changes to toc and inline
1 parent 33ad06b commit 399a058

File tree

2 files changed

+38
-55
lines changed

2 files changed

+38
-55
lines changed

docs/docs/reference/metaprogramming/inline.md

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -58,37 +58,25 @@ If `Config.logging == false`, this will be rewritten (simplified) to
5858

5959
```scala
6060
def factorial(n: BigInt): BigInt = {
61-
/* parameters of log passed by-name (1) */
62-
def msg = s"factorial($n)"
63-
def op =
64-
if (n == 0) 1
65-
else n * factorial(n - 1)
66-
67-
/* inlined body of log (2) */
68-
op
61+
if (n == 0) 1
62+
else n * factorial(n - 1)
6963
}
7064
```
7165

72-
and if `true` it will be rewritten in the code below:
66+
and if `true` it will be rewritten to the code below:
7367

7468
```scala
7569
def factorial(n: BigInt): BigInt = {
76-
/* parameters of log passed by-name (1) */
77-
def msg = s"factorial($n)"
78-
def op =
79-
if (n == 0) 1
80-
else n * factorial(n - 1)
81-
82-
/* inlined body of log (2) */
83-
println(s"${" " * indent}start $msg")
84-
indent += 1
70+
val msgVal = s"factorial($n)"
71+
println(s"${" " * indent}start $msgVal")
72+
Logger.inline$indent += 1
8573
val result = op
86-
indent -= 1
87-
println(s"${" " * indent}$msg = $result")
74+
Logger.inline$indent -= 1
75+
println(s"${" " * indent}$msgVal = $result")
8876
result
8977
}
9078
```
91-
79+
TODO: adapt to real code.
9280
Note (1) that the arguments corresponding to the parameters `msg` and `op` of
9381
the inline method `log` are defined before the inlined body (which is in this
9482
case simply `op` (2)). By-name parameters of the inline method correspond to

docs/docs/reference/metaprogramming/toc.md

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,40 @@ title: "Overview"
66
The following pages introduce the redesign of metaprogramming in Scala. They
77
introduce the following fundamental facilities:
88

9-
1. [Inline](./inline.html) `inline` is a new soft-modifier that guarantees that
9+
1. [Inline](./inline.html) `inline` is a new modifier that guarantees that
1010
a definition will be inlined at the point of use. The primary motivation
1111
behind inline is to reduce the overhead behind function calls and access to
1212
values. The expansion will be performed by the Scala compiler during the
13-
`Typer` compiler phase. However, as opposed to inline in other ecosystems,
13+
`Typer` compiler phase. Unlike Scala's existsing
14+
As opposed to inline in some other ecosystems,
1415
inlining is not merely a request to the compiler but for Scala it is a
15-
_command_. The reason is that inlining in Scala can driver other compile-time
16-
operations too, like inline pattern matching (enabling type-level
16+
_command_. The reason is that inlining in Scala can drive other compile-time
17+
operations, like inline pattern matching (enabling type-level
1718
programming), macros (enabling compile-time, generative, metaprogramming) and
18-
runtime code generation (multi-stage programming). In this section we
19-
describe up to inline pattern matching describing the basic constructs.
19+
runtime code generation (multi-stage programming).
2020

2121
2. [Macros](./macros.html) Macros are built on two well-known fundamental
22-
operations: quotation and splicing. Quotation is expressed as `'{...}` for
23-
expressions (both forms are equivalent) and as `'[...]` for types. Splicing
24-
is expressed as `${ ... }`. Whereas inlining is driven completely by the
25-
language level features of scala (pattern matching, inline vals and
26-
definitions), macros enable is synthesize/compute code at will treating code
27-
values as first class citizens and splicing them together independently.
28-
Here, we move towards _domain-specific_ metaprogramming.
29-
30-
3. [Staging](./staging.html) Macros can be seen as distinct phase while
31-
programming. You write your regular code that will be compiled according to
32-
the semantics of the language and the macro code that is going to be
33-
"compiled" or "generated" according the intented purpose of the programmer.
34-
Staging (or Multi-Stage Programming) can be seen as taking one step further
35-
this exact concept and can make code generation depent not only on static
36-
data but also on data available at _runtime_. This splits the evaluation of
37-
the program in many phases or ... stages, thus the "Multi-Stage" in the
38-
programming paradigm we say it supports.
39-
40-
4. [TASTy Reflection](./tasty-reflect.html) With TASTy reflection we can
41-
`unseal` fragments of code and analyze them with reflection over the TASTy
42-
format of the code.
43-
44-
5. [TASTy Inspection](./tasty-inspect.html) Up until now we described how we can
45-
expand, calculate at compile-time, or generate programs. The Scala compiler
46-
offers quarantees at the level of types that the generated programs cannot go
47-
wrong. With TASTy inspection we can load compiled files and analyze their
48-
typed AST structure according to the TASTy format.
49-
22+
operations: quotation and splicing. Quotation converts program code to
23+
data, specifically, a (tree-like) representation of this code. It is
24+
expressed as `'{...}` for expressions and as `'[...]` for types. Splicing,
25+
expressed as `${ ... }`, goes the other way: it converts a program's representation
26+
to program code. Together with `inline`, these two abstractions allow
27+
to construct program code programmatically.
28+
29+
3. [Staging](./staging.html) Where macros construct code at _compile-time_,
30+
staging lets programs construct new code at _runtime_. That way,
31+
code generation can depend not only on static data but also on data available at runtime. This splits the evaluation of the program in two or more phases or ...
32+
stages. Consequently, this method generative programming is called "Multi-Stage Programming". Staging is built on the same foundations as macros. It uses
33+
quotes and splices, but leaves out `inline`.
34+
35+
4. [TASTy Reflection](./tasty-reflect.html) Quotations are a "black-box"
36+
representation of code. They can be parameterized and composed using
37+
splices but their structure cannot be analyzed from the outside. Tasty
38+
reflection gives a way to analyze code structure by partly revealing the representation type of a piece of code in a standard API. The representation
39+
type is a form of typed abstract syntax tree, which gives rise to the "TASTy`
40+
moniker.
41+
42+
5. [TASTy Inspection](./tasty-inspect.html) Typed abstract syntax trees are serialized
43+
in a custom compressed binary format in `.tasty` files. TASTy inspection allows
44+
to load these files and analyze their content's tree structure.
5045

0 commit comments

Comments
 (0)