Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: thecodeshop/mruby
base: 91b4929697
...
head fork: thecodeshop/mruby
compare: 265ff670c8
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 28 files changed
  • 0 commit comments
  • 3 contributors
View
2  include/mruby.h
@@ -329,7 +329,7 @@ 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*, struct RProc*);
+mrb_value mrb_funcall_with_block(mrb_state*, mrb_value, const char*, int, mrb_value*, mrb_value);
mrb_sym mrb_intern(mrb_state*,const char*);
const char *mrb_sym2name(mrb_state*,mrb_sym);
mrb_value mrb_str_format(mrb_state *, int, const mrb_value *, mrb_value);
View
2  include/mruby/hash.h
@@ -31,7 +31,7 @@ mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key);
mrb_value mrb_hash_getWithDef(mrb_state *mrb, mrb_value hash, mrb_value vkey, mrb_value def);
mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key);
mrb_value mrb_hash(mrb_state *mrb, mrb_value obj);
-void ruby_setenv(mrb_state *mrb, const char *name, const char *value);
+mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value self);
/* RHASH_TBL allocates st_table if not available. */
#define RHASH(obj) ((struct RHash*)((obj).value.p))
View
7 src/Makefile
@@ -7,6 +7,8 @@ BASEDIR = .
TARGET := ../lib/libmruby_core.a
YSRC := $(BASEDIR)/parse.y
YC := $(BASEDIR)/y.tab.c
+KWD := $(BASEDIR)/keywords
+LDEF := $(BASEDIR)/lex.def
EXCEPT1 := $(YC) $(BASEDIR)/minimain.c
OBJY := $(patsubst %.c,%.o,$(YC))
OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c)))
@@ -48,13 +50,16 @@ $(OBJS) : %.o : %.c
$(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@
# parser complie
-$(OBJY) : $(YC)
+$(OBJY) : $(YC) $(LDEF)
$(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(YC) -o $(OBJY)
# yacc complie
$(YC) : $(YSRC)
$(YACC) -o $(YC) $(YSRC)
+$(LDEF) : $(KWD)
+ gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$$' $(KWD) > $(LDEF)
+
# clean up
.PHONY : clean #cleandep
clean :
View
29 src/array.c
@@ -177,10 +177,7 @@ mrb_ary_concat_m(mrb_state *mrb, mrb_value self)
{
mrb_value other;
- mrb_get_args(mrb, "o", &other);
- if (mrb_type(other) != MRB_TT_ARRAY) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "expected Array");
- }
+ mrb_get_args(mrb, "A", &other);
mrb_ary_concat(mrb, self, other);
return self;
}
@@ -193,11 +190,7 @@ mrb_ary_plus(mrb_state *mrb, mrb_value self)
mrb_value other;
mrb_value ary;
- mrb_get_args(mrb, "o", &other);
- if (mrb_type(other) != MRB_TT_ARRAY) {
- mrb_raise(mrb, E_ARGUMENT_ERROR, "expected Array");
- }
-
+ mrb_get_args(mrb, "A", &other);
ary = mrb_ary_new_capa(mrb, a1->len + RARRAY_LEN(other));
a2 = mrb_ary_ptr(ary);
memcpy(a2->buf, a1->buf, sizeof(mrb_value)*a1->len);
@@ -924,22 +917,10 @@ mrb_ary_join(mrb_state *mrb, mrb_value ary, mrb_value sep)
static mrb_value
mrb_ary_join_m(mrb_state *mrb, mrb_value ary)
{
- mrb_value *argv;
- int argc;
-
- mrb_get_args(mrb, "*", &argv, &argc);
- switch(argc) {
- case 0:
- return mrb_ary_join(mrb, ary, mrb_nil_value());
-
- case 1:
- return mrb_ary_join(mrb, ary, argv[0]);
-
- default:
- mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
- }
+ mrb_value sep = mrb_nil_value();
- return mrb_nil_value(); /* dummy */
+ mrb_get_args(mrb, "|o", &sep);
+ return mrb_ary_join(mrb, ary, sep);
}
static mrb_value
View
249 src/class.c
@@ -328,15 +328,67 @@ mrb_define_method_vm(mrb_state *mrb, struct RClass *c, mrb_sym name, mrb_value b
kh_value(h, k) = mrb_proc_ptr(body);
}
+static mrb_value
+check_type(mrb_state *mrb, mrb_value val, enum mrb_vtype t, const char *c, const char *m)
+{
+ mrb_value tmp;
+
+ tmp = mrb_check_convert_type(mrb, val, t, c, m);
+ if (mrb_nil_p(tmp)) {
+ mrb_raise(mrb, E_TYPE_ERROR, "expected %s", c);
+ }
+ return tmp;
+}
+
+static mrb_value
+to_str(mrb_state *mrb, mrb_value val)
+{
+ return check_type(mrb, val, MRB_TT_STRING, "String", "to_str");
+}
+
+static mrb_value
+to_ary(mrb_state *mrb, mrb_value val)
+{
+ return check_type(mrb, val, MRB_TT_ARRAY, "Array", "to_ary");
+}
+
+static mrb_value
+to_hash(mrb_state *mrb, mrb_value val)
+{
+ return check_type(mrb, val, MRB_TT_HASH, "Hash", "to_hash");
+}
+
+/*
+ retrieve arguments from mrb_state.
+
+ mrb_get_args(mrb, format, ...)
+
+ returns number of arguments parsed.
+
+ fortmat specifiers:
+
+ o: Object [mrb_value]
+ S: String [mrb_value]
+ A: Array [mrb_value]
+ H: Hash [mrb_value]
+ s: String [char*,int]
+ z: String [char*]
+ a: Array [mrb_value*,int]
+ f: Float [mrb_float]
+ i: Integer [mrb_int]
+ &: Block [mrb_value]
+ *: rest argument [mrb_value*,int]
+ |: optional
+ */
int
mrb_get_args(mrb_state *mrb, const char *format, ...)
{
char c;
- int i=0;
+ int i = 0;
mrb_value *sp = mrb->stack + 1;
va_list ap;
int argc = mrb->ci->argc;
- int *argcp;
+ int opt = 0;
va_start(ap, format);
if (argc < 0) {
@@ -346,39 +398,92 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
sp = a->buf;
}
while ((c = *format++)) {
+ if (argc < i) {
+ if (opt) continue;
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
+ }
switch (c) {
case 'o':
{
mrb_value *p;
+
p = va_arg(ap, mrb_value*);
*p = *sp;
i++; sp++;
}
break;
- case 'i':
+ case 'S':
{
- mrb_int *p;
+ mrb_value *p;
- p = va_arg(ap, mrb_int*);
- switch (sp->tt) {
- case MRB_TT_FIXNUM:
- *p = mrb_fixnum(*sp);
- break;
- case MRB_TT_FLOAT:
- *p = (mrb_int)mrb_float(*sp);
- break;
- case MRB_TT_FALSE:
- *p = 0;
- break;
- default:
- {
- mrb_value tmp;
+ p = va_arg(ap, mrb_value*);
+ *p = to_str(mrb, *sp);
+ i++; sp++;
+ }
+ break;
+ case 'A':
+ {
+ mrb_value *p;
- tmp = mrb_convert_type(mrb, *sp, MRB_TT_FIXNUM, "Integer", "to_int");
- *p = mrb_fixnum(tmp);
- }
- break;
- }
+ p = va_arg(ap, mrb_value*);
+ *p = to_ary(mrb, *sp);
+ i++; sp++;
+ }
+ break;
+ case 'H':
+ {
+ mrb_value *p;
+
+ p = va_arg(ap, mrb_value*);
+ *p = to_hash(mrb, *sp);
+ i++; sp++;
+ }
+ break;
+ case 's':
+ {
+ mrb_value ss;
+ struct RString *s;
+ char **ps = 0;
+ int *pl = 0;
+
+ ss = to_str(mrb, *sp);
+ s = mrb_str_ptr(ss);
+ ps = va_arg(ap, char**);
+ *ps = s->buf;
+ pl = va_arg(ap, int*);
+ *pl = s->len;
+ i++; sp++;
+ }
+ break;
+ case 'z':
+ {
+ mrb_value ss;
+ struct RString *s;
+ char **ps;
+
+ ss = to_str(mrb, *sp);
+ s = mrb_str_ptr(ss);
+ if (strlen(s->buf) != s->len) {
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "String contains NUL");
+ }
+ ps = va_arg(ap, char**);
+ *ps = s->buf;
+ i++; sp++;
+ }
+ break;
+ case 'a':
+ {
+ mrb_value aa;
+ struct RArray *a;
+ mrb_value **pb;
+ int *pl;
+
+ aa = to_ary(mrb, *sp);
+ a = mrb_ary_ptr(aa);
+ pb = va_arg(ap, mrb_value**);
+ *pb = a->buf;
+ pl = va_arg(ap, int*);
+ *pl = a->len;
i++; sp++;
}
break;
@@ -409,53 +514,34 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
i++; sp++;
}
break;
- case 's':
+ case 'i':
{
- char **ps = 0;
- size_t *pl = 0;
- struct RString *s;
+ mrb_int *p;
- if (argc > i) {
- s = mrb_str_ptr(*sp);
- ps = va_arg(ap, char**);
- *ps = s->buf;
- pl = va_arg(ap, size_t*);
- *pl = s->len;
+ p = va_arg(ap, mrb_int*);
+ switch (sp->tt) {
+ case MRB_TT_FIXNUM:
+ *p = mrb_fixnum(*sp);
+ break;
+ case MRB_TT_FLOAT:
+ *p = (mrb_int)mrb_float(*sp);
+ break;
+ case MRB_TT_FALSE:
+ *p = 0;
+ break;
+ default:
+ {
+ mrb_value tmp;
+
+ tmp = mrb_convert_type(mrb, *sp, MRB_TT_FIXNUM, "Integer", "to_int");
+ *p = mrb_fixnum(tmp);
+ }
+ break;
}
i++; sp++;
}
break;
- case 'a':
- {
- mrb_value *var;
- var = va_arg(ap, mrb_value*);
- if (argc > i) {
- if (var) {
- memcpy(var, sp, sizeof(mrb_value)*(argc-i));
- }
- //i = mrb->argc;
- }
- else {
- if (var) *var = mrb_ary_new(mrb);
- }
- argcp = va_arg(ap, int*);
- *argcp = argc-i;
- goto last_var;
- }
- break;
- case 'b':
- {
- struct RProc **p;
- mrb_value *bp = mrb->stack + 1;
- p = va_arg(ap, struct RProc**);
- if (mrb->ci->argc > 0) {
- bp += mrb->ci->argc;
- }
- if (mrb_nil_p(*bp)) *p = 0;
- else *p = mrb_proc_ptr(*bp);
- }
- break;
case '&':
{
mrb_value *p, *bp = mrb->stack + 1;
@@ -467,30 +553,34 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
*p = *bp;
}
break;
+ case '|':
+ opt = 1;
+ break;
case '*':
{
mrb_value **var;
+ int *pl;
+
var = va_arg(ap, mrb_value**);
- argcp = va_arg(ap, int*);
+ pl = va_arg(ap, int*);
if (argc > i) {
- *argcp = argc-i;
- if (*argcp > 0) {
- if (var) {
- *var = sp;
- }
- i += *argcp;
+ *pl = argc-i;
+ if (*pl > 0) {
+ *var = sp;
+ i = argc;
}
}
else {
- *argcp = 0;
+ *pl = 0;
*var = NULL;
}
- goto last_var;
}
break;
}
}
-last_var:
+ if (!c && argc > i) {
+ mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
+ }
va_end(ap);
return 0;
}
@@ -679,17 +769,17 @@ mrb_value
mrb_class_new_instance_m(mrb_state *mrb, mrb_value klass)
{
mrb_value *argv;
- struct RProc *b;
+ mrb_value blk;
struct RClass *k = mrb_class_ptr(klass);
struct RClass *c;
int argc;
mrb_value obj;
- mrb_get_args(mrb, "b*", &b, &argv, &argc);
+ mrb_get_args(mrb, "*&", &argv, &argc, &blk);
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, b);
+ mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk);
return obj;
}
@@ -698,18 +788,17 @@ mrb_value
mrb_instance_new(mrb_state *mrb, mrb_value cv)
{
struct RClass *c = mrb_class_ptr(cv);
- struct RProc *b;
struct RObject *o;
enum mrb_vtype ttype = MRB_INSTANCE_TT(c);
- mrb_value obj;
+ mrb_value obj, blk;
mrb_value *argv;
int argc;
if (ttype == 0) ttype = MRB_TT_OBJECT;
o = (struct RObject*)mrb_obj_alloc(mrb, ttype, c);
obj = mrb_obj_value(o);
- mrb_get_args(mrb, "b*", &b, &argv, &argc);
- mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, b);
+ mrb_get_args(mrb, "*&", &argv, &argc, &blk);
+ mrb_funcall_with_block(mrb, obj, "initialize", argc, argv, blk);
return obj;
}
View
6 src/encoding.c
@@ -1028,8 +1028,8 @@ static mrb_value
enc_find(mrb_state *mrb, mrb_value klass)
{
mrb_value enc;
- mrb_get_args(mrb, "o", &enc);
+ mrb_get_args(mrb, "o", &enc);
return mrb_enc_from_encoding(mrb, to_encoding(mrb, enc));
}
@@ -1058,6 +1058,7 @@ enc_compatible_p(mrb_state *mrb, mrb_value klass)
mrb_value str1;
mrb_value str2;
mrb_encoding *enc;
+
mrb_get_args(mrb, "oo", &str1, &str2);
if (!enc_capable(str1)) return mrb_nil_value();
if (!enc_capable(str2)) return mrb_nil_value();
@@ -1081,6 +1082,7 @@ static mrb_value
enc_load(mrb_state *mrb, mrb_value klass)
{
mrb_value str;
+
mrb_get_args(mrb, "o", &str);
return enc_find(mrb, str);
}
@@ -1277,6 +1279,7 @@ static mrb_value
set_default_external(mrb_state *mrb, mrb_value klass)
{
mrb_value encoding;
+
mrb_get_args(mrb, "o", &encoding);
mrb_warning("setting Encoding.default_external");
mrb_enc_set_default_external(mrb, encoding);
@@ -1335,6 +1338,7 @@ static mrb_value
set_default_internal(mrb_state *mrb, mrb_value klass)
{
mrb_value encoding;
+
mrb_get_args(mrb, "o", &encoding);
mrb_warning("setting Encoding.default_internal");
mrb_enc_set_default_internal(mrb, encoding);
View
2  src/error.c
@@ -83,7 +83,6 @@ exc_exception(mrb_state *mrb, mrb_value self)
int argc;
mrb_get_args(mrb, "*", &argv, &argc);
-
if (argc == 0) return self;
if (argc == 1 && mrb_obj_equal(mrb, self, argv[0])) return self;
exc = mrb_obj_clone(mrb, self);
@@ -161,7 +160,6 @@ exc_equal(mrb_state *mrb, mrb_value exc)
mrb_sym id_mesg = mrb_intern(mrb, "mesg");
mrb_get_args(mrb, "o", &obj);
-
if (mrb_obj_equal(mrb, exc, obj)) return mrb_true_value();
if (mrb_obj_class(mrb, exc) != mrb_obj_class(mrb, obj)) {
View
1  src/etc.c
@@ -67,6 +67,7 @@ mrb_lastline_get(mrb_state *mrb)
//return mrb_nil_value();
mrb_value *argv;
int argc;
+
mrb_get_args(mrb, "*", &argv, &argc);
if (argc < 1) {
return mrb_nil_value();
View
14 src/gc.c
@@ -844,9 +844,10 @@ gc_interval_ratio_get(mrb_state *mrb, mrb_value obj)
static mrb_value
gc_interval_ratio_set(mrb_state *mrb, mrb_value obj)
{
- mrb_value ratio;
- mrb_get_args(mrb, "o", &ratio);
- mrb->gc_interval_ratio = mrb_fixnum(mrb_to_int(mrb, ratio));
+ mrb_int ratio;
+
+ mrb_get_args(mrb, "i", &ratio);
+ mrb->gc_interval_ratio = ratio;
return mrb_nil_value();
}
@@ -876,9 +877,10 @@ gc_step_ratio_get(mrb_state *mrb, mrb_value obj)
static mrb_value
gc_step_ratio_set(mrb_state *mrb, mrb_value obj)
{
- mrb_value ratio;
- mrb_get_args(mrb, "o", &ratio);
- mrb->gc_step_ratio = mrb_fixnum(mrb_to_int(mrb, ratio));
+ mrb_int ratio;
+
+ mrb_get_args(mrb, "i", &ratio);
+ mrb->gc_step_ratio = ratio;
return mrb_nil_value();
}
View
11 src/hash.c
@@ -283,7 +283,6 @@ mrb_hash_init_core(mrb_state *mrb, mrb_value hash)
int argc;
mrb_get_args(mrb, "o*", &block, &argv, &argc);
-
mrb_hash_modify(mrb, hash);
if (mrb_nil_p(block)) {
if (argc > 0) {
@@ -434,7 +433,6 @@ mrb_hash_default(mrb_state *mrb, mrb_value hash)
mrb_value key;
mrb_get_args(mrb, "*", &argv, &argc);
-
if (MRB_RHASH_PROCDEFAULT_P(hash)) {
if (argc == 0) return mrb_nil_value();
key = argv[0];
@@ -470,8 +468,8 @@ static mrb_value
mrb_hash_set_default(mrb_state *mrb, mrb_value hash)
{
mrb_value ifnone;
- mrb_get_args(mrb, "o", &ifnone);
+ mrb_get_args(mrb, "o", &ifnone);
mrb_hash_modify(mrb, hash);
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone"), ifnone);
RHASH(hash)->flags &= ~(MRB_HASH_PROC_DEFAULT);
@@ -521,8 +519,8 @@ static mrb_value
mrb_hash_set_default_proc(mrb_state *mrb, mrb_value hash)
{
mrb_value ifnone;
- mrb_get_args(mrb, "o", &ifnone);
+ mrb_get_args(mrb, "o", &ifnone);
mrb_hash_modify(mrb, hash);
mrb_iv_set(mrb, hash, mrb_intern(mrb, "ifnone"), ifnone);
RHASH(hash)->flags |= MRB_HASH_PROC_DEFAULT;
@@ -789,7 +787,6 @@ mrb_hash_replace(mrb_state *mrb, mrb_value hash)
khiter_t k;
mrb_get_args(mrb, "o", &hash2);
-
mrb_hash_modify_check(mrb, hash);
hash2 = to_hash(mrb, hash2);
if (mrb_obj_equal(mrb, hash, hash2)) return hash;
@@ -1207,6 +1204,7 @@ static mrb_value
mrb_hash_equal(mrb_state *mrb, mrb_value hash1)
{
mrb_value hash2;
+
mrb_get_args(mrb, "o", &hash2);
return hash_equal(mrb, hash1, hash2, FALSE);
}
@@ -1224,6 +1222,7 @@ static mrb_value
mrb_hash_eql(mrb_state *mrb, mrb_value hash1)
{
mrb_value hash2;
+
mrb_get_args(mrb, "o", &hash2);
return hash_equal(mrb, hash1, hash2, TRUE);
}
@@ -1292,7 +1291,6 @@ mrb_hash_assoc(mrb_state *mrb, mrb_value hash)
mrb_value key, value, has_key;
mrb_get_args(mrb, "o", &key);
-
if (mrb_nil_p(key))
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
@@ -1325,7 +1323,6 @@ mrb_hash_rassoc(mrb_state *mrb, mrb_value hash)
mrb_value key, value, has_key;
mrb_get_args(mrb, "o", &key);
-
if (mrb_nil_p(key))
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
View
2  src/kernel.c
@@ -958,10 +958,10 @@ class_instance_method_list(mrb_state *mrb, int argc, mrb_value *argv, struct RCl
}
else {
mrb_value r;
+
mrb_get_args(mrb, "o", &r);
recur = mrb_test(r);
}
-
ary = mrb_ary_new(mrb);
oldklass = 0;
while (klass && (klass != oldklass)) {
View
2  src/keywords
@@ -31,7 +31,7 @@ in, {keyword_in, keyword_in}, EXPR_VALUE
module, {keyword_module, keyword_module}, EXPR_VALUE
next, {keyword_next, keyword_next}, EXPR_MID
nil, {keyword_nil, keyword_nil}, EXPR_END
-not, {keyword_not, keyword_not}, EXPR_VALUE
+not, {keyword_not, keyword_not}, EXPR_ARG
or, {keyword_or, keyword_or}, EXPR_VALUE
redo, {keyword_redo, keyword_redo}, EXPR_END
rescue, {keyword_rescue, modifier_rescue}, EXPR_MID
View
90 src/lex.def
@@ -1,5 +1,5 @@
/* ANSI-C code produced by gperf version 3.0.3 */
-/* Command-line: gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$' keywords */
+/* Command-line: gperf -L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k'1,3,$' ./keywords */
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
@@ -28,13 +28,13 @@
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
#endif
-#line 1 "keywords"
+#line 1 "./keywords"
struct kwtable {const char *name; int id[2]; enum mrb_lex_state_enum state;};
const struct kwtable *mrb_reserved_word(const char *, unsigned int);
static const struct kwtable *reserved_word(const char *, unsigned int);
#define mrb_reserved_word(str, len) reserved_word(str, len)
-#line 8 "keywords"
+#line 8 "./keywords"
struct kwtable;
#define TOTAL_KEYWORDS 40
@@ -110,87 +110,87 @@ mrb_reserved_word (register const char *str, register unsigned int len)
static const struct kwtable wordlist[] =
{
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
-#line 18 "keywords"
+#line 18 "./keywords"
{"break", {keyword_break, keyword_break}, EXPR_MID},
-#line 23 "keywords"
+#line 23 "./keywords"
{"else", {keyword_else, keyword_else}, EXPR_BEG},
-#line 33 "keywords"
+#line 33 "./keywords"
{"nil", {keyword_nil, keyword_nil}, EXPR_END},
-#line 26 "keywords"
+#line 26 "./keywords"
{"ensure", {keyword_ensure, keyword_ensure}, EXPR_BEG},
-#line 25 "keywords"
+#line 25 "./keywords"
{"end", {keyword_end, keyword_end}, EXPR_END},
-#line 42 "keywords"
+#line 42 "./keywords"
{"then", {keyword_then, keyword_then}, EXPR_BEG},
-#line 34 "keywords"
- {"not", {keyword_not, keyword_not}, EXPR_VALUE},
-#line 27 "keywords"
+#line 34 "./keywords"
+ {"not", {keyword_not, keyword_not}, EXPR_ARG},
+#line 27 "./keywords"
{"false", {keyword_false, keyword_false}, EXPR_END},
-#line 40 "keywords"
+#line 40 "./keywords"
{"self", {keyword_self, keyword_self}, EXPR_END},
-#line 24 "keywords"
+#line 24 "./keywords"
{"elsif", {keyword_elsif, keyword_elsif}, EXPR_VALUE},
-#line 37 "keywords"
+#line 37 "./keywords"
{"rescue", {keyword_rescue, modifier_rescue}, EXPR_MID},
-#line 43 "keywords"
+#line 43 "./keywords"
{"true", {keyword_true, keyword_true}, EXPR_END},
-#line 46 "keywords"
+#line 46 "./keywords"
{"until", {keyword_until, modifier_until}, EXPR_VALUE},
-#line 45 "keywords"
+#line 45 "./keywords"
{"unless", {keyword_unless, modifier_unless}, EXPR_VALUE},
-#line 39 "keywords"
+#line 39 "./keywords"
{"return", {keyword_return, keyword_return}, EXPR_MID},
-#line 21 "keywords"
+#line 21 "./keywords"
{"def", {keyword_def, keyword_def}, EXPR_FNAME},
-#line 16 "keywords"
+#line 16 "./keywords"
{"and", {keyword_and, keyword_and}, EXPR_VALUE},
-#line 22 "keywords"
+#line 22 "./keywords"
{"do", {keyword_do, keyword_do}, EXPR_BEG},
-#line 49 "keywords"
+#line 49 "./keywords"
{"yield", {keyword_yield, keyword_yield}, EXPR_ARG},
-#line 28 "keywords"
+#line 28 "./keywords"
{"for", {keyword_for, keyword_for}, EXPR_VALUE},
-#line 44 "keywords"
+#line 44 "./keywords"
{"undef", {keyword_undef, keyword_undef}, EXPR_FNAME},
-#line 35 "keywords"
+#line 35 "./keywords"
{"or", {keyword_or, keyword_or}, EXPR_VALUE},
-#line 30 "keywords"
+#line 30 "./keywords"
{"in", {keyword_in, keyword_in}, EXPR_VALUE},
-#line 47 "keywords"
+#line 47 "./keywords"
{"when", {keyword_when, keyword_when}, EXPR_VALUE},
-#line 38 "keywords"
+#line 38 "./keywords"
{"retry", {keyword_retry, keyword_retry}, EXPR_END},
-#line 29 "keywords"
+#line 29 "./keywords"
{"if", {keyword_if, modifier_if}, EXPR_VALUE},
-#line 19 "keywords"
+#line 19 "./keywords"
{"case", {keyword_case, keyword_case}, EXPR_VALUE},
-#line 36 "keywords"
+#line 36 "./keywords"
{"redo", {keyword_redo, keyword_redo}, EXPR_END},
-#line 32 "keywords"
+#line 32 "./keywords"
{"next", {keyword_next, keyword_next}, EXPR_MID},
-#line 41 "keywords"
+#line 41 "./keywords"
{"super", {keyword_super, keyword_super}, EXPR_ARG},
-#line 31 "keywords"
+#line 31 "./keywords"
{"module", {keyword_module, keyword_module}, EXPR_VALUE},
-#line 17 "keywords"
+#line 17 "./keywords"
{"begin", {keyword_begin, keyword_begin}, EXPR_BEG},
-#line 11 "keywords"
+#line 11 "./keywords"
{"__LINE__", {keyword__LINE__, keyword__LINE__}, EXPR_END},
-#line 12 "keywords"
+#line 12 "./keywords"
{"__FILE__", {keyword__FILE__, keyword__FILE__}, EXPR_END},
-#line 10 "keywords"
+#line 10 "./keywords"
{"__ENCODING__", {keyword__ENCODING__, keyword__ENCODING__}, EXPR_END},
-#line 14 "keywords"
+#line 14 "./keywords"
{"END", {keyword_END, keyword_END}, EXPR_END},
-#line 15 "keywords"
+#line 15 "./keywords"
{"alias", {keyword_alias, keyword_alias}, EXPR_FNAME},
-#line 13 "keywords"
+#line 13 "./keywords"
{"BEGIN", {keyword_BEGIN, keyword_BEGIN}, EXPR_END},
{""},
-#line 20 "keywords"
+#line 20 "./keywords"
{"class", {keyword_class, keyword_class}, EXPR_CLASS},
{""}, {""},
-#line 48 "keywords"
+#line 48 "./keywords"
{"while", {keyword_while, modifier_while}, EXPR_VALUE}
};
@@ -208,5 +208,5 @@ mrb_reserved_word (register const char *str, register unsigned int len)
}
return 0;
}
-#line 50 "keywords"
+#line 50 "./keywords"
View
7 src/numeric.c
@@ -306,6 +306,7 @@ static mrb_value
num_eql(mrb_state *mrb, mrb_value x)
{
mrb_value y;
+
mrb_get_args(mrb, "o", &y);
if (mrb_type(x) != mrb_type(y)) return mrb_false_value();
if (mrb_equal(mrb, x, y)) {
@@ -942,8 +943,8 @@ fix_xor(mrb_state *mrb, mrb_value x)
{
mrb_value y;
mrb_int val;
- mrb_get_args(mrb, "o", &y);
+ mrb_get_args(mrb, "o", &y);
y = bit_coerce(mrb, y);
val = mrb_fixnum(x) ^ mrb_fixnum(y);
return mrb_fixnum_value(val);
@@ -965,8 +966,8 @@ mrb_fix_lshift(mrb_state *mrb, mrb_value x)
{
mrb_value y;
mrb_int val, width;
- mrb_get_args(mrb, "o", &y);
+ mrb_get_args(mrb, "o", &y);
val = mrb_fixnum(x);
y = bit_coerce(mrb, y);
width = mrb_fixnum(y);
@@ -1000,8 +1001,8 @@ mrb_fix_rshift(mrb_state *mrb, mrb_value x)
{
mrb_value y;
mrb_int i, val;
- mrb_get_args(mrb, "o", &y);
+ mrb_get_args(mrb, "o", &y);
val = mrb_fixnum(x);
y = bit_coerce(mrb, y);
i = mrb_fixnum(y);
View
5 src/parse.y
@@ -1869,6 +1869,10 @@ primary : literal
{
$$ = $2;
}
+ | tLPAREN_ARG {p->lstate = EXPR_ENDARG;} rparen
+ {
+ $$ = 0;
+ }
| tLPAREN compstmt ')'
{
$$ = $2;
@@ -4198,7 +4202,6 @@ parser_yylex(parser_state *p)
}
else if (IS_SPCARG(-1)) {
c = tLPAREN_ARG;
- yywarning(p, "(...) interpreted as grouped expression");
}
p->paren_nest++;
COND_PUSH(0);
View
17 src/range.c
@@ -433,8 +433,8 @@ static mrb_value
range_eql(mrb_state *mrb, mrb_value range)
{
mrb_value obj;
- mrb_get_args(mrb, "o", &obj);
+ mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, range, obj))
return mrb_true_value();
if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS))
@@ -447,16 +447,17 @@ mrb_value
range_initialize_copy(mrb_state *mrb, mrb_value copy)
{
mrb_value src;
+
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");
- }
- memcpy(mrb_range_ptr(copy), mrb_range_ptr(src), sizeof(struct RRange));
+ 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");
+ }
+ memcpy(mrb_range_ptr(copy), mrb_range_ptr(src), sizeof(struct RRange));
- return copy;
+ return copy;
}
void
View
4 src/re.c
@@ -229,6 +229,7 @@ static mrb_value
mrb_reg_s_quote(mrb_state *mrb, mrb_value c/*, mrb_value str*/)
{
mrb_value str;
+
mrb_get_args(mrb, "o", &str);
return mrb_reg_quote(mrb, reg_operand(mrb, str, 1/*TRUE*/));
}
@@ -1520,6 +1521,7 @@ mrb_value
mrb_reg_match(mrb_state *mrb, mrb_value re/*, mrb_value str*/)
{
mrb_value str;
+
mrb_get_args(mrb, "o", &str);
return mrb_reg_match_str(mrb, re, str);
}
@@ -1582,7 +1584,7 @@ mrb_reg_match_m(mrb_state *mrb, /*int argc, mrb_value *argv,*/ mrb_value re)
long pos;
//if (mrb_scan_args(argc, argv, "11", &str, &initpos) == 2) {
- mrb_get_args(mrb, "&*", &b, &argv, &argc);
+ mrb_get_args(mrb, "*&", &argv, &argc, &b);
if (argc == 2) {
initpos = argv[1];
pos = mrb_fixnum(initpos);
View
11 src/string.c
@@ -1101,6 +1101,7 @@ static mrb_value
mrb_str_match(mrb_state *mrb, mrb_value self/* x */)
{
mrb_value y;
+
mrb_get_args(mrb, "o", &y);
switch (mrb_type(y)) {
case MRB_TT_STRING:
@@ -2048,7 +2049,7 @@ mrb_str_each_line(mrb_state *mrb, mrb_value str)
int argc;
//if (mrb_scan_args(argc, argv, "01", &rs) == 0) {
- mrb_get_args(mrb, "&*", &b, &argv, &argc);
+ mrb_get_args(mrb, "*&", &argv, &argc, &b);
if (argc > 0) {
rs = argv[0];
} else {
@@ -2632,8 +2633,8 @@ mrb_str_include(mrb_state *mrb, mrb_value self)
{
mrb_int i;
mrb_value str2;
- mrb_get_args(mrb, "o", &str2);
+ mrb_get_args(mrb, "o", &str2);
if (mrb_type(str2) == MRB_TT_FIXNUM) {
if (memchr(RSTRING_PTR(self), mrb_fixnum(str2), RSTRING_LEN(self)))
return mrb_true_value();
@@ -2955,7 +2956,8 @@ mrb_str_match_m(mrb_state *mrb, mrb_value self)
mrb_value *argv;
int argc;
mrb_value re, result, b;
- mrb_get_args(mrb, "&*", &b, &argv, &argc);
+
+ mrb_get_args(mrb, "*&", &argv, &argc, &b);
if (argc < 1)
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments (%d for 1..2)", argc);
re = argv[0];
@@ -3336,7 +3338,7 @@ mrb_str_scan(mrb_state *mrb, mrb_value str)
char *p = ps->buf;
long len = ps->len;
- mrb_get_args(mrb, "&o", &b, &pat);
+ mrb_get_args(mrb, "o&", &pat, &b);
pat = get_pat(mrb, pat, 1);
if (!mrb_block_given_p()) {
mrb_value ary = mrb_ary_new(mrb);
@@ -4292,6 +4294,7 @@ static mrb_value
mrb_str_force_encoding(mrb_state *mrb, mrb_value self)
{
mrb_value enc;
+
mrb_get_args(mrb, "o", &enc);
str_modifiable(self);
mrb_enc_associate(mrb, self, mrb_to_encoding(mrb, enc));
View
52 src/struct.c
@@ -533,19 +533,20 @@ mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{
mrb_value s;
+
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");
- }
- if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
- mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
- }
- memcpy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), sizeof(mrb_value)*RSTRUCT_LEN(copy));
+ 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");
+ }
+ if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
+ mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
+ }
+ memcpy(RSTRUCT_PTR(copy), RSTRUCT_PTR(s), sizeof(mrb_value)*RSTRUCT_LEN(copy));
- return copy;
+ return copy;
}
static mrb_value
@@ -668,24 +669,25 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
long i;
mrb_value idx;
mrb_value val;
+
mrb_get_args(mrb, "oo", &idx, &val);
- if (mrb_type(idx) == MRB_TT_STRING || mrb_type(idx) == MRB_TT_SYMBOL) {
- return mrb_struct_aset_id(mrb, s, mrb_to_id(mrb, idx), val);
- }
+ if (mrb_type(idx) == MRB_TT_STRING || mrb_type(idx) == MRB_TT_SYMBOL) {
+ return mrb_struct_aset_id(mrb, s, mrb_to_id(mrb, idx), val);
+ }
- i = mrb_fixnum(idx);
- if (i < 0) i = RSTRUCT_LEN(s) + i;
- if (i < 0) {
- mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too small for struct(size:%ld)",
- i, RSTRUCT_LEN(s));
- }
- if (RSTRUCT_LEN(s) <= i) {
- mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too large for struct(size:%ld)",
- i, RSTRUCT_LEN(s));
- }
- mrb_struct_modify(s);
- return RSTRUCT_PTR(s)[i] = val;
+ i = mrb_fixnum(idx);
+ if (i < 0) i = RSTRUCT_LEN(s) + i;
+ if (i < 0) {
+ mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too small for struct(size:%ld)",
+ i, RSTRUCT_LEN(s));
+ }
+ if (RSTRUCT_LEN(s) <= i) {
+ mrb_raise(mrb, E_INDEX_ERROR, "offset %ld too large for struct(size:%ld)",
+ i, RSTRUCT_LEN(s));
+ }
+ mrb_struct_modify(s);
+ return RSTRUCT_PTR(s)[i] = val;
}
static mrb_value
View
7 src/time.c
@@ -268,7 +268,7 @@ mrb_time_gm(mrb_state *mrb, mrb_value self)
{
mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0;
- mrb_get_args(mrb, "iiiiiii",
+ mrb_get_args(mrb, "i|iiiiii",
&ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
return mrb_time_wrap(mrb, mrb_class_ptr(self),
time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_UTC));
@@ -282,7 +282,7 @@ mrb_time_local(mrb_state *mrb, mrb_value self)
{
mrb_int ayear = 0, amonth = 1, aday = 1, ahour = 0, amin = 0, asec = 0, ausec = 0;
- mrb_get_args(mrb, "iiiiiii",
+ mrb_get_args(mrb, "i|iiiiii",
&ayear, &amonth, &aday, &ahour, &amin, &asec, &ausec);
return mrb_time_wrap(mrb, mrb_class_ptr(self),
time_mktime(mrb, ayear, amonth, aday, ahour, amin, asec, ausec, MRB_TIMEZONE_LOCAL));
@@ -352,7 +352,6 @@ mrb_time_minus(mrb_state *mrb, mrb_value self)
struct mrb_time *tm;
mrb_get_args(mrb, "f", &f);
-
tm = mrb_get_datatype(mrb, self, &mrb_time_type);
if(!tm) return mrb_nil_value();
f -= tm->sec;
@@ -499,8 +498,8 @@ static mrb_value
mrb_time_initialize_copy(mrb_state *mrb, mrb_value copy)
{
mrb_value src;
- mrb_get_args(mrb, "o", &src);
+ mrb_get_args(mrb, "o", &src);
if (mrb_obj_equal(mrb, copy, src)) return copy;
if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) {
mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class");
View
11 src/vm.c
@@ -160,7 +160,7 @@ 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, struct RProc *blk)
+mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int argc, mrb_value *argv, mrb_value blk)
{
struct RProc *p;
struct RClass *c;
@@ -197,12 +197,7 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, const char *name, int arg
else if (argc > 0) {
memcpy(mrb->stack+1, argv, sizeof(mrb_value)*argc);
}
- if (!blk) {
- mrb->stack[argc+1] = mrb_nil_value();
- }
- else {
- mrb->stack[argc+1] = mrb_obj_value(blk);
- }
+ mrb->stack[argc+1] = blk;
if (MRB_PROC_CFUNC_P(p)) {
val = p->body.func(mrb, self);
@@ -218,7 +213,7 @@ 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)
{
- return mrb_funcall_with_block(mrb, self, name, argc, argv, 0);
+ return mrb_funcall_with_block(mrb, self, name, argc, argv, mrb_nil_value());
}
mrb_value
View
8 test/t/array.rb
@@ -83,7 +83,7 @@
assert('Array#index', '15.2.12.5.14') do
a = [1,2,3]
- a.index(2) == 1
+ a.index(2) == 1
end
assert('Array#initialize', '15.2.12.5.15') do
@@ -99,7 +99,7 @@
a = [1,2,3]
b = [].initialize_copy(a)
- b == [1,2,3]
+ b == [1,2,3]
end
assert('Array#join', '15.2.12.5.17') do
@@ -165,7 +165,7 @@
assert('Array#rindex', '15.2.12.5.26') do
a = [1,2,3]
- a.rindex(2) == 1
+ a.rindex(2) == 1
end
assert('Array#shift', '15.2.12.5.27') do
@@ -178,7 +178,7 @@
assert('Array#size', '15.2.12.5.28') do
a = [1,2,3]
- a.size == 3
+ a.size == 3
end
assert('Array#slice', '15.2.12.5.29') do
View
14 test/t/float.rb
@@ -9,7 +9,7 @@
a = 3.123456788 + 0.000000001
b = 3.123456789 + 1
- check_float(a, 3.123456789) and
+ check_float(a, 3.123456789) and
check_float(b, 4.123456789)
end
@@ -17,8 +17,8 @@
a = 3.123456790 - 0.000000001
b = 5.123456789 - 1
- check_float(a, 3.123456789) and
- check_float(b, 4.123456789)
+ check_float(a, 3.123456789) and
+ check_float(b, 4.123456789)
end
assert('Float#*', '15.2.9.3.3') do
@@ -47,17 +47,17 @@
assert('Float#<=>', '15.2.9.3.6') do
a = 3.123456789 <=> 3.123456788
- b = 3.123456789 <=> 3.123456789
+ b = 3.123456789 <=> 3.123456789
c = 3.123456789 <=> 3.123456790
a2 = 3.123456789 <=> 3
c2 = 3.123456789 <=> 4
-
+
a == 1 and b == 0 and c == -1 and
a2 == 1 and c2 == -1
end
assert('Float#==', '15.2.9.3.7') do
- 3.1 == 3.1 and not (3.1 == 3.2)
+ 3.1 == 3.1 and not 3.1 == 3.2
end
assert('Float#ceil', '15.2.9.3.8') do
@@ -74,7 +74,7 @@
end
assert('Float#infinite?', '15.2.9.3.11') do
- not 3.123456789.infinite? and
+ not 3.123456789.infinite? and
(1.0 / 0.0).infinite?
end
View
8 test/t/hash.rb
@@ -169,17 +169,17 @@
end
assert('Hash#merge', '15.2.13.4.22') do
- a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
- b = { 'cba_key' => 'XXX', 'xyz_key' => 'xyz_value' }
+ a = { 'abc_key' => 'abc_value', 'cba_key' => 'cba_value' }
+ b = { 'cba_key' => 'XXX', 'xyz_key' => 'xyz_value' }
result_1 = a.merge b
result_2 = a.merge(b) do |key, original, new|
original
end
- result_1 == {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
+ result_1 == {'abc_key' => 'abc_value', 'cba_key' => 'XXX',
'xyz_key' => 'xyz_value' } and
- result_2 == {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
+ result_2 == {'abc_key' => 'abc_value', 'cba_key' => 'cba_value',
'xyz_key' => 'xyz_value' }
end
View
2  test/t/integer.rb
@@ -108,7 +108,7 @@
3.downto(1) do |i|
a += i
end
- a == 6
+ a == 6
end
assert('Integer#eql?', '15.2.8.3.16') do
View
4 test/t/math.rb
@@ -10,7 +10,7 @@
end
-assert('Fundamental trig identities') do
+assert('Fundamental trig identities') do
result = true
N = 15
N.times do |i|
@@ -26,7 +26,7 @@
result &= check_float((1/t) ** 2 + 1, (1/s) ** 2)
end
result
-end
+end
assert('Math.erf 0') do
check_float(Math.erf(0), 0)
View
4 test/t/string.rb
@@ -115,7 +115,7 @@
assert('String#chop!', '15.2.10.5.12') do
a = ''
b = 'abc'
-
+
a.chop!
b.chop!
@@ -147,7 +147,7 @@
a.each_line do |line|
n_list << line
end
-
+
list == n_list
end
View
3  tools/mirb/mirb.c
@@ -162,7 +162,8 @@ main(void)
last_code_line[char_index] = '\0';
- if (strcmp(last_code_line, "quit") == 0) {
+ if ((strcmp(last_code_line, "quit") == 0) ||
+ (strcmp(last_code_line, "exit") == 0)) {
if (code_block_open) {
/* cancel the current block and reset */
code_block_open = FALSE;

No commit comments for this range

Something went wrong with that request. Please try again.