Live data from Hacker News

Corrode: C to Rust translator written in Haskell

github.com

51–60 of 127 posts

Re: Corrode: C to Rust translator written in Haskell

#51

Earlier quoted context omitted.

https://github.com/rust-lang/rust/issues/26097

With the literate style, code is prefixed and comments are raw. So, instead of: -- foo is a function foo :: String -> String It's foo is a function > foo :: String -> String

Sorry, I am not understanding what you're implying here. I am well aware of the definition of literate programming. (And what you've said isn't actually enough to be considered literate programming under Knuth's definition: that's just tangle, still missing weave. Though notably, a lot of people argue that weave isn't needed with today's programming languages...)

Re: Corrode: C to Rust translator written in Haskell

#53
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.

On some architecture int is 32bit while isize is actually 64bit so no, that translation is definitely not the ideal one.

Re: Corrode: C to Rust translator written in Haskell

#54
post #12

Earlier quoted context omitted.

Oh great, I can't wait to hear this "well, actually"[1] for the rest of my life. [1] https://www.recurse.com/manual#sub-sec-social-rules

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"…

> 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)...

100% of English speakers who hear the word "rust" will first think of metal oxidation. "Correcting" people who make that "mistake" adds nothing of value to the conversation and just expresses "I know more than you" because you know some obscure minutia that was mentioned in an IRC channel once. Nerds love doing this "I'm smarter than you" kind of shit, so much so that it is developing its own noun, "well actually". It's obnoxious and distracting and contributes nothing, so I called it out.

Re: Corrode: C to Rust translator written in Haskell

#55

The name "Corrode" doesn't seem very positive given the purpose of this program...

Well, it's just building off the same (negative) connotations of "Rust", which I think was itself a questionable name, trivial though it might seem.

I've been looking at newer languages recently, and I see a lot of promise in Nim -- which renamed itself from Nimrod after users warned about what it connotes. Rust could take a cue.

Re: Corrode: C to Rust translator written in Haskell

#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.

Re: Corrode: C to Rust translator written in Haskell

#57
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.

No, most real-world C code will expect a C `int` to be 32 bits, while `isize` is often 64 bits.

On the other hand, at least for Unix systems `long` is often equivalent to Rust's `isize`: 32 bits for 32-bit architectures, and 64 bits for 64-bit architectures, so it would make sense to convert `long` to `isize`.

Re: Corrode: C to Rust translator written in Haskell

#58
post #47

> Partial automation for migrating legacy code that was implemented in C. (This tool does not fully automate the job because its output is only as safe as the input was; you should clean up the output afterward to use Rust features and idioms where appropriate.) This was my immediate concern. Is there any chance this tool can produce anything close to clean, safe, idiomatic, rust code?

> Is there any chance this tool can produce anything close to clean, safe, idiomatic, rust code?

That is generally not possible, unless the C code only uses specific patterns known by the converter tool. That's very unlikely, considering that people write C code to be 'quick' and usually use all kinds of tricks.

Re: Corrode: C to Rust translator written in Haskell

#59

Earlier quoted context omitted.

With the literate style, code is prefixed and comments are raw. So, instead of: -- foo is a function foo :: String -> String It's foo is a function > foo :: String -> String

Sorry, I am not understanding what you're implying here. I am well aware of the definition of literate programming. (And what you've said isn't actually enough to be considered literate programming under Knuth's definition: that's just tangle, still missing weave. Though notably, a lot of people argue that weave isn't needed with today's programming languages...)

I mentioned it because I didn't see it in my scanning of the issue you linked to.

Edit: I should have looked more closely, sorry.

Re: Corrode: C to Rust translator written in Haskell

#60
post #55

The name "Corrode" doesn't seem very positive given the purpose of this program...

Well, it's just building off the same (negative) connotations of "Rust", which I think was itself a questionable name, trivial though it might seem. I've been looking at newer languages recently, and I see a lot of promise in Nim -- which renamed itself from Nimrod after users warned about what it connotes. Rust could take a cue.

Well, Rust isn't actually named after iron oxide. It's actually named after the fungus (https://en.wikipedia.org/wiki/Rust_(fungus)). Most people just don't know about the fungus.
Post reply on HN