always cleanup when doing set_stuff
parent
f4e9cbf27f
commit
16c99e1f9e
11
cs_val.cc
11
cs_val.cc
|
@ -25,6 +25,7 @@ void CsValue::cleanup() {
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
p_type = CsValueType::null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CsValueType CsValue::get_type() const {
|
CsValueType CsValue::get_type() const {
|
||||||
|
@ -32,11 +33,13 @@ CsValueType CsValue::get_type() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_int(CsInt val) {
|
void CsValue::set_int(CsInt val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::integer;
|
p_type = CsValueType::integer;
|
||||||
csv_get<CsInt>(p_stor) = val;
|
csv_get<CsInt>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_float(CsFloat val) {
|
void CsValue::set_float(CsFloat val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::number;
|
p_type = CsValueType::number;
|
||||||
csv_get<CsFloat>(p_stor) = val;
|
csv_get<CsFloat>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
@ -55,39 +58,45 @@ void CsValue::set_str(CsString val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_null() {
|
void CsValue::set_null() {
|
||||||
p_type = CsValueType::null;
|
cleanup();
|
||||||
csv_get<CsBytecode *>(p_stor) = nullptr;
|
csv_get<CsBytecode *>(p_stor) = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_code(CsBytecode *val) {
|
void CsValue::set_code(CsBytecode *val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::code;
|
p_type = CsValueType::code;
|
||||||
csv_get<CsBytecode *>(p_stor) = val;
|
csv_get<CsBytecode *>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_cstr(ostd::ConstCharRange val) {
|
void CsValue::set_cstr(ostd::ConstCharRange val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::cstring;
|
p_type = CsValueType::cstring;
|
||||||
p_len = val.size();
|
p_len = val.size();
|
||||||
csv_get<char const *>(p_stor) = val.data();
|
csv_get<char const *>(p_stor) = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_mstr(ostd::CharRange val) {
|
void CsValue::set_mstr(ostd::CharRange val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::string;
|
p_type = CsValueType::string;
|
||||||
p_len = val.size();
|
p_len = val.size();
|
||||||
csv_get<char *>(p_stor) = val.data();
|
csv_get<char *>(p_stor) = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_ident(CsIdent *val) {
|
void CsValue::set_ident(CsIdent *val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::ident;
|
p_type = CsValueType::ident;
|
||||||
csv_get<CsIdent *>(p_stor) = val;
|
csv_get<CsIdent *>(p_stor) = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set_macro(ostd::ConstCharRange val) {
|
void CsValue::set_macro(ostd::ConstCharRange val) {
|
||||||
|
cleanup();
|
||||||
p_type = CsValueType::macro;
|
p_type = CsValueType::macro;
|
||||||
p_len = val.size();
|
p_len = val.size();
|
||||||
csv_get<char const *>(p_stor) = val.data();
|
csv_get<char const *>(p_stor) = val.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CsValue::set(CsValue &tv) {
|
void CsValue::set(CsValue &tv) {
|
||||||
|
cleanup();
|
||||||
*this = tv;
|
*this = tv;
|
||||||
tv.set_null();
|
tv.set_null();
|
||||||
}
|
}
|
||||||
|
|
29
cs_vm.cc
29
cs_vm.cc
|
@ -160,7 +160,6 @@ static inline ostd::Uint32 *forcecode(CsState &cs, CsValue &v) {
|
||||||
GenState gs(cs);
|
GenState gs(cs);
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
gs.gen_main(v.get_str());
|
gs.gen_main(v.get_str());
|
||||||
v.cleanup();
|
|
||||||
v.set_code(reinterpret_cast<CsBytecode *>(gs.code.disown() + 1));
|
v.set_code(reinterpret_cast<CsBytecode *>(gs.code.disown() + 1));
|
||||||
code = reinterpret_cast<ostd::Uint32 *>(v.get_code());
|
code = reinterpret_cast<ostd::Uint32 *>(v.get_code());
|
||||||
}
|
}
|
||||||
|
@ -389,15 +388,11 @@ static inline void callcommand(
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '$':
|
case '$':
|
||||||
if (++i < numargs) {
|
i += 1;
|
||||||
args[i].cleanup();
|
|
||||||
}
|
|
||||||
args[i].set_ident(id);
|
args[i].set_ident(id);
|
||||||
break;
|
break;
|
||||||
case 'N':
|
case 'N':
|
||||||
if (++i < numargs) {
|
i += 1;
|
||||||
args[i].cleanup();
|
|
||||||
}
|
|
||||||
args[i].set_int(CsInt(lookup ? -1 : i - fakeargs));
|
args[i].set_int(CsInt(lookup ? -1 : i - fakeargs));
|
||||||
break;
|
break;
|
||||||
case 'C': {
|
case 'C': {
|
||||||
|
@ -574,65 +569,52 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_NULL | RET_NULL:
|
case CODE_NULL | RET_NULL:
|
||||||
result.cleanup();
|
|
||||||
result.set_null();
|
result.set_null();
|
||||||
continue;
|
continue;
|
||||||
case CODE_NULL | RET_STR:
|
case CODE_NULL | RET_STR:
|
||||||
result.cleanup();
|
|
||||||
result.set_str("");
|
result.set_str("");
|
||||||
continue;
|
continue;
|
||||||
case CODE_NULL | RET_INT:
|
case CODE_NULL | RET_INT:
|
||||||
result.cleanup();
|
|
||||||
result.set_int(0);
|
result.set_int(0);
|
||||||
continue;
|
continue;
|
||||||
case CODE_NULL | RET_FLOAT:
|
case CODE_NULL | RET_FLOAT:
|
||||||
result.cleanup();
|
|
||||||
result.set_float(0.0f);
|
result.set_float(0.0f);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_FALSE | RET_STR:
|
case CODE_FALSE | RET_STR:
|
||||||
result.cleanup();
|
|
||||||
result.set_str("0");
|
result.set_str("0");
|
||||||
continue;
|
continue;
|
||||||
case CODE_FALSE | RET_NULL:
|
case CODE_FALSE | RET_NULL:
|
||||||
case CODE_FALSE | RET_INT:
|
case CODE_FALSE | RET_INT:
|
||||||
result.cleanup();
|
|
||||||
result.set_int(0);
|
result.set_int(0);
|
||||||
continue;
|
continue;
|
||||||
case CODE_FALSE | RET_FLOAT:
|
case CODE_FALSE | RET_FLOAT:
|
||||||
result.cleanup();
|
|
||||||
result.set_float(0.0f);
|
result.set_float(0.0f);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_TRUE | RET_STR:
|
case CODE_TRUE | RET_STR:
|
||||||
result.cleanup();
|
|
||||||
result.set_str("1");
|
result.set_str("1");
|
||||||
continue;
|
continue;
|
||||||
case CODE_TRUE | RET_NULL:
|
case CODE_TRUE | RET_NULL:
|
||||||
case CODE_TRUE | RET_INT:
|
case CODE_TRUE | RET_INT:
|
||||||
result.cleanup();
|
|
||||||
result.set_int(1);
|
result.set_int(1);
|
||||||
continue;
|
continue;
|
||||||
case CODE_TRUE | RET_FLOAT:
|
case CODE_TRUE | RET_FLOAT:
|
||||||
result.cleanup();
|
|
||||||
result.set_float(1.0f);
|
result.set_float(1.0f);
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_NOT | RET_STR:
|
case CODE_NOT | RET_STR:
|
||||||
result.cleanup();
|
|
||||||
--numargs;
|
--numargs;
|
||||||
result.set_str(args[numargs].get_bool() ? "0" : "1");
|
result.set_str(args[numargs].get_bool() ? "0" : "1");
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
continue;
|
continue;
|
||||||
case CODE_NOT | RET_NULL:
|
case CODE_NOT | RET_NULL:
|
||||||
case CODE_NOT | RET_INT:
|
case CODE_NOT | RET_INT:
|
||||||
result.cleanup();
|
|
||||||
--numargs;
|
--numargs;
|
||||||
result.set_int(!args[numargs].get_bool());
|
result.set_int(!args[numargs].get_bool());
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
continue;
|
continue;
|
||||||
case CODE_NOT | RET_FLOAT:
|
case CODE_NOT | RET_FLOAT:
|
||||||
result.cleanup();
|
|
||||||
--numargs;
|
--numargs;
|
||||||
result.set_float(CsFloat(!args[numargs].get_bool()));
|
result.set_float(CsFloat(!args[numargs].get_bool()));
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
|
@ -645,7 +627,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
code = runcode(cs, code, args[numargs++]);
|
code = runcode(cs, code, args[numargs++]);
|
||||||
continue;
|
continue;
|
||||||
case CODE_ENTER_RESULT:
|
case CODE_ENTER_RESULT:
|
||||||
result.cleanup();
|
|
||||||
code = runcode(cs, code, result);
|
code = runcode(cs, code, result);
|
||||||
continue;
|
continue;
|
||||||
case CODE_EXIT | RET_STR:
|
case CODE_EXIT | RET_STR:
|
||||||
|
@ -669,7 +650,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
case CODE_LOCAL: {
|
case CODE_LOCAL: {
|
||||||
result.cleanup();
|
|
||||||
int numlocals = op >> 8, offset = numargs - numlocals;
|
int numlocals = op >> 8, offset = numargs - numlocals;
|
||||||
CsIdentStack locals[MaxArguments];
|
CsIdentStack locals[MaxArguments];
|
||||||
for (int i = 0; i < numlocals; ++i) {
|
for (int i = 0; i < numlocals; ++i) {
|
||||||
|
@ -688,7 +668,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case CODE_DOARGS | RET_FLOAT:
|
case CODE_DOARGS | RET_FLOAT:
|
||||||
if (cs.p_stack != &cs.noalias) {
|
if (cs.p_stack != &cs.noalias) {
|
||||||
cs_do_args(cs, [&]() {
|
cs_do_args(cs, [&]() {
|
||||||
result.cleanup();
|
|
||||||
cs.run_ret(args[--numargs].get_code(), result);
|
cs.run_ret(args[--numargs].get_code(), result);
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
force_arg(result, op & CODE_RET_MASK);
|
force_arg(result, op & CODE_RET_MASK);
|
||||||
|
@ -700,7 +679,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case CODE_DO | RET_STR:
|
case CODE_DO | RET_STR:
|
||||||
case CODE_DO | RET_INT:
|
case CODE_DO | RET_INT:
|
||||||
case CODE_DO | RET_FLOAT:
|
case CODE_DO | RET_FLOAT:
|
||||||
result.cleanup();
|
|
||||||
cs.run_ret(args[--numargs].get_code(), result);
|
cs.run_ret(args[--numargs].get_code(), result);
|
||||||
args[numargs].cleanup();
|
args[numargs].cleanup();
|
||||||
force_arg(result, op & CODE_RET_MASK);
|
force_arg(result, op & CODE_RET_MASK);
|
||||||
|
@ -893,7 +871,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case CsValueType::cstring:
|
case CsValueType::cstring:
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
gs.gen_main(arg.get_strr());
|
gs.gen_main(arg.get_strr());
|
||||||
arg.cleanup();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gs.code.reserve(8);
|
gs.code.reserve(8);
|
||||||
|
@ -919,7 +896,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
GenState gs(cs);
|
GenState gs(cs);
|
||||||
gs.code.reserve(64);
|
gs.code.reserve(64);
|
||||||
gs.gen_main(s);
|
gs.gen_main(s);
|
||||||
arg.cleanup();
|
|
||||||
arg.set_code(reinterpret_cast<CsBytecode *>(
|
arg.set_code(reinterpret_cast<CsBytecode *>(
|
||||||
gs.code.disown() + 1
|
gs.code.disown() + 1
|
||||||
));
|
));
|
||||||
|
@ -969,7 +945,6 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
);
|
);
|
||||||
cs.p_stack->usedargs |= 1 << id->get_index();
|
cs.p_stack->usedargs |= 1 << id->get_index();
|
||||||
}
|
}
|
||||||
arg.cleanup();
|
|
||||||
arg.set_ident(id);
|
arg.set_ident(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -401,7 +401,6 @@ void CsState::clear_override(CsIdent &id) {
|
||||||
switch (id.get_type()) {
|
switch (id.get_type()) {
|
||||||
case CsIdentType::alias: {
|
case CsIdentType::alias: {
|
||||||
CsAlias &a = static_cast<CsAlias &>(id);
|
CsAlias &a = static_cast<CsAlias &>(id);
|
||||||
a.get_value().cleanup();
|
|
||||||
CsAliasInternal::clean_code(&a);
|
CsAliasInternal::clean_code(&a);
|
||||||
a.get_value().set_str("");
|
a.get_value().set_str("");
|
||||||
break;
|
break;
|
||||||
|
@ -467,14 +466,12 @@ CsIdent *CsState::force_ident(CsValue &v) {
|
||||||
case CsValueType::cstring:
|
case CsValueType::cstring:
|
||||||
case CsValueType::string: {
|
case CsValueType::string: {
|
||||||
CsIdent *id = new_ident(v.get_strr());
|
CsIdent *id = new_ident(v.get_strr());
|
||||||
v.cleanup();
|
|
||||||
v.set_ident(id);
|
v.set_ident(id);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
v.cleanup();
|
|
||||||
v.set_ident(identmap[DummyIdx]);
|
v.set_ident(identmap[DummyIdx]);
|
||||||
return identmap[DummyIdx];
|
return identmap[DummyIdx];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue