diff options
| -rw-r--r-- | include/mruby/dump.h | 5 | ||||
| -rw-r--r-- | include/mruby/proc.h | 2 | ||||
| -rw-r--r-- | src/array.c | 13 | ||||
| -rw-r--r-- | src/class.c | 133 | ||||
| -rw-r--r-- | src/codegen.c | 17 | ||||
| -rw-r--r-- | src/hash.c | 4 | ||||
| -rw-r--r-- | src/kernel.c | 2 | ||||
| -rw-r--r-- | src/load.c | 36 | ||||
| -rw-r--r-- | src/parse.y | 5 | ||||
| -rw-r--r-- | src/string.c | 4 | ||||
| -rw-r--r-- | src/time.c | 2 | ||||
| -rw-r--r-- | src/variable.c | 2 | ||||
| -rw-r--r-- | test/init_mrbtest.c | 4 | ||||
| -rw-r--r-- | test/t/array.rb | 4 | ||||
| -rw-r--r-- | test/t/bs_block.rb | 30 | ||||
| -rw-r--r-- | test/t/module.rb | 58 | ||||
| -rw-r--r-- | test/t/syntax.rb | 11 | ||||
| -rw-r--r-- | test/t/time.rb | 2 | ||||
| -rw-r--r-- | tools/mirb/mirb.c | 8 | ||||
| -rw-r--r-- | tools/mruby/mruby.c | 2 |
20 files changed, 301 insertions, 43 deletions
diff --git a/include/mruby/dump.h b/include/mruby/dump.h index cad797275..87c9841e6 100644 --- a/include/mruby/dump.h +++ b/include/mruby/dump.h @@ -16,9 +16,10 @@ extern "C" { #include <stdint.h> int mrb_dump_irep(mrb_state*,int,FILE*); -int mrb_load_irep(mrb_state*,FILE*); -int mrb_load_irep_offset(mrb_state*,FILE*,long); int mrb_read_irep(mrb_state*,const char*); +int mrb_read_irep_file(mrb_state*,FILE*); +mrb_value mrb_load_irep(mrb_state*,const char*); +mrb_value mrb_load_irep_file(mrb_state*,FILE*); int mrb_bdump_irep(mrb_state *mrb, int n, FILE *f,const char *initname); diff --git a/include/mruby/proc.h b/include/mruby/proc.h index 50e55f231..96f7ddbd7 100644 --- a/include/mruby/proc.h +++ b/include/mruby/proc.h @@ -52,7 +52,7 @@ struct RProc *mrb_closure_new(mrb_state*, mrb_irep*); void mrb_proc_copy(struct RProc *a, struct RProc *b); #include "mruby/khash.h" -KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1); +KHASH_DECLARE(mt, mrb_sym, struct RProc*, 1) #if defined(__cplusplus) } /* extern "C" { */ diff --git a/src/array.c b/src/array.c index ea461e029..d4f5d1c5e 100644 --- a/src/array.c +++ b/src/array.c @@ -719,24 +719,21 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self) mrb_get_args(mrb, "*", &argv, &argc); switch(argc) { case 2: - if (mrb_fixnum_p(argv[0])) { - mrb_ary_set(mrb, self, mrb_fixnum(argv[0]), argv[1]); - } - else { + if (!mrb_fixnum_p(argv[0])) { /* Should we support Range object for 1st arg ? */ mrb_raise(mrb, E_TYPE_ERROR, "expected Fixnum for 1st argument"); } - break; + mrb_ary_set(mrb, self, mrb_fixnum(argv[0]), argv[1]); + return argv[1]; case 3: mrb_ary_splice(mrb, self, mrb_fixnum(argv[0]), mrb_fixnum(argv[1]), argv[2]); - break; + return argv[2]; default: mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments"); + return mrb_nil_value(); } - - return self; } mrb_value diff --git a/src/class.c b/src/class.c index fe2baa4f2..dcd0ae492 100644 --- a/src/class.c +++ b/src/class.c @@ -7,6 +7,7 @@ #include "mruby.h" #include <stdarg.h> #include <stdio.h> +#include <ctype.h> #include "mruby/class.h" #include "mruby/proc.h" #include "mruby/string.h" @@ -15,7 +16,7 @@ #include "mruby/array.h" #include "error.h" -KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal); +KHASH_DEFINE(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) typedef struct fc_result { mrb_sym name; @@ -630,7 +631,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...) } break; default: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide argument specifier %c", c); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid argument specifier %c", c); break; } } @@ -722,6 +723,43 @@ mrb_mod_include(mrb_state *mrb, mrb_value klass) return klass; } +/* 15.2.2.4.28 */ +/* + * call-seq: + * mod.include?(module) -> true or false + * + * Returns <code>true</code> if <i>module</i> is included in + * <i>mod</i> or one of <i>mod</i>'s ancestors. + * + * module A + * end + * class B + * include A + * end + * class C < B + * end + * B.include?(A) #=> true + * C.include?(A) #=> true + * A.include?(A) #=> false + */ +static mrb_value +mrb_mod_include_p(mrb_state *mrb, mrb_value mod) +{ + mrb_value mod2; + struct RClass *c = mrb_class_ptr(mod); + + mrb_get_args(mrb, "o", &mod2); + mrb_check_type(mrb, mod2, MRB_TT_MODULE); + + while (c) { + if (c->tt == MRB_TT_ICLASS) { + if (c->c == mrb_class_ptr(mod2)) return mrb_true_value(); + } + c = c->super; + } + return mrb_false_value(); +} + static mrb_value mrb_mod_ancestors(mrb_state *mrb, mrb_value self) { @@ -770,6 +808,73 @@ mrb_mod_included_modules(mrb_state *mrb, mrb_value self) return result; } +mrb_value class_instance_method_list(mrb_state*, int, mrb_value*, struct RClass*, int); + +/* 15.2.2.4.33 */ +/* + * call-seq: + * mod.instance_methods(include_super=true) -> array + * + * Returns an array containing the names of the public and protected instance + * methods in the receiver. For a module, these are the public and protected methods; + * for a class, they are the instance (not singleton) methods. With no + * argument, or with an argument that is <code>false</code>, the + * instance methods in <i>mod</i> are returned, otherwise the methods + * in <i>mod</i> and <i>mod</i>'s superclasses are returned. + * + * module A + * def method1() end + * end + * class B + * def method2() end + * end + * class C < B + * def method3() end + * end + * + * A.instance_methods #=> [:method1] + * B.instance_methods(false) #=> [:method2] + * C.instance_methods(false) #=> [:method3] + * C.instance_methods(true).length #=> 43 + */ + +static mrb_value +mrb_mod_instance_methods(mrb_state *mrb, mrb_value mod) +{ + mrb_value *argv; + int argc; + struct RClass *c = mrb_class_ptr(mod); + + mrb_get_args(mrb, "*", &argv, &argc); + return class_instance_method_list(mrb, argc, argv, c, 0); +} + +mrb_value mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv, mrb_value self, struct RClass *c); + +/* 15.2.2.4.35 */ +/* + * call-seq: + * mod.class_eval {| | block } -> obj + * mod.module_eval {| | block } -> obj + * + * Evaluates block in the context of _mod_. This can + * be used to add methods to a class. <code>module_eval</code> returns + * the result of evaluating its argument. + */ + +mrb_value +mrb_mod_module_eval(mrb_state *mrb, mrb_value mod) +{ + mrb_value a, b; + struct RClass *c; + + if (mrb_get_args(mrb, "|S&", &a, &b) == 1) { + mrb_raise(mrb, E_NOTIMP_ERROR, "module_eval/class_eval with string not implemented"); + } + c = mrb_class_ptr(mod); + return mrb_yield_internal(mrb, b, 0, 0, mod, c); +} + mrb_value mrb_singleton_class(mrb_state *mrb, mrb_value v) { @@ -1338,11 +1443,25 @@ mrb_sym_value(mrb_state *mrb, mrb_value val) return mrb_symbol(val); } +static void +check_const_name(mrb_state *mrb, mrb_sym id) +{ + const char *s; + int len; + + s = mrb_sym2name_len(mrb, id, &len); + if (len < 1 || !ISUPPER(*s)) { + mrb_name_error(mrb, id, "wrong constant name %s", s); + } +} + mrb_value mrb_mod_const_defined(mrb_state *mrb, mrb_value mod) { mrb_value sym; mrb_get_args(mrb, "o", &sym); + + check_const_name(mrb, mrb_sym_value(mrb,sym)); if(mrb_const_defined(mrb, mod, mrb_sym_value(mrb, sym))) { return mrb_true_value(); } @@ -1354,6 +1473,8 @@ mrb_mod_const_get(mrb_state *mrb, mrb_value mod) { mrb_value sym; mrb_get_args(mrb, "o", &sym); + + check_const_name(mrb, mrb_sym_value(mrb,sym)); return mrb_const_get(mrb, mod, mrb_sym_value(mrb, sym)); } @@ -1362,6 +1483,8 @@ mrb_mod_const_set(mrb_state *mrb, mrb_value mod) { mrb_value sym, value; mrb_get_args(mrb, "oo", &sym, &value); + + check_const_name(mrb, mrb_sym_value(mrb,sym)); mrb_const_set(mrb, mod, mrb_sym_value(mrb, sym), value); return value; } @@ -1424,9 +1547,13 @@ mrb_init_class(mrb_state *mrb) mrb_define_method(mrb, mod, "extend_object", mrb_mod_extend_object, ARGS_REQ(1)); /* 15.2.2.4.25 */ mrb_define_method(mrb, mod, "extended", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.26 */ mrb_define_method(mrb, mod, "include", mrb_mod_include, ARGS_ANY()); /* 15.2.2.4.27 */ + mrb_define_method(mrb, mod, "include?", mrb_mod_include_p, ARGS_REQ(1)); /* 15.2.2.4.28 */ mrb_define_method(mrb, mod, "append_features", mrb_mod_append_features, ARGS_REQ(1)); /* 15.2.2.4.10 */ - mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */ + mrb_define_method(mrb, mod, "class_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.15 */ + mrb_define_method(mrb, mod, "included", mrb_bob_init, ARGS_REQ(1)); /* 15.2.2.4.29 */ mrb_define_method(mrb, mod, "included_modules", mrb_mod_included_modules, ARGS_NONE()); /* 15.2.2.4.30 */ + mrb_define_method(mrb, mod, "instance_methods", mrb_mod_instance_methods, ARGS_ANY()); /* 15.2.2.4.33 */ + mrb_define_method(mrb, mod, "module_eval", mrb_mod_module_eval, ARGS_ANY()); /* 15.2.2.4.35 */ mrb_define_method(mrb, mod, "to_s", mrb_mod_to_s, ARGS_NONE()); mrb_define_method(mrb, mod, "inspect", mrb_mod_to_s, ARGS_NONE()); diff --git a/src/codegen.c b/src/codegen.c index f37a9e331..a6c94d871 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1412,7 +1412,6 @@ codegen(codegen_scope *s, node *tree, int val) codegen(s, tree->cdr->cdr->car, VAL); pop(); gen_assignment(s, tree->car, cursp(), val); - if (val) pop(); dispatch(s, pos); break; } @@ -1501,7 +1500,7 @@ codegen(codegen_scope *s, node *tree, int val) case NODE_RETURN: codegen(s, tree, VAL); pop(); - if (s->loop && s->loop->type != LOOP_NORMAL) { + if (s->loop) { genop(s, MKOP_AB(OP_RETURN, cursp(), OP_R_RETURN)); } else { @@ -2080,6 +2079,10 @@ scope_new(mrb_state *mrb, codegen_scope *prev, node *lv) p->nlocals = p->sp; p->ai = mrb->arena_idx; + //because of a potential bad memory access in case of gc let's allocate the irep right now + mrb_add_irep(mrb, mrb->irep_len); + mrb->irep[mrb->irep_len] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); + mrb->irep[mrb->irep_len]->plen = 0; p->idx = mrb->irep_len++; p->filename = prev->filename; if (p->filename) { @@ -2093,10 +2096,12 @@ scope_finish(codegen_scope *s, int idx) { mrb_state *mrb = s->mrb; mrb_irep *irep; - - mrb_add_irep(mrb, idx); - irep = mrb->irep[idx] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); - + + //Comment out these instructions already done in scope_new + //mrb_add_irep(mrb, idx); + //irep = mrb->irep[idx] = (mrb_irep *)mrb_malloc(mrb, sizeof(mrb_irep)); + irep = mrb->irep[idx]; + irep->flags = 0; irep->idx = idx; if (s->iseq) { diff --git a/src/hash.c b/src/hash.c index c74ac837b..c7a419250 100644 --- a/src/hash.c +++ b/src/hash.c @@ -29,8 +29,8 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b) return mrb_eql(mrb, a, b); } -KHASH_DECLARE(ht, mrb_value, mrb_value, 1); -KHASH_DEFINE (ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal); +KHASH_DECLARE(ht, mrb_value, mrb_value, 1) +KHASH_DEFINE (ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal) static void mrb_hash_modify(mrb_state *mrb, mrb_value hash); diff --git a/src/kernel.c b/src/kernel.c index 5fcebc4a9..531c6d9d8 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -717,7 +717,7 @@ method_entry_loop(mrb_state *mrb, struct RClass* klass, mrb_value ary) } } -static mrb_value +mrb_value class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RClass* klass, int obj) { mrb_value ary; diff --git a/src/load.c b/src/load.c index 142c6fdf7..3cd8d91b0 100644 --- a/src/load.c +++ b/src/load.c @@ -11,6 +11,7 @@ #ifdef ENABLE_REGEXP #include "re.h" #endif +#include "mruby/proc.h" #include "mruby/irep.h" typedef struct _RiteFILE @@ -28,7 +29,7 @@ const char hex2bin[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, //30-3f 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, //40-4f 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //50-5f - 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 //60-6f + 0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0 //60-6f //70-ff }; @@ -241,7 +242,7 @@ error_exit: } int -mrb_load_irep(mrb_state *mrb, FILE* fp) +mrb_read_irep_file(mrb_state *mrb, FILE* fp) { int ret, i; uint32_t len, rlen = 0; @@ -659,3 +660,34 @@ hex_to_str(char *hex, char *str, uint16_t *str_len) } return str; } + +static void +irep_error(mrb_state *mrb, int n) +{ + static const char msg[] = "irep load error"; + mrb->exc = (struct RObject*)mrb_object(mrb_exc_new(mrb, E_SCRIPT_ERROR, msg, sizeof(msg) - 1)); +} + +mrb_value +mrb_load_irep_file(mrb_state *mrb, FILE* fp) +{ + int n = mrb_read_irep_file(mrb, fp); + + if (n < 0) { + irep_error(mrb, n); + return mrb_nil_value(); + } + return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); +} + +mrb_value +mrb_load_irep(mrb_state *mrb, const char *bin) +{ + int n = mrb_read_irep(mrb, bin); + + if (n < 0) { + irep_error(mrb, n); + return mrb_nil_value(); + } + return mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); +} diff --git a/src/parse.y b/src/parse.y index bfea1f69c..7ecdbab85 100644 --- a/src/parse.y +++ b/src/parse.y @@ -3307,7 +3307,8 @@ read_escape(parser_state *p) int buf[3]; int i; - for (i=0; i<3; i++) { + buf[0] = c; + for (i=1; i<3; i++) { buf[i] = nextc(p); if (buf[i] == -1) goto eof; if (buf[i] < '0' || '7' < buf[i]) { @@ -3315,7 +3316,7 @@ read_escape(parser_state *p) break; } } - c = scan_oct(buf, i+1, &i); + c = scan_oct(buf, i, &i); } return c; diff --git a/src/string.c b/src/string.c index 425b79ca7..7ab6e5806 100644 --- a/src/string.c +++ b/src/string.c @@ -2511,7 +2511,7 @@ mrb_cstr_to_inum(mrb_state *mrb, const char *str, int base, int badcheck) return mrb_fixnum_value(result); } bad: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide string for number(%s)", str); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for number(%s)", str); /* not reached */ return mrb_fixnum_value(0); } @@ -2621,7 +2621,7 @@ mrb_cstr_to_dbl(mrb_state *mrb, const char * p, int badcheck) if (p == end) { if (badcheck) { bad: - mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalide string for float(%s)", p); + mrb_raisef(mrb, E_ARGUMENT_ERROR, "invalid string for float(%s)", p); /* not reached */ } return d; diff --git a/src/time.c b/src/time.c index 09ebea78a..c647ef6ce 100644 --- a/src/time.c +++ b/src/time.c @@ -395,7 +395,7 @@ mrb_time_yday(mrb_state *mrb, mrb_value self) tm = (struct mrb_time *)mrb_check_datatype(mrb, self, &mrb_time_type); if (!tm) return mrb_nil_value(); - return mrb_fixnum_value(tm->datetime.tm_yday); + return mrb_fixnum_value(tm->datetime.tm_yday + 1); } /* 15.2.19.7.32 */ diff --git a/src/variable.c b/src/variable.c index 7d583da40..6907a8e2a 100644 --- a/src/variable.c +++ b/src/variable.c @@ -256,7 +256,7 @@ iv_free(mrb_state *mrb, iv_tbl *t) #endif KHASH_DECLARE(iv, mrb_sym, mrb_value, 1) -KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal); +KHASH_DEFINE(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) typedef struct iv_tbl { khash_t(iv) h; diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index b9f09dd2f..e68c9d71a 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -9,9 +9,7 @@ extern const char mrbtest_irep[]; void mrb_init_mrbtest(mrb_state *mrb) { - int n = mrb_read_irep(mrb, mrbtest_irep); - - mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); + mrb_load_irep(mrb, mrbtest_irep); if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(0); diff --git a/test/t/array.rb b/test/t/array.rb index 560faf8e7..90fa85c7f 100644 --- a/test/t/array.rb +++ b/test/t/array.rb @@ -74,8 +74,8 @@ assert('Array#[]=', '15.2.12.5.5') do e3 = e1 end - [1,2,3].[]=(1,4) == [1, 4, 3] and - [1,2,3].[]=(1,2,3) == [1, 3] and + [1,2,3].[]=(1,4) == 4 and + [1,2,3].[]=(1,2,3) == 3 and e2.class == ArgumentError and e3.class == ArgumentError end diff --git a/test/t/bs_block.rb b/test/t/bs_block.rb index cbfb925fe..4bfdc304a 100644 --- a/test/t/bs_block.rb +++ b/test/t/bs_block.rb @@ -389,7 +389,7 @@ assert('BS Block [ruby-core:14395]') do t.test_for_bug end -assert("BS Block 32") do +assert("BS Block 33") do module TestReturnFromNestedBlock def self.test 1.times do @@ -402,3 +402,31 @@ assert("BS Block 32") do end TestReturnFromNestedBlock.test == :ok end + +assert("BS Block 34") do + module TestReturnFromNestedBlock_BSBlock34 + def self.test + 1.times do + while true + return :ok + end + end + :bad + end + end + TestReturnFromNestedBlock_BSBlock34.test == :ok +end + +assert("BS Block 35") do + module TestReturnFromNestedBlock_BSBlock35 + def self.test + 1.times do + until false + return :ok + end + end + :bad + end + end + TestReturnFromNestedBlock_BSBlock35.test == :ok +end diff --git a/test/t/module.rb b/test/t/module.rb index 511658150..5e825c6b5 100644 --- a/test/t/module.rb +++ b/test/t/module.rb @@ -31,6 +31,22 @@ assert('Module#append_features', '15.2.2.4.10') do Test4AppendFeatures2.const_get(:Const4AppendFeatures2) == Test4AppendFeatures2 end +assert('Module#class_eval', '15.2.2.4.15') do + class Test4ClassEval + @a = 11 + @b = 12 + end + Test4ClassEval.class_eval do + def method1 + end + end + r = Test4ClassEval.instance_methods + Test4ClassEval.class_eval{ @a } == 11 and + Test4ClassEval.class_eval{ @b } == 12 and + r.class == Array and r.include?(:method1) +end + + assert('Module#class_variables', '15.2.2.4.19') do class Test4ClassVariables1 @@var1 = 1 @@ -92,6 +108,20 @@ assert('Module#include', '15.2.2.4.27') do Test4Include2.const_get(:Const4Include) == 42 end +assert('Module#include?', '15.2.2.4.28') do + module Test4IncludeP + end + class Test4IncludeP2 + include Test4IncludeP + end + class Test4IncludeP3 < Test4IncludeP2 + end + + Test4IncludeP2.include?(Test4IncludeP) && + Test4IncludeP3.include?(Test4IncludeP) && + ! Test4IncludeP.include?(Test4IncludeP) +end + assert('Module#included', '15.2.2.4.29') do module Test4Included Const4Included = 42 @@ -118,6 +148,34 @@ assert('Module#included_modules', '15.2.2.4.30') do r.class == Array and r.include?(Test4includedModules) end +assert('Module#instance_methods', '15.2.2.4.33') do + module Test4InstanceMethodsA + def method1() end + end + class Test4InstanceMethodsB + def method2() end + end + class Test4InstanceMethodsC < Test4InstanceMethodsB + def method3() end + end + + r = Test4InstanceMethodsC.instance_methods(true) + + Test4InstanceMethodsA.instance_methods == [:method1] and + Test4InstanceMethodsB.instance_methods(false) == [:method2] and + Test4InstanceMethodsC.instance_methods(false) == [:method3] and + r.class == Array and r.include?(:method3) and r.include?(:method2) +end + +assert('Module#module_eval', '15.2.2.4.35') do + module Test4ModuleEval + @a = 11 + @b = 12 + end + Test4ModuleEval.module_eval{ @a } == 11 and + Test4ModuleEval.module_eval{ @b } == 12 +end + # Not ISO specified assert('Module#to_s') do diff --git a/test/t/syntax.rb b/test/t/syntax.rb index 47221d425..0501608e5 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -58,3 +58,14 @@ assert('Nested const reference') do Syntax4Const::CONST1 == "hello world" and Syntax4Const::Const2.new.const1 == "hello world" end + +assert('Abbreviated variable assignment as returns') do + module Syntax4AbbrVarAsgnAsReturns + class A + def b + @c ||= 1 + end + end + end + Syntax4AbbrVarAsgnAsReturns::A.new.b == 1 +end diff --git a/test/t/time.rb b/test/t/time.rb index ba4ceedc4..f92459d5e 100644 --- a/test/t/time.rb +++ b/test/t/time.rb @@ -177,7 +177,7 @@ if Object.const_defined?(:Time) end assert('Time#yday', '15.2.19.7.31') do - Time.gm(2012, 12, 23).yday == 357 + Time.gm(2012, 12, 23).yday == 358 end assert('Time#year', '15.2.19.7.32') do diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c index 502400c72..d3903ef57 100644 --- a/tools/mirb/mirb.c +++ b/tools/mirb/mirb.c @@ -5,7 +5,7 @@ ** an interactive way and executes it ** immediately. It's a REPL... */ - + #include <string.h> #include <mruby.h> @@ -143,7 +143,7 @@ print_cmdline(int code_block_open) int main(void) { - char last_char; + int last_char; char ruby_code[1024] = { 0 }; char last_code_line[1024] = { 0 }; int char_index; @@ -156,7 +156,7 @@ main(void) print_hint(); - /* new interpreter instance */ + /* new interpreter instance */ mrb = mrb_open(); if (mrb == NULL) { fprintf(stderr, "Invalid mrb interpreter, exiting mirb"); @@ -207,7 +207,7 @@ main(void) parser->send = ruby_code + strlen(ruby_code); parser->lineno = 1; mrb_parser_parse(parser, cxt); - code_block_open = is_code_block_open(parser); + code_block_open = is_code_block_open(parser); if (code_block_open) { /* no evaluation of code */ diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c index d9386f6e2..d3ea924c7 100644 --- a/tools/mruby/mruby.c +++ b/tools/mruby/mruby.c @@ -238,7 +238,7 @@ main(int argc, char **argv) mrb_define_global_const(mrb, "ARGV", ARGV); if (args.mrbfile) { - n = mrb_load_irep(mrb, args.rfp); + n = mrb_read_irep_file(mrb, args.rfp); if (n < 0) { fprintf(stderr, "failed to load mrb file: %s\n", args.cmdline); } |
