rename p_stack to p_callstack in CsState
parent
08c4e9f343
commit
f3fd6892bc
14
Makefile
14
Makefile
|
@ -36,10 +36,10 @@ repl: $(LIBCS_LIB) tools/repl.cc tools/linenoise.cc tools/linenoise.hh
|
|||
clean:
|
||||
rm -f $(LIBCS_LIB) $(LIBCS_OBJ) repl
|
||||
|
||||
cubescript.o: cubescript.hh cubescript_conf.hh cs_vm.hh
|
||||
cs_gen.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh
|
||||
cs_vm.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh
|
||||
cs_val.o: cubescript.hh cubescript_conf.hh cs_vm.hh cs_util.hh
|
||||
lib_str.o: cubescript.hh cubescript_conf.hh
|
||||
lib_math.o: cubescript.hh cubescript_conf.hh
|
||||
lib_list.o: cubescript.hh cubescript_conf.hh cs_util.hh
|
||||
src/cubescript.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh
|
||||
src/cs_gen.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
|
||||
src/cs_vm.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
|
||||
src/cs_val.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_vm.hh src/cs_util.hh
|
||||
src/lib_str.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh
|
||||
src/lib_math.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh
|
||||
src/lib_list.o: include/cubescript/cubescript.hh include/cubescript/cubescript_conf.hh src/cs_util.hh
|
||||
|
|
|
@ -322,7 +322,7 @@ struct OSTD_EXPORT CsState {
|
|||
CsVector<CsIdent *> identmap;
|
||||
|
||||
CsIdentLink noalias;
|
||||
CsIdentLink *p_stack = &noalias;
|
||||
CsIdentLink *p_callstack = &noalias;
|
||||
|
||||
int identflags = 0;
|
||||
int nodebug = 0;
|
||||
|
|
34
src/cs_vm.cc
34
src/cs_vm.cc
|
@ -75,10 +75,10 @@ void cs_debug_alias(CsState &cs) {
|
|||
return;
|
||||
}
|
||||
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++;
|
||||
}
|
||||
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;
|
||||
++depth;
|
||||
if (depth < dalias->get_value()) {
|
||||
|
@ -436,16 +436,16 @@ static inline void cs_call_alias(
|
|||
int oldflags = cs.identflags;
|
||||
cs.identflags |= a->get_flags()&CsIdfOverridden;
|
||||
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 *>(
|
||||
CsAliasInternal::compile_code(a, cs)
|
||||
);
|
||||
bcode_incr(codep);
|
||||
runcode(cs, codep+1, (result));
|
||||
bcode_decr(codep);
|
||||
cs.p_stack = aliaslink.next;
|
||||
cs.p_callstack = aliaslink.next;
|
||||
cs.identflags = oldflags;
|
||||
for (int i = 0; i < callargs; 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) {
|
||||
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 static_cast<CsAlias *>(id);
|
||||
|
@ -502,7 +502,7 @@ static inline int cs_get_lookupu_type(
|
|||
}
|
||||
if (
|
||||
(id->get_index() < MaxArguments) &&
|
||||
!(cs.p_stack->usedargs & (1 << id->get_index()))
|
||||
!(cs.p_callstack->usedargs & (1 << id->get_index()))
|
||||
) {
|
||||
return CsIdUnknown;
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
|||
case CsCodeDoArgs | CsRetString:
|
||||
case CsCodeDoArgs | CsRetInt:
|
||||
case CsCodeDoArgs | CsRetFloat:
|
||||
if (cs.p_stack != &cs.noalias) {
|
||||
if (cs.p_callstack != &cs.noalias) {
|
||||
cs_do_args(cs, [&]() {
|
||||
cs.run(args[--numargs].get_code(), result);
|
||||
force_arg(result, op & CsCodeRetMask);
|
||||
|
@ -881,12 +881,12 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
|||
continue;
|
||||
case CsCodeIdentArg: {
|
||||
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;
|
||||
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);
|
||||
continue;
|
||||
|
@ -903,14 +903,14 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
|||
}
|
||||
if (
|
||||
id->get_index() < MaxArguments &&
|
||||
!(cs.p_stack->usedargs & (1 << id->get_index()))
|
||||
!(cs.p_callstack->usedargs & (1 << id->get_index()))
|
||||
) {
|
||||
CsValue nv;
|
||||
CsAliasInternal::push_arg(
|
||||
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);
|
||||
continue;
|
||||
|
@ -1383,7 +1383,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
|
|||
result.force_null();
|
||||
CsIdent *id = cs.identmap[op >> 13];
|
||||
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;
|
||||
force_arg(result, op & CsCodeRetMask);
|
||||
continue;
|
||||
|
@ -1494,7 +1494,7 @@ noid:
|
|||
CsAlias *a = static_cast<CsAlias *>(id);
|
||||
if (
|
||||
a->get_index() < MaxArguments &&
|
||||
!(cs.p_stack->usedargs & (1 << a->get_index()))
|
||||
!(cs.p_callstack->usedargs & (1 << a->get_index()))
|
||||
) {
|
||||
numargs = offset - 1;
|
||||
force_arg(result, op & CsCodeRetMask);
|
||||
|
@ -1590,7 +1590,7 @@ void CsState::run(CsIdent *id, CsValueRange args, CsValue &ret) {
|
|||
case CsIdentType::Alias: {
|
||||
CsAlias *a = static_cast<CsAlias *>(id);
|
||||
if (a->get_index() < MaxArguments) {
|
||||
if (!(p_stack->usedargs & (1 << a->get_index()))) {
|
||||
if (!(p_callstack->usedargs & (1 << a->get_index()))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
18
src/cs_vm.hh
18
src/cs_vm.hh
|
@ -275,12 +275,12 @@ struct CsAliasInternal {
|
|||
}
|
||||
|
||||
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);
|
||||
clean_code(a);
|
||||
} else {
|
||||
push_arg(a, v, cs.p_stack->argstack[a->get_index()], false);
|
||||
cs.p_stack->usedargs |= 1 << a->get_index();
|
||||
push_arg(a, v, cs.p_callstack->argstack[a->get_index()], false);
|
||||
cs.p_callstack->usedargs |= 1 << a->get_index();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ struct CsAliasInternal {
|
|||
template<typename F>
|
||||
static void cs_do_args(CsState &cs, F body) {
|
||||
CsIdentStack argstack[MaxArguments];
|
||||
int argmask1 = cs.p_stack->usedargs;
|
||||
int argmask1 = cs.p_callstack->usedargs;
|
||||
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
|
||||
if (argmask1 & 1) {
|
||||
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 = {
|
||||
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();
|
||||
prevstack->usedargs = aliaslink.usedargs;
|
||||
cs.p_stack = aliaslink.next;
|
||||
int argmask2 = cs.p_stack->usedargs;
|
||||
cs.p_callstack = aliaslink.next;
|
||||
int argmask2 = cs.p_callstack->usedargs;
|
||||
for (int i = 0; argmask2; argmask2 >>= 1, ++i) {
|
||||
if (argmask2 & 1) {
|
||||
CsAliasInternal::redo_arg(
|
||||
|
|
|
@ -276,7 +276,7 @@ CsState::CsState(): p_out(&ostd::out), p_err(&ostd::err) {
|
|||
})->p_type = CsIdDo;
|
||||
|
||||
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); });
|
||||
} else {
|
||||
run(args[0].get_code(), res);
|
||||
|
@ -824,7 +824,7 @@ CsState::get_alias_val(ostd::ConstCharRange name) {
|
|||
}
|
||||
if (
|
||||
(a->get_index() < MaxArguments) &&
|
||||
!(p_stack->usedargs & (1 << a->get_index()))
|
||||
!(p_callstack->usedargs & (1 << a->get_index()))
|
||||
) {
|
||||
return ostd::nothing;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue