Debugger, begin runtime stuff

This commit is contained in:
2025-06-11 10:50:38 -05:00
parent a36eea12d0
commit f939d1b08b
6 changed files with 277 additions and 104 deletions

View File

@@ -5,7 +5,7 @@
#:use-module (rnrs io ports)
#:use-module ((scheme base)
#:select (write-u8 write-bytevector))
#:export (assemble assemble-file))
#:export (assemble))
(define (lookup-instruction inst)
(define inst-obj (assq inst *instruction-set*))
@@ -36,9 +36,9 @@
(write-bytevector bv))
(define (assemble inst-seq port)
(define labels (find-labels inst-seq 1))
(with-output-to-port port
(lambda ()
(define labels (find-labels inst-seq 1))
(let loop ([seq inst-seq])
(cond
[(null? seq) '()]
@@ -54,13 +54,5 @@
(if (number? (cadr inst))
(write-word (cadr inst))
(write-word (assq-ref labels (cadr inst)))))
(loop (cdr seq)))])))))
(define (assemble-file file out)
(call-with-input-file file
(lambda (in)
(define (read-all next)
(if (eof-object? next)
'()
(cons next (read-all (read in)))))
(assemble (read-all (read in)) out))))
(loop (cdr seq)))]))))
labels)