Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 70 lines (55 sloc) 1.802 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
/* A CompiledFile represents a .rbc. This class understands the layout
* of a .rbc file. It can validate and load the body into a CompiledMethod
* object.
*
* CompiledFile::execute is a root stack frame in Rubinius. It's where
* primary execution begins, when the VM loads the loader.rbc and executes
* it. */

#include "compiled_file.hpp"
#include "marshal.hpp"
#include "message.hpp"
#include "objectmemory.hpp"
#include "object_utils.hpp"

#include "builtin/task.hpp"
#include "builtin/staticscope.hpp"
#include "builtin/compiledmethod.hpp"
#include "builtin/class.hpp"
#include "builtin/thread.hpp"


namespace rubinius {
  CompiledFile* CompiledFile::load(std::istream& stream) {
    std::string magic, sum;
    long ver;

    stream >> magic;
    stream >> ver;
    stream >> sum;
    stream.get(); // eat the \n

    return new CompiledFile(magic, ver, sum, &stream);
  }

  Object* CompiledFile::body(STATE) {
    UnMarshaller mar(state, *stream);
    return mar.unmarshal();
  }

  bool CompiledFile::execute(STATE) {
    Task* task = state->new_task();
    TypedRoot<CompiledMethod*> cm(state, as<CompiledMethod>(body(state)));

    Message msg(state);
    msg.setup(NULL, G(main), task->active(), 0, 0);
    msg.name = cm->name();
    msg.module = G(object);
    msg.method = cm.get();

    G(current_thread)->task(state, task);
    state->activate_task(task);

    cm.get()->scope(state, StaticScope::create(state));
    cm.get()->scope()->module(state, G(object));

    cm->execute(state, G(current_task), msg);
    try {
      state->run_and_monitor();
    } catch(Task::Halt &e) {
      return true;
    }

    // Task::execute contains the safe point, thus the above Task
    // and CompiledMethod pointers have likely been moved. DO NOT
    // USE THEM.

    return false;
  }
}
Something went wrong with that request. Please try again.