cleanup preparations

master
Daniel Kolesa 2016-08-20 16:40:00 +01:00
parent 8be7f74f5f
commit 77b35f2d52
5 changed files with 56 additions and 40 deletions

View File

@ -65,10 +65,10 @@ void cs_debug_alias(CsState &cs) {
return;
}
int total = 0, depth = 0;
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) {
for (IdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
total++;
}
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) {
for (IdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
Ident *id = l->id;
++depth;
if (depth < cs.dbgalias) {
@ -460,9 +460,9 @@ static inline void cs_call_alias(
int oldflags = cs.identflags;
cs.identflags |= a->get_flags()&IDF_OVERRIDDEN;
IdentLink aliaslink = {
a, cs.stack, (1<<callargs)-1, argstack
a, cs.p_stack, (1<<callargs)-1, argstack
};
cs.stack = &aliaslink;
cs.p_stack = &aliaslink;
if (!a->code) {
a->code = reinterpret_cast<Bytecode *>(
compilecode(cs, a->val_v.get_str())
@ -472,7 +472,7 @@ static inline void cs_call_alias(
bcode_incr(codep);
runcode(cs, codep+1, (result));
bcode_decr(codep);
cs.stack = aliaslink.next;
cs.p_stack = aliaslink.next;
cs.identflags = oldflags;
for (int i = 0; i < callargs; i++) {
static_cast<Alias *>(cs.identmap[i])->pop_arg();
@ -502,7 +502,7 @@ static inline Alias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
static inline Alias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
Ident *id = cs.identmap[op >> 8];
if (!(cs.stack->usedargs & (1 << id->get_index()))) {
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) {
return nullptr;
}
return static_cast<Alias *>(id);
@ -528,7 +528,7 @@ static inline int cs_get_lookupu_type(
arg.cleanup();
if (
(id->get_index() < MaxArguments) &&
!(cs.stack->usedargs & (1 << id->get_index()))
!(cs.p_stack->usedargs & (1 << id->get_index()))
) {
return ID_UNKNOWN;
}
@ -691,7 +691,7 @@ static ostd::Uint32 const *runcode(
case CODE_DOARGS | RET_STR:
case CODE_DOARGS | RET_INT:
case CODE_DOARGS | RET_FLOAT:
if (cs.stack != &cs.noalias) {
if (cs.p_stack != &cs.noalias) {
cs_do_args(cs, [&]() {
result.cleanup();
cs.run_ret(args[--numargs].code, result);
@ -940,11 +940,11 @@ static ostd::Uint32 const *runcode(
continue;
case CODE_IDENTARG: {
Alias *a = static_cast<Alias *>(cs.identmap[op >> 8]);
if (!(cs.stack->usedargs & (1 << a->get_index()))) {
if (!(cs.p_stack->usedargs & (1 << a->get_index()))) {
a->push_arg(
null_value, cs.stack->argstack[a->get_index()], false
null_value, cs.p_stack->argstack[a->get_index()], false
);
cs.stack->usedargs |= 1 << a->get_index();
cs.p_stack->usedargs |= 1 << a->get_index();
}
args[numargs++].set_ident(a);
continue;
@ -961,12 +961,12 @@ static ostd::Uint32 const *runcode(
}
if (
id->get_index() < MaxArguments &&
!(cs.stack->usedargs & (1 << id->get_index()))
!(cs.p_stack->usedargs & (1 << id->get_index()))
) {
static_cast<Alias *>(id)->push_arg(
null_value, cs.stack->argstack[id->get_index()], false
null_value, cs.p_stack->argstack[id->get_index()], false
);
cs.stack->usedargs |= 1 << id->get_index();
cs.p_stack->usedargs |= 1 << id->get_index();
}
arg.cleanup();
arg.set_ident(id);
@ -1427,7 +1427,7 @@ static ostd::Uint32 const *runcode(
result.force_null();
Ident *id = cs.identmap[op >> 13];
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
if (!(cs.stack->usedargs & (1 << id->get_index()))) {
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) {
free_args(args, numargs, offset);
force_arg(result, op & CODE_RET_MASK);
continue;
@ -1543,7 +1543,7 @@ noid:
Alias *a = static_cast<Alias *>(id);
if (
a->get_index() < MaxArguments &&
!(cs.stack->usedargs & (1 << a->get_index()))
!(cs.p_stack->usedargs & (1 << a->get_index()))
) {
free_args(args, numargs, offset - 1);
force_arg(result, op & CODE_RET_MASK);
@ -1640,7 +1640,7 @@ void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
case IdentType::alias: {
Alias *a = static_cast<Alias *>(id);
if (a->get_index() < MaxArguments) {
if (!(stack->usedargs & (1 << a->get_index()))) {
if (!(p_stack->usedargs & (1 << a->get_index()))) {
break;
}
}

View File

@ -79,21 +79,21 @@ struct NullValue: CsValue {
template<typename F>
static void cs_do_args(CsState &cs, F body) {
IdentStack argstack[MaxArguments];
int argmask1 = cs.stack->usedargs;
int argmask1 = cs.p_stack->usedargs;
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
if (argmask1 & 1) {
static_cast<Alias *>(cs.identmap[i])->undo_arg(argstack[i]);
}
}
IdentLink *prevstack = cs.stack->next;
IdentLink *prevstack = cs.p_stack->next;
IdentLink aliaslink = {
cs.stack->id, cs.stack, prevstack->usedargs, prevstack->argstack
cs.p_stack->id, cs.p_stack, prevstack->usedargs, prevstack->argstack
};
cs.stack = &aliaslink;
cs.p_stack = &aliaslink;
body();
prevstack->usedargs = aliaslink.usedargs;
cs.stack = aliaslink.next;
int argmask2 = cs.stack->usedargs;
cs.p_stack = aliaslink.next;
int argmask2 = cs.p_stack->usedargs;
for (int i = 0; argmask2; argmask2 >>= 1, ++i) {
if (argmask2 & 1) {
static_cast<Alias *>(cs.identmap[i])->redo_arg(argstack[i]);

View File

@ -269,9 +269,9 @@ void CsState::clear_override(Ident &id) {
switch (id.get_type()) {
case IdentType::alias: {
Alias &a = static_cast<Alias &>(id);
a.val_v.cleanup();
a.cleanup_value();
a.clean_code();
a.val_v.set_str("");
a.set_value_str("");
break;
}
case IdentType::ivar: {
@ -746,7 +746,7 @@ void Alias::pop_arg() {
return;
}
IdentStack *st = stack;
val_v.cleanup();
cleanup_value();
set_value(*stack);
clean_code();
stack = st->next;
@ -770,18 +770,18 @@ void Alias::redo_arg(IdentStack const &st) {
}
void Alias::set_arg(CsState &cs, CsValue &v) {
if (cs.stack->usedargs & (1 << get_index())) {
val_v.cleanup();
if (cs.p_stack->usedargs & (1 << get_index())) {
cleanup_value();
set_value(v);
clean_code();
} else {
push_arg(v, cs.stack->argstack[get_index()], false);
cs.stack->usedargs |= 1 << get_index();
push_arg(v, cs.p_stack->argstack[get_index()], false);
cs.p_stack->usedargs |= 1 << get_index();
}
}
void Alias::set_alias(CsState &cs, CsValue &v) {
val_v.cleanup();
cleanup_value();
set_value(v);
clean_code();
p_flags = (p_flags & cs.identflags) | cs.identflags;
@ -972,7 +972,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
}
if (
(a->get_index() < MaxArguments) &&
!(stack->usedargs & (1 << a->get_index()))
!(p_stack->usedargs & (1 << a->get_index()))
) {
return ostd::nothing;
}
@ -1166,7 +1166,7 @@ void cs_init_lib_io(CsState &cs) {
static inline void cs_set_iter(Alias &a, CsInt i, IdentStack &stack) {
if (a.stack == &stack) {
a.val_v.cleanup();
a.cleanup_value();
a.val_v.set_int(i);
return;
}
@ -1229,7 +1229,7 @@ void cs_init_lib_base(CsState &cs) {
}, ID_DO);
cs_add_command(cs, "doargs", "e", [&cs](CsValueRange args, CsValue &res) {
if (cs.stack != &cs.noalias) {
if (cs.p_stack != &cs.noalias) {
cs_do_args(cs, [&]() { cs.run_ret(args[0].get_code(), res); });
} else {
cs.run_ret(args[0].get_code(), res);

View File

@ -313,6 +313,22 @@ struct OSTD_EXPORT Alias: Ident {
val_v = v.val_s;
}
void set_value_cstr(ostd::ConstCharRange val) {
val_v.set_cstr(val);
}
void set_value_mstr(ostd::CharRange val) {
val_v.set_mstr(val);
}
void set_value_str(ostd::String val) {
val_v.set_str(ostd::move(val));
}
void cleanup_value() {
val_v.cleanup();
}
void get_cstr(CsValue &v) const;
void get_cval(CsValue &v) const;
@ -327,7 +343,7 @@ struct OSTD_EXPORT Alias: Ident {
void clean_code();
void force_null() {
val_v.cleanup();
cleanup_value();
val_v.set_null();
}
};
@ -356,7 +372,7 @@ struct OSTD_EXPORT CsState {
Ident *dummy = nullptr;
IdentLink noalias;
IdentLink *stack = &noalias;
IdentLink *p_stack = &noalias;
ostd::ConstCharRange src_file;
ostd::ConstCharRange src_str;

View File

@ -70,9 +70,9 @@ static inline void cs_list_assoc(CsValueRange args, CsValue &res, F cmp) {
static inline void cs_set_iter(Alias &a, char *val, IdentStack &stack) {
if (a.stack == &stack) {
a.val_v.cleanup();
a.cleanup_value();
a.clean_code();
a.val_v.set_mstr(val);
a.set_value_mstr(val);
return;
}
CsValue v;
@ -549,9 +549,9 @@ struct ListSortFun {
bool operator()(ListSortItem const &xval, ListSortItem const &yval) {
x->clean_code();
x->val_v.set_cstr(xval.str);
x->set_value_cstr(xval.str);
y->clean_code();
y->val_v.set_cstr(yval.str);
y->set_value_cstr(yval.str);
return cs.run_bool(body);
}
};