Skip to content

Commit

Permalink
Refactor code out of rubinius::VM
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Phoenix committed Feb 5, 2010
1 parent 588c6a3 commit 9b196bb
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 435 deletions.
1 change: 0 additions & 1 deletion kernel/bootstrap/load_order.txt
Expand Up @@ -24,7 +24,6 @@ proc.rbc
process.rbc
regexp.rbc
rubinius.rbc
scheduler.rbc
selector.rbc
sendsite.rbc
static_scope.rbc
Expand Down
151 changes: 0 additions & 151 deletions kernel/bootstrap/scheduler.rb

This file was deleted.

57 changes: 0 additions & 57 deletions vm/builtin/channel.cpp
Expand Up @@ -164,63 +164,6 @@ namespace rubinius {
}
};

Object* Channel::send_on_signal(STATE, Channel* chan, Fixnum* signal) {
SendToChannel* cb = new SendToChannel(state, chan);
event::Signal* sig = new event::Signal(state, cb, signal->to_native());
state->signal_events->start(sig);
return signal;
}

Object* Channel::send_on_readable(STATE, Channel* chan, IO* io,
Object* maybe_buffer, Fixnum* bytes) {

SendToChannel* cb = new SendToChannel(state, chan);
event::Read* sig = new event::Read(state, cb, io->to_fd());
sig->into_buffer(maybe_buffer, bytes->to_native());

state->events->start(sig);
return io;
}

Object* Channel::send_on_writable(STATE, Channel* chan, IO* io) {
SendToChannel* cb = new SendToChannel(state, chan);
event::Write* sig = new event::Write(state, cb, io->to_fd());

state->events->start(sig);
return io;
}

Object* Channel::send_in_microseconds(STATE, Channel* chan, Integer* useconds, Object* tag) {
double seconds = useconds->to_native() / 1000000.0;

return send_in_seconds(state, chan, seconds, tag);
}

Object* Channel::send_in_seconds(STATE, Channel* chan, Float* seconds, Object* tag) {
double secs = seconds->to_double(state);
return send_in_seconds(state, chan, secs, tag);
}

Object* Channel::send_in_seconds(STATE, Channel* chan, double seconds, Object* tag) {
SendToChannel* cb = new SendToChannel(state, chan);
event::Timer* sig = new event::Timer(state, cb, seconds, tag);
state->events->start(sig);
return Qnil;
}

Object* Channel::send_on_stopped(VM* state, Channel* channel, Fixnum* pid, Fixnum* flags)
{
event::Child::add(state,
new SendToChannel(state, channel),
static_cast<pid_t>(pid->to_int()),
flags->to_int() );

/* @todo Figure out the cancellation by id method. */
return Qnil;
}



/* ChannelCallback */

