diff options
| -rw-r--r-- | build_config/boxing.rb | 129 | ||||
| -rw-r--r-- | build_config/host-m32.rb | 2 | ||||
| -rw-r--r-- | include/mruby.h | 2 | ||||
| -rw-r--r-- | include/mruby/ops.h | 7 | ||||
| -rw-r--r-- | src/class.c | 10 | ||||
| -rw-r--r-- | src/numeric.c | 64 | ||||
| -rw-r--r-- | src/vm.c | 9 | ||||
| -rw-r--r-- | tasks/toolchains/gcc.rake | 2 | ||||
| -rw-r--r-- | test/t/float.rb | 14 |
9 files changed, 170 insertions, 69 deletions
diff --git a/build_config/boxing.rb b/build_config/boxing.rb index 242e0fe0a..75046e371 100644 --- a/build_config/boxing.rb +++ b/build_config/boxing.rb @@ -1,32 +1,151 @@ -MRuby::Build.new('no-boxing') do |conf| +MRuby::Build.new('boxing-no-m64-i64') do |conf| toolchain :gcc + conf.cc.flags << '-m64' + conf.linker.flags << '-m64' + conf.gembox 'default' conf.compilers.each do |c| - c.defines += %w(MRB_NO_BOXING) + c.defines += %w(MRB_NO_BOXING MRB_INT64) end + conf.enable_debug conf.enable_test conf.enable_bintest end -MRuby::Build.new('word_boxing') do |conf| +MRuby::Build.new('boxing-no-m64-i32') do |conf| toolchain :gcc + conf.cc.flags << '-m64' + conf.linker.flags << '-m64' + conf.gembox 'default' conf.compilers.each do |c| - c.defines += %w(MRB_WORD_BOXING) + c.defines += %w(MRB_NO_BOXING MRB_INT32) end + conf.enable_debug conf.enable_test conf.enable_bintest end -MRuby::Build.new('nan_boxing') do |conf| +MRuby::Build.new('boxing-no-m32-i64') do |conf| toolchain :gcc + conf.cc.flags << '-m32' + conf.linker.flags << '-m32' + + # Turn on `enable_debug` for better debugging + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_NO_BOXING MRB_INT64) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-no-m32-i32') do |conf| + toolchain :gcc + + conf.cc.flags << '-m32' + conf.linker.flags << '-m32' + + # Turn on `enable_debug` for better debugging + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_NO_BOXING MRB_INT32) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-word-m64-i64') do |conf| + toolchain :gcc + + conf.cc.flags << '-m64' + conf.linker.flags << '-m64' + + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_WORD_BOXING MRB_INT64) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-word-m64-i32') do |conf| + toolchain :gcc + + conf.cc.flags << '-m64' + conf.linker.flags << '-m64' + + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_WORD_BOXING MRB_INT32) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-word-m32-i64') do |conf| + toolchain :gcc + + conf.cc.flags << '-m32' + conf.linker.flags << '-m32' + + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_WORD_BOXING MRB_INT64) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-word-m32-i32') do |conf| + toolchain :gcc + + conf.cc.flags << '-m32' + conf.linker.flags << '-m32' + + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_WORD_BOXING MRB_INT32) + end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-nan-m64') do |conf| + toolchain :gcc + + conf.cc.flags << '-m64' + conf.linker.flags << '-m64' + conf.gembox 'default' conf.compilers.each do |c| c.defines += %w(MRB_NAN_BOXING) end + conf.enable_debug + conf.enable_test + conf.enable_bintest +end + +MRuby::Build.new('boxing-nan-m64') do |conf| + toolchain :gcc + + conf.cc.flags << '-m32' + conf.linker.flags << '-m32' + + conf.gembox 'default' + conf.compilers.each do |c| + c.defines += %w(MRB_NAN_BOXING MRB_INT32) + end + conf.enable_debug conf.enable_test conf.enable_bintest end diff --git a/build_config/host-m32.rb b/build_config/host-m32.rb index c2b07137f..9e27a0792 100644 --- a/build_config/host-m32.rb +++ b/build_config/host-m32.rb @@ -9,7 +9,7 @@ MRuby::Build.new do |conf| conf.linker.flags << '-m32' # Turn on `enable_debug` for better debugging - enable_debug + conf.enable_debug conf.enable_test conf.enable_bintest end diff --git a/include/mruby.h b/include/mruby.h index 0fad0d440..8099a85e2 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -287,7 +287,7 @@ typedef struct mrb_state { struct RObject *nomem_err; /* pre-allocated NoMemoryError */ struct RObject *stack_err; /* pre-allocated SysStackError */ #ifdef MRB_GC_FIXED_ARENA - struct RObject *arena_err; /* pre-allocated arena overfow error */ + struct RObject *arena_err; /* pre-allocated arena overflow error */ #endif void *ud; /* auxiliary data */ diff --git a/include/mruby/ops.h b/include/mruby/ops.h index 87f48d2a9..02f227634 100644 --- a/include/mruby/ops.h +++ b/include/mruby/ops.h @@ -61,13 +61,14 @@ OPCODE(SENDV, BB) /* R(a) = call(R(a),Syms(b),*R(a+1)) */ OPCODE(SENDVB, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),&R(a+2)) */ OPCODE(SEND, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c)) */ OPCODE(SENDB, BBB) /* R(a) = call(R(a),Syms(b),R(a+1),...,R(a+c),&R(a+c+1)) */ +OPCODE(SENDVK, BB) /* R(a) = call(R(a),Syms(b),*R(a+1),**(a+2),&R(a+3)) # todo */ OPCODE(CALL, Z) /* R(0) = self.call(frame.argc, frame.argv) */ OPCODE(SUPER, BB) /* R(a) = super(R(a+1),... ,R(a+b+1)) */ OPCODE(ARGARY, BS) /* R(a) = argument array (16=m5:r1:m5:d1:lv4) */ OPCODE(ENTER, W) /* arg setup according to flags (23=m5:o5:r1:m5:k5:d1:b1) */ -OPCODE(KEY_P, BB) /* R(a) = kdict.key?(Syms(b)) # todo */ -OPCODE(KEYEND, Z) /* raise unless kdict.empty? # todo */ -OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) # todo */ +OPCODE(KEY_P, BB) /* R(a) = kdict.key?(Syms(b)) */ +OPCODE(KEYEND, Z) /* raise unless kdict.empty? */ +OPCODE(KARG, BB) /* R(a) = kdict[Syms(b)]; kdict.delete(Syms(b)) */ OPCODE(RETURN, B) /* return R(a) (normal) */ OPCODE(RETURN_BLK, B) /* return R(a) (in-block return) */ OPCODE(BREAK, B) /* break R(a) */ diff --git a/src/class.c b/src/class.c index 26366aeb9..e28951499 100644 --- a/src/class.c +++ b/src/class.c @@ -1375,8 +1375,10 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru void *klass_mt = find_origin(c)->mt; while (m) { - int superclass_seen = 0; + int original_seen = FALSE; + int superclass_seen = FALSE; + if (c == ins_pos) original_seen = TRUE; if (m->flags & MRB_FL_CLASS_IS_PREPENDED) goto skip; @@ -1385,16 +1387,17 @@ include_module_at(mrb_state *mrb, struct RClass *c, struct RClass *ins_pos, stru p = c->super; while (p) { + if (c == p) original_seen = TRUE; if (p->tt == MRB_TT_ICLASS) { if (p->mt == m->mt) { - if (!superclass_seen) { + if (!superclass_seen && original_seen) { ins_pos = p; /* move insert point */ } goto skip; } } else if (p->tt == MRB_TT_CLASS) { if (!search_super) break; - superclass_seen = 1; + superclass_seen = TRUE; } p = p->super; } @@ -1569,7 +1572,6 @@ mrb_singleton_class_ptr(mrb_state *mrb, mrb_value v) case MRB_TT_TRUE: return mrb->true_class; case MRB_TT_CPTR: - return mrb->object_class; case MRB_TT_SYMBOL: case MRB_TT_INTEGER: #ifndef MRB_NO_FLOAT diff --git a/src/numeric.c b/src/numeric.c index fec79ffd1..a16b57dc9 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -249,8 +249,23 @@ flo_div(mrb_state *mrb, mrb_value xv) return mrb_float_value(mrb, x); } +/* 15.2.9.3.16(x) */ +/* + * call-seq: + * flt.to_s -> string + * flt.inspect -> string + * + * Returns a string containing a representation of self. As well as a + * fixed or exponential form of the number, the call may return + * "<code>NaN</code>", "<code>Infinity</code>", and + * "<code>-Infinity</code>". + * + * 3.0.to_s #=> 3.0 + * 3.25.to_s #=> 3.25 + */ + static mrb_value -flo_to_str(mrb_state *mrb, mrb_value flt, mrb_bool add_dot_zero) +flo_to_s(mrb_state *mrb, mrb_value flt) { mrb_float f = mrb_float(flt); mrb_value str; @@ -293,7 +308,7 @@ flo_to_str(mrb_state *mrb, mrb_value flt, mrb_bool add_dot_zero) str = mrb_float_to_str(mrb, flt, fmt); goto insert_dot_zero; } - else if (add_dot_zero) { + else { mrb_str_cat(mrb, str, ".0", 2); } @@ -305,49 +320,6 @@ flo_to_str(mrb_state *mrb, mrb_value flt, mrb_bool add_dot_zero) return str; } -/* 15.2.9.3.16(x) */ -/* - * call-seq: - * flt.to_s -> string - * - * Returns a string containing a representation of self. As well as a - * fixed or exponential form of the number, the call may return - * "<code>NaN</code>", "<code>Infinity</code>", and - * "<code>-Infinity</code>". - * - * Trailing <code>.0</code> is removed. - * - * 3.0.to_s #=> 3 - * 3.25.to_s #=> 3.25 - */ - -static mrb_value -flo_to_s(mrb_state *mrb, mrb_value flt) -{ - return flo_to_str(mrb, flt, FALSE); -} - -/* - * call-seq: - * flt.inspect -> string - * - * Returns a string containing a representation of self. As well as a - * fixed or exponential form of the number, the call may return - * "<code>NaN</code>", "<code>Infinity</code>", and - * "<code>-Infinity</code>". - * - * Trailing <code>.0</code> is added. - * - * 3.0.to_s #=> 3.0 - * 3.25.to_s #=> 3.25 - */ - -static mrb_value -flo_inspect(mrb_state *mrb, mrb_value flt) -{ - return flo_to_str(mrb, flt, TRUE); -} - /* 15.2.9.3.2 */ /* * call-seq: @@ -1725,7 +1697,7 @@ mrb_init_numeric(mrb_state *mrb) mrb_define_method(mrb, fl, "eql?", flo_eql, MRB_ARGS_REQ(1)); /* 15.2.8.3.16 */ mrb_define_method(mrb, fl, "to_s", flo_to_s, MRB_ARGS_NONE()); /* 15.2.9.3.16(x) */ - mrb_define_method(mrb, fl, "inspect", flo_inspect, MRB_ARGS_NONE()); + mrb_define_method(mrb, fl, "inspect", flo_to_s , MRB_ARGS_NONE()); mrb_define_method(mrb, fl, "nan?", flo_nan_p, MRB_ARGS_NONE()); #ifdef INFINITY @@ -1590,7 +1590,10 @@ RETRY_TRY_BLOCK: mrb_exc_set(mrb, exc); goto L_RAISE; } - if (target_class->tt == MRB_TT_MODULE) { + if (target_class->flags & MRB_FL_CLASS_IS_PREPENDED) { + target_class = ci->target_class; + } + else if (target_class->tt == MRB_TT_MODULE) { target_class = ci->target_class; if (target_class->tt != MRB_TT_ICLASS) { mrb_value exc = mrb_exc_new_lit(mrb, E_RUNTIME_ERROR, "superclass info lost [mruby limitations]"); @@ -2817,6 +2820,10 @@ RETRY_TRY_BLOCK: goto L_RAISE; } + CASE(OP_SENDVK, BB) { /* not yet implemented */ + NEXT; + } + CASE(OP_STOP, Z) { /* stop VM */ CHECKPOINT_RESTORE(RBREAK_TAG_STOP) { diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index b5d6e1f25..34d747af5 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -6,7 +6,7 @@ MRuby::Toolchain.new(:gcc) do |conf, params| [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler| if compiler == conf.cxx - compiler.command = ENV['CXX'] || default_command.sub(/cc|$/, '++') + compiler.command = ENV['CXX'] || conf.cc.command.sub(/g\Kcc|$/, '++') compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compiler_flags] else compiler.command = ENV['CC'] || default_command diff --git a/test/t/float.rb b/test/t/float.rb index e2a8a5088..b69cae2fb 100644 --- a/test/t/float.rb +++ b/test/t/float.rb @@ -212,10 +212,10 @@ assert('Float#to_s') do assert_equal("Infinity", Float::INFINITY.to_s) assert_equal("-Infinity", (-Float::INFINITY).to_s) assert_equal("NaN", Float::NAN.to_s) - assert_equal("0", 0.0.to_s) - assert_equal("-0", -0.0.to_s) + assert_equal("0.0", 0.0.to_s) + assert_equal("-0.0", -0.0.to_s) assert_equal("-3.25", -3.25.to_s) - assert_equal("50", 50.0.to_s) + assert_equal("50.0", 50.0.to_s) assert_equal("0.0125", 0.0125.to_s) assert_equal("-0.0125", -0.0125.to_s) assert_equal("1.0e-10", 0.0000000001.to_s) @@ -224,8 +224,8 @@ assert('Float#to_s') do assert_equal("-1.0e+20", -1e20.to_s) assert_equal("1.0e+16", 10000000000000000.0.to_s) assert_equal("-1.0e+16", -10000000000000000.0.to_s) - assert_equal("100000", 100000.0.to_s) - assert_equal("-100000", -100000.0.to_s) + assert_equal("100000.0", 100000.0.to_s) + assert_equal("-100000.0", -100000.0.to_s) if uses_float assert_equal("1.0e+08", 100000000.0.to_s) assert_equal("-1.0e+08", -100000000.0.to_s) @@ -234,8 +234,8 @@ assert('Float#to_s') do else assert_equal("1.0e+15", 1000000000000000.0.to_s) assert_equal("-1.0e+15", -1000000000000000.0.to_s) - assert_equal("100000000000000", 100000000000000.0.to_s) - assert_equal("-100000000000000", -100000000000000.0.to_s) + assert_equal("100000000000000.0", 100000000000000.0.to_s) + assert_equal("-100000000000000.0", -100000000000000.0.to_s) end end |
