remove the var global stuff + more progress

master
Daniel Kolesa 2015-08-06 23:54:49 +01:00
parent c785d03208
commit 7c5f962768
2 changed files with 17 additions and 22 deletions

View File

@ -31,6 +31,8 @@ CsState::CsState(): result(&no_ret) {
new_ident((const char *)buf, IDF_ARG); new_ident((const char *)buf, IDF_ARG);
} }
dummy = new_ident("//dummy", IDF_UNKNOWN); dummy = new_ident("//dummy", IDF_UNKNOWN);
add_ident(ID_VAR, "numargs", MAX_ARGUMENTS, 0, &numargs);
add_ident(ID_VAR, "dbgalias", 0, 1000, &dbgalias);
} }
CsState::~CsState() { CsState::~CsState() {
@ -165,8 +167,6 @@ void CsState::set_alias(ostd::ConstCharRange name, TaggedValue &v) {
} }
} }
int _numargs = variable("numargs", MAX_ARGUMENTS, 0, 0, &_numargs, nullptr, 0);
void TaggedValue::cleanup() { void TaggedValue::cleanup() {
switch (type) { switch (type) {
case VAL_STR: case VAL_STR:
@ -297,20 +297,18 @@ ostd::ConstCharRange debug_line(CsState &cs, ostd::ConstCharRange p,
return fmt; return fmt;
} }
int dbgalias = variable("dbgalias", 0, 4, 1000, &dbgalias, nullptr, 0);
void debug_alias(CsState &cs) { void debug_alias(CsState &cs) {
if (!dbgalias) return; if (!cs.dbgalias) return;
int total = 0, depth = 0; int total = 0, depth = 0;
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) total++; for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) total++;
for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) { for (IdentLink *l = cs.stack; l != &cs.noalias; l = l->next) {
Ident *id = l->id; Ident *id = l->id;
++depth; ++depth;
if (depth < dbgalias) if (depth < cs.dbgalias)
ostd::err.writefln(" %d) %s", total - depth + 1, id->name); ostd::err.writefln(" %d) %s", total - depth + 1, id->name);
else if (l->next == &cs.noalias) else if (l->next == &cs.noalias)
ostd::err.writefln(depth == dbgalias ? " %d) %s" ostd::err.writefln(depth == cs.dbgalias ? " %d) %s"
: " ..%d) %s", : " ..%d) %s",
total - depth + 1, id->name); total - depth + 1, id->name);
} }
} }
@ -423,16 +421,12 @@ void init_lib_base(CsState &cs) {
cs.add_command("resetvar", "s", [](CsState &cs, char *name) { cs.add_command("resetvar", "s", [](CsState &cs, char *name) {
cs.result->set_int(cs.reset_var(name)); cs.result->set_int(cs.reset_var(name));
}); });
}
ICOMMAND(alias, "sT", (CsState &cs, const char *name, TaggedValue *v), { cs.add_command("alias", "sT", [](CsState &cs, const char *name,
cs.set_alias(name, *v); TaggedValue *v) {
v->type = VAL_NULL; cs.set_alias(name, *v);
}); v->type = VAL_NULL;
});
int variable(const char *name, int min, int cur, int max, int *storage, IdentFunc fun, int flags) {
cstate.add_ident(ID_VAR, name, min, max, storage, fun, flags);
return cur;
} }
#define _GETVAR(id, vartype, name, retval) \ #define _GETVAR(id, vartype, name, retval) \
@ -2819,8 +2813,8 @@ static const ostd::uint *runcode(const ostd::uint *code, TaggedValue &result) {
IdentStack argstack[MAX_ARGUMENTS]; \ IdentStack argstack[MAX_ARGUMENTS]; \
for(int i = 0; i < callargs; i++) \ for(int i = 0; i < callargs; i++) \
cstate.identmap[i]->push_arg(args[offset + i], argstack[i]); \ cstate.identmap[i]->push_arg(args[offset + i], argstack[i]); \
int oldargs = _numargs; \ int oldargs = cstate.numargs; \
_numargs = callargs; \ cstate.numargs = callargs; \
int oldflags = cstate.identflags; \ int oldflags = cstate.identflags; \
cstate.identflags |= id->flags&IDF_OVERRIDDEN; \ cstate.identflags |= id->flags&IDF_OVERRIDDEN; \
IdentLink aliaslink = { id, cstate.stack, (1<<callargs)-1, argstack }; \ IdentLink aliaslink = { id, cstate.stack, (1<<callargs)-1, argstack }; \
@ -2838,7 +2832,7 @@ static const ostd::uint *runcode(const ostd::uint *code, TaggedValue &result) {
for(int argmask = aliaslink.usedargs&(~0<<callargs), i = callargs; argmask; i++) \ for(int argmask = aliaslink.usedargs&(~0<<callargs), i = callargs; argmask; i++) \
if(argmask&(1<<i)) { cstate.identmap[i]->pop_arg(); argmask &= ~(1<<i); } \ if(argmask&(1<<i)) { cstate.identmap[i]->pop_arg(); argmask &= ~(1<<i); } \
result.force(op&CODE_RET_MASK); \ result.force(op&CODE_RET_MASK); \
_numargs = oldargs; \ cstate.numargs = oldargs; \
numargs = SKIPARGS(offset); \ numargs = SKIPARGS(offset); \
} }
result.force_null(); result.force_null();
@ -3248,7 +3242,7 @@ static void doargs(CsState &cs, ostd::uint *body) {
COMMANDK(doargs, ID_DOARGS, "e"); COMMANDK(doargs, ID_DOARGS, "e");
ICOMMANDK(if, ID_IF, "tee", (CsState &cs, TaggedValue *cond, ostd::uint *t, ostd::uint *f), executeret(getbool(*cond) ? t : f, *cs.result)); ICOMMANDK(if, ID_IF, "tee", (CsState &cs, TaggedValue *cond, ostd::uint *t, ostd::uint *f), executeret(getbool(*cond) ? t : f, *cs.result));
ICOMMAND( ?, "tTT", (CsState &, TaggedValue *cond, TaggedValue *t, TaggedValue *f), result(*(getbool(*cond) ? t : f))); ICOMMAND(?, "tTT", (CsState &, TaggedValue *cond, TaggedValue *t, TaggedValue *f), result(*(getbool(*cond) ? t : f)));
ICOMMAND(pushif, "rTe", (CsState &cs, Ident *id, TaggedValue *v, ostd::uint *code), { ICOMMAND(pushif, "rTe", (CsState &cs, Ident *id, TaggedValue *v, ostd::uint *code), {
if (id->type != ID_ALIAS || id->index < MAX_ARGUMENTS) return; if (id->type != ID_ALIAS || id->index < MAX_ARGUMENTS) return;

View File

@ -319,6 +319,8 @@ struct CsState {
int identflags = 0; int identflags = 0;
int nodebug = 0; int nodebug = 0;
int numargs = 0;
int dbgalias = 4;
CsState(); CsState();
~CsState(); ~CsState();
@ -532,7 +534,6 @@ inline void Ident::getcval(TaggedValue &v) const {
} }
} }
extern int variable(const char *name, int min, int cur, int max, int *storage, IdentFunc fun, int flags);
extern void setvar(const char *name, int i, bool dofunc = true, bool doclamp = true); extern void setvar(const char *name, int i, bool dofunc = true, bool doclamp = true);
extern void setfvar(const char *name, float f, bool dofunc = true, bool doclamp = true); extern void setfvar(const char *name, float f, bool dofunc = true, bool doclamp = true);
extern void setsvar(const char *name, const char *str, bool dofunc = true); extern void setsvar(const char *name, const char *str, bool dofunc = true);