Skip to content

Commit

Permalink
v0.3.4 => v0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Satoshi Shiba committed Nov 28, 2011
1 parent 83f5dd1 commit 8932d9b
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 172 deletions.
6 changes: 4 additions & 2 deletions cast_off.gemspec
@@ -1,10 +1,12 @@
Gem::Specification.new do |spec|
spec.name = "cast_off"
spec.version = "0.3.3"
spec.version = "0.3.5"
spec.platform = Gem::Platform::RUBY
spec.summary = "Compiler for Ruby1.9.3"
spec.description = <<-EOS
CastOff is a compiler for Ruby1.9.3
CastOff is a compiler for Ruby1.9.3.
Command line tool cast_off is available after installation.
See 'cast_off --help' for more information.
EOS
spec.files = Dir['{lib/**/*,ext/**/*}'] + %w[
cast_off.gemspec
Expand Down
19 changes: 17 additions & 2 deletions ext/cast_off/cast_off.c.rb
Expand Up @@ -734,6 +734,12 @@ def = me->def;
}
}

static VALUE cast_off_class_wrapper_method_defined_p(VALUE self, VALUE mid)
{
VALUE klass = cast_off_class_wrapper_get_class(self);
return search_method(klass, SYM2ID(mid)) ? Qtrue : Qfalse;
}

static VALUE cast_off_class_wrapper_get_method_type(VALUE self, VALUE mid)
{
VALUE klass = cast_off_class_wrapper_get_class(self);
Expand Down Expand Up @@ -948,14 +954,22 @@ module = wrapper->module;
VALUE module = cast_off_module_wrapper_get_module(self);
VALUE name = rb_mod_name(module);

/* TODO error handling */
if (TYPE(name) != T_STRING) {
rb_raise(rb_eTypeError, "failed to get module name");
}

return name;
}

