Hacker News new | past | comments | ask | show | jobs | submit login

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.




Look here: 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.


I haven't looked at this one in detail, but MonadFix and the recursive do syntax (https://wiki.haskell.org/MonadFix) will probably solve this problem by allowing forward references.


That'll do for the hole-filling approach :-)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: