From 6bdd257c42958b72aa257bfd686fe351708ea72e Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 14 Jun 2012 01:17:44 +0900 Subject: inspect format for exception has changed --- src/error.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index ae89541c1..e83c71931 100644 --- a/src/error.c +++ b/src/error.c @@ -136,18 +136,13 @@ exc_inspect(mrb_state *mrb, mrb_value exc) { mrb_value str, klass; - klass = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); + str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); exc = mrb_obj_as_string(mrb, exc); - if (RSTRING_LEN(exc) == 0) { - return klass; - } - - str = mrb_str_new2(mrb, "#<"); - mrb_str_append(mrb, str, klass); - mrb_str_cat2(mrb, str, ": "); - mrb_str_append(mrb, str, exc); - mrb_str_cat2(mrb, str, ">"); + if (RSTRING_LEN(exc) > 0) { + mrb_str_cat2(mrb, str, ": "); + mrb_str_append(mrb, str, exc); + } return str; } -- cgit v1.2.3 From df7be84dba8d972b47d1441056f077b7f1ec4c33 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 14 Jun 2012 01:18:07 +0900 Subject: add newline between functions --- src/error.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index e83c71931..d0cbc91c3 100644 --- a/src/error.c +++ b/src/error.c @@ -218,6 +218,7 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...) exc = mrb_class_new_instance(mrb, 2, argv, E_NAME_ERROR); mrb_exc_raise(mrb, exc); } + mrb_value mrb_sprintf(mrb_state *mrb, const char *fmt, ...) { -- cgit v1.2.3 From b775bc771e8c6effbf583cadf5da270d3c016a15 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Thu, 14 Jun 2012 01:19:45 +0900 Subject: remove unused variable --- src/error.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index d0cbc91c3..bb334322f 100644 --- a/src/error.c +++ b/src/error.c @@ -134,7 +134,7 @@ exc_message(mrb_state *mrb, mrb_value exc) static mrb_value exc_inspect(mrb_state *mrb, mrb_value exc) { - mrb_value str, klass; + mrb_value str; str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); exc = mrb_obj_as_string(mrb, exc); -- cgit v1.2.3 From f564ec7e822c55e8ef6973170818263675b2499f Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 00:56:00 +0900 Subject: Remove some redundant code. --- src/codegen.c | 12 ------------ src/error.c | 30 ------------------------------ src/error.h | 1 - src/etc.c | 8 -------- src/hash.c | 8 -------- src/kernel.c | 13 ------------- src/load.c | 8 -------- src/object.c | 8 -------- src/parse.y | 8 -------- src/range.c | 8 -------- src/string.c | 2 +- src/variable.c | 8 -------- 12 files changed, 1 insertion(+), 113 deletions(-) (limited to 'src/error.c') diff --git a/src/codegen.c b/src/codegen.c index 1bdc2d21c..b64a18b96 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -298,20 +298,8 @@ push_(codegen_scope *s) s->sp++; nregs_update; } -#if 0 -static void -push_n_(codegen_scope *s, int n) -{ - if (s->sp + n > 511) { - codegen_error(s, "too complex expression"); - } - s->sp += n; - nregs_update; -} -#endif #define push() push_(s) -#define push_n(n) push_n_(s, n) #define pop() (s->sp--) #define pop_n(n) (s->sp-=(n)) #define cursp() (s->sp) diff --git a/src/error.c b/src/error.c index bb334322f..e6ccdf096 100644 --- a/src/error.c +++ b/src/error.c @@ -20,14 +20,6 @@ #define warn_printf printf -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - mrb_value mrb_exc_new(mrb_state *mrb, struct RClass *c, const char *ptr, long len) { @@ -300,28 +292,6 @@ sysexit_status(mrb_state *mrb, mrb_value err) return mrb_fixnum(st); } -void -error_pos(void) -{ -#if 0 - const char *sourcefile = mrb_sourcefile(); - int sourceline = mrb_sourceline(); - - if (sourcefile) { - if (sourceline == 0) { - warn_printf("%s", sourcefile); - } - else if (mrb_frame_callee()) { - warn_printf("%s:%d:in `%s'", sourcefile, sourceline, - mrb_sym2name(mrb, mrb_frame_callee())); - } - else { - warn_printf("%s:%d", sourcefile, sourceline); - } - } -#endif -} - static void set_backtrace(mrb_state *mrb, mrb_value info, mrb_value bt) { diff --git a/src/error.h b/src/error.h index 8a86e7d3d..e4d6acb6c 100644 --- a/src/error.h +++ b/src/error.h @@ -14,7 +14,6 @@ struct RException { void mrb_sys_fail(mrb_state *mrb, const char *mesg); void mrb_bug_errno(const char*, int); int sysexit_status(mrb_state *mrb, mrb_value err); -void error_pos(void); mrb_value mrb_exc_new3(mrb_state *mrb, struct RClass* c, mrb_value str); mrb_value make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr); mrb_value mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv); diff --git a/src/etc.c b/src/etc.c index 5d70c8bc7..40a00c1f5 100644 --- a/src/etc.c +++ b/src/etc.c @@ -10,14 +10,6 @@ #include "mruby/numeric.h" #include "mruby/data.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - struct RData* mrb_data_object_alloc(mrb_state *mrb, struct RClass *klass, void *ptr, const struct mrb_data_type *type) { diff --git a/src/hash.c b/src/hash.c index 4a85fcec3..fe5336dc1 100644 --- a/src/hash.c +++ b/src/hash.c @@ -33,14 +33,6 @@ mrb_hash_ht_hash_equal(mrb_state *mrb, mrb_value a, mrb_value b) KHASH_INIT(ht, mrb_value, mrb_value, 1, mrb_hash_ht_hash_func, mrb_hash_ht_hash_equal); -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - static void mrb_hash_modify(mrb_state *mrb, mrb_value hash); static inline mrb_value diff --git a/src/kernel.c b/src/kernel.c index 4856af7ad..6dfe6be19 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -34,22 +34,9 @@ typedef enum { NOEX_RESPONDS = 0x80 } mrb_method_flag_t; -#ifdef INCLUDE_REGEXP -#include "re.h" -#include "regint.h" -#endif - KHASH_INIT(mt, mrb_sym, struct RProc*, 1, kh_int_hash_func, kh_int_hash_equal) KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - struct obj_ivar_tag { mrb_value obj; int (*func)(mrb_sym key, mrb_value val, void * arg); diff --git a/src/load.c b/src/load.c index 053ec2d7e..1f853df00 100644 --- a/src/load.c +++ b/src/load.c @@ -13,14 +13,6 @@ #endif #include "mruby/irep.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - typedef struct _RiteFILE { FILE* fp; diff --git a/src/object.c b/src/object.c index c9ea3f8eb..a30e7c58a 100644 --- a/src/object.c +++ b/src/object.c @@ -11,14 +11,6 @@ #include "mruby/class.h" #include "mruby/numeric.h" -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - int mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2) { diff --git a/src/parse.y b/src/parse.y index 7ca0cda80..5e44dd85a 100644 --- a/src/parse.y +++ b/src/parse.y @@ -41,14 +41,6 @@ static void backref_error(parser_state *p, node *n); #define identchar(c) (isalnum(c) || (c) == '_' || !isascii(c)) -#ifndef TRUE -#define TRUE 1 -#endif - -#ifndef FALSE -#define FALSE 0 -#endif - typedef unsigned int stack_type; #define BITSTACK_PUSH(stack, n) ((stack) = ((stack)<<1)|((n)&1)) diff --git a/src/range.c b/src/range.c index acec1514e..a158dd920 100644 --- a/src/range.c +++ b/src/range.c @@ -15,14 +15,6 @@ #include #include -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - #ifndef OTHER #define OTHER 2 #endif diff --git a/src/string.c b/src/string.c index 14041127a..a9e155c72 100644 --- a/src/string.c +++ b/src/string.c @@ -763,7 +763,7 @@ num_index: len = RSTRING_LEN(str); switch (mrb_range_beg_len(mrb, indx, &beg, &len, len, 0)) { - case 0/*FLASE*/: + case FALSE: break; case 2/*OTHER*/: return mrb_nil_value(); diff --git a/src/variable.c b/src/variable.c index b8957fb6a..47029da28 100644 --- a/src/variable.c +++ b/src/variable.c @@ -21,14 +21,6 @@ KHASH_INIT(iv, mrb_sym, mrb_value, 1, kh_int_hash_func, kh_int_hash_equal) -#ifndef FALSE -#define FALSE 0 -#endif - -#ifndef TRUE -#define TRUE 1 -#endif - static void mark_tbl(mrb_state *mrb, struct kh_iv *h) { -- cgit v1.2.3 From 56103509c89807c7498a4f91ed715a3e684b0b31 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 02:36:51 +0900 Subject: Remove as NotImplemenetedError is defined in mrblib/. --- src/error.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index e6ccdf096..3585f1634 100644 --- a/src/error.c +++ b/src/error.c @@ -398,7 +398,6 @@ mrb_init_exception(mrb_state *mrb) // eScriptError = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ // mrb_define_class(mrb, "SyntaxError", eScriptError); /* 15.2.38 */ // mrb_define_class(mrb, "LoadError", eScriptError); /* 15.2.39 */ - // mrb_define_class(mrb, "NotImplementedError", eScriptError_class); // mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */ mrb_define_class(mrb, "LocalJumpError", mrb->eStandardError_class); /* 15.2.25 */ -- cgit v1.2.3 From 9983e1d77378dd55d0b0380df848a307d4669bff Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 12:26:17 +0900 Subject: Remove unused funcions. --- src/error.c | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index 3585f1634..d50c596cc 100644 --- a/src/error.c +++ b/src/error.c @@ -172,15 +172,6 @@ mrb_exc_raise(mrb_state *mrb, mrb_value exc) longjmp(*(jmp_buf*)mrb->jmp, 1); } -void -mrb_raise_va(mrb_state *mrb, struct RClass *c, const char *fmt, va_list args) -{ - char buf[256]; - - vsnprintf(buf, 256, fmt, args); - mrb_exc_raise(mrb, mrb_exc_new(mrb, c, buf, strlen(buf))); -} - void mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...) { @@ -236,18 +227,6 @@ mrb_warn(const char *fmt, ...) } -void -mrb_warning(const char *fmt, ...) -{ - va_list args; - char buf[256]; - - va_start(args, fmt); - snprintf(buf, 256, "warning: %s", fmt); - printf(buf, args); - va_end(args); -} - void mrb_bug(const char *fmt, ...) { -- cgit v1.2.3 From ccec3da35bb2a6fff9fb58c30645b02692996f8b Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 12:27:44 +0900 Subject: Use return value of vsnprintf() for the string length. It is redundant using strlen(). --- src/error.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index d50c596cc..548527f07 100644 --- a/src/error.c +++ b/src/error.c @@ -177,11 +177,15 @@ mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...) { va_list args; char buf[256]; + int n; va_start(args, fmt); - vsnprintf(buf, 256, fmt, args); + n = vsnprintf(buf, 256, fmt, args); va_end(args); - mrb_exc_raise(mrb, mrb_exc_new(mrb, c, buf, strlen(buf))); + if (n < 0) { + n = 0; + } + mrb_exc_raise(mrb, mrb_exc_new(mrb, c, buf, n)); } void @@ -190,12 +194,15 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...) mrb_value exc, argv[2]; va_list args; char buf[256]; + int n; va_start(args, fmt); - //argv[0] = mrb_vsprintf(fmt, args); - vsnprintf(buf, 256, fmt, args); - argv[0] = mrb_str_new(mrb, buf, strlen(buf)); + n = vsnprintf(buf, 256, fmt, args); va_end(args); + if (n < 0) { + n = 0; + } + argv[0] = mrb_str_new(mrb, buf, n); argv[1] = mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id)); exc = mrb_class_new_instance(mrb, 2, argv, E_NAME_ERROR); @@ -207,11 +214,15 @@ mrb_sprintf(mrb_state *mrb, const char *fmt, ...) { va_list args; char buf[256]; + int n; va_start(args, fmt); - vsnprintf(buf, 256, fmt, args); + n = vsnprintf(buf, 256, fmt, args); va_end(args); - return mrb_str_new(mrb, buf, strlen(buf)); + if (n < 0) { + n = 0; + } + return mrb_str_new(mrb, buf, n); } void -- cgit v1.2.3 From cfd5f5157d06f9c62a04660843c3c02014d8a3a5 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Fri, 15 Jun 2012 13:06:43 +0900 Subject: Move Subclasses of ScriptError to mrblib. --- mrblib/error.rb | 8 ++++++++ src/error.c | 3 --- test/t/exception.rb | 30 ++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) (limited to 'src/error.c') diff --git a/mrblib/error.rb b/mrblib/error.rb index 3fa7f21e3..1cb2b1150 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -17,5 +17,13 @@ end class ScriptError < Exception end +# ISO 15.2.38 +class SyntaxError < ScriptError +end + +# ISO 15.2.39 +class LoadError < ScriptError +end + class NotImplementedError < ScriptError end diff --git a/src/error.c b/src/error.c index 548527f07..590fad5a5 100644 --- a/src/error.c +++ b/src/error.c @@ -385,9 +385,6 @@ mrb_init_exception(mrb_state *mrb) eNameError = mrb_define_class(mrb, "NameError", mrb->eStandardError_class); /* 15.2.31 */ mrb_define_class(mrb, "NoMethodError", eNameError); /* 15.2.32 */ - // eScriptError = mrb_define_class(mrb, "ScriptError", mrb->eException_class); /* 15.2.37 */ - // mrb_define_class(mrb, "SyntaxError", eScriptError); /* 15.2.38 */ - // mrb_define_class(mrb, "LoadError", eScriptError); /* 15.2.39 */ // mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */ mrb_define_class(mrb, "LocalJumpError", mrb->eStandardError_class); /* 15.2.25 */ diff --git a/test/t/exception.rb b/test/t/exception.rb index 22795161f..d7226a368 100644 --- a/test/t/exception.rb +++ b/test/t/exception.rb @@ -41,6 +41,36 @@ assert('Exception.exception', '15.2.22.4.1') do e.message == 'a' end +assert('ScriptError', '15.2.37') do + begin + raise ScriptError.new + rescue ScriptError + true + else + false + end +end + +assert('SyntaxError', '15.2.38') do + begin + raise SyntaxError.new + rescue SyntaxError + true + else + false + end +end + +assert('LoadError', '15.2.39') do + begin + raise LoadError.new + rescue LoadError + true + else + false + end +end + # Not ISO specified assert('Exception 1') do -- cgit v1.2.3 From 195d1dd685124edf93735a751f8ec34a7bfe76c0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Fri, 15 Jun 2012 14:03:02 +0900 Subject: do not use fixed sized buffer in mrb_bug/mrb_warn; close #287 --- include/mruby.h | 1 - src/error.c | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) (limited to 'src/error.c') diff --git a/include/mruby.h b/include/mruby.h index 25fc96b53..94fb44ad2 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -428,7 +428,6 @@ int mrb_block_given_p(void); void mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...); void rb_raise(struct RClass *c, const char *fmt, ...); void mrb_warn(const char *fmt, ...); -void mrb_warning(const char *fmt, ...); void mrb_bug(const char *fmt, ...); #define E_TYPE_ERROR (mrb_class_obj_get(mrb, "TypeError")) diff --git a/src/error.c b/src/error.c index 590fad5a5..3ef08a631 100644 --- a/src/error.c +++ b/src/error.c @@ -229,25 +229,23 @@ void mrb_warn(const char *fmt, ...) { va_list args; - char buf[256]; va_start(args, fmt); - snprintf(buf, 256, "warning: %s", fmt); - printf(buf, args); + printf("warning: "); + vprintf(fmt, args); va_end(args); } - void mrb_bug(const char *fmt, ...) { va_list args; - char buf[256]; va_start(args, fmt); - snprintf(buf, 256, "bug: %s", fmt); - printf(buf, args); + printf("bug: "); + vprintf(fmt, args); va_end(args); + exit(EXIT_FAILURE); } static const char * -- cgit v1.2.3 From 742c4fb86f321f24f3da722bfb49adf56067cc4e Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 18 Jun 2012 09:06:13 +0900 Subject: ignore id to create NameError --- src/error.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index 3ef08a631..1d8d2ddeb 100644 --- a/src/error.c +++ b/src/error.c @@ -203,9 +203,8 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...) n = 0; } argv[0] = mrb_str_new(mrb, buf, n); - - argv[1] = mrb_str_new_cstr(mrb, mrb_sym2name(mrb, id)); - exc = mrb_class_new_instance(mrb, 2, argv, E_NAME_ERROR); + argv[1] = mrb_symbol_value(id); /* ignore now */ + exc = mrb_class_new_instance(mrb, 1, argv, E_NAME_ERROR); mrb_exc_raise(mrb, exc); } -- cgit v1.2.3 From 955a48d964a2bbe175617880c868ca8b862da74e Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Mon, 18 Jun 2012 10:30:17 +0900 Subject: move exception definiton to mrblib --- mrblib/error.rb | 39 +++++++++++++++++++++++++++++++++++++++ src/error.c | 25 ------------------------- 2 files changed, 39 insertions(+), 25 deletions(-) (limited to 'src/error.c') diff --git a/mrblib/error.rb b/mrblib/error.rb index 5d49ec1e4..16e88eefb 100644 --- a/mrblib/error.rb +++ b/mrblib/error.rb @@ -13,6 +13,44 @@ class Exception end end +# ISO 15.2.24 +class ArgumentError < StandardError +end + +# ISO 15.2.25 +class LocalJumpError < StandardError +end + +# ISO 15.2.26 +class RangeError < StandardError +end + +class FloatDomainError < RangeError +end + +# ISO 15.2.26 +class RegexpError < StandardError +end + +# ISO 15.2.29 +class TypeError < StandardError +end + +# ISO 15.2.31 +class NameError < StandardError +end + +# ISO 15.2.32 +class NoMethodError < NameError +end + +# ISO 15.2.33 +class IndexError < StandardError +end + +class KeyError < IndexError +end + # ISO 15.2.37 class ScriptError < Exception end @@ -23,3 +61,4 @@ end class NotImplementedError < ScriptError end + diff --git a/src/error.c b/src/error.c index 1d8d2ddeb..981b2abab 100644 --- a/src/error.c +++ b/src/error.c @@ -359,9 +359,6 @@ void mrb_init_exception(mrb_state *mrb) { struct RClass *e; - struct RClass *eIndexError; - struct RClass *eRangeError; - struct RClass *eNameError; mrb->eException_class = e = mrb_define_class(mrb, "Exception", mrb->object_class); /* 15.2.22 */ mrb_define_class_method(mrb, e, "exception", mrb_instance_new, ARGS_ANY()); @@ -374,26 +371,4 @@ mrb_init_exception(mrb_state *mrb) mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ mrb->eRuntimeError_class = mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ - - mrb_define_class(mrb, "TypeError", mrb->eStandardError_class); /* 15.2.29 */ - mrb_define_class(mrb, "ArgumentError", mrb->eStandardError_class); /* 15.2.24 */ - eIndexError = mrb_define_class(mrb, "IndexError", mrb->eStandardError_class); /* 15.2.33 */ - eRangeError = mrb_define_class(mrb, "RangeError", mrb->eStandardError_class); /* 15.2.26 */ - eNameError = mrb_define_class(mrb, "NameError", mrb->eStandardError_class); /* 15.2.31 */ - - mrb_define_class(mrb, "NoMethodError", eNameError); /* 15.2.32 */ - // mrb_define_class(mrb, "SystemCallError", mrb->eStandardError_class); /* 15.2.36 */ - mrb_define_class(mrb, "LocalJumpError", mrb->eStandardError_class); /* 15.2.25 */ - -#ifdef INCLUDE_REGEX - mrb_define_class(mrb, "RegexpError", mrb->eStandardError_class); /* 15.2.27 */ -#endif - -#ifdef INCLUDE_ENCODING - mrb_define_class(mrb, "EncodingError", mrb->eStandardError_class); -#endif - // mrb_define_class(mrb, "ZeroDivisionError", mrb->eStandardError_class); /* 15.2.30 */ - - mrb_define_class(mrb, "FloatDomainError", eRangeError); - mrb_define_class(mrb, "KeyError", eIndexError); } -- cgit v1.2.3 From 8f9b958f1e269e6e2c58402ae0409a3a99e8bcf4 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Tue, 19 Jun 2012 12:54:49 +0900 Subject: raise should initialize Exception object --- src/error.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index 981b2abab..b2d9a8c8d 100644 --- a/src/error.c +++ b/src/error.c @@ -71,14 +71,14 @@ static mrb_value exc_exception(mrb_state *mrb, mrb_value self) { mrb_value exc; - mrb_value *argv; + mrb_value a; int argc; - mrb_get_args(mrb, "*", &argv, &argc); + argc = mrb_get_args(mrb, "|o", &a); if (argc == 0) return self; - if (argc == 1 && mrb_obj_equal(mrb, self, argv[0])) return self; + if (mrb_obj_equal(mrb, self, a)) return self; exc = mrb_obj_clone(mrb, self); - exc_initialize(mrb, exc); + mrb_iv_set(mrb, exc, mrb_intern(mrb, "mesg"), a); return exc; } @@ -321,7 +321,7 @@ exception_call: // mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); //} if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) { - mesg = mrb_funcall(mrb, argv[0], "exception", n, argv+1); + mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1); } else { /* undef */ -- cgit v1.2.3 From ef50e63a63c9b3759a2030816c9e2c5ec4e14cd0 Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 20 Jun 2012 20:43:27 +0900 Subject: remove RuntimeError from mrb_state --- include/mruby.h | 2 +- src/error.c | 8 ++++---- src/gc.c | 2 +- src/kernel.c | 6 +++--- src/re.c | 2 +- src/string.c | 2 +- src/vm.c | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) (limited to 'src/error.c') diff --git a/include/mruby.h b/include/mruby.h index ef742cef4..aadd56e94 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -279,7 +279,6 @@ typedef struct mrb_state { struct RClass *eException_class; struct RClass *eStandardError_class; - struct RClass *eRuntimeError_class; void *ud; /* auxiliary data */ } mrb_state; @@ -430,6 +429,7 @@ void rb_raise(struct RClass *c, const char *fmt, ...); void mrb_warn(const char *fmt, ...); void mrb_bug(const char *fmt, ...); +#define E_RUNTIME_ERROR (mrb_class_obj_get(mrb, "RuntimeError")) #define E_TYPE_ERROR (mrb_class_obj_get(mrb, "TypeError")) #define E_ARGUMENT_ERROR (mrb_class_obj_get(mrb, "ArgumentError")) #define E_INDEX_ERROR (mrb_class_obj_get(mrb, "IndexError")) diff --git a/src/error.c b/src/error.c index b2d9a8c8d..1183d8643 100644 --- a/src/error.c +++ b/src/error.c @@ -301,7 +301,7 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) if (isstr) { mesg = mrb_check_string_type(mrb, argv[0]); if (!mrb_nil_p(mesg)) { - mesg = mrb_exc_new3(mrb, mrb->eRuntimeError_class, mesg); + mesg = mrb_exc_new3(mrb, E_RUNTIME_ERROR, mesg); break; } } @@ -352,7 +352,7 @@ mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv) void mrb_sys_fail(mrb_state *mrb, const char *mesg) { - mrb_raise(mrb, mrb->eRuntimeError_class, "%s", mesg); + mrb_raise(mrb, E_RUNTIME_ERROR, "%s", mesg); } void @@ -369,6 +369,6 @@ mrb_init_exception(mrb_state *mrb) mrb_define_method(mrb, e, "message", exc_message, ARGS_NONE()); mrb_define_method(mrb, e, "inspect", exc_inspect, ARGS_NONE()); - mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ - mrb->eRuntimeError_class = mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ + mrb->eStandardError_class = mrb_define_class(mrb, "StandardError", mrb->eException_class); /* 15.2.23 */ + mrb_define_class(mrb, "RuntimeError", mrb->eStandardError_class); /* 15.2.28 */ } diff --git a/src/gc.c b/src/gc.c index c07c9b13b..a7537a015 100644 --- a/src/gc.c +++ b/src/gc.c @@ -277,7 +277,7 @@ gc_protect(mrb_state *mrb, struct RBasic *p) if (mrb->arena_idx > MRB_ARENA_SIZE) { /* arena overflow error */ mrb->arena_idx = MRB_ARENA_SIZE - 4; /* force room in arena */ - mrb_raise(mrb, mrb->eRuntimeError_class, "arena overflow error"); + mrb_raise(mrb, E_RUNTIME_ERROR, "arena overflow error"); } mrb->arena[mrb->arena_idx++] = p; } diff --git a/src/kernel.c b/src/kernel.c index 5b65714b6..209eaa91d 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -573,7 +573,7 @@ mrb_obj_instance_eval(mrb_state *mrb, mrb_value self) mrb_value a, b; if (mrb_get_args(mrb, "|S&", &a, &b) == 1) { - mrb_raise(mrb, mrb->eRuntimeError_class, "instance_eval with string not implemented"); + mrb_raise(mrb, E_RUNTIME_ERROR, "instance_eval with string not implemented"); } return mrb_yield_with_self(mrb, b, 0, 0, self); } @@ -1019,13 +1019,13 @@ mrb_f_raise(mrb_state *mrb, mrb_value self) argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]); switch (argc) { case 0: - mrb_raise(mrb, mrb->eRuntimeError_class, ""); + mrb_raise(mrb, E_RUNTIME_ERROR, ""); break; case 1: a[1] = mrb_check_string_type(mrb, a[0]); if (!mrb_nil_p(a[1])) { argc = 2; - a[0] = mrb_obj_value(mrb->eRuntimeError_class); + a[0] = mrb_obj_value(E_RUNTIME_ERROR); } /* fall through */ default: diff --git a/src/re.c b/src/re.c index 70e7c59b6..b821d2e71 100644 --- a/src/re.c +++ b/src/re.c @@ -2143,7 +2143,7 @@ mrb_reg_regsub(mrb_state *mrb, mrb_value str, mrb_value src, struct re_registers break; } else { - mrb_raise(mrb, mrb->eRuntimeError_class, "invalid group name reference format"); + mrb_raise(mrb, E_RUNTIME_ERROR, "invalid group name reference format"); } } diff --git a/src/string.c b/src/string.c index 6392b504c..585edf8a3 100644 --- a/src/string.c +++ b/src/string.c @@ -100,7 +100,7 @@ str_mod_check(mrb_state *mrb, mrb_value str, char *p, mrb_int len) struct RString *s = mrb_str_ptr(str); if (s->ptr != p || s->len != len) { - mrb_raise(mrb, mrb->eRuntimeError_class, "string modified"); + mrb_raise(mrb, E_RUNTIME_ERROR, "string modified"); } } diff --git a/src/vm.c b/src/vm.c index c78799c6d..f3e5a497a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -1604,7 +1604,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self) CASE(OP_ERR) { /* Bx raise RuntimeError with message Lit(Bx) */ mrb_value msg = pool[GETARG_Bx(i)]; - mrb_value exc = mrb_exc_new3(mrb, mrb->eRuntimeError_class, msg); + mrb_value exc = mrb_exc_new3(mrb, E_RUNTIME_ERROR, msg); mrb->exc = (struct RObject*)mrb_object(exc); goto L_RAISE; -- cgit v1.2.3 From d534f26f16ba94c2182a44e4201352d1fb277af0 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Wed, 27 Jun 2012 10:36:39 +0900 Subject: Use sizeof to get char array sizes. --- src/class.c | 4 ++-- src/codegen.c | 4 ++-- src/error.c | 6 +++--- src/time.c | 2 +- src/vm.c | 6 +++--- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/error.c') diff --git a/src/class.c b/src/class.c index 071d7aebe..599db9da5 100644 --- a/src/class.c +++ b/src/class.c @@ -1149,11 +1149,11 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass) switch (mrb_type(klass)) { case MRB_TT_CLASS: - snprintf(buf, 256, "#", c); + snprintf(buf, sizeof(buf), "#", c); break; case MRB_TT_MODULE: - snprintf(buf, 256, "#", c); + snprintf(buf, sizeof(buf), "#", c); break; default: diff --git a/src/codegen.c b/src/codegen.c index cbf401a1f..fb0006625 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -1537,7 +1537,7 @@ codegen(codegen_scope *s, node *tree, int val) int len; int sym; - len = snprintf(buf, 3, "$%c", (int)(intptr_t)tree); + len = snprintf(buf, sizeof(buf), "$%c", (int)(intptr_t)tree); sym = new_sym(s, mrb_intern2(s->mrb, buf, len)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); @@ -1550,7 +1550,7 @@ codegen(codegen_scope *s, node *tree, int val) int len; int sym; - len = snprintf(buf, 3, "$%d", (int)(intptr_t)tree); + len = snprintf(buf, sizeof(buf), "$%d", (int)(intptr_t)tree); sym = new_sym(s, mrb_intern2(s->mrb, buf, len)); genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym)); push(); diff --git a/src/error.c b/src/error.c index 1183d8643..e46e37cbb 100644 --- a/src/error.c +++ b/src/error.c @@ -180,7 +180,7 @@ mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...) int n; va_start(args, fmt); - n = vsnprintf(buf, 256, fmt, args); + n = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if (n < 0) { n = 0; @@ -197,7 +197,7 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...) int n; va_start(args, fmt); - n = vsnprintf(buf, 256, fmt, args); + n = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if (n < 0) { n = 0; @@ -216,7 +216,7 @@ mrb_sprintf(mrb_state *mrb, const char *fmt, ...) int n; va_start(args, fmt); - n = vsnprintf(buf, 256, fmt, args); + n = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if (n < 0) { n = 0; diff --git a/src/time.c b/src/time.c index 28cc3c1a3..3da824e82 100644 --- a/src/time.c +++ b/src/time.c @@ -435,7 +435,7 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self) tm = mrb_get_datatype(mrb, self, &mrb_time_type); if (!tm) return mrb_nil_value(); d = &tm->datetime; - len = snprintf(buf, 256, "%s %s %02d %02d:%02d:%02d %s%d", + len = snprintf(buf, sizeof(buf), "%s %s %02d %02d:%02d:%02d %s%d", wday_names[d->tm_wday], mon_names[d->tm_mon], d->tm_mday, d->tm_hour, d->tm_min, d->tm_sec, tm->timezone == MRB_TIMEZONE_UTC ? "UTC " : "", diff --git a/src/vm.c b/src/vm.c index 136ece3bd..d69081c9c 100644 --- a/src/vm.c +++ b/src/vm.c @@ -295,7 +295,7 @@ localjump_error(mrb_state *mrb, const char *kind) int len; mrb_value exc; - len = snprintf(buf, 256, "unexpected %s", kind); + len = snprintf(buf, sizeof(buf), "unexpected %s", kind); exc = mrb_exc_new(mrb, E_LOCALJUMP_ERROR, buf, len); mrb->exc = (struct RObject*)mrb_object(exc); } @@ -308,12 +308,12 @@ argnum_error(mrb_state *mrb, int num) mrb_value exc; if (mrb->ci->mid) { - len = snprintf(buf, 256, "'%s': wrong number of arguments (%d for %d)", + len = snprintf(buf, sizeof(buf), "'%s': wrong number of arguments (%d for %d)", mrb_sym2name(mrb, mrb->ci->mid), mrb->ci->argc, num); } else { - len = snprintf(buf, 256, "wrong number of arguments (%d for %d)", + len = snprintf(buf, sizeof(buf), "wrong number of arguments (%d for %d)", mrb->ci->argc, num); } exc = mrb_exc_new(mrb, E_ARGUMENT_ERROR, buf, len); -- cgit v1.2.3 From 96366117ea4bd91bccf00110469765ebc1ebaa8c Mon Sep 17 00:00:00 2001 From: Junji Sawada Date: Sat, 14 Jul 2012 11:39:25 +0900 Subject: Remove unnecessary header inclusion --- include/mruby/khash.h | 1 - src/cdump.c | 1 - src/codegen.c | 3 --- src/error.c | 5 ----- src/gc.c | 3 +-- src/hash.c | 1 - src/kernel.c | 5 ----- src/numeric.c | 4 ---- src/proc.c | 1 - src/range.c | 3 --- src/sprintf.c | 1 - src/string.c | 3 +-- src/struct.c | 4 ---- src/symbol.c | 4 ---- src/variable.c | 2 -- 15 files changed, 2 insertions(+), 39 deletions(-) (limited to 'src/error.c') diff --git a/include/mruby/khash.h b/include/mruby/khash.h index 0803521b7..09b23f6af 100644 --- a/include/mruby/khash.h +++ b/include/mruby/khash.h @@ -12,7 +12,6 @@ extern "C" { #endif #include -#include #include typedef uint32_t khint_t; diff --git a/src/cdump.c b/src/cdump.c index 16c1dc8ae..a4a2ac5e1 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -10,7 +10,6 @@ #include "mruby/irep.h" #include "mruby/string.h" -#include "re.h" #define MRB_CDUMP_LINE_LEN 128 diff --git a/src/codegen.c b/src/codegen.c index 6db09f310..9166b7144 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -10,15 +10,12 @@ #include "mruby.h" #include "mruby/string.h" #include "mruby/irep.h" -#include "mruby/proc.h" #include "mruby/compile.h" #include "mruby/numeric.h" #include "opcode.h" #include "node.h" #include #include -#include -#include #include typedef mrb_ast_node node; diff --git a/src/error.c b/src/error.c index e46e37cbb..5bfbc4319 100644 --- a/src/error.c +++ b/src/error.c @@ -6,14 +6,9 @@ #include "mruby.h" #include -#include #include #include #include "error.h" -#include "opcode.h" -#include "mruby/irep.h" -#include "mruby/proc.h" -#include "mruby/numeric.h" #include "mruby/variable.h" #include "mruby/string.h" #include "mruby/class.h" diff --git a/src/gc.c b/src/gc.c index ada0bf31f..3c00bb015 100644 --- a/src/gc.c +++ b/src/gc.c @@ -11,12 +11,10 @@ #include "mruby/string.h" #include "mruby/hash.h" #include "mruby/range.h" -#include "mruby/khash.h" #include #include "mruby/struct.h" #include "mruby/proc.h" #include "mruby/data.h" -#include "mruby/numeric.h" #include "mruby/variable.h" /* @@ -101,6 +99,7 @@ typedef struct { } RVALUE; #ifdef GC_PROFILE +#include #include static double program_invoke_time = 0; diff --git a/src/hash.c b/src/hash.c index ed8b70270..dacef4713 100644 --- a/src/hash.c +++ b/src/hash.c @@ -11,7 +11,6 @@ #include "mruby/array.h" #include "mruby/string.h" #include "mruby/variable.h" -#include static inline khint_t mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key) diff --git a/src/kernel.c b/src/kernel.c index 240c0dcb3..f5a1f3d53 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -6,14 +6,9 @@ #include "mruby.h" #include "mruby/string.h" -#include -#include #include "mruby/proc.h" -#include "mruby/range.h" #include "mruby/array.h" -#include "mruby/hash.h" #include "mruby/class.h" -#include "mruby/struct.h" #include "mruby/variable.h" #include "error.h" diff --git a/src/numeric.c b/src/numeric.c index 6638cf62c..ec3f97ca6 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -8,11 +8,7 @@ #include "mruby/numeric.h" #include "mruby/string.h" #include "mruby/array.h" -#include -#include "mruby/class.h" -#include "mruby/variable.h" -#include #include #include #include diff --git a/src/proc.c b/src/proc.c index 98f753ac6..3e9bf1f67 100644 --- a/src/proc.c +++ b/src/proc.c @@ -6,7 +6,6 @@ #include "mruby.h" #include "mruby/proc.h" -#include "mruby/array.h" #include "mruby/class.h" #include "opcode.h" diff --git a/src/range.c b/src/range.c index 703ad12aa..b05836914 100644 --- a/src/range.c +++ b/src/range.c @@ -7,9 +7,6 @@ #include "mruby.h" #include "mruby/class.h" #include "mruby/range.h" -#include "mruby/variable.h" -#include "error.h" -#include "mruby/numeric.h" #include "mruby/string.h" #include diff --git a/src/sprintf.c b/src/sprintf.c index b597ff343..519e40b4b 100644 --- a/src/sprintf.c +++ b/src/sprintf.c @@ -15,7 +15,6 @@ #include "mruby/hash.h" #include "mruby/numeric.h" #include -#include #include #ifdef HAVE_IEEEFP_H diff --git a/src/string.c b/src/string.c index 14da83c51..e41116ebc 100644 --- a/src/string.c +++ b/src/string.c @@ -10,11 +10,10 @@ #include #include "mruby/string.h" #include -#include "mruby/numeric.h" +#include #include "mruby/range.h" #include "mruby/array.h" #include "mruby/class.h" -#include "mruby/variable.h" #include #ifdef ENABLE_REGEXP #include "re.h" diff --git a/src/struct.c b/src/struct.c index 25cd02d3d..6d8ce057f 100644 --- a/src/struct.c +++ b/src/struct.c @@ -17,13 +17,9 @@ #include "encoding.h" #endif -#include "mruby/numeric.h" -#include "mruby/hash.h" #include "mruby/string.h" #include "mruby/class.h" #include "mruby/variable.h" -#include "mruby/range.h" -#include "error.h" //#include "defines.h" #define mrb_long2int(n) ((int)(n)) diff --git a/src/symbol.c b/src/symbol.c index baab0fb3c..40484d4b5 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -8,12 +8,8 @@ #include "mruby/khash.h" #include -#include -#include #include "mruby/string.h" #include -#include "mruby/class.h" -#include "mruby/variable.h" /* ------------------------------------------------------ */ typedef struct symbol_name { diff --git a/src/variable.c b/src/variable.c index e2f3a7d08..be686bf72 100644 --- a/src/variable.c +++ b/src/variable.c @@ -8,8 +8,6 @@ #include "mruby/class.h" #include "mruby/khash.h" #include "mruby/variable.h" -#include "mruby/string.h" -#include "mruby/range.h" #include "error.h" #include "mruby/array.h" -- cgit v1.2.3 From b2fc62f3a917e9ab1d562b49312f8d7dd2e057c5 Mon Sep 17 00:00:00 2001 From: Masaki Muranaka Date: Sun, 29 Jul 2012 15:25:14 +0900 Subject: Remove commented out code. --- src/error.c | 9 ------- src/etc.c | 5 ---- src/hash.c | 8 +++---- src/kernel.c | 76 ++++++++++++++++------------------------------------------ src/object.c | 1 - src/range.c | 1 - src/string.c | 9 ------- src/struct.c | 9 ------- src/variable.c | 5 ---- 9 files changed, 24 insertions(+), 99 deletions(-) (limited to 'src/error.c') diff --git a/src/error.c b/src/error.c index 5bfbc4319..e71245509 100644 --- a/src/error.c +++ b/src/error.c @@ -29,7 +29,6 @@ mrb_exc_new3(mrb_state *mrb, struct RClass* c, mrb_value str) return mrb_funcall(mrb, mrb_obj_value(c), "new", 1, str); } -//mrb_value make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr); /* * call-seq: * Exception.new(msg = nil) -> exception @@ -307,14 +306,6 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) case 3: n = 1; exception_call: - //if (argv[0] == sysstack_error) return argv[0]; - - //CONST_ID(mrb, exception, "exception"); - //mesg = mrb_check_funcall(mrb, argv[0], exception, n, argv+1); - //if (mrb_nil_p(mesg)) { - // /* undef */ - // mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); - //} if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) { mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1); } diff --git a/src/etc.c b/src/etc.c index 7e9381d16..d14498d9c 100644 --- a/src/etc.c +++ b/src/etc.c @@ -52,11 +52,6 @@ mrb_check_datatype(mrb_state *mrb, mrb_value obj, const struct mrb_data_type *ty mrb_value mrb_lastline_get(mrb_state *mrb) { - //mrb_value *var = mrb_svar(0); - //if (var) { - // return *var; - //} - //return mrb_nil_value(); mrb_value *argv; int argc; diff --git a/src/hash.c b/src/hash.c index 04e8c60be..5d3835019 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1339,9 +1339,9 @@ mrb_init_hash(mrb_state *mrb) mrb_define_method(mrb, h, "default_proc", mrb_hash_default_proc,ARGS_NONE()); /* 15.2.13.4.7 */ mrb_define_method(mrb, h, "default_proc=", mrb_hash_set_default_proc,ARGS_REQ(1)); /* 15.2.13.4.7 */ mrb_define_method(mrb, h, "__delete", mrb_hash_delete, ARGS_REQ(1)); /* core of 15.2.13.4.8 */ -//mrb_define_method(mrb, h, "each", mrb_hash_each_pair, ARGS_NONE()); /* 15.2.13.4.9 */ /* move to mrblib\hash.rb */ -//mrb_define_method(mrb, h, "each_key", mrb_hash_each_key, ARGS_NONE()); /* 15.2.13.4.10 */ /* move to mrblib\hash.rb */ -//mrb_define_method(mrb, h, "each_value", mrb_hash_each_value, ARGS_NONE()); /* 15.2.13.4.11 */ /* move to mrblib\hash.rb */ +// "each" 15.2.13.4.9 move to mrblib/hash.rb +// "each_key" 15.2.13.4.10 move to mrblib/hash.rb +// "each_value" 15.2.13.4.11 move to mrblib/hash.rb mrb_define_method(mrb, h, "empty?", mrb_hash_empty_p, ARGS_NONE()); /* 15.2.13.4.12 */ mrb_define_method(mrb, h, "has_key?", mrb_hash_has_key, ARGS_REQ(1)); /* 15.2.13.4.13 */ mrb_define_method(mrb, h, "has_value?", mrb_hash_has_value, ARGS_REQ(1)); /* 15.2.13.4.14 */ @@ -1352,7 +1352,7 @@ mrb_init_hash(mrb_state *mrb) mrb_define_method(mrb, h, "keys", mrb_hash_keys, ARGS_NONE()); /* 15.2.13.4.19 */ mrb_define_method(mrb, h, "length", mrb_hash_size_m, ARGS_NONE()); /* 15.2.13.4.20 */ mrb_define_method(mrb, h, "member?", mrb_hash_has_key, ARGS_REQ(1)); /* 15.2.13.4.21 */ -//mrb_define_method(mrb, h, "merge", mrb_hash_merge, ARGS_REQ(1)); /* 15.2.13.4.22 */ /* move to mrblib\hash.rb */ +// "merge" 15.2.13.4.22 move to mrblib/hash.rb mrb_define_method(mrb, h, "replace", mrb_hash_replace, ARGS_REQ(1)); /* 15.2.13.4.23 */ mrb_define_method(mrb, h, "shift", mrb_hash_shift, ARGS_NONE()); /* 15.2.13.4.24 */ mrb_define_method(mrb, h, "size", mrb_hash_size_m, ARGS_NONE()); /* 15.2.13.4.25 */ diff --git a/src/kernel.c b/src/kernel.c index 468891b23..8aba1a808 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -72,9 +72,6 @@ inspect_obj(mrb_state *mrb, mrb_value obj, mrb_value str, int recur) int mrb_obj_basic_to_s_p(mrb_state *mrb, mrb_value obj) { - //const mrb_method_entry_t *me = mrb_method_entry(CLASS_OF(obj), mrb_intern("to_s")); - //if (me && me->def && me->def->type == VM_METHOD_TYPE_CFUNC && - //me->def->body.cfunc.func == mrb_any_to_s) struct RProc *me = mrb_method_search(mrb, mrb_class(mrb, obj), mrb_intern(mrb, "to_s")); if (me && MRB_PROC_CFUNC_P(me) && (me->body.func == mrb_any_to_s)) return 1; @@ -314,52 +311,38 @@ mrb_singleton_class_clone(mrb_state *mrb, mrb_value obj) { struct RClass *klass = RBASIC(obj)->c; - //if (!FL_TEST(klass, FL_SINGLETON)) - //return klass; if (klass->tt != MRB_TT_SCLASS) return klass; else { - //struct clone_method_data data; - /* copy singleton(unnamed) class */ - //VALUE clone = class_alloc(RBASIC(klass)->flags, 0); + /* copy singleton(unnamed) class */ struct RClass *clone = (struct RClass*)mrb_obj_alloc(mrb, klass->tt, mrb->class_class); - //clone->super = objklass->super; - if ((mrb_type(obj) == MRB_TT_CLASS) || - (mrb_type(obj) == MRB_TT_SCLASS)) { /* BUILTIN_TYPE(obj) == T_CLASS */ - clone->c = clone; - } - else { - clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass)); - } + if ((mrb_type(obj) == MRB_TT_CLASS) || + (mrb_type(obj) == MRB_TT_SCLASS)) { /* BUILTIN_TYPE(obj) == T_CLASS */ + clone->c = clone; + } + else { + clone->c = mrb_singleton_class_clone(mrb, mrb_obj_value(klass)); + } - clone->super = klass->super; - if (klass->iv) { - clone->iv = klass->iv; - } - if (klass->mt) { - clone->mt = kh_copy(mt, mrb, klass->mt); - } - else { - clone->mt = kh_init(mt, mrb); - } - clone->tt = MRB_TT_SCLASS; - return clone; + clone->super = klass->super; + if (klass->iv) { + clone->iv = klass->iv; + } + if (klass->mt) { + clone->mt = kh_copy(mt, mrb, klass->mt); + } + else { + clone->mt = kh_init(mt, mrb); + } + clone->tt = MRB_TT_SCLASS; + return clone; } } static void init_copy(mrb_state *mrb, mrb_value dest, mrb_value obj) { - //if (OBJ_FROZEN(dest)) { - // rb_raise(rb_eTypeError, "[bug] frozen object (%s) allocated", rb_obj_classname(dest)); - //} - //RBASIC(dest)->flags &= ~(T_MASK|FL_EXIVAR); - //RBASIC(dest)->flags |= RBASIC(obj)->flags & (T_MASK|FL_EXIVAR|FL_TAINT); - //if (FL_TEST(obj, FL_EXIVAR)) { - // mrb_copy_generic_ivar(dest, obj); - //} - //mrb_gc_copy_finalizer(dest, obj); switch (mrb_type(obj)) { case MRB_TT_OBJECT: case MRB_TT_CLASS: @@ -416,8 +399,6 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self) clone = (struct RObject*)mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self)); clone->c = mrb_singleton_class_clone(mrb, self); init_copy(mrb, mrb_obj_value(clone), self); - //1-9-2 no bug mrb_funcall(mrb, clone, "initialize_clone", 1, self); - //RBASIC(clone)->flags |= RBASIC(obj)->flags & FL_FREEZE; return mrb_obj_value(clone); } @@ -466,7 +447,6 @@ mrb_obj_extend(mrb_state *mrb, int argc, mrb_value *argv, mrb_value obj) mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (at least 1)"); } for (i = 0; i < argc; i++) { - //Check_Type(argv[i], T_MODULE); mrb_check_type(mrb, argv[i], MRB_TT_MODULE); } while (argc--) { @@ -511,19 +491,6 @@ mrb_obj_extend_m(mrb_state *mrb, mrb_value self) return mrb_obj_extend(mrb, argc, argv, self); } -/* 15.3.1.2.4 */ -/* 15.3.1.3.14 */ -/* - * call-seq: - * global_variables -> array - * - * Returns an array of the names of global variables. - * - * global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr] - */ -//mrb_value -//mrb_f_global_variables(mrb_state *mrb, mrb_value self) - /* 15.3.1.3.15 */ /* * call-seq: @@ -824,7 +791,6 @@ mrb_obj_singleton_methods(mrb_state *mrb, int argc, mrb_value *argv, mrb_value o recur = mrb_true_value(); } else { - //mrb_scan_args(argc, argv, "01", &recur); recur = argv[0]; } klass = mrb_class(mrb, obj); @@ -853,7 +819,6 @@ retry: else { mrb_value recur; - //mrb_scan_args(argc, argv, "1", &recur); recur = argv[0]; if (mrb_test(recur)) { argc = 0; @@ -1073,7 +1038,6 @@ obj_respond_to(mrb_state *mrb, mrb_value self) mrb_sym id; mrb_get_args(mrb, "*", &argv, &argc); - //mrb_scan_args(argc, argv, "11", &mid, &priv); mid = argv[0]; if (argc > 1) priv = argv[1]; else priv = mrb_nil_value(); diff --git a/src/object.c b/src/object.c index 43e064fb0..4f5fb1d28 100644 --- a/src/object.c +++ b/src/object.c @@ -516,7 +516,6 @@ mrb_to_integer(mrb_state *mrb, mrb_value val, const char *method) mrb_value v; if (FIXNUM_P(val)) return val; - //if (TYPE(val) == T_BIGNUM) return val; v = convert_type(mrb, val, "Integer", method, TRUE); if (!mrb_obj_is_kind_of(mrb, v, mrb->fixnum_class)) { const char *cname = mrb_obj_classname(mrb, val); diff --git a/src/range.c b/src/range.c index 14fa2a6a3..9113a810a 100644 --- a/src/range.c +++ b/src/range.c @@ -412,7 +412,6 @@ range_initialize_copy(mrb_state *mrb, mrb_value copy) mrb_get_args(mrb, "o", &src); if (mrb_obj_equal(mrb, copy, src)) return copy; - //mrb_check_frozen(copy); if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } diff --git a/src/string.c b/src/string.c index e41116ebc..0a5dee88e 100644 --- a/src/string.c +++ b/src/string.c @@ -1354,7 +1354,6 @@ str_gsub(mrb_state *mrb, mrb_value str, mrb_int bang) static mrb_value mrb_str_gsub(mrb_state *mrb, mrb_value self) { - //return str_gsub(argc, argv, self, 0); return str_gsub(mrb, self, 0); } @@ -1469,10 +1468,8 @@ mrb_str_index_m(mrb_state *mrb, mrb_value str) int argc; mrb_value sub; - //mrb_value initpos; mrb_int pos; - //if (mrb_scan_args(argc, argv, "11", &sub, &initpos) == 2) { mrb_get_args(mrb, "*", &argv, &argc); if (argc == 2) { pos = mrb_fixnum(argv[1]); @@ -1959,7 +1956,6 @@ scan_once(mrb_state *mrb, mrb_value str, mrb_value pat, mrb_int *start) if (mrb_reg_search(mrb, pat, str, *start, 0) >= 0) { match = mrb_backref_get(mrb); - //regs = RMATCH(match)->regs; pmatch = mrb_match_ptr(match); regs = &pmatch->rmatch->regs; if (regs->beg[0] == regs->end[0]) { @@ -2143,7 +2139,6 @@ mrb_str_split_m(mrb_state *mrb, mrb_value str) split_type = awk; } else { -//fs_set: if (mrb_type(spat) == MRB_TT_STRING) { split_type = string; #ifdef ENABLE_REGEXP @@ -2546,7 +2541,6 @@ mrb_str_to_inum(mrb_state *mrb, mrb_value str, int base, int badcheck) if (s) { len = RSTRING_LEN(str); if (s[len]) { /* no sentinel somehow */ - //char *p = ALLOCA_N(char, len+1); char *p = mrb_malloc(mrb, len+1); //MEMCPY(p, s, char, len); @@ -2584,10 +2578,8 @@ mrb_str_to_i(mrb_state *mrb, mrb_value self) { mrb_value *argv; int argc; - //mrb_value b; int base; - //mrb_scan_args(argc, *argv, "01", &b); mrb_get_args(mrb, "*", &argv, &argc); if (argc == 0) base = 10; @@ -2710,7 +2702,6 @@ mrb_str_to_dbl(mrb_state *mrb, mrb_value str, int badcheck) static mrb_value mrb_str_to_f(mrb_state *mrb, mrb_value self) { - //return mrb_float_new(mrb_str_to_dbl(self, 0/*Qfalse*/)); return mrb_float_value(mrb_str_to_dbl(mrb, self, 0/*Qfalse*/)); } diff --git a/src/struct.c b/src/struct.c index 6d8ce057f..0a95f9e49 100644 --- a/src/struct.c +++ b/src/struct.c @@ -38,8 +38,6 @@ struct_ivar_get(mrb_state *mrb, mrb_value c, mrb_sym id) mrb_value ans; for (;;) { - //if (mrb_ivar_defined(c, id)) - // return mrb_iv_get(mrb, c, id); ans = mrb_iv_get(mrb, c, id); if (!mrb_nil_p(ans)) return ans; kclass = RCLASS_SUPER(c); @@ -260,19 +258,15 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass * k //OBJ_FREEZE(members); if (mrb_nil_p(name)) { c = mrb_class_new(mrb, klass); - //mrb_make_metaclass(nstr, RBASIC(klass)->c); - //mrb_class_inherited(klass, nstr); } else { /* old style: should we warn? */ name = mrb_str_to_str(mrb, name); id = mrb_to_id(mrb, name); if (!mrb_is_const_id(id)) { - //mrb_name_error(id, "identifier %s needs to be constant", StringValuePtr(name)); mrb_name_error(mrb, id, "identifier %s needs to be constant", mrb_string_value_ptr(mrb, name)); } if (mrb_const_defined_at(mrb, klass, id)) { - //mrb_warn("redefining constant Struct::%s", StringValuePtr(name)); mrb_warn("redefining constant Struct::%s", mrb_string_value_ptr(mrb, name)); //?rb_mod_remove_const(klass, mrb_sym2name(mrb, id)); } @@ -376,7 +370,6 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) mrb_get_args(mrb, "&*", &b, &argv, &argc); if (argc > 0) name = argv[0]; if (argc > 1) rest = argv[1]; - //mrb_scan_args(argc, argv, "1*", &name, &rest); if (mrb_type(rest) == MRB_TT_ARRAY) { if (!mrb_nil_p(name) && SYMBOL_P(name)) { /* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */ @@ -389,7 +382,6 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass) argcnt = argc-1; if (!mrb_nil_p(name) && SYMBOL_P(name)) { /* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */ - //mrb_ary_unshift(mrb, rest, name); name = mrb_nil_value(); pargv = &argv[0]; argcnt++; @@ -557,7 +549,6 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) mrb_get_args(mrb, "o", &s); if (mrb_obj_equal(mrb, copy, s)) return copy; - //mrb_check_frozen(copy); if (!mrb_obj_is_instance_of(mrb, s, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } diff --git a/src/variable.c b/src/variable.c index a1a7f2e82..04e5ad9f7 100644 --- a/src/variable.c +++ b/src/variable.c @@ -460,10 +460,6 @@ kiv_lookup(khash_t(iv)* table, mrb_sym key, mrb_value *value) khash_t(iv) *h=table; khiter_t k; - // you must check(iv==0), before you call this function. - //if (!obj->iv) { - // return 0; - //} k = kh_get(iv, h, key); if (k != kh_end(h)) { *value = kh_value(h, k); @@ -505,7 +501,6 @@ mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id) mrb_value mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id) { - //return ivar_get(obj, id, FALSE); return mrb_iv_get(mrb, obj, id); } -- cgit v1.2.3 From d271bf0aa6e44a315802cf4246f5b92552be010a Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 13:15:02 +0900 Subject: make mrb_funcall_argv and mrb_funcall_with_block to take mrb_sym as a method name --- include/mruby.h | 4 ++-- src/class.c | 36 ++++++++++++++++++++++++------------ src/error.c | 17 ++++++++++------- src/kernel.c | 2 +- src/re.c | 2 +- src/variable.c | 4 ++-- src/vm.c | 10 ++++++---- 7 files changed, 46 insertions(+), 29 deletions(-) (limited to 'src/error.c') diff --git a/include/mruby.h b/include/mruby.h index 6fcda4d35..451b4eb8b 100644 --- a/include/mruby.h +++ b/include/mruby.h @@ -330,8 +330,8 @@ struct RClass * mrb_define_module_under(mrb_state *mrb, struct RClass *outer, co int mrb_get_args(mrb_state *mrb, const char *format, ...); mrb_value mrb_funcall(mrb_state*, mrb_value, const char*, int,...); -mrb_value mrb_funcall_argv(mrb_state*, mrb_value, const char*, int, mrb_value*); -mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, const char*, int, mrb_value*, mrb_value); +mrb_value mrb_funcall_argv(mrb_state*, mrb_value, mrb_sym, int, mrb_value*); +mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, mrb_sym, int, mrb_value*, mrb_value); mrb_sym mrb_intern(mrb_state*,const char*); mrb_sym mrb_intern2(mrb_state*,const char*,int); mrb_sym mrb_intern_str(mrb_state*,mrb_value); diff --git a/src/class.c b/src/class.c index 6efc9f5e7..50d0b6317 100644 --- a/src/class.c +++ b/src/class.c @@ -723,8 +723,8 @@ mrb_mod_include(mrb_state *mrb, mrb_value klass) mrb_check_type(mrb, argv[i], MRB_TT_MODULE); } while (argc--) { - mrb_funcall_argv(mrb, argv[argc], "append_features", 1, &klass); - mrb_funcall_argv(mrb, argv[argc], "included", 1, &klass); + mrb_funcall(mrb, argv[argc], "append_features", 1, klass); + mrb_funcall(mrb, argv[argc], "included", 1, klass); } return klass; @@ -877,29 +877,41 @@ mrb_method_search(mrb_state *mrb, struct RClass* c, mrb_sym mid) mrb_value mrb_funcall(mrb_state *mrb, mrb_value self, const char *name, int argc, ...) { - mrb_value args[MRB_FUNCALL_ARGC_MAX]; + mrb_sym mid = mrb_intern(mrb, name); va_list ap; int i; - if (argc != 0) { + if (argc == 0) { + return mrb_funcall_argv(mrb, self, mid, 0, 0); + } + else if (argc == 1) { + mrb_value v; + + va_start(ap, argc); + v = va_arg(ap, mrb_value); + va_end(ap); + return mrb_funcall_argv(mrb, self, mid, 1, &v); + } + else { + mrb_value argv[MRB_FUNCALL_ARGC_MAX]; + if (argc > MRB_FUNCALL_ARGC_MAX) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)\n", MRB_FUNCALL_ARGC_MAX); - } + mrb_raise(mrb, E_ARGUMENT_ERROR, "Too long arguments. (limit=%d)", MRB_FUNCALL_ARGC_MAX); + } va_start(ap, argc); for (i = 0; i < argc; i++) { - args[i] = va_arg(ap, mrb_value); + argv[i] = va_arg(ap, mrb_value); } va_end(ap); + return mrb_funcall_argv(mrb, self, mid, argc, argv); } - return mrb_funcall_argv(mrb, self, name, argc, args); } - void mrb_obj_call_init(mrb_state *mrb, mrb_value obj, int argc, mrb_value *argv) { - mrb_funcall_argv(mrb, obj, "initialize", argc, argv); + mrb_funcall_argv(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv); } /* @@ -938,7 +950,7 @@ mrb_class_new_instance_m(mrb_state *mrb, mrb_value klass) c = (struct RClass*)mrb_obj_alloc(mrb, k->tt, k); c->super = k; obj = mrb_obj_value(c); - mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk); + mrb_funcall_with_block(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv, blk); return obj; } @@ -957,7 +969,7 @@ mrb_instance_new(mrb_state *mrb, mrb_value cv) o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c); obj = mrb_obj_value(o); mrb_get_args(mrb, "*&", &argv, &argc, &blk); - mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk); + mrb_funcall_with_block(mrb, obj, mrb_intern(mrb, "initialize"), argc, argv, blk); return obj; } diff --git a/src/error.c b/src/error.c index e71245509..6fe839cb2 100644 --- a/src/error.c +++ b/src/error.c @@ -144,7 +144,7 @@ exc_equal(mrb_state *mrb, mrb_value exc) if (mrb_obj_equal(mrb, exc, obj)) return mrb_true_value(); if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) { - if ( mrb_respond_to(mrb, obj, mrb_intern(mrb, "message")) ) { + if (mrb_respond_to(mrb, obj, mrb_intern(mrb, "message"))) { mesg = mrb_funcall(mrb, obj, "message", 0); } else @@ -306,12 +306,15 @@ make_exception(mrb_state *mrb, int argc, mrb_value *argv, int isstr) case 3: n = 1; exception_call: - if (mrb_respond_to(mrb, argv[0], mrb_intern(mrb, "exception"))) { - mesg = mrb_funcall_argv(mrb, argv[0], "exception", n, argv+1); - } - else { - /* undef */ - mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); + { + mrb_sym exc = mrb_intern(mrb, "exception"); + if (mrb_respond_to(mrb, argv[0], exc)) { + mesg = mrb_funcall_argv(mrb, argv[0], exc, n, argv+1); + } + else { + /* undef */ + mrb_raise(mrb, E_TYPE_ERROR, "exception class/object expected"); + } } break; diff --git a/src/kernel.c b/src/kernel.c index 36dfbe769..740960f80 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -245,7 +245,7 @@ mrb_f_send(mrb_state *mrb, mrb_value self) int argc; mrb_get_args(mrb, "n*&", &name, &argv, &argc, &block); - return mrb_funcall_with_block(mrb,self, mrb_sym2name(mrb, name), argc, argv, block); + return mrb_funcall_with_block(mrb,self, name, argc, argv, block); } /* 15.3.1.2.2 */ diff --git a/src/re.c b/src/re.c index f3cfea484..0022f9a9c 100644 --- a/src/re.c +++ b/src/re.c @@ -76,7 +76,7 @@ mrb_reg_s_new_instance(mrb_state *mrb, /*int argc, mrb_value *argv, */mrb_value re->ptr = 0; re->src = 0; re->usecnt = 0; - return mrb_funcall_argv(mrb, mrb_obj_value(re), "initialize", argc, argv); + return mrb_funcall_argv(mrb, mrb_obj_value(re), mrb_intern(mrb, "initialize"), argc, argv); } mrb_value diff --git a/src/variable.c b/src/variable.c index b81b292d9..a62e7e126 100644 --- a/src/variable.c +++ b/src/variable.c @@ -320,8 +320,8 @@ const_get(mrb_state *mrb, struct RClass *base, mrb_sym sym) return kh_value(h, k); } if (mrb_respond_to(mrb, mrb_obj_value(c), cm)) { - mrb_value argv = mrb_symbol_value(sym); - return mrb_funcall_argv(mrb, mrb_obj_value(c), "const_missing", 1, &argv); + mrb_value name = mrb_symbol_value(sym); + return mrb_funcall(mrb, mrb_obj_value(c), "const_missing", 1, name); } } c = c->super; diff --git a/src/vm.c b/src/vm.c index 2a13f0ea4..130e56071 100644 --- a/src/vm.c +++ b/src/vm.c @@ -179,16 +179,18 @@ ecall(mrb_state *mrb, int i) } mrb_value -mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int argc, mrb_value *argv, mrb_value blk) +mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mrb_value *argv, mrb_value blk) { struct RProc *p; struct RClass *c; - mrb_sym mid = mrb_intern(mrb, name); mrb_sym undef = 0; mrb_callinfo *ci; int n = mrb->ci->nregs; mrb_value val; + if (argc < 0) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative argc for funcall (%d)", argc); + } c = mrb_class(mrb, self); p = mrb_method_search_vm(mrb, &c, mid); if (!p) { @@ -232,9 +234,9 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int arg } mrb_value -mrb_funcall_argv(mrb_state *mrb, mrb_value self, const char *name, int argc, mrb_value *argv) +mrb_funcall_argv(mrb_state *mrb, mrb_value self, mrb_sym mid, int argc, mrb_value *argv) { - return mrb_funcall_with_block(mrb, self, name, argc, argv, mrb_nil_value()); + return mrb_funcall_with_block(mrb, self, mid, argc, argv, mrb_nil_value()); } mrb_value -- cgit v1.2.3