1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* yarvcore.h: add rb_thread_t#top_wrapper, top_self.

* eval_load.c (rb_load): support eval in wrapper module
  (load(file, true)).
* eval.c: ditto.
* eval_jump.h: ditto.
* iseq.c: ditto.
* vm.c: ditto.
* yarvcore.c: ditto.
* insns.def: add a empty line.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11884 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-02-25 16:29:26 +00:00
parent e98f7e1eaa
commit 9987d53e51
9 changed files with 70 additions and 27 deletions

View file

@ -1,3 +1,22 @@
Mon Feb 26 00:58:39 2007 Koichi Sasada <ko1@atdot.net>
* yarvcore.h: add rb_thread_t#top_wrapper, top_self.
* eval_load.c (rb_load): support eval in wrapper module
(load(file, true)).
* eval.c: ditto.
* eval_jump.h: ditto.
* iseq.c: ditto.
* vm.c: ditto.
* yarvcore.c: ditto.
* insns.def: add a empty line.
Mon Feb 26 00:54:36 2007 Koichi Sasada <ko1@atdot.net>
* common.mk: change "gdb" rule. You can debug miniruby with

23
eval.c
View file

@ -35,8 +35,6 @@ VALUE rb_eSysStackError;
extern int ruby_nerrs;
extern VALUE ruby_top_self;
static VALUE ruby_wrapper; /* security wrapper */
static VALUE eval _((VALUE, VALUE, VALUE, char *, int));
static VALUE rb_yield_0 _((VALUE, VALUE, VALUE, int, int));
@ -289,17 +287,20 @@ VALUE
rb_eval_string_wrap(const char *str, int *state)
{
int status;
VALUE self = ruby_top_self;
VALUE wrapper = ruby_wrapper;
rb_thread_t *th = GET_THREAD();
VALUE self = th->top_self;
VALUE wrapper = th->top_wrapper;
VALUE val;
ruby_top_self = rb_obj_clone(ruby_top_self);
rb_extend_object(ruby_top_self, ruby_wrapper);
th->top_wrapper = rb_module_new();
th->top_self = rb_obj_clone(ruby_top_self);
rb_extend_object(th->top_self, th->top_wrapper);
val = rb_eval_string_protect(str, &status);
ruby_top_self = self;
ruby_wrapper = wrapper;
th->top_self = self;
th->top_wrapper = wrapper;
if (state) {
*state = status;
}
@ -2687,11 +2688,13 @@ rb_obj_extend(int argc, VALUE *argv, VALUE obj)
static VALUE
top_include(int argc, VALUE *argv, VALUE self)
{
rb_thread_t *th = GET_THREAD();
rb_secure(4);
if (ruby_wrapper) {
if (th->top_wrapper) {
rb_warning
("main#include in the wrapped load is effective only in wrapper module");
return rb_mod_include(argc, argv, ruby_wrapper);
return rb_mod_include(argc, argv, th->top_wrapper);
}
return rb_mod_include(argc, argv, rb_cObject);
}

View file

@ -318,8 +318,9 @@ rb_set_end_proc(void (*func)(VALUE), VALUE data)
{
struct end_proc_data *link = ALLOC(struct end_proc_data);
struct end_proc_data **list;
rb_thread_t *th = GET_THREAD();
if (ruby_wrapper) {
if (th->top_wrapper) {
list = &ephemeral_end_procs;
}
else {

View file

@ -136,7 +136,7 @@ rb_load_internal(char *file)
}
iseq = rb_iseq_new(node, rb_str_new2("<top (required)>"),
rb_str_new2(file), Qfalse, ISEQ_TYPE_TOP);
rb_str_new2(file), Qfalse, ISEQ_TYPE_TOP);
rb_thread_eval(GET_THREAD(), iseq);
return 0;
@ -147,7 +147,9 @@ rb_load(VALUE fname, int wrap)
{
VALUE tmp;
int state;
volatile VALUE self = ruby_top_self;
rb_thread_t *th = GET_THREAD();
VALUE wrapper = th->top_wrapper;
VALUE self = th->top_self;
FilePathValue(fname);
fname = rb_str_new4(fname);
@ -157,14 +159,17 @@ rb_load(VALUE fname, int wrap)
}
fname = tmp;
GET_THREAD()->errinfo = Qnil; /* ensure */
th->errinfo = Qnil; /* ensure */
if (!wrap) {
rb_secure(4); /* should alter global state */
th->top_wrapper = 0;
}
else {
/* load in anonymous module as toplevel */
self = rb_obj_clone(ruby_top_self);
th->top_self = rb_obj_clone(ruby_top_self);
th->top_wrapper = rb_module_new();
rb_extend_object(th->top_self, th->top_wrapper);
}
PUSH_TAG(PROT_NONE);
@ -174,6 +179,9 @@ rb_load(VALUE fname, int wrap)
}
POP_TAG();
th->top_self = self;
th->top_wrapper = wrapper;
if (ruby_nerrs > 0) {
ruby_nerrs = 0;
rb_exc_raise(GET_THREAD()->errinfo);
@ -184,7 +192,7 @@ rb_load(VALUE fname, int wrap)
if (!NIL_P(GET_THREAD()->errinfo)) {
/* exception during load */
rb_exc_raise(GET_THREAD()->errinfo);
rb_exc_raise(th->errinfo);
}
}

View file

@ -1058,6 +1058,7 @@ defineclass
if (super == Qnil) {
super = rb_cObject;
}
if (cbase == Qnil) {
cbase = th_get_cbase(th);
}

14
iseq.c
View file

@ -107,12 +107,14 @@ prepare_iseq_build(rb_iseq_t *iseq,
VALUE parent, VALUE type, VALUE block_opt,
const rb_compile_option_t *option)
{
rb_thread_t *th = GET_THREAD();
iseq->name = name;
iseq->defined_method_id = 0;
iseq->filename = filename;
iseq->iseq_mark_ary = rb_ary_new();
RBASIC(iseq->iseq_mark_ary)->klass = 0;
iseq->type = type;
iseq->arg_rest = 0;
iseq->arg_block = 0;
@ -124,7 +126,7 @@ prepare_iseq_build(rb_iseq_t *iseq,
/* set class nest stack */
if (type == ISEQ_TYPE_TOP) {
/* toplevel is private */
iseq->cref_stack = NEW_BLOCK(rb_cObject);
iseq->cref_stack = NEW_BLOCK(th->top_wrapper ? th->top_wrapper : rb_cObject);
iseq->cref_stack->nd_file = 0;
iseq->cref_stack->nd_visi = NOEX_PRIVATE;
}
@ -144,17 +146,17 @@ prepare_iseq_build(rb_iseq_t *iseq,
RBASIC(iseq->compile_data->mark_ary)->klass = 0;
iseq->compile_data->storage_head = iseq->compile_data->storage_current =
(struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
(struct iseq_compile_data_storage *)
ALLOC_N(char, INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE +
sizeof(struct iseq_compile_data_storage));
iseq->compile_data->catch_table_ary = rb_ary_new();
iseq->compile_data->storage_head->pos = 0;
iseq->compile_data->storage_head->next = 0;
iseq->compile_data->storage_head->size =
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
INITIAL_ISEQ_COMPILE_DATA_STORAGE_BUFF_SIZE;
iseq->compile_data->storage_head->buff =
(char *)(&iseq->compile_data->storage_head->buff + 1);
(char *)(&iseq->compile_data->storage_head->buff + 1);
iseq->compile_data->option = option;
if (type == ISEQ_TYPE_TOP ||

6
vm.c
View file

@ -139,8 +139,6 @@ pop_frame(rb_thread_t *th)
th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
}
EXTERN VALUE ruby_top_self;
VALUE
th_set_finish_env(rb_thread_t *th)
{
@ -165,7 +163,7 @@ th_set_top_stack(rb_thread_t *th, VALUE iseqval)
th_set_finish_env(th);
push_frame(th, iseq, FRAME_MAGIC_TOP,
ruby_top_self, 0, iseq->iseq_encoded,
th->top_self, 0, iseq->iseq_encoded,
th->cfp->sp, 0, iseq->local_size);
}
@ -1150,7 +1148,7 @@ th_get_cbase(rb_thread_t *th)
rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp);
NODE *cref = get_cref(cfp->iseq, cfp->lfp);
VALUE klass = Qundef;
while (cref) {
if ((klass = cref->nd_clss) != 0) {
break;

View file

@ -277,6 +277,8 @@ thread_mark(void *ptr)
MARK_UNLESS_NULL(th->value);
MARK_UNLESS_NULL(th->errinfo);
MARK_UNLESS_NULL(th->local_svar);
MARK_UNLESS_NULL(th->top_self);
MARK_UNLESS_NULL(th->top_wrapper);
rb_mark_tbl(th->local_storage);
@ -340,6 +342,8 @@ th_init(rb_thread_t *th)
th_init2(th);
}
extern VALUE ruby_top_self;
static VALUE
thread_init(VALUE self)
{
@ -350,6 +354,9 @@ thread_init(VALUE self)
th_init(th);
th->self = self;
th->vm = vm;
th->top_wrapper = 0;
th->top_self = ruby_top_self;
return self;
}

View file

@ -404,6 +404,10 @@ struct rb_thread_struct
/* passed via parse.y, eval.c (rb_scope_setup_local_tbl) */
ID *top_local_tbl;
/* for load(true) */
VALUE top_self;
VALUE top_wrapper;
/* eval env */
rb_block_t *base_block;