Skip to content

Commit

Permalink
[ lec6 ] update interpreter.md
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasabel committed Nov 21, 2024
1 parent c5481aa commit d06fa2f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ Material: plt = course book, dragon = Dragon book. Slides follow closely the plt
| Tue 12/11 | 13-15 | Formal languages and parsing | [slides](plt-book/ipl-book/slides/3-slides-ipl-book.pdf), plt 3, dragon 3,4, [shift-reduce parsing](notes/sr-states.md), [LR-table](notes/LR-table.html), [lr-demo](https://github.com/teach-plt/lr-demo)|
| Thu 14/11 | 13-15 | Theory of lexing | [slides](plt-book/ipl-book/slides/3-slides-ipl-book.pdf), plt 3, dragon 3,4 |
| *Mon 18/11* | *23* | *Lab 1 deadline* | |
| Tue 19/11 | 13-15 | Type checking | [slides](plt-book/ipl-book/slides/4-slides-ipl-book.pdf), plt 4, dragon 5,6, [script](notes/type-checking.html) [prime.c](notes/prime.c) |
| Tue 19/11 | 13-15 | Type checking | [slides](plt-book/ipl-book/slides/4-slides-ipl-book.pdf), plt 4, dragon 5,6, [script](notes/type-checking.html), [prime.c](notes/prime.c), [prime-stms.c](notes/prime-stms.c), [division.c](notes/division.c), [division-annotated.c](notes/division-annotated.c) |
| Thu 21/11 | 13-15 | Interpreting | [slides](plt-book/ipl-book/slides/5-slides-ipl-book.pdf), plt 5, [script](notes/interpreter.html) |
| Tue 26/11 | 13-14 | Hands-on with Lab 2 (Haskell) | |
| Tue 26/11 | 13-14 | Hands-on with Lab 2 (Haskell) | [script](notes/monads.html) |
| Tue 26/11 | 14-15 | Hands-on with Lab 2 (Java) | |
| Thu 28/11 | 13-15 **SB-H5** | Code generation | [slides](plt-book/ipl-book/slides/6-slides-ipl-book.pdf), plt 6, dragon 6,7, [notes](notes/compilation.html), [prime.c](notes/prime.c), [prime.j](notes/prime.j) |
| Tue 03/12 | 13-14 | Hands-on with Lab 3 (Haskell) | |
Expand Down
22 changes: 20 additions & 2 deletions notes/interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Why an interpreter if we can have a compiler?
- Can help _boot strapping_ (self-implementating) a language.
1. Write interpreter `I` for new language `X` in existing language `Y`.
2. Write simple compiler `C` for `X` in `X`.
3. Run (via `I'`) `C` on `C` to get a compiled compiler `C'`.
3. Run (via `I`) `C` on `C` to get a compiled compiler `C'`.
4. Write an optimizing compiler `O` for `X` in `X`.
5. Run `C'` on `O` to get an a compiled optimizing compiler `Cₒ`.
6. Run `Cₒ` on `Cₒ` to get an optimized optimizing compiler `Cₒ'`.
Expand Down Expand Up @@ -137,6 +137,17 @@ order, even in parallel!
- Allowing non-termination:
> If `e : t` then either evaluation of `e` diverges, or `e ⇓ v` with `v : t`.
Quiz:
- Which of these hold in exceptional cases?
* Overflow
* Division by zero
- Is this definition type-sound?
```
eval(γ, EDiv double e₁ e₂) = VDouble 0.0
```
Effects
-------
Expand Down Expand Up @@ -475,6 +486,8 @@ Function call.
To implement the side condition, we need a global map `σ` from
function names `f` to their definition `t f (t₁ x₁,...,tₙ xₙ) { ss }`.

Quiz: In the last rule, what if `ss` does not contain a `return` statement?

### Implementation

In Java, we can use Java's exception mechanism.
Expand Down Expand Up @@ -522,6 +535,8 @@ In Haskell, we can use the _exception monad_.
throwError v
```

N.B.: `makeEnv (x₁:t₁, ..., xₙ:tₙ) (v₁, ..., vₙ) = (x₁=v₁, ... xₙ=tₙ)`.


Programs
--------
Expand Down Expand Up @@ -582,7 +597,10 @@ You can circumvent this by defining your own `and`:
while (and (x < 10, f(x++))) { ... }
```

Digression on: call-by-name (call-by-need) call-by-value
### Digression: call-by-name / call-by-need / call-by-value

(This is properly covered in the lecture on functional languages and in lab 4.)

- call-by-value: evaluate function arguments, pass values to function
- call-by-name: pass expressions to function unevaluated (substitution)
- call-by-need: like call-by-name, only evaluate each argument when it
Expand Down

0 comments on commit d06fa2f

Please sign in to comment.