Bytecode -> CsBytecode
parent
29e833dae6
commit
48cd1efa80
44
cs_vm.cc
44
cs_vm.cc
|
@ -123,25 +123,25 @@ static void bcode_unref(ostd::Uint32 *code) {
|
|||
}
|
||||
}
|
||||
|
||||
BytecodeRef::BytecodeRef(Bytecode *v): p_code(v) {
|
||||
CsBytecodeRef::CsBytecodeRef(CsBytecode *v): p_code(v) {
|
||||
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
}
|
||||
BytecodeRef::BytecodeRef(BytecodeRef const &v): p_code(v.p_code) {
|
||||
CsBytecodeRef::CsBytecodeRef(CsBytecodeRef const &v): p_code(v.p_code) {
|
||||
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
}
|
||||
|
||||
BytecodeRef::~BytecodeRef() {
|
||||
CsBytecodeRef::~CsBytecodeRef() {
|
||||
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
}
|
||||
|
||||
BytecodeRef &BytecodeRef::operator=(BytecodeRef const &v) {
|
||||
CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef const &v) {
|
||||
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
p_code = v.p_code;
|
||||
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
return *this;
|
||||
}
|
||||
|
||||
BytecodeRef &BytecodeRef::operator=(BytecodeRef &&v) {
|
||||
CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef &&v) {
|
||||
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code));
|
||||
p_code = v.p_code;
|
||||
v.p_code = nullptr;
|
||||
|
@ -154,7 +154,7 @@ static inline ostd::Uint32 const *forcecode(CsState &cs, CsValue &v) {
|
|||
gs.code.reserve(64);
|
||||
gs.gen_main(v.get_str());
|
||||
v.cleanup();
|
||||
v.set_code(reinterpret_cast<Bytecode *>(gs.code.disown() + 1));
|
||||
v.set_code(reinterpret_cast<CsBytecode *>(gs.code.disown() + 1));
|
||||
}
|
||||
return reinterpret_cast<ostd::Uint32 const *>(v.code);
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ void CsValue::copy_arg(CsValue &r) const {
|
|||
ostd::Uint32 *dst = new ostd::Uint32[end - bcode + 1];
|
||||
*dst++ = CODE_START;
|
||||
memcpy(dst, bcode, (end - bcode) * sizeof(ostd::Uint32));
|
||||
r.set_code(reinterpret_cast<Bytecode const *>(dst));
|
||||
r.set_code(reinterpret_cast<CsBytecode const *>(dst));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
@ -379,7 +379,7 @@ static inline void callcommand(
|
|||
break;
|
||||
}
|
||||
args[i].set_code(
|
||||
reinterpret_cast<Bytecode *>(emptyblock[VAL_NULL] + 1)
|
||||
reinterpret_cast<CsBytecode *>(emptyblock[VAL_NULL] + 1)
|
||||
);
|
||||
fakeargs++;
|
||||
} else {
|
||||
|
@ -765,7 +765,7 @@ static ostd::Uint32 const *runcode(
|
|||
case CODE_MACRO: {
|
||||
ostd::Uint32 len = op >> 8;
|
||||
args[numargs++].set_macro(
|
||||
reinterpret_cast<Bytecode const *>(code), len
|
||||
reinterpret_cast<CsBytecode const *>(code), len
|
||||
);
|
||||
code += len / sizeof(ostd::Uint32) + 1;
|
||||
continue;
|
||||
|
@ -848,28 +848,28 @@ static ostd::Uint32 const *runcode(
|
|||
|
||||
case CODE_EMPTY | RET_NULL:
|
||||
args[numargs++].set_code(
|
||||
reinterpret_cast<Bytecode *>(emptyblock[VAL_NULL] + 1)
|
||||
reinterpret_cast<CsBytecode *>(emptyblock[VAL_NULL] + 1)
|
||||
);
|
||||
break;
|
||||
case CODE_EMPTY | RET_STR:
|
||||
args[numargs++].set_code(
|
||||
reinterpret_cast<Bytecode *>(emptyblock[VAL_STR] + 1)
|
||||
reinterpret_cast<CsBytecode *>(emptyblock[VAL_STR] + 1)
|
||||
);
|
||||
break;
|
||||
case CODE_EMPTY | RET_INT:
|
||||
args[numargs++].set_code(
|
||||
reinterpret_cast<Bytecode *>(emptyblock[VAL_INT] + 1)
|
||||
reinterpret_cast<CsBytecode *>(emptyblock[VAL_INT] + 1)
|
||||
);
|
||||
break;
|
||||
case CODE_EMPTY | RET_FLOAT:
|
||||
args[numargs++].set_code(
|
||||
reinterpret_cast<Bytecode *>(emptyblock[VAL_FLOAT] + 1)
|
||||
reinterpret_cast<CsBytecode *>(emptyblock[VAL_FLOAT] + 1)
|
||||
);
|
||||
break;
|
||||
case CODE_BLOCK: {
|
||||
ostd::Uint32 len = op >> 8;
|
||||
args[numargs++].set_code(
|
||||
reinterpret_cast<Bytecode const *>(code + 1)
|
||||
reinterpret_cast<CsBytecode const *>(code + 1)
|
||||
);
|
||||
code += len;
|
||||
continue;
|
||||
|
@ -908,7 +908,7 @@ static ostd::Uint32 const *runcode(
|
|||
break;
|
||||
}
|
||||
arg.set_code(
|
||||
reinterpret_cast<Bytecode const *>(gs.code.disown() + 1)
|
||||
reinterpret_cast<CsBytecode const *>(gs.code.disown() + 1)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
@ -923,7 +923,7 @@ static ostd::Uint32 const *runcode(
|
|||
gs.code.reserve(64);
|
||||
gs.gen_main(arg.s);
|
||||
arg.cleanup();
|
||||
arg.set_code(reinterpret_cast<Bytecode const *>(
|
||||
arg.set_code(reinterpret_cast<CsBytecode const *>(
|
||||
gs.code.disown() + 1
|
||||
));
|
||||
} else {
|
||||
|
@ -1567,7 +1567,7 @@ exit:
|
|||
return code;
|
||||
}
|
||||
|
||||
void CsState::run_ret(Bytecode const *code, CsValue &ret) {
|
||||
void CsState::run_ret(CsBytecode const *code, CsValue &ret) {
|
||||
runcode(*this, reinterpret_cast<ostd::Uint32 const *>(code), ret);
|
||||
}
|
||||
|
||||
|
@ -1657,7 +1657,7 @@ void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
|
|||
--rundepth;
|
||||
}
|
||||
|
||||
CsString CsState::run_str(Bytecode const *code) {
|
||||
CsString CsState::run_str(CsBytecode const *code) {
|
||||
CsValue ret;
|
||||
run_ret(code, ret);
|
||||
CsString s = ret.get_str();
|
||||
|
@ -1681,7 +1681,7 @@ CsString CsState::run_str(Ident *id, CsValueRange args) {
|
|||
return s;
|
||||
}
|
||||
|
||||
CsInt CsState::run_int(Bytecode const *code) {
|
||||
CsInt CsState::run_int(CsBytecode const *code) {
|
||||
CsValue ret;
|
||||
run_ret(code, ret);
|
||||
CsInt i = ret.get_int();
|
||||
|
@ -1705,7 +1705,7 @@ CsInt CsState::run_int(Ident *id, CsValueRange args) {
|
|||
return i;
|
||||
}
|
||||
|
||||
CsFloat CsState::run_float(Bytecode const *code) {
|
||||
CsFloat CsState::run_float(CsBytecode const *code) {
|
||||
CsValue ret;
|
||||
run_ret(code, ret);
|
||||
CsFloat f = ret.get_float();
|
||||
|
@ -1729,7 +1729,7 @@ CsFloat CsState::run_float(Ident *id, CsValueRange args) {
|
|||
return f;
|
||||
}
|
||||
|
||||
bool CsState::run_bool(Bytecode const *code) {
|
||||
bool CsState::run_bool(CsBytecode const *code) {
|
||||
CsValue ret;
|
||||
run_ret(code, ret);
|
||||
bool b = ret.get_bool();
|
||||
|
@ -1753,7 +1753,7 @@ bool CsState::run_bool(Ident *id, CsValueRange args) {
|
|||
return b;
|
||||
}
|
||||
|
||||
void CsState::run(Bytecode const *code) {
|
||||
void CsState::run(CsBytecode const *code) {
|
||||
CsValue ret;
|
||||
run_ret(code, ret);
|
||||
ret.cleanup();
|
||||
|
|
|
@ -530,7 +530,7 @@ void CsValue::set_null() {
|
|||
i = 0;
|
||||
}
|
||||
|
||||
void CsValue::set_code(Bytecode const *val) {
|
||||
void CsValue::set_code(CsBytecode const *val) {
|
||||
p_type = VAL_CODE;
|
||||
code = val;
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ void CsValue::set_ident(Ident *val) {
|
|||
id = val;
|
||||
}
|
||||
|
||||
void CsValue::set_macro(Bytecode const *val, ostd::Size ln) {
|
||||
void CsValue::set_macro(CsBytecode const *val, ostd::Size ln) {
|
||||
p_type = VAL_MACRO;
|
||||
len = ln;
|
||||
code = val;
|
||||
|
@ -659,11 +659,11 @@ CsFloat CsValue::get_float() const {
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
Bytecode *CsValue::get_code() const {
|
||||
CsBytecode *CsValue::get_code() const {
|
||||
if (get_type() != VAL_CODE) {
|
||||
return nullptr;
|
||||
}
|
||||
return const_cast<Bytecode *>(code);
|
||||
return const_cast<CsBytecode *>(code);
|
||||
}
|
||||
|
||||
Ident *CsValue::get_ident() const {
|
||||
|
@ -719,7 +719,7 @@ void CsValue::get_val(CsValue &r) const {
|
|||
}
|
||||
}
|
||||
|
||||
OSTD_EXPORT bool code_is_empty(Bytecode const *code) {
|
||||
OSTD_EXPORT bool code_is_empty(CsBytecode const *code) {
|
||||
if (!code) {
|
||||
return true;
|
||||
}
|
||||
|
@ -817,9 +817,9 @@ void Alias::clean_code() {
|
|||
}
|
||||
}
|
||||
|
||||
Bytecode *Alias::compile_code(CsState &cs) {
|
||||
CsBytecode *Alias::compile_code(CsState &cs) {
|
||||
if (!p_acode) {
|
||||
p_acode = reinterpret_cast<Bytecode *>(compilecode(cs, val_v.get_str()));
|
||||
p_acode = reinterpret_cast<CsBytecode *>(compilecode(cs, val_v.get_str()));
|
||||
}
|
||||
return p_acode;
|
||||
}
|
||||
|
@ -1259,7 +1259,7 @@ static inline void cs_set_iter(Alias &a, CsInt i, IdentStack &stack) {
|
|||
|
||||
static inline void cs_do_loop(
|
||||
CsState &cs, Ident &id, CsInt offset, CsInt n, CsInt step,
|
||||
Bytecode *cond, Bytecode *body
|
||||
CsBytecode *cond, CsBytecode *body
|
||||
) {
|
||||
if (n <= 0 || !id.is_alias()) {
|
||||
return;
|
||||
|
@ -1278,7 +1278,7 @@ static inline void cs_do_loop(
|
|||
|
||||
static inline void cs_loop_conc(
|
||||
CsState &cs, CsValue &res, Ident &id, CsInt offset, CsInt n,
|
||||
CsInt step, Bytecode *body, bool space
|
||||
CsInt step, CsBytecode *body, bool space
|
||||
) {
|
||||
if (n <= 0 || !id.is_alias()) {
|
||||
return;
|
||||
|
@ -1423,7 +1423,7 @@ void cs_init_lib_base(CsState &cs) {
|
|||
cs_add_command(cs, "pushif", "rTe", [&cs](CsValueRange args, CsValue &res) {
|
||||
Ident *id = args[0].get_ident();
|
||||
CsValue &v = args[1];
|
||||
Bytecode *code = args[2].get_code();
|
||||
CsBytecode *code = args[2].get_code();
|
||||
if (!id->is_alias() || (id->get_index() < MaxArguments)) {
|
||||
return;
|
||||
}
|
||||
|
@ -1494,7 +1494,7 @@ void cs_init_lib_base(CsState &cs) {
|
|||
});
|
||||
|
||||
cs_add_command(cs, "while", "ee", [&cs](CsValueRange args, CsValue &) {
|
||||
Bytecode *cond = args[0].get_code(), *body = args[1].get_code();
|
||||
CsBytecode *cond = args[0].get_code(), *body = args[1].get_code();
|
||||
while (cs.run_bool(cond)) {
|
||||
cs.run_int(body);
|
||||
}
|
||||
|
|
|
@ -36,33 +36,33 @@ enum {
|
|||
IDF_ARG = 1 << 6
|
||||
};
|
||||
|
||||
struct Bytecode;
|
||||
struct CsBytecode;
|
||||
|
||||
struct OSTD_EXPORT BytecodeRef {
|
||||
BytecodeRef():
|
||||
struct OSTD_EXPORT CsBytecodeRef {
|
||||
CsBytecodeRef():
|
||||
p_code(nullptr)
|
||||
{}
|
||||
BytecodeRef(Bytecode *v);
|
||||
BytecodeRef(BytecodeRef const &v);
|
||||
BytecodeRef(BytecodeRef &&v):
|
||||
CsBytecodeRef(CsBytecode *v);
|
||||
CsBytecodeRef(CsBytecodeRef const &v);
|
||||
CsBytecodeRef(CsBytecodeRef &&v):
|
||||
p_code(v.p_code)
|
||||
{
|
||||
v.p_code = nullptr;
|
||||
}
|
||||
|
||||
~BytecodeRef();
|
||||
~CsBytecodeRef();
|
||||
|
||||
BytecodeRef &operator=(BytecodeRef const &v);
|
||||
BytecodeRef &operator=(BytecodeRef &&v);
|
||||
CsBytecodeRef &operator=(CsBytecodeRef const &v);
|
||||
CsBytecodeRef &operator=(CsBytecodeRef &&v);
|
||||
|
||||
operator bool() const { return p_code != nullptr; }
|
||||
operator Bytecode *() const { return p_code; }
|
||||
operator CsBytecode *() const { return p_code; }
|
||||
|
||||
private:
|
||||
Bytecode *p_code;
|
||||
CsBytecode *p_code;
|
||||
};
|
||||
|
||||
OSTD_EXPORT bool code_is_empty(Bytecode const *code);
|
||||
OSTD_EXPORT bool code_is_empty(CsBytecode const *code);
|
||||
|
||||
struct Ident;
|
||||
|
||||
|
@ -70,7 +70,7 @@ struct OSTD_EXPORT CsValue {
|
|||
union {
|
||||
CsInt i; /* ID_IVAR, VAL_INT */
|
||||
CsFloat f; /* ID_FVAR, VAL_FLOAT */
|
||||
Bytecode const *code; /* VAL_CODE */
|
||||
CsBytecode const *code; /* VAL_CODE */
|
||||
Ident *id; /* VAL_IDENT */
|
||||
char *s; /* ID_SVAR, VAL_STR */
|
||||
char const *cstr; /* VAL_CSTR */
|
||||
|
@ -83,11 +83,11 @@ struct OSTD_EXPORT CsValue {
|
|||
void set_float(CsFloat val);
|
||||
void set_str(CsString val);
|
||||
void set_null();
|
||||
void set_code(Bytecode const *val);
|
||||
void set_code(CsBytecode const *val);
|
||||
void set_cstr(ostd::ConstCharRange val);
|
||||
void set_mstr(ostd::CharRange val);
|
||||
void set_ident(Ident *val);
|
||||
void set_macro(Bytecode const *val, ostd::Size ln);
|
||||
void set_macro(CsBytecode const *val, ostd::Size ln);
|
||||
|
||||
void set(CsValue &tv);
|
||||
|
||||
|
@ -95,7 +95,7 @@ struct OSTD_EXPORT CsValue {
|
|||
ostd::ConstCharRange get_strr() const;
|
||||
CsInt get_int() const;
|
||||
CsFloat get_float() const;
|
||||
Bytecode *get_code() const;
|
||||
CsBytecode *get_code() const;
|
||||
Ident *get_ident() const;
|
||||
void get_val(CsValue &r) const;
|
||||
|
||||
|
@ -301,7 +301,7 @@ struct OSTD_EXPORT Alias: Ident {
|
|||
void set_alias(CsState &cs, CsValue &v);
|
||||
|
||||
void clean_code();
|
||||
Bytecode *compile_code(CsState &cs);
|
||||
CsBytecode *compile_code(CsState &cs);
|
||||
|
||||
void force_null() {
|
||||
cleanup_value();
|
||||
|
@ -309,7 +309,7 @@ struct OSTD_EXPORT Alias: Ident {
|
|||
}
|
||||
|
||||
private:
|
||||
Bytecode *p_acode;
|
||||
CsBytecode *p_acode;
|
||||
IdentStack *p_astack;
|
||||
};
|
||||
|
||||
|
@ -383,27 +383,27 @@ struct OSTD_EXPORT CsState {
|
|||
ostd::ConstCharRange name, ostd::ConstCharRange args, CmdFunc func
|
||||
);
|
||||
|
||||
CsString run_str(Bytecode const *code);
|
||||
CsString run_str(CsBytecode const *code);
|
||||
CsString run_str(ostd::ConstCharRange code);
|
||||
CsString run_str(Ident *id, CsValueRange args);
|
||||
|
||||
CsInt run_int(Bytecode const *code);
|
||||
CsInt run_int(CsBytecode const *code);
|
||||
CsInt run_int(ostd::ConstCharRange code);
|
||||
CsInt run_int(Ident *id, CsValueRange args);
|
||||
|
||||
CsFloat run_float(Bytecode const *code);
|
||||
CsFloat run_float(CsBytecode const *code);
|
||||
CsFloat run_float(ostd::ConstCharRange code);
|
||||
CsFloat run_float(Ident *id, CsValueRange args);
|
||||
|
||||
bool run_bool(Bytecode const *code);
|
||||
bool run_bool(CsBytecode const *code);
|
||||
bool run_bool(ostd::ConstCharRange code);
|
||||
bool run_bool(Ident *id, CsValueRange args);
|
||||
|
||||
void run_ret(Bytecode const *code, CsValue &ret);
|
||||
void run_ret(CsBytecode const *code, CsValue &ret);
|
||||
void run_ret(ostd::ConstCharRange code, CsValue &ret);
|
||||
void run_ret(Ident *id, CsValueRange args, CsValue &ret);
|
||||
|
||||
void run(Bytecode const *code);
|
||||
void run(CsBytecode const *code);
|
||||
void run(ostd::ConstCharRange code);
|
||||
void run(Ident *id, CsValueRange args);
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ static inline void cs_set_iter(Alias &a, char *val, IdentStack &stack) {
|
|||
|
||||
static void cs_loop_list_conc(
|
||||
CsState &cs, CsValue &res, Ident *id, ostd::ConstCharRange list,
|
||||
Bytecode const *body, bool space
|
||||
CsBytecode const *body, bool space
|
||||
) {
|
||||
if (!id->is_alias()) {
|
||||
return;
|
||||
|
@ -539,7 +539,7 @@ struct ListSortItem {
|
|||
struct ListSortFun {
|
||||
CsState &cs;
|
||||
Alias *x, *y;
|
||||
Bytecode *body;
|
||||
CsBytecode *body;
|
||||
|
||||
bool operator()(ListSortItem const &xval, ListSortItem const &yval) {
|
||||
x->clean_code();
|
||||
|
@ -552,7 +552,7 @@ struct ListSortFun {
|
|||
|
||||
static void cs_list_sort(
|
||||
CsState &cs, CsValue &res, ostd::ConstCharRange list, Ident *x, Ident *y,
|
||||
Bytecode *body, Bytecode *unique
|
||||
CsBytecode *body, CsBytecode *unique
|
||||
) {
|
||||
if (x == y || !x->is_alias() || !y->is_alias()) {
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue