Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-settings.php on line 468

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-settings.php on line 483

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-settings.php on line 490

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-settings.php on line 526

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-includes/cache.php on line 103

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /home/worldofb/public_html/llvmruby/wordpress-llvmruby/wp-includes/theme.php on line 618
support for 32-bit and 64-bit ruby interpreters at llvmruby.org

llvmruby.org

support for 32-bit and 64-bit ruby interpreters

2 comments

Tonight, I implemented and tested support for 32-bit Ruby. How does this work?

  // Figure out details of the target machine
  const IntegerType *machine_word_type;
  if(sizeof(void*) == 4) {
    machine_word_type = Type::Int32Ty;
  } else {
    machine_word_type = Type::Int64Ty;
  }
  rb_define_const(cLLVMRuby, "MACHINE_WORD", Data_Wrap_Struct(cLLVMType, NULL, NULL, const_cast<IntegerType*>(machine_word_type)));

First the extension creates a MACHINE_WORD type based on the pointer size of the machine.

  # describe structures used by the ruby 1.8/1.9 interpreters
  module RubyInternals
    FIXNUM_FLAG = 0x1.llvm
    CHAR = Type::Int8Ty
    P_CHAR = Type::pointer(CHAR)
    LONG = MACHINE_WORD
    VALUE = MACHINE_WORD
    P_VALUE = Type::pointer(VALUE)
    ID = MACHINE_WORD
    RBASIC = Type::struct([VALUE, VALUE])
    RARRAY = Type::struct([RBASIC, LONG, LONG, P_VALUE])
    P_RARRAY = Type::pointer(RARRAY)
    RSTRING = Type::struct([RBASIC, LONG, P_CHAR, VALUE])
    P_RSTRING = Type::pointer(RSTRING)
  end

All the Ruby data types are defined in the RubyInternals module.

If you are familiar with Ruby internals from having worked on C extensions, you will know that everything is a VALUE, which is one machine word that is either nil, true, false, a FixInt, or a pointer to a struct somewhere on the heap. This makes our definitions pretty simple, all that changes between machines is the size of this pointer.

You’ll also notice in this code, that the native Ruby data types themselves are defined in Ruby code here. For example, an Array in Ruby is represented internally using this struct:

struct RArray {
    struct RBasic basic;
    long len;
    union {
        long capa;
        VALUE shared;
    } aux;
    VALUE *ptr;
};

And in our Ruby mappings that allows us to work on this structure, it’s defined basically the same way using LLVM data types:

RARRAY = Type::struct([RBASIC, LONG, LONG, P_VALUE])

Easy!

Written by tom

August 27th, 2008 at 5:30 am

Posted in Uncategorized

2 Responses to 'support for 32-bit and 64-bit ruby interpreters'

Subscribe to comments with RSS or TrackBack to 'support for 32-bit and 64-bit ruby interpreters'.

  1. ???

    ?? ??? ??????, ??? ?????????? ??????, ???? ????????? ??????? ? ??????????….

    ????? ????????

    17 Mar 10 at 3:01 am

  2. ? ?????????, ??, ??-?????, ?? ?????????? ??????. ????????? ??? ????????. ?????? ??? ? PM, ??????????….

    ????????????? ? ?????????????? Tonight, I implemented and tested support for 32-bit Ruby…..

    Kylie BattName

    11 Apr 10 at 6:36 pm

Leave a Reply