Skip to content

Commit

Permalink
now compile some of the VM primitives into bitcode that will be added…
Browse files Browse the repository at this point in the history
… to the default compilation module and later inlined

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4136 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
lrz committed May 24, 2010
1 parent 6c1eac7 commit 002ed5d
Show file tree
Hide file tree
Showing 24 changed files with 1,648 additions and 2,267 deletions.
5 changes: 5 additions & 0 deletions HACKING.rdoc
Expand Up @@ -124,6 +124,11 @@ The following environment variables might help you debug easy bugs.
* VM_VERIFY_IR: set it to any value to force a LLVM module verification before * VM_VERIFY_IR: set it to any value to force a LLVM module verification before
the interpreter quits. the interpreter quits.


* VM_OPT_LEVEL: set it either to 0, 1, 2 or 3 to change the optimization level
of the LLVM code generator.

* VM_DISABLE_INLINING: set it to any value to disable function inlining.

* DYLD_LIBRARY_PATH: in case you are debugging a Cocoa application, set this * DYLD_LIBRARY_PATH: in case you are debugging a Cocoa application, set this
variable to "." before starting gdb, and you won't have to re-install MacRuby variable to "." before starting gdb, and you won't have to re-install MacRuby
every time you re-compile it. every time you re-compile it.
Expand Down
31 changes: 0 additions & 31 deletions array.c
Expand Up @@ -89,27 +89,6 @@ rary_erase(VALUE ary, size_t idx, size_t len)
return item; return item;
} }


void
rary_store(VALUE ary, long idx, VALUE item)
{
if (idx < 0) {
const long len = RARY(ary)->len;
idx += len;
if (idx < 0) {
rb_raise(rb_eIndexError, "index %ld out of array",
idx - len);
}
}
if (idx >= RARY(ary)->len) {
rary_reserve(ary, idx + 1);
for (size_t i = RARY(ary)->len; i < idx + 1; i++) {
rary_elt_set(ary, i, Qnil);
}
RARY(ary)->len = idx + 1;
}
rary_elt_set(ary, idx, item);
}

static void static void
rary_resize(VALUE ary, size_t newlen) rary_resize(VALUE ary, size_t newlen)
{ {
Expand Down Expand Up @@ -217,8 +196,6 @@ rb_ary_new(void)
return rb_ary_new2(ARY_DEFAULT_SIZE); return rb_ary_new2(ARY_DEFAULT_SIZE);
} }


static void rary_push(VALUE ary, VALUE item);

VALUE VALUE
rb_ary_new3(long n, ...) rb_ary_new3(long n, ...)
{ {
Expand Down Expand Up @@ -488,14 +465,6 @@ rary_push_m(VALUE ary, SEL sel, VALUE item)
* #=> ["a", "b", "c", "d", "e", "f"] * #=> ["a", "b", "c", "d", "e", "f"]
*/ */


static void
rary_push(VALUE ary, VALUE item)
{
rary_reserve(ary, RARY(ary)->len + 1);
rary_elt_set(ary, RARY(ary)->len, item);
RARY(ary)->len++;
}

static VALUE static VALUE
rary_push_m2(VALUE ary, SEL sel, int argc, VALUE *argv) rary_push_m2(VALUE ary, SEL sel, int argc, VALUE *argv)
{ {
Expand Down
34 changes: 33 additions & 1 deletion array.h
Expand Up @@ -89,6 +89,39 @@ rary_entry(VALUE ary, long offset)
return rary_elt(ary, offset); return rary_elt(ary, offset);
} }


void rary_reserve(VALUE ary, size_t newlen);

static inline void
rary_store(VALUE ary, long idx, VALUE item)
{
if (idx < 0) {
const long len = RARY(ary)->len;
idx += len;
if (idx < 0) {
rb_raise(rb_eIndexError, "index %ld out of array",
idx - len);
}
}
size_t uidx = (size_t)idx;
if (uidx >= RARY(ary)->len) {
rary_reserve(ary, uidx + 1);
size_t i;
for (i = RARY(ary)->len; i < uidx + 1; i++) {
rary_elt_set(ary, i, Qnil);
}
RARY(ary)->len = uidx + 1;
}
rary_elt_set(ary, uidx, item);
}

static inline void
rary_push(VALUE ary, VALUE item)
{
rary_reserve(ary, RARY(ary)->len + 1);
rary_elt_set(ary, RARY(ary)->len, item);
RARY(ary)->len++;
}

static inline void static inline void
rb_ary_modify(VALUE ary) rb_ary_modify(VALUE ary)
{ {
Expand Down Expand Up @@ -120,7 +153,6 @@ VALUE rary_unshift(VALUE ary, SEL sel, int argc, VALUE *argv);
VALUE rary_each(VALUE ary, SEL sel); VALUE rary_each(VALUE ary, SEL sel);
VALUE rary_sort(VALUE ary, SEL sel); VALUE rary_sort(VALUE ary, SEL sel);
VALUE rary_sort_bang(VALUE ary, SEL sel); VALUE rary_sort_bang(VALUE ary, SEL sel);
void rary_store(VALUE ary, long idx, VALUE item);
VALUE rary_subseq(VALUE ary, long beg, long len); VALUE rary_subseq(VALUE ary, long beg, long len);
void rary_insert(VALUE ary, long idx, VALUE val); void rary_insert(VALUE ary, long idx, VALUE val);


Expand Down
2 changes: 1 addition & 1 deletion b.rb
@@ -1,6 +1,6 @@
def bench(e, options) def bench(e, options)
puts e puts e
['./miniruby', 'ruby19'].each do |r| ['./miniruby', 'ruby1.9'].each do |r|
puts `#{r} -v`.strip puts `#{r} -v`.strip
line = File.exist?(e) ? "#{r} \"#{e}\"" : "#{r} -e \"#{e}\"" line = File.exist?(e) ? "#{r} \"#{e}\"" : "#{r} -e \"#{e}\""
n = options.include?('--no-rehearsal') ? 1 : 3 n = options.include?('--no-rehearsal') ? 1 : 3
Expand Down
36 changes: 4 additions & 32 deletions bignum.c
Expand Up @@ -270,20 +270,6 @@ rb_int2big(SIGNED_VALUE n)
return big; return big;
} }


VALUE
rb_uint2inum(VALUE n)
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_uint2big(n);
}

VALUE
rb_int2inum(SIGNED_VALUE n)
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_int2big(n);
}

