prefix APIs

master
Daniel Kolesa 2016-08-29 18:17:11 +01:00
parent 48cd1efa80
commit fd6eca6529
6 changed files with 455 additions and 455 deletions

View File

@ -420,10 +420,10 @@ static void compilelookup(GenState &gs, int ltype, int prevargs = MaxResults) {
lookup = ostd::Box<char[]>(cutword(gs.source));
if (!lookup) goto invalid;
lookupid:
Ident *id = gs.cs.new_ident(lookup.get());
CsIdent *id = gs.cs.new_ident(lookup.get());
if (id) {
switch (id->get_type()) {
case IdentType::ivar:
case CsIdentType::ivar:
gs.code.push(
CODE_IVAR | cs_ret_code(ltype, RET_INT) |
(id->get_index() << 8)
@ -440,7 +440,7 @@ lookupid:
break;
}
return;
case IdentType::fvar:
case CsIdentType::fvar:
gs.code.push(
CODE_FVAR | cs_ret_code(ltype, RET_FLOAT) |
(id->get_index() << 8)
@ -457,7 +457,7 @@ lookupid:
break;
}
return;
case IdentType::svar:
case CsIdentType::svar:
switch (ltype) {
case VAL_POP:
return;
@ -478,7 +478,7 @@ lookupid:
break;
}
goto done;
case IdentType::alias:
case CsIdentType::alias:
switch (ltype) {
case VAL_POP:
return;
@ -512,7 +512,7 @@ lookupid:
break;
}
goto done;
case IdentType::command: {
case CsIdentType::command: {
int comtype = CODE_COM, numargs = 0;
if (prevargs >= MaxResults) {
gs.code.push(CODE_ENTER);
@ -740,19 +740,19 @@ static bool compileblocksub(GenState &gs, int prevargs) {
}
lookup = ostd::Box<char[]>(cs_dup_ostr(lkup));
lookupid:
Ident *id = gs.cs.new_ident(lookup.get());
CsIdent *id = gs.cs.new_ident(lookup.get());
if (id) {
switch (id->get_type()) {
case IdentType::ivar:
case CsIdentType::ivar:
gs.code.push(CODE_IVAR | (id->get_index() << 8));
goto done;
case IdentType::fvar:
case CsIdentType::fvar:
gs.code.push(CODE_FVAR | (id->get_index() << 8));
goto done;
case IdentType::svar:
case CsIdentType::svar:
gs.code.push(CODE_SVARM | (id->get_index() << 8));
goto done;
case IdentType::alias:
case CsIdentType::alias:
gs.code.push(
(id->get_index() < MaxArguments
? CODE_LOOKUPMARG
@ -1093,10 +1093,10 @@ static void compilestatements(GenState &gs, int rettype, int brak, int prevargs)
case '\0':
gs.next_char();
if (idname) {
Ident *id = gs.cs.new_ident(idname.get());
CsIdent *id = gs.cs.new_ident(idname.get());
if (id) {
switch (id->get_type()) {
case IdentType::alias:
case CsIdentType::alias:
more = compilearg(gs, VAL_ANY, prevargs);
if (!more) {
gs.gen_str();
@ -1108,7 +1108,7 @@ static void compilestatements(GenState &gs, int rettype, int brak, int prevargs)
) | (id->get_index() << 8)
);
goto endstatement;
case IdentType::ivar:
case CsIdentType::ivar:
more = compilearg(gs, VAL_INT, prevargs);
if (!more) {
gs.gen_int();
@ -1117,7 +1117,7 @@ static void compilestatements(GenState &gs, int rettype, int brak, int prevargs)
CODE_IVAR1 | (id->get_index() << 8)
);
goto endstatement;
case IdentType::fvar:
case CsIdentType::fvar:
more = compilearg(gs, VAL_FLOAT, prevargs);
if (!more) {
gs.gen_float();
@ -1126,7 +1126,7 @@ static void compilestatements(GenState &gs, int rettype, int brak, int prevargs)
CODE_FVAR1 | (id->get_index() << 8)
);
goto endstatement;
case IdentType::svar:
case CsIdentType::svar:
more = compilearg(gs, VAL_CSTR, prevargs);
if (!more) {
gs.gen_str();
@ -1161,7 +1161,7 @@ noid:
}
gs.code.push(CODE_CALLU | (numargs << 8));
} else {
Ident *id = gs.cs.get_ident(idname.get());
CsIdent *id = gs.cs.get_ident(idname.get());
if (!id) {
if (!cs_check_num(idname.get())) {
gs.gen_str(idname.get(), true);

234
cs_vm.cc
View File

@ -6,7 +6,7 @@
namespace cscript {
static inline bool cs_has_cmd_cb(Ident *id) {
static inline bool cs_has_cmd_cb(CsIdent *id) {
if (!id->is_command() && !id->is_special()) {
return false;
}
@ -14,15 +14,15 @@ static inline bool cs_has_cmd_cb(Ident *id) {
return !!cb->cb_cftv;
}
static inline void cs_push_alias(Ident *id, IdentStack &st) {
static inline void cs_push_alias(CsIdent *id, CsIdentStack &st) {
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
static_cast<Alias *>(id)->push_arg(null_value, st);
static_cast<CsAlias *>(id)->push_arg(null_value, st);
}
}
static inline void cs_pop_alias(Ident *id) {
static inline void cs_pop_alias(CsIdent *id) {
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
}
@ -63,16 +63,16 @@ ostd::ConstCharRange cs_debug_line(
}
void cs_debug_alias(CsState &cs) {
Ivar *dalias = static_cast<Ivar *>(cs.identmap[DbgaliasIdx]);
CsIvar *dalias = static_cast<CsIvar *>(cs.identmap[DbgaliasIdx]);
if (!dalias->get_value()) {
return;
}
int total = 0, depth = 0;
for (IdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
for (CsIdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
total++;
}
for (IdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
Ident *id = l->id;
for (CsIdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) {
CsIdent *id = l->id;
++depth;
if (depth < dalias->get_value()) {
ostd::err.writefln(" %d) %s", total - depth + 1, id->get_name());
@ -449,13 +449,13 @@ static ostd::Uint32 const *runcode(
);
static inline void cs_call_alias(
CsState &cs, Alias *a, CsValue *args, CsValue &result,
CsState &cs, CsAlias *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];
CsIvar *anargs = static_cast<CsIvar *>(cs.identmap[NumargsIdx]);
CsIdentStack argstack[MaxArguments];
for(int i = 0; i < callargs; i++) {
static_cast<Alias *>(cs.identmap[i])->push_arg(
static_cast<CsAlias *>(cs.identmap[i])->push_arg(
args[offset + i], argstack[i], false
);
}
@ -463,7 +463,7 @@ static inline void cs_call_alias(
anargs->set_value(callargs);
int oldflags = cs.identflags;
cs.identflags |= a->get_flags()&IDF_OVERRIDDEN;
IdentLink aliaslink = {
CsIdentLink aliaslink = {
a, cs.p_stack, (1<<callargs)-1, argstack
};
cs.p_stack = &aliaslink;
@ -474,12 +474,12 @@ static inline void cs_call_alias(
cs.p_stack = aliaslink.next;
cs.identflags = oldflags;
for (int i = 0; i < callargs; i++) {
static_cast<Alias *>(cs.identmap[i])->pop_arg();
static_cast<CsAlias *>(cs.identmap[i])->pop_arg();
}
int argmask = aliaslink.usedargs & (~0 << callargs);
for (; argmask; ++callargs) {
if (argmask & (1 << callargs)) {
static_cast<Alias *>(cs.identmap[callargs])->pop_arg();
static_cast<CsAlias *>(cs.identmap[callargs])->pop_arg();
argmask &= ~(1 << callargs);
}
}
@ -491,24 +491,24 @@ static inline void cs_call_alias(
static constexpr int MaxRunDepth = 255;
static thread_local int rundepth = 0;
static inline Alias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
Ident *id = cs.identmap[op >> 8];
static inline CsAlias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
CsIdent *id = cs.identmap[op >> 8];
if (id->get_flags() & IDF_UNKNOWN) {
cs_debug_code(cs, "unknown alias lookup: %s", id->get_name());
}
return static_cast<Alias *>(id);
return static_cast<CsAlias *>(id);
}
static inline Alias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
Ident *id = cs.identmap[op >> 8];
static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
CsIdent *id = cs.identmap[op >> 8];
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) {
return nullptr;
}
return static_cast<Alias *>(id);
return static_cast<CsAlias *>(id);
}
static inline int cs_get_lookupu_type(
CsState &cs, CsValue &arg, Ident *&id, ostd::Uint32 op
CsState &cs, CsValue &arg, CsIdent *&id, ostd::Uint32 op
) {
if (
arg.get_type() != VAL_STR &&
@ -520,7 +520,7 @@ static inline int cs_get_lookupu_type(
id = cs.get_ident(arg.s);
if (id) {
switch(id->get_type()) {
case IdentType::alias:
case CsIdentType::alias:
if (id->get_flags() & IDF_UNKNOWN) {
break;
}
@ -532,16 +532,16 @@ static inline int cs_get_lookupu_type(
return ID_UNKNOWN;
}
return ID_ALIAS;
case IdentType::svar:
case CsIdentType::svar:
arg.cleanup();
return ID_SVAR;
case IdentType::ivar:
case CsIdentType::ivar:
arg.cleanup();
return ID_IVAR;
case IdentType::fvar:
case CsIdentType::fvar:
arg.cleanup();
return ID_FVAR;
case IdentType::command: {
case CsIdentType::command: {
arg.cleanup();
arg.set_null();
CsValue buf[MaxArguments];
@ -669,13 +669,13 @@ static ostd::Uint32 const *runcode(
result.set_null();
continue;
case CODE_PRINT:
cs.print_var(static_cast<Var *>(cs.identmap[op >> 8]));
cs.print_var(static_cast<CsVar *>(cs.identmap[op >> 8]));
continue;
case CODE_LOCAL: {
result.cleanup();
int numlocals = op >> 8, offset = numargs - numlocals;
IdentStack locals[MaxArguments];
CsIdentStack locals[MaxArguments];
for (int i = 0; i < numlocals; ++i) {
cs_push_alias(args[offset + i].id, locals[i]);
}
@ -938,7 +938,7 @@ static ostd::Uint32 const *runcode(
args[numargs++].set_ident(cs.identmap[op >> 8]);
continue;
case CODE_IDENTARG: {
Alias *a = static_cast<Alias *>(cs.identmap[op >> 8]);
CsAlias *a = static_cast<CsAlias *>(cs.identmap[op >> 8]);
if (!(cs.p_stack->usedargs & (1 << a->get_index()))) {
a->push_arg(
null_value, cs.p_stack->argstack[a->get_index()], false
@ -950,7 +950,7 @@ static ostd::Uint32 const *runcode(
}
case CODE_IDENTU: {
CsValue &arg = args[numargs - 1];
Ident *id = cs.identmap[DummyIdx];
CsIdent *id = cs.identmap[DummyIdx];
if (
arg.get_type() == VAL_STR ||
arg.get_type() == VAL_MACRO ||
@ -962,7 +962,7 @@ static ostd::Uint32 const *runcode(
id->get_index() < MaxArguments &&
!(cs.p_stack->usedargs & (1 << id->get_index()))
) {
static_cast<Alias *>(id)->push_arg(
static_cast<CsAlias *>(id)->push_arg(
null_value, cs.p_stack->argstack[id->get_index()], false
);
cs.p_stack->usedargs |= 1 << id->get_index();
@ -973,25 +973,25 @@ static ostd::Uint32 const *runcode(
}
case CODE_LOOKUPU | RET_STR: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
arg.set_str(ostd::move(
static_cast<Alias *>(id)->val_v.get_str()
static_cast<CsAlias *>(id)->val_v.get_str()
));
continue;
case ID_SVAR:
arg.set_str(static_cast<Svar *>(id)->get_value());
arg.set_str(static_cast<CsSvar *>(id)->get_value());
continue;
case ID_IVAR:
arg.set_str(ostd::move(
intstr(static_cast<Ivar *>(id)->get_value())
intstr(static_cast<CsIvar *>(id)->get_value())
));
continue;
case ID_FVAR:
arg.set_str(ostd::move(
floatstr(static_cast<Fvar *>(id)->get_value())
floatstr(static_cast<CsFvar *>(id)->get_value())
));
continue;
case ID_UNKNOWN:
@ -1007,7 +1007,7 @@ static ostd::Uint32 const *runcode(
);
continue;
case CODE_LOOKUPARG | RET_STR: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_str("");
} else {
@ -1016,23 +1016,23 @@ static ostd::Uint32 const *runcode(
continue;
}
case CODE_LOOKUPU | RET_INT: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
arg.set_int(static_cast<Alias *>(id)->val_v.get_int());
arg.set_int(static_cast<CsAlias *>(id)->val_v.get_int());
continue;
case ID_SVAR:
arg.set_int(cs_parse_int(
static_cast<Svar *>(id)->get_value()
static_cast<CsSvar *>(id)->get_value()
));
continue;
case ID_IVAR:
arg.set_int(static_cast<Ivar *>(id)->get_value());
arg.set_int(static_cast<CsIvar *>(id)->get_value());
continue;
case ID_FVAR:
arg.set_int(
CsInt(static_cast<Fvar *>(id)->get_value())
CsInt(static_cast<CsFvar *>(id)->get_value())
);
continue;
case ID_UNKNOWN:
@ -1048,7 +1048,7 @@ static ostd::Uint32 const *runcode(
);
continue;
case CODE_LOOKUPARG | RET_INT: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_int(0);
} else {
@ -1057,27 +1057,27 @@ static ostd::Uint32 const *runcode(
continue;
}
case CODE_LOOKUPU | RET_FLOAT: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
arg.set_float(
static_cast<Alias *>(id)->val_v.get_float()
static_cast<CsAlias *>(id)->val_v.get_float()
);
continue;
case ID_SVAR:
arg.set_float(cs_parse_float(
static_cast<Svar *>(id)->get_value()
static_cast<CsSvar *>(id)->get_value()
));
continue;
case ID_IVAR:
arg.set_float(CsFloat(
static_cast<Ivar *>(id)->get_value()
static_cast<CsIvar *>(id)->get_value()
));
continue;
case ID_FVAR:
arg.set_float(
static_cast<Fvar *>(id)->get_value()
static_cast<CsFvar *>(id)->get_value()
);
continue;
case ID_UNKNOWN:
@ -1093,7 +1093,7 @@ static ostd::Uint32 const *runcode(
);
continue;
case CODE_LOOKUPARG | RET_FLOAT: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_float(CsFloat(0));
} else {
@ -1102,21 +1102,21 @@ static ostd::Uint32 const *runcode(
continue;
}
case CODE_LOOKUPU | RET_NULL: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
static_cast<Alias *>(id)->val_v.get_val(arg);
static_cast<CsAlias *>(id)->val_v.get_val(arg);
continue;
case ID_SVAR:
arg.set_str(static_cast<Svar *>(id)->get_value());
arg.set_str(static_cast<CsSvar *>(id)->get_value());
continue;
case ID_IVAR:
arg.set_int(static_cast<Ivar *>(id)->get_value());
arg.set_int(static_cast<CsIvar *>(id)->get_value());
continue;
case ID_FVAR:
arg.set_float(
static_cast<Fvar *>(id)->get_value()
static_cast<CsFvar *>(id)->get_value()
);
continue;
case ID_UNKNOWN:
@ -1130,7 +1130,7 @@ static ostd::Uint32 const *runcode(
cs_get_lookup_id(cs, op)->val_v.get_val(args[numargs++]);
continue;
case CODE_LOOKUPARG | RET_NULL: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_null();
} else {
@ -1140,23 +1140,23 @@ static ostd::Uint32 const *runcode(
}
case CODE_LOOKUPMU | RET_STR: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
static_cast<Alias *>(id)->get_cstr(arg);
static_cast<CsAlias *>(id)->get_cstr(arg);
continue;
case ID_SVAR:
arg.set_cstr(static_cast<Svar *>(id)->get_value());
arg.set_cstr(static_cast<CsSvar *>(id)->get_value());
continue;
case ID_IVAR:
arg.set_str(ostd::move(
intstr(static_cast<Ivar *>(id)->get_value())
intstr(static_cast<CsIvar *>(id)->get_value())
));
continue;
case ID_FVAR:
arg.set_str(ostd::move(
floatstr(static_cast<Fvar *>(id)->get_value())
floatstr(static_cast<CsFvar *>(id)->get_value())
));
continue;
case ID_UNKNOWN:
@ -1170,7 +1170,7 @@ static ostd::Uint32 const *runcode(
cs_get_lookup_id(cs, op)->get_cstr(args[numargs++]);
continue;
case CODE_LOOKUPMARG | RET_STR: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_cstr("");
} else {
@ -1179,20 +1179,20 @@ static ostd::Uint32 const *runcode(
continue;
}
case CODE_LOOKUPMU | RET_NULL: {
Ident *id = nullptr;
CsIdent *id = nullptr;
CsValue &arg = args[numargs - 1];
switch (cs_get_lookupu_type(cs, arg, id, op)) {
case ID_ALIAS:
static_cast<Alias *>(id)->get_cval(arg);
static_cast<CsAlias *>(id)->get_cval(arg);
continue;
case ID_SVAR:
arg.set_cstr(static_cast<Svar *>(id)->get_value());
arg.set_cstr(static_cast<CsSvar *>(id)->get_value());
continue;
case ID_IVAR:
arg.set_int(static_cast<Ivar *>(id)->get_value());
arg.set_int(static_cast<CsIvar *>(id)->get_value());
continue;
case ID_FVAR:
arg.set_float(static_cast<Fvar *>(id)->get_value());
arg.set_float(static_cast<CsFvar *>(id)->get_value());
continue;
case ID_UNKNOWN:
arg.set_null();
@ -1205,7 +1205,7 @@ static ostd::Uint32 const *runcode(
cs_get_lookup_id(cs, op)->get_cval(args[numargs++]);
continue;
case CODE_LOOKUPMARG | RET_NULL: {
Alias *a = cs_get_lookuparg_id(cs, op);
CsAlias *a = cs_get_lookuparg_id(cs, op);
if (!a) {
args[numargs++].set_null();
} else {
@ -1217,27 +1217,27 @@ static ostd::Uint32 const *runcode(
case CODE_SVAR | RET_STR:
case CODE_SVAR | RET_NULL:
args[numargs++].set_str(
static_cast<Svar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsSvar *>(cs.identmap[op >> 8])->get_value()
);
continue;
case CODE_SVAR | RET_INT:
args[numargs++].set_int(cs_parse_int(
static_cast<Svar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsSvar *>(cs.identmap[op >> 8])->get_value()
));
continue;
case CODE_SVAR | RET_FLOAT:
args[numargs++].set_float(cs_parse_float(
static_cast<Svar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsSvar *>(cs.identmap[op >> 8])->get_value()
));
continue;
case CODE_SVARM:
args[numargs++].set_cstr(
static_cast<Svar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsSvar *>(cs.identmap[op >> 8])->get_value()
);
continue;
case CODE_SVAR1:
cs.set_var_str_checked(
static_cast<Svar *>(cs.identmap[op >> 8]), args[--numargs].s
static_cast<CsSvar *>(cs.identmap[op >> 8]), args[--numargs].s
);
args[numargs].cleanup();
continue;
@ -1245,34 +1245,34 @@ static ostd::Uint32 const *runcode(
case CODE_IVAR | RET_INT:
case CODE_IVAR | RET_NULL:
args[numargs++].set_int(
static_cast<Ivar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsIvar *>(cs.identmap[op >> 8])->get_value()
);
continue;
case CODE_IVAR | RET_STR:
args[numargs++].set_str(ostd::move(intstr(
static_cast<Ivar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsIvar *>(cs.identmap[op >> 8])->get_value()
)));
continue;
case CODE_IVAR | RET_FLOAT:
args[numargs++].set_float(CsFloat(
static_cast<Ivar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsIvar *>(cs.identmap[op >> 8])->get_value()
));
continue;
case CODE_IVAR1:
cs.set_var_int_checked(
static_cast<Ivar *>(cs.identmap[op >> 8]), args[--numargs].i
static_cast<CsIvar *>(cs.identmap[op >> 8]), args[--numargs].i
);
continue;
case CODE_IVAR2:
numargs -= 2;
cs.set_var_int_checked(
static_cast<Ivar *>(cs.identmap[op >> 8]),
static_cast<CsIvar *>(cs.identmap[op >> 8]),
(args[numargs].i << 16) | (args[numargs + 1].i << 8));
continue;
case CODE_IVAR3:
numargs -= 3;
cs.set_var_int_checked(
static_cast<Ivar *>(cs.identmap[op >> 8]),
static_cast<CsIvar *>(cs.identmap[op >> 8]),
(args[numargs].i << 16)
| (args[numargs + 1].i << 8)
| args[numargs + 2].i);
@ -1281,22 +1281,22 @@ static ostd::Uint32 const *runcode(
case CODE_FVAR | RET_FLOAT:
case CODE_FVAR | RET_NULL:
args[numargs++].set_float(
static_cast<Fvar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsFvar *>(cs.identmap[op >> 8])->get_value()
);
continue;
case CODE_FVAR | RET_STR:
args[numargs++].set_str(ostd::move(floatstr(
static_cast<Fvar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsFvar *>(cs.identmap[op >> 8])->get_value()
)));
continue;
case CODE_FVAR | RET_INT:
args[numargs++].set_int(int(
static_cast<Fvar *>(cs.identmap[op >> 8])->get_value()
static_cast<CsFvar *>(cs.identmap[op >> 8])->get_value()
));
continue;
case CODE_FVAR1:
cs.set_var_float_checked(
static_cast<Fvar *>(cs.identmap[op >> 8]), args[--numargs].f
static_cast<CsFvar *>(cs.identmap[op >> 8]), args[--numargs].f
);
continue;
@ -1385,12 +1385,12 @@ static ostd::Uint32 const *runcode(
}
case CODE_ALIAS:
static_cast<Alias *>(cs.identmap[op >> 8])->set_alias(
static_cast<CsAlias *>(cs.identmap[op >> 8])->set_alias(
cs, args[--numargs]
);
continue;
case CODE_ALIASARG:
static_cast<Alias *>(cs.identmap[op >> 8])->set_arg(
static_cast<CsAlias *>(cs.identmap[op >> 8])->set_arg(
cs, args[--numargs]
);
continue;
@ -1405,7 +1405,7 @@ static ostd::Uint32 const *runcode(
case CODE_CALL | RET_FLOAT:
case CODE_CALL | RET_INT: {
result.force_null();
Ident *id = cs.identmap[op >> 13];
CsIdent *id = cs.identmap[op >> 13];
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
if (id->get_flags() & IDF_UNKNOWN) {
cs_debug_code(cs, "unknown command: %s", id->get_name());
@ -1414,7 +1414,7 @@ static ostd::Uint32 const *runcode(
continue;
}
cs_call_alias(
cs, static_cast<Alias *>(id), args, result, callargs,
cs, static_cast<CsAlias *>(id), args, result, callargs,
numargs, offset, 0, op
);
continue;
@ -1424,7 +1424,7 @@ static ostd::Uint32 const *runcode(
case CODE_CALLARG | RET_FLOAT:
case CODE_CALLARG | RET_INT: {
result.force_null();
Ident *id = cs.identmap[op >> 13];
CsIdent *id = cs.identmap[op >> 13];
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) {
free_args(args, numargs, offset);
@ -1432,7 +1432,7 @@ static ostd::Uint32 const *runcode(
continue;
}
cs_call_alias(
cs, static_cast<Alias *>(id), args, result, callargs,
cs, static_cast<CsAlias *>(id), args, result, callargs,
numargs, offset, 0, op
);
continue;
@ -1458,7 +1458,7 @@ litval:
}
continue;
}
Ident *id = cs.get_ident(idarg.s);
CsIdent *id = cs.get_ident(idarg.s);
if (!id) {
noid:
if (cs_check_num(idarg.s)) {
@ -1489,7 +1489,7 @@ noid:
numargs = offset - 1;
continue;
case ID_LOCAL: {
IdentStack locals[MaxArguments];
CsIdentStack locals[MaxArguments];
idarg.cleanup();
for (ostd::Size j = 0; j < ostd::Size(callargs); ++j) {
cs_push_alias(cs.force_ident(
@ -1504,10 +1504,10 @@ noid:
}
case ID_IVAR:
if (callargs <= 0) {
cs.print_var(static_cast<Ivar *>(id));
cs.print_var(static_cast<CsIvar *>(id));
} else {
cs.set_var_int_checked(
static_cast<Ivar *>(id),
static_cast<CsIvar *>(id),
ostd::iter(&args[offset], callargs)
);
}
@ -1516,10 +1516,10 @@ noid:
continue;
case ID_FVAR:
if (callargs <= 0) {
cs.print_var(static_cast<Fvar *>(id));
cs.print_var(static_cast<CsFvar *>(id));
} else {
cs.set_var_float_checked(
static_cast<Fvar *>(id),
static_cast<CsFvar *>(id),
args[offset].force_float()
);
}
@ -1528,10 +1528,10 @@ noid:
continue;
case ID_SVAR:
if (callargs <= 0) {
cs.print_var(static_cast<Svar *>(id));
cs.print_var(static_cast<CsSvar *>(id));
} else {
cs.set_var_str_checked(
static_cast<Svar *>(id),
static_cast<CsSvar *>(id),
args[offset].force_str()
);
}
@ -1539,7 +1539,7 @@ noid:
force_arg(result, op & CODE_RET_MASK);
continue;
case ID_ALIAS: {
Alias *a = static_cast<Alias *>(id);
CsAlias *a = static_cast<CsAlias *>(id);
if (
a->get_index() < MaxArguments &&
!(cs.p_stack->usedargs & (1 << a->get_index()))
@ -1582,7 +1582,7 @@ void CsState::run_ret(ostd::ConstCharRange code, CsValue &ret) {
}
}
void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
void CsState::run_ret(CsIdent *id, CsValueRange args, CsValue &ret) {
int nargs = int(args.size());
ret.set_null();
++rundepth;
@ -1595,7 +1595,7 @@ void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
break;
}
/* fallthrough */
case IdentType::command:
case CsIdentType::command:
if (nargs < static_cast<Command *>(id)->numargs) {
CsValue buf[MaxArguments];
memcpy(buf, args.data(), args.size() * sizeof(CsValue));
@ -1611,33 +1611,33 @@ void CsState::run_ret(Ident *id, CsValueRange args, CsValue &ret) {
}
nargs = 0;
break;
case IdentType::ivar:
case CsIdentType::ivar:
if (args.empty()) {
print_var(static_cast<Ivar *>(id));
print_var(static_cast<CsIvar *>(id));
} else {
set_var_int_checked(static_cast<Ivar *>(id), args);
set_var_int_checked(static_cast<CsIvar *>(id), args);
}
break;
case IdentType::fvar:
case CsIdentType::fvar:
if (args.empty()) {
print_var(static_cast<Fvar *>(id));
print_var(static_cast<CsFvar *>(id));
} else {
set_var_float_checked(
static_cast<Fvar *>(id), args[0].force_float()
static_cast<CsFvar *>(id), args[0].force_float()
);
}
break;
case IdentType::svar:
case CsIdentType::svar:
if (args.empty()) {
print_var(static_cast<Svar *>(id));
print_var(static_cast<CsSvar *>(id));
} else {
set_var_str_checked(
static_cast<Svar *>(id), args[0].force_str()
static_cast<CsSvar *>(id), args[0].force_str()
);
}
break;
case IdentType::alias: {
Alias *a = static_cast<Alias *>(id);
case CsIdentType::alias: {
CsAlias *a = static_cast<CsAlias *>(id);
if (a->get_index() < MaxArguments) {
if (!(p_stack->usedargs & (1 << a->get_index()))) {
break;
@ -1673,7 +1673,7 @@ CsString CsState::run_str(ostd::ConstCharRange code) {
return s;
}
CsString CsState::run_str(Ident *id, CsValueRange args) {
CsString CsState::run_str(CsIdent *id, CsValueRange args) {
CsValue ret;
run_ret(id, args, ret);
CsString s = ret.get_str();
@ -1697,7 +1697,7 @@ CsInt CsState::run_int(ostd::ConstCharRange code) {
return i;
}
CsInt CsState::run_int(Ident *id, CsValueRange args) {
CsInt CsState::run_int(CsIdent *id, CsValueRange args) {
CsValue ret;
run_ret(id, args, ret);
CsInt i = ret.get_int();
@ -1721,7 +1721,7 @@ CsFloat CsState::run_float(ostd::ConstCharRange code) {
return f;
}
CsFloat CsState::run_float(Ident *id, CsValueRange args) {
CsFloat CsState::run_float(CsIdent *id, CsValueRange args) {
CsValue ret;
run_ret(id, args, ret);
CsFloat f = ret.get_float();
@ -1745,7 +1745,7 @@ bool CsState::run_bool(ostd::ConstCharRange code) {
return b;
}
bool CsState::run_bool(Ident *id, CsValueRange args) {
bool CsState::run_bool(CsIdent *id, CsValueRange args) {
CsValue ret;
run_ret(id, args, ret);
bool b = ret.get_bool();
@ -1765,7 +1765,7 @@ void CsState::run(ostd::ConstCharRange code) {
ret.cleanup();
}
void CsState::run(Ident *id, CsValueRange args) {
void CsState::run(CsIdent *id, CsValueRange args) {
CsValue ret;
run_ret(id, args, ret);
ret.cleanup();

View File

@ -22,7 +22,7 @@ enum {
ID_LOCAL, ID_DO, ID_DOARGS, ID_IF, ID_RESULT, ID_NOT, ID_AND, ID_OR
};
struct Command: Ident {
struct Command: CsIdent {
char *cargs;
ostd::Uint32 argmask;
int numargs;
@ -82,15 +82,15 @@ struct NullValue: CsValue {
template<typename F>
static void cs_do_args(CsState &cs, F body) {
IdentStack argstack[MaxArguments];
CsIdentStack argstack[MaxArguments];
int argmask1 = cs.p_stack->usedargs;
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
if (argmask1 & 1) {
static_cast<Alias *>(cs.identmap[i])->undo_arg(argstack[i]);
static_cast<CsAlias *>(cs.identmap[i])->undo_arg(argstack[i]);
}
}
IdentLink *prevstack = cs.p_stack->next;
IdentLink aliaslink = {
CsIdentLink *prevstack = cs.p_stack->next;
CsIdentLink aliaslink = {
cs.p_stack->id, cs.p_stack, prevstack->usedargs, prevstack->argstack
};
cs.p_stack = &aliaslink;
@ -100,7 +100,7 @@ static void cs_do_args(CsState &cs, F body) {
int argmask2 = cs.p_stack->usedargs;
for (int i = 0; argmask2; argmask2 >>= 1, ++i) {
if (argmask2 & 1) {
static_cast<Alias *>(cs.identmap[i])->redo_arg(argstack[i]);
static_cast<CsAlias *>(cs.identmap[i])->redo_arg(argstack[i]);
}
}
}
@ -206,7 +206,7 @@ struct GenState {
void gen_float(ostd::ConstCharRange word);
void gen_ident(Ident *id) {
void gen_ident(CsIdent *id) {
code.push(
((id->get_index() < MaxArguments)
? CODE_IDENTARG

View File

@ -38,63 +38,63 @@ bool cs_check_num(ostd::ConstCharRange s) {
}
}
Ident::Ident(IdentType tp, ostd::ConstCharRange nm, int fl):
CsIdent::CsIdent(CsIdentType tp, ostd::ConstCharRange nm, int fl):
p_name(nm), p_type(int(tp)), p_flags(fl)
{}
Var::Var(IdentType tp, ostd::ConstCharRange name, VarCb f, int fl):
Ident(tp, name, fl), cb_var(ostd::move(f))
CsVar::CsVar(CsIdentType tp, ostd::ConstCharRange name, CsVarCb f, int fl):
CsIdent(tp, name, fl), cb_var(ostd::move(f))
{}
Ivar::Ivar(
ostd::ConstCharRange name, CsInt m, CsInt x, CsInt v, VarCb f, int fl
CsIvar::CsIvar(
ostd::ConstCharRange name, CsInt m, CsInt x, CsInt v, CsVarCb f, int fl
):
Var(IdentType::ivar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
CsVar(CsIdentType::ivar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
{}
Fvar::Fvar(
ostd::ConstCharRange name, CsFloat m, CsFloat x, CsFloat v, VarCb f, int fl
CsFvar::CsFvar(
ostd::ConstCharRange name, CsFloat m, CsFloat x, CsFloat v, CsVarCb f, int fl
):
Var(IdentType::fvar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
CsVar(CsIdentType::fvar, name, ostd::move(f), fl | ((m > x) ? IDF_READONLY : 0)),
p_storage(v), p_minval(m), p_maxval(x), p_overrideval(0)
{}
Svar::Svar(ostd::ConstCharRange name, ostd::ConstCharRange v, VarCb f, int fl):
Var(IdentType::svar, name, ostd::move(f), fl),
CsSvar::CsSvar(ostd::ConstCharRange name, ostd::ConstCharRange v, CsVarCb f, int fl):
CsVar(CsIdentType::svar, name, ostd::move(f), fl),
p_storage(v), p_overrideval()
{}
Svar::Svar(ostd::ConstCharRange name, CsString &&v, VarCb f, int fl):
Var(IdentType::svar, name, ostd::move(f), fl),
CsSvar::CsSvar(ostd::ConstCharRange name, CsString &&v, CsVarCb f, int fl):
CsVar(CsIdentType::svar, name, ostd::move(f), fl),
p_storage(ostd::forward<CsString &&>(v)), p_overrideval()
{}
Alias::Alias(ostd::ConstCharRange name, char *a, int fl):
Ident(IdentType::alias, name, fl),
CsAlias::CsAlias(ostd::ConstCharRange name, char *a, int fl):
CsIdent(CsIdentType::alias, name, fl),
p_acode(nullptr), p_astack(nullptr)
{
val_v.set_mstr(a);
}
Alias::Alias(ostd::ConstCharRange name, CsInt a, int fl):
Ident(IdentType::alias, name, fl),
CsAlias::CsAlias(ostd::ConstCharRange name, CsInt a, int fl):
CsIdent(CsIdentType::alias, name, fl),
p_acode(nullptr), p_astack(nullptr)
{
val_v.set_int(a);
}
Alias::Alias(ostd::ConstCharRange name, CsFloat a, int fl):
Ident(IdentType::alias, name, fl),
CsAlias::CsAlias(ostd::ConstCharRange name, CsFloat a, int fl):
CsIdent(CsIdentType::alias, name, fl),
p_acode(nullptr), p_astack(nullptr)
{
val_v.set_float(a);
}
Alias::Alias(ostd::ConstCharRange name, int fl):
Ident(IdentType::alias, name, fl),
CsAlias::CsAlias(ostd::ConstCharRange name, int fl):
CsIdent(CsIdentType::alias, name, fl),
p_acode(nullptr), p_astack(nullptr)
{
val_v.set_null();
}
Alias::Alias(ostd::ConstCharRange name, CsValue const &v, int fl):
Ident(IdentType::alias, name, fl),
CsAlias::CsAlias(ostd::ConstCharRange name, CsValue const &v, int fl):
CsIdent(CsIdentType::alias, name, fl),
val_v(v), p_acode(nullptr), p_astack(nullptr)
{}
@ -102,147 +102,147 @@ Command::Command(
int tp, ostd::ConstCharRange name, ostd::ConstCharRange args,
ostd::Uint32 amask, int nargs, CmdFunc f
):
Ident(IdentType::command, name, 0),
CsIdent(CsIdentType::command, name, 0),
cargs(!args.empty() ? cs_dup_ostr(args) : nullptr),
argmask(amask), numargs(nargs), cb_cftv(ostd::move(f))
{
p_type = tp;
}
bool Ident::is_alias() const {
return get_type() == IdentType::alias;
bool CsIdent::is_alias() const {
return get_type() == CsIdentType::alias;
}
Alias *Ident::get_alias() {
CsAlias *CsIdent::get_alias() {
if (!is_alias()) {
return nullptr;
}
return static_cast<Alias *>(this);
return static_cast<CsAlias *>(this);
}
Alias const *Ident::get_alias() const {
CsAlias const *CsIdent::get_alias() const {
if (!is_alias()) {
return nullptr;
}
return static_cast<Alias const *>(this);
return static_cast<CsAlias const *>(this);
}
bool Ident::is_command() const {
return get_type() == IdentType::command;
bool CsIdent::is_command() const {
return get_type() == CsIdentType::command;
}
bool Ident::is_special() const {
return get_type() == IdentType::special;
bool CsIdent::is_special() const {
return get_type() == CsIdentType::special;
}
bool Ident::is_var() const {
IdentType tp = get_type();
return (tp >= IdentType::ivar) && (tp <= IdentType::svar);
bool CsIdent::is_var() const {
CsIdentType tp = get_type();
return (tp >= CsIdentType::ivar) && (tp <= CsIdentType::svar);
}
Var *Ident::get_var() {
CsVar *CsIdent::get_var() {
if (!is_var()) {
return nullptr;
}
return static_cast<Var *>(this);
return static_cast<CsVar *>(this);
}
Var const *Ident::get_var() const {
CsVar const *CsIdent::get_var() const {
if (!is_var()) {
return nullptr;
}
return static_cast<Var const *>(this);
return static_cast<CsVar const *>(this);
}
bool Ident::is_ivar() const {
return get_type() == IdentType::ivar;
bool CsIdent::is_ivar() const {
return get_type() == CsIdentType::ivar;
}
Ivar *Ident::get_ivar() {
CsIvar *CsIdent::get_ivar() {
if (!is_ivar()) {
return nullptr;
}
return static_cast<Ivar *>(this);
return static_cast<CsIvar *>(this);
}
Ivar const *Ident::get_ivar() const {
CsIvar const *CsIdent::get_ivar() const {
if (!is_ivar()) {
return nullptr;
}
return static_cast<Ivar const *>(this);
return static_cast<CsIvar const *>(this);
}
bool Ident::is_fvar() const {
return get_type() == IdentType::fvar;
bool CsIdent::is_fvar() const {
return get_type() == CsIdentType::fvar;
}
Fvar *Ident::get_fvar() {
CsFvar *CsIdent::get_fvar() {
if (!is_fvar()) {
return nullptr;
}
return static_cast<Fvar *>(this);
return static_cast<CsFvar *>(this);
}
Fvar const *Ident::get_fvar() const {
CsFvar const *CsIdent::get_fvar() const {
if (!is_fvar()) {
return nullptr;
}
return static_cast<Fvar const *>(this);
return static_cast<CsFvar const *>(this);
}
bool Ident::is_svar() const {
return get_type() == IdentType::svar;
bool CsIdent::is_svar() const {
return get_type() == CsIdentType::svar;
}
Svar *Ident::get_svar() {
CsSvar *CsIdent::get_svar() {
if (!is_svar()) {
return nullptr;
}
return static_cast<Svar *>(this);
return static_cast<CsSvar *>(this);
}
Svar const *Ident::get_svar() const {
CsSvar const *CsIdent::get_svar() const {
if (!is_svar()) {
return nullptr;
}
return static_cast<Svar const *>(this);
return static_cast<CsSvar const *>(this);
}
CsInt Ivar::get_val_min() const {
CsInt CsIvar::get_val_min() const {
return p_minval;
}
CsInt Ivar::get_val_max() const {
CsInt CsIvar::get_val_max() const {
return p_maxval;
}
CsInt Ivar::get_value() const {
CsInt CsIvar::get_value() const {
return p_storage;
}
void Ivar::set_value(CsInt val) {
void CsIvar::set_value(CsInt val) {
p_storage = val;
}
CsFloat Fvar::get_val_min() const {
CsFloat CsFvar::get_val_min() const {
return p_minval;
}
CsFloat Fvar::get_val_max() const {
CsFloat CsFvar::get_val_max() const {
return p_maxval;
}
CsFloat Fvar::get_value() const {
CsFloat CsFvar::get_value() const {
return p_storage;
}
void Fvar::set_value(CsFloat val) {
void CsFvar::set_value(CsFloat val) {
p_storage = val;
}
ostd::ConstCharRange Svar::get_value() const {
ostd::ConstCharRange CsSvar::get_value() const {
return p_storage.iter();
}
void Svar::set_value(ostd::ConstCharRange val) {
void CsSvar::set_value(ostd::ConstCharRange val) {
p_storage = val;
}
void Svar::set_value(CsString &&val) {
void CsSvar::set_value(CsString &&val) {
p_storage = ostd::forward<CsString &&>(val);
}
@ -258,13 +258,13 @@ CsState::CsState() {
snprintf(buf, sizeof(buf), "arg%d", i + 1);
new_ident(static_cast<char const *>(buf), IDF_ARG);
}
Ident *id = new_ident("//dummy");
CsIdent *id = new_ident("//dummy");
assert(id->get_index() == DummyIdx);
id = add_ident<Ivar>("numargs", MaxArguments, 0, 0);
id = add_ident<CsIvar>("numargs", MaxArguments, 0, 0);
assert(id->get_index() == NumargsIdx);
id = add_ident<Ivar>("dbgalias", 0, 1000, 4);
id = add_ident<CsIvar>("dbgalias", 0, 1000, 4);
assert(id->get_index() == DbgaliasIdx);
cs_init_lib_base(*this);
@ -272,8 +272,8 @@ CsState::CsState() {
CsState::~CsState() {
for (auto &p: idents.iter()) {
Ident *i = p.second;
Alias *a = i->get_alias();
CsIdent *i = p.second;
CsAlias *a = i->get_alias();
if (a) {
a->force_null();
a->clean_code();
@ -284,32 +284,32 @@ CsState::~CsState() {
}
}
void CsState::clear_override(Ident &id) {
void CsState::clear_override(CsIdent &id) {
if (!(id.get_flags() & IDF_OVERRIDDEN)) {
return;
}
switch (id.get_type()) {
case IdentType::alias: {
Alias &a = static_cast<Alias &>(id);
case CsIdentType::alias: {
CsAlias &a = static_cast<CsAlias &>(id);
a.cleanup_value();
a.clean_code();
a.set_value_str("");
break;
}
case IdentType::ivar: {
Ivar &iv = static_cast<Ivar &>(id);
case CsIdentType::ivar: {
CsIvar &iv = static_cast<CsIvar &>(id);
iv.set_value(iv.p_overrideval);
iv.changed();
break;
}
case IdentType::fvar: {
Fvar &fv = static_cast<Fvar &>(id);
case CsIdentType::fvar: {
CsFvar &fv = static_cast<CsFvar &>(id);
fv.set_value(fv.p_overrideval);
fv.changed();
break;
}
case IdentType::svar: {
Svar &sv = static_cast<Svar &>(id);
case CsIdentType::svar: {
CsSvar &sv = static_cast<CsSvar &>(id);
sv.set_value(sv.p_overrideval);
sv.changed();
break;
@ -326,7 +326,7 @@ void CsState::clear_overrides() {
}
}
Ident *CsState::add_ident(Ident *id) {
CsIdent *CsState::add_ident(CsIdent *id) {
if (!id) {
return nullptr;
}
@ -335,8 +335,8 @@ Ident *CsState::add_ident(Ident *id) {
return identmap.push(id);
}
Ident *CsState::new_ident(ostd::ConstCharRange name, int flags) {
Ident *id = get_ident(name);
CsIdent *CsState::new_ident(ostd::ConstCharRange name, int flags) {
CsIdent *id = get_ident(name);
if (!id) {
if (cs_check_num(name)) {
cs_debug_code(
@ -344,23 +344,23 @@ Ident *CsState::new_ident(ostd::ConstCharRange name, int flags) {
);
return identmap[DummyIdx];
}
id = add_ident<Alias>(name, flags);
id = add_ident<CsAlias>(name, flags);
}
return id;
}
Ident *CsState::force_ident(CsValue &v) {
CsIdent *CsState::force_ident(CsValue &v) {
switch (v.get_type()) {
case VAL_IDENT:
return v.id;
case VAL_MACRO:
case VAL_CSTR: {
Ident *id = new_ident(v.s);
CsIdent *id = new_ident(v.s);
v.set_ident(id);
return id;
}
case VAL_STR: {
Ident *id = new_ident(v.s);
CsIdent *id = new_ident(v.s);
delete[] v.s;
v.set_ident(id);
return id;
@ -372,7 +372,7 @@ Ident *CsState::force_ident(CsValue &v) {
}
bool CsState::reset_var(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id) {
return false;
}
@ -385,18 +385,18 @@ bool CsState::reset_var(ostd::ConstCharRange name) {
}
void CsState::touch_var(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (id && id->is_var()) {
static_cast<Var *>(id)->changed();
static_cast<CsVar *>(id)->changed();
}
}
void CsState::set_alias(ostd::ConstCharRange name, CsValue &v) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (id) {
switch (id->get_type()) {
case IdentType::alias: {
Alias *a = static_cast<Alias *>(id);
case CsIdentType::alias: {
CsAlias *a = static_cast<CsAlias *>(id);
if (a->get_index() < MaxArguments) {
a->set_arg(*this, v);
} else {
@ -404,14 +404,14 @@ void CsState::set_alias(ostd::ConstCharRange name, CsValue &v) {
}
return;
}
case IdentType::ivar:
set_var_int_checked(static_cast<Ivar *>(id), v.get_int());
case CsIdentType::ivar:
set_var_int_checked(static_cast<CsIvar *>(id), v.get_int());
break;
case IdentType::fvar:
set_var_float_checked(static_cast<Fvar *>(id), v.get_float());
case CsIdentType::fvar:
set_var_float_checked(static_cast<CsFvar *>(id), v.get_float());
break;
case IdentType::svar:
set_var_str_checked(static_cast<Svar *>(id), v.get_str());
case CsIdentType::svar:
set_var_str_checked(static_cast<CsSvar *>(id), v.get_str());
break;
default:
cs_debug_code(
@ -425,11 +425,11 @@ void CsState::set_alias(ostd::ConstCharRange name, CsValue &v) {
cs_debug_code(*this, "cannot alias number %s", name);
v.cleanup();
} else {
add_ident<Alias>(name, v, identflags);
add_ident<CsAlias>(name, v, identflags);
}
}
void CsState::print_var_int(Ivar *iv, CsInt i) {
void CsState::print_var_int(CsIvar *iv, CsInt i) {
if (i < 0) {
writefln("%s = %d", iv->get_name(), i);
return;
@ -448,11 +448,11 @@ void CsState::print_var_int(Ivar *iv, CsInt i) {
}
}
void CsState::print_var_float(Fvar *fv, CsFloat f) {
void CsState::print_var_float(CsFvar *fv, CsFloat f) {
writefln("%s = %s", fv->get_name(), floatstr(f));
}
void CsState::print_var_str(Svar *sv, ostd::ConstCharRange s) {
void CsState::print_var_str(CsSvar *sv, ostd::ConstCharRange s) {
if (ostd::find(s, '"').empty()) {
writefln("%s = \"%s\"", sv->get_name(), s);
} else {
@ -460,20 +460,20 @@ void CsState::print_var_str(Svar *sv, ostd::ConstCharRange s) {
}
}
void CsState::print_var(Var *v) {
void CsState::print_var(CsVar *v) {
switch (v->get_type()) {
case IdentType::ivar: {
Ivar *iv = static_cast<Ivar *>(v);
case CsIdentType::ivar: {
CsIvar *iv = static_cast<CsIvar *>(v);
print_var_int(iv, iv->get_value());
break;
}
case IdentType::fvar: {
Fvar *fv = static_cast<Fvar *>(v);
case CsIdentType::fvar: {
CsFvar *fv = static_cast<CsFvar *>(v);
print_var_float(fv, fv->get_value());
break;
}
case IdentType::svar: {
Svar *sv = static_cast<Svar *>(v);
case CsIdentType::svar: {
CsSvar *sv = static_cast<CsSvar *>(v);
print_var_str(sv, sv->get_value());
break;
}
@ -547,7 +547,7 @@ void CsValue::set_mstr(ostd::CharRange val) {
s = val.data();
}
void CsValue::set_ident(Ident *val) {
void CsValue::set_ident(CsIdent *val) {
p_type = VAL_IDENT;
id = val;
}
@ -666,7 +666,7 @@ CsBytecode *CsValue::get_code() const {
return const_cast<CsBytecode *>(code);
}
Ident *CsValue::get_ident() const {
CsIdent *CsValue::get_ident() const {
if (get_type() != VAL_IDENT) {
return nullptr;
}
@ -719,7 +719,7 @@ void CsValue::get_val(CsValue &r) const {
}
}
OSTD_EXPORT bool code_is_empty(CsBytecode const *code) {
OSTD_EXPORT bool cs_code_is_empty(CsBytecode const *code) {
if (!code) {
return true;
}
@ -732,7 +732,7 @@ bool CsValue::code_is_empty() const {
if (get_type() != VAL_CODE) {
return true;
}
return cscript::code_is_empty(code);
return cscript::cs_code_is_empty(code);
}
static inline bool cs_get_bool(ostd::ConstCharRange s) {
@ -767,7 +767,7 @@ bool CsValue::get_bool() const {
}
}
void Alias::get_cstr(CsValue &v) const {
void CsAlias::get_cstr(CsValue &v) const {
switch (val_v.get_type()) {
case VAL_MACRO:
v.set_macro(val_v.code, val_v.len);
@ -788,7 +788,7 @@ void Alias::get_cstr(CsValue &v) const {
}
}
void Alias::get_cval(CsValue &v) const {
void CsAlias::get_cval(CsValue &v) const {
switch (val_v.get_type()) {
case VAL_MACRO:
v.set_macro(val_v.code, val_v.len);
@ -809,7 +809,7 @@ void Alias::get_cval(CsValue &v) const {
}
}
void Alias::clean_code() {
void CsAlias::clean_code() {
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(p_acode);
if (bcode) {
bcode_decr(bcode);
@ -817,14 +817,14 @@ void Alias::clean_code() {
}
}
CsBytecode *Alias::compile_code(CsState &cs) {
CsBytecode *CsAlias::compile_code(CsState &cs) {
if (!p_acode) {
p_acode = reinterpret_cast<CsBytecode *>(compilecode(cs, val_v.get_str()));
}
return p_acode;
}
void Alias::push_arg(CsValue const &v, IdentStack &st, bool um) {
void CsAlias::push_arg(CsValue const &v, CsIdentStack &st, bool um) {
if (p_astack == &st) {
/* prevent cycles and unnecessary code elsewhere */
cleanup_value();
@ -842,19 +842,19 @@ void Alias::push_arg(CsValue const &v, IdentStack &st, bool um) {
}
}
void Alias::pop_arg() {
void CsAlias::pop_arg() {
if (!p_astack) {
return;
}
IdentStack *st = p_astack;
CsIdentStack *st = p_astack;
cleanup_value();
set_value(*p_astack);
clean_code();
p_astack = st->next;
}
void Alias::undo_arg(IdentStack &st) {
IdentStack *prev = p_astack;
void CsAlias::undo_arg(CsIdentStack &st) {
CsIdentStack *prev = p_astack;
st.val_s = val_v;
st.next = prev;
p_astack = prev->next;
@ -862,15 +862,15 @@ void Alias::undo_arg(IdentStack &st) {
clean_code();
}
void Alias::redo_arg(IdentStack const &st) {
IdentStack *prev = st.next;
void CsAlias::redo_arg(CsIdentStack const &st) {
CsIdentStack *prev = st.next;
prev->val_s = val_v;
p_astack = prev;
set_value(st);
clean_code();
}
void Alias::set_arg(CsState &cs, CsValue &v) {
void CsAlias::set_arg(CsState &cs, CsValue &v) {
if (cs.p_stack->usedargs & (1 << get_index())) {
cleanup_value();
set_value(v);
@ -881,34 +881,34 @@ void Alias::set_arg(CsState &cs, CsValue &v) {
}
}
void Alias::set_alias(CsState &cs, CsValue &v) {
void CsAlias::set_alias(CsState &cs, CsValue &v) {
cleanup_value();
set_value(v);
clean_code();
p_flags = (p_flags & cs.identflags) | cs.identflags;
}
IdentType Ident::get_type() const {
CsIdentType CsIdent::get_type() const {
if (p_type > ID_ALIAS) {
return IdentType::special;
return CsIdentType::special;
}
return IdentType(p_type);
return CsIdentType(p_type);
}
ostd::ConstCharRange Ident::get_name() const {
ostd::ConstCharRange CsIdent::get_name() const {
return p_name;
}
int Ident::get_flags() const {
int CsIdent::get_flags() const {
return p_flags;
}
int Ident::get_index() const {
int CsIdent::get_index() const {
return p_index;
}
template<typename SF>
static inline bool cs_override_var(CsState &cs, Var *v, int &vflags, SF sf) {
static inline bool cs_override_var(CsState &cs, CsVar *v, int &vflags, SF sf) {
if ((cs.identflags & IDF_OVERRIDDEN) || (vflags & IDF_OVERRIDE)) {
if (vflags & IDF_PERSIST) {
cs_debug_code(
@ -931,11 +931,11 @@ static inline bool cs_override_var(CsState &cs, Var *v, int &vflags, SF sf) {
void CsState::set_var_int(
ostd::ConstCharRange name, CsInt v, bool dofunc, bool doclamp
) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) {
return;
}
Ivar *iv = static_cast<Ivar *>(id);
CsIvar *iv = static_cast<CsIvar *>(id);
bool success = cs_override_var(
*this, iv, iv->p_flags,
[&iv]() { iv->p_overrideval = iv->get_value(); }
@ -956,11 +956,11 @@ void CsState::set_var_int(
void CsState::set_var_float(
ostd::ConstCharRange name, CsFloat v, bool dofunc, bool doclamp
) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) {
return;
}
Fvar *fv = static_cast<Fvar *>(id);
CsFvar *fv = static_cast<CsFvar *>(id);
bool success = cs_override_var(
*this, fv, fv->p_flags,
[&fv]() { fv->p_overrideval = fv->get_value(); }
@ -981,11 +981,11 @@ void CsState::set_var_float(
void CsState::set_var_str(
ostd::ConstCharRange name, ostd::ConstCharRange v, bool dofunc
) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_svar()) {
return;
}
Svar *sv = static_cast<Svar *>(id);
CsSvar *sv = static_cast<CsSvar *>(id);
bool success = cs_override_var(
*this, sv, sv->p_flags,
[&sv]() { sv->p_overrideval = sv->get_value(); }
@ -1000,64 +1000,64 @@ void CsState::set_var_str(
}
ostd::Maybe<CsInt> CsState::get_var_int(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) {
return ostd::nothing;
}
return static_cast<Ivar *>(id)->get_value();
return static_cast<CsIvar *>(id)->get_value();
}
ostd::Maybe<CsFloat> CsState::get_var_float(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) {
return ostd::nothing;
}
return static_cast<Fvar *>(id)->get_value();
return static_cast<CsFvar *>(id)->get_value();
}
ostd::Maybe<CsString> CsState::get_var_str(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_svar()) {
return ostd::nothing;
}
return CsString(static_cast<Svar *>(id)->get_value());
return CsString(static_cast<CsSvar *>(id)->get_value());
}
ostd::Maybe<CsInt> CsState::get_var_min_int(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) {
return ostd::nothing;
}
return static_cast<Ivar *>(id)->get_val_min();
return static_cast<CsIvar *>(id)->get_val_min();
}
ostd::Maybe<CsInt> CsState::get_var_max_int(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_ivar()) {
return ostd::nothing;
}
return static_cast<Ivar *>(id)->get_val_max();
return static_cast<CsIvar *>(id)->get_val_max();
}
ostd::Maybe<CsFloat> CsState::get_var_min_float(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) {
return ostd::nothing;
}
return static_cast<Fvar *>(id)->get_val_min();
return static_cast<CsFvar *>(id)->get_val_min();
}
ostd::Maybe<CsFloat> CsState::get_var_max_float(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsIdent *id = get_ident(name);
if (!id || id->is_fvar()) {
return ostd::nothing;
}
return static_cast<Fvar *>(id)->get_val_max();
return static_cast<CsFvar *>(id)->get_val_max();
}
ostd::Maybe<CsString>
CsState::get_alias_val(ostd::ConstCharRange name) {
Alias *a = get_alias(name);
CsAlias *a = get_alias(name);
if (!a) {
return ostd::nothing;
}
@ -1070,7 +1070,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
return ostd::move(a->val_v.get_str());
}
CsInt cs_clamp_var(CsState &cs, Ivar *iv, CsInt v) {
CsInt cs_clamp_var(CsState &cs, CsIvar *iv, CsInt v) {
if (v < iv->get_val_min()) {
v = iv->get_val_min();
} else if (v > iv->get_val_max()) {
@ -1092,7 +1092,7 @@ CsInt cs_clamp_var(CsState &cs, Ivar *iv, CsInt v) {
return v;
}
void CsState::set_var_int_checked(Ivar *iv, CsInt v) {
void CsState::set_var_int_checked(CsIvar *iv, CsInt v) {
if (iv->get_flags() & IDF_READONLY) {
cs_debug_code(*this, "variable '%s' is read only", iv->get_name());
return;
@ -1111,7 +1111,7 @@ void CsState::set_var_int_checked(Ivar *iv, CsInt v) {
iv->changed();
}
void CsState::set_var_int_checked(Ivar *iv, CsValueRange args) {
void CsState::set_var_int_checked(CsIvar *iv, CsValueRange args) {
CsInt v = args[0].force_int();
if ((iv->get_flags() & IDF_HEX) && (args.size() > 1)) {
v = (v << 16) | (args[1].force_int() << 8);
@ -1122,7 +1122,7 @@ void CsState::set_var_int_checked(Ivar *iv, CsValueRange args) {
set_var_int_checked(iv, v);
}
CsFloat cs_clamp_fvar(CsState &cs, Fvar *fv, CsFloat v) {
CsFloat cs_clamp_fvar(CsState &cs, CsFvar *fv, CsFloat v) {
if (v < fv->get_val_min()) {
v = fv->get_val_min();
} else if (v > fv->get_val_max()) {
@ -1137,7 +1137,7 @@ CsFloat cs_clamp_fvar(CsState &cs, Fvar *fv, CsFloat v) {
return v;
}
void CsState::set_var_float_checked(Fvar *fv, CsFloat v) {
void CsState::set_var_float_checked(CsFvar *fv, CsFloat v) {
if (fv->get_flags() & IDF_READONLY) {
cs_debug_code(*this, "variable '%s' is read only", fv->get_name());
return;
@ -1156,7 +1156,7 @@ void CsState::set_var_float_checked(Fvar *fv, CsFloat v) {
fv->changed();
}
void CsState::set_var_str_checked(Svar *sv, ostd::ConstCharRange v) {
void CsState::set_var_str_checked(CsSvar *sv, ostd::ConstCharRange v) {
if (sv->get_flags() & IDF_READONLY) {
cs_debug_code(*this, "variable '%s' is read only", sv->get_name());
return;
@ -1251,21 +1251,21 @@ void cs_init_lib_io(CsState &cs) {
});
}
static inline void cs_set_iter(Alias &a, CsInt i, IdentStack &stack) {
static inline void cs_set_iter(CsAlias &a, CsInt i, CsIdentStack &stack) {
CsValue v;
v.set_int(i);
a.push_arg(v, stack);
}
static inline void cs_do_loop(
CsState &cs, Ident &id, CsInt offset, CsInt n, CsInt step,
CsState &cs, CsIdent &id, CsInt offset, CsInt n, CsInt step,
CsBytecode *cond, CsBytecode *body
) {
if (n <= 0 || !id.is_alias()) {
return;
}
Alias &a = static_cast<Alias &>(id);
IdentStack stack;
CsAlias &a = static_cast<CsAlias &>(id);
CsIdentStack stack;
for (CsInt i = 0; i < n; ++i) {
cs_set_iter(a, offset + i * step, stack);
if (cond && !cs.run_bool(cond)) {
@ -1277,14 +1277,14 @@ static inline void cs_do_loop(
}
static inline void cs_loop_conc(
CsState &cs, CsValue &res, Ident &id, CsInt offset, CsInt n,
CsState &cs, CsValue &res, CsIdent &id, CsInt offset, CsInt n,
CsInt step, CsBytecode *body, bool space
) {
if (n <= 0 || !id.is_alias()) {
return;
}
Alias &a = static_cast<Alias &>(id);
IdentStack stack;
CsAlias &a = static_cast<CsAlias &>(id);
CsIdentStack stack;
CsVector<char> s;
for (CsInt i = 0; i < n; ++i) {
cs_set_iter(a, offset + i * step, stack);
@ -1421,15 +1421,15 @@ void cs_init_lib_base(CsState &cs) {
});
cs_add_command(cs, "pushif", "rTe", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
CsValue &v = args[1];
CsBytecode *code = args[2].get_code();
if (!id->is_alias() || (id->get_index() < MaxArguments)) {
return;
}
Alias *a = static_cast<Alias *>(id);
CsAlias *a = static_cast<CsAlias *>(id);
if (v.get_bool()) {
IdentStack stack;
CsIdentStack stack;
a->push_arg(v, stack);
v.set_null();
cs.run_ret(code, res);
@ -1563,12 +1563,12 @@ void cs_init_lib_base(CsState &cs) {
});
cs_add_command(cs, "push", "rTe", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
if (!id->is_alias() || (id->get_index() < MaxArguments)) {
return;
}
Alias *a = static_cast<Alias *>(id);
IdentStack stack;
CsAlias *a = static_cast<CsAlias *>(id);
CsIdentStack stack;
CsValue &v = args[1];
a->push_arg(v, stack);
v.set_null();

View File

@ -62,16 +62,16 @@ private:
CsBytecode *p_code;
};
OSTD_EXPORT bool code_is_empty(CsBytecode const *code);
OSTD_EXPORT bool cs_code_is_empty(CsBytecode const *code);
struct Ident;
struct CsIdent;
struct OSTD_EXPORT CsValue {
union {
CsInt i; /* ID_IVAR, VAL_INT */
CsFloat f; /* ID_FVAR, VAL_FLOAT */
CsBytecode const *code; /* VAL_CODE */
Ident *id; /* VAL_IDENT */
CsIdent *id; /* VAL_IDENT */
char *s; /* ID_SVAR, VAL_STR */
char const *cstr; /* VAL_CSTR */
};
@ -86,7 +86,7 @@ struct OSTD_EXPORT CsValue {
void set_code(CsBytecode const *val);
void set_cstr(ostd::ConstCharRange val);
void set_mstr(ostd::CharRange val);
void set_ident(Ident *val);
void set_ident(CsIdent *val);
void set_macro(CsBytecode const *val, ostd::Size ln);
void set(CsValue &tv);
@ -96,7 +96,7 @@ struct OSTD_EXPORT CsValue {
CsInt get_int() const;
CsFloat get_float() const;
CsBytecode *get_code() const;
Ident *get_ident() const;
CsIdent *get_ident() const;
void get_val(CsValue &r) const;
bool get_bool() const;
@ -117,63 +117,63 @@ private:
using CsValueRange = ostd::PointerRange<CsValue>;
struct IdentStack {
struct CsIdentStack {
CsValue val_s;
IdentStack *next;
CsIdentStack *next;
};
struct CsState;
enum class IdentType {
enum class CsIdentType {
ivar = 0, fvar, svar, command, alias, special
};
struct Var;
struct Ivar;
struct Fvar;
struct Svar;
struct Alias;
struct CsVar;
struct CsIvar;
struct CsFvar;
struct CsSvar;
struct CsAlias;
struct OSTD_EXPORT Ident {
struct OSTD_EXPORT CsIdent {
friend struct CsState;
IdentType get_type() const;
CsIdentType get_type() const;
ostd::ConstCharRange get_name() const;
int get_flags() const;
int get_index() const;
bool is_alias() const;
Alias *get_alias();
Alias const *get_alias() const;
CsAlias *get_alias();
CsAlias const *get_alias() const;
bool is_command() const;
bool is_special() const;
bool is_var() const;
Var *get_var();
Var const *get_var() const;
CsVar *get_var();
CsVar const *get_var() const;
bool is_ivar() const;
Ivar *get_ivar();
Ivar const *get_ivar() const;
CsIvar *get_ivar();
CsIvar const *get_ivar() const;
bool is_fvar() const;
Fvar *get_fvar();
Fvar const *get_fvar() const;
CsFvar *get_fvar();
CsFvar const *get_fvar() const;
bool is_svar() const;
Svar *get_svar();
Svar const *get_svar() const;
CsSvar *get_svar();
CsSvar const *get_svar() const;
int get_type_raw() const {
return p_type;
}
protected:
Ident(IdentType tp, ostd::ConstCharRange name, int flags = 0);
CsIdent(CsIdentType tp, ostd::ConstCharRange name, int flags = 0);
CsString p_name;
/* represents the IdentType above, but internally it has a wider variety
/* represents the CsIdentType above, but internally it has a wider variety
* of values, so it's an int here (maps to an internal enum)
*/
int p_type, p_flags;
@ -182,16 +182,16 @@ private:
int p_index = -1;
};
using VarCb = ostd::Function<void(Ident &)>;
using CsVarCb = ostd::Function<void(CsIdent &)>;
struct OSTD_EXPORT Var: Ident {
struct OSTD_EXPORT CsVar: CsIdent {
friend struct CsState;
protected:
Var(IdentType tp, ostd::ConstCharRange name, VarCb func, int flags = 0);
CsVar(CsIdentType tp, ostd::ConstCharRange name, CsVarCb func, int flags = 0);
private:
VarCb cb_var;
CsVarCb cb_var;
void changed() {
if (cb_var) {
@ -200,7 +200,7 @@ private:
}
};
struct OSTD_EXPORT Ivar: Var {
struct OSTD_EXPORT CsIvar: CsVar {
friend struct CsState;
CsInt get_val_min() const;
@ -209,16 +209,16 @@ struct OSTD_EXPORT Ivar: Var {
CsInt get_value() const;
void set_value(CsInt val);
Ivar(
CsIvar(
ostd::ConstCharRange n, CsInt m, CsInt x, CsInt v,
VarCb f = VarCb(), int flags = 0
CsVarCb f = CsVarCb(), int flags = 0
);
private:
CsInt p_storage, p_minval, p_maxval, p_overrideval;
};
struct OSTD_EXPORT Fvar: Var {
struct OSTD_EXPORT CsFvar: CsVar {
friend struct CsState;
CsFloat get_val_min() const;
@ -227,28 +227,28 @@ struct OSTD_EXPORT Fvar: Var {
CsFloat get_value() const;
void set_value(CsFloat val);
Fvar(
CsFvar(
ostd::ConstCharRange n, CsFloat m, CsFloat x, CsFloat v,
VarCb f = VarCb(), int flags = 0
CsVarCb f = CsVarCb(), int flags = 0
);
private:
CsFloat p_storage, p_minval, p_maxval, p_overrideval;
};
struct OSTD_EXPORT Svar: Var {
struct OSTD_EXPORT CsSvar: CsVar {
friend struct CsState;
ostd::ConstCharRange get_value() const;
void set_value(ostd::ConstCharRange val);
void set_value(CsString &&val);
Svar(
ostd::ConstCharRange n, ostd::ConstCharRange v, VarCb f = VarCb(),
CsSvar(
ostd::ConstCharRange n, ostd::ConstCharRange v, CsVarCb f = CsVarCb(),
int flags = 0
);
Svar(
ostd::ConstCharRange n, CsString &&v, VarCb f = VarCb(),
CsSvar(
ostd::ConstCharRange n, CsString &&v, CsVarCb f = CsVarCb(),
int flags = 0
);
@ -256,20 +256,20 @@ private:
CsString p_storage, p_overrideval;
};
struct OSTD_EXPORT Alias: Ident {
struct OSTD_EXPORT CsAlias: CsIdent {
CsValue val_v;
Alias(ostd::ConstCharRange n, char *a, int flags);
Alias(ostd::ConstCharRange n, CsInt a, int flags);
Alias(ostd::ConstCharRange n, CsFloat a, int flags);
Alias(ostd::ConstCharRange n, int flags);
Alias(ostd::ConstCharRange n, CsValue const &v, int flags);
CsAlias(ostd::ConstCharRange n, char *a, int flags);
CsAlias(ostd::ConstCharRange n, CsInt a, int flags);
CsAlias(ostd::ConstCharRange n, CsFloat a, int flags);
CsAlias(ostd::ConstCharRange n, int flags);
CsAlias(ostd::ConstCharRange n, CsValue const &v, int flags);
void set_value(CsValue const &v) {
val_v = v;
}
void set_value(IdentStack const &v) {
void set_value(CsIdentStack const &v) {
val_v = v.val_s;
}
@ -292,10 +292,10 @@ struct OSTD_EXPORT Alias: Ident {
void get_cstr(CsValue &v) const;
void get_cval(CsValue &v) const;
void push_arg(CsValue const &v, IdentStack &st, bool um = true);
void push_arg(CsValue const &v, CsIdentStack &st, bool um = true);
void pop_arg();
void undo_arg(IdentStack &st);
void redo_arg(IdentStack const &st);
void undo_arg(CsIdentStack &st);
void redo_arg(CsIdentStack const &st);
void set_arg(CsState &cs, CsValue &v);
void set_alias(CsState &cs, CsValue &v);
@ -310,14 +310,14 @@ struct OSTD_EXPORT Alias: Ident {
private:
CsBytecode *p_acode;
IdentStack *p_astack;
CsIdentStack *p_astack;
};
struct IdentLink {
Ident *id;
IdentLink *next;
struct CsIdentLink {
CsIdent *id;
CsIdentLink *next;
int usedargs;
IdentStack *argstack;
CsIdentStack *argstack;
};
enum {
@ -331,11 +331,11 @@ enum {
using CmdFunc = ostd::Function<void(CsValueRange, CsValue &)>;
struct OSTD_EXPORT CsState {
CsMap<ostd::ConstCharRange, Ident *> idents;
CsVector<Ident *> identmap;
CsMap<ostd::ConstCharRange, CsIdent *> idents;
CsVector<CsIdent *> identmap;
IdentLink noalias;
IdentLink *p_stack = &noalias;
CsIdentLink noalias;
CsIdentLink *p_stack = &noalias;
int identflags = 0;
int nodebug = 0;
@ -345,31 +345,31 @@ struct OSTD_EXPORT CsState {
void init_libs(int libs = CS_LIB_ALL);
void clear_override(Ident &id);
void clear_override(CsIdent &id);
void clear_overrides();
Ident *new_ident(ostd::ConstCharRange name, int flags = IDF_UNKNOWN);
Ident *force_ident(CsValue &v);
CsIdent *new_ident(ostd::ConstCharRange name, int flags = IDF_UNKNOWN);
CsIdent *force_ident(CsValue &v);
template<typename T, typename ...A>
T *add_ident(A &&...args) {
return static_cast<T *>(add_ident(new T(ostd::forward<A>(args)...)));
}
Ident *get_ident(ostd::ConstCharRange name) {
Ident **id = idents.at(name);
CsIdent *get_ident(ostd::ConstCharRange name) {
CsIdent **id = idents.at(name);
if (!id) {
return nullptr;
}
return *id;
}
Alias *get_alias(ostd::ConstCharRange name) {
Ident *id = get_ident(name);
CsAlias *get_alias(ostd::ConstCharRange name) {
CsIdent *id = get_ident(name);
if (!id->is_alias()) {
return nullptr;
}
return static_cast<Alias *>(id);
return static_cast<CsAlias *>(id);
}
bool have_ident(ostd::ConstCharRange name) {
@ -385,27 +385,27 @@ struct OSTD_EXPORT CsState {
CsString run_str(CsBytecode const *code);
CsString run_str(ostd::ConstCharRange code);
CsString run_str(Ident *id, CsValueRange args);
CsString run_str(CsIdent *id, CsValueRange args);
CsInt run_int(CsBytecode const *code);
CsInt run_int(ostd::ConstCharRange code);
CsInt run_int(Ident *id, CsValueRange args);
CsInt run_int(CsIdent *id, CsValueRange args);
CsFloat run_float(CsBytecode const *code);
CsFloat run_float(ostd::ConstCharRange code);
CsFloat run_float(Ident *id, CsValueRange args);
CsFloat run_float(CsIdent *id, CsValueRange args);
bool run_bool(CsBytecode const *code);
bool run_bool(ostd::ConstCharRange code);
bool run_bool(Ident *id, CsValueRange args);
bool run_bool(CsIdent *id, CsValueRange args);
void run_ret(CsBytecode const *code, CsValue &ret);
void run_ret(ostd::ConstCharRange code, CsValue &ret);
void run_ret(Ident *id, CsValueRange args, CsValue &ret);
void run_ret(CsIdent *id, CsValueRange args, CsValue &ret);
void run(CsBytecode const *code);
void run(ostd::ConstCharRange code);
void run(Ident *id, CsValueRange args);
void run(CsIdent *id, CsValueRange args);
ostd::Maybe<CsString> run_file_str(ostd::ConstCharRange fname);
ostd::Maybe<CsInt> run_file_int(ostd::ConstCharRange fname);
@ -428,10 +428,10 @@ struct OSTD_EXPORT CsState {
ostd::ConstCharRange name, ostd::ConstCharRange v, bool dofunc = true
);
void set_var_int_checked(Ivar *iv, CsInt v);
void set_var_int_checked(Ivar *iv, CsValueRange args);
void set_var_float_checked(Fvar *fv, CsFloat v);
void set_var_str_checked(Svar *fv, ostd::ConstCharRange v);
void set_var_int_checked(CsIvar *iv, CsInt v);
void set_var_int_checked(CsIvar *iv, CsValueRange args);
void set_var_float_checked(CsFvar *fv, CsFloat v);
void set_var_str_checked(CsSvar *fv, ostd::ConstCharRange v);
ostd::Maybe<CsInt> get_var_int(ostd::ConstCharRange name);
ostd::Maybe<CsFloat> get_var_float(ostd::ConstCharRange name);
@ -445,17 +445,17 @@ struct OSTD_EXPORT CsState {
ostd::Maybe<CsString> get_alias_val(ostd::ConstCharRange name);
void print_var(Var *v);
void print_var_int(Ivar *iv, CsInt i);
void print_var_float(Fvar *fv, CsFloat f);
void print_var_str(Svar *sv, ostd::ConstCharRange s);
void print_var(CsVar *v);
void print_var_int(CsIvar *iv, CsInt i);
void print_var_float(CsFvar *fv, CsFloat f);
void print_var_str(CsSvar *sv, ostd::ConstCharRange s);
private:
Ident *add_ident(Ident *id);
CsIdent *add_ident(CsIdent *id);
};
struct OSTD_EXPORT StackedValue: CsValue {
StackedValue(Ident *id = nullptr):
StackedValue(CsIdent *id = nullptr):
CsValue(), p_a(nullptr), p_stack(), p_pushed(false)
{
set_alias(id);
@ -465,15 +465,15 @@ struct OSTD_EXPORT StackedValue: CsValue {
pop();
}
bool set_alias(Ident *id) {
bool set_alias(CsIdent *id) {
if (!id || !id->is_alias()) {
return false;
}
p_a = static_cast<Alias *>(id);
p_a = static_cast<CsAlias *>(id);
return true;
}
Alias *get_alias() const {
CsAlias *get_alias() const {
return p_a;
}
@ -500,8 +500,8 @@ struct OSTD_EXPORT StackedValue: CsValue {
}
private:
Alias *p_a;
IdentStack p_stack;
CsAlias *p_a;
CsIdentStack p_stack;
bool p_pushed;
};

View File

@ -68,25 +68,25 @@ static inline void cs_list_assoc(CsValueRange args, CsValue &res, F cmp) {
}
}
static inline void cs_set_iter(Alias &a, char *val, IdentStack &stack) {
static inline void cs_set_iter(CsAlias &a, char *val, CsIdentStack &stack) {
CsValue v;
v.set_mstr(val);
a.push_arg(v, stack);
}
static void cs_loop_list_conc(
CsState &cs, CsValue &res, Ident *id, ostd::ConstCharRange list,
CsState &cs, CsValue &res, CsIdent *id, ostd::ConstCharRange list,
CsBytecode const *body, bool space
) {
if (!id->is_alias()) {
return;
}
IdentStack stack;
CsIdentStack stack;
CsVector<char> r;
int n = 0;
for (util::ListParser p(list); p.parse(); ++n) {
char *val = p.element().disown();
cs_set_iter(*static_cast<Alias *>(id), val, stack);
cs_set_iter(*static_cast<CsAlias *>(id), val, stack);
if (n && space) {
r.push(' ');
}
@ -97,7 +97,7 @@ static void cs_loop_list_conc(
v.cleanup();
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
r.push('\0');
ostd::Size len = r.size();
@ -201,17 +201,17 @@ void cs_init_lib_list(CsState &cs) {
});
cs.add_command("listfind", "rse", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
auto body = args[2].get_code();
if (!id->is_alias()) {
res.set_int(-1);
return;
}
IdentStack stack;
CsIdentStack stack;
int n = -1;
for (util::ListParser p(args[1].get_strr()); p.parse();) {
++n;
cs_set_iter(*static_cast<Alias *>(id), cs_dup_ostr(p.item), stack);
cs_set_iter(*static_cast<CsAlias *>(id), cs_dup_ostr(p.item), stack);
if (cs.run_bool(body)) {
res.set_int(CsInt(n));
goto found;
@ -220,21 +220,21 @@ void cs_init_lib_list(CsState &cs) {
res.set_int(-1);
found:
if (n >= 0) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
});
cs.add_command("listassoc", "rse", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
auto body = args[2].get_code();
if (!id->is_alias()) {
return;
}
IdentStack stack;
CsIdentStack stack;
int n = -1;
for (util::ListParser p(args[1].get_strr()); p.parse();) {
++n;
cs_set_iter(*static_cast<Alias *>(id), cs_dup_ostr(p.item), stack);
cs_set_iter(*static_cast<CsAlias *>(id), cs_dup_ostr(p.item), stack);
if (cs.run_bool(body)) {
if (p.parse()) {
auto elem = p.element();
@ -249,7 +249,7 @@ found:
}
}
if (n >= 0) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
});
@ -298,70 +298,70 @@ found:
});
cs.add_command("looplist", "rse", [&cs](CsValueRange args, CsValue &) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
auto body = args[2].get_code();
if (!id->is_alias()) {
return;
}
IdentStack stack;
CsIdentStack stack;
int n = 0;
for (util::ListParser p(args[1].get_strr()); p.parse(); ++n) {
cs_set_iter(*static_cast<Alias *>(id), p.element().disown(), stack);
cs_set_iter(*static_cast<CsAlias *>(id), p.element().disown(), stack);
cs.run_int(body);
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
});
cs.add_command("looplist2", "rrse", [&cs](CsValueRange args, CsValue &) {
Ident *id = args[0].get_ident(), *id2 = args[1].get_ident();
CsIdent *id = args[0].get_ident(), *id2 = args[1].get_ident();
auto body = args[3].get_code();
if (!id->is_alias() || !id2->is_alias()) {
return;
}
IdentStack stack, stack2;
CsIdentStack stack, stack2;
int n = 0;
for (util::ListParser p(args[2].get_strr()); p.parse(); n += 2) {
cs_set_iter(*static_cast<Alias *>(id), p.element().disown(), stack);
cs_set_iter(*static_cast<CsAlias *>(id), p.element().disown(), stack);
cs_set_iter(
*static_cast<Alias *>(id2),
*static_cast<CsAlias *>(id2),
p.parse() ? p.element().disown() : cs_dup_ostr(""), stack2
);
cs.run_int(body);
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<Alias *>(id2)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
static_cast<CsAlias *>(id2)->pop_arg();
}
});
cs.add_command("looplist3", "rrrse", [&cs](CsValueRange args, CsValue &) {
Ident *id = args[0].get_ident();
Ident *id2 = args[1].get_ident();
Ident *id3 = args[2].get_ident();
CsIdent *id = args[0].get_ident();
CsIdent *id2 = args[1].get_ident();
CsIdent *id3 = args[2].get_ident();
auto body = args[4].get_code();
if (!id->is_alias() || !id2->is_alias() || !id3->is_alias()) {
return;
}
IdentStack stack, stack2, stack3;
CsIdentStack stack, stack2, stack3;
int n = 0;
for (util::ListParser p(args[3].get_strr()); p.parse(); n += 3) {
cs_set_iter(*static_cast<Alias *>(id), p.element().disown(), stack);
cs_set_iter(*static_cast<CsAlias *>(id), p.element().disown(), stack);
cs_set_iter(
*static_cast<Alias *>(id2),
*static_cast<CsAlias *>(id2),
p.parse() ? p.element().disown() : cs_dup_ostr(""), stack2
);
cs_set_iter(
*static_cast<Alias *>(id3),
*static_cast<CsAlias *>(id3),
p.parse() ? p.element().disown() : cs_dup_ostr(""), stack3
);
cs.run_int(body);
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<Alias *>(id2)->pop_arg();
static_cast<Alias *>(id3)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
static_cast<CsAlias *>(id2)->pop_arg();
static_cast<CsAlias *>(id3)->pop_arg();
}
});
@ -384,17 +384,17 @@ found:
});
cs.add_command("listfilter", "rse", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
auto body = args[2].get_code();
if (!id->is_alias()) {
return;
}
IdentStack stack;
CsIdentStack stack;
CsVector<char> r;
int n = 0;
for (util::ListParser p(args[1].get_strr()); p.parse(); ++n) {
char *val = cs_dup_ostr(p.item);
cs_set_iter(*static_cast<Alias *>(id), val, stack);
cs_set_iter(*static_cast<CsAlias *>(id), val, stack);
if (cs.run_bool(body)) {
if (r.size()) {
r.push(' ');
@ -403,7 +403,7 @@ found:
}
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
r.push('\0');
ostd::Size len = r.size() - 1;
@ -411,22 +411,22 @@ found:
});
cs.add_command("listcount", "rse", [&cs](CsValueRange args, CsValue &res) {
Ident *id = args[0].get_ident();
CsIdent *id = args[0].get_ident();
auto body = args[2].get_code();
if (!id->is_alias()) {
return;
}
IdentStack stack;
CsIdentStack stack;
int n = 0, r = 0;
for (util::ListParser p(args[1].get_strr()); p.parse(); ++n) {
char *val = cs_dup_ostr(p.item);
cs_set_iter(*static_cast<Alias *>(id), val, stack);
cs_set_iter(*static_cast<CsAlias *>(id), val, stack);
if (cs.run_bool(body)) {
r++;
}
}
if (n) {
static_cast<Alias *>(id)->pop_arg();
static_cast<CsAlias *>(id)->pop_arg();
}
res.set_int(r);
});
@ -538,7 +538,7 @@ struct ListSortItem {
struct ListSortFun {
CsState &cs;
Alias *x, *y;
CsAlias *x, *y;
CsBytecode *body;
bool operator()(ListSortItem const &xval, ListSortItem const &yval) {
@ -551,14 +551,14 @@ struct ListSortFun {
};
static void cs_list_sort(
CsState &cs, CsValue &res, ostd::ConstCharRange list, Ident *x, Ident *y,
CsState &cs, CsValue &res, ostd::ConstCharRange list, CsIdent *x, CsIdent *y,
CsBytecode *body, CsBytecode *unique
) {
if (x == y || !x->is_alias() || !y->is_alias()) {
return;
}
Alias *xa = static_cast<Alias *>(x), *ya = static_cast<Alias *>(y);
CsAlias *xa = static_cast<CsAlias *>(x), *ya = static_cast<CsAlias *>(y);
CsVector<ListSortItem> items;
ostd::Size clen = list.size();
@ -581,7 +581,7 @@ static void cs_list_sort(
CsValue nv;
nv.set_null();
IdentStack xstack, ystack;
CsIdentStack xstack, ystack;
xa->push_arg(nv, xstack);
ya->push_arg(nv, ystack);
@ -590,7 +590,7 @@ static void cs_list_sort(
if (body) {
ListSortFun f = { cs, xa, ya, body };
ostd::sort_cmp(items.iter(), f);
if (!code_is_empty(unique)) {
if (!cs_code_is_empty(unique)) {
f.body = unique;
totaluniq = items[0].quote.size();
nuniq = 1;