Cython-like language for Ruby

301 views
Skip to first unread message

Sameer Deshmukh

unread,
May 9, 2016, 2:59:37 PM5/9/16
to SciRuby Development
Hello,

So I was thinking about how we spend so much time writing C or Java extensions for our gems, and it seems that a viable way forward would be develop a Cython-like statically typed sub-language for Ruby that can be easily called from a Ruby script (the way Cython works with Python).

Yehuda Katz (Rails and Ember.js fame) has recently released the Helix gem, which allows for very simple interaction between Ruby and Rust. If you have a look at the tutorial you'll notice that getting a Rust<-> Ruby bridge setup has now become an almost brainless activity.

I'm wondering if we can make some thing like these tools for work in SciRuby. It can have the following features:
  • Should look and feel like Ruby.
  • Should be able to compile to either C or Java depending on the interpreter it is being compiled for (maybe support just C initially).
  • Will let one work trasparently work with the MRI/JRuby C/Java API (MRI API changes should not reflect in the language). This is especially important after the build failures caused on NMatrix after the Ruby 2.3.0 upgrade. That we can just modify the language and gems need not bother about the actual implementation.
  • Be very easy to call that code from a Ruby script (like Helix lets one call Rust code).
Your ideas and leads will be much appreciated!

Victor Shepelev

unread,
May 9, 2016, 3:26:24 PM5/9/16
to sciru...@googlegroups.com
There is interesting example in Crystal language: http://crystal-lang.org/
It was started exactly as "Ruby with type annotations and compilable", but then had drift apart.

It is still pretty like Ruby, but not completely. And, as far as I know, its just because Ruby's type systems and message passing semantic don't allow anything near effective compilation, even with type annotations.

--
You received this message because you are subscribed to the Google Groups "SciRuby Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sciruby-dev...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sameer Deshmukh

unread,
May 9, 2016, 4:43:20 PM5/9/16
to SciRuby Development
So I'm thinking more on the lines of generating working C code from the script that will be written. It's job will be to generate Ruby extension modules. It's basically a C code generator that looks and feels like Ruby.

Sameer Deshmukh

unread,
May 9, 2016, 5:03:31 PM5/9/16
to SciRuby Development
Here's a thread that further clarifies what I'm saying: https://github.com/crystal-lang/crystal/issues/1717

Victor Shepelev

unread,
May 9, 2016, 5:04:43 PM5/9/16
to sciru...@googlegroups.com
Yep, thanks, already found it too :)

Sameer Deshmukh

unread,
May 9, 2016, 5:37:07 PM5/9/16
to SciRuby Development
Something interesting (but now dead): http://www.zenspider.com/pdf/Ruby2C.pdf

Kenta Murata

unread,
May 10, 2016, 12:40:09 AM5/10/16
to SciRuby Development
There is another approach taken by ko1 (YARV developer).
This mixes Ruby and C by a special method-call syntax.


Unfortunately Japanese paper and presentation are only available.
But you can read abstract part written in English and some code part.
Check it up.

2016年5月10日火曜日 6時37分07秒 UTC+9 Sameer Deshmukh:

Sameer Deshmukh

unread,
May 10, 2016, 3:24:20 AM5/10/16
to SciRuby Development
Is he still working on this? Could you point me to the code repo (if any)?

I'm extremely excited about this project and would like to take it up and get a working prototype out there ASAP.

Jens Wille

unread,
May 10, 2016, 5:26:19 AM5/10/16
to sciru...@googlegroups.com
Sameer Deshmukh [2016-05-10 09:24]:
> Is he still working on this? Could you point me to the code repo
> (if any)?
apparently not, but you can find the code and some english
documentation here:

<https://github.com/ko1/ruby/tree/ricsin/ricsin>

cheers
jens

Sameer Deshmukh

unread,
May 10, 2016, 9:07:11 AM5/10/16
to SciRuby Development, li...@blackwinter.de
Ricsin looks like something similar to Inline::C, the difference being that it defines an explicit syntax for writing inline C code into Ruby scripts.

I'm looking for a language which looks and feels like Ruby, yet compiles to C and is easily callable from Ruby scripts. I think that would be the easiest way to write C extensions for Ruby since you never the comfort of Ruby (almost).
Reply all
Reply to author
Forward
0 new messages