tcr / parser-c

Haskell's language-c ported to Rust.
http://docs.rs/parser-c
31 stars 5 forks source link

Remove a lot of clones from parser/lexer #22

Closed birkenfeld closed 7 years ago

birkenfeld commented 7 years ago

I made the Parser monad use FnBox instead of Fn, so that all closures can take ownership and drop values after they are called. This works because P<T> values are only used once - that's an important property for closure-based monads in Haskell as well (to get the desired sequencing).

My clones of Alex/Happy have been updated to generate the code that is in these commits.

Another very important change is in input_stream, which keeps a cloneable stream by just referring to an Rc<Vec<u8>>. This gets rid of the huge burden of cloning the input string (potentially multiple times) for every char the lexer sees...

birkenfeld commented 7 years ago

Hm, a stack overflow. Interesting...

tcr commented 7 years ago

I made the Parser monad use FnBox instead of Fn, so that all closures can take ownership and drop values after they are called.

Excellent. Earlier passes at this (literally, while I was learning monads) made use of FnBox, though I struggled to make it work. Using it complicates the path to stable a bit but that's a secondary concern.