move all alias related stuff to Alias
parent
e7ce1d2b1e
commit
f275f06a5f
58
cs_vm.cc
58
cs_vm.cc
|
@ -490,20 +490,20 @@ static inline void cs_call_alias(
|
|||
static constexpr int MaxRunDepth = 255;
|
||||
static thread_local int rundepth = 0;
|
||||
|
||||
static inline Ident *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
|
||||
static inline Alias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
|
||||
Ident *id = cs.identmap[op >> 8];
|
||||
if (id->flags & IDF_UNKNOWN) {
|
||||
cs_debug_code(cs, "unknown alias lookup: %s", id->name);
|
||||
}
|
||||
return id;
|
||||
return static_cast<Alias *>(id);
|
||||
}
|
||||
|
||||
static inline Ident *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
|
||||
static inline Alias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
|
||||
Ident *id = cs.identmap[op >> 8];
|
||||
if (!(cs.stack->usedargs&(1<<id->index))) {
|
||||
return nullptr;
|
||||
}
|
||||
return id;
|
||||
return static_cast<Alias *>(id);
|
||||
}
|
||||
|
||||
static inline int cs_get_lookupu_type(
|
||||
|
@ -971,7 +971,9 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
arg.set_str(ostd::move(id->get_str()));
|
||||
arg.set_str(ostd::move(
|
||||
static_cast<Alias *>(id)->get_str()
|
||||
));
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_str(*id->storage.sp);
|
||||
|
@ -995,11 +997,11 @@ static ostd::Uint32 const *runcode(
|
|||
);
|
||||
continue;
|
||||
case CODE_LOOKUPARG | RET_STR: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_str("");
|
||||
} else {
|
||||
args[numargs++].set_str(ostd::move(id->get_str()));
|
||||
args[numargs++].set_str(ostd::move(a->get_str()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -1008,7 +1010,7 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
arg.set_int(id->get_int());
|
||||
arg.set_int(static_cast<Alias *>(id)->get_int());
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_int(cs_parse_int(*id->storage.sp));
|
||||
|
@ -1032,11 +1034,11 @@ static ostd::Uint32 const *runcode(
|
|||
);
|
||||
continue;
|
||||
case CODE_LOOKUPARG | RET_INT: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_int(0);
|
||||
} else {
|
||||
args[numargs++].set_int(id->get_int());
|
||||
args[numargs++].set_int(a->get_int());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -1045,7 +1047,7 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
arg.set_float(id->get_float());
|
||||
arg.set_float(static_cast<Alias *>(id)->get_float());
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_float(cs_parse_float(*id->storage.sp));
|
||||
|
@ -1069,11 +1071,11 @@ static ostd::Uint32 const *runcode(
|
|||
);
|
||||
continue;
|
||||
case CODE_LOOKUPARG | RET_FLOAT: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_float(CsFloat(0));
|
||||
} else {
|
||||
args[numargs++].set_float(id->get_float());
|
||||
args[numargs++].set_float(a->get_float());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -1082,7 +1084,7 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
id->get_val(arg);
|
||||
static_cast<Alias *>(id)->get_val(arg);
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_str(*id->storage.sp);
|
||||
|
@ -1104,11 +1106,11 @@ static ostd::Uint32 const *runcode(
|
|||
cs_get_lookup_id(cs, op)->get_val(args[numargs++]);
|
||||
continue;
|
||||
case CODE_LOOKUPARG | RET_NULL: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_null();
|
||||
} else {
|
||||
id->get_val(args[numargs++]);
|
||||
a->get_val(args[numargs++]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -1118,7 +1120,7 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
id->get_cstr(arg);
|
||||
static_cast<Alias *>(id)->get_cstr(arg);
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_cstr(*id->storage.sp);
|
||||
|
@ -1140,11 +1142,11 @@ static ostd::Uint32 const *runcode(
|
|||
cs_get_lookup_id(cs, op)->get_cstr(args[numargs++]);
|
||||
continue;
|
||||
case CODE_LOOKUPMARG | RET_STR: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_cstr("");
|
||||
} else {
|
||||
id->get_cstr(args[numargs++]);
|
||||
a->get_cstr(args[numargs++]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -1153,7 +1155,7 @@ static ostd::Uint32 const *runcode(
|
|||
TaggedValue &arg = args[numargs - 1];
|
||||
switch (cs_get_lookupu_type(cs, arg, id, op)) {
|
||||
case ID_ALIAS:
|
||||
id->get_cval(arg);
|
||||
static_cast<Alias *>(id)->get_cval(arg);
|
||||
continue;
|
||||
case ID_SVAR:
|
||||
arg.set_cstr(*id->storage.sp);
|
||||
|
@ -1175,11 +1177,11 @@ static ostd::Uint32 const *runcode(
|
|||
cs_get_lookup_id(cs, op)->get_cval(args[numargs++]);
|
||||
continue;
|
||||
case CODE_LOOKUPMARG | RET_NULL: {
|
||||
Ident *id = cs_get_lookuparg_id(cs, op);
|
||||
if (!id) {
|
||||
Alias *a = cs_get_lookuparg_id(cs, op);
|
||||
if (!a) {
|
||||
args[numargs++].set_null();
|
||||
} else {
|
||||
id->get_cval(args[numargs++]);
|
||||
a->get_cval(args[numargs++]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -78,50 +78,44 @@ Svar::Svar(ostd::ConstCharRange n, char **s, VarCb f, int flagsv):
|
|||
}
|
||||
|
||||
/* ID_ALIAS */
|
||||
Alias::Alias(ostd::ConstCharRange n, char *a, int flagsv) {
|
||||
Alias::Alias(ostd::ConstCharRange n, char *a, int flagsv):
|
||||
valtype(VAL_STR), code(nullptr), stack(nullptr)
|
||||
{
|
||||
type = ID_ALIAS;
|
||||
valtype = VAL_STR;
|
||||
flags = flagsv;
|
||||
name = n;
|
||||
code = nullptr;
|
||||
stack = nullptr;
|
||||
val.s = a;
|
||||
val.len = strlen(a);
|
||||
}
|
||||
Alias::Alias(ostd::ConstCharRange n, CsInt a, int flagsv) {
|
||||
Alias::Alias(ostd::ConstCharRange n, CsInt a, int flagsv):
|
||||
valtype(VAL_INT), code(nullptr), stack(nullptr)
|
||||
{
|
||||
type = ID_ALIAS;
|
||||
valtype = VAL_INT;
|
||||
flags = flagsv;
|
||||
name = n;
|
||||
code = nullptr;
|
||||
stack = nullptr;
|
||||
val.i = a;
|
||||
}
|
||||
Alias::Alias(ostd::ConstCharRange n, CsFloat a, int flagsv) {
|
||||
Alias::Alias(ostd::ConstCharRange n, CsFloat a, int flagsv):
|
||||
valtype(VAL_FLOAT), code(nullptr), stack(nullptr)
|
||||
{
|
||||
type = ID_ALIAS;
|
||||
valtype = VAL_FLOAT;
|
||||
flags = flagsv;
|
||||
name = n;
|
||||
code = nullptr;
|
||||
stack = nullptr;
|
||||
val.f = a;
|
||||
}
|
||||
Alias::Alias(ostd::ConstCharRange n, int flagsv) {
|
||||
Alias::Alias(ostd::ConstCharRange n, int flagsv):
|
||||
valtype(VAL_NULL), code(nullptr), stack(nullptr)
|
||||
{
|
||||
type = ID_ALIAS;
|
||||
valtype = VAL_NULL;
|
||||
flags = flagsv;
|
||||
name = n;
|
||||
code = nullptr;
|
||||
stack = nullptr;
|
||||
}
|
||||
Alias::Alias(ostd::ConstCharRange n, TaggedValue const &v, int flagsv) {
|
||||
Alias::Alias(ostd::ConstCharRange n, TaggedValue const &v, int flagsv):
|
||||
valtype(v.p_type), code(nullptr), stack(nullptr), val(v)
|
||||
{
|
||||
type = ID_ALIAS;
|
||||
valtype = v.p_type;
|
||||
flags = flagsv;
|
||||
name = n;
|
||||
code = nullptr;
|
||||
stack = nullptr;
|
||||
val = v;
|
||||
}
|
||||
|
||||
/* ID_COMMAND */
|
||||
|
@ -461,7 +455,7 @@ CsInt TaggedValue::get_int() const {
|
|||
return cs_get_int(*this, get_type());
|
||||
}
|
||||
|
||||
CsInt Ident::get_int() const {
|
||||
CsInt Alias::get_int() const {
|
||||
return cs_get_int(val, get_valtype());
|
||||
}
|
||||
|
||||
|
@ -483,7 +477,7 @@ CsFloat TaggedValue::get_float() const {
|
|||
return cs_get_float(*this, get_type());
|
||||
}
|
||||
|
||||
CsFloat Ident::get_float() const {
|
||||
CsFloat Alias::get_float() const {
|
||||
return cs_get_float(val, get_valtype());
|
||||
}
|
||||
|
||||
|
@ -519,7 +513,7 @@ ostd::String TaggedValue::get_str() const {
|
|||
return cs_get_str(*this, get_type());
|
||||
}
|
||||
|
||||
ostd::String Ident::get_str() const {
|
||||
ostd::String Alias::get_str() const {
|
||||
return cs_get_str(val, get_valtype());
|
||||
}
|
||||
|
||||
|
@ -539,7 +533,7 @@ ostd::ConstCharRange TaggedValue::get_strr() const {
|
|||
return cs_get_strr(*this, get_type());
|
||||
}
|
||||
|
||||
ostd::ConstCharRange Ident::get_strr() const {
|
||||
ostd::ConstCharRange Alias::get_strr() const {
|
||||
return cs_get_strr(val, get_valtype());
|
||||
}
|
||||
|
||||
|
@ -567,7 +561,7 @@ void TaggedValue::get_val(TaggedValue &r) const {
|
|||
cs_get_val(*this, get_type(), r);
|
||||
}
|
||||
|
||||
void Ident::get_val(TaggedValue &r) const {
|
||||
void Alias::get_val(TaggedValue &r) const {
|
||||
cs_get_val(val, get_valtype(), r);
|
||||
}
|
||||
|
||||
|
@ -619,7 +613,7 @@ bool TaggedValue::get_bool() const {
|
|||
}
|
||||
}
|
||||
|
||||
void Ident::get_cstr(TaggedValue &v) const {
|
||||
void Alias::get_cstr(TaggedValue &v) const {
|
||||
switch (get_valtype()) {
|
||||
case VAL_MACRO:
|
||||
v.set_macro(val.code, val.len);
|
||||
|
@ -640,7 +634,7 @@ void Ident::get_cstr(TaggedValue &v) const {
|
|||
}
|
||||
}
|
||||
|
||||
void Ident::get_cval(TaggedValue &v) const {
|
||||
void Alias::get_cval(TaggedValue &v) const {
|
||||
switch (get_valtype()) {
|
||||
case VAL_MACRO:
|
||||
v.set_macro(val.code, val.len);
|
||||
|
|
|
@ -179,51 +179,22 @@ enum class IdentType {
|
|||
|
||||
struct OSTD_EXPORT Ident {
|
||||
ostd::byte type; /* ID_something */
|
||||
int valtype; /* ID_ALIAS */
|
||||
ostd::ushort flags;
|
||||
int index;
|
||||
ostd::String name;
|
||||
union {
|
||||
struct { /* ID_IVAR, ID_FVAR, ID_SVAR */
|
||||
union {
|
||||
struct { /* ID_IVAR */
|
||||
CsInt minval, maxval;
|
||||
};
|
||||
struct { /* ID_FVAR */
|
||||
CsFloat minvalf, maxvalf;
|
||||
};
|
||||
struct { /* ID_IVAR, ID_FVAR, ID_SVAR */
|
||||
union {
|
||||
struct { /* ID_IVAR */
|
||||
CsInt minval, maxval;
|
||||
};
|
||||
struct { /* ID_FVAR */
|
||||
CsFloat minvalf, maxvalf;
|
||||
};
|
||||
IdentValuePtr storage;
|
||||
IdentValue overrideval;
|
||||
};
|
||||
struct { /* ID_ALIAS */
|
||||
IdentValue val;
|
||||
IdentStack *stack;
|
||||
};
|
||||
IdentValuePtr storage;
|
||||
IdentValue overrideval;
|
||||
};
|
||||
|
||||
void set_value(TaggedValue const &v) {
|
||||
valtype = v.get_type();
|
||||
val = v;
|
||||
}
|
||||
|
||||
void set_value(IdentStack const &v) {
|
||||
valtype = v.valtype;
|
||||
val = v.val;
|
||||
}
|
||||
|
||||
CsFloat get_float() const;
|
||||
CsInt get_int() const;
|
||||
ostd::String get_str() const;
|
||||
ostd::ConstCharRange get_strr() const;
|
||||
void get_val(TaggedValue &r) const;
|
||||
void get_cstr(TaggedValue &v) const;
|
||||
void get_cval(TaggedValue &v) const;
|
||||
|
||||
int get_valtype() const {
|
||||
return valtype;
|
||||
}
|
||||
|
||||
IdentType get_type() const;
|
||||
|
||||
bool is_alias() const {
|
||||
|
@ -292,7 +263,10 @@ struct OSTD_EXPORT Svar: Var {
|
|||
};
|
||||
|
||||
struct OSTD_EXPORT Alias: Ident {
|
||||
int valtype;
|
||||
Bytecode *code;
|
||||
IdentStack *stack;
|
||||
IdentValue val;
|
||||
|
||||
Alias(ostd::ConstCharRange n, char *a, int flags);
|
||||
Alias(ostd::ConstCharRange n, CsInt a, int flags);
|
||||
|
@ -300,6 +274,28 @@ struct OSTD_EXPORT Alias: Ident {
|
|||
Alias(ostd::ConstCharRange n, int flags);
|
||||
Alias(ostd::ConstCharRange n, TaggedValue const &v, int flags);
|
||||
|
||||
void set_value(TaggedValue const &v) {
|
||||
valtype = v.get_type();
|
||||
val = v;
|
||||
}
|
||||
|
||||
void set_value(IdentStack const &v) {
|
||||
valtype = v.valtype;
|
||||
val = v.val;
|
||||
}
|
||||
|
||||
CsFloat get_float() const;
|
||||
CsInt get_int() const;
|
||||
ostd::String get_str() const;
|
||||
ostd::ConstCharRange get_strr() const;
|
||||
void get_val(TaggedValue &r) const;
|
||||
void get_cstr(TaggedValue &v) const;
|
||||
void get_cval(TaggedValue &v) const;
|
||||
|
||||
int get_valtype() const {
|
||||
return valtype;
|
||||
}
|
||||
|
||||
void push_arg(TaggedValue const &v, IdentStack &st, bool um = true);
|
||||
void pop_arg();
|
||||
void undo_arg(IdentStack &st);
|
||||
|
@ -473,10 +469,10 @@ enum {
|
|||
OSTD_EXPORT void init_libs(CsState &cs, int libs = CS_LIB_ALL);
|
||||
|
||||
struct OSTD_EXPORT StackedValue: TaggedValue {
|
||||
StackedValue(Alias *a = nullptr):
|
||||
StackedValue(Ident *id = nullptr):
|
||||
TaggedValue(), p_a(nullptr), p_stack(), p_pushed(false)
|
||||
{
|
||||
set_alias(a);
|
||||
set_alias(id);
|
||||
}
|
||||
|
||||
~StackedValue() {
|
||||
|
|
Loading…
Reference in New Issue