Skip to content

Commit

Permalink
More fixes for new CAPI CallFrames
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jun 7, 2011
1 parent f5bbeff commit cd104c1
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 14 deletions.
10 changes: 4 additions & 6 deletions vm/builtin/block_environment.cpp
Expand Up @@ -236,7 +236,10 @@ namespace rubinius {
}

Object* BlockEnvironment::of_sender(STATE, CallFrame* call_frame) {
NativeMethodEnvironment* nme = NativeMethodEnvironment::get();
if(NativeMethodFrame* nmf = call_frame->previous->native_method_frame()) {
return NativeMethodEnvironment::get()->get_object(nmf->block());
}

CallFrame* target = call_frame->previous->top_ruby_frame();

// We assume that code using this is going to use it over and
Expand All @@ -245,11 +248,6 @@ namespace rubinius {

target->cm->backend_method()->set_no_inline();

if(nme->current_call_frame() == call_frame->previous) {
NativeMethodFrame* nmf = nme->current_native_frame();
if(nmf) return nme->get_object(nmf->block());
}

if(target && target->scope) {
return target->scope->block();
}
Expand Down
4 changes: 4 additions & 0 deletions vm/builtin/location.cpp
Expand Up @@ -22,6 +22,10 @@ namespace rubinius {
Location* Location::create(STATE, CallFrame* call_frame,
bool include_variables)
{
if(NativeMethodFrame* nmf = call_frame->native_method_frame()) {
return create(state, nmf);
}

Location* loc = state->new_object<Location>(G(location));
loc->method_module(state, call_frame->module());
loc->receiver(state, call_frame->self());
Expand Down
1 change: 1 addition & 0 deletions vm/builtin/nativemethod.cpp
Expand Up @@ -645,6 +645,7 @@ namespace rubinius {
CallFrame cf;
cf.previous = call_frame;
cf.cm = 0;
cf.scope = 0;
cf.dispatch_data = (void*)&nmf;
cf.flags = CallFrame::cNativeMethod;

Expand Down
4 changes: 2 additions & 2 deletions vm/builtin/regexp.cpp
Expand Up @@ -624,7 +624,7 @@ namespace rubinius {
Object* Regexp::last_match_result(STATE, Fixnum* mode, Fixnum* which,
CallFrame* call_frame)
{
Object* current_match = call_frame->top_ruby_frame()->last_match(state);
Object* current_match = call_frame->last_match(state);

if(MatchData* match = try_as<MatchData>(current_match)) {
switch(mode->to_native()) {
Expand Down Expand Up @@ -667,7 +667,7 @@ namespace rubinius {
}

if(CallFrame* parent = call_frame->previous) {
parent->top_ruby_frame()->set_last_match(state, obj);
parent->set_last_match(state, obj);
}

return obj;
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/thread.cpp
Expand Up @@ -119,7 +119,7 @@ namespace rubinius {
if(!native_thread_) return nil<Tuple>();

VM* vm = native_thread_->vm();
CallFrame* cf = vm->saved_call_frame();
CallFrame* cf = vm->saved_call_frame()->top_ruby_frame();

VariableScope* scope = cf->promote_scope(state);

Expand Down
33 changes: 28 additions & 5 deletions vm/call_frame.cpp
Expand Up @@ -9,12 +9,13 @@
#include "builtin/tuple.hpp"
#include "builtin/staticscope.hpp"
#include "builtin/lookuptable.hpp"
#include "builtin/nativemethod.hpp"

#include "object_utils.hpp"

namespace rubinius {
Object* CallFrame::last_match(STATE) {
CallFrame* use = this;
CallFrame* use = this->top_ruby_frame();;

while(use && use->is_inline_block()) {
CallFrame* yielder = use->previous;
Expand All @@ -29,7 +30,7 @@ namespace rubinius {
}

void CallFrame::set_last_match(STATE, Object* obj) {
CallFrame* use = this;
CallFrame* use = this->top_ruby_frame();

while(use && use->is_inline_block()) {
CallFrame* yielder = use->previous;
Expand Down Expand Up @@ -73,12 +74,26 @@ namespace rubinius {
CallFrame* cf = this;

while(cf) {
if(!cf->cm) {
stream << static_cast<void*>(cf) << ": ";

if(NativeMethodFrame* nmf = cf->native_method_frame()) {
NativeMethod* nm = try_as<NativeMethod>(nmf->get_object(nmf->method()));
if(nm || !nm->name()->symbol_p()) {
stream << "capi:" << nm->name()->c_str(state) << " at ";
stream << nm->file()->c_str(state);
} else {
stream << "unknown capi";
}

stream << std::endl;
cf = static_cast<CallFrame*>(cf->previous);
continue;
}

stream << static_cast<void*>(cf) << ": ";
if(!cf->cm) {
cf = static_cast<CallFrame*>(cf->previous);
continue;
}

if(cf->is_block_p(state)) {
stream << "__block__";
Expand Down Expand Up @@ -151,7 +166,7 @@ namespace rubinius {
bool CallFrame::scope_still_valid(VariableScope* scope) {
CallFrame* cur = this;
while(cur) {
if(cur->scope->on_heap() == scope) return true;
if(cur->scope && cur->scope->on_heap() == scope) return true;
cur = static_cast<CallFrame*>(cur->previous);
}

Expand All @@ -161,6 +176,12 @@ namespace rubinius {
void CallFrame::dump() {
VM* state = VM::current_state();
std::cout << "<CallFrame:" << (void*)this << " ";

if(native_method_p()) {
std::cout << "capi>\n";
return;
}

if(is_inline_frame()) {
std::cout << "inline ";
}
Expand All @@ -181,6 +202,8 @@ namespace rubinius {
}

Object* CallFrame::find_breakpoint(STATE) {
if(!cm) return 0;

LookupTable* tbl = cm->breakpoints();
if(tbl->nil_p()) return 0;

Expand Down
1 change: 1 addition & 0 deletions vm/call_frame.hpp
Expand Up @@ -245,6 +245,7 @@ namespace rubinius {
VariableScope* promote_scope_full(STATE);

VariableScope* promote_scope(STATE) {
if(!scope) rubinius::bug("bad CallFrame to promote");
if(VariableScope* vs = scope->on_heap()) return vs;
return promote_scope_full(state);
}
Expand Down
9 changes: 9 additions & 0 deletions vm/helpers.cpp
Expand Up @@ -49,6 +49,8 @@ namespace rubinius {

*found = false;

call_frame = call_frame->top_ruby_frame();

// Ok, this has to be explained or it will be considered black magic.
// The scope chain always ends with an entry at the top that contains
// a parent of nil, and a module of Object. This entry is put in
Expand Down Expand Up @@ -117,6 +119,9 @@ namespace rubinius {

Object* const_missing(STATE, Symbol* sym, CallFrame* call_frame) {
Module* under;

call_frame = call_frame->top_ruby_frame();

StaticScope* scope = call_frame->static_scope();
if(scope->nil_p()) {
under = G(object);
Expand Down Expand Up @@ -146,6 +151,8 @@ namespace rubinius {
Class* open_class(STATE, CallFrame* call_frame, Object* super, Symbol* name, bool* created) {
Module* under;

call_frame = call_frame->top_ruby_frame();

if(call_frame->static_scope()->nil_p()) {
under = G(object);
} else {
Expand Down Expand Up @@ -214,6 +221,8 @@ namespace rubinius {
Module* open_module(STATE, CallFrame* call_frame, Symbol* name) {
Module* under = G(object);

call_frame = call_frame->top_ruby_frame();

if(!call_frame->static_scope()->nil_p()) {
under = call_frame->static_scope()->module();
}
Expand Down

0 comments on commit cd104c1

Please sign in to comment.