move Bytecode around a bit

master
Daniel Kolesa 2015-12-20 00:28:12 +01:00
parent 6bcd53c51a
commit fa4381000e
1 changed files with 32 additions and 31 deletions

View File

@ -84,6 +84,38 @@ 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(Bytecode &&v): p_code(v.p_code) { v.p_code = nullptr; }
~Bytecode() { bcode_unref(p_code); }
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;
}
operator bool() const { return p_code != nullptr; }
operator ostd::Uint32 *() const { return p_code; }
private:
ostd::Uint32 *p_code;
};
struct Ident;
struct IdentValue {
@ -469,37 +501,6 @@ struct CsState {
ostd::Uint32 *compile(ostd::ConstCharRange code);
};
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(Bytecode &&v): p_code(v.p_code) { v.p_code = nullptr; }
~Bytecode() { bcode_unref(p_code); }
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;
}
operator bool() const { return p_code != nullptr; }
operator ostd::Uint32 *() const { return p_code; }
private:
ostd::Uint32 *p_code;
};
void init_lib_base(CsState &cs);
void init_lib_io(CsState &cs);
void init_lib_math(CsState &cs);