Arbitrary stack access. What to do with tail calls?

This commit is contained in:
2025-12-09 16:03:03 -06:00
parent 69b6ccbce0
commit 3ad9159969
4 changed files with 25 additions and 21 deletions

View File

@@ -58,6 +58,9 @@
[(->list)
(lambda ()
(reverse-vector->list the-stack 0 top))]
[(set!)
(lambda (k obj)
(vector-set! the-stack k obj))]
[else (error "stack dispatch unknown value")])))
(define (push stack v)
@@ -81,6 +84,9 @@
(define (stack->list stack)
((stack '->list)))
(define (stack-set! stack k obj)
((stack 'set!) k obj))
;;; IO
(define (read-word)
@@ -116,6 +122,7 @@
(rot #x18)
(over #x19)
(not #x1a)
(set! #x1b)
(bye #xff)))
(define instruction-name car)
@@ -243,6 +250,11 @@
(push data-stack b)
(push data-stack a)
(push data-stack b))]
[(set!)
;; use let* to induce an order of evaluation
(let* ([idx (pop data-stack)]
[obj (pop data-stack)])
(stack-set! data-stack idx obj))]
[(bye) (set! exit? #t)])
(when (not exit?)
(run-vm vm)))