Skip to content

Commit

Permalink
example 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Griswold committed Nov 2, 2019
1 parent 2975cdc commit c3f10ce
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
35 changes: 28 additions & 7 deletions chapter-5/5.2/base.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,15 @@
(lambda (insts labels)
(let ((next-inst (car text)))
(if (symbol? next-inst)
(receive
insts
(cons
(make-label-entry
next-inst
insts)
labels))
(if (assoc next-inst labels)
(error "Label already exists --" next-inst)
(receive
insts
(cons
(make-label-entry
next-inst
insts)
labels)))
(receive
(cons (make-instruction
next-inst)
Expand Down Expand Up @@ -437,3 +439,22 @@
(cadr val)
(error "Unknown operation: ASSEMBLE"
symbol))))


(define ex5.8-test-machine
(make-machine
'(a)
(list)
'(start
(goto (label here))
here
(assign a (const 3))
(goto (label there))
here
(assign a (const 4))
(goto (label there))
there)))

(start ex5.8-test-machine)
(display "ex5.8-test-machine: ")
(display (get-register-contents ex5.8-test-machine 'a))
4 changes: 4 additions & 0 deletions chapter-5/5.2/ex5.8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The contents of register a will be three.

This is because the first instance of the symbol is the one referenced by the
assoc in *lookup-label*.

0 comments on commit c3f10ce

Please sign in to comment.