Compare commits

...

1 Commits
main ... pixel

Author SHA1 Message Date
4d5bcd5d12 temp 2025-11-23 21:04:14 +01:00

View File

@ -7,6 +7,7 @@
(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]
@ -27,12 +28,23 @@
(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 state form (+ offset (* 4 (length (. state :instructions))))) (insert-label
state
form
(+ offset (* 4 (length (. state :instructions)))))
(push (. state :instructions) (push (. state :instructions)
(if (any (slice form 2) label?) (if (any (slice form 2) label?)
(let [{: type :offset addend} (. relocatable-instructions (. form 1))] (let [opcode (. form 1)
(push (. state :reverse-labels) {: type :label (. (find-pred form label?) :label) :offset (+ offset (* 4 (length (. state :instructions))))}) args (slice form 2)
((. form 1) (table.unpack (replace-label! (slice form 2) addend)))) {: 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))))))) ((. form 1) (table.unpack (slice form 2)))))))
state)) state))