yarv-diff:258
From: ko1 atdot.net
Date: 15 Feb 2006 08:51:06 -0000
Subject: [yarv-diff:258] r421 - in trunk: . rb
Author: ko1
Date: 2006-02-15 17:51:05 +0900 (Wed, 15 Feb 2006)
New Revision: 421
Modified:
trunk/
trunk/ChangeLog
trunk/eval.c
trunk/eval_intern.h
trunk/eval_jump.h
trunk/eval_load.c
trunk/insns.def
trunk/opt_insn_unif.def
trunk/opt_operand.def
trunk/rb/insns2vm.rb
trunk/test.rb
trunk/thread.c
trunk/vm.c
Log:
r633@lermite: ko1 | 2006-02-15 17:48:32 +0900
* eval_intern.h :
* eval_jump.h, vm.c : localjump_error() and jump_tag_but_local_jump()
move to th_localjump_error and th_jump_tag_but_local_jump at vm.c
* eval.c : ditto
* eval_load.c : ditto
* insns.def : ditto
* vm.c : ditto
* vm.c (th_make_jump_tag_but_local_jump) : added
* opt_insn_unif.def : fix indnet (revert change)
* opt_operand.def : ditto
* rb/insns2vm.rb : fix error message
* thread.c : raise exception at join if illegal local jump
Property changes on: trunk
___________________________________________________________________
Name: svk:merge
- 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:629
+ 81cd9672-7512-7e48-ae48-6936450e977d:/local/yarv/trunk:633
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/ChangeLog 2006-02-15 08:51:05 UTC (rev 421)
@@ -4,6 +4,32 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-02-15(Wed) 17:39:16 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * eval_intern.h :
+
+ * eval_jump.h, vm.c : localjump_error() and jump_tag_but_local_jump()
+ move to th_localjump_error and th_jump_tag_but_local_jump at vm.c
+
+ * eval.c : ditto
+
+ * eval_load.c : ditto
+
+ * insns.def : ditto
+
+ * vm.c : ditto
+
+ * vm.c (th_make_jump_tag_but_local_jump) : added
+
+ * opt_insn_unif.def : fix indnet (revert change)
+
+ * opt_operand.def : ditto
+
+ * rb/insns2vm.rb : fix error message
+
+ * thread.c : raise exception at join if illegal local jump
+
+
2006-02-15(Wed) 14:21:45 +900 Yukihiro Matsumoto <matz ruby-lang.org>
* ChangeLog: add local variables line to support Emacs.
@@ -18,6 +44,7 @@
* eval.c (rb_obj_instance_eval): should be no singleton classes for
true, false, and nil. [ruby-dev:28186]
+
2006-02-14(Tue) 19:30:20 +0900 Koichi Sasada <ko1 atdot.net>
* array.c : fix indent
Modified: trunk/eval.c
===================================================================
--- trunk/eval.c 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/eval.c 2006-02-15 08:51:05 UTC (rev 421)
@@ -379,7 +379,7 @@
ruby_safe_level = safe;
POP_TAG();
- jump_tag_but_local_jump(state, val);
+ th_jump_tag_but_local_jump(state, val);
return val;
}
@@ -1170,14 +1170,14 @@
break; /* should not happen */
}
snprintf(mesg, sizeof mesg, "%s from proc-closure", statement);
- localjump_error(mesg, result, state);
+ th_localjump_error(mesg, result, state);
}
void
rb_need_block()
{
if (!rb_block_given_p()) {
- localjump_error("no block given", Qnil, 0);
+ th_localjump_error("no block given", Qnil, 0);
}
}
Modified: trunk/eval_intern.h
===================================================================
--- trunk/eval_intern.h 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/eval_intern.h 2006-02-15 08:51:05 UTC (rev 421)
@@ -285,6 +285,8 @@
NORETURN(void rb_raise_jump _((VALUE)));
NORETURN(void print_undef _((VALUE, ID)));
+NORETURN(void th_localjump_error(const char *, VALUE, int));
+NORETURN(void th_jump_tag_but_local_jump(int, VALUE));
rb_thread_t rb_vm_curr_thread();
VALUE th_compile(yarv_thread_t *th, VALUE str, VALUE file, VALUE line);
Modified: trunk/eval_jump.h
===================================================================
--- trunk/eval_jump.h 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/eval_jump.h 2006-02-15 08:51:05 UTC (rev 421)
@@ -411,72 +411,7 @@
ruby_safe_level = safe;
}
-
-NORETURN(static void localjump_error(const char *, VALUE, int));
-static void
-localjump_error(const char *mesg, VALUE value, int reason)
-{
- VALUE exc = rb_exc_new2(rb_eLocalJumpError, mesg);
- ID id;
-
- rb_iv_set(exc, "@exit_value", value);
- switch (reason) {
- case TAG_BREAK:
- id = rb_intern("break");
- break;
- case TAG_REDO:
- id = rb_intern("redo");
- break;
- case TAG_RETRY:
- id = rb_intern("retry");
- break;
- case TAG_NEXT:
- id = rb_intern("next");
- break;
- case TAG_RETURN:
- id = rb_intern("return");
- break;
- default:
- id = rb_intern("noreason");
- break;
- }
- rb_iv_set(exc, "@reason", ID2SYM(id));
- rb_exc_raise(exc);
-}
-
-
-NORETURN(void jump_tag_but_local_jump(int, VALUE));
void
-jump_tag_but_local_jump(int state, VALUE val)
-{
- if (val == Qundef)
- val = GET_THREAD()->tag->retval;
- switch (state) {
- case 0:
- break;
- case TAG_RETURN:
- localjump_error("unexpected return", val, state);
- break;
- case TAG_BREAK:
- localjump_error("unexpected break", val, state);
- break;
- case TAG_NEXT:
- localjump_error("unexpected next", val, state);
- break;
- case TAG_REDO:
- localjump_error("unexpected redo", Qnil, state);
- break;
- case TAG_RETRY:
- localjump_error("retry outside of rescue clause", Qnil, state);
- break;
- default:
- break;
- }
- JUMP_TAG(state);
-}
-
-
-void
Init_jump()
{
rb_define_global_function("catch", rb_f_catch, 1);
Modified: trunk/eval_load.c
===================================================================
--- trunk/eval_load.c 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/eval_load.c 2006-02-15 08:51:05 UTC (rev 421)
@@ -120,9 +120,6 @@
int state;
volatile VALUE self = ruby_top_self;
yarv_thread_t *th = GET_THREAD();
-
- /* default visibility is private at loading toplevel */
- th_klass_init(th);
FilePathValue(fname);
fname = rb_str_new4(fname);
@@ -153,7 +150,7 @@
rb_exc_raise(GET_THREAD()->errinfo);
}
if (state) {
- jump_tag_but_local_jump(state, Qundef);
+ th_jump_tag_but_local_jump(state, Qundef);
}
if (!NIL_P(GET_THREAD()->errinfo)) {
Modified: trunk/insns.def
===================================================================
--- trunk/insns.def 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/insns.def 2006-02-15 08:51:05 UTC (rev 421)
@@ -1319,9 +1319,9 @@
blockptr = tmp_blockptr;
mn = rb_method_node(klass, id);
}
+ LABEL_IS_SC(start_method_dispatch):
#endif
#endif
- LABEL_IS_SC(start_method_dispatch):
macro_eval_invoke_method(recv, klass, id, num, mn, blockptr);
YARV_CHECK_INTS();
}
@@ -1367,7 +1367,7 @@
int argc = num;
if (block == 0) {
- localjump_error("no block given (yield)", Qnil, 0);
+ th_localjump_error("no block given (yield)", Qnil, 0);
}
iseq = block->iseq;
@@ -1553,8 +1553,8 @@
}
}
if (is_orphan) {
- localjump_error("unexpected return", throwobj,
- TAG_RETURN);
+ th_localjump_error("unexpected return", throwobj,
+ TAG_RETURN);
}
/* set current lfp */
Modified: trunk/opt_insn_unif.def
===================================================================
--- trunk/opt_insn_unif.def 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/opt_insn_unif.def 2006-02-15 08:51:05 UTC (rev 421)
@@ -4,15 +4,24 @@
#
putobject putobject
- putobject putstring
- putobject setlocal
- putobject setdynamic
- putstring putstring
- putstring putobject putstring setlocal putstring setdynamic
+putobject putstring
+putobject setlocal
+putobject setdynamic
+
+putstring putstring
+putstring putobject
+putstring setlocal
+putstring setdynamic
+
# putnil end
- dup setlocal
+
+dup setlocal
+
# from tarai
- getlocal getlocal
+getlocal getlocal
# getlocal send
+
# from tak, ackermann
- getlocal putobject
+getlocal putobject
+
+
Modified: trunk/opt_operand.def
===================================================================
--- trunk/opt_operand.def 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/opt_operand.def 2006-02-15 08:51:05 UTC (rev 421)
@@ -8,68 +8,50 @@
#
getlocal 2
- getlocal 3
- getlocal 4
- setlocal 2
- setlocal 3
- setlocal 4
- getdynamic *, 0
- getdynamic 1, 0
- getdynamic 2, 0
- getdynamic 3, 0
- getdynamic 4, 0
- setdynamic *, 0
- setdynamic 1, 0
- setdynamic 2, 0 setdynamic 3, 0 setdynamic 4, 0 putobject INT2FIX(0)
- putobject
- INT2FIX(1)
- putobject
- Qtrue
- putobject
- Qfalse
+getlocal 3
+getlocal 4
+
+setlocal 2
+setlocal 3
+setlocal 4
+
+getdynamic *, 0
+getdynamic 1, 0
+getdynamic 2, 0
+getdynamic 3, 0
+getdynamic 4, 0
+
+setdynamic *, 0
+setdynamic 1, 0
+setdynamic 2, 0
+setdynamic 3, 0
+setdynamic 4, 0
+
+putobject INT2FIX(0)
+putobject INT2FIX(1)
+putobject Qtrue
+putobject Qfalse
+
# CALL
- send *, *,
- Qfalse,
- 0, *
- send *,
- 0,
- Qfalse,
- 0, *
- send *,
- 1,
- Qfalse,
- 0, *
- send *,
- 2,
- Qfalse,
- 0, *
- send *,
- 3,
- Qfalse,
- 0, *
+send *, *, Qfalse, 0, *
+send *, 0, Qfalse, 0, *
+send *, 1, Qfalse, 0, *
+send *, 2, Qfalse, 0, *
+send *, 3, Qfalse, 0, *
+
# FCALL
- send *, *,
- Qfalse,
- 0x04, *
- send *,
- 0,
- Qfalse,
- 0x04, *
- send *,
- 1,
- Qfalse,
- 0x04, *
- send *,
- 2,
- Qfalse,
- 0x04, *
- send *,
- 3,
- Qfalse,
- 0x04, *
+send *, *, Qfalse, 0x04, *
+send *, 0, Qfalse, 0x04, *
+send *, 1, Qfalse, 0x04, *
+send *, 2, Qfalse, 0x04, *
+send *, 3, Qfalse, 0x04, *
+
# VCALL
- send *,
- 0,
- Qfalse,
- 0x0c, *
- __END__
+send *, 0, Qfalse, 0x0c, *
+
+
+__END__
+
+
+
+
Modified: trunk/rb/insns2vm.rb
===================================================================
--- trunk/rb/insns2vm.rb 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/rb/insns2vm.rb 2006-02-15 08:51:05 UTC (rev 421)
@@ -270,7 +270,7 @@
opes = insn.opes
if opes.size != opts.size
- raise "operand size mismatcvh for #{insn.name} (#{opts.size})"
+ raise "operand size mismatcvh for #{insn.name} (opes: #{opes.size}, opts: #{opts.size})"
end
ninsn = insn.name + '_OP_' + opts.map{|e| label_escape(e)}.join('_')
Modified: trunk/test.rb
===================================================================
--- trunk/test.rb 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/test.rb 2006-02-15 08:51:05 UTC (rev 421)
@@ -1,4 +1,37 @@
+def m
+ Thread.new{
+ eval("return")
+ }
+end
+
+m.join
+__END__
+
+Thread.new{}.kill
+__END__
+Thread.new{}
+
+__END__
+def test_ok bool
+ p bool
+end
+
+def get_block &b
+ b
+end
+def argument_test a, b, c=nil, d=nil
+end
+
+argument_test(true, get_block(&lambda{||}))
+argument_test(false, get_block(&lambda{||}),1)
+argument_test(true, get_block(&lambda{|a,|}),1)
+argument_test(false, get_block(&lambda{|a,|}),1,2)
+
+begin; raise; rescue; end
+__END__
+
+__END__
Thread.new{
no_method()
}.join
Modified: trunk/thread.c
===================================================================
--- trunk/thread.c 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/thread.c 2006-02-15 08:51:05 UTC (rev 421)
@@ -39,6 +39,7 @@
/* for model 2 */
#include "eval_intern.h"
+#include "vm.h"
#define THREAD_DEBUG 0
@@ -167,6 +168,14 @@
th->value = Qnil;
}
TH_POP_TAG();
+
+ if (TYPE(th->errinfo) == T_NODE) {
+ VALUE err = th->errinfo;
+
+ th->errinfo = th_make_jump_tag_but_local_jump(
+ GET_THROWOBJ_STATE(err), GET_THROWOBJ_VAL(err));
+ }
+
th->status = THREAD_KILLED;
thread_debug("thread end: %p\n", th);
st_delete_wrap(GET_VM()->living_threads, th->self);
@@ -236,6 +245,8 @@
* tick...
*/
+VALUE th_make_localjump_error(const char *mesg, VALUE value, int reason);
+
static VALUE
yarv_thread_join(int argc, VALUE *argv, VALUE self)
{
Modified: trunk/vm.c
===================================================================
--- trunk/vm.c 2006-02-15 05:27:51 UTC (rev 420)
+++ trunk/vm.c 2006-02-15 08:51:05 UTC (rev 421)
@@ -550,7 +550,7 @@
yarv_block_t *block = GC_GUARDED_PTR_REF(cfp->lfp[0]);
VALUE val;
if (block == 0) {
- localjump_error("no block given", Qnil, 0);
+ th_localjump_error("no block given", Qnil, 0);
}
else {
if (BUILTIN_TYPE(block->iseq) != T_NODE) {
@@ -1128,14 +1128,15 @@
/*********************************************************/
/*********************************************************/
-static void
-localjump_error(const char *mesg, VALUE value, int reason)
+static VALUE
+make_localjump_error(const char *mesg, VALUE value, int reason)
{
VALUE exc =
rb_exc_new2(rb_const_get(rb_cObject, rb_intern("LocalJumpError")),
mesg);
ID id;
-
+
+ rb_iv_set(exc, "@reason", ID2SYM(id));
rb_iv_set(exc, "@exit_value", value);
switch (reason) {
case TAG_BREAK:
@@ -1158,10 +1159,58 @@
break;
}
rb_iv_set(exc, "@reason", ID2SYM(id));
+ return exc;
+}
+
+void
+th_localjump_error(const char *mesg, VALUE value, int reason)
+{
+ VALUE exc = make_localjump_error(mesg, value, reason);
rb_exc_raise(exc);
}
+VALUE
+th_make_jump_tag_but_local_jump(int state, VALUE val)
+{
+ VALUE result = Qnil;
+
+ if (val == Qundef)
+ val = GET_THREAD()->tag->retval;
+ switch (state) {
+ case 0:
+ break;
+ case TAG_RETURN:
+ result = make_localjump_error("unexpected return", val, state);
+ break;
+ case TAG_BREAK:
+ result = make_localjump_error("unexpected break", val, state);
+ break;
+ case TAG_NEXT:
+ result = make_localjump_error("unexpected next", val, state);
+ break;
+ case TAG_REDO:
+ result = make_localjump_error("unexpected redo", Qnil, state);
+ break;
+ case TAG_RETRY:
+ result = make_localjump_error("retry outside of rescue clause", Qnil, state);
+ break;
+ default:
+ break;
+ }
+ return result;
+}
+
void
+th_jump_tag_but_local_jump(int state, VALUE val)
+{
+ VALUE exc = th_make_jump_tag_but_local_jump(state, val);
+ if (val != Qnil) {
+ rb_exc_raise(exc);
+ }
+ JUMP_TAG(state);
+}
+
+void
th_iter_break(yarv_thread_t *th)
{
yarv_control_frame_t *cfp = th->cfp;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml