Esempio n. 1
0
reader_t
open(const std::string& file)
{
	const p_ply pply = ply_open(file.c_str(), nullptr, 0, nullptr);
    if (!pply)
    	throw std::runtime_error("Can't open file: " + file);

	const std::shared_ptr<t_ply_> ply(pply, ply_close);
    if (!ply_read_header(ply.get()))
    	throw std::runtime_error("Can't read header: " + file);

    return reader_t(ply);
}
Esempio n. 2
0
void
VM::boot()
{
    try {
#if USE_DEBUG_BOOT
        {
            char load_path[] = "heap/debug-boot.vmi";
            m_bootport = make_file_port(m_heap, make_string_literal(m_heap, load_path), SCM_PORT_DIRECTION_IN, 0, SCM_PORT_BUFFER_MODE_BLOCK, scm_true);
            printf(";; loading \"%s\"\n", load_path);
            fflush(stdout);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#else
        {
            scm_bvector_t bv = make_bvector_mapping(m_heap, (void*)s_bootimage, sizeof(s_bootimage));
            m_bootport = make_bytevector_port(m_heap, make_symbol(m_heap, "bootimage"), SCM_PORT_DIRECTION_IN, bv, scm_true);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#endif
        m_bootport = (scm_port_t)scm_unspecified;
        m_current_environment = m_heap->m_interaction_environment;
#if USE_DEBUG_CORE
        {
            char load_path[] = "heap/debug-core.vmi";
            m_bootport = make_file_port(m_heap, make_string_literal(m_heap, load_path), SCM_PORT_DIRECTION_IN, 0, SCM_PORT_BUFFER_MODE_BLOCK, scm_true);
            printf(";; loading \"%s\"\n", load_path);
            fflush(stdout);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#elif USE_INTERNED_CORE
        {
            scm_bvector_t bv = make_bvector_mapping(m_heap, (void*)s_coreimage, sizeof(s_coreimage));
            m_bootport = make_bytevector_port(m_heap, make_symbol(m_heap, "bootimage"), SCM_PORT_DIRECTION_IN, bv, scm_true);
            scoped_lock lock_port(m_bootport->lock);
            while (true) {
                reset();
                scm_obj_t obj = reader_t(this, m_bootport).read(NULL);
                if (obj == scm_eof) break;
                m_pc = obj;
                prebind(m_pc);
                run(false);
            }
            port_close(m_bootport);
        }
#endif
        m_bootport = (scm_port_t)scm_unspecified;
    } catch (vm_exception_t& e) {
        fatal("fatal in boot: unexpected vm_exception_t");
    } catch (reader_exception_t& e) {
        fatal("fatal in boot: unexpected reader_expecption_t(%s)", e.m_message);
    } catch (io_exception_t& e) {
        fatal("fatal in boot: unexpected io_expecption_t(%d, %s)", e.m_err, e.m_message);
    } catch (io_codec_exception_t& e) {
        fatal("fatal in boot: unexpected io_codec_exception_t(%d, %s)", e.m_operation, e.m_message);
    } catch (vm_escape_t& e) {
        fatal("fatal in boot: unexpected vm_escape_t, maybe <#subr escape> in bad context");
    } catch (vm_continue_t& e) {
        fatal("fatal in boot: unexpected vm_continue_t, maybe <#subr escape> in bad context");
    } catch (int code) {
        fatal("fatal in boot: unexpected system error (errno %d, %s)", code, strerror(code));
    } catch (...) {
        fatal("fatal in boot: unknown exception");
    }
  #if PROFILE_OPCODE
    memset(m_opcode_profile, 0, sizeof(m_opcode_profile));
  #endif
}