unexpose raw bytecode ref/unref (always use Bytecode objects)

master
Daniel Kolesa 2015-12-24 15:57:19 +01:00
parent fa4381000e
commit 22f9373fe7
2 changed files with 24 additions and 19 deletions

View File

@ -2435,6 +2435,25 @@ void bcode_unref(ostd::Uint32 *code) {
}
}
Bytecode::Bytecode(ostd::Uint32 *v): p_code(v) { bcode_ref(p_code); }
Bytecode::Bytecode(const Bytecode &v): p_code(v.p_code) { bcode_ref(p_code); }
Bytecode::~Bytecode() { bcode_unref(p_code); }
Bytecode &Bytecode::operator=(const Bytecode &v) {
bcode_unref(p_code);
p_code = v.p_code;
bcode_ref(p_code);
return *this;
}
Bytecode &Bytecode::operator=(Bytecode &&v) {
bcode_unref(p_code);
p_code = v.p_code;
v.p_code = nullptr;
return *this;
}
static const ostd::Uint32 *skipcode(const ostd::Uint32 *code, TaggedValue &result = no_ret) {
int depth = 0;
for (;;) {

View File

@ -84,30 +84,16 @@ enum {
IDF_NOEXPAND = 1 << 7
};
void bcode_ref(ostd::Uint32 *p);
void bcode_unref(ostd::Uint32 *p);
struct Bytecode {
Bytecode(): p_code(nullptr) {}
Bytecode(ostd::Uint32 *v): p_code(v) { bcode_ref(p_code); }
Bytecode(const Bytecode &v): p_code(v.p_code) { bcode_ref(p_code); }
Bytecode(ostd::Uint32 *v);
Bytecode(const Bytecode &v);
Bytecode(Bytecode &&v): p_code(v.p_code) { v.p_code = nullptr; }
~Bytecode() { bcode_unref(p_code); }
~Bytecode();
Bytecode &operator=(const Bytecode &v) {
bcode_unref(p_code);
p_code = v.p_code;
bcode_ref(p_code);
return *this;
}
Bytecode &operator=(Bytecode &&v) {
bcode_unref(p_code);
p_code = v.p_code;
v.p_code = nullptr;
return *this;
}
Bytecode &operator=(const Bytecode &v);
Bytecode &operator=(Bytecode &&v);
operator bool() const { return p_code != nullptr; }
operator ostd::Uint32 *() const { return p_code; }