summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDaniel Bovensiepen <[email protected]>2012-09-19 09:36:35 +0900
committerDaniel Bovensiepen <[email protected]>2012-09-19 09:36:35 +0900
commitc0ff4fed3b721ae5892f3644e57b51551a612c0d (patch)
tree272807d44ec0025a2f64ef79301f3131630f4642
parent17c877011d2ecaba8a904f1b5b87a4aa2f5a82bb (diff)
parent1afda93c7ae70d85e713a2a44e9c32dd604f1a5a (diff)
downloadmruby-c0ff4fed3b721ae5892f3644e57b51551a612c0d.tar.gz
mruby-c0ff4fed3b721ae5892f3644e57b51551a612c0d.zip
Merge remote-tracking branch 'upstream/master' into mrbgems
-rw-r--r--CONTRIBUTING.md (renamed from doc/coding_conventions.md)33
-rw-r--r--cmake/Toolchain-OSX-GenericShElf.cmake.sample37
-rw-r--r--include/mrbconf.h3
-rw-r--r--mrblib/numeric.rb17
-rw-r--r--src/codegen.c57
-rw-r--r--src/parse.y127
-rw-r--r--src/string.c5
-rw-r--r--test/t/integer.rb16
-rw-r--r--test/t/kernel.rb2
9 files changed, 192 insertions, 105 deletions
diff --git a/doc/coding_conventions.md b/CONTRIBUTING.md
index aa47fe980..08995978f 100644
--- a/doc/coding_conventions.md
+++ b/CONTRIBUTING.md
@@ -1,14 +1,31 @@
-# Coding conventions
+# How to contribute
+
+mruby is an open-source project which is looking forward to each contribution.
+
+## Your Pull Request
+
+To make it easy to review and understand your change please keep the following
+things in mind before submitting your pull request:
+
+* Work on the latest possible state of **mruby/master**
+* Test your changes before creating a pull request (**make test**)
+* If possible write a test case which confirms your change
+* Don't mix several features or bug-fixes in one pull request
+* Create a branch which is dedicated to your change
+* Create a meaningful commit message
+* Explain your change (i.e. with a link to the issue you are fixing)
+
+## Coding conventions
How to style your C and Ruby code which you want to submit.
-## C code
+### C code
The core part (parser, bytecode-interpreter, core-lib, etc.) of mruby is
written in the C programming language. Please note the following hints for your
C code:
-### Comply with C99 (ISO/IEC 9899:1999)
+#### Comply with C99 (ISO/IEC 9899:1999)
mruby should be highly portable to other systems and compilers. For that it is
recommended to keep your code as close as possible to the C99 standard
@@ -17,19 +34,19 @@ recommended to keep your code as close as possible to the C99 standard
Although we target C99, VC is also an important target for mruby, so that we
avoid local variable declaration in the middle.
-### Reduce library dependencies to a minimum
+#### Reduce library dependencies to a minimum
The dependencies to libraries should be put to an absolute minimum. This
increases the portability but makes it also easier to cut away parts of mruby
on-demand.
-### Don't use C++ style comments
+#### Don't use C++ style comments
/* This is the prefered comment style */
Use C++ style comments only for temporary comment e.g. commenting out some code lines.
-### Insert a break after the method return value:
+#### Insert a break after the method return value:
int
main(void)
@@ -37,12 +54,12 @@ Use C++ style comments only for temporary comment e.g. commenting out some code
...
}
-## Ruby code
+### Ruby code
Parts of the standard library of mruby is written in the Ruby programming language
itself. Please note the following hints for your Ruby code:
-### Comply with the Ruby standard (ISO/IEC 30170:2012)
+#### Comply with the Ruby standard (ISO/IEC 30170:2012)
mruby is currently targeting to execute Ruby code which complies to ISO/IEC
30170:2012 (http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=59579).
diff --git a/cmake/Toolchain-OSX-GenericShElf.cmake.sample b/cmake/Toolchain-OSX-GenericShElf.cmake.sample
new file mode 100644
index 000000000..1f847830a
--- /dev/null
+++ b/cmake/Toolchain-OSX-GenericShElf.cmake.sample
@@ -0,0 +1,37 @@
+#
+# Typical usage:
+# 0) install cmake version 2.8-9 or higher.
+# 1) install a PizzaFactory cross compiler
+# a) darwin toolchain targeting sh-elf: http://sourceforge.jp/projects/pf3gnuchains/downloads/50061/sh-pizzafactory-elf.pkg/
+# b) install pkg.
+# c) export PATH=$PATH:/pizza/bin
+# 2) cp cmake/Toolchain-OSX-GenericShElf.cmake.sample ~/Toolchain-OSX-GenericShElf.cmake
+# 3) tweak toolchain values as needed
+# 4) cd build
+# 5) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-OSX-GenericShElf.cmake ..
+# 6) Run mirb on gdb
+# a) sh-pizzafactory-elf-gdb tools/mirb/mirb
+# b) target sim
+# c) load
+# d) run
+
+# name of the target OS on which the built artifacts will run
+# and the toolchain prefix
+set(CMAKE_SYSTEM_NAME Generic)
+set(TOOLCHAIN_PREFIX sh-pizzafactory-elf)
+
+# cross compilers to use for C and C++
+set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
+set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
+
+# target environment(s) on the build host system
+# set 1st to dir with the cross compiler's C/C++ headers/libs
+# set 2nd to dir containing personal cross development headers/libs
+set(CMAKE_FIND_ROOT_PATH /pizza/${TOOLCHAIN_PREFIX})
+
+# modify default behavior of FIND_XXX() commands to
+# search for headers/libs in the target environment and
+# search for programs in the build host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/include/mrbconf.h b/include/mrbconf.h
index b4332adcd..d7ccb261d 100644
--- a/include/mrbconf.h
+++ b/include/mrbconf.h
@@ -62,11 +62,10 @@ typedef double mrb_float;
#ifdef MRB_NAN_BOXING
typedef int32_t mrb_int;
-typedef int32_t mrb_sym;
#else
typedef int mrb_int;
-typedef intptr_t mrb_sym;
#endif
+typedef short mrb_sym;
/* define ENABLE_XXXX from DISABLE_XXX */
#ifndef DISABLE_REGEXP
diff --git a/mrblib/numeric.rb b/mrblib/numeric.rb
index 9f65d5633..1d701b1fc 100644
--- a/mrblib/numeric.rb
+++ b/mrblib/numeric.rb
@@ -1,6 +1,6 @@
##
# Integer
-#
+#
# ISO 15.2.8
class Integer
@@ -10,7 +10,6 @@ class Integer
#
# ISO 15.2.8.3.15
def downto(num, &block)
- raise TypeError, "expected Integer" unless num.kind_of? Integer
i = self
while(i >= num)
block.call(i)
@@ -38,7 +37,6 @@ class Integer
#
# ISO 15.2.8.3.27
def upto(num, &block)
- raise TypeError, "expected Integer" unless num.kind_of? Integer
i = self
while(i <= num)
block.call(i)
@@ -46,6 +44,19 @@ class Integer
end
self
end
+
+ ##
+ # Calls the given block from +self+ to +num+
+ # incremented by +step+ (default 1).
+ #
+ def step(num, step=1, &block)
+ i = if num.kind_of? Float then self.to_f else self end
+ while(i <= num)
+ block.call(i)
+ i += step
+ end
+ self
+ end
end
##
diff --git a/src/codegen.c b/src/codegen.c
index 799ec1500..50d3e3d3b 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -466,7 +466,8 @@ node_len(node *tree)
return n;
}
-#define lv_name(lv) ((mrb_sym)(lv)->car)
+#define sym(x) ((mrb_sym)(intptr_t)(x))
+#define lv_name(lv) sym((lv)->car)
static int
lv_idx(codegen_scope *s, mrb_sym id)
{
@@ -582,7 +583,7 @@ lambda_body(codegen_scope *s, node *tree, int blk)
dispatch(s, pos+i);
codegen(s, opt->car->cdr, VAL);
- idx = lv_idx(s, (mrb_sym)opt->car->car);
+ idx = lv_idx(s, (mrb_sym)(intptr_t)opt->car->car);
pop();
genop_peep(s, MKOP_AB(OP_MOVE, idx, cursp()), NOVAL);
i++;
@@ -706,7 +707,7 @@ gen_values(codegen_scope *s, node *t)
static void
gen_call(codegen_scope *s, node *tree, mrb_sym name, int sp, int val)
{
- mrb_sym sym = name ? name : (mrb_sym)tree->cdr->car;
+ mrb_sym sym = name ? name : sym(tree->cdr->car);
int idx;
int n = 0, noop = 0, sendv = 0, blk = 0;
@@ -796,11 +797,11 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val)
node = node->cdr;
switch ((intptr_t)type) {
case NODE_GVAR:
- idx = new_sym(s, (mrb_sym)node);
+ idx = new_sym(s, sym(node));
genop_peep(s, MKOP_ABx(OP_SETGLOBAL, sp, idx), val);
break;
case NODE_LVAR:
- idx = lv_idx(s, (mrb_sym)node);
+ idx = lv_idx(s, sym(node));
if (idx > 0) {
if (idx != sp) {
genop_peep(s, MKOP_AB(OP_MOVE, idx, sp), val);
@@ -812,7 +813,7 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val)
codegen_scope *up = s->prev;
while (up) {
- idx = lv_idx(up, (mrb_sym)node);
+ idx = lv_idx(up, sym(node));
if (idx > 0) {
genop_peep(s, MKOP_ABC(OP_SETUPVAR, sp, idx, lv), val);
break;
@@ -824,19 +825,19 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val)
}
break;
case NODE_IVAR:
- idx = new_sym(s, (mrb_sym)node);
+ idx = new_sym(s, sym(node));
genop_peep(s, MKOP_ABx(OP_SETIV, sp, idx), val);
break;
case NODE_CVAR:
- idx = new_sym(s, (mrb_sym)node);
+ idx = new_sym(s, sym(node));
genop_peep(s, MKOP_ABx(OP_SETCV, sp, idx), val);
break;
case NODE_CONST:
- idx = new_sym(s, (mrb_sym)node);
+ idx = new_sym(s, sym(node));
genop_peep(s, MKOP_ABx(OP_SETCONST, sp, idx), val);
break;
case NODE_COLON2:
- idx = new_sym(s, (mrb_sym)node->cdr);
+ idx = new_sym(s, sym(node->cdr));
genop_peep(s, MKOP_AB(OP_MOVE, cursp(), sp), NOVAL);
push();
codegen(s, node->car, VAL);
@@ -846,7 +847,7 @@ gen_assignment(codegen_scope *s, node *node, int sp, int val)
case NODE_CALL:
push();
- gen_call(s, node, attrsym(s, (mrb_sym)node->cdr->car), sp, val);
+ gen_call(s, node, attrsym(s, sym(node->cdr->car)), sp, val);
val = NOVAL; /* push should have done in gen_call() */
break;
@@ -1247,7 +1248,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_COLON2:
{
- int sym = new_sym(s, (mrb_sym)tree->cdr);
+ int sym = new_sym(s, sym(tree->cdr));
codegen(s, tree->car, VAL);
pop();
@@ -1258,7 +1259,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_COLON3:
{
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_A(OP_OCLASS, cursp()));
genop(s, MKOP_ABx(OP_GETMCNST, cursp(), sym));
@@ -1378,7 +1379,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_OP_ASGN:
{
- mrb_sym sym = (mrb_sym)tree->cdr->car;
+ mrb_sym sym = sym(tree->cdr->car);
int len;
const char *name = mrb_sym2name_len(s->mrb, sym, &len);
int idx;
@@ -1592,7 +1593,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_LVAR:
if (val) {
- int idx = lv_idx(s, (mrb_sym)tree);
+ int idx = lv_idx(s, sym(tree));
if (idx > 0) {
genop(s, MKOP_AB(OP_MOVE, cursp(), idx));
@@ -1602,7 +1603,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen_scope *up = s->prev;
while (up) {
- idx = lv_idx(up, (mrb_sym)tree);
+ idx = lv_idx(up, sym(tree));
if (idx > 0) {
genop(s, MKOP_ABC(OP_GETUPVAR, cursp(), idx, lv));
break;
@@ -1617,7 +1618,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_GVAR:
{
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_ABx(OP_GETGLOBAL, cursp(), sym));
push();
@@ -1626,7 +1627,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_IVAR:
{
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_ABx(OP_GETIV, cursp(), sym));
push();
@@ -1635,7 +1636,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_CVAR:
{
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_ABx(OP_GETCV, cursp(), sym));
push();
@@ -1644,7 +1645,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_CONST:
{
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_ABx(OP_GETCONST, cursp(), sym));
push();
@@ -1828,7 +1829,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_SYM:
if (val) {
- int sym = new_sym(s, (mrb_sym)tree);
+ int sym = new_sym(s, sym(tree));
genop(s, MKOP_ABx(OP_LOADSYM, cursp(), sym));
push();
@@ -1874,8 +1875,8 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_ALIAS:
{
- int a = new_msym(s, (mrb_sym)tree->car);
- int b = new_msym(s, (mrb_sym)tree->cdr);
+ int a = new_msym(s, sym(tree->car));
+ int b = new_msym(s, sym(tree->cdr));
int c = new_msym(s, mrb_intern(s->mrb, "alias_method"));
genop(s, MKOP_A(OP_TCLASS, cursp()));
@@ -1895,7 +1896,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_UNDEF:
{
- int sym = new_msym(s, (mrb_sym)tree);
+ int sym = new_msym(s, sym(tree));
int undef = new_msym(s, mrb_intern(s->mrb, "undef_method"));
genop(s, MKOP_A(OP_TCLASS, cursp()));
@@ -1934,7 +1935,7 @@ codegen(codegen_scope *s, node *tree, int val)
push();
}
pop(); pop();
- idx = new_msym(s, (mrb_sym)tree->car->cdr);
+ idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_CLASS, cursp(), idx));
idx = scope_body(s, tree->cdr->cdr->car);
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
@@ -1960,7 +1961,7 @@ codegen(codegen_scope *s, node *tree, int val)
codegen(s, tree->car->car, VAL);
}
pop();
- idx = new_msym(s, (mrb_sym)tree->car->cdr);
+ idx = new_msym(s, sym(tree->car->cdr));
genop(s, MKOP_AB(OP_MODULE, cursp(), idx));
idx = scope_body(s, tree->cdr->car);
genop(s, MKOP_ABx(OP_EXEC, cursp(), idx));
@@ -1987,7 +1988,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_DEF:
{
- int sym = new_msym(s, (mrb_sym)tree->car);
+ int sym = new_msym(s, sym(tree->car));
int idx = lambda_body(s, tree->cdr, 0);
genop(s, MKOP_A(OP_TCLASS, cursp()));
@@ -2004,7 +2005,7 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_SDEF:
{
node *recv = tree->car;
- int sym = new_msym(s, (mrb_sym)tree->cdr->car);
+ int sym = new_msym(s, sym(tree->cdr->car));
int idx = lambda_body(s, tree->cdr->cdr, 0);
codegen(s, recv, VAL);
diff --git a/src/parse.y b/src/parse.y
index d7d0ce73e..a7f645456 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -58,6 +58,9 @@ typedef unsigned int stack_type;
#define CMDARG_LEXPOP() BITSTACK_LEXPOP(p->cmdarg_stack)
#define CMDARG_P() BITSTACK_SET_P(p->cmdarg_stack)
+#define sym(x) ((mrb_sym)(intptr_t)(x))
+#define nsym(x) ((node*)(intptr_t)(x))
+
static mrb_sym
intern_gen(parser_state *p, const char *s)
{
@@ -219,7 +222,7 @@ local_var_p(parser_state *p, mrb_sym sym)
while (l) {
node *n = l->car;
while (n) {
- if ((mrb_sym)n->car == sym) return 1;
+ if (sym(n->car) == sym) return 1;
n = n->cdr;
}
l = l->cdr;
@@ -230,7 +233,7 @@ local_var_p(parser_state *p, mrb_sym sym)
static void
local_add_f(parser_state *p, mrb_sym sym)
{
- p->locals->car = push(p->locals->car, (node*)sym);
+ p->locals->car = push(p->locals->car, nsym(sym));
}
static void
@@ -298,7 +301,7 @@ new_false(parser_state *p)
static node*
new_alias(parser_state *p, mrb_sym a, mrb_sym b)
{
- return cons((node*)NODE_ALIAS, cons((node*)a, (node*)b));
+ return cons((node*)NODE_ALIAS, cons(nsym(a), nsym(b)));
}
// (:if cond then else)
@@ -368,14 +371,14 @@ new_self(parser_state *p)
static node*
new_call(parser_state *p, node *a, mrb_sym b, node *c)
{
- return list4((node*)NODE_CALL, a, (node*)b, c);
+ return list4((node*)NODE_CALL, a, nsym(b), c);
}
// (:fcall self mid args)
static node*
new_fcall(parser_state *p, mrb_sym b, node *c)
{
- return list4((node*)NODE_FCALL, new_self(p), (node*)b, c);
+ return list4((node*)NODE_FCALL, new_self(p), nsym(b), c);
}
#if 0
@@ -467,14 +470,14 @@ new_dot3(parser_state *p, node *a, node *b)
static node*
new_colon2(parser_state *p, node *b, mrb_sym c)
{
- return cons((node*)NODE_COLON2, cons(b, (node*)c));
+ return cons((node*)NODE_COLON2, cons(b, nsym(c)));
}
// (:colon3 . c)
static node*
new_colon3(parser_state *p, mrb_sym c)
{
- return cons((node*)NODE_COLON3, (node*)c);
+ return cons((node*)NODE_COLON3, nsym(c));
}
// (:and a b)
@@ -516,7 +519,7 @@ new_hash(parser_state *p, node *a)
static node*
new_sym(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_SYM, (node*)sym);
+ return cons((node*)NODE_SYM, nsym(sym));
}
static mrb_sym
@@ -532,42 +535,42 @@ new_strsym(parser_state *p, node* str)
static node*
new_lvar(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_LVAR, (node*)sym);
+ return cons((node*)NODE_LVAR, nsym(sym));
}
// (:gvar . a)
static node*
new_gvar(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_GVAR, (node*)sym);
+ return cons((node*)NODE_GVAR, nsym(sym));
}
// (:ivar . a)
static node*
new_ivar(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_IVAR, (node*)sym);
+ return cons((node*)NODE_IVAR, nsym(sym));
}
// (:cvar . a)
static node*
new_cvar(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_CVAR, (node*)sym);
+ return cons((node*)NODE_CVAR, nsym(sym));
}
// (:const . a)
static node*
new_const(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_CONST, (node*)sym);
+ return cons((node*)NODE_CONST, nsym(sym));
}
// (:undef a...)
static node*
new_undef(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_UNDEF, (node*)sym);
+ return cons((node*)NODE_UNDEF, nsym(sym));
}
// (:class class super body)
@@ -595,21 +598,21 @@ new_module(parser_state *p, node *m, node *b)
static node*
new_def(parser_state *p, mrb_sym m, node *a, node *b)
{
- return list5((node*)NODE_DEF, (node*)m, p->locals->car, a, b);
+ return list5((node*)NODE_DEF, nsym(m), p->locals->car, a, b);
}
// (:sdef obj m lv (arg . body))
static node*
new_sdef(parser_state *p, node *o, mrb_sym m, node *a, node *b)
{
- return list6((node*)NODE_SDEF, o, (node*)m, p->locals->car, a, b);
+ return list6((node*)NODE_SDEF, o, nsym(m), p->locals->car, a, b);
}
// (:arg . sym)
static node*
new_arg(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_ARG, (node*)sym);
+ return cons((node*)NODE_ARG, nsym(sym));
}
// (m o r m2 b)
@@ -623,8 +626,8 @@ new_args(parser_state *p, node *m, node *opt, mrb_sym rest, node *m2, mrb_sym bl
{
node *n;
- n = cons(m2, (node*)blk);
- n = cons((node*)rest, n);
+ n = cons(m2, nsym(blk));
+ n = cons(nsym(rest), n);
n = cons(opt, n);
return cons(m, n);
}
@@ -668,7 +671,7 @@ new_masgn(parser_state *p, node *a, node *b)
static node*
new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
{
- return list4((node*)NODE_OP_ASGN, a, (node*)op, b);
+ return list4((node*)NODE_OP_ASGN, a, nsym(op), b);
}
// (:int . i)
@@ -807,7 +810,7 @@ static void
assignable(parser_state *p, node *lhs)
{
if ((int)(intptr_t)lhs->car == NODE_LVAR) {
- local_add(p, (mrb_sym)lhs->cdr);
+ local_add(p, sym(lhs->cdr));
}
}
@@ -817,8 +820,8 @@ var_reference(parser_state *p, node *lhs)
node *n;
if ((int)(intptr_t)lhs->car == NODE_LVAR) {
- if (!local_var_p(p, (mrb_sym)lhs->cdr)) {
- n = new_fcall(p, (mrb_sym)lhs->cdr, 0);
+ if (!local_var_p(p, sym(lhs->cdr))) {
+ n = new_fcall(p, sym(lhs->cdr), 0);
cons_free(lhs);
return n;
}
@@ -1451,15 +1454,15 @@ cname : tIDENTIFIER
cpath : tCOLON3 cname
{
- $$ = cons((node*)1, (node*)$2);
+ $$ = cons((node*)1, nsym($2));
}
| cname
{
- $$ = cons((node*)0, (node*)$1);
+ $$ = cons((node*)0, nsym($1));
}
| primary_value tCOLON2 cname
{
- $$ = cons($1, (node*)$3);
+ $$ = cons($1, nsym($3));
}
;
@@ -2768,14 +2771,14 @@ f_arg : f_arg_item
f_opt : tIDENTIFIER '=' arg_value
{
local_add_f(p, $1);
- $$ = cons((node*)$1, $3);
+ $$ = cons(nsym($1), $3);
}
;
f_block_opt : tIDENTIFIER '=' primary_value
{
local_add_f(p, $1);
- $$ = cons((node*)$1, $3);
+ $$ = cons(nsym($1), $3);
}
;
@@ -4706,7 +4709,7 @@ parser_update_cxt(parser_state *p, mrbc_context *cxt)
cxt->syms = (mrb_sym *)mrb_realloc(p->mrb, cxt->syms, i*sizeof(mrb_sym));
cxt->slen = i;
for (i=0, n=n0; n; i++,n=n->cdr) {
- cxt->syms[i] = (mrb_sym)n->car;
+ cxt->syms[i] = sym(n->car);
}
}
@@ -5034,7 +5037,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
while (n2) {
dump_prefix(offset+2);
- printf("%s=", mrb_sym2name(mrb, (mrb_sym)n2->car->car));
+ printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr;
}
@@ -5043,7 +5046,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n->car) {
dump_prefix(offset+1);
- printf("rest=*%s\n", mrb_sym2name(mrb, (mrb_sym)n->car));
+ printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
}
n = n->cdr;
if (n->car) {
@@ -5054,7 +5057,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n) {
dump_prefix(offset+1);
- printf("blk=&%s\n", mrb_sym2name(mrb, (mrb_sym)n));
+ printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
}
}
dump_prefix(offset+1);
@@ -5177,7 +5180,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
while (n2) {
if (n2->car) {
if (n2 != tree->car) printf(", ");
- printf("%s", mrb_sym2name(mrb, (mrb_sym)n2->car));
+ printf("%s", mrb_sym2name(mrb, sym(n2->car)));
}
n2 = n2->cdr;
}
@@ -5194,7 +5197,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
parser_dump(mrb, tree->car, offset+1);
dump_prefix(offset+1);
printf("method='%s' (%d)\n",
- mrb_sym2name(mrb, (mrb_sym)tree->cdr->car),
+ mrb_sym2name(mrb, sym(tree->cdr->car)),
(int)(intptr_t)tree->cdr->car);
tree = tree->cdr->cdr->car;
if (tree) {
@@ -5225,13 +5228,13 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
printf("NODE_COLON2:\n");
parser_dump(mrb, tree->car, offset+1);
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree->cdr));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree->cdr)));
break;
case NODE_COLON3:
printf("NODE_COLON3:\n");
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_ARRAY:
@@ -5314,7 +5317,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
parser_dump(mrb, tree->car, offset+2);
tree = tree->cdr;
dump_prefix(offset+1);
- printf("op='%s' (%d)\n", mrb_sym2name(mrb, (mrb_sym)tree->car), (int)(intptr_t)tree->car);
+ printf("op='%s' (%d)\n", mrb_sym2name(mrb, sym(tree->car)), (int)(intptr_t)tree->car);
tree = tree->cdr;
parser_dump(mrb, tree->car, offset+1);
break;
@@ -5366,23 +5369,23 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
break;
case NODE_LVAR:
- printf("NODE_LVAR %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_LVAR %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_GVAR:
- printf("NODE_GVAR %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_GVAR %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_IVAR:
- printf("NODE_IVAR %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_IVAR %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_CVAR:
- printf("NODE_CVAR %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_CVAR %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_CONST:
- printf("NODE_CONST %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_CONST %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_BACK_REF:
@@ -5394,7 +5397,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
break;
case NODE_ARG:
- printf("NODE_ARG %s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_ARG %s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_BLOCK_ARG:
@@ -5425,7 +5428,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
break;
case NODE_SYM:
- printf("NODE_SYM :%s\n", mrb_sym2name(mrb, (mrb_sym)tree));
+ printf("NODE_SYM :%s\n", mrb_sym2name(mrb, sym(tree)));
break;
case NODE_SELF:
@@ -5446,29 +5449,29 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_ALIAS:
printf("NODE_ALIAS %s %s:\n",
- mrb_sym2name(mrb, (mrb_sym)tree->car),
- mrb_sym2name(mrb, (mrb_sym)tree->cdr));
+ mrb_sym2name(mrb, sym(tree->car)),
+ mrb_sym2name(mrb, sym(tree->cdr)));
break;
case NODE_UNDEF:
printf("NODE_UNDEF %s:\n",
- mrb_sym2name(mrb, (mrb_sym)tree));
+ mrb_sym2name(mrb, sym(tree)));
break;
case NODE_CLASS:
printf("NODE_CLASS:\n");
if (tree->car->car == (node*)0) {
dump_prefix(offset+1);
- printf(":%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
else if (tree->car->car == (node*)1) {
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
else {
parser_dump(mrb, tree->car->car, offset+1);
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
if (tree->cdr->car) {
dump_prefix(offset+1);
@@ -5484,16 +5487,16 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
printf("NODE_MODULE:\n");
if (tree->car->car == (node*)0) {
dump_prefix(offset+1);
- printf(":%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf(":%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
else if (tree->car->car == (node*)1) {
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
else {
parser_dump(mrb, tree->car->car, offset+1);
dump_prefix(offset+1);
- printf("::%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car->cdr));
+ printf("::%s\n", mrb_sym2name(mrb, sym(tree->car->cdr)));
}
dump_prefix(offset+1);
printf("body:\n");
@@ -5511,7 +5514,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
case NODE_DEF:
printf("NODE_DEF:\n");
dump_prefix(offset+1);
- printf("%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car));
+ printf("%s\n", mrb_sym2name(mrb, sym(tree->car)));
tree = tree->cdr;
{
node *n2 = tree->car;
@@ -5523,7 +5526,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
while (n2) {
if (n2->car) {
if (n2 != tree->car) printf(", ");
- printf("%s", mrb_sym2name(mrb, (mrb_sym)n2->car));
+ printf("%s", mrb_sym2name(mrb, sym(n2->car)));
}
n2 = n2->cdr;
}
@@ -5548,7 +5551,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
while (n2) {
dump_prefix(offset+2);
- printf("%s=", mrb_sym2name(mrb, (mrb_sym)n2->car->car));
+ printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr;
}
@@ -5557,7 +5560,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n->car) {
dump_prefix(offset+1);
- printf("rest=*%s\n", mrb_sym2name(mrb, (mrb_sym)n->car));
+ printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
}
n = n->cdr;
if (n->car) {
@@ -5568,7 +5571,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n) {
dump_prefix(offset+1);
- printf("blk=&%s\n", mrb_sym2name(mrb, (mrb_sym)n));
+ printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
}
}
parser_dump(mrb, tree->cdr->car, offset+1);
@@ -5579,7 +5582,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
parser_dump(mrb, tree->car, offset+1);
tree = tree->cdr;
dump_prefix(offset+1);
- printf(":%s\n", mrb_sym2name(mrb, (mrb_sym)tree->car));
+ printf(":%s\n", mrb_sym2name(mrb, sym(tree->car)));
tree = tree->cdr->cdr;
if (tree->car) {
node *n = tree->car;
@@ -5598,7 +5601,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
while (n2) {
dump_prefix(offset+2);
- printf("%s=", mrb_sym2name(mrb, (mrb_sym)n2->car->car));
+ printf("%s=", mrb_sym2name(mrb, sym(n2->car->car)));
parser_dump(mrb, n2->car->cdr, 0);
n2 = n2->cdr;
}
@@ -5607,7 +5610,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n->car) {
dump_prefix(offset+1);
- printf("rest=*%s\n", mrb_sym2name(mrb, (mrb_sym)n->car));
+ printf("rest=*%s\n", mrb_sym2name(mrb, sym(n->car)));
}
n = n->cdr;
if (n->car) {
@@ -5618,7 +5621,7 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
n = n->cdr;
if (n) {
dump_prefix(offset+1);
- printf("blk=&%s\n", mrb_sym2name(mrb, (mrb_sym)n));
+ printf("blk=&%s\n", mrb_sym2name(mrb, sym(n)));
}
}
tree = tree->cdr;
diff --git a/src/string.c b/src/string.c
index 7077e9dfd..57bbbc831 100644
--- a/src/string.c
+++ b/src/string.c
@@ -379,7 +379,10 @@ mrb_str_plus(mrb_state *mrb, mrb_value a, mrb_value b)
static mrb_value
mrb_str_plus_m(mrb_state *mrb, mrb_value self)
{
- return mrb_nil_value();
+ mrb_value str;
+
+ mrb_get_args(mrb, "S", &str);
+ return mrb_str_plus(mrb, self, str);
}
/*
diff --git a/test/t/integer.rb b/test/t/integer.rb
index 872723445..56ea6bf13 100644
--- a/test/t/integer.rb
+++ b/test/t/integer.rb
@@ -172,3 +172,19 @@ assert('Integer#upto', '15.2.8.3.27') do
end
a == 6
end
+
+# Not ISO specified
+
+assert('Integer#step') do
+ a = []
+ b = []
+ 1.step(3) do |i|
+ a << i
+ end
+ 1.step(6, 2) do |i|
+ b << i
+ end
+
+ a == [1, 2, 3] and
+ b == [1, 3, 5]
+end
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index 1342f0254..fb0aee310 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -337,5 +337,5 @@ assert('Kernel#singleton_methods', '15.3.1.3.45') do
end
assert('Kernel#to_s', '15.3.1.3.46') do
- to_s == '#<Object:0x0>'
+ to_s.class == String
end