Skip to content

Commit 875ccb2

Browse files
committed
[lec8] fix compilation.md notes
1 parent d4b5779 commit 875ccb2

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

notes/compilation.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ rest of the stack unchanged.
205205
emit(t-add) -- either iadd or dadd
206206

207207
compileExp(EVar x):
208-
a <- lookupVar
208+
a <- lookupVar x
209209
emit(t-load a) -- either iload or dload
210210

211211
compileExp(ECall x es)
@@ -374,10 +374,10 @@ compileStm(SIfElse e s₁ s₂):
374374
- logical operators:
375375
```haskell
376376
compileBool(ETrue, Ltrue, Lfalse):
377-
goto ETrue
377+
goto LTrue
378378

379379
compileBool(EFalse, Ltrue, Lfalse):
380-
goto EFalse
380+
goto LFalse
381381

382382
compileBool(EAnd e₁ e₂, Ltrue, Lfalse):
383383
Ltrue' newLabel
@@ -393,11 +393,16 @@ Sometimes booleans need to be represented by 0 and 1,
393393
e.g. when assigning to a boolean variable:
394394
```haskell
395395
compileExp(e) | typeOf(e) == bool:
396-
Ltrue, Lfalse <- newLabel
397-
iconst_1 -- speculate "true"
396+
Ltrue, Lfalse, Ldone <- newLabel
397+
398398
compileBool(e, Ltrue, Lfalse)
399-
Lfalse: -- no? change to "false"
399+
Ltrue:
400+
iconst_1
401+
goto Ldone
402+
403+
Lfalse:
400404
pop
401405
iconst_0
402-
Ltrue:
406+
407+
Ldone:
403408
```

0 commit comments

Comments
 (0)