Compare commits

...

2 Commits

3 changed files with 19 additions and 13 deletions

View File

@ -1,3 +1,6 @@
(push main)
(jmp)
;; Note that this is scheme syntax wrapping asm for a stack machine
(variable eol 0)
(variable scan 0)
@ -8,9 +11,6 @@
(variable new 0)
(variable root 0)
(push main)
(jmp)
alloc ;; ( -- p)
;; Test if free will go beyond eom
(ref free)
@ -129,7 +129,7 @@ gc-loop
(<)
(branch gc-loop-done)
(ref scan)
(relocate-reg)
(push relocate-reg)
(push gc-loop)
(jmp)
gc-loop-done

View File

@ -49,7 +49,7 @@
(define (write-word word)
(define bv (make-bytevector 4))
(bytevector-s32-native-set! bv 0 word)
(bytevector-u32-native-set! bv 0 word)
(write-bytevector bv))
(define (assembly-pass seq labels)

View File

@ -6,13 +6,14 @@
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-43)
#:use-module (ice-9 format)
#:export (make-stack (push . stack-push) (pop . stack-pop) (peek . stack-peek) stack-ref stack->list
(make-vm* . make-vm) run-vm
vm-memory-ref vm-memory-byte-ref vm-memory-set! vm-memory vm-load-program!
vm-data-stack vm-ret-stack
vm-debugger vm-debugger-set!
vm-pc vm-pc-set!
*instruction-set* instruction-type instruction-code))
(make-vm* . make-vm) run-vm
vm-memory-ref vm-memory-byte-ref vm-memory-set! vm-memory vm-load-program!
vm-data-stack vm-ret-stack
vm-debugger vm-debugger-set!
vm-pc vm-pc-set!
*instruction-set* instruction-type instruction-code))
;;; Data Structures
(define *stack-size* 512)
@ -114,12 +115,16 @@
(swap #x17)
(rot #x18)
(over #x19)
(not #x1a)
(bye #xff)))
(define instruction-code cadr)
(define (op-lookup code)
(car (find (lambda (x) (= (instruction-code x) code)) *instruction-set*)))
(let ([op (find (lambda (x) (= (instruction-code x) code)) *instruction-set*)])
(if op
(car op)
(error (format #f "tried to execute non-existant instruction ~x" code)))))
(define (binop-lookup op)
(case (op-lookup op)
@ -129,7 +134,8 @@
[(or) logior]
[(nand) (compose lognot logand)]
[(nor) (compose lognot logior)]
[(xor) logxor]))
[(xor) logxor]
[(not) lognot]))
(define (relop-lookup op)
(case (op-lookup op)