Skip to content

Commit

Permalink
Correctly use block call frame
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Jul 10, 2012
1 parent 689cc37 commit 29f92c2
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 21 deletions.
4 changes: 4 additions & 0 deletions kernel/common/env.rb
Expand Up @@ -246,3 +246,7 @@ def update(other, &block)
# Missing and deprecated: indexes, indices
end
end

class Object
ENV = Rubinius::EnvironmentVariables.new
end
2 changes: 0 additions & 2 deletions kernel/loader.rb
Expand Up @@ -44,8 +44,6 @@ def self.debugger=(prc)
def preamble
@stage = "running Loader preamble"

Object.const_set :ENV, EnvironmentVariables.new

# Set the default visibility for the top level binding
TOPLEVEL_BINDING.variables.method_visibility = :private

Expand Down
8 changes: 7 additions & 1 deletion vm/arguments.hpp
Expand Up @@ -14,16 +14,18 @@ namespace rubinius {
Symbol* name_;
Object* recv_;
Object* block_;
CallFrame* block_call_frame_;

uint32_t total_;
Object** arguments_;
Tuple* argument_container_;

public:
Arguments(Symbol* name, Object* recv, Object* block, uint32_t total, Object** buffer)
Arguments(Symbol* name, Object* recv, Object* block, CallFrame* block_call_frame, uint32_t total, Object** buffer)
: name_(name)
, recv_(recv)
, block_(block)
, block_call_frame_(block_call_frame)
, total_(total)
, arguments_(buffer)
, argument_container_(0)
Expand Down Expand Up @@ -84,6 +86,10 @@ namespace rubinius {
return block_;
}

CallFrame* block_call_frame() {
return block_call_frame_;
}

void set_block(Object* val) {
block_ = val;
}
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/block_environment.cpp
Expand Up @@ -285,7 +285,7 @@ namespace rubinius {

Module* mod = invocation.module;
if(!mod) mod = env->module();
scope->initialize(invocation.self, env->top_scope_->block(),
scope->initialize(invocation.self, env->top_scope_->block(), env->top_scope_->block_frame(),
mod, vmm->number_of_locals);
scope->set_parent(env->scope_);

Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/system.cpp
Expand Up @@ -1555,7 +1555,7 @@ namespace rubinius {
CallFrame* calling_environment)
{
Dispatch msg(state->symbol("__script__"), G(object), cm);
Arguments args(state->symbol("__script__"), G(main), cNil, 0, 0);
Arguments args(state->symbol("__script__"), G(main), cNil, NULL, 0, 0);

OnStack<1> os(state, cm);

Expand Down
5 changes: 5 additions & 0 deletions vm/builtin/variable_scope.hpp
Expand Up @@ -36,6 +36,7 @@ namespace rubinius {
public:
Object* self_; // slot

CallFrame* block_frame_;
int number_of_locals_;
bool isolated_;
Object** locals_;
Expand Down Expand Up @@ -99,6 +100,10 @@ namespace rubinius {
return locals_[pos];
}

CallFrame* block_frame() {
return block_frame_;
}

int number_of_locals() {
return number_of_locals_;
}
Expand Down
4 changes: 2 additions & 2 deletions vm/capi/capi.cpp
Expand Up @@ -200,7 +200,7 @@ namespace rubinius {
LEAVE_CAPI(env->state());

LookupData lookup(recv, recv->lookup_begin(env->state()), env->state()->globals().sym_private.get());
Arguments args_o(method, recv, block, arg_count, args);
Arguments args_o(method, recv, block, env->current_call_frame(), arg_count, args);
Dispatch dis(method);

Object* ret = dis.send(env->state(), env->current_call_frame(),
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace rubinius {
Symbol* method = (Symbol*)method_name;

LookupData lookup(recv, recv->lookup_begin(env->state()), env->state()->globals().sym_private.get());
Arguments args_o(method, recv, cNil, arg_count, args);
Arguments args_o(method, recv, cNil, NULL, arg_count, args);
Dispatch dis(method);

Object* ret = dis.send(env->state(), env->current_call_frame(),
Expand Down
21 changes: 11 additions & 10 deletions vm/instructions.def
Expand Up @@ -385,6 +385,7 @@ instruction set_local_depth(depth index) [ value -- value ]
}

if(index >= scope->number_of_locals()) {
std::cout << depth << " " << index << " " << scope->number_of_locals() << std::endl;
Exception::internal_error(state, call_frame,
"illegal set_local_depth usage, bad index");
RUN_EXCEPTION();
Expand Down Expand Up @@ -905,7 +906,7 @@ instruction send_method(literal) [ receiver -- value ] => send
Object* recv = stack_top();
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, recv, cNil, 0, 0);
Arguments args(cache->name, recv, cNil, NULL, 0, 0);
Object* ret = cache->execute(state, call_frame, args);

(void)stack_pop();
Expand Down Expand Up @@ -942,7 +943,7 @@ instruction send_stack(literal count) [ receiver +count -- value ] => send
Object* recv = stack_back(count);
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, recv, cNil, count,
Arguments args(cache->name, recv, cNil, NULL, count,
stack_back_position(count));

Object* ret = cache->execute(state, call_frame, args);
Expand Down Expand Up @@ -983,7 +984,7 @@ instruction send_stack_with_block(literal count) [ block receiver +count -- valu
Object* recv = stack_back(count);
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, recv, block, count,
Arguments args(cache->name, recv, block, call_frame, count,
stack_back_position(count));

Object* ret = cache->execute(state, call_frame, args);
Expand Down Expand Up @@ -1026,7 +1027,7 @@ instruction send_stack_with_splat(literal count) [ block array receiver +count -
Object* recv = stack_back(count);
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, recv, block, count,
Arguments args(cache->name, recv, block, call_frame, count,
stack_back_position(count));

if(!ary->nil_p()) {
Expand Down Expand Up @@ -1068,7 +1069,7 @@ instruction send_super_stack_with_block(literal count) [ block +count -- value ]
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);
Object* const recv = call_frame->self();

Arguments new_args(cache->name, recv, block, count,
Arguments new_args(cache->name, recv, block, call_frame, count,
stack_back_position(count));

Object* ret = cache->execute(state, call_frame, new_args);
Expand Down Expand Up @@ -1101,7 +1102,7 @@ instruction send_super_stack_with_splat(literal count) [ block array +count -- v
Object* const recv = call_frame->self();
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments new_args(cache->name, recv, block, count,
Arguments new_args(cache->name, recv, block, call_frame, count,
stack_back_position(count));

if(!ary->nil_p()) {
Expand Down Expand Up @@ -1344,7 +1345,7 @@ instruction yield_stack(count) [ +count -- value ] => yield
} else if(CompiledMethod *cm = try_as<CompiledMethod>(t1)) {
// TODO: We do not need to be doing this everytime.
cm->scope(state, call_frame->previous->constant_scope());
BlockEnvironment* env = BlockEnvironment::under_call_frame(state, gct, cm, call_frame->previous);
BlockEnvironment* env = BlockEnvironment::under_call_frame(state, gct, cm, call_frame->scope->block_frame());
ret = env->call(state, call_frame, args);
} else if(t1->nil_p()) {
state->raise_exception(Exception::make_lje(state, call_frame));
Expand Down Expand Up @@ -2081,7 +2082,7 @@ instruction zsuper(literal) [ block -- value ]

InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments new_args(cache->name, recv, block, arg_count, 0);
Arguments new_args(cache->name, recv, block, call_frame, arg_count, 0);
new_args.use_tuple(tup, arg_count);

Object* ret;
Expand Down Expand Up @@ -2281,7 +2282,7 @@ instruction call_custom(literal count) [ receiver +count -- value ] => send
Object* recv = stack_back(count);
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, recv, cNil, count,
Arguments args(cache->name, recv, cNil, NULL, count,
stack_back_position(count));

Object* ret = cache->execute(state, call_frame, args);
Expand All @@ -2304,7 +2305,7 @@ instruction meta_to_s(literal) [ object -- string ] => send
flush_ip();
InlineCache* cache = reinterpret_cast<InlineCache*>(literal);

Arguments args(cache->name, stack_top(), cNil, 0, 0);
Arguments args(cache->name, stack_top(), cNil, NULL, 0, 0);
Object* ret = cache->execute(state, call_frame, args);
if(ret && !kind_of<String>(ret)) {
ret = stack_top()->to_s(state, false);
Expand Down
1 change: 1 addition & 0 deletions vm/stack_variables.cpp
Expand Up @@ -28,6 +28,7 @@ namespace rubinius {
scope->fiber(state, state->vm()->current_fiber.get());

scope->number_of_locals_ = vmm->number_of_locals;
scope->block_frame_ = block_frame_;

if(full) {
scope->isolated_ = false;
Expand Down
8 changes: 7 additions & 1 deletion vm/stack_variables.hpp
Expand Up @@ -12,16 +12,18 @@ namespace rubinius {
VariableScope* parent_;
Object* self_;
Object* block_;
CallFrame *block_frame_;
Module* module_;
Object* last_match_;
Object* locals_[0];

public:
void initialize(Object* self, Object* block, Module* module, int locals) {
void initialize(Object* self, Object* block, CallFrame *block_frame, Module* module, int locals) {
on_heap_ = 0;
parent_ = 0;
self_ = self;
block_ = block;
block_frame_ = block_frame;
module_ = module;
last_match_ = cNil;

Expand Down Expand Up @@ -50,6 +52,10 @@ namespace rubinius {
return block_;
}

CallFrame* block_frame() {
return block_frame_;
}

Module* module() {
return module_;
}
Expand Down
6 changes: 3 additions & 3 deletions vm/vmmethod.cpp
Expand Up @@ -568,7 +568,7 @@ namespace rubinius {
// look in the wrong place.
//
// Thus, we have to cache the value in the StackVariables.
scope->initialize(args.recv(), args.block(), mod, vmm->number_of_locals);
scope->initialize(args.recv(), args.block(), args.block_call_frame(), mod, vmm->number_of_locals);

InterpreterCallFrame* frame = ALLOCA_CALLFRAME(vmm->stack_size);
frame->prepare(vmm->stack_size);
Expand Down Expand Up @@ -640,13 +640,13 @@ namespace rubinius {
// look in the wrong place.
//
// Thus, we have to cache the value in the StackVariables.
scope->initialize(G(main), cNil, G(object), vmm->number_of_locals);
scope->initialize(G(main), cNil, NULL, G(object), vmm->number_of_locals);

InterpreterCallFrame* frame = ALLOCA_CALLFRAME(vmm->stack_size);

frame->prepare(vmm->stack_size);

Arguments args(state->symbol("__script__"), G(main), cNil, 0, 0);
Arguments args(state->symbol("__script__"), G(main), cNil, NULL, 0, 0);

frame->previous = previous;
frame->flags = 0;
Expand Down

0 comments on commit 29f92c2

Please sign in to comment.