Exemple #1
0
  //
  // HACK: remove this when performance is better and compiled_file.rb
  // unmarshal_data method works.
  Object* System::compiledfile_load(STATE, String* path, Integer* version) {
    if(!state->probe->nil_p()) {
      state->probe->load_runtime(state, std::string(path->c_str()));
    }

    std::ifstream stream(path->c_str());
    if(!stream) {
      return Primitives::failure();
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      return Primitives::failure();
    }

    uint64_t ver = version->to_ulong_long();
    if(ver > 0 && cf->version > 0 && cf->version != ver) {
      return Primitives::failure();
    }

    Object *body = cf->body(state);

    delete cf;
    return body;
  }
  void test_body() {
    std::istringstream stream;
    stream.str("!RBIX\n1\n42\nt");

    CompiledFile* cf = CompiledFile::load(stream);
    TS_ASSERT_EQUALS(cf->body(state), cTrue);
  }
Exemple #3
0
int main(int argc, char **argv) {
  JITCompiler compiler;
  VMManager * manager = new VMManager;
  SharedState * shared = manager->create_shared_state();
  ConfigParser * config = new ConfigParser;
  shared->user_config = config;
  VM* state = shared->thread_nexus()->new_vm();

  state->initialize(VM::default_bytes);
  state->boot();

  state->global_lock().lock();

  std::ifstream stream(argv[1]);
  if(!stream) {
    cout << "Can't open ' " << argv[1] << "'\n";
    return 1;
  }

  CompiledFile* cf = CompiledFile::load(state, stream);
  if(cf->magic != "!RBIX") {
    cout << "Invalid file.\n";
  }

  MachineCode* mcode = as<CompiledCode>(cf->body(state))->formalize(state, false);

  delete cf;

  compiler.compile(state, mcode);
  MachineMethod* mm = MachineMethod::create(state, mcode, compiler);
  mm->show();
  return 0;
}
  void test_load_file() {
    std::fstream stream("vm/test/fixture.rbc_");
    TS_ASSERT(!!stream);

    CompiledFile* cf = CompiledFile::load(stream);
    TS_ASSERT_EQUALS(cf->magic, "!RBIX");

    CompiledCode* code = try_as<CompiledCode>(cf->body(state));
    TS_ASSERT(code);
  }
Exemple #5
0
  //
  // HACK: remove this when performance is better and compiled_file.rb
  // unmarshal_data method works.
  Object* System::compiledfile_load(STATE, String* path, Object* version) {
    if(!state->probe->nil_p()) {
      state->probe->load_runtime(state, std::string(path->c_str()));
    }

    std::ifstream stream(path->c_str());
    if(!stream) {
      std::ostringstream msg;
      msg << "unable to open file to run: " << path->c_str();
      Exception::io_error(state, msg.str().c_str());
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      std::ostringstream msg;
      msg << "Invalid file: " << path->c_str();
      Exception::io_error(state, msg.str().c_str());
    }

    return cf->body(state);
  }
Exemple #6
0
  //
  // HACK: remove this when performance is better and compiled_file.rb
  // unmarshal_data method works.
  Object* System::compiledfile_load(STATE, String* path, Integer* version) {
    std::ifstream stream(path->c_str(state));
    if(!stream) {
      return Primitives::failure();
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      delete cf;
      return Primitives::failure();
    }

    uint64_t ver = version->to_ulong_long();
    if((ver > 0 && cf->version != ver) || cf->sum != "x") {
      delete cf;
      return Primitives::failure();
    }

    Object *body = cf->body(state);

    delete cf;
    return body;
  }