#ifdef HAVE_LONG_LONG #ifdef HAVE_LONG_LONG


void void
Expand Down Expand Up @@ -628,8 +614,8 @@ rb_str_to_inum(VALUE str, int base, int badcheck)


#if HAVE_LONG_LONG #if HAVE_LONG_LONG


static VALUE VALUE
rb_ull2big(unsigned LONG_LONG n) rb_ull2big(unsigned long long n)
{ {
BDIGIT_DBL num = n; BDIGIT_DBL num = n;
long i = 0; long i = 0;
Expand All @@ -649,8 +635,8 @@ rb_ull2big(unsigned LONG_LONG n)
return big; return big;
} }


static VALUE VALUE
rb_ll2big(LONG_LONG n) rb_ll2big(long long n)
{ {
long neg = 0; long neg = 0;
VALUE big; VALUE big;
Expand All @@ -666,20 +652,6 @@ rb_ll2big(LONG_LONG n)
return big; return big;
} }


VALUE
rb_ull2inum(unsigned LONG_LONG n)
{
if (POSFIXABLE(n)) return LONG2FIX(n);
return rb_ull2big(n);
}

VALUE
rb_ll2inum(LONG_LONG n)
{
if (FIXABLE(n)) return LONG2FIX(n);
return rb_ll2big(n);
}

#endif /* HAVE_LONG_LONG */ #endif /* HAVE_LONG_LONG */


VALUE VALUE
Expand Down
16 changes: 5 additions & 11 deletions bridgesupport.cpp
Expand Up @@ -701,6 +701,7 @@ rb_boxed_objc_type(VALUE rcv, SEL sel)
return rb_ivar_get(rcv, boxed_ivar_type); return rb_ivar_get(rcv, boxed_ivar_type);
} }


extern "C"
bool bool
rb_boxed_is_type(VALUE klass, const char *type) rb_boxed_is_type(VALUE klass, const char *type)
{ {
Expand Down Expand Up @@ -764,6 +765,7 @@ rb_pointer_init_type(rb_vm_pointer_t *ptr, VALUE type)
assert(ptr->type_size > 0); assert(ptr->type_size > 0);
} }


extern "C"
VALUE VALUE
rb_pointer_new(const char *type_str, void *val, size_t len) rb_pointer_new(const char *type_str, void *val, size_t len)
{ {
Expand All @@ -779,6 +781,7 @@ rb_pointer_new(const char *type_str, void *val, size_t len)


static VALUE rb_pointer_aset(VALUE rcv, SEL sel, VALUE idx, VALUE val); static VALUE rb_pointer_aset(VALUE rcv, SEL sel, VALUE idx, VALUE val);


extern "C"
VALUE VALUE
rb_pointer_new2(const char *type_str, VALUE rval) rb_pointer_new2(const char *type_str, VALUE rval)
{ {
Expand Down Expand Up @@ -828,6 +831,7 @@ rb_pointer_s_new(VALUE rcv, SEL sel, int argc, VALUE *argv)
xmalloc(GET_CORE()->get_sizeof(type_str) * rlen), rlen); xmalloc(GET_CORE()->get_sizeof(type_str) * rlen), rlen);
} }


