forked from OctaForge/libcubescript
cleanup
parent
d538667e9f
commit
580b41ded5
73
command.cc
73
command.cc
|
@ -2982,7 +2982,7 @@ void executeret(const char *p, TaggedValue &result) {
|
||||||
if (int(code[0]) >= 0x100) code.disown();
|
if (int(code[0]) >= 0x100) code.disown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void executeret(Ident *id, TaggedValue *args, int numargs, bool lookup, TaggedValue &result) {
|
void executeret(Ident *id, TaggedValue *args, int numargs, TaggedValue &result) {
|
||||||
result.set_null();
|
result.set_null();
|
||||||
++rundepth;
|
++rundepth;
|
||||||
TaggedValue *prevret = cstate.result;
|
TaggedValue *prevret = cstate.result;
|
||||||
|
@ -2996,8 +2996,8 @@ void executeret(Ident *id, TaggedValue *args, int numargs, bool lookup, TaggedVa
|
||||||
if (numargs < id->numargs) {
|
if (numargs < id->numargs) {
|
||||||
TaggedValue buf[MAX_ARGUMENTS];
|
TaggedValue buf[MAX_ARGUMENTS];
|
||||||
memcpy(buf, args, numargs * sizeof(TaggedValue));
|
memcpy(buf, args, numargs * sizeof(TaggedValue));
|
||||||
callcommand(id, buf, numargs, lookup);
|
callcommand(id, buf, numargs, false);
|
||||||
} else callcommand(id, args, numargs, lookup);
|
} else callcommand(id, args, numargs, false);
|
||||||
numargs = 0;
|
numargs = 0;
|
||||||
break;
|
break;
|
||||||
case ID_VAR:
|
case ID_VAR:
|
||||||
|
@ -3031,35 +3031,35 @@ void executeret(Ident *id, TaggedValue *args, int numargs, bool lookup, TaggedVa
|
||||||
--rundepth;
|
--rundepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *executestr(const ostd::uint *code) {
|
ostd::String CsState::run_str(const ostd::uint *code) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
runcode(code, result);
|
runcode(code, result);
|
||||||
if (result.type == VAL_NULL) return nullptr;
|
if (result.type == VAL_NULL) return ostd::String();
|
||||||
result.force_str();
|
result.force_str();
|
||||||
return result.s;
|
ostd::String ret(result.s);
|
||||||
|
delete[] result.s;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *executestr(const char *p) {
|
ostd::String CsState::run_str(ostd::ConstCharRange code) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
executeret(p, result);
|
/* FIXME range */
|
||||||
if (result.type == VAL_NULL) return nullptr;
|
executeret(code.data(), result);
|
||||||
|
if (result.type == VAL_NULL) return ostd::String();
|
||||||
result.force_str();
|
result.force_str();
|
||||||
return result.s;
|
ostd::String ret(result.s);
|
||||||
|
delete[] result.s;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *executestr(Ident *id, TaggedValue *args, int numargs, bool lookup) {
|
char *executestr(Ident *id, TaggedValue *args, int numargs) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
executeret(id, args, numargs, lookup, result);
|
executeret(id, args, numargs, result);
|
||||||
if (result.type == VAL_NULL) return nullptr;
|
if (result.type == VAL_NULL) return nullptr;
|
||||||
result.force_str();
|
result.force_str();
|
||||||
return result.s;
|
return result.s;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *execidentstr(const char *name, bool lookup) {
|
|
||||||
Ident *id = cstate.idents.at(name);
|
|
||||||
return id ? executestr(id, nullptr, 0, lookup) : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int execute(const ostd::uint *code) {
|
int execute(const ostd::uint *code) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
runcode(code, result);
|
runcode(code, result);
|
||||||
|
@ -3080,19 +3080,14 @@ int execute(const char *p) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int execute(Ident *id, TaggedValue *args, int numargs, bool lookup) {
|
int execute(Ident *id, TaggedValue *args, int numargs) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
executeret(id, args, numargs, lookup, result);
|
executeret(id, args, numargs, result);
|
||||||
int i = result.get_int();
|
int i = result.get_int();
|
||||||
result.cleanup();
|
result.cleanup();
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int execident(const char *name, int noid, bool lookup) {
|
|
||||||
Ident *id = cstate.idents.at(name);
|
|
||||||
return id ? execute(id, nullptr, 0, lookup) : noid;
|
|
||||||
}
|
|
||||||
|
|
||||||
float executefloat(const ostd::uint *code) {
|
float executefloat(const ostd::uint *code) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
runcode(code, result);
|
runcode(code, result);
|
||||||
|
@ -3109,19 +3104,14 @@ float executefloat(const char *p) {
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float executefloat(Ident *id, TaggedValue *args, int numargs, bool lookup) {
|
float executefloat(Ident *id, TaggedValue *args, int numargs) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
executeret(id, args, numargs, lookup, result);
|
executeret(id, args, numargs, result);
|
||||||
float f = result.get_float();
|
float f = result.get_float();
|
||||||
result.cleanup();
|
result.cleanup();
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
float execidentfloat(const char *name, float noid, bool lookup) {
|
|
||||||
Ident *id = cstate.idents.at(name);
|
|
||||||
return id ? executefloat(id, nullptr, 0, lookup) : noid;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool executebool(const ostd::uint *code) {
|
bool executebool(const ostd::uint *code) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
runcode(code, result);
|
runcode(code, result);
|
||||||
|
@ -3138,19 +3128,14 @@ bool executebool(const char *p) {
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool executebool(Ident *id, TaggedValue *args, int numargs, bool lookup) {
|
bool executebool(Ident *id, TaggedValue *args, int numargs) {
|
||||||
TaggedValue result;
|
TaggedValue result;
|
||||||
executeret(id, args, numargs, lookup, result);
|
executeret(id, args, numargs, result);
|
||||||
bool b = getbool(result);
|
bool b = getbool(result);
|
||||||
result.cleanup();
|
result.cleanup();
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool execidentbool(const char *name, bool noid, bool lookup) {
|
|
||||||
Ident *id = cstate.idents.at(name);
|
|
||||||
return id ? executebool(id, nullptr, 0, lookup) : noid;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool execfile(const char *cfgfile, bool msg) {
|
bool execfile(const char *cfgfile, bool msg) {
|
||||||
const char *oldsourcefile = sourcefile, *oldsourcestr = sourcestr;
|
const char *oldsourcefile = sourcefile, *oldsourcestr = sourcestr;
|
||||||
char *buf = nullptr;
|
char *buf = nullptr;
|
||||||
|
@ -3645,9 +3630,9 @@ COMMAND(listassoc, "rse");
|
||||||
notfound: \
|
notfound: \
|
||||||
cs.result->set_int(-1); \
|
cs.result->set_int(-1); \
|
||||||
});
|
});
|
||||||
LISTFIND(listfind =, "i", int, , parseint(start) == *val);
|
LISTFIND(listfind=, "i", int, , parseint(start) == *val);
|
||||||
LISTFIND(listfind = f, "f", float, , parsefloat(start) == *val);
|
LISTFIND(listfind=f, "f", float, , parsefloat(start) == *val);
|
||||||
LISTFIND(listfind = s, "s", char, int len = (int)strlen(val), int(end - start) == len && !memcmp(start, val, len));
|
LISTFIND(listfind=s, "s", char, int len = (int)strlen(val), int(end - start) == len && !memcmp(start, val, len));
|
||||||
|
|
||||||
#define LISTASSOC(name, fmt, type, init, cmp) \
|
#define LISTASSOC(name, fmt, type, init, cmp) \
|
||||||
ICOMMAND(name, "s" fmt, (CsState &, char *list, type *val), \
|
ICOMMAND(name, "s" fmt, (CsState &, char *list, type *val), \
|
||||||
|
@ -3659,9 +3644,9 @@ LISTFIND(listfind = s, "s", char, int len = (int)strlen(val), int(end - start) =
|
||||||
if(!parselist(s)) break; \
|
if(!parselist(s)) break; \
|
||||||
} \
|
} \
|
||||||
});
|
});
|
||||||
LISTASSOC(listassoc =, "i", int, , parseint(start) == *val);
|
LISTASSOC(listassoc=, "i", int, , parseint(start) == *val);
|
||||||
LISTASSOC(listassoc = f, "f", float, , parsefloat(start) == *val);
|
LISTASSOC(listassoc=f, "f", float, , parsefloat(start) == *val);
|
||||||
LISTASSOC(listassoc = s, "s", char, int len = (int)strlen(val), int(end - start) == len && !memcmp(start, val, len));
|
LISTASSOC(listassoc=s, "s", char, int len = (int)strlen(val), int(end - start) == len && !memcmp(start, val, len));
|
||||||
|
|
||||||
void looplist(CsState &, Ident *id, const char *list, const ostd::uint *body) {
|
void looplist(CsState &, Ident *id, const char *list, const ostd::uint *body) {
|
||||||
if (id->type != ID_ALIAS) return;
|
if (id->type != ID_ALIAS) return;
|
||||||
|
|
17
command.hh
17
command.hh
|
@ -319,6 +319,9 @@ struct CsState {
|
||||||
|
|
||||||
bool add_command(ostd::ConstCharRange name, ostd::ConstCharRange args,
|
bool add_command(ostd::ConstCharRange name, ostd::ConstCharRange args,
|
||||||
IdentFunc func, int type = ID_COMMAND);
|
IdentFunc func, int type = ID_COMMAND);
|
||||||
|
|
||||||
|
ostd::String run_str(const ostd::uint *code);
|
||||||
|
ostd::String run_str(ostd::ConstCharRange code);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern CsState cstate;
|
extern CsState cstate;
|
||||||
|
@ -474,23 +477,19 @@ extern void keepcode(ostd::uint *p);
|
||||||
extern void freecode(ostd::uint *p);
|
extern void freecode(ostd::uint *p);
|
||||||
extern void executeret(const ostd::uint *code, TaggedValue &result = *cstate.result);
|
extern void executeret(const ostd::uint *code, TaggedValue &result = *cstate.result);
|
||||||
extern void executeret(const char *p, TaggedValue &result = *cstate.result);
|
extern void executeret(const char *p, TaggedValue &result = *cstate.result);
|
||||||
extern void executeret(Ident *id, TaggedValue *args, int numargs, bool lookup = false, TaggedValue &result = *cstate.result);
|
extern void executeret(Ident *id, TaggedValue *args, int numargs, TaggedValue &result = *cstate.result);
|
||||||
extern char *executestr(const ostd::uint *code);
|
extern char *executestr(const ostd::uint *code);
|
||||||
extern char *executestr(const char *p);
|
extern char *executestr(const char *p);
|
||||||
extern char *executestr(Ident *id, TaggedValue *args, int numargs, bool lookup = false);
|
extern char *executestr(Ident *id, TaggedValue *args, int numargs);
|
||||||
extern char *execidentstr(const char *name, bool lookup = false);
|
|
||||||
extern int execute(const ostd::uint *code);
|
extern int execute(const ostd::uint *code);
|
||||||
extern int execute(const char *p);
|
extern int execute(const char *p);
|
||||||
extern int execute(Ident *id, TaggedValue *args, int numargs, bool lookup = false);
|
extern int execute(Ident *id, TaggedValue *args, int numargs);
|
||||||
extern int execident(const char *name, int noid = 0, bool lookup = false);
|
|
||||||
extern float executefloat(const ostd::uint *code);
|
extern float executefloat(const ostd::uint *code);
|
||||||
extern float executefloat(const char *p);
|
extern float executefloat(const char *p);
|
||||||
extern float executefloat(Ident *id, TaggedValue *args, int numargs, bool lookup = false);
|
extern float executefloat(Ident *id, TaggedValue *args, int numargs);
|
||||||
extern float execidentfloat(const char *name, float noid = 0, bool lookup = false);
|
|
||||||
extern bool executebool(const ostd::uint *code);
|
extern bool executebool(const ostd::uint *code);
|
||||||
extern bool executebool(const char *p);
|
extern bool executebool(const char *p);
|
||||||
extern bool executebool(Ident *id, TaggedValue *args, int numargs, bool lookup = false);
|
extern bool executebool(Ident *id, TaggedValue *args, int numargs);
|
||||||
extern bool execidentbool(const char *name, bool noid = false, bool lookup = false);
|
|
||||||
extern bool execfile(const char *cfgfile, bool msg = true);
|
extern bool execfile(const char *cfgfile, bool msg = true);
|
||||||
extern void alias(const char *name, const char *action);
|
extern void alias(const char *name, const char *action);
|
||||||
extern void alias(const char *name, TaggedValue &v);
|
extern void alias(const char *name, TaggedValue &v);
|
||||||
|
|
Loading…
Reference in New Issue