Skip to content

Commit

Permalink
interpreter/interp: add 'runtime' field and handle Extern instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
pdarragh committed Jun 30, 2022
1 parent ab6c8fe commit 5ecfb77
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions interpreter/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
;; Given a machine state, takes the next step according to the a86 semantics.
(define (step state)
(match state
[(State tick ip first-inst last-inst labels registers flags memory)
[(State tick ip first-inst last-inst labels registers flags memory runtime)
(let ([address-from-offset
(curry address-from-offset registers)]
[make-state
Expand All @@ -28,7 +28,8 @@
labels
(or new-registers registers)
(or new-flags flags)
memory))]
memory
runtime))]
[process-argument
(λ (arg #:as [interpretation '()])
(cond
Expand Down Expand Up @@ -63,6 +64,11 @@
arg
interpretation)]))])
(match (memory-ref memory ip)
[(Extern l)
;; ensure external function exists in runtime, then skip
(unless (hash-has-key? runtime l)
(raise-user-error 'step "reference to undefined external function ~a" l))
(make-state)]
[(Label _)
;; skip
(make-state)]
Expand Down

0 comments on commit 5ecfb77

Please sign in to comment.