diff options
| -rw-r--r-- | CONTRIBUTING.md | 11 | ||||
| -rw-r--r-- | Rakefile | 4 | ||||
| -rw-r--r-- | build_config/boxing.rb | 129 | ||||
| -rw-r--r-- | build_config/host-m32.rb | 2 | ||||
| -rw-r--r-- | build_config/travis.rb | 2 | ||||
| -rw-r--r-- | include/mruby.h | 2 | ||||
| -rw-r--r-- | include/mruby/array.h | 4 | ||||
| -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/core.rake (renamed from src/mruby_core.rake) | 0 | ||||
| -rw-r--r-- | tasks/mrblib.rake (renamed from mrblib/mrblib.rake) | 0 | ||||
| -rw-r--r-- | tasks/toolchains/gcc.rake | 4 | ||||
| -rw-r--r-- | test/t/float.rb | 14 |
15 files changed, 175 insertions, 87 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ec25f89b1..fec2e8907 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,11 +33,6 @@ mruby should be highly portable to other systems and compilers. For this it is recommended to keep your code as close as possible to the C99 standard (http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf). -Although we target C99, we've heard some compilers in the embedded environment -still requires declarations of local variables to be at the beginning of a -scope. Until we confirm the situation has changed, we use the old-style -variable declaration. - Visual C++ is also an important target for mruby (supported version is 2013 or later). For this reason features that are not supported by Visual C++ may not be used (e.g. `%z` of `strftime()`). @@ -50,12 +45,6 @@ The dependencies to libraries should be kept to an absolute minimum. This increases the portability but makes it also easier to cut away parts of mruby on-demand. -#### Don't use C++ style comments - - /* This is the preferred comment style */ - -Use C++ style comments only for temporary comment e.g. commenting out some code lines. - #### Insert a break after the function return value: int @@ -22,8 +22,8 @@ MRuby.each_target do |build| end # load custom rules -load "#{MRUBY_ROOT}/src/mruby_core.rake" -load "#{MRUBY_ROOT}/mrblib/mrblib.rake" +load "#{MRUBY_ROOT}/tasks/core.rake" +load "#{MRUBY_ROOT}/tasks/mrblib.rake" load "#{MRUBY_ROOT}/tasks/mrbgems.rake" load "#{MRUBY_ROOT}/tasks/libmruby.rake" 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/build_config/travis.rb b/build_config/travis.rb index 58a739ce6..3b28b4c4e 100644 --- a/build_config/travis.rb +++ b/build_config/travis.rb @@ -4,7 +4,6 @@ MRuby::Build.new('full-debug') do |conf| # include all core GEMs conf.gembox 'full-core' - conf.cc.flags += %w(-Werror=declaration-after-statement) conf.cc.defines += %w(MRB_GC_STRESS MRB_ENABLE_DEBUG_HOOK) conf.enable_test @@ -15,7 +14,6 @@ MRuby::Build.new do |conf| # include all core GEMs conf.gembox 'full-core' - conf.cc.flags += %w(-Werror=declaration-after-statement) conf.compilers.each do |c| c.defines += %w(MRB_GC_FIXED_ARENA) 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/array.h b/include/mruby/array.h index 5164efa69..34011d537 100644 --- a/include/mruby/array.h +++ b/include/mruby/array.h @@ -249,10 +249,10 @@ MRB_API mrb_value mrb_ary_entry(mrb_value ary, mrb_int offset); * * Equivalent to: * - * ary.shift + * ary[head, len] = rpl * * @param mrb The mruby state reference. - * @param self The array from which the value will be shifted. + * @param self The array from which the value will be partiality replaced. * @param head Beginning position of a replacement subsequence. * @param len Length of a replacement subsequence. * @param rpl The array of replacement elements. 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/src/mruby_core.rake b/tasks/core.rake index c4816d4ce..c4816d4ce 100644 --- a/src/mruby_core.rake +++ b/tasks/core.rake diff --git a/mrblib/mrblib.rake b/tasks/mrblib.rake index 7231b63bc..7231b63bc 100644 --- a/mrblib/mrblib.rake +++ b/tasks/mrblib.rake diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index b5d6e1f25..316d2d9a1 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -2,11 +2,11 @@ MRuby::Toolchain.new(:gcc) do |conf, params| default_command = params[:default_command] || 'gcc' compiler_flags = %w(-g -O3 -Wall -Wundef) c_mandatory_flags = %w(-std=gnu99) - cxx_invalid_flags = %w(-Wdeclaration-after-statement -Werror-implicit-function-declaration) + cxx_invalid_flags = %w(-Werror-implicit-function-declaration) [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 |
