WIP runtime re-write

This commit is contained in:
Dane Johnson 2025-06-28 10:35:46 -05:00
parent cc3d576112
commit ab558d9f60

View File

@ -1,33 +1,28 @@
;; 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 the-cars 0) (variable old 0)
(variable the-cdrs 0) (variable new 0)
(variable new-cars 0)
(variable new-cdrs 0)
(push main) (push main)
(jmp) (jmp)
alloc alloc ;; ( -- p)
;; Test if free will go beyond eom ;; Test if free will go beyond eom
(push free) (ref free)
(@)
(dup) ; ( -- free free) (dup) ; ( -- free free)
(push 8) (push 8)
(+) (+)
(dup) ; ( -- free free+8 free+8) (dup) ; ( -- free free+8 free+8)
(push eom) (ref eom)
(@)
(<) ; ( -- free free+8 (free+8 < eom)) (<) ; ( -- free free+8 (free+8 < eom))
(branch alloc-do-gc) (push alloc-do-gc)
(if)
;; write free+8 to free ;; write free+8 to free
(push free) (set! 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
@ -41,36 +36,21 @@ alloc-do-gc
(push alloc) (push alloc)
(jmp) (jmp)
gc-start gc-start ;; ( -- )
; Move scan & free back to 0 ; Move scan & free to start of new memory
(push 0) (ref new)
(push free) (dup)
(!) (set! free)
(push 0) (set! scan)
(push scan) (ref root)
(!) (push relocate-object)
; Push the first cons to relocate (root) (call)
(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