get rid of noalias
parent
f1e1a02a11
commit
233b9dc7dd
|
@ -345,8 +345,7 @@ struct OSTD_EXPORT CsState {
|
||||||
CsMap<ostd::ConstCharRange, CsIdent *> idents;
|
CsMap<ostd::ConstCharRange, CsIdent *> idents;
|
||||||
CsVector<CsIdent *> identmap;
|
CsVector<CsIdent *> identmap;
|
||||||
|
|
||||||
CsIdentLink noalias;
|
CsIdentLink *p_callstack = nullptr;
|
||||||
CsIdentLink *p_callstack = &noalias;
|
|
||||||
|
|
||||||
int identflags = 0;
|
int identflags = 0;
|
||||||
int nodebug = 0;
|
int nodebug = 0;
|
||||||
|
|
54
src/cs_vm.cc
54
src/cs_vm.cc
|
@ -66,34 +66,34 @@ bool CsStackState::gap() const {
|
||||||
CsStackState cs_save_stack(CsState &cs) {
|
CsStackState cs_save_stack(CsState &cs) {
|
||||||
CsIvar *dalias = static_cast<CsIvar *>(cs.identmap[DbgaliasIdx]);
|
CsIvar *dalias = static_cast<CsIvar *>(cs.identmap[DbgaliasIdx]);
|
||||||
if (!dalias->get_value()) {
|
if (!dalias->get_value()) {
|
||||||
return CsStackState(nullptr, true);
|
return CsStackState(nullptr, !!cs.p_callstack);
|
||||||
}
|
}
|
||||||
int total = 0, depth = 0;
|
int total = 0, depth = 0;
|
||||||
for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
|
for (CsIdentLink *l = cs.p_callstack; l; l = l->next) {
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
if (!total) {
|
if (!total) {
|
||||||
return CsStackState(nullptr, true);
|
return CsStackState(nullptr, false);
|
||||||
}
|
}
|
||||||
CsStackStateNode *st =
|
CsStackStateNode *st =
|
||||||
new CsStackStateNode[ostd::min(total, dalias->get_value())];
|
new CsStackStateNode[ostd::min(total, dalias->get_value())];
|
||||||
CsStackStateNode *ret = st, *nd = st;
|
CsStackStateNode *ret = st, *nd = st;
|
||||||
++st;
|
++st;
|
||||||
for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
|
for (CsIdentLink *l = cs.p_callstack; l; l = l->next) {
|
||||||
++depth;
|
++depth;
|
||||||
if (depth < dalias->get_value()) {
|
if (depth < dalias->get_value()) {
|
||||||
nd->id = l->id;
|
nd->id = l->id;
|
||||||
nd->index = total - depth + 1;
|
nd->index = total - depth + 1;
|
||||||
if (l->next == &cs.noalias) {
|
if (!l->next) {
|
||||||
nd->next = nullptr;
|
nd->next = nullptr;
|
||||||
} else {
|
} else {
|
||||||
nd->next = st;
|
nd->next = st;
|
||||||
}
|
}
|
||||||
nd = st++;
|
nd = st++;
|
||||||
} else if (l->next == &cs.noalias) {
|
} else if (!l->next) {
|
||||||
nd->id = l->id;
|
nd->id = l->id;
|
||||||
nd->index = 1;
|
nd->index = 1;
|
||||||
nd->next = NULL;
|
nd->next = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CsStackState(ret, total != dalias->get_value());
|
return CsStackState(ret, total != dalias->get_value());
|
||||||
|
@ -487,7 +487,7 @@ static inline CsAlias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
|
||||||
|
|
||||||
static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
|
static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
|
||||||
CsIdent *id = cs.identmap[op >> 8];
|
CsIdent *id = cs.identmap[op >> 8];
|
||||||
if (!(cs.p_callstack->usedargs & (1 << id->get_index()))) {
|
if (!cs_is_arg_used(cs, id)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return static_cast<CsAlias *>(id);
|
return static_cast<CsAlias *>(id);
|
||||||
|
@ -510,10 +510,7 @@ static inline int cs_get_lookupu_type(
|
||||||
if (id->get_flags() & CsIdfUnknown) {
|
if (id->get_flags() & CsIdfUnknown) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (
|
if ((id->get_index() < MaxArguments) && !cs_is_arg_used(cs, id)) {
|
||||||
(id->get_index() < MaxArguments) &&
|
|
||||||
!(cs.p_callstack->usedargs & (1 << id->get_index()))
|
|
||||||
) {
|
|
||||||
return CsIdUnknown;
|
return CsIdUnknown;
|
||||||
}
|
}
|
||||||
return CsIdAlias;
|
return CsIdAlias;
|
||||||
|
@ -655,13 +652,11 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
case CsCodeDoArgs | CsRetString:
|
case CsCodeDoArgs | CsRetString:
|
||||||
case CsCodeDoArgs | CsRetInt:
|
case CsCodeDoArgs | CsRetInt:
|
||||||
case CsCodeDoArgs | CsRetFloat:
|
case CsCodeDoArgs | CsRetFloat:
|
||||||
if (cs.p_callstack != &cs.noalias) {
|
cs_do_args(cs, [&]() {
|
||||||
cs_do_args(cs, [&]() {
|
cs.run(args[--numargs].get_code(), result);
|
||||||
cs.run(args[--numargs].get_code(), result);
|
force_arg(result, op & CsCodeRetMask);
|
||||||
force_arg(result, op & CsCodeRetMask);
|
});
|
||||||
});
|
continue;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
/* fallthrough */
|
/* fallthrough */
|
||||||
case CsCodeDo | CsRetNull:
|
case CsCodeDo | CsRetNull:
|
||||||
case CsCodeDo | CsRetString:
|
case CsCodeDo | CsRetString:
|
||||||
|
@ -899,7 +894,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
continue;
|
continue;
|
||||||
case CsCodeIdentArg: {
|
case CsCodeIdentArg: {
|
||||||
CsAlias *a = static_cast<CsAlias *>(cs.identmap[op >> 8]);
|
CsAlias *a = static_cast<CsAlias *>(cs.identmap[op >> 8]);
|
||||||
if (!(cs.p_callstack->usedargs & (1 << a->get_index()))) {
|
if (!cs_is_arg_used(cs, a)) {
|
||||||
CsValue nv;
|
CsValue nv;
|
||||||
CsAliasInternal::push_arg(
|
CsAliasInternal::push_arg(
|
||||||
a, nv, cs.p_callstack->argstack[a->get_index()], false
|
a, nv, cs.p_callstack->argstack[a->get_index()], false
|
||||||
|
@ -919,10 +914,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
) {
|
) {
|
||||||
id = cs.new_ident(arg.get_strr());
|
id = cs.new_ident(arg.get_strr());
|
||||||
}
|
}
|
||||||
if (
|
if ((id->get_index() < MaxArguments) && !cs_is_arg_used(cs, id)) {
|
||||||
id->get_index() < MaxArguments &&
|
|
||||||
!(cs.p_callstack->usedargs & (1 << id->get_index()))
|
|
||||||
) {
|
|
||||||
CsValue nv;
|
CsValue nv;
|
||||||
CsAliasInternal::push_arg(
|
CsAliasInternal::push_arg(
|
||||||
static_cast<CsAlias *>(id), nv,
|
static_cast<CsAlias *>(id), nv,
|
||||||
|
@ -1401,7 +1393,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
||||||
result.force_null();
|
result.force_null();
|
||||||
CsIdent *id = cs.identmap[op >> 13];
|
CsIdent *id = cs.identmap[op >> 13];
|
||||||
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
|
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
|
||||||
if (!(cs.p_callstack->usedargs & (1 << id->get_index()))) {
|
if (!cs_is_arg_used(cs, id)) {
|
||||||
numargs = offset;
|
numargs = offset;
|
||||||
force_arg(result, op & CsCodeRetMask);
|
force_arg(result, op & CsCodeRetMask);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1514,8 +1506,8 @@ noid:
|
||||||
case CsIdAlias: {
|
case CsIdAlias: {
|
||||||
CsAlias *a = static_cast<CsAlias *>(id);
|
CsAlias *a = static_cast<CsAlias *>(id);
|
||||||
if (
|
if (
|
||||||
a->get_index() < MaxArguments &&
|
(a->get_index() < MaxArguments) &&
|
||||||
!(cs.p_callstack->usedargs & (1 << a->get_index()))
|
!cs_is_arg_used(cs, a)
|
||||||
) {
|
) {
|
||||||
numargs = offset - 1;
|
numargs = offset - 1;
|
||||||
force_arg(result, op & CsCodeRetMask);
|
force_arg(result, op & CsCodeRetMask);
|
||||||
|
@ -1619,10 +1611,10 @@ void CsState::run(CsIdent *id, CsValueRange args, CsValue &ret) {
|
||||||
break;
|
break;
|
||||||
case CsIdentType::Alias: {
|
case CsIdentType::Alias: {
|
||||||
CsAlias *a = static_cast<CsAlias *>(id);
|
CsAlias *a = static_cast<CsAlias *>(id);
|
||||||
if (a->get_index() < MaxArguments) {
|
if (
|
||||||
if (!(p_callstack->usedargs & (1 << a->get_index()))) {
|
(a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)
|
||||||
break;
|
) {
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if (a->get_value().get_type() == CsValueType::Null) {
|
if (a->get_value().get_type() == CsValueType::Null) {
|
||||||
break;
|
break;
|
||||||
|
|
13
src/cs_vm.hh
13
src/cs_vm.hh
|
@ -236,6 +236,13 @@ static inline void bcode_decr(ostd::Uint32 *bc) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool cs_is_arg_used(CsState &cs, CsIdent *id) {
|
||||||
|
if (!cs.p_callstack) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return cs.p_callstack->usedargs & (1 << id->get_index());
|
||||||
|
}
|
||||||
|
|
||||||
struct CsAliasInternal {
|
struct CsAliasInternal {
|
||||||
static void push_arg(
|
static void push_arg(
|
||||||
CsAlias *a, CsValue &v, CsIdentStack &st, bool um = true
|
CsAlias *a, CsValue &v, CsIdentStack &st, bool um = true
|
||||||
|
@ -284,7 +291,7 @@ struct CsAliasInternal {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_arg(CsAlias *a, CsState &cs, CsValue &v) {
|
static void set_arg(CsAlias *a, CsState &cs, CsValue &v) {
|
||||||
if (cs.p_callstack->usedargs & (1 << a->get_index())) {
|
if (cs_is_arg_used(cs, a)) {
|
||||||
a->p_val = ostd::move(v);
|
a->p_val = ostd::move(v);
|
||||||
clean_code(a);
|
clean_code(a);
|
||||||
} else {
|
} else {
|
||||||
|
@ -323,6 +330,10 @@ struct CsAliasInternal {
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
static void cs_do_args(CsState &cs, F body) {
|
static void cs_do_args(CsState &cs, F body) {
|
||||||
|
if (!cs.p_callstack) {
|
||||||
|
body();
|
||||||
|
return;
|
||||||
|
}
|
||||||
CsIdentStack argstack[MaxArguments];
|
CsIdentStack argstack[MaxArguments];
|
||||||
int argmask1 = cs.p_callstack->usedargs;
|
int argmask1 = cs.p_callstack->usedargs;
|
||||||
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
|
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
|
||||||
|
|
|
@ -255,11 +255,6 @@ void cs_init_lib_base(CsState &cs);
|
||||||
CsState::CsState():
|
CsState::CsState():
|
||||||
p_callhook(), p_panicfunc(), p_out(&ostd::out), p_err(&ostd::err)
|
p_callhook(), p_panicfunc(), p_out(&ostd::out), p_err(&ostd::err)
|
||||||
{
|
{
|
||||||
noalias.id = nullptr;
|
|
||||||
noalias.next = nullptr;
|
|
||||||
noalias.usedargs = (1 << MaxArguments) - 1;
|
|
||||||
noalias.argstack = nullptr;
|
|
||||||
|
|
||||||
/* default panic func */
|
/* default panic func */
|
||||||
p_panicfunc = [this](ostd::ConstCharRange v, CsStackState) {
|
p_panicfunc = [this](ostd::ConstCharRange v, CsStackState) {
|
||||||
get_err().writefln(
|
get_err().writefln(
|
||||||
|
@ -286,11 +281,7 @@ CsState::CsState():
|
||||||
})->p_type = CsIdDo;
|
})->p_type = CsIdDo;
|
||||||
|
|
||||||
new_command("doargs", "e", [this](CsValueRange args, CsValue &res) {
|
new_command("doargs", "e", [this](CsValueRange args, CsValue &res) {
|
||||||
if (p_callstack != &noalias) {
|
cs_do_args(*this, [&]() { run(args[0].get_code(), res); });
|
||||||
cs_do_args(*this, [&]() { run(args[0].get_code(), res); });
|
|
||||||
} else {
|
|
||||||
run(args[0].get_code(), res);
|
|
||||||
}
|
|
||||||
})->p_type = CsIdDoArgs;
|
})->p_type = CsIdDoArgs;
|
||||||
|
|
||||||
new_command("if", "tee", [this](CsValueRange args, CsValue &res) {
|
new_command("if", "tee", [this](CsValueRange args, CsValue &res) {
|
||||||
|
@ -881,10 +872,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
|
||||||
if (!a) {
|
if (!a) {
|
||||||
return ostd::nothing;
|
return ostd::nothing;
|
||||||
}
|
}
|
||||||
if (
|
if ((a->get_index() < MaxArguments) && !cs_is_arg_used(*this, a)) {
|
||||||
(a->get_index() < MaxArguments) &&
|
|
||||||
!(p_callstack->usedargs & (1 << a->get_index()))
|
|
||||||
) {
|
|
||||||
return ostd::nothing;
|
return ostd::nothing;
|
||||||
}
|
}
|
||||||
return ostd::move(a->get_value().get_str());
|
return ostd::move(a->get_value().get_str());
|
||||||
|
|
Loading…
Reference in New Issue