Compare commits

..

No commits in common. "pixel" and "main" have entirely different histories.
pixel ... main

View File

@ -7,7 +7,6 @@
(require :host.assembler.opcodes)) (require :host.assembler.opcodes))
(local {: any : slice : push : map :match find-pred} (require :deps.lume)) (local {: any : slice : push : map :match find-pred} (require :deps.lume))
(local {: word->byte : hex} (require :host.util)) (local {: word->byte : hex} (require :host.util))
(local f (require :fennel))
(fn label [name] {:label name}) (fn label [name] {:label name})
(fn label? [value] (fn label? [value]
@ -25,28 +24,17 @@
form) form)
(fn assemble [forms offset] (fn assemble [forms offset]
(let [state {:labels {} :instructions [] :reverse-labels []}] (let [state {:labels {} :instructions [] :reverse-labels []}]
(each [_ form (ipairs forms)] (each [_ form (ipairs forms)]
(if (= (type form) :string) (if (= (type form) :string)
(insert-label (insert-label state form (+ offset (* 4 (length (. state :instructions)))))
state (push (. state :instructions)
form (if (any (slice form 2) label?)
(+ offset (* 4 (length (. state :instructions))))) (let [{: type :offset addend} (. relocatable-instructions (. form 1))]
(push (. state :instructions) (push (. state :reverse-labels) {: type :label (. (find-pred form label?) :label) :offset (+ offset (* 4 (length (. state :instructions))))})
(if (any (slice form 2) label?) ((. form 1) (table.unpack (replace-label! (slice form 2) addend))))
(let [opcode (. form 1) ((. form 1) (table.unpack (slice form 2)))))))
args (slice form 2) state))
{: type :offset addend}
(. relocatable-instructions opcode)]
(push
(. state :reverse-labels)
{: type
:label (. (find-pred form label?) :label)
:offset (+ offset (* 4 (length (. state :instructions))))})
(opcode
(table.unpack (replace-label! args addend))))
((. form 1) (table.unpack (slice form 2)))))))
state))
(fn link [{: labels : instructions : reverse-labels} base] (fn link [{: labels : instructions : reverse-labels} base]
(each [_ {: type :label target : offset} (ipairs reverse-labels)] (each [_ {: type :label target : offset} (ipairs reverse-labels)]