mirror of
https://github.com/matrix-construct/construct
synced 2025-01-13 08:23:56 +01:00
ircd::js: Checkpoint corrections to XDR; esr52.
This commit is contained in:
parent
9a579c8dcb
commit
da04032cc4
2 changed files with 101 additions and 48 deletions
|
@ -31,9 +31,9 @@ struct xdr
|
|||
struct object;
|
||||
|
||||
const struct header *header;
|
||||
const struct sourcecode *sourcecode;
|
||||
const struct atom *name;
|
||||
const struct binding *binding;
|
||||
const struct sourcecode *sourcecode;
|
||||
const struct sourcemap *sourcemap;
|
||||
const struct displayurl *displayurl;
|
||||
const struct filename *filename;
|
||||
|
@ -51,18 +51,13 @@ struct xdr
|
|||
void for_each_const(const std::function<void (const struct consts &)> &) const;
|
||||
void for_each_object(const std::function<void (const struct object &)> &) const;
|
||||
|
||||
xdr(const uint8_t *const &buffer, const size_t &len);
|
||||
xdr(const const_buffer &);
|
||||
};
|
||||
|
||||
struct xdr::header
|
||||
{
|
||||
uint32_t magic;
|
||||
uint16_t n_args;
|
||||
uint16_t n_block_locals;
|
||||
uint16_t n_body_level_lexicals;
|
||||
uint32_t n_vars;
|
||||
uint32_t n_unaliased_vars;
|
||||
uint16_t n_unaliased_body_level_lexicals;
|
||||
uint32_t build_id_length;
|
||||
uint32_t build_id;
|
||||
uint32_t length;
|
||||
uint32_t prologue_length;
|
||||
uint32_t version;
|
||||
|
@ -70,9 +65,9 @@ struct xdr::header
|
|||
uint32_t n_srcnotes;
|
||||
uint32_t n_consts;
|
||||
uint32_t n_objects;
|
||||
uint32_t n_regexps;
|
||||
uint32_t n_scopes;
|
||||
uint32_t n_try_notes;
|
||||
uint32_t n_block_scopes;
|
||||
uint32_t n_scope_notes;
|
||||
uint32_t n_yield_offsets;
|
||||
uint32_t n_typesets;
|
||||
uint32_t fun_length;
|
||||
|
@ -80,28 +75,10 @@ struct xdr::header
|
|||
|
||||
size_t num_names() const;
|
||||
size_t num_bindings() const;
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
struct xdr::atom
|
||||
{
|
||||
uint32_t encoding : 1;
|
||||
uint32_t length : 31; union
|
||||
{
|
||||
const char latin1[0];
|
||||
const char16_t two_byte[0];
|
||||
};
|
||||
}
|
||||
__attribute__((packed));
|
||||
static_assert(sizeof(struct xdr::atom) == 4, "");
|
||||
|
||||
struct xdr::binding
|
||||
{
|
||||
uint8_t aliased : 1;
|
||||
uint8_t kind : 7;
|
||||
}
|
||||
__attribute__((packed));
|
||||
static_assert(sizeof(struct xdr::binding) == 1, "");
|
||||
// debug print
|
||||
friend std::ostream &operator<<(std::ostream &, const header &);
|
||||
};
|
||||
|
||||
struct xdr::sourcecode
|
||||
{
|
||||
|
@ -111,6 +88,9 @@ struct xdr::sourcecode
|
|||
uint32_t compressed_length;
|
||||
uint8_t arguments_not_included;
|
||||
const char16_t code[0];
|
||||
|
||||
// debug print
|
||||
friend std::ostream &operator<<(std::ostream &, const sourcecode &);
|
||||
}
|
||||
__attribute__((packed));
|
||||
|
||||
|
@ -119,16 +99,14 @@ struct xdr::sourcemap
|
|||
uint8_t have;
|
||||
uint32_t len;
|
||||
const char16_t url[0];
|
||||
}
|
||||
__attribute__((packed));
|
||||
};
|
||||
|
||||
struct xdr::displayurl
|
||||
{
|
||||
uint8_t have;
|
||||
uint32_t len;
|
||||
const char16_t url[0];
|
||||
}
|
||||
__attribute__((packed));
|
||||
};
|
||||
|
||||
struct xdr::filename
|
||||
{
|
||||
|
@ -136,13 +114,34 @@ struct xdr::filename
|
|||
const char name[0];
|
||||
};
|
||||
|
||||
struct xdr::atom
|
||||
{
|
||||
uint32_t encoding : 1;
|
||||
uint32_t length : 31; union
|
||||
{
|
||||
const char latin1[0];
|
||||
const char16_t two_byte[0];
|
||||
};
|
||||
};
|
||||
static_assert(sizeof(struct xdr::atom) == 4, "");
|
||||
|
||||
struct xdr::binding
|
||||
{
|
||||
uint8_t aliased : 1;
|
||||
uint8_t kind : 7;
|
||||
};
|
||||
static_assert(sizeof(struct xdr::binding) == 1, "");
|
||||
|
||||
struct xdr::source
|
||||
{
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
uint32_t lineno;
|
||||
uint32_t column;
|
||||
uint32_t nfixed;
|
||||
uint32_t nslots;
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &, const source &);
|
||||
};
|
||||
|
||||
struct xdr::bytecode
|
||||
|
|
78
ircd/xdr.cc
78
ircd/xdr.cc
|
@ -23,19 +23,78 @@ decltype(xdr::bytecode::info) xdr::bytecode::info
|
|||
} // namespace js
|
||||
} // namespace ircd
|
||||
|
||||
ircd::js::xdr::xdr(const uint8_t *const &buf,
|
||||
const size_t &len)
|
||||
std::ostream &
|
||||
ircd::js::operator<<(std::ostream &s, const struct xdr::header &h)
|
||||
{
|
||||
s << std::setw(34) << std::left << "build_id_length" << h.build_id_length << std::endl;
|
||||
s << std::setw(34) << std::left << "build_id" << h.build_id << std::endl;
|
||||
s << std::setw(34) << std::left << "length" << h.length << std::endl;
|
||||
s << std::setw(34) << std::left << "prologue_length" << h.prologue_length << std::endl;
|
||||
s << std::setw(34) << std::left << "version" << h.version << std::endl;
|
||||
s << std::setw(34) << std::left << "n_atoms" << h.n_atoms << std::endl;
|
||||
s << std::setw(34) << std::left << "n_srcnotes" << h.n_srcnotes << std::endl;
|
||||
s << std::setw(34) << std::left << "n_consts" << h.n_consts << std::endl;
|
||||
s << std::setw(34) << std::left << "n_objects" << h.n_objects << std::endl;
|
||||
s << std::setw(34) << std::left << "n_scopes" << h.n_scopes << std::endl;
|
||||
s << std::setw(34) << std::left << "n_try_notes" << h.n_try_notes << std::endl;
|
||||
s << std::setw(34) << std::left << "n_scope_notes" << h.n_scope_notes << std::endl;
|
||||
s << std::setw(34) << std::left << "n_yield_offsets" << h.n_yield_offsets << std::endl;
|
||||
s << std::setw(34) << std::left << "n_typesets" << h.n_typesets << std::endl;
|
||||
s << std::setw(34) << std::left << "fun_length" << h.fun_length << std::endl;
|
||||
s << std::setw(34) << std::left << "script_bits" << h.script_bits << std::endl;
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
ircd::js::operator<<(std::ostream &s, const struct xdr::sourcecode &h)
|
||||
{
|
||||
s << std::setw(34) << std::left << "has_source" << bool(h.has_source) << std::endl;
|
||||
s << std::setw(34) << std::left << "retrievable" << bool(h.retrievable) << std::endl;
|
||||
s << std::setw(34) << std::left << "length" << h.length << std::endl;
|
||||
s << std::setw(34) << std::left << "compressed_length" << h.compressed_length << std::endl;
|
||||
s << std::setw(34) << std::left << "arguments_not_included" << bool(h.arguments_not_included) << std::endl;
|
||||
return s;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
ircd::js::operator<<(std::ostream &s, const struct xdr::source &h)
|
||||
{
|
||||
s << std::setw(34) << std::left << "start" << h.start << std::endl;
|
||||
s << std::setw(34) << std::left << "end" << h.end << std::endl;
|
||||
s << std::setw(34) << std::left << "lineno" << h.lineno << std::endl;
|
||||
s << std::setw(34) << std::left << "column" << h.column << std::endl;
|
||||
s << std::setw(34) << std::left << "nfixed" << h.nfixed << std::endl;
|
||||
s << std::setw(34) << std::left << "nslots" << h.nslots << std::endl;
|
||||
return s;
|
||||
}
|
||||
|
||||
__attribute__((optimize("-O0")))
|
||||
ircd::js::xdr::xdr(const const_buffer &buf)
|
||||
:header
|
||||
{
|
||||
reinterpret_cast<const struct header *>(buf)
|
||||
reinterpret_cast<const struct header *>(data(buf))
|
||||
}
|
||||
,sourcecode{[this]() -> const struct sourcecode *
|
||||
{
|
||||
if(this->header->script_bits & ~(1 << 14))
|
||||
return nullptr;
|
||||
|
||||
return reinterpret_cast<const struct sourcecode *>(this->header + 1);
|
||||
}()}
|
||||
/*
|
||||
,name
|
||||
{
|
||||
reinterpret_cast<const struct atom *>(buf + sizeof(*header))
|
||||
reinterpret_cast<const struct atom *>(data(buf) + sizeof(struct header))
|
||||
}
|
||||
,binding{[this]
|
||||
{
|
||||
const auto *ret(reinterpret_cast<const uint8_t *>(this->name));
|
||||
std::cout << *this->header << std::endl;
|
||||
|
||||
const auto *ret
|
||||
{
|
||||
reinterpret_cast<const uint8_t *>(this->name)
|
||||
};
|
||||
|
||||
for_each_name([&ret](const struct atom &atom)
|
||||
{
|
||||
ret += sizeof(struct atom) + atom.length;
|
||||
|
@ -43,12 +102,6 @@ ircd::js::xdr::xdr(const uint8_t *const &buf,
|
|||
|
||||
return reinterpret_cast<const struct binding *>(ret);
|
||||
}()}
|
||||
,sourcecode{[this]
|
||||
{
|
||||
const auto bindings(header->num_bindings());
|
||||
const auto *ptr(reinterpret_cast<const uint8_t *>(this->binding + bindings));
|
||||
return reinterpret_cast<const struct sourcecode *>(ptr);
|
||||
}()}
|
||||
,sourcemap{[this]
|
||||
{
|
||||
const auto *ptr(reinterpret_cast<const uint8_t *>(this->sourcecode + 1) + this->sourcecode->compressed_length);
|
||||
|
@ -122,6 +175,7 @@ ircd::js::xdr::xdr(const uint8_t *const &buf,
|
|||
|
||||
return reinterpret_cast<const struct object *>(ptr);
|
||||
}()}
|
||||
*/
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -215,7 +269,7 @@ size_t
|
|||
ircd::js::xdr::header::num_names()
|
||||
const
|
||||
{
|
||||
return n_args + n_vars + n_body_level_lexicals;
|
||||
return 0;//return n_args + n_vars + n_body_level_lexicals;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue