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