static VALUE cast_off_module_wrapper_marshal_load(VALUE self, VALUE name)
{
VALUE module = rb_path_to_class(name);
VALUE module;

if (NIL_P(name)) {
rb_raise(rb_eArgError, "invalid marshal");
}

module = rb_path_to_class(name);
if (rb_obj_class(module) != rb_cModule) {
rb_raise(rb_eCastOffCompileError, "failed to load module");
}
Expand Down Expand Up @@ -1495,6 +1509,7 @@ module = wrapper->module;
rb_define_method(rb_cCastOffClassWrapper, "singleton?", cast_off_class_wrapper_singleton_p, 0);
rb_define_method(rb_cCastOffClassWrapper, "get_cfunc_argc", cast_off_class_wrapper_get_cfunc_argc, 1);
rb_define_method(rb_cCastOffClassWrapper, "get_method_type", cast_off_class_wrapper_get_method_type, 1);
rb_define_method(rb_cCastOffClassWrapper, "method_defined?", cast_off_class_wrapper_method_defined_p, 1);
rb_define_method(rb_cCastOffClassWrapper, "get_attr_id", cast_off_class_wrapper_get_attr_id, 1);
rb_define_method(rb_cCastOffClassWrapper, "instance_method_exist?", cast_off_class_wrapper_instance_method_exist_p, 1);
rb_define_method(rb_cCastOffClassWrapper, "contain_class", cast_off_class_wrapper_contain_class, 0);
Expand Down
4 changes: 2 additions & 2 deletions ext/cast_off/depend
Expand Up @@ -3,7 +3,7 @@ $(srcdir)/generated_c_include/unbox_api.h: \
$(RUBY) -- $(srcdir)/generated_c_include/unbox_api.h.rb > $@


cast_off.c: \
$(srcdir)/cast_off.c: \
$(srcdir)/ruby_source/1.9.3/debug.h \
$(srcdir)/ruby_source/1.9.3/gc.h \
$(srcdir)/ruby_source/1.9.3/id.h \
Expand Down Expand Up @@ -51,7 +51,7 @@ cast_off.c: \
$(RUBY) -- $(srcdir)/cast_off.c.rb $(srcdir)/ruby_source $(srcdir)/generated_c_include > $@


cast_off.o: \
$(srcdir)/cast_off.o: \
$(arch_hdrdir)/ruby/config.h \
$(hdrdir)/ruby/defines.h \
$(hdrdir)/ruby/intern.h \
Expand Down
4 changes: 2 additions & 2 deletions ext/cast_off/extconf.rb
Expand Up @@ -12,8 +12,8 @@
$defs.push '-DCABI_PASS_CFP' if enable_config 'cabi-pass-cfp', true

$INCFLAGS << ' -I$(srcdir)/ruby_source'
$objs = %w'cast_off.o'
$srcs = %w'cast_off.c.rb'
$objs = %w'$(srcdir)/cast_off.o'
$srcs = %w'$(srcdir)/cast_off.c.rb'
create_header
create_makefile 'cast_off'

109 changes: 0 additions & 109 deletions ext/cast_off/generated_c_include/inline_api.h
@@ -1,114 +1,5 @@
#define TYPE_ERROR_MESSAGE() "type mismatch"

static inline VALUE
cast_off_inline_fixnum_fixnum_plus(VALUE recv, VALUE obj)
{
#if 0
#ifdef INJECT_GUARD
if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif
#endif

#ifndef LONG_LONG_VALUE
{
VALUE val = (recv + (obj & (~1)));
#ifdef INJECT_GUARD
if ((~(recv ^ obj) & (recv ^ val)) & ((VALUE)0x01 << ((sizeof(VALUE) * CHAR_BIT) - 1))) {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif /* INJECT_GUARD */
return val;
}
#else /* LONG_LONG_VALUE */
{
long a, b, c;
a = FIX2LONG(recv);
b = FIX2LONG(obj);
c = a + b;
#ifdef INJECT_GUARD
if (UNLIKELY(!FIXABLE(c))) {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif /* INJECT_GUARD */
return LONG2FIX(c);
}
#endif /* LONG_LONG_VALUE */
}

static inline VALUE
cast_off_inline_fixnum_float_plus(VALUE recv, VALUE obj)
{
return DBL2NUM((double)FIX2LONG(recv) + RFLOAT_VALUE(obj));
}

static inline VALUE
cast_off_inline_fixnum_fixnum_minus(VALUE recv, VALUE obj)
{
long a, b, c;

#if 0
#ifdef INJECT_GUARD
if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif
#endif

a = FIX2LONG(recv);
b = FIX2LONG(obj);
c = a - b;
#ifdef INJECT_GUARD
if (LIKELY(FIXABLE(c))) {
#endif
return LONG2FIX(c);
#ifdef INJECT_GUARD
} else {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif
}

static inline VALUE
cast_off_inline_fixnum_float_minus(VALUE recv, VALUE obj)
{
return DBL2NUM((double)FIX2LONG(recv) - RFLOAT_VALUE(obj));
}

static inline VALUE
cast_off_inline_fixnum_fixnum_mult(VALUE recv, VALUE obj)
{
long a, b, c;

#if 0
#ifdef INJECT_GUARD
if (UNLIKELY(!FIXNUM_2_P(recv, obj))) {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif
#endif

a = FIX2LONG(recv);
b = FIX2LONG(obj);
c = a * b;
#ifdef INJECT_GUARD
if (LIKELY(FIXABLE(c))) {
#endif
return LONG2FIX(c);
#ifdef INJECT_GUARD
} else {
rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE());
}
#endif
}

static inline VALUE
cast_off_inline_fixnum_float_mult(VALUE recv, VALUE obj)
{
return DBL2NUM((double)FIX2LONG(recv) * RFLOAT_VALUE(obj));
}

static inline VALUE
cast_off_inline_fixnum_le(VALUE recv, VALUE obj)
{
Expand Down
70 changes: 57 additions & 13 deletions ext/cast_off/generated_c_include/unbox_api.h.rb
Expand Up @@ -9,91 +9,129 @@
#endif
__END__
#define CBOOL2RBOOL(b) ((b) ? Qtrue : Qfalse)
#ifdef INJECT_GUARD
#define CFIX2RFIX(b) (FIXABLE?((b)) ? LONG2FIX((b)) : rb_raise(rb_eCastOffExecutionError, TYPE_ERROR_MESSAGE()))
#else
#define CFIX2RFIX(b) LONG2FIX((b))
#endif
static inline VALUE CDOUBLE2RINT(double f)
{
if (f > 0.0) f = floor(f);
if (f < 0.0) f = ceil(f);
return FIXABLE(f) ? LONG2FIX((double)f) : rb_dbl2big(f);
}
static inline VALUE PLUS(long a, long b)
{
long c = a + b;
if (FIXABLE(c)) {
return LONG2FIX(c);
} else {
return rb_big_plus(rb_int2big(a), rb_int2big(b));
}
}
static inline VALUE MINUS(long a, long b)
{
long c = a - b;
if (FIXABLE(c)) {
return LONG2FIX(c);
} else {
return rb_big_minus(rb_int2big(a), rb_int2big(b));
}
}
static inline VALUE MULT(long a, long b)
{
if (a == 0) {
return LONG2FIX(0);
} else {
volatile long c = a * b;
if (FIXABLE(c) && c / a == b) {
return LONG2FIX(c);
} else {
return rb_big_mul(rb_int2big(a), rb_int2big(b));
}
}
}

%# arg size, [type0, type1, ...]
%[['float',
% {'-' => 'uminus'},
% 0,
% :unary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {},
% {'VALUE' => 'DBL2NUM', 'double' => ''}],
% ['float',
% {'' => 'to_f'},
% 0,
% :unary_operator,
% {'VALUE' => ''},
% {},
% {'VALUE' => '', 'double' => 'RFLOAT_VALUE'}],
% ['float',
% {'' => 'to_i'},
% 0,
% :unary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {},
% {'VALUE' => 'CDOUBLE2RINT'}],
% ['fixnum',
% {'-' => 'uminus'},
% 0,
% :unary_operator,
% {'VALUE' => 'FIX2LONG', 'long' => ''},
% {},
% {'VALUE' => 'CFIX2RFIX', 'long' => ''}],
% {'VALUE' => 'LONG2NUM'}],
% ['fixnum',
% {'(double)' => 'to_f'},
% 0,
% :unary_operator,
% {'VALUE' => 'FIX2LONG', 'long' => ''},
% {},
% {'VALUE' => 'DBL2NUM', 'double' => ''}],
% ['float_float',
% {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
% 1,
% :binary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'DBL2NUM', 'double' => ''}],
% ['float_float',
% {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
% 1,
% :binary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'CBOOL2RBOOL'}],
% ['fixnum_fixnum',
% {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
% {'PLUS' => 'plus', 'MINUS' => 'minus', 'MULT' => 'mult'},
% 1,
% :function,
% {'VALUE' => 'FIX2LONG', 'long' => ''},
% {'VALUE' => 'FIX2LONG', 'long' => ''},
% {'VALUE' => 'CFIX2RFIX', 'long' => ''}],
% {'VALUE' => ''}],
% ['fixnum_float',
% {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
% {'+' => 'plus', '-' => 'minus', '*' => 'mult'},
% 1,
% :binary_operator,
% {'VALUE' => '(double)FIX2LONG', 'long' => ''},
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'DBL2NUM', 'double' => ''}],
% ['fixnum_float',
% {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
% 1,
% :binary_operator,
% {'VALUE' => '(double)FIX2LONG', 'long' => ''},
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => 'CBOOL2RBOOL'}],
% ['float_fixnum',
% {'+' => 'plus', '-' => 'minus', '*' => 'mult', '/' => 'div'},
% 1,
% :binary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => '(double)FIX2LONG', 'long' => ''},
% {'VALUE' => 'DBL2NUM', 'double' => ''}],
% ['float_fixnum',
% {'>' => 'gt', '>=' => 'ge', '<' => 'lt', '<=' => 'le', '==' => 'eq', '==' => 'eqq'},
% 1,
% :binary_operator,
% {'VALUE' => 'RFLOAT_VALUE', 'double' => ''},
% {'VALUE' => '(double)FIX2LONG', 'long' => ''},
% {'VALUE' => 'CBOOL2RBOOL'}]].each do |(function_name, h, argc, reciever_converter, arguments_converter, return_value_converter)|
% {'VALUE' => 'CBOOL2RBOOL'}]].each do |(function_name, h, argc, operation, reciever_converter, arguments_converter, return_value_converter)|
% arguments_decls = arguments_converter.keys
% reciever_decls = reciever_converter.keys
% return_value_decls = return_value_converter.keys
Expand All @@ -117,11 +155,17 @@
static inline <%= return_value %>
cast_off_inline_<%= function_name %>_<%= name %>_<%= suffix %>(<%= parameter.join(', ') %>)
{
% if argc > 0
% case operation
% when :unary_operator
% raise unless argc == 0 && statement.size == 1
return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.first %>));
% when :binary_operator
% raise unless argc == 1 && statement.size == 2
return <%= return_value_converter[return_value] %>(<%= statement.join(" #{operator} ") %>);
% when :function
return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.join(", ") %>));
% else
% raise unless statement.size == 1
return <%= return_value_converter[return_value] %>(<%= operator %>(<%= statement.first %>));
% raise
% end
}
% end
Expand Down

0 comments on commit 8932d9b

Please sign in to comment.