#lang scheme/base
(require "tools.ss"
"target.ss")
(provide code-register-postponed!
code-compile!
code-print
code-pointers
code-pointers-set!
code->binary
code-clear!)
(define *postponed-macro-stack* '()) (define (code-register-postponed! code) (push! *postponed-macro-stack* code))
(define *postponed* '())
(define *cfg* '())
(define *pointers* '((code 0) (data 0)))
(define (code-pointers) *pointers*)
(define (code-pointers-set! p) (set! *pointers* p))
(define (code-compile! compile assemble!)
(let ((cfg (compile *postponed-macro-stack*)))
(let-values (((_ pointers) (assemble! cfg *pointers*)))
(set! *pointers* pointers)
(set! *cfg* (append cfg *cfg*))
(set! *postponed* (append *postponed-macro-stack* *postponed*)) (set! *postponed-macro-stack* '()))))
(define (code-print [cfg *cfg*])
(for-each print-target-word (reverse cfg)))
(define (code->binary [chain-list *cfg*])
(map
(lambda (c) (binchunk-split c 0 8))
(or (target-chains->bin chain-list)
(error 'code->binary))))
(define (code-clear!)
(set! *postponed-macro-stack* '())
(set! *postponed* '())
(set! *cfg* '()))