extern "C"
void * void *
rb_pointer_get_data(VALUE rcv, const char *type) rb_pointer_get_data(VALUE rcv, const char *type)
{ {
Expand Down Expand Up @@ -1115,17 +1119,7 @@ RoxorCore::bs_parse_cb(bs_element_type_t type, void *value, void *ctx)
if (!CFDictionaryGetValueIfPresent(rb_cObject_dict, if (!CFDictionaryGetValueIfPresent(rb_cObject_dict,
(const void *)name, NULL)) { (const void *)name, NULL)) {


VALUE val; VALUE val = rb_str_new2(bs_strconst->value);
#if 0 // this is likely not needed anymore
if (bs_strconst->nsstring) {
CFStringRef string = CFStringCreateWithCString(NULL,
bs_strconst->value, kCFStringEncodingUTF8);
val = (VALUE)string;
}
else {
#endif
val = rb_str_new2(bs_strconst->value);
// }
CFDictionarySetValue(rb_cObject_dict, (const void *)name, CFDictionarySetValue(rb_cObject_dict, (const void *)name,
(const void *)val); (const void *)val);
} }
Expand Down
16 changes: 10 additions & 6 deletions bridgesupport.h
Expand Up @@ -10,6 +10,16 @@
#define __BRIDGESUPPORT_H_ #define __BRIDGESUPPORT_H_


#if defined(__cplusplus) #if defined(__cplusplus)
extern "C" {
#endif

void *rb_pointer_get_data(VALUE rcv, const char *type);
VALUE rb_pointer_new(const char *type_str, void *val, size_t len);
VALUE rb_pointer_new2(const char *type_str, VALUE val);
bool rb_boxed_is_type(VALUE klass, const char *type);

#if defined(__cplusplus)
} // extern "C"


#include "bs.h" #include "bs.h"


Expand All @@ -25,12 +35,6 @@ typedef struct rb_vm_bs_boxed {
VALUE klass; VALUE klass;
} rb_vm_bs_boxed_t; } rb_vm_bs_boxed_t;


VALUE rb_pointer_new(const char *type_str, void *val, size_t len);
VALUE rb_pointer_new2(const char *type_str, VALUE val);
void *rb_pointer_get_data(VALUE rcv, const char *type);

bool rb_boxed_is_type(VALUE klass, const char *type);

#endif /* __cplusplus */ #endif /* __cplusplus */


#endif /* __BRIDGESUPPORT_H_ */ #endif /* __BRIDGESUPPORT_H_ */
61 changes: 61 additions & 0 deletions class.h
Expand Up @@ -39,6 +39,67 @@ CFMutableDictionaryRef rb_class_ivar_dict(VALUE);
CFMutableDictionaryRef rb_class_ivar_dict_or_create(VALUE); CFMutableDictionaryRef rb_class_ivar_dict_or_create(VALUE);
void rb_class_ivar_set_dict(VALUE, CFMutableDictionaryRef); void rb_class_ivar_set_dict(VALUE, CFMutableDictionaryRef);


typedef enum {
SCOPE_DEFAULT = 0, // public for everything but Object
SCOPE_PUBLIC,
SCOPE_PRIVATE,
SCOPE_PROTECTED,
SCOPE_MODULE_FUNC,
} rb_vm_scope_t;

static inline void
rb_vm_check_if_module(VALUE mod)
{
switch (TYPE(mod)) {
case T_CLASS:
case T_MODULE:
break;

default:
rb_raise(rb_eTypeError, "%s is not a class/module",
RSTRING_PTR(rb_inspect(mod)));
}
}

static inline void
rb_vm_set_current_scope(VALUE mod, rb_vm_scope_t scope)
{
if (scope == SCOPE_DEFAULT) {
scope = mod == rb_cObject ? SCOPE_PRIVATE : SCOPE_PUBLIC;
}
long v = RCLASS_VERSION(mod);
switch (scope) {
case SCOPE_PUBLIC:
v &= ~RCLASS_SCOPE_PRIVATE;
v &= ~RCLASS_SCOPE_PROTECTED;
v &= ~RCLASS_SCOPE_MOD_FUNC;
break;

case SCOPE_PRIVATE:
v |= RCLASS_SCOPE_PRIVATE;
v &= ~RCLASS_SCOPE_PROTECTED;
v &= ~RCLASS_SCOPE_MOD_FUNC;
break;

case SCOPE_PROTECTED:
v &= ~RCLASS_SCOPE_PRIVATE;
v |= RCLASS_SCOPE_PROTECTED;
v &= ~RCLASS_SCOPE_MOD_FUNC;
break;

case SCOPE_MODULE_FUNC:
v &= ~RCLASS_SCOPE_PRIVATE;
v &= ~RCLASS_SCOPE_PROTECTED;
v |= RCLASS_SCOPE_MOD_FUNC;
break;

case SCOPE_DEFAULT:
abort(); // handled earlier
}

RCLASS_SET_VERSION(mod, v);
}

#if defined(__cplusplus) #if defined(__cplusplus)
} // extern "C" } // extern "C"
#endif #endif
Expand Down

0 comments on commit 002ed5d

Please sign in to comment.