summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/mruby.h1
-rw-r--r--src/array.c4
-rw-r--r--src/class.c27
-rw-r--r--src/parse.y4
-rw-r--r--src/variable.c13
-rw-r--r--tools/mruby/mruby.c10
6 files changed, 29 insertions, 30 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 1124ba89c..137a1b94e 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -297,7 +297,6 @@ void mrb_undef_method(mrb_state*, struct RClass*, const char*);
mrb_value mrb_instance_new(mrb_state *mrb, mrb_value cv);
struct RClass * mrb_class_new(mrb_state *mrb, struct RClass *super);
struct RClass * mrb_module_new(mrb_state *mrb);
-struct RClass * mrb_class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym name);
struct RClass * mrb_class_get(mrb_state *mrb, const char *name);
struct RClass * mrb_class_obj_get(mrb_state *mrb, const char *name);
diff --git a/src/array.c b/src/array.c
index ec687bbf3..ed1c3f475 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1006,7 +1006,7 @@ mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
/*
* call-seq:
- * ary.join(sep=nil) -> str
+ * ary.join(sep="") -> str
*
* Returns a string created by converting each element of the array to
* a string, separated by <i>sep</i>.
@@ -1020,7 +1020,7 @@ mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
{
mrb_value sep = mrb_nil_value();
- mrb_get_args(mrb, "|o", &sep);
+ mrb_get_args(mrb, "|S", &sep);
return mrb_ary_join(mrb, ary, sep);
}
diff --git a/src/class.c b/src/class.c
index 774b020a8..1409c0b33 100644
--- a/src/class.c
+++ b/src/class.c
@@ -216,6 +216,23 @@ mrb_vm_define_class(mrb_state *mrb, mrb_value outer, mrb_value super, mrb_sym id
return c;
}
+static struct RClass *
+class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id)
+{
+ mrb_value c = mrb_const_get(mrb, mrb_obj_value(klass), id);
+
+ if (c.tt != MRB_TT_MODULE && c.tt != MRB_TT_CLASS) {
+ mrb_raise(mrb, E_TYPE_ERROR, "%s is not a class/module", mrb_sym2name(mrb, id));
+ }
+ return mrb_class_ptr(c);
+}
+
+struct RClass *
+mrb_class_get(mrb_state *mrb, const char *name)
+{
+ return class_from_sym(mrb, mrb->object_class, mrb_intern(mrb, name));
+}
+
/*!
* Defines a class under the namespace of \a outer.
* \param outer a class which contains the new class.
@@ -239,10 +256,7 @@ mrb_define_class_under(mrb_state *mrb, struct RClass *outer, const char *name, s
mrb_sym id = mrb_intern(mrb, name);
if (mrb_const_defined_at(mrb, outer, id)) {
- c = mrb_class_from_sym(mrb, outer, id);
- if (c->tt != MRB_TT_CLASS) {
- mrb_raise(mrb, E_TYPE_ERROR, "%s is not a class", mrb_sym2name(mrb, id));
- }
+ c = class_from_sym(mrb, outer, id);
if (mrb_class_real(c->super) != super) {
mrb_name_error(mrb, id, "%s is already defined", mrb_sym2name(mrb, id));
}
@@ -265,10 +279,7 @@ mrb_define_module_under(mrb_state *mrb, struct RClass *outer, const char *name)
mrb_sym id = mrb_intern(mrb, name);
if (mrb_const_defined_at(mrb, outer, id)) {
- c = mrb_class_from_sym(mrb, outer, id);
- if (c->tt != MRB_TT_MODULE) {
- mrb_raise(mrb, E_TYPE_ERROR, "%s is not a module", mrb_sym2name(mrb, id));
- }
+ c = class_from_sym(mrb, outer, id);
return c;
}
c = mrb_module_new(mrb);
diff --git a/src/parse.y b/src/parse.y
index c766b3927..48823233f 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -688,7 +688,7 @@ new_float(parser_state *p, const char *s)
static node*
new_str(parser_state *p, const char *s, int len)
{
- return cons((node*)NODE_STR, cons((node*)strndup(s, len), (node*)len));
+ return cons((node*)NODE_STR, cons((node*)strndup(s, len), (node*)(intptr_t)len));
}
// (:dstr . a)
@@ -4708,7 +4708,7 @@ parser_update_cxt(parser_state *p, mrbc_context *cxt)
int i = 0;
if (!cxt) return;
- if ((int)p->tree->car != NODE_SCOPE) return;
+ if ((int)(intptr_t)p->tree->car != NODE_SCOPE) return;
n0 = n = p->tree->cdr->car;
while (n) {
i++;
diff --git a/src/variable.c b/src/variable.c
index be686bf72..501bed5a6 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -495,19 +495,6 @@ mrb_const_defined_at(mrb_state *mrb, struct RClass *klass, mrb_sym id)
return mrb_const_defined_0(mrb, klass, id, TRUE, FALSE);
}
-struct RClass *
-mrb_class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id)
-{
- mrb_value c = const_get(mrb, klass, id);
- return mrb_class_ptr(c);
-}
-
-struct RClass *
-mrb_class_get(mrb_state *mrb, const char *name)
-{
- return mrb_class_from_sym(mrb, mrb->object_class, mrb_intern(mrb, name));
-}
-
mrb_value
mrb_attr_get(mrb_state *mrb, mrb_value obj, mrb_sym id)
{
diff --git a/tools/mruby/mruby.c b/tools/mruby/mruby.c
index d3c22f96d..abc0bdc5e 100644
--- a/tools/mruby/mruby.c
+++ b/tools/mruby/mruby.c
@@ -196,11 +196,13 @@ main(int argc, char **argv)
v = mrb_load_file_cxt(mrb, args.rfp, c);
}
mrbc_context_free(mrb, c);
- if (args.check_syntax) {
- printf("Syntax OK\n");
+ if (mrb->exc) {
+ if (!mrb_undef_p(v)) {
+ mrb_p(mrb, mrb_obj_value(mrb->exc));
+ }
}
- else if (!mrb_undef_p(v) && mrb->exc) {
- mrb_p(mrb, mrb_obj_value(mrb->exc));
+ else if (args.check_syntax) {
+ printf("Syntax OK\n");
}
}
cleanup(mrb, &args);