5 ms·
Awesome article! Seems a reasonably complete assembler too with one notable exception: Forward jumps, conditionals specifically. These may be a tad tricky to f
by brandonbloom 11y ago
Awesome article!
Seems a reasonably complete assembler too with one notable exception: Forward jumps, conditionals specifically. These may be a tad tricky to fit in to a monad because they require either knowing the future (eg. how far away the jump target is) or rewriting the past (eg. leave a hole and fill it in later).
I'd really like to see both approaches in Haskell, since they're kinda different. My guess is that in the former case, you'd have nested/delimited monads with buffers. However, I don't know Haskell enough to figure out how to accomplish the hole-filling approach.
EDIT: On second thought, I guess both approaches (traditionally "two-pass" vs "one-pass" assemblers) can be accomplished by changing labels to be opaque rather than addresses and storing a symbol table in either JITMem or the two-types that would replace it for a two-pass approach.
- paulajohnson 11y agoI haven't looked at this one in detail, but MonadFix and the recursive do syntax (https://wiki.haskell.org/MonadFix https://wiki.haskell.org/MonadFix) will probably solve this problem by allowing forward references.
- brandonbloom 11y agoThat'll do for the hole-filling approach :-)
- thesz 11y agoLook here: http://www.eliza.ch/doc/wadler92essence_of_FP.pdf http://www.eliza.ch/doc/wadler92essence_of_FP.pdf (page 11) The state in the monad in the quoted paper flows backward. The part of assembler that works with label's addresses can use that trick from 1992.