Compare commits

..

No commits in common. "ab558d9f608cf6b5523ed272fae149937a7a0eaf" and "227dcc662ea33caf6e44e5fdbf82882146f217c5" have entirely different histories.

3 changed files with 47 additions and 33 deletions

View File

@ -1,28 +1,33 @@
;; Note that this is scheme syntax wrapping asm for a stack machine ;; Note that this is scheme syntax wrapping asm for a stack machine
(variable eom 1024)
;; These need to be initialized with the runtime
(variable scan 0) (variable scan 0)
(variable free 0) (variable free 0)
(variable eom 1024)
;; These need to be initialized later
(variable root 0) (variable root 0)
(variable old 0) (variable the-cars 0)
(variable new 0) (variable the-cdrs 0)
(variable new-cars 0)
(variable new-cdrs 0)
(push main) (push main)
(jmp) (jmp)
alloc ;; ( -- p) alloc
;; Test if free will go beyond eom ;; Test if free will go beyond eom
(ref free) (push free)
(@)
(dup) ; ( -- free free) (dup) ; ( -- free free)
(push 8) (push 8)
(+) (+)
(dup) ; ( -- free free+8 free+8) (dup) ; ( -- free free+8 free+8)
(ref eom) (push eom)
(@)
(<) ; ( -- free free+8 (free+8 < eom)) (<) ; ( -- free free+8 (free+8 < eom))
(push alloc-do-gc) (branch alloc-do-gc)
(if)
;; write free+8 to free ;; write free+8 to free
(set! free) (push free)
(!)
;; return the old free, it is memory the program can use ;; return the old free, it is memory the program can use
(return) (return)
alloc-do-gc alloc-do-gc
@ -36,21 +41,36 @@ alloc-do-gc
(push alloc) (push alloc)
(jmp) (jmp)
gc-start ;; ( -- ) gc-start
; Move scan & free to start of new memory ; Move scan & free back to 0
(ref new) (push 0)
(dup) (push free)
(set! free) (!)
(set! scan) (push 0)
(ref root) (push scan)
(push relocate-object) (!)
(call) ; Push the first cons to relocate (root)
(push root)
(@)
; Call the relocation routine
(push gc-loop) (push gc-loop)
(call) (call)
; Swap new and old cars and cdrs
(push new-cars)
(@)
(push the-cars)
(@)
(push new-cars)
(!)
(push the-cars)
(!)
(push new-cdrs)
(@)
(push the-cdrs)
(@)
(push new-cdrs)
(!)
(push the-cdrs)
(!)
; return to allocation
(return) (return)
relocate-object ;; (o -- )
;; TODO
main
;; TODO

View File

@ -7,14 +7,8 @@
#:select (write-u8 write-bytevector)) #:select (write-u8 write-bytevector))
#:export (assemble)) #:export (assemble))
(define *aliases*
'((if . branch)))
(define (or-alias inst)
(or (assq-ref *aliases* inst) inst))
(define (lookup-instruction inst) (define (lookup-instruction inst)
(define inst-obj (assq (or-alias inst) *instruction-set*)) (define inst-obj (assq inst *instruction-set*))
(if inst-obj (if inst-obj
inst-obj inst-obj
(error (format #f "could not find instruction ~a" inst)))) (error (format #f "could not find instruction ~a" inst))))

View File

@ -32,7 +32,7 @@
(=) (=)
(or) (or)
(push recur) (push recur)
(if) (branch)
(return) (return)
recur recur
(dup) (dup)