add copy_arg to TaggedValue

master
Daniel Kolesa 2016-08-03 23:03:44 +01:00
parent b5ed19730e
commit f4e1c1a32e
2 changed files with 31 additions and 1 deletions

View File

@ -405,6 +405,35 @@ void TaggedValue::cleanup() {
}
}
static ostd::Uint32 const *skipcode(ostd::Uint32 const *code, TaggedValue *result = nullptr);
void TaggedValue::copy_arg(TaggedValue &r) const {
r.cleanup();
switch (get_type()) {
case VAL_INT:
case VAL_FLOAT:
case VAL_IDENT:
r = *this;
break;
case VAL_STR:
case VAL_CSTR:
case VAL_MACRO:
r.set_str(ostd::ConstCharRange(s, len));
break;
case VAL_CODE: {
ostd::Uint32 const *end = skipcode(code);
ostd::Uint32 *dst = new ostd::Uint32[end - code + 1];
*dst++ = CODE_START;
memcpy(dst, code, (end - code) * sizeof(ostd::Uint32));
r.set_code(dst);
break;
}
default:
r.set_null();
break;
}
}
void TaggedValue::force_null() {
if (get_type() == VAL_NULL) return;
cleanup();
@ -2420,7 +2449,7 @@ Bytecode &Bytecode::operator=(Bytecode &&v) {
return *this;
}
static ostd::Uint32 const *skipcode(ostd::Uint32 const *code, TaggedValue *result = nullptr) {
static ostd::Uint32 const *skipcode(ostd::Uint32 const *code, TaggedValue *result) {
int depth = 0;
for (;;) {
ostd::Uint32 op = *code++;

View File

@ -143,6 +143,7 @@ struct OSTD_EXPORT TaggedValue: IdentValue {
ostd::ConstCharRange force_str();
void cleanup();
void copy_arg(TaggedValue &r) const;
private:
int p_type;