If I take a ruby code
puts "Hello World!"
and rewrite it using the C API of Ruby
#include "ruby.h"
int main() {
ruby_init();
rb_funcall(Qnil, rb_intern("puts"), 1, rb_str_new2("Hello World!"));
ruby_finalize();
return 0;
}
and compile it, is this a way to compile Ruby code?
If I create a program that uses Ripper
to parse the Ruby code and rewrite it as C, can I call it as a "Ruby compiler"? There're some ruby code that can't be rewrited in Ruby in this way? Did someone tried to write this kind of "compiler" before?
A couple of good articles on this topic:
Also have you heard of Crystal? While not truly Ruby, it looks interesting:
Crystal is a programming language with the following goals:
- Have the same syntax as Ruby, or at least as similar as possible.
- Never have to specify the type of a variable or method argument.
- Be able to call C code by writing bindings to it in Crystal.
- Have compile-time evaluation and generation of code, to avoid boilerplate code.
- Compile to efficient native code.
about it on SO: Anybody tried the Crystal Programming Language (machine-code compiled Ruby)?
And another (commercial) project with the same purposes but mainly targeted at embedded development: http://foundry-lang.org/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With