rename p_stack to p_callstack in CsState

master
Daniel Kolesa 2016-09-08 21:30:08 +02:00
parent 08c4e9f343
commit f3fd6892bc
5 changed files with 36 additions and 36 deletions

View File

@ -36,10 +36,10 @@ repl: $(LIBCS_LIB) tools/repl.cc tools/linenoise.cc tools/linenoise.hh
clean: clean:
rm -f $(LIBCS_LIB) $(LIBCS_OBJ) repl rm -f $(LIBCS_LIB) $(LIBCS_OBJ) repl
cubescript.o: cubescript.hh cubescript_conf.hh cs_vm.hh src/cubescript.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh
cs_gen.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh src/cs_gen.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
cs_vm.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh src/cs_vm.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
cs_val.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh src/cs_val.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
lib_str.o: cubescript.hh cubescript_conf.hh src/lib_str.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh
lib_math.o: cubescript.hh cubescript_conf.hh src/lib_math.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh
lib_list.o: cubescript.hh cubescript_conf.hh cs_util.hh src/lib_list.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_util.hh

View File

@ -322,7 +322,7 @@ struct OSTD_EXPORT CsState {
CsVector<CsIdent *> identmap; CsVector<CsIdent *> identmap;
CsIdentLink noalias; CsIdentLink noalias;
CsIdentLink *p_stack = &noalias; CsIdentLink *p_callstack = &noalias;
int identflags = 0; int identflags = 0;
int nodebug = 0; int nodebug = 0;

View File

@ -75,10 +75,10 @@ void cs_debug_alias(CsState &cs) {
return; return;
} }
int total = 0, depth = 0; int total = 0, depth = 0;
for (CsIdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) { for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
total++; total++;
} }
for (CsIdentLink *l = cs.p_stack; l != &cs.noalias; l = l->next) { for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
CsIdent *id = l->id; CsIdent *id = l->id;
++depth; ++depth;
if (depth < dalias->get_value()) { if (depth < dalias->get_value()) {
@ -436,16 +436,16 @@ static inline void cs_call_alias(
int oldflags = cs.identflags; int oldflags = cs.identflags;
cs.identflags |= a->get_flags()&CsIdfOverridden; cs.identflags |= a->get_flags()&CsIdfOverridden;
CsIdentLink aliaslink = { CsIdentLink aliaslink = {
a, cs.p_stack, (1<<callargs)-1, argstack a, cs.p_callstack, (1<<callargs)-1, argstack
}; };
cs.p_stack = &aliaslink; cs.p_callstack = &aliaslink;
ostd::Uint32 *codep = reinterpret_cast<ostd::Uint32 *>( ostd::Uint32 *codep = reinterpret_cast<ostd::Uint32 *>(
CsAliasInternal::compile_code(a, cs) CsAliasInternal::compile_code(a, cs)
); );
bcode_incr(codep); bcode_incr(codep);
runcode(cs, codep+1, (result)); runcode(cs, codep+1, (result));
bcode_decr(codep); bcode_decr(codep);
cs.p_stack = aliaslink.next; cs.p_callstack = aliaslink.next;
cs.identflags = oldflags; cs.identflags = oldflags;
for (int i = 0; i < callargs; i++) { for (int i = 0; i < callargs; i++) {
CsAliasInternal::pop_arg(static_cast<CsAlias *>(cs.identmap[i])); CsAliasInternal::pop_arg(static_cast<CsAlias *>(cs.identmap[i]));
@ -477,7 +477,7 @@ static inline CsAlias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) {
static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) { static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) {
CsIdent *id = cs.identmap[op >> 8]; CsIdent *id = cs.identmap[op >> 8];
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) { if (!(cs.p_callstack->usedargs & (1 << id->get_index()))) {
return nullptr; return nullptr;
} }
return static_cast<CsAlias *>(id); return static_cast<CsAlias *>(id);
@ -502,7 +502,7 @@ static inline int cs_get_lookupu_type(
} }
if ( if (
(id->get_index() < MaxArguments) && (id->get_index() < MaxArguments) &&
!(cs.p_stack->usedargs & (1 << id->get_index())) !(cs.p_callstack->usedargs & (1 << id->get_index()))
) { ) {
return CsIdUnknown; return CsIdUnknown;
} }
@ -642,7 +642,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
case CsCodeDoArgs | CsRetString: case CsCodeDoArgs | CsRetString:
case CsCodeDoArgs | CsRetInt: case CsCodeDoArgs | CsRetInt:
case CsCodeDoArgs | CsRetFloat: case CsCodeDoArgs | CsRetFloat:
if (cs.p_stack != &cs.noalias) { if (cs.p_callstack != &cs.noalias) {
cs_do_args(cs, [&]() { cs_do_args(cs, [&]() {
cs.run(args[--numargs].get_code(), result); cs.run(args[--numargs].get_code(), result);
force_arg(result, op & CsCodeRetMask); force_arg(result, op & CsCodeRetMask);
@ -881,12 +881,12 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
continue; continue;
case CsCodeIdentArg: { case CsCodeIdentArg: {
CsAlias *a = static_cast<CsAlias *>(cs.identmap[op >> 8]); CsAlias *a = static_cast<CsAlias *>(cs.identmap[op >> 8]);
if (!(cs.p_stack->usedargs & (1 << a->get_index()))) { if (!(cs.p_callstack->usedargs & (1 << a->get_index()))) {
CsValue nv; CsValue nv;
CsAliasInternal::push_arg( CsAliasInternal::push_arg(
a, nv, cs.p_stack->argstack[a->get_index()], false a, nv, cs.p_callstack->argstack[a->get_index()], false
); );
cs.p_stack->usedargs |= 1 << a->get_index(); cs.p_callstack->usedargs |= 1 << a->get_index();
} }
args[numargs++].set_ident(a); args[numargs++].set_ident(a);
continue; continue;
@ -903,14 +903,14 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
} }
if ( if (
id->get_index() < MaxArguments && id->get_index() < MaxArguments &&
!(cs.p_stack->usedargs & (1 << id->get_index())) !(cs.p_callstack->usedargs & (1 << id->get_index()))
) { ) {
CsValue nv; CsValue nv;
CsAliasInternal::push_arg( CsAliasInternal::push_arg(
static_cast<CsAlias *>(id), nv, static_cast<CsAlias *>(id), nv,
cs.p_stack->argstack[id->get_index()], false cs.p_callstack->argstack[id->get_index()], false
); );
cs.p_stack->usedargs |= 1 << id->get_index(); cs.p_callstack->usedargs |= 1 << id->get_index();
} }
arg.set_ident(id); arg.set_ident(id);
continue; continue;
@ -1383,7 +1383,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
result.force_null(); result.force_null();
CsIdent *id = cs.identmap[op >> 13]; CsIdent *id = cs.identmap[op >> 13];
int callargs = (op >> 8) & 0x1F, offset = numargs - callargs; int callargs = (op >> 8) & 0x1F, offset = numargs - callargs;
if (!(cs.p_stack->usedargs & (1 << id->get_index()))) { if (!(cs.p_callstack->usedargs & (1 << id->get_index()))) {
numargs = offset; numargs = offset;
force_arg(result, op & CsCodeRetMask); force_arg(result, op & CsCodeRetMask);
continue; continue;
@ -1494,7 +1494,7 @@ noid:
CsAlias *a = static_cast<CsAlias *>(id); CsAlias *a = static_cast<CsAlias *>(id);
if ( if (
a->get_index() < MaxArguments && a->get_index() < MaxArguments &&
!(cs.p_stack->usedargs & (1 << a->get_index())) !(cs.p_callstack->usedargs & (1 << a->get_index()))
) { ) {
numargs = offset - 1; numargs = offset - 1;
force_arg(result, op & CsCodeRetMask); force_arg(result, op & CsCodeRetMask);
@ -1590,7 +1590,7 @@ void CsState::run(CsIdent *id, CsValueRange args, CsValue &ret) {
case CsIdentType::Alias: { case CsIdentType::Alias: {
CsAlias *a = static_cast<CsAlias *>(id); CsAlias *a = static_cast<CsAlias *>(id);
if (a->get_index() < MaxArguments) { if (a->get_index() < MaxArguments) {
if (!(p_stack->usedargs & (1 << a->get_index()))) { if (!(p_callstack->usedargs & (1 << a->get_index()))) {
break; break;
} }
} }

View File

@ -275,12 +275,12 @@ struct CsAliasInternal {
} }
static void set_arg(CsAlias *a, CsState &cs, CsValue &v) { static void set_arg(CsAlias *a, CsState &cs, CsValue &v) {
if (cs.p_stack->usedargs & (1 << a->get_index())) { if (cs.p_callstack->usedargs & (1 << a->get_index())) {
a->p_val = ostd::move(v); a->p_val = ostd::move(v);
clean_code(a); clean_code(a);
} else { } else {
push_arg(a, v, cs.p_stack->argstack[a->get_index()], false); push_arg(a, v, cs.p_callstack->argstack[a->get_index()], false);
cs.p_stack->usedargs |= 1 << a->get_index(); cs.p_callstack->usedargs |= 1 << a->get_index();
} }
} }
@ -315,7 +315,7 @@ struct CsAliasInternal {
template<typename F> template<typename F>
static void cs_do_args(CsState &cs, F body) { static void cs_do_args(CsState &cs, F body) {
CsIdentStack argstack[MaxArguments]; CsIdentStack argstack[MaxArguments];
int argmask1 = cs.p_stack->usedargs; int argmask1 = cs.p_callstack->usedargs;
for (int i = 0; argmask1; argmask1 >>= 1, ++i) { for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
if (argmask1 & 1) { if (argmask1 & 1) {
CsAliasInternal::undo_arg( CsAliasInternal::undo_arg(
@ -323,15 +323,15 @@ static void cs_do_args(CsState &cs, F body) {
); );
} }
} }
CsIdentLink *prevstack = cs.p_stack->next; CsIdentLink *prevstack = cs.p_callstack->next;
CsIdentLink aliaslink = { CsIdentLink aliaslink = {
cs.p_stack->id, cs.p_stack, prevstack->usedargs, prevstack->argstack cs.p_callstack->id, cs.p_callstack, prevstack->usedargs, prevstack->argstack
}; };
cs.p_stack = &aliaslink; cs.p_callstack = &aliaslink;
body(); body();
prevstack->usedargs = aliaslink.usedargs; prevstack->usedargs = aliaslink.usedargs;
cs.p_stack = aliaslink.next; cs.p_callstack = aliaslink.next;
int argmask2 = cs.p_stack->usedargs; int argmask2 = cs.p_callstack->usedargs;
for (int i = 0; argmask2; argmask2 >>= 1, ++i) { for (int i = 0; argmask2; argmask2 >>= 1, ++i) {
if (argmask2 & 1) { if (argmask2 & 1) {
CsAliasInternal::redo_arg( CsAliasInternal::redo_arg(

View File

@ -276,7 +276,7 @@ CsState::CsState(): p_out(&ostd::out), p_err(&ostd::err) {
})->p_type = CsIdDo; })->p_type = CsIdDo;
new_command("doargs", "e", [this](CsValueRange args, CsValue &res) { new_command("doargs", "e", [this](CsValueRange args, CsValue &res) {
if (p_stack != &noalias) { if (p_callstack != &noalias) {
cs_do_args(*this, [&]() { run(args[0].get_code(), res); }); cs_do_args(*this, [&]() { run(args[0].get_code(), res); });
} else { } else {
run(args[0].get_code(), res); run(args[0].get_code(), res);
@ -824,7 +824,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
} }
if ( if (
(a->get_index() < MaxArguments) && (a->get_index() < MaxArguments) &&
!(p_stack->usedargs & (1 << a->get_index())) !(p_callstack->usedargs & (1 << a->get_index()))
) { ) {
return ostd::nothing; return ostd::nothing;
} }