Live data from Hacker News

Corrode: C to Rust translator written in Haskell

github.com

31–40 of 127 posts

Re: Corrode: C to Rust translator written in Haskell

#32
I was curious about how this worked so I looked into the source a little (even though Haskell isn't exactly my cup of tea), and WOW... This is just amazing. The most important part of the source is highly educative literate haskell:

https://github.com/jameysharp/corrode/blob/master/src/Langua...

Re: Corrode: C to Rust translator written in Haskell

#33

Earlier quoted context omitted.

I was going to downvote you for a snarky response (I felt the reply explaining that Rust also has iron/oxidation references was a better response)... ... but that's a really good link that you provided. I've never read that before & it's a great resource for thinking about how to behave socially as a programmer. While I don't agree with all of it, I love their "don't pile-on" and "don't bring negativity from outside"…

Why are they talking specifically about _feigning_ surprise? Isn't the effect the same even if you're honestly surprised?

If you're honestly surprised (and can't/don't hide it), the effect on the other person may be similar, but that's the nature of communication. Feigning surprise is manufacturing a situation with negative aspects.

Re: Corrode: C to Rust translator written in Haskell

#34
post #30

It's too bad this is written in Haskell. I don't have anything against Haskell, it is just not as popular a language as others.[1] Any ANTLR target language would have been a solid choice.[2] This way more of the community could contribute. This is an invaluable tool if we're truly going to see a shift from C (or C++) to Rust. [1] http://pypl.github.io/PYPL.html [2] http://www.antlr.org/download.html

I've used ANTLR in anger a few times and for some reason it's always left a bad taste in my mouth. I always seem to spend more time debugging how ANTLR works rather than doing the work I set out to do.

Granted most of my use cases was building a simple DSL so it might be different when talking about whole source conversion.

Re: Corrode: C to Rust translator written in Haskell

#35

as many "transpilers" / compilers, whatever you might name them, it lacks example input output. I want to see how my new rust code base looks light, does it compile with some heuritics, or just 1:1 C to rust primitives?

Here you go. It didn't like my stdio.h. Apparently enums and unions aren't supported, but: extern int printf(char *, ...); int main(int argc, char argv[]) { printf("Hello, world!\n"); return 0; } Was turned into: extern { fn printf(arg1 : *mut u8, ...) -> i32; } #[no_mangle] pub unsafe fn main(mut argc : i32, mut argv : *mut u8) -> i32 { printf(b"Hello, world!\n\0".as_ptr() as (*mut u8)); 0i32 } edit: Also worth noti…

Shouldn't a C `int` be converted to Rust's `isize`. I think that captures the spirit better.

Re: Corrode: C to Rust translator written in Haskell

#36

Earlier quoted context omitted.

I was going to downvote you for a snarky response (I felt the reply explaining that Rust also has iron/oxidation references was a better response)... ... but that's a really good link that you provided. I've never read that before & it's a great resource for thinking about how to behave socially as a programmer. While I don't agree with all of it, I love their "don't pile-on" and "don't bring negativity from outside"…

Why are they talking specifically about _feigning_ surprise? Isn't the effect the same even if you're honestly surprised?

I think the effect is the same. But that's also why I liked the link - I'm sometimes honestly surprised, or seeking clarification (eg "So you really haven't heard of the Playstation 4.5 & Playstation VR? But I thought you were a PS4 gamer?"). But by expressing it as feigning surprise, I understand that the other person feels I'm belittling or mocking them, even if that wasn't my intent.

For me at least, it was a better explanation than XKCD 1053: https://xkcd.com/1053/

Re: Corrode: C to Rust translator written in Haskell

#37
Absolutely blown away by the detail of the documentation. The main logic of this project is in a literate haskell file you can easily read on GitHub.

https://github.com/jameysharp/corrode/blob/master/src/Langua...

I wonder how readable is to someone who isn't experienced in Haskell. To me reads like a breeze, but I have a project using the exact same parsing library so maybe that puts me at an advantage.

The language-c library he uses is an excellent one, it's a fully spec compliant C parser that's well maintained. I've based my C compiler on it and I haven't encountered any C code it couldn't parse yet. One time I upgraded to a new OSX and Apple added some stupid thing to their headers that broke the parser and a fix was merged within days. This means it takes away the entire headache of parsing C leaving just the actual compiling.

Re: Corrode: C to Rust translator written in Haskell

#38
post #30

It's too bad this is written in Haskell. I don't have anything against Haskell, it is just not as popular a language as others.[1] Any ANTLR target language would have been a solid choice.[2] This way more of the community could contribute. This is an invaluable tool if we're truly going to see a shift from C (or C++) to Rust. [1] http://pypl.github.io/PYPL.html [2] http://www.antlr.org/download.html

I think people interested in compilers are disproportionately Haskell inclined.

Re: Corrode: C to Rust translator written in Haskell

#39
post #30

It's too bad this is written in Haskell. I don't have anything against Haskell, it is just not as popular a language as others.[1] Any ANTLR target language would have been a solid choice.[2] This way more of the community could contribute. This is an invaluable tool if we're truly going to see a shift from C (or C++) to Rust. [1] http://pypl.github.io/PYPL.html [2] http://www.antlr.org/download.html

I've used ANTLR in anger a few times and for some reason it's always left a bad taste in my mouth. I always seem to spend more time debugging how ANTLR works rather than doing the work I set out to do. Granted most of my use cases was building a simple DSL so it might be different when talking about whole source conversion.

The documentation is really spare, but coincidentally, the books written by Terrence Parr are good reads and with the right time investment, make dealing with Antlr feel less like voodoo and more like software engineering.

Re: Corrode: C to Rust translator written in Haskell

#40
post #32

I was curious about how this worked so I looked into the source a little (even though Haskell isn't exactly my cup of tea), and WOW... This is just amazing. The most important part of the source is highly educative literate haskell: https://github.com/jameysharp/corrode/blob/master/src/Langua...

That's an incredibly brilliant idea, there's some serious craftsmanship going on in that source file.

Kinda taking Rust's doc unit tests format to a whole new level.

Post reply on HN