summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/codegen.c8
-rw-r--r--src/vm.c23
-rw-r--r--test/t/comparable.rb15
-rw-r--r--test/t/exception.rb23
-rw-r--r--test/t/kernel.rb25
-rw-r--r--test/t/module.rb23
-rw-r--r--tools/mirb/mirb.c2
7 files changed, 86 insertions, 33 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 83d0136ef..d9fc10657 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -317,6 +317,14 @@ genop_peep(codegen_scope *s, mrb_code i, int val)
s->iseq[s->pc-1] = MKOP_A(c0, 0);
genop(s, MKOP_AB(OP_RETURN, 0, OP_R_NORMAL));
return;
+#if 0
+ case OP_SEND:
+ if (GETARG_B(i) == OP_R_NORMAL && GETARG_A(i) == GETARG_A(i0)) {
+ s->iseq[s->pc-1] = MKOP_ABC(OP_TAILCALL, GETARG_A(i0), GETARG_B(i0), GETARG_C(i0));
+ return;
+ }
+ break;
+#endif
default:
break;
}
diff --git a/src/vm.c b/src/vm.c
index c319e7148..13058fc28 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -403,7 +403,7 @@ mrb_yield_internal(mrb_state *mrb, mrb_value b, int argc, mrb_value *argv, mrb_v
ci->nregs = argc + 2;
}
else {
- ci->nregs = p->body.irep->nregs + 2;
+ ci->nregs = p->body.irep->nregs + 1;
}
ci->acc = -1;
mrb->stack = mrb->stack + n;
@@ -568,7 +568,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
stack_extend(mrb, irep->nregs, irep->nregs);
mrb->ci->proc = proc;
- mrb->ci->nregs = irep->nregs + 2;
+ mrb->ci->nregs = irep->nregs + 1;
regs = mrb->stack;
regs[0] = self;
@@ -873,7 +873,13 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
else {
ci->argc = n;
}
- ci->target_class = c;
+ if (c->tt == MRB_TT_ICLASS) {
+ ci->target_class = c->c;
+ }
+ else {
+ ci->target_class = c;
+ }
+
ci->pc = pc + 1;
ci->acc = a;
@@ -1189,9 +1195,11 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
NEXT;
}
+ L_RETURN:
+ i = MKOP_AB(OP_RETURN, GETARG_A(i), OP_R_NORMAL);
+ /* fall through */
CASE(OP_RETURN) {
/* A return R(A) */
- L_RETURN:
if (mrb->exc) {
mrb_callinfo *ci;
int eidx;
@@ -1327,7 +1335,6 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
}
-
/* replace callinfo */
ci = mrb->ci;
ci->mid = mid;
@@ -1652,7 +1659,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
} while (0)
CASE(OP_EQ) {
- /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/
+ /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:==,C=1)*/
int a = GETARG_A(i);
if (mrb_obj_eq(mrb, regs[a], regs[a+1])) {
SET_TRUE_VALUE(regs[a]);
@@ -1670,7 +1677,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
CASE(OP_LE) {
- /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/
+ /* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1)*/
OP_CMP(<=);
NEXT;
}
@@ -1682,7 +1689,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
CASE(OP_GE) {
- /* A B C R(A) := R(A)<R(A+1) (Syms[B]=:<,C=1)*/
+ /* A B C R(A) := R(A)<=R(A+1) (Syms[B]=:<=,C=1)*/
OP_CMP(>=);
NEXT;
}
diff --git a/test/t/comparable.rb b/test/t/comparable.rb
index c95134246..ab81fa3ed 100644
--- a/test/t/comparable.rb
+++ b/test/t/comparable.rb
@@ -54,3 +54,18 @@ assert('Comparable#>=', '15.3.3.2.5') do
(Foo.new >= Foo.new) == true
end
+assert('Comparable#between?', '15.3.3.2.6') do
+ class Foo
+ include Comparable
+ def <=>(x)
+ x
+ end
+ end
+
+ c = Foo.new
+ c.between?(-1, 1) == false &&
+ c.between?(-1, -1) == false &&
+ c.between?( 1, 1) == false &&
+ c.between?( 1, -1) == true &&
+ c.between?(0, 0) == true
+end
diff --git a/test/t/exception.rb b/test/t/exception.rb
index 7ecc51fa8..d43ce8833 100644
--- a/test/t/exception.rb
+++ b/test/t/exception.rb
@@ -318,26 +318,3 @@ end
assert('Exception#inspect without message') do
Exception.new.inspect
end
-
-# very deeply recursive function that stil returns albeit very deeply so
-$test_infinite_recursion = 0
-TEST_INFINITE_RECURSION_MAX = 1000000
-def test_infinite_recursion
- $test_infinite_recursion += 1
- if $test_infinite_recursion > TEST_INFINITE_RECURSION_MAX
- return $test_infinite_recursion
- end
- test_infinite_recursion
-end
-
-assert('Infinite recursion should result in an exception being raised') do
- a = begin
- test_infinite_recursion
- rescue
- :ok
- end
- # OK if an exception was caught, otherwise a number will be stored in a
- a == :ok
-end
-
-
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index 835834359..abc8f260b 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -155,6 +155,16 @@ assert('Kernel#clone', '15.3.1.3.8') do
a.set(2)
c = a.clone
+ immutables = [ 1, :foo, true, false, nil ]
+ error_count = 0
+ immutables.each do |i|
+ begin
+ i.clone
+ rescue TypeError
+ error_count += 1
+ end
+ end
+
a.get == 2 and b.get == 1 and c.get == 2 &&
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
@@ -185,7 +195,18 @@ assert('Kernel#dup', '15.3.1.3.9') do
a.set(2)
c = a.dup
- a.get == 2 and b.get == 1 and c.get == 2 and
+ immutables = [ 1, :foo, true, false, nil ]
+ error_count = 0
+ immutables.each do |i|
+ begin
+ i.dup
+ rescue TypeError
+ error_count += 1
+ end
+ end
+
+ error_count == immutables.size and
+ a.get == 2 and b.get == 1 and c.get == 2 and
a.respond_to?(:test) == true and
b.respond_to?(:test) == false and
c.respond_to?(:test) == false
@@ -330,6 +351,8 @@ assert('Kernel#raise', '15.3.1.3.40') do
e_list[1].class == RuntimeError
end
+# Kernel#require is defined in mruby-require. '15.3.1.3.42'
+
assert('Kernel#respond_to?', '15.3.1.3.43') do
class Test4RespondTo
def test_method; end
diff --git a/test/t/module.rb b/test/t/module.rb
index 1ff9d3aea..4b689ea5b 100644
--- a/test/t/module.rb
+++ b/test/t/module.rb
@@ -297,6 +297,29 @@ assert('Module#remove_method', '15.2.2.4.41') do
not Test4RemoveMethod::Child.instance_methods(false).include? :hello
end
+assert('Module.undef_method', '15.2.2.4.42') do
+ module Test4UndefMethod
+ class Parent
+ def hello
+ end
+ end
+
+ class Child < Parent
+ def hello
+ end
+ end
+
+ class GrandChild < Child
+ end
+ end
+
+ Test4UndefMethod::Child.class_eval{ undef_method :hello }
+
+ Test4UndefMethod::Parent.new.respond_to?(:hello) and
+ not Test4UndefMethod::Child.new.respond_to?(:hello) and
+ not Test4UndefMethod::GrandChild.new.respond_to?(:hello)
+end
+
# Not ISO specified
diff --git a/tools/mirb/mirb.c b/tools/mirb/mirb.c
index 008829cfb..cde0b0d4b 100644
--- a/tools/mirb/mirb.c
+++ b/tools/mirb/mirb.c
@@ -273,7 +273,7 @@ main(int argc, char **argv)
printf("\n");
break;
}
- strncat(last_code_line, line, sizeof(last_code_line)-1);
+ strncpy(last_code_line, line, sizeof(last_code_line)-1);
add_history(line);
free(line);
#endif