Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Deccan Ruby Conf 2017 Rubex intro

Deccan Ruby Conf 2017 Rubex intro

A lightning talk briefly describing Rubex with a simple example.

Sameer Deshmukh

August 12, 2017
Tweet

More Decks by Sameer Deshmukh

Other Decks in Programming

Transcript

  1. Rubex code C code CRuby runtime Language which looks like

    Ruby. Code ready to interface with Ruby. Code actually runs here.
  2. def fibo(n) a, b, i, temp = 1, 1, 0,

    nil print a, "\n" print b, "\n" while i < n do temp = b b = a + b a = temp i += 1 print b, "\n" end end fibo(10);
  3. VALUE cfibo(VALUE obj_n, VALUE self) { int n = INT2FIX(obj_n);

    int i = 0, a = 1, b = 1, temp = 0; printf("%d\n", a); printf("%d\n", b); while (i < n) { temp = b; b = a + b; a = temp; i += 1; print("%d\n", b); } return self; } Init_fibo(void) { rb_define_global_function("fibo", cfibo, 1); }
  4. BIG Problems • Difficult and irritating to write. • Debugging

    is time consuming. • Remember the CRuby C API. • Need to care about small things.™* *Matz.
  5. def fibo(int n) int a = 1, b = 1,

    i = 0, temp = 0 print a, "\n" print b, "\n" while i < n do temp = b b = a + b a = temp i += 1 print b, "\n" end end
  6. def fibo(int n) int a = 1, b = 1,

    i = 0, temp = 0 print a, "\n" print b, "\n" while i < n do temp = b b = a + b a = temp i += 1 print b, "\n" end end
  7. Salient Features • Looks exactly like Ruby but with the

    ability to declare C types. • Implicit, transparent conversion and interfacing between Ruby and C. • Compiles to C code so is super fast. • Simple and intuitive interfaces to the Ruby GC. • Interface with external C libraries.