Browse Source

style fixes

master
Daniel Kolesa 3 years ago
parent
commit
8805594bc2
8 changed files with 58 additions and 58 deletions
  1. +1
    -1
      include/cubescript/cubescript.hh
  2. +2
    -2
      src/cs_util.hh
  3. +2
    -2
      src/cs_val.cc
  4. +10
    -10
      src/cs_vm.cc
  5. +6
    -6
      src/cs_vm.hh
  6. +6
    -6
      src/cubescript.cc
  7. +7
    -7
      src/lib_list.cc
  8. +24
    -24
      src/lib_math.cc

+ 1
- 1
include/cubescript/cubescript.hh View File

@ -276,7 +276,7 @@ private:
struct OSTD_EXPORT cs_alias: cs_ident {
friend struct cs_state;
friend struct cs_shared_state;
friend struct cs_aliasInternal;
friend struct cs_alias_internal;
cs_value const &get_value() const {
return p_val;


+ 2
- 2
src/cs_util.hh View File

@ -9,10 +9,10 @@
namespace cscript {
template<typename K, typename V>
using CsMap = std::unordered_map<K, V>;
using cs_map = std::unordered_map<K, V>;
template<typename T>
using CsVector = std::vector<T>;
using cs_vector = std::vector<T>;
cs_int cs_parse_int(
ostd::string_range input, ostd::string_range *end = nullptr


+ 2
- 2
src/cs_val.cc View File

@ -416,7 +416,7 @@ bool cs_stacked_value::push() {
if (!p_a) {
return false;
}
cs_aliasInternal::push_arg(p_a, *this, p_stack);
cs_alias_internal::push_arg(p_a, *this, p_stack);
p_pushed = true;
return true;
}
@ -425,7 +425,7 @@ bool cs_stacked_value::pop() {
if (!p_pushed || !p_a) {
return false;
}
cs_aliasInternal::pop_arg(p_a);
cs_alias_internal::pop_arg(p_a);
p_pushed = false;
return true;
}


+ 10
- 10
src/cs_vm.cc View File

@ -25,13 +25,13 @@ struct cs_cmd_internal {
static inline void cs_push_alias(cs_ident *id, cs_ident_stack &st) {
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
cs_value nv;
cs_aliasInternal::push_arg(static_cast<cs_alias *>(id), nv, st);
cs_alias_internal::push_arg(static_cast<cs_alias *>(id), nv, st);
}
}
static inline void cs_pop_alias(cs_ident *id) {
if (id->is_alias() && (id->get_index() >= MaxArguments)) {
cs_aliasInternal::pop_arg(static_cast<cs_alias *>(id));
cs_alias_internal::pop_arg(static_cast<cs_alias *>(id));
}
}
@ -472,7 +472,7 @@ static inline void cs_call_alias(
cs_ivar *anargs = static_cast<cs_ivar *>(cs.p_state->identmap[NumargsIdx]);
cs_ident_stack argstack[MaxArguments];
for(int i = 0; i < callargs; i++) {
cs_aliasInternal::push_arg(
cs_alias_internal::push_arg(
static_cast<cs_alias *>(cs.p_state->identmap[i]),
args[offset + i], argstack[i], false
);
@ -486,7 +486,7 @@ static inline void cs_call_alias(
};
cs.p_callstack = &aliaslink;
uint32_t *codep = reinterpret_cast<uint32_t *>(
cs_aliasInternal::compile_code(a, cs)
cs_alias_internal::compile_code(a, cs)
);
bcode_incr(codep);
cs_do_and_cleanup([&]() {
@ -496,14 +496,14 @@ static inline void cs_call_alias(
cs.p_callstack = aliaslink.next;
cs.identflags = oldflags;
for (int i = 0; i < callargs; i++) {
cs_aliasInternal::pop_arg(
cs_alias_internal::pop_arg(
static_cast<cs_alias *>(cs.p_state->identmap[i])
);
}
int argmask = aliaslink.usedargs & int(~0U << callargs);
for (; argmask; ++callargs) {
if (argmask & (1 << callargs)) {
cs_aliasInternal::pop_arg(static_cast<cs_alias *>(
cs_alias_internal::pop_arg(static_cast<cs_alias *>(
cs.p_state->identmap[callargs])
);
argmask &= ~(1 << callargs);
@ -970,7 +970,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
);
if (!cs_is_arg_used(cs, a)) {
cs_value nv;
cs_aliasInternal::push_arg(
cs_alias_internal::push_arg(
a, nv, cs.p_callstack->argstack[a->get_index()], false
);
cs.p_callstack->usedargs |= 1 << a->get_index();
@ -990,7 +990,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
}
if ((id->get_index() < MaxArguments) && !cs_is_arg_used(cs, id)) {
cs_value nv;
cs_aliasInternal::push_arg(
cs_alias_internal::push_arg(
static_cast<cs_alias *>(id), nv,
cs.p_callstack->argstack[id->get_index()], false
);
@ -1433,13 +1433,13 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) {
}
case CsCodeAlias:
cs_aliasInternal::set_alias(
cs_alias_internal::set_alias(
static_cast<cs_alias *>(cs.p_state->identmap[op >> 8]),
cs, args[--numargs]
);
continue;
case CsCodeAliasArg:
cs_aliasInternal::set_arg(
cs_alias_internal::set_arg(
static_cast<cs_alias *>(cs.p_state->identmap[op >> 8]),
cs, args[--numargs]
);


+ 6
- 6
src/cs_vm.hh View File

@ -94,8 +94,8 @@ enum {
};
struct cs_shared_state {
CsMap<ostd::string_range, cs_ident *> idents;
CsVector<cs_ident *> identmap;
cs_map<ostd::string_range, cs_ident *> idents;
cs_vector<cs_ident *> identmap;
cs_alloc_cb allocf;
void *aptr;
@ -146,7 +146,7 @@ struct cs_gen_state {
cs_state &cs;
cs_gen_state *prevps;
bool parsing = true;
CsVector<uint32_t> code;
cs_vector<uint32_t> code;
ostd::string_range source;
size_t current_line;
ostd::string_range src_name;
@ -316,7 +316,7 @@ static inline bool cs_is_arg_used(cs_state &cs, cs_ident *id) {
return cs.p_callstack->usedargs & (1 << id->get_index());
}
struct cs_aliasInternal {
struct cs_alias_internal {
static void push_arg(
cs_alias *a, cs_value &v, cs_ident_stack &st, bool um = true
) {
@ -412,7 +412,7 @@ static void cs_do_args(cs_state &cs, F body) {
int argmask1 = cs.p_callstack->usedargs;
for (int i = 0; argmask1; argmask1 >>= 1, ++i) {
if (argmask1 & 1) {
cs_aliasInternal::undo_arg(
cs_alias_internal::undo_arg(
static_cast<cs_alias *>(cs.p_state->identmap[i]), argstack[i]
);
}
@ -432,7 +432,7 @@ static void cs_do_args(cs_state &cs, F body) {
int argmask2 = cs.p_callstack->usedargs;
for (int i = 0; argmask2; argmask2 >>= 1, ++i) {
if (argmask2 & 1) {
cs_aliasInternal::redo_arg(
cs_alias_internal::redo_arg(
static_cast<cs_alias *>(cs.p_state->identmap[i]), argstack[i]
);
}


+ 6
- 6
src/cubescript.cc View File

@ -428,7 +428,7 @@ OSTD_EXPORT void cs_state::destroy() {
cs_alias *a = i->get_alias();
if (a) {
a->get_value().force_null();
cs_aliasInternal::clean_code(a);
cs_alias_internal::clean_code(a);
}
p_state->destroy(i);
}
@ -468,7 +468,7 @@ OSTD_EXPORT void cs_state::clear_override(cs_ident &id) {
switch (id.get_type()) {
case cs_ident_type::Alias: {
cs_alias &a = static_cast<cs_alias &>(id);
cs_aliasInternal::clean_code(&a);
cs_alias_internal::clean_code(&a);
a.get_value().set_str("");
break;
}
@ -624,9 +624,9 @@ OSTD_EXPORT void cs_state::set_alias(ostd::string_range name, cs_value v) {
case cs_ident_type::Alias: {
cs_alias *a = static_cast<cs_alias *>(id);
if (a->get_index() < MaxArguments) {
cs_aliasInternal::set_arg(a, *this, v);
cs_alias_internal::set_arg(a, *this, v);
} else {
cs_aliasInternal::set_alias(a, *this, v);
cs_alias_internal::set_alias(a, *this, v);
}
return;
}
@ -1103,8 +1103,8 @@ void cs_init_lib_base(cs_state &gcs) {
rc = false;
}
ret.set_int(rc);
cs_aliasInternal::set_alias(cret, cs, result);
cs_aliasInternal::set_alias(css, cs, tback);
cs_alias_internal::set_alias(cret, cs, result);
cs_alias_internal::set_alias(css, cs, tback);
});
gcs.new_command("?", "tTT", [](auto &, auto args, auto &res) {


+ 7
- 7
src/lib_list.cc View File

@ -6,24 +6,24 @@
namespace cscript {
template<typename T>
struct CsArgVal;
struct cs_arg_val;
template<>
struct CsArgVal<cs_int> {
struct cs_arg_val<cs_int> {
static cs_int get(cs_value &tv) {
return tv.get_int();
}
};
template<>
struct CsArgVal<cs_float> {
struct cs_arg_val<cs_float> {
static cs_float get(cs_value &tv) {
return tv.get_float();
}
};
template<>
struct CsArgVal<ostd::string_range> {
struct cs_arg_val<ostd::string_range> {
static ostd::string_range get(cs_value &tv) {
return tv.get_strr();
}
@ -34,7 +34,7 @@ static inline void cs_list_find(
cs_state &cs, cs_value_r args, cs_value &res, F cmp
) {
cs_int n = 0, skip = args[2].get_int();
T val = CsArgVal<T>::get(args[1]);
T val = cs_arg_val<T>::get(args[1]);
for (util::list_parser p(cs, args[0].get_strr()); p.parse(); ++n) {
if (cmp(p, val)) {
res.set_int(n);
@ -55,7 +55,7 @@ template<typename T, typename F>
static inline void cs_list_assoc(
cs_state &cs, cs_value_r args, cs_value &res, F cmp
) {
T val = CsArgVal<T>::get(args[1]);
T val = cs_arg_val<T>::get(args[1]);
for (util::list_parser p(cs, args[0].get_strr()); p.parse();) {
if (cmp(p, val)) {
if (p.parse()) {
@ -541,7 +541,7 @@ static void cs_list_sort(
cs_alias *xa = static_cast<cs_alias *>(x), *ya = static_cast<cs_alias *>(y);
CsVector<ListSortItem> items;
cs_vector<ListSortItem> items;
size_t total = 0;
for (util::list_parser p(cs, list); p.parse();) {


+ 24
- 24
src/lib_math.cc View File

@ -12,10 +12,10 @@ static constexpr cs_float PI = 3.14159265358979f;
static constexpr cs_float RAD = PI / 180.0f;
template<typename T>
struct CsMathVal;
struct cs_math_val;
template<>
struct CsMathVal<cs_int> {
struct cs_math_val<cs_int> {
static cs_int get(cs_value &tv) {
return tv.get_int();
}
@ -25,7 +25,7 @@ struct CsMathVal<cs_int> {
};
template<>
struct CsMathVal<cs_float> {
struct cs_math_val<cs_float> {
static cs_float get(cs_value &tv) {
return tv.get_float();
}
@ -35,7 +35,7 @@ struct CsMathVal<cs_float> {
};
template<typename T>
struct CsMathNoop {
struct cs_math_noop {
T operator()(T arg) {
return arg;
}
@ -48,26 +48,26 @@ static inline void cs_mathop(
) {
T val;
if (args.size() >= 2) {
val = binop(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
val = binop(cs_math_val<T>::get(args[0]), cs_math_val<T>::get(args[1]));
for (size_t i = 2; i < args.size(); ++i) {
val = binop(val, CsMathVal<T>::get(args[i]));
val = binop(val, cs_math_val<T>::get(args[i]));
}
} else {
val = unop(!args.empty() ? CsMathVal<T>::get(args[0]) : initval);
val = unop(!args.empty() ? cs_math_val<T>::get(args[0]) : initval);
}
CsMathVal<T>::set(res, val);
cs_math_val<T>::set(res, val);
}
template<typename T, typename F>
static inline void cs_cmpop(cs_value_r args, cs_value &res, F cmp) {
bool val;
if (args.size() >= 2) {
val = cmp(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
val = cmp(cs_math_val<T>::get(args[0]), cs_math_val<T>::get(args[1]));
for (size_t i = 2; (i < args.size()) && val; ++i) {
val = cmp(CsMathVal<T>::get(args[i - 1]), CsMathVal<T>::get(args[i]));
val = cmp(cs_math_val<T>::get(args[i - 1]), cs_math_val<T>::get(args[i]));
}
} else {
val = cmp(!args.empty() ? CsMathVal<T>::get(args[0]) : T(0), T(0));
val = cmp(!args.empty() ? cs_math_val<T>::get(args[0]) : T(0), T(0));
}
res.set_int(cs_int(val));
}
@ -169,11 +169,11 @@ void cs_init_lib_math(cs_state &cs) {
});
cs.new_command("+", "i1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_int>(args, res, 0, std::plus<cs_int>(), CsMathNoop<cs_int>());
cs_mathop<cs_int>(args, res, 0, std::plus<cs_int>(), cs_math_noop<cs_int>());
});
cs.new_command("*", "i1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_int>(
args, res, 1, std::multiplies<cs_int>(), CsMathNoop<cs_int>()
args, res, 1, std::multiplies<cs_int>(), cs_math_noop<cs_int>()
);
});
cs.new_command("-", "i1V", [](auto &, auto args, auto &res) {
@ -194,12 +194,12 @@ void cs_init_lib_math(cs_state &cs) {
});
cs.new_command("&", "i1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_int>(
args, res, 0, std::bit_and<cs_int>(), CsMathNoop<cs_int>()
args, res, 0, std::bit_and<cs_int>(), cs_math_noop<cs_int>()
);
});
cs.new_command("|", "i1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_int>(
args, res, 0, std::bit_or<cs_int>(), CsMathNoop<cs_int>()
args, res, 0, std::bit_or<cs_int>(), cs_math_noop<cs_int>()
);
});
@ -247,7 +247,7 @@ void cs_init_lib_math(cs_state &cs) {
return (val2 < cs_int(sizeof(cs_int) * CHAR_BIT))
? (val1 << std::max(val2, cs_int(0)))
: 0;
}, CsMathNoop<cs_int>()
}, cs_math_noop<cs_int>()
);
});
cs.new_command(">>", "i1V", [](auto &, auto args, auto &res) {
@ -256,18 +256,18 @@ void cs_init_lib_math(cs_state &cs) {
return val1 >> std::clamp(
val2, cs_int(0), cs_int(sizeof(cs_int) * CHAR_BIT)
);
}, CsMathNoop<cs_int>()
}, cs_math_noop<cs_int>()
);
});
cs.new_command("+f", "f1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_float>(
args, res, 0, std::plus<cs_float>(), CsMathNoop<cs_float>()
args, res, 0, std::plus<cs_float>(), cs_math_noop<cs_float>()
);
});
cs.new_command("*f", "f1V", [](auto &, auto args, auto &res) {
cs_mathop<cs_float>(
args, res, 1, std::multiplies<cs_float>(), CsMathNoop<cs_float>()
args, res, 1, std::multiplies<cs_float>(), cs_math_noop<cs_float>()
);
});
cs.new_command("-f", "f1V", [](auto &, auto args, auto &res) {
@ -283,7 +283,7 @@ void cs_init_lib_math(cs_state &cs) {
return val1 / val2;
}
return cs_int(0);
}, CsMathNoop<cs_int>()
}, cs_math_noop<cs_int>()
);
});
cs.new_command("mod", "i1V", [](auto &, auto args, auto &res) {
@ -293,7 +293,7 @@ void cs_init_lib_math(cs_state &cs) {
return val1 % val2;
}
return cs_int(0);
}, CsMathNoop<cs_int>()
}, cs_math_noop<cs_int>()
);
});
cs.new_command("divf", "f1V", [](auto &, auto args, auto &res) {
@ -303,7 +303,7 @@ void cs_init_lib_math(cs_state &cs) {
return val1 / val2;
}
return cs_float(0);
}, CsMathNoop<cs_float>()
}, cs_math_noop<cs_float>()
);
});
cs.new_command("modf", "f1V", [](auto &, auto args, auto &res) {
@ -313,7 +313,7 @@ void cs_init_lib_math(cs_state &cs) {
return cs_float(fmod(val1, val2));
}
return cs_float(0);
}, CsMathNoop<cs_float>()
}, cs_math_noop<cs_float>()
);
});
@ -321,7 +321,7 @@ void cs_init_lib_math(cs_state &cs) {
cs_mathop<cs_float>(
args, res, 0, [](cs_float val1, cs_float val2) {
return cs_float(pow(val1, val2));
}, CsMathNoop<cs_float>()
}, cs_math_noop<cs_float>()
);
});


Loading…
Cancel
Save