forked from OctaForge/libcubescript
raw members of CsValue are now private
This commit is contained in:
parent
83c50ebf67
commit
5e1d4c3f39
49
cs_vm.cc
49
cs_vm.cc
|
@ -166,7 +166,7 @@ static inline void forcecond(CsState &cs, CsValue &v) {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
if (v.s[0]) {
|
if (!v.get_strr().empty()) {
|
||||||
forcecode(cs, v);
|
forcecode(cs, v);
|
||||||
} else {
|
} else {
|
||||||
v.set_int(0);
|
v.set_int(0);
|
||||||
|
@ -263,7 +263,7 @@ void CsValue::copy_arg(CsValue &r) const {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
r.set_str(ostd::ConstCharRange(s, len));
|
r.set_str(ostd::ConstCharRange(p_s, p_len));
|
||||||
break;
|
break;
|
||||||
case VAL_CODE: {
|
case VAL_CODE: {
|
||||||
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(r.get_code());
|
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(r.get_code());
|
||||||
|
@ -517,7 +517,7 @@ static inline int cs_get_lookupu_type(
|
||||||
) {
|
) {
|
||||||
return -2; /* default case */
|
return -2; /* default case */
|
||||||
}
|
}
|
||||||
id = cs.get_ident(arg.s);
|
id = cs.get_ident(arg.get_strr());
|
||||||
if (id) {
|
if (id) {
|
||||||
switch(id->get_type()) {
|
switch(id->get_type()) {
|
||||||
case CsIdentType::alias:
|
case CsIdentType::alias:
|
||||||
|
@ -554,7 +554,7 @@ static inline int cs_get_lookupu_type(
|
||||||
return ID_UNKNOWN;
|
return ID_UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cs_debug_code(cs, "unknown alias lookup: %s", arg.s);
|
cs_debug_code(cs, "unknown alias lookup: %s", arg.get_strr());
|
||||||
arg.cleanup();
|
arg.cleanup();
|
||||||
return ID_UNKNOWN;
|
return ID_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
@ -879,14 +879,14 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
gs.code.reserve(8);
|
gs.code.reserve(8);
|
||||||
gs.code.push(CODE_START);
|
gs.code.push(CODE_START);
|
||||||
gs.gen_int(arg.i);
|
gs.gen_int(arg.get_int());
|
||||||
gs.code.push(CODE_RESULT);
|
gs.code.push(CODE_RESULT);
|
||||||
gs.code.push(CODE_EXIT);
|
gs.code.push(CODE_EXIT);
|
||||||
break;
|
break;
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
gs.code.reserve(8);
|
gs.code.reserve(8);
|
||||||
gs.code.push(CODE_START);
|
gs.code.push(CODE_START);
|
||||||
gs.gen_float(arg.f);
|
gs.gen_float(arg.get_float());
|
||||||
gs.code.push(CODE_RESULT);
|
gs.code.push(CODE_RESULT);
|
||||||
gs.code.push(CODE_EXIT);
|
gs.code.push(CODE_EXIT);
|
||||||
break;
|
break;
|
||||||
|
@ -894,7 +894,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
gs.gen_main(arg.s);
|
gs.gen_main(arg.get_strr());
|
||||||
arg.cleanup();
|
arg.cleanup();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -915,11 +915,12 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
switch (arg.get_type()) {
|
switch (arg.get_type()) {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR: {
|
||||||
if (arg.s[0]) {
|
ostd::ConstCharRange s = arg.get_strr();
|
||||||
|
if (!s.empty()) {
|
||||||
GenState gs(cs);
|
GenState gs(cs);
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
gs.gen_main(arg.s);
|
gs.gen_main(s);
|
||||||
arg.cleanup();
|
arg.cleanup();
|
||||||
arg.set_code(reinterpret_cast<CsBytecode *>(
|
arg.set_code(reinterpret_cast<CsBytecode *>(
|
||||||
gs.code.disown() + 1
|
gs.code.disown() + 1
|
||||||
|
@ -928,6 +929,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
arg.force_null();
|
arg.force_null();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -954,7 +956,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
arg.get_type() == VAL_MACRO ||
|
arg.get_type() == VAL_MACRO ||
|
||||||
arg.get_type() == VAL_CSTR
|
arg.get_type() == VAL_CSTR
|
||||||
) {
|
) {
|
||||||
id = cs.new_ident(ostd::ConstCharRange(arg.cstr, arg.len));
|
id = cs.new_ident(arg.get_strr());
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
id->get_index() < MaxArguments &&
|
id->get_index() < MaxArguments &&
|
||||||
|
@ -1235,7 +1237,8 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
case CODE_SVAR1:
|
case CODE_SVAR1:
|
||||||
cs.set_var_str_checked(
|
cs.set_var_str_checked(
|
||||||
static_cast<CsSvar *>(cs.identmap[op >> 8]), args[--numargs].s
|
static_cast<CsSvar *>(cs.identmap[op >> 8]),
|
||||||
|
args[--numargs].get_strr()
|
||||||
);
|
);
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
continue;
|
continue;
|
||||||
|
@ -1258,22 +1261,25 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
case CODE_IVAR1:
|
case CODE_IVAR1:
|
||||||
cs.set_var_int_checked(
|
cs.set_var_int_checked(
|
||||||
static_cast<CsIvar *>(cs.identmap[op >> 8]), args[--numargs].i
|
static_cast<CsIvar *>(cs.identmap[op >> 8]),
|
||||||
|
args[--numargs].get_int()
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
case CODE_IVAR2:
|
case CODE_IVAR2:
|
||||||
numargs -= 2;
|
numargs -= 2;
|
||||||
cs.set_var_int_checked(
|
cs.set_var_int_checked(
|
||||||
static_cast<CsIvar *>(cs.identmap[op >> 8]),
|
static_cast<CsIvar *>(cs.identmap[op >> 8]),
|
||||||
(args[numargs].i << 16) | (args[numargs + 1].i << 8));
|
(args[numargs].get_int() << 16)
|
||||||
|
| (args[numargs + 1].get_int() << 8)
|
||||||
|
);
|
||||||
continue;
|
continue;
|
||||||
case CODE_IVAR3:
|
case CODE_IVAR3:
|
||||||
numargs -= 3;
|
numargs -= 3;
|
||||||
cs.set_var_int_checked(
|
cs.set_var_int_checked(
|
||||||
static_cast<CsIvar *>(cs.identmap[op >> 8]),
|
static_cast<CsIvar *>(cs.identmap[op >> 8]),
|
||||||
(args[numargs].i << 16)
|
(args[numargs].get_int() << 16)
|
||||||
| (args[numargs + 1].i << 8)
|
| (args[numargs + 1].get_int() << 8)
|
||||||
| args[numargs + 2].i);
|
| (args[numargs + 2].get_int()));
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_FVAR | RET_FLOAT:
|
case CODE_FVAR | RET_FLOAT:
|
||||||
|
@ -1294,7 +1300,8 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
case CODE_FVAR1:
|
case CODE_FVAR1:
|
||||||
cs.set_var_float_checked(
|
cs.set_var_float_checked(
|
||||||
static_cast<CsFvar *>(cs.identmap[op >> 8]), args[--numargs].f
|
static_cast<CsFvar *>(cs.identmap[op >> 8]),
|
||||||
|
args[--numargs].get_float()
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -1456,13 +1463,13 @@ litval:
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
CsIdent *id = cs.get_ident(idarg.s);
|
CsIdent *id = cs.get_ident(idarg.get_strr());
|
||||||
if (!id) {
|
if (!id) {
|
||||||
noid:
|
noid:
|
||||||
if (cs_check_num(idarg.s)) {
|
if (cs_check_num(idarg.get_strr())) {
|
||||||
goto litval;
|
goto litval;
|
||||||
}
|
}
|
||||||
cs_debug_code(cs, "unknown command: %s", idarg.s);
|
cs_debug_code(cs, "unknown command: %s", idarg.get_strr());
|
||||||
result.force_null();
|
result.force_null();
|
||||||
free_args(args, numargs, offset - 1);
|
free_args(args, numargs, offset - 1);
|
||||||
force_arg(result, op & CODE_RET_MASK);
|
force_arg(result, op & CODE_RET_MASK);
|
||||||
|
|
100
cubescript.cc
100
cubescript.cc
|
@ -354,14 +354,10 @@ CsIdent *CsState::force_ident(CsValue &v) {
|
||||||
case VAL_IDENT:
|
case VAL_IDENT:
|
||||||
return v.get_ident();
|
return v.get_ident();
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR: {
|
case VAL_CSTR:
|
||||||
CsIdent *id = new_ident(v.s);
|
|
||||||
v.set_ident(id);
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
case VAL_STR: {
|
case VAL_STR: {
|
||||||
CsIdent *id = new_ident(v.s);
|
CsIdent *id = new_ident(v.get_strr());
|
||||||
delete[] v.s;
|
v.cleanup();
|
||||||
v.set_ident(id);
|
v.set_ident(id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +481,7 @@ void CsState::print_var(CsVar *v) {
|
||||||
void CsValue::cleanup() {
|
void CsValue::cleanup() {
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
delete[] s;
|
delete[] p_s;
|
||||||
break;
|
break;
|
||||||
case VAL_CODE:
|
case VAL_CODE:
|
||||||
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(p_code);
|
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(p_code);
|
||||||
|
@ -502,12 +498,12 @@ int CsValue::get_type() const {
|
||||||
|
|
||||||
void CsValue::set_int(CsInt val) {
|
void CsValue::set_int(CsInt val) {
|
||||||
p_type = VAL_INT;
|
p_type = VAL_INT;
|
||||||
i = val;
|
p_i = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_float(CsFloat val) {
|
void CsValue::set_float(CsFloat val) {
|
||||||
p_type = VAL_FLOAT;
|
p_type = VAL_FLOAT;
|
||||||
f = val;
|
p_f = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_str(CsString val) {
|
void CsValue::set_str(CsString val) {
|
||||||
|
@ -525,7 +521,7 @@ void CsValue::set_str(CsString val) {
|
||||||
|
|
||||||
void CsValue::set_null() {
|
void CsValue::set_null() {
|
||||||
p_type = VAL_NULL;
|
p_type = VAL_NULL;
|
||||||
i = 0;
|
p_code = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_code(CsBytecode *val) {
|
void CsValue::set_code(CsBytecode *val) {
|
||||||
|
@ -535,14 +531,14 @@ void CsValue::set_code(CsBytecode *val) {
|
||||||
|
|
||||||
void CsValue::set_cstr(ostd::ConstCharRange val) {
|
void CsValue::set_cstr(ostd::ConstCharRange val) {
|
||||||
p_type = VAL_CSTR;
|
p_type = VAL_CSTR;
|
||||||
len = val.size();
|
p_len = val.size();
|
||||||
cstr = val.data();
|
p_cstr = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_mstr(ostd::CharRange val) {
|
void CsValue::set_mstr(ostd::CharRange val) {
|
||||||
p_type = VAL_STR;
|
p_type = VAL_STR;
|
||||||
len = val.size();
|
p_len = val.size();
|
||||||
s = val.data();
|
p_s = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_ident(CsIdent *val) {
|
void CsValue::set_ident(CsIdent *val) {
|
||||||
|
@ -552,8 +548,8 @@ void CsValue::set_ident(CsIdent *val) {
|
||||||
|
|
||||||
void CsValue::set_macro(ostd::ConstCharRange val) {
|
void CsValue::set_macro(ostd::ConstCharRange val) {
|
||||||
p_type = VAL_MACRO;
|
p_type = VAL_MACRO;
|
||||||
len = val.size();
|
p_len = val.size();
|
||||||
cstr = val.data();
|
p_cstr = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set(CsValue &tv) {
|
void CsValue::set(CsValue &tv) {
|
||||||
|
@ -574,15 +570,15 @@ CsFloat CsValue::force_float() {
|
||||||
CsFloat rf = 0.0f;
|
CsFloat rf = 0.0f;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
rf = i;
|
rf = p_i;
|
||||||
break;
|
break;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
rf = cs_parse_float(s);
|
rf = cs_parse_float(ostd::ConstCharRange(p_s, p_len));
|
||||||
break;
|
break;
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
return f;
|
return p_f;
|
||||||
}
|
}
|
||||||
cleanup();
|
cleanup();
|
||||||
set_float(rf);
|
set_float(rf);
|
||||||
|
@ -593,15 +589,15 @@ CsInt CsValue::force_int() {
|
||||||
CsInt ri = 0;
|
CsInt ri = 0;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
ri = f;
|
ri = p_f;
|
||||||
break;
|
break;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
ri = cs_parse_int(s);
|
ri = cs_parse_int(ostd::ConstCharRange(p_s, p_len));
|
||||||
break;
|
break;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
return i;
|
return p_i;
|
||||||
}
|
}
|
||||||
cleanup();
|
cleanup();
|
||||||
set_int(ri);
|
set_int(ri);
|
||||||
|
@ -612,33 +608,33 @@ ostd::ConstCharRange CsValue::force_str() {
|
||||||
CsString rs;
|
CsString rs;
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
rs = ostd::move(floatstr(f));
|
rs = ostd::move(floatstr(p_f));
|
||||||
break;
|
break;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
rs = ostd::move(intstr(i));
|
rs = ostd::move(intstr(p_i));
|
||||||
break;
|
break;
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
rs = ostd::ConstCharRange(s, len);
|
rs = ostd::ConstCharRange(p_s, p_len);
|
||||||
break;
|
break;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
return s;
|
return ostd::ConstCharRange(p_s, p_len);
|
||||||
}
|
}
|
||||||
cleanup();
|
cleanup();
|
||||||
set_str(ostd::move(rs));
|
set_str(ostd::move(rs));
|
||||||
return s;
|
return ostd::ConstCharRange(p_s, p_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
CsInt CsValue::get_int() const {
|
CsInt CsValue::get_int() const {
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
return CsInt(f);
|
return CsInt(p_f);
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
return i;
|
return p_i;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
return cs_parse_int(s);
|
return cs_parse_int(ostd::ConstCharRange(p_s, p_len));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -646,13 +642,13 @@ CsInt CsValue::get_int() const {
|
||||||
CsFloat CsValue::get_float() const {
|
CsFloat CsValue::get_float() const {
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
return f;
|
return p_f;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
return CsFloat(i);
|
return CsFloat(p_i);
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
return cs_parse_float(s);
|
return cs_parse_float(ostd::ConstCharRange(p_s, p_len));
|
||||||
}
|
}
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -676,11 +672,11 @@ CsString CsValue::get_str() const {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
return ostd::ConstCharRange(s, len);
|
return ostd::ConstCharRange(p_s, p_len);
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
return intstr(i);
|
return intstr(p_i);
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
return floatstr(f);
|
return floatstr(p_f);
|
||||||
}
|
}
|
||||||
return CsString("");
|
return CsString("");
|
||||||
}
|
}
|
||||||
|
@ -690,7 +686,7 @@ ostd::ConstCharRange CsValue::get_strr() const {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
return ostd::ConstCharRange(s, len);
|
return ostd::ConstCharRange(p_s, p_len);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -702,14 +698,14 @@ void CsValue::get_val(CsValue &r) const {
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR: {
|
case VAL_CSTR: {
|
||||||
r.set_str(ostd::ConstCharRange(s, len));
|
r.set_str(ostd::ConstCharRange(p_s, p_len));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
r.set_int(i);
|
r.set_int(p_i);
|
||||||
break;
|
break;
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
r.set_float(f);
|
r.set_float(p_f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
r.set_null();
|
r.set_null();
|
||||||
|
@ -753,13 +749,13 @@ static inline bool cs_get_bool(ostd::ConstCharRange s) {
|
||||||
bool CsValue::get_bool() const {
|
bool CsValue::get_bool() const {
|
||||||
switch (get_type()) {
|
switch (get_type()) {
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
return f != 0;
|
return p_f != 0;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
return i != 0;
|
return p_i != 0;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
return cs_get_bool(ostd::ConstCharRange(s, len));
|
return cs_get_bool(ostd::ConstCharRange(p_s, p_len));
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -768,17 +764,17 @@ bool CsValue::get_bool() const {
|
||||||
void CsAlias::get_cstr(CsValue &v) const {
|
void CsAlias::get_cstr(CsValue &v) const {
|
||||||
switch (val_v.get_type()) {
|
switch (val_v.get_type()) {
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
v.set_macro(ostd::ConstCharRange(val_v.cstr, val_v.len));
|
v.set_macro(val_v.get_strr());
|
||||||
break;
|
break;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
v.set_cstr(ostd::ConstCharRange(val_v.s, val_v.len));
|
v.set_cstr(val_v.get_strr());
|
||||||
break;
|
break;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
v.set_str(ostd::move(intstr(val_v.i)));
|
v.set_str(ostd::move(intstr(val_v.get_int())));
|
||||||
break;
|
break;
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
v.set_str(ostd::move(floatstr(val_v.f)));
|
v.set_str(ostd::move(floatstr(val_v.get_float())));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
v.set_cstr("");
|
v.set_cstr("");
|
||||||
|
@ -789,17 +785,17 @@ void CsAlias::get_cstr(CsValue &v) const {
|
||||||
void CsAlias::get_cval(CsValue &v) const {
|
void CsAlias::get_cval(CsValue &v) const {
|
||||||
switch (val_v.get_type()) {
|
switch (val_v.get_type()) {
|
||||||
case VAL_MACRO:
|
case VAL_MACRO:
|
||||||
v.set_macro(ostd::ConstCharRange(val_v.cstr, val_v.len));
|
v.set_macro(val_v.get_strr());
|
||||||
break;
|
break;
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
v.set_cstr(ostd::ConstCharRange(val_v.s, val_v.len));
|
v.set_cstr(val_v.get_strr());
|
||||||
break;
|
break;
|
||||||
case VAL_INT:
|
case VAL_INT:
|
||||||
v.set_int(val_v.i);
|
v.set_int(val_v.get_int());
|
||||||
break;
|
break;
|
||||||
case VAL_FLOAT:
|
case VAL_FLOAT:
|
||||||
v.set_float(val_v.f);
|
v.set_float(val_v.get_float());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
v.set_null();
|
v.set_null();
|
||||||
|
|
|
@ -67,16 +67,6 @@ OSTD_EXPORT bool cs_code_is_empty(CsBytecode *code);
|
||||||
struct CsIdent;
|
struct CsIdent;
|
||||||
|
|
||||||
struct OSTD_EXPORT CsValue {
|
struct OSTD_EXPORT CsValue {
|
||||||
union {
|
|
||||||
CsInt i; /* ID_IVAR, VAL_INT */
|
|
||||||
CsFloat f; /* ID_FVAR, VAL_FLOAT */
|
|
||||||
CsBytecode *p_code; /* VAL_CODE */
|
|
||||||
CsIdent *p_id; /* VAL_IDENT */
|
|
||||||
char *s; /* ID_SVAR, VAL_STR */
|
|
||||||
char const *cstr; /* VAL_CSTR */
|
|
||||||
};
|
|
||||||
ostd::Size len;
|
|
||||||
|
|
||||||
int get_type() const;
|
int get_type() const;
|
||||||
|
|
||||||
void set_int(CsInt val);
|
void set_int(CsInt val);
|
||||||
|
@ -112,6 +102,15 @@ struct OSTD_EXPORT CsValue {
|
||||||
void copy_arg(CsValue &r) const;
|
void copy_arg(CsValue &r) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
union {
|
||||||
|
CsInt p_i; /* ID_IVAR, VAL_INT */
|
||||||
|
CsFloat p_f; /* ID_FVAR, VAL_FLOAT */
|
||||||
|
CsBytecode *p_code; /* VAL_CODE */
|
||||||
|
CsIdent *p_id; /* VAL_IDENT */
|
||||||
|
char *p_s; /* ID_SVAR, VAL_STR */
|
||||||
|
char const *p_cstr; /* VAL_CSTR */
|
||||||
|
};
|
||||||
|
ostd::Size p_len;
|
||||||
int p_type;
|
int p_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -626,14 +625,18 @@ namespace util {
|
||||||
auto s = ostd::appender<CsString>();
|
auto s = ostd::appender<CsString>();
|
||||||
switch (vals[i].get_type()) {
|
switch (vals[i].get_type()) {
|
||||||
case VAL_INT: {
|
case VAL_INT: {
|
||||||
auto r = format_int(ostd::forward<R>(writer), vals[i].i);
|
auto r = format_int(
|
||||||
|
ostd::forward<R>(writer), vals[i].get_int()
|
||||||
|
);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
ret += ostd::Size(r);
|
ret += ostd::Size(r);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case VAL_FLOAT: {
|
case VAL_FLOAT: {
|
||||||
auto r = format_float(ostd::forward<R>(writer), vals[i].f);
|
auto r = format_float(
|
||||||
|
ostd::forward<R>(writer), vals[i].get_float()
|
||||||
|
);
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
ret += ostd::Size(r);
|
ret += ostd::Size(r);
|
||||||
}
|
}
|
||||||
|
@ -641,9 +644,11 @@ namespace util {
|
||||||
}
|
}
|
||||||
case VAL_STR:
|
case VAL_STR:
|
||||||
case VAL_CSTR:
|
case VAL_CSTR:
|
||||||
case VAL_MACRO:
|
case VAL_MACRO: {
|
||||||
ret += writer.put_n(vals[i].s, vals[i].len);
|
auto sv = vals[i].get_strr();
|
||||||
|
ret += writer.put_n(sv.data(), sv.size());
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue