forked from OctaForge/libcubescript
no need to store the core vars in the state struct
parent
c29cd02263
commit
d288833c65
18
cs_vm.cc
18
cs_vm.cc
|
@ -61,7 +61,8 @@ ostd::ConstCharRange cs_debug_line(
|
|||
}
|
||||
|
||||
void cs_debug_alias(CsState &cs) {
|
||||
if (!cs.dbgalias->get_value()) {
|
||||
Ivar *dalias = static_cast<Ivar *>(cs.identmap[DbgaliasIdx]);
|
||||
if (!dalias->get_value()) {
|
||||
return;
|
||||
}
|
||||
int total = 0, depth = 0;
|
||||
|
@ -71,11 +72,11 @@ void cs_debug_alias(CsState &cs) {
|
|||
for (IdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
|
||||
Ident *id = l->id;
|
||||
++depth;
|
||||
if (depth < cs.dbgalias->get_value()) {
|
||||
if (depth < dalias->get_value()) {
|
||||
ostd::err.writefln(" %d) %s", total - depth + 1, id->get_name());
|
||||
} else if (l->next == &cs.noalias) {
|
||||
ostd::err.writefln(
|
||||
depth == cs.dbgalias->get_value() ? " %d) %s" : " ..%d) %s",
|
||||
depth == dalias->get_value() ? " %d) %s" : " ..%d) %s",
|
||||
total - depth + 1, id->get_name()
|
||||
);
|
||||
}
|
||||
|
@ -388,7 +389,7 @@ static inline void callcommand(
|
|||
if (rep) {
|
||||
break;
|
||||
}
|
||||
args[i].set_ident(cs.dummy);
|
||||
args[i].set_ident(cs.identmap[DummyIdx]);
|
||||
fakeargs++;
|
||||
} else {
|
||||
cs.force_ident(args[i]);
|
||||
|
@ -449,14 +450,15 @@ static inline void cs_call_alias(
|
|||
CsState &cs, Alias *a, CsValue *args, CsValue &result,
|
||||
int callargs, int &nargs, int offset, int skip, ostd::Uint32 op
|
||||
) {
|
||||
Ivar *anargs = static_cast<Ivar *>(cs.identmap[NumargsIdx]);
|
||||
IdentStack argstack[MaxArguments];
|
||||
for(int i = 0; i < callargs; i++) {
|
||||
static_cast<Alias *>(cs.identmap[i])->push_arg(
|
||||
args[offset + i], argstack[i], false
|
||||
);
|
||||
}
|
||||
int oldargs = cs.numargs->get_value();
|
||||
cs.numargs->set_value(callargs);
|
||||
int oldargs = anargs->get_value();
|
||||
anargs->set_value(callargs);
|
||||
int oldflags = cs.identflags;
|
||||
cs.identflags |= a->get_flags()&IDF_OVERRIDDEN;
|
||||
IdentLink aliaslink = {
|
||||
|
@ -480,7 +482,7 @@ static inline void cs_call_alias(
|
|||
}
|
||||
}
|
||||
force_arg(result, op & CODE_RET_MASK);
|
||||
cs.numargs->set_value(oldargs);
|
||||
anargs->set_value(oldargs);
|
||||
nargs = offset - skip;
|
||||
}
|
||||
|
||||
|
@ -946,7 +948,7 @@ static ostd::Uint32 const *runcode(
|
|||
}
|
||||
case CODE_IDENTU: {
|
||||
CsValue &arg = args[numargs - 1];
|
||||
Ident *id = cs.dummy;
|
||||
Ident *id = cs.identmap[DummyIdx];
|
||||
if (
|
||||
arg.get_type() == VAL_STR ||
|
||||
arg.get_type() == VAL_MACRO ||
|
||||
|
|
6
cs_vm.hh
6
cs_vm.hh
|
@ -13,6 +13,10 @@ namespace cscript {
|
|||
static constexpr int MaxArguments = 25;
|
||||
static constexpr int MaxResults = 7;
|
||||
|
||||
static constexpr int DummyIdx = MaxArguments;
|
||||
static constexpr int NumargsIdx = MaxArguments + 1;
|
||||
static constexpr int DbgaliasIdx = MaxArguments + 2;
|
||||
|
||||
enum {
|
||||
ID_UNKNOWN = -1, ID_IVAR, ID_FVAR, ID_SVAR, ID_COMMAND, ID_ALIAS,
|
||||
ID_LOCAL, ID_DO, ID_DOARGS, ID_IF, ID_RESULT, ID_NOT, ID_AND, ID_OR
|
||||
|
@ -213,7 +217,7 @@ struct GenState {
|
|||
}
|
||||
|
||||
void gen_ident() {
|
||||
gen_ident(cs.dummy);
|
||||
gen_ident(cs.identmap[DummyIdx]);
|
||||
}
|
||||
|
||||
void gen_ident(ostd::ConstCharRange word) {
|
||||
|
|
|
@ -258,9 +258,15 @@ CsState::CsState() {
|
|||
snprintf(buf, sizeof(buf), "arg%d", i + 1);
|
||||
new_ident(static_cast<char const *>(buf), IDF_ARG);
|
||||
}
|
||||
dummy = new_ident("//dummy");
|
||||
numargs = add_ident<Ivar>("numargs", MaxArguments, 0, 0);
|
||||
dbgalias = add_ident<Ivar>("dbgalias", 0, 1000, 4);
|
||||
Ident *id = new_ident("//dummy");
|
||||
assert(id->get_index() == DummyIdx);
|
||||
|
||||
id = add_ident<Ivar>("numargs", MaxArguments, 0, 0);
|
||||
assert(id->get_index() == NumargsIdx);
|
||||
|
||||
id = add_ident<Ivar>("dbgalias", 0, 1000, 4);
|
||||
assert(id->get_index() == DbgaliasIdx);
|
||||
|
||||
cs_init_lib_base(*this);
|
||||
}
|
||||
|
||||
|
@ -336,7 +342,7 @@ Ident *CsState::new_ident(ostd::ConstCharRange name, int flags) {
|
|||
cs_debug_code(
|
||||
*this, "number %s is not a valid identifier name", name
|
||||
);
|
||||
return dummy;
|
||||
return identmap[DummyIdx];
|
||||
}
|
||||
id = add_ident<Alias>(name, flags);
|
||||
}
|
||||
|
@ -361,8 +367,8 @@ Ident *CsState::force_ident(CsValue &v) {
|
|||
}
|
||||
}
|
||||
v.cleanup();
|
||||
v.set_ident(dummy);
|
||||
return dummy;
|
||||
v.set_ident(identmap[DummyIdx]);
|
||||
return identmap[DummyIdx];
|
||||
}
|
||||
|
||||
bool CsState::reset_var(ostd::ConstCharRange name) {
|
||||
|
|
|
@ -377,8 +377,6 @@ struct OSTD_EXPORT CsState {
|
|||
CsMap<ostd::ConstCharRange, Ident *> idents;
|
||||
CsVector<Ident *> identmap;
|
||||
|
||||
Ident *dummy = nullptr;
|
||||
|
||||
IdentLink noalias;
|
||||
IdentLink *p_stack = &noalias;
|
||||
|
||||
|
@ -387,8 +385,6 @@ struct OSTD_EXPORT CsState {
|
|||
|
||||
int identflags = 0;
|
||||
int nodebug = 0;
|
||||
Ivar *numargs = nullptr;
|
||||
Ivar *dbgalias = nullptr;
|
||||
|
||||
CsState();
|
||||
~CsState();
|
||||
|
|
Loading…
Reference in New Issue