[HN Gopher] Natalie: An early-stage Ruby implementation that com...
___________________________________________________________________
Natalie: An early-stage Ruby implementation that compiles to C++
Author : ksec
Score : 69 points
Date : 2021-12-23 11:37 UTC (11 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| netule wrote:
| I'm genuinely curious: why would I use this over something like
| Crystal, which is pretty much Ruby, but native?
|
| https://crystal-lang.org/
| pjmlp wrote:
| Ideally, access to the existing Ruby ecosystem.
|
| Crystal makes sense in the context of writing stuff from
| scratch or wanting to contribute to the ecosystem.
| 999900000999 wrote:
| I sincerely doubt a tool like this will give you access to
| the full Ruby ecosystem.
|
| I definitely love the idea though, I struggle with lower
| level languages, although I consider myself fairly decent
| with both Python and JavaScript.
| pjmlp wrote:
| This one in particular probably not, since it is in early
| stages.
|
| RubyMotion on the contrary is quite advanced and an AOT
| compiler to go to, when one wants to use Ruby for mobile
| development.
|
| http://www.rubymotion.com/
| _3u10 wrote:
| RubyMotion is probably as good as it gets for AOT. Ruby
| depends on dynamic dispatch and thankfully objc is very
| similar the needs of a Ruby-like language.
|
| Truffle might work even better as it's able to recompile.
|
| Any C++ port will likely need to reimplement half of the
| objc runtime to support all of Ruby. Not sure if
| clangs/gcc objc support includes the runtime, but I'm
| imagining it would... so maybe it's reusable that way.
| cmer wrote:
| Is RubyMotion something we can actually use to build non-
| toy apps in 2021? I thought it was dead, but perhaps it
| is not!
| chrisseaton wrote:
| > which is pretty much Ruby
|
| Crystal looks similar, but really has very different semantics,
| and so can't run existing Ruby.
| ksec wrote:
| I was going to suggest adding Natalie to Ruby Compiler List
| [1], turns out Natalie is already on the list and started in
| 2019!
|
| [1]https://ruby-compilers.com
| chrisseaton wrote:
| Yeah I need to do the deep dive on it!
| vidarh wrote:
| Crystal is _superficially similar_ but it pretty much ends
| there, and many off the differences feels pretty arbitrary.
| adamrt wrote:
| Andreas Kling (of SerenityOS) recently did a Natalie contribution
| video that I found interesting.
| https://www.youtube.com/watch?v=b4PZgvPYkP4
| akling wrote:
| And if you'd like to see Tim (original author of Natalie)
| working on Natalie, he has a YouTube channel with lots of great
| content here:
| https://www.youtube.com/channel/UCgWip0vxtqu34rZrFeCpUow :^)
| ModernMech wrote:
| I'm a little confused about this project. I'm trying to build the
| most complete list of programming languages out there (currently
| working on it via my favorites, it you want to have a look), and
| I'm trying to figure out if this qualifies.
|
| Usually it's pretty easy to get on my list: if you call your
| project a language I add it to the list.
|
| But this one gives me a little pause, because it seems like this
| language is not distinct from Ruby at all. Rather this is a
| straight up Ruby -> C++.
|
| Is it fair to call this a language rather than a compiler? To me,
| a language is more than syntax and semantics, but includes an
| library ecosystem, tooling, and community. Does Natalie aim to
| grow a community, or will it exist fully within the Rudy
| ecosystem?
| pmontra wrote:
| In the JavaScript world this would be called a transpiler.
| Instead of compiling a newer version of JS into an older one
| this compiles Ruby in a totally different language, C++.
| However the Ruby interpreter (MRI) is written in C so C++ is
| less far away from it than, let's say, Java. I didn't check the
| code but I wonder if they inlined some code from MRI.
| alekq wrote:
| It is Ruby implementation if I got it right, not a Ruby-like
| language.
|
| Not the first and probably not the last one (jRuby, Rubinius,
| MacRuby etc.).
| chrisseaton wrote:
| > because it seems like this language is not distinct from Ruby
| at all
|
| I don't think it claims to be - it's a compiler for Ruby.
| ModernMech wrote:
| The domain is Natalie-lang.org and the header on that page is
| "Natalie Programming Language", so that's where I'm a little
| confused. Maybe the goal isn't to be a Ruby compiler but to
| transition into something more, so I was wondering if anyone
| had any idea.
| saghm wrote:
| This isn't the first time something like this has been done;
| for a while Facebook used a PHP to C++ compiler before
| switching to compiling it directly to native code via a JIT:
|
| https://en.wikipedia.org/wiki/HipHop_for_PHP
| https://en.wikipedia.org/wiki/HHVM
| sitkack wrote:
| This is cool, it looks conceptually similar to Shedskin. A Python
| to C++ compiler.
|
| https://shedskin.github.io/
| racl101 wrote:
| Ugh, these names.
| turbinerneiter wrote:
| I always wonder why you would target another language with your
| compiler, instead of an IR.
|
| What is the benefit of transpiling to C++ over using LLVM?
|
| (not meant as a criticism, genuinely curious)
| pjmlp wrote:
| It is easier to deal with, going one step further requires
| dealing with more low level coding and can be demotivating for
| some.
|
| However I would advise to target an IR instead.
|
| Doesn't need to be LLVM, if the purpose is only learning about
| compilers, do as follows:
|
| 1 - Create an IR, preferably stack based as they are quite easy
| to target
|
| 2 - Basic IR interpreter for testing the workflow
|
| 3 - With a macro assembler, convert the IR into machine code in
| a dumb way
|
| Now you have a workable compiler, even if it won't win any
| prizes.
|
| If still interesting, then proceed to improve the code
| generation in a proper way.
| sitkack wrote:
| Ribbit is an R4RS implementation that is extremely compact.
| The video is only 15 minutes and worth a watch.
|
| https://github.com/udem-dlteam/ribbit
|
| https://www.iro.umontreal.ca/~feeley/papers/YvonFeeleyVMIL21.
| ..
|
| https://www.youtube.com/watch?v=A3r0cYRwrSs
| pjmlp wrote:
| Thanks for sharing.
| afranchuk wrote:
| "It depends", as always :)
|
| Some people may do it because it's more approachable to them
| (and/or others). Others may have language models/runtimes that
| align closely with the target language. Or they may want to
| "stand on the shoulders of giants", benefiting from the higher-
| level optimizations of the target language. Also, for example,
| LLVM still doesn't target as many architectures as gcc (though
| I'm not saying that's necessarily very relevant for most
| users).
|
| That's just what comes to mind. I can't say for certain
| anything about this particular language though!
| sesuximo wrote:
| One reason is that c++ is a stable "api" whereas llvm ir is a
| somewhat moving target
| rurban wrote:
| Most importantly you get immediate startup. No need to parse
| and compile. Then you'll also need less memory.
|
| And third and less important you can add more expensive offline
| optimizations, which are too heavy at run-time. Like escape
| analysis, and inlining.
|
| Esp for the static parts. The dynamic parts just call into the
| shared ruby runtime.
| chrisseaton wrote:
| > Most importantly you get immediate startup. No need to
| parse and compile.
|
| Compiling to an IR doesn't mean 'and then interpret or JIT
| it'. Can can use an IR to compile to native. GCC, Clang, Rust
| etc all an IR, for example.
| kdasme wrote:
| I was under impression this can already be achieved via
| TruffleRuby compilation into a native image? Not that I used it,
| but thought this is doable, and the process is well tested.
| tambre wrote:
| autconf in 2021 instead of something more humane like CMake,
| Meson, Bazel, build2. Why?
| whyareyoul wrote:
| Whys it matter? Its solid, exists everywhere and works and
| contributors dont have to learn $buildsystem of the month
___________________________________________________________________
(page generated 2021-12-23 23:00 UTC)