Live data from Hacker News

Corrode: C to Rust translator written in Haskell

github.com

71–80 of 127 posts

Re: Corrode: C to Rust translator written in Haskell

#73
post #56
post #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…

By "some stupid thing to their headers" are you referring to nullability annotations? I'm not sure what else Apple would have added to pure C headers (as opposed to obj-c) any time in the past few years.

I would like to know, too.

Re: Corrode: C to Rust translator written in Haskell

#74
I do get that Haskell is useful to be taken as a tool for these kind of code transformations (at least I have seen quite a few of those) but I am always a bit surprised that people would start such a project in a language that has -per se- nothing to do with either the source or the target language. I know, I know, it doesn't always have to be this way, but I am very much of the opinion that everytime good tools in an ecosystem are written in the language in said ecosystem you get a lot more (and meaningful) contributions.

Best examples: rake (and everything in the ruby ecosystem basically), the amount of people touching ruby c code is very small compared to all the 'standard tools', or cargo.

Re: Corrode: C to Rust translator written in Haskell

#75
post #4

Earlier quoted context omitted.

Rust is a type of corrosion.

Ah very true. I interpret it as (from Googles define) "destroy or weaken (something) gradually." i.e. destroy/weaken the C code into Rust... Maybe it's just me, though.

Exactly, _Corrode_ makes C code _rusty_!

Re: Corrode: C to Rust translator written in Haskell

#76
post #74

I do get that Haskell is useful to be taken as a tool for these kind of code transformations (at least I have seen quite a few of those) but I am always a bit surprised that people would start such a project in a language that has -per se- nothing to do with either the source or the target language. I know, I know, it doesn't always have to be this way, but I am very much of the opinion that everytime good tools in a…

Haskell is very good at writing correct parsers easily—that's one thing. This is part of the reason it was chosen as an early perl6 test bed via pugs. Rust is getting there (I'm a big fan of the lalrpop library) but the ecosystem is no where near as mature as Haskell's for feature-complete libraries. The pace of development of the rust ecosystem is mind-boggling, though—I never guessed that rust would have taken off in popularity as much as it has.

Re: Corrode: C to Rust translator written in Haskell

#77
post #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…

It's not that bad to read. The documentation alone makes it easy to work on. This was dropped in the /r/rust thread: http://jamey.thesharps.us/2016/07/translating-c-to-rust-and-...

He lays it out fairly well for people to help out.

Re: Corrode: C to Rust translator written in Haskell

#78
post #35

Earlier quoted context omitted.

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.

Only for ILP64 ABIs, which aren't common.

Re: Corrode: C to Rust translator written in Haskell

#79

Earlier quoted context omitted.

On the rust subreddit someone tongue-in-cheek suggested `cargo clippy | rustfix` to be used in conjunction with this tool for better rust code. But that actually could work! Clippy has a ton of lints that make your code more idiomatic, and rustfix basically takes diagnostic output and applies suggestions (still WIP). Clippy is geared towards making human-written unidiomatic code better, so it might not catch some sil…

I haven't used nightly much, what all does Clippy do?

Check out Clippy online! Go do http://play.integer32.com/, paste in your code, click "Clippy".
Post reply on HN