A Rust frontend for GCC
From: | Philip Herron <redbrain-/MQLu3FmUzdAfugRpC6u6w-AT-public.gmane.org> | |
To: | gcc-/MQLu3FmUzdAfugRpC6u6w-AT-public.gmane.org, "rust-dev-4eJtQOnFJqFAfugRpC6u6w-AT-public.gmane.org" <rust-dev-4eJtQOnFJqFAfugRpC6u6w-AT-public.gmane.org> | |
Subject: | Rust front-end to GCC | |
Date: | Tue, 3 Dec 2013 17:22:07 +0000 | |
Message-ID: | <CAEvRbeoL2NiJ+sfVEtWFMTdP8aWk2jOzmbRbLspj7GSynWQLhQ@mail.gmail.com> | |
Archive‑link: | Article |
Hey all Some of you may have noticed the gccrs branch on the git mirror. Since PyCon IE 2013 i gave a talk on my Python Front-end pet project and heard about rust by a few people and i never really looked at it before until then but i've kind of been hooked since. So to learn the language i've been writing this front-end to GCC. Only really a a month or so on and off work in between work. Currently it compiles alot of rust already in fairly little effort on my side GCC is doing loads of the heavy lifting. Currently it compiles most of the basic stuff such as a struct an impl block while loop, functions expressions calling methods passing arguments etc. Currently focusing on getting the typing working correctly to support & and ~ and look at how templates might work as well as need to implement break and return. There is still a lot of work but i would really like to share it and see what people think. Personally i think rust will target GCC very well and be a good addition (if / when it works). I really want to try and give back to this community who have been very good to me in learning over the last few years with GSOC. To get a jist of what i am compiling in my tests are something like: fn fib1 (n:int) -> int { if (n <= 1) { 1 } else { n * fib1 (n - 1) } } fn fib2 (n:int) -> int { let mut i = 1; let mut result = 1; while (i <= n) { result = result * i; i = i + 1; } result } fn main () { fib1 (10); fib2 (10); } Or struct mytype { x : int } impl mytype { fn test (self) -> int { println ("yyoyoyo"); test2 (1) } } fn main () { let x = mytype { x : 1 }; let z = x.x; let y = x.test (); let a = test2 (y); } fn test2 (x : int) -> int { let z = x; 1 + z } Theses are both pretty abstract test cases but were the ones i just made work a while ago. Lots more work to do on it but i feel these 2 test cases working is kind of a mile stone for me. I will start a wiki page on the project and the code i work on is at http://gcc.gnu.org/git/?p=gcc.git;a=shortlog;h=refs/heads... and i have it on github first mostly for travis CI and so i can do a bunch of commits and rebase etc http://github.com/redbrain/gccrs Thanks --Phil
Posted Dec 3, 2013 19:32 UTC (Tue)
by HelloWorld (guest, #56129)
[Link]
Posted Dec 4, 2013 8:01 UTC (Wed)
by smurf (subscriber, #17840)
[Link]
But: please name your functions correctly. You want "fac". ;-)
fib(n) := n<2 ? n : fib(n-1)+fib(n-2)
Posted Dec 4, 2013 9:08 UTC (Wed)
by rvfh (guest, #31018)
[Link] (1 responses)
Forgive my GCC ignorance...
Posted Dec 4, 2013 9:37 UTC (Wed)
by mathstuf (subscriber, #69389)
[Link]
Posted Dec 4, 2013 10:36 UTC (Wed)
by Otus (subscriber, #67685)
[Link] (9 responses)
How do you write "rustic" programs?
Posted Dec 4, 2013 11:19 UTC (Wed)
by HelloWorld (guest, #56129)
[Link]
Posted Dec 4, 2013 12:34 UTC (Wed)
by apoelstra (subscriber, #75205)
[Link] (1 responses)
There is a tutorial that ships with Rust. It is the same as the online one but will be different if you download git HEAD because that's just how fast the language moves.
Shortly before I arrived there was a deprecation of '@' pointers, which appeared in the online tutorial. I've seen the tutorial updated to account for this, development on GC'd and ref-counted pointers which are supposed to replace '@' (which are unspecified "managed" pointers). I've also seen the deprecation of &fn "borrowed function" syntax in favor of something more precise with different syntax ('procedures' which are non-mutable in some sense and can be passed between tasks, and something mutable which can't, IIRC).
There was an LWN article in July which described the semantics of for loops and lambda functions. That stuff also changed before I started following the project.
The Rust source is written in Rust, and there are developers and enthusiasts on #rust on irc.mozilla.org. These two sources should help you to write rustic code. (But "rustic" will mean something different in a month no doubt, so you might want to wait for more stability. :))
It's very exciting development and I don't mean to give the impression that this is not a worthwhile language to learn. Just that in 2013/2014 the syntax is still a moving target and that you'd best not spend time writing massive amounts of code in it.
On the other hand, Rust's safe pointer model is quite mind-bending and worth getting a jump on. So there is a motivation for learning the language today.
Posted Dec 9, 2013 1:53 UTC (Mon)
by nix (subscriber, #2304)
[Link]
Posted Dec 4, 2013 14:27 UTC (Wed)
by Kit (guest, #55925)
[Link] (4 responses)
Mind you, though, that breaking changes in the language is currently the norm, and a lot of material out there for Rust covers old versions- and some people actually try to follow Master instead of the current release, so library support can be a bit painful.
Posted Dec 4, 2013 15:01 UTC (Wed)
by Otus (subscriber, #67685)
[Link]
Thanks, that's pretty close to what I was looking for.
Posted Dec 4, 2013 19:59 UTC (Wed)
by shmerl (guest, #65921)
[Link] (2 responses)
Posted Dec 4, 2013 23:11 UTC (Wed)
by stevenb (guest, #11536)
[Link]
Posted Dec 5, 2013 2:00 UTC (Thu)
by Kit (guest, #55925)
[Link]
There's no timeline yet, although I think (think!) a Rust dev guessed that they might have a clear path to 1.0 in about a year (not that they'd have 1.0 out then, just something akin to a timeline). Rust feels like, once it stabilizes, that it could be a true alternative to C and C++ as a "systems" language.
Posted Dec 6, 2013 0:54 UTC (Fri)
by intgr (subscriber, #39733)
[Link]
You mean, uh, "rusty"? :)
Posted Dec 9, 2013 11:10 UTC (Mon)
by bgmarete (guest, #47484)
[Link] (6 responses)
Posted Dec 9, 2013 13:37 UTC (Mon)
by mathstuf (subscriber, #69389)
[Link] (1 responses)
Posted Dec 11, 2013 8:01 UTC (Wed)
by bgmarete (guest, #47484)
[Link]
I have been putting off looking at Rust, mostly because it would have been a distraction from Go which has been a lot of fun to learn and use. Like C, it is a very small language which easily fits in the head, its always-improving performance is more than acceptable (and significantly better than Python's) and it supports modern facilities that are useful and which enhance safety. All this has meant that it has replaced Python and C++ where I am concerned, and my real work (business) has come to rely on it a great deal. So I am very anxious to see it advance in great leaps and bounds.
But your comment and Cyberax's below mean that I will be taking a serious look at Rust soon.
Posted Dec 9, 2013 19:45 UTC (Mon)
by Cyberax (✭ supporter ✭, #52523)
[Link] (3 responses)
Let's see:
Posted Dec 10, 2013 21:34 UTC (Tue)
by lsl (subscriber, #86508)
[Link] (2 responses)
> 1) It's a compiled language with types but it still has no generics. Fail.
It's not that bad. Sure, in some cases generics would be nice but in practice it just doesn't seem to be a serious issue. Better no generics than a botched-up design.
> 2) Global heap with a GC. [...]
You have to think about the garbage you're creating if you want good performance, true. In contrast to Java Go gives you the possibilities to acutally control the amount of garbage created (i.e. the allocations done). Oh, and the GC gets better and better with each release.
> 3) No real new ideas about multithreading.
You mean Go's support for concurrency (which is not just multithreading) at the language level? Yes, it's nothing groundbreaking. Stuff like this was available in other (though more exotic) languages for years. So what? Even though the underlying ideas are not new, the realization of them in Go is pretty nice and (IMHO) unmatched by any mainstream language.
In terms of new and exciting language features you never saw anywhere else Go certainly isn't that interesting. But doing actual programming in Go is a lot of fun. IMHO it's a very well designed language. You really notice how much thought went into certain decisions to make its parts work so nicely together. Just look at how all the interface stuff (especially the IO related ones) works out in a real program. You don't get something like that by throwing together tons of unrelated features.
For my programming needs Go replaced C in many places.
Posted Dec 10, 2013 22:48 UTC (Tue)
by Cyberax (✭ supporter ✭, #52523)
[Link]
> It's not that bad. Sure, in some cases generics would be nice but in practice it just doesn't seem to be a serious issue. Better no generics than a botched-up design.
> You have to think about the garbage you're creating if you want good performance, true. In contrast to Java Go gives you the possibilities to acutally control the amount of garbage created (i.e. the allocations done).
>Oh, and the GC gets better and better with each release.
> You mean Go's support for concurrency (which is not just multithreading) at the language level? Yes, it's nothing groundbreaking.
>In terms of new and exciting language features you never saw anywhere else Go certainly isn't that interesting. But doing actual programming in Go is a lot of fun.
Frankly, I'd have preferred a clean Python code to Go code.
Posted Dec 11, 2013 3:29 UTC (Wed)
by mathstuf (subscriber, #69389)
[Link]
No, but C++ developers migrating to Go was an expectation of the developers[1]. It hasn't happened and instead they're getting Python and Ruby programmers.
[1]http://commandcenter.blogspot.se/2012/06/less-is-exponent...
Great news!
A Rust frontend for GCC
fac(n) := n<2 ? n : n*fac(n-1)
Frontends for GCC
Frontends for GCC
A Rust frontend for GCC
A Rust frontend for GCC
https://github.com/mozilla/rust/wiki/Note-style-guide
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
A Rust frontend for GCC
1) It's a compiled language with types but it still has no generics. Fail.
2) Global heap with a GC. It means an endless struggle to make it work acceptably enough on large datasets. Just ask those nice Sun JVM developers.
3) No real new ideas about multithreading.
A Rust frontend for GCC
A Rust frontend for GCC
That's why Go mostly reminds me of pre-1.5 Java.
Mostly because people migrate to Go from dynamic languages.
Go does not do ANYTHING different than Java in relation to GC. All the Go objects are allocated on the stack or in the heap, just like in Java.
Yeah, and it can continue pretty much indefinitely. Up until recently Go used a dumb imprecise conservative GC, right now they are about 5-10 years from the current state-of-the-art GCs.
Exactly. On the other hand, Rust provides guaranteed safe multithreading with very little effort from the programmer.
I work on third-party Go code (Docker) and it certainly is NOT fun at all.
A Rust frontend for GCC