ChannelCallback::ChannelCallback(STATE, Channel* chan) : ObjectCallback(state) {
Expand Down
22 changes: 0 additions & 22 deletions vm/builtin/channel.hpp
Expand Up @@ -58,28 +58,6 @@ namespace rubinius {

bool has_readers_p();

// Ruby.primitive :scheduler_send_on_signal
static Object* send_on_signal(STATE, Channel* chan, Fixnum* signal);

// Ruby.primitive :scheduler_send_on_readable
static Object* send_on_readable(STATE, Channel* chan, IO* io, Object* maybe_buffer, Fixnum* bytes);

// Ruby.primitive :scheduler_send_on_writable
static Object* send_on_writable(STATE, Channel* chan, IO* io);

// Ruby.primitive :scheduler_send_in_microseconds
static Object* send_in_microseconds(STATE, Channel* chan, Integer* useconds, Object* tag);

// Ruby.primitive :scheduler_send_in_seconds
static Object* send_in_seconds(STATE, Channel* chan, Float* seconds, Object* tag);
static Object* send_in_seconds(STATE, Channel* chan, double seconds, Object* tag);

/**
* Event child process ending.
*/
// Ruby.primitive :scheduler_send_on_stopped
static Object* send_on_stopped(STATE, Channel* channel, Fixnum* pid, Fixnum* flags);


class Info : public TypeInfo {
public:
Expand Down
10 changes: 7 additions & 3 deletions vm/builtin/data.cpp
Expand Up @@ -5,6 +5,8 @@

#include "gc/gc.hpp"

#include "capi/capi.hpp"

namespace rubinius {

void Data::init(STATE) {
Expand Down Expand Up @@ -33,10 +35,12 @@ namespace rubinius {
Data* data = as<Data>(t);

if(data->mark()) {
ObjectMark* cur = VM::current_state()->current_mark;
VM::current_state()->current_mark = &mark;
ObjectMark* cur = capi::current_mark();
capi::set_current_mark(&mark);

(*data->mark())(data->data());
VM::current_state()->current_mark = cur;

capi::set_current_mark(cur);
}

// Data's can be written to without write barriers running,
Expand Down
3 changes: 0 additions & 3 deletions vm/builtin/io.cpp
Expand Up @@ -307,7 +307,6 @@ namespace rubinius {
break;

case 0:
// state->events->clear_by_fd(desc);
break;

default:
Expand Down Expand Up @@ -351,8 +350,6 @@ namespace rubinius {
descriptor(state, Fixnum::from(-2));
}

/** @todo Fix when can only remove read or write events. --rue */
state->events->clear_by_fd(desc);
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/module.cpp
Expand Up @@ -107,7 +107,7 @@ namespace rubinius {
void Module::add_method(STATE, Symbol* name, Executable* exec, Symbol* vis) {
if(!vis) vis = G(sym_public);
method_table_->store(state, name, exec, vis);
state->global_cache->clear(this, name);
state->global_cache()->clear(this, name);
}

Executable* Module::find_method(Symbol* name, Module** defined_in) {
Expand Down
12 changes: 6 additions & 6 deletions vm/builtin/symbol.cpp
Expand Up @@ -33,27 +33,27 @@ namespace rubinius {
}

String* Symbol::to_str(STATE) {
return state->symbols.lookup_string(state, this);
return state->shared.symbols.lookup_string(state, this);
}

const char* Symbol::c_str(STATE) const {
return state->symbols.lookup_cstring(state, this);
return state->shared.symbols.lookup_cstring(state, this);
}

Array* Symbol::all_symbols(STATE) {
return state->symbols.all_as_array(state);
return state->shared.symbols.all_as_array(state);
}

Object* Symbol::is_ivar_p(STATE) {
return state->symbols.kind(state, this) == SymbolTable::IVar ? Qtrue : Qfalse;
return state->shared.symbols.kind(state, this) == SymbolTable::IVar ? Qtrue : Qfalse;
}

Object* Symbol::is_cvar_p(STATE) {
return state->symbols.kind(state, this) == SymbolTable::CVar ? Qtrue : Qfalse;
return state->shared.symbols.kind(state, this) == SymbolTable::CVar ? Qtrue : Qfalse;
}

Object* Symbol::is_constant_p(STATE) {
return state->symbols.kind(state, this) == SymbolTable::Constant ? Qtrue : Qfalse;
return state->shared.symbols.kind(state, this) == SymbolTable::Constant ? Qtrue : Qfalse;
}

void Symbol::Info::show(STATE, Object* self, int level) {
Expand Down
2 changes: 1 addition & 1 deletion vm/builtin/system.cpp
Expand Up @@ -301,7 +301,7 @@ namespace rubinius {

Object* System::vm_reset_method_cache(STATE, Symbol* name) {
// 1. clear the global cache
state->global_cache->clear(name);
state->global_cache()->clear(name);

state->shared.ic_registry()->clear(name);
return name;
Expand Down
3 changes: 3 additions & 0 deletions vm/capi/capi.hpp
Expand Up @@ -21,6 +21,9 @@ namespace rubinius {

namespace capi {

/** Set what ObjectMark* object should be used by C-API */
void set_current_mark(ObjectMark* mark);
ObjectMark* current_mark();

Symbol* prefixed_by(std::string prefix, std::string name);
Symbol* prefixed_by(std::string prefix, ID name);
Expand Down
18 changes: 17 additions & 1 deletion vm/capi/gc.cpp
@@ -1,11 +1,27 @@
#include "builtin/object.hpp"
#include "util/thread.hpp"

#include "capi/capi.hpp"
#include "capi/ruby.h"

using namespace rubinius;
using namespace rubinius::capi;


static thread::ThreadData<ObjectMark*> _current_mark;

namespace rubinius {
namespace capi {
void set_current_mark(ObjectMark* mark) {
_current_mark.set(mark);
}

ObjectMark* current_mark() {
return _current_mark.get();
}
}
}

extern "C" {
VALUE rb_gc_start() {
VALUE gc_class_handle = rb_const_get(rb_cObject, rb_intern("GC"));
Expand All @@ -20,7 +36,7 @@ extern "C" {
void rb_gc_mark(VALUE ptr) {
Handle* handle = Handle::from(ptr);
if(CAPI_REFERENCE_P(handle) && handle->object()->reference_p()) {
Object* res = VM::current_state()->current_mark->call(handle->object());
Object* res = capi::current_mark()->call(handle->object());
if(res) {
handle->set_object(res);
}
Expand Down

0 comments on commit 9b196bb

Please sign in to comment.