Skip to content

Commit

Permalink
interpreter/interp: handle void returns from external funcs for #1
Browse files Browse the repository at this point in the history
  • Loading branch information
pdarragh committed Jul 6, 2022
1 parent 7786981 commit 3e8408c
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions interpreter/interp.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,23 @@
;; call the external function
(let* ([func (hash-ref runtime external-function)]
[sp (hash-ref registers 'rsp)]
[result (func registers memory sp)]
[_ (unless (integer? result)
(raise-user-error 'step
"result of external function '~a' not an integer; got ~v"
external-function
result))]
[_ (unless (<= (integer-length result) (word-size-bits))
(raise-user-error 'step
"integer result of external function '~a' too large; got ~v"
external-function
result))]
[new-registers (hash-set registers 'rax result)])
(make-state #:with-registers new-registers))]
[result (func registers memory sp)])
(cond
[(void? result)
(make-state)]
[(not (integer? result))
(raise-user-error 'step
"result of external function '~a' not #<void> or an integer; got ~v"
external-function
result)]
[(not (<= (integer-length result) (word-size-bits)))
(raise-user-error 'step
"integer result of external function '~a' too large; got ~v"
external-function
result)]
[else
(let ([new-registers (hash-set registers 'rax result)])
(make-state #:with-registers new-registers))]))]
[(Call dst)
;; Mem.push(ip + wordsize)
;; ip = dst
Expand Down

0 comments on commit 3e8408c

Please sign in to comment.