本文整理汇总了C++中CompiledFile类的典型用法代码示例。如果您正苦于以下问题:C++ CompiledFile类的具体用法?C++ CompiledFile怎么用?C++ CompiledFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompiledFile类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_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);
}
示例2: stream
void Environment::run_file(std::string file) {
if(!state->probe->nil_p()) state->probe->load_runtime(state, file);
std::ifstream stream(file.c_str());
if(!stream) throw std::runtime_error("Unable to open file to run");
CompiledFile* cf = CompiledFile::load(stream);
if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");
// TODO check version number
cf->execute(state);
if(!G(current_task)->exception()->nil_p()) {
// Reset the context so we can show the backtrace
// HACK need to use write barrier aware stuff?
Exception* exc = G(current_task)->exception();
G(current_task)->active(state, exc->context());
std::ostringstream msg;
msg << "exception detected at toplevel: ";
if(!exc->message()->nil_p()) {
msg << exc->message()->c_str();
}
msg << " (" << exc->klass()->name()->c_str(state) << ")";
Assertion::raise(msg.str().c_str());
}
}
示例3: main
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;
}
示例4: test_load_file
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);
}
示例5: stream
void Environment::run_file(std::string file) {
std::ifstream stream(file.c_str());
if(!stream) {
std::string msg = std::string("Unable to open file to run: ");
msg.append(file);
throw std::runtime_error(msg);
}
CompiledFile* cf = CompiledFile::load(stream);
if(cf->magic != "!RBIX") {
std::ostringstream msg;
msg << "attempted to open a bytecode file with invalid magic identifier"
<< ": path: " << file << ", magic: " << cf->magic;
throw std::runtime_error(msg.str().c_str());
}
if((signature_ > 0 && cf->signature != signature_)
|| cf->version != version_) {
throw BadKernelFile(file);
}
cf->execute(state);
if(state->vm()->thread_state()->raise_reason() == cException) {
Exception* exc = as<Exception>(state->vm()->thread_state()->current_exception());
std::ostringstream msg;
msg << "exception detected at toplevel: ";
if(!exc->reason_message()->nil_p()) {
if(String* str = try_as<String>(exc->reason_message())) {
msg << str->c_str(state);
} else {
msg << "<non-string Exception message>";
}
} else if(Exception::argument_error_p(state, exc)) {
msg << "given "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@given")))->to_native()
<< ", expected "
<< as<Fixnum>(exc->get_ivar(state, state->symbol("@expected")))->to_native();
}
msg << " (" << exc->klass()->debug_str(state) << ")";
std::cout << msg.str() << "\n";
exc->print_locations(state);
Assertion::raise(msg.str().c_str());
}
delete cf;
}
示例6: stream
//
// 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);
}
示例7: stream
//
// 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;
}
示例8: prettyprint_in_file
void AST_t::prettyprint_in_file(const CompiledFile& compiled_file, bool internal) const
{
if (!internal)
{
prettyprint_set_not_internal_output();
}
else
{
prettyprint_set_internal_output();
}
FILE *file = fopen(compiled_file.get_filename().c_str(), "a");
if (file == NULL)
{
running_error("Could not open output file '%s' (%s)\n",
compiled_file.get_filename().c_str(),
strerror(errno));
}
::prettyprint(file, this->_ast);
fclose(file);
}