use size_t

master
Daniel Kolesa 2017-01-25 02:09:50 +01:00
parent d14c8f8593
commit 1c5c0939e1
9 changed files with 89 additions and 89 deletions

View File

@ -111,7 +111,7 @@ struct OSTD_EXPORT CsValue {
private: private:
ostd::AlignedUnion<1, CsInt, CsFloat, void *> p_stor; ostd::AlignedUnion<1, CsInt, CsFloat, void *> p_stor;
ostd::Size p_len; size_t p_len;
CsValueType p_type; CsValueType p_type;
}; };
@ -338,13 +338,13 @@ enum {
}; };
using CsHookCb = ostd::Function<void(CsState &)>; using CsHookCb = ostd::Function<void(CsState &)>;
using CsAllocCb = void *(*)(void *, void *, ostd::Size, ostd::Size); using CsAllocCb = void *(*)(void *, void *, size_t, size_t);
enum class CsLoopState { enum class CsLoopState {
Normal = 0, Break, Continue Normal = 0, Break, Continue
}; };
static inline void *cs_default_alloc(void *, void *p, ostd::Size, ostd::Size ns) { static inline void *cs_default_alloc(void *, void *p, size_t, size_t ns) {
if (!ns) { if (!ns) {
delete[] static_cast<unsigned char *>(p); delete[] static_cast<unsigned char *>(p);
return nullptr; return nullptr;
@ -519,7 +519,7 @@ struct OSTD_EXPORT CsState {
private: private:
CsIdent *add_ident(CsIdent *id); CsIdent *add_ident(CsIdent *id);
void *alloc(void *ptr, ostd::Size olds, ostd::Size news); void *alloc(void *ptr, size_t olds, size_t news);
template<typename T> template<typename T>
struct CsAllocator { struct CsAllocator {
@ -538,10 +538,10 @@ private:
template<typename TT> template<typename TT>
CsAllocator(CsAllocator<TT> const &a) noexcept: p_state(a.p_state) {} CsAllocator(CsAllocator<TT> const &a) noexcept: p_state(a.p_state) {}
T *allocate(ostd::Size n) { T *allocate(size_t n) {
return static_cast<T *>(p_state.alloc(nullptr, 0, n * sizeof(T))); return static_cast<T *>(p_state.alloc(nullptr, 0, n * sizeof(T)));
} }
void deallocate(T *p, ostd::Size n) noexcept { void deallocate(T *p, size_t n) noexcept {
p_state.alloc(p, n * sizeof(T), 0); p_state.alloc(p, n * sizeof(T), 0);
} }
@ -626,7 +626,7 @@ struct CsErrorException {
auto ret = ostd::format( auto ret = ostd::format(
ostd::CharRange(fbuf, sizeof(fbuf)), msg, std::forward<A>(args)... ostd::CharRange(fbuf, sizeof(fbuf)), msg, std::forward<A>(args)...
); );
if ((ret < 0) || (ostd::Size(ret) > sizeof(fbuf))) { if ((ret < 0) || (size_t(ret) > sizeof(fbuf))) {
p_errmsg = save_msg(cs, msg); p_errmsg = save_msg(cs, msg);
} else { } else {
p_errmsg = save_msg(cs, ostd::CharRange(fbuf, ret)); p_errmsg = save_msg(cs, ostd::CharRange(fbuf, ret));
@ -670,8 +670,8 @@ private:
namespace util { namespace util {
template<typename R> template<typename R>
inline ostd::Size escape_string(R &&writer, ostd::ConstCharRange str) { inline size_t escape_string(R &&writer, ostd::ConstCharRange str) {
ostd::Size ret = 2; size_t ret = 2;
writer.put('"'); writer.put('"');
for (; !str.empty(); str.pop_front()) { for (; !str.empty(); str.pop_front()) {
switch (str.front()) { switch (str.front()) {
@ -700,8 +700,8 @@ namespace util {
} }
template<typename R> template<typename R>
inline ostd::Size unescape_string(R &&writer, ostd::ConstCharRange str) { inline size_t unescape_string(R &&writer, ostd::ConstCharRange str) {
ostd::Size ret = 0; size_t ret = 0;
for (; !str.empty(); str.pop_front()) { for (; !str.empty(); str.pop_front()) {
if (str.front() == '^') { if (str.front() == '^') {
str.pop_front(); str.pop_front();
@ -749,13 +749,13 @@ namespace util {
} }
OSTD_EXPORT ostd::ConstCharRange parse_string( OSTD_EXPORT ostd::ConstCharRange parse_string(
CsState &cs, ostd::ConstCharRange str, ostd::Size &nlines CsState &cs, ostd::ConstCharRange str, size_t &nlines
); );
inline ostd::ConstCharRange parse_string( inline ostd::ConstCharRange parse_string(
CsState &cs, ostd::ConstCharRange str CsState &cs, ostd::ConstCharRange str
) { ) {
ostd::Size nlines; size_t nlines;
return parse_string(cs, str, nlines); return parse_string(cs, str, nlines);
} }
@ -771,10 +771,10 @@ namespace util {
void skip(); void skip();
bool parse(); bool parse();
ostd::Size count(); size_t count();
template<typename R> template<typename R>
ostd::Size get_item(R &&writer) const { size_t get_item(R &&writer) const {
if (!p_quote.empty() && (*p_quote == '"')) { if (!p_quote.empty() && (*p_quote == '"')) {
return unescape_string(std::forward<R>(writer), p_item); return unescape_string(std::forward<R>(writer), p_item);
} else { } else {
@ -821,12 +821,12 @@ private:
} }
template<typename R> template<typename R>
inline ostd::Size tvals_concat( inline size_t tvals_concat(
R &&writer, CsValueRange vals, R &&writer, CsValueRange vals,
ostd::ConstCharRange sep = ostd::ConstCharRange() ostd::ConstCharRange sep = ostd::ConstCharRange()
) { ) {
ostd::Size ret = 0; size_t ret = 0;
for (ostd::Size i = 0; i < vals.size(); ++i) { for (size_t i = 0; i < vals.size(); ++i) {
auto s = ostd::appender<CsString>(); auto s = ostd::appender<CsString>();
switch (vals[i].get_type()) { switch (vals[i].get_type()) {
case CsValueType::Int: { case CsValueType::Int: {
@ -834,7 +834,7 @@ private:
std::forward<R>(writer), vals[i].get_int() std::forward<R>(writer), vals[i].get_int()
); );
if (r > 0) { if (r > 0) {
ret += ostd::Size(r); ret += size_t(r);
} }
break; break;
} }
@ -843,7 +843,7 @@ private:
std::forward<R>(writer), vals[i].get_float() std::forward<R>(writer), vals[i].get_float()
); );
if (r > 0) { if (r > 0) {
ret += ostd::Size(r); ret += size_t(r);
} }
break; break;
} }
@ -866,8 +866,8 @@ private:
} }
template<typename R> template<typename R>
inline ostd::Size print_stack(R &&writer, CsStackState const &st) { inline size_t print_stack(R &&writer, CsStackState const &st) {
ostd::Size ret = 0; size_t ret = 0;
auto nd = st.get(); auto nd = st.get();
while (nd) { while (nd) {
auto rt = ostd::format( auto rt = ostd::format(
@ -877,7 +877,7 @@ private:
nd->index, nd->id->get_name() nd->index, nd->id->get_name()
); );
if (rt > 0) { if (rt > 0) {
ret += ostd::Size(rt); ret += size_t(rt);
} else { } else {
return ret; return ret;
} }

View File

@ -10,7 +10,7 @@
namespace cscript { namespace cscript {
ostd::ConstCharRange GenState::get_str() { ostd::ConstCharRange GenState::get_str() {
ostd::Size nl; size_t nl;
ostd::ConstCharRange beg = source; ostd::ConstCharRange beg = source;
source = util::parse_string(cs, source, nl); source = util::parse_string(cs, source, nl);
current_line += nl - 1; current_line += nl - 1;
@ -109,8 +109,8 @@ static inline int cs_ret_code(int type, int def = 0) {
static void compilestatements( static void compilestatements(
GenState &gs, int rettype, int brak = '\0', int prevargs = 0 GenState &gs, int rettype, int brak = '\0', int prevargs = 0
); );
static inline ostd::Pair<ostd::ConstCharRange, ostd::Size> compileblock( static inline ostd::Pair<ostd::ConstCharRange, size_t> compileblock(
GenState &gs, ostd::ConstCharRange p, ostd::Size line, GenState &gs, ostd::ConstCharRange p, size_t line,
int rettype = CsRetNull, int brak = '\0' int rettype = CsRetNull, int brak = '\0'
); );
@ -172,16 +172,16 @@ static inline void compileblock(GenState &gs) {
gs.code.push_back(CsCodeEmpty); gs.code.push_back(CsCodeEmpty);
} }
static inline ostd::Pair<ostd::ConstCharRange, ostd::Size> compileblock( static inline ostd::Pair<ostd::ConstCharRange, size_t> compileblock(
GenState &gs, ostd::ConstCharRange p, ostd::Size line, int rettype, int brak GenState &gs, ostd::ConstCharRange p, size_t line, int rettype, int brak
) { ) {
ostd::Size start = gs.code.size(); size_t start = gs.code.size();
gs.code.push_back(CsCodeBlock); gs.code.push_back(CsCodeBlock);
gs.code.push_back(CsCodeOffset | ((start + 2) << 8)); gs.code.push_back(CsCodeOffset | ((start + 2) << 8));
ostd::Size retline = line; size_t retline = line;
if (p) { if (p) {
ostd::ConstCharRange op = gs.source; ostd::ConstCharRange op = gs.source;
ostd::Size oldline = gs.current_line; size_t oldline = gs.current_line;
gs.source = p; gs.source = p;
gs.current_line = line; gs.current_line = line;
compilestatements(gs, CsValAny, brak); compilestatements(gs, CsValAny, brak);
@ -209,7 +209,7 @@ static inline void compileunescapestr(GenState &gs, bool macro = false) {
size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(ostd::Uint32); size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(ostd::Uint32);
char *buf = new char[bufs + 1]; char *buf = new char[bufs + 1];
auto writer = ostd::CharRange(buf, bufs); auto writer = ostd::CharRange(buf, bufs);
ostd::Size len = util::unescape_string(writer, str); size_t len = util::unescape_string(writer, str);
memset(&buf[len], 0, sizeof(ostd::Uint32) - len % sizeof(ostd::Uint32)); memset(&buf[len], 0, sizeof(ostd::Uint32) - len % sizeof(ostd::Uint32));
gs.code.back() |= len << 8; gs.code.back() |= len << 8;
uint32_t *ubuf = reinterpret_cast<uint32_t *>(buf); uint32_t *ubuf = reinterpret_cast<uint32_t *>(buf);
@ -587,7 +587,7 @@ done:
static void compileblockmain(GenState &gs, int wordtype, int prevargs) { static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
char const *start = gs.source.data(); char const *start = gs.source.data();
ostd::Size curline = gs.current_line; size_t curline = gs.current_line;
int concs = 0; int concs = 0;
for (int brak = 1; brak;) { for (int brak = 1; brak;) {
switch (gs.skip_until("@\"/[]")) { switch (gs.skip_until("@\"/[]")) {
@ -763,7 +763,7 @@ static bool compilearg(
gs.get_str(); gs.get_str();
break; break;
case CsValCond: { case CsValCond: {
ostd::Size line = gs.current_line; size_t line = gs.current_line;
auto s = gs.get_str_dup(); auto s = gs.get_str_dup();
if (!s.empty()) { if (!s.empty()) {
compileblock(gs, s, line); compileblock(gs, s, line);
@ -791,7 +791,7 @@ static bool compilearg(
compileunescapestr(gs, true); compileunescapestr(gs, true);
break; break;
default: { default: {
ostd::Size line = gs.current_line; size_t line = gs.current_line;
auto s = gs.get_str_dup(); auto s = gs.get_str_dup();
gs.gen_value(wordtype, s, line); gs.gen_value(wordtype, s, line);
break; break;
@ -810,7 +810,7 @@ static bool compilearg(
); );
gs.code.push_back(CsCodeExit | cs_ret_code(wordtype)); gs.code.push_back(CsCodeExit | cs_ret_code(wordtype));
} else { } else {
ostd::Size start = gs.code.size(); size_t start = gs.code.size();
compilestatements( compilestatements(
gs, wordtype > CsValAny ? CsValCany : CsValAny, ')', prevargs gs, wordtype > CsValAny ? CsValCany : CsValAny, ')', prevargs
); );
@ -846,7 +846,7 @@ static bool compilearg(
return !gs.get_word().empty(); return !gs.get_word().empty();
} }
case CsValCond: { case CsValCond: {
ostd::Size line = gs.current_line; size_t line = gs.current_line;
auto s = gs.get_word(); auto s = gs.get_word();
if (s.empty()) { if (s.empty()) {
return false; return false;
@ -855,7 +855,7 @@ static bool compilearg(
return true; return true;
} }
case CsValCode: { case CsValCode: {
ostd::Size line = gs.current_line; size_t line = gs.current_line;
auto s = gs.get_word(); auto s = gs.get_word();
if (s.empty()) { if (s.empty()) {
return false; return false;
@ -871,7 +871,7 @@ static bool compilearg(
return !w.empty(); return !w.empty();
} }
default: { default: {
ostd::Size line = gs.current_line; size_t line = gs.current_line;
auto s = gs.get_word(); auto s = gs.get_word();
if (s.empty()) { if (s.empty()) {
return false; return false;
@ -1256,7 +1256,7 @@ static void compilestatements(GenState &gs, int rettype, int brak, int prevargs)
for (;;) { for (;;) {
gs.skip_comments(); gs.skip_comments();
idname.clear(); idname.clear();
ostd::Size curline = gs.current_line; size_t curline = gs.current_line;
bool more = compilearg(gs, CsValWord, prevargs, &idname); bool more = compilearg(gs, CsValWord, prevargs, &idname);
if (!more) { if (!more) {
goto endstatement; goto endstatement;

View File

@ -185,9 +185,9 @@ done:
namespace util { namespace util {
OSTD_EXPORT ostd::ConstCharRange parse_string( OSTD_EXPORT ostd::ConstCharRange parse_string(
CsState &cs, ostd::ConstCharRange str, ostd::Size &nlines CsState &cs, ostd::ConstCharRange str, size_t &nlines
) { ) {
ostd::Size nl = 0; size_t nl = 0;
nlines = nl; nlines = nl;
if (str.empty() || (*str != '\"')) { if (str.empty() || (*str != '\"')) {
return str; return str;
@ -370,8 +370,8 @@ endblock:
return true; return true;
} }
ostd::Size ListParser::count() { size_t ListParser::count() {
ostd::Size ret = 0; size_t ret = 0;
while (parse()) { while (parse()) {
++ret; ++ret;
} }

View File

@ -47,7 +47,7 @@ CsStackState::CsStackState(CsStackState &&st):
} }
CsStackState::~CsStackState() { CsStackState::~CsStackState() {
ostd::Size len = 0; size_t len = 0;
for (CsStackStateNode const *nd = p_node; nd; nd = nd->next) { for (CsStackStateNode const *nd = p_node; nd; nd = nd->next) {
++len; ++len;
} }
@ -1525,7 +1525,7 @@ noid:
continue; continue;
case CsIdLocal: { case CsIdLocal: {
CsIdentStack locals[MaxArguments]; CsIdentStack locals[MaxArguments];
for (ostd::Size j = 0; j < ostd::Size(callargs); ++j) { for (size_t j = 0; j < size_t(callargs); ++j) {
cs_push_alias(cs.force_ident( cs_push_alias(cs.force_ident(
args[offset + j] args[offset + j]
), locals[j]); ), locals[j]);
@ -1533,7 +1533,7 @@ noid:
cs_do_and_cleanup([&]() { cs_do_and_cleanup([&]() {
code = runcode(cs, code, result); code = runcode(cs, code, result);
}, [&]() { }, [&]() {
for (ostd::Size j = 0; j < ostd::Size(callargs); ++j) { for (size_t j = 0; j < size_t(callargs); ++j) {
cs_pop_alias(args[offset + j].get_ident()); cs_pop_alias(args[offset + j].get_ident());
} }
}); });
@ -1810,7 +1810,7 @@ static bool cs_run_file(
CsState &cs, ostd::ConstCharRange fname, CsValue &ret CsState &cs, ostd::ConstCharRange fname, CsValue &ret
) { ) {
ostd::Box<char[]> buf; ostd::Box<char[]> buf;
ostd::Size len; size_t len;
ostd::FileStream f(fname, ostd::StreamMode::read); ostd::FileStream f(fname, ostd::StreamMode::read);
if (!f.is_open()) { if (!f.is_open()) {

View File

@ -100,7 +100,7 @@ struct CsSharedState {
CsAllocCb allocf; CsAllocCb allocf;
void *aptr; void *aptr;
void *alloc(void *ptr, ostd::Size os, ostd::Size ns) { void *alloc(void *ptr, size_t os, size_t ns) {
return allocf(aptr, ptr, os, ns); return allocf(aptr, ptr, os, ns);
} }
@ -112,9 +112,9 @@ struct CsSharedState {
} }
template<typename T> template<typename T>
T *create_array(ostd::Size len) { T *create_array(size_t len) {
T *ret = static_cast<T *>(alloc(nullptr, 0, len * sizeof(T))); T *ret = static_cast<T *>(alloc(nullptr, 0, len * sizeof(T)));
for (ostd::Size i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
new (&ret[i]) T(); new (&ret[i]) T();
} }
return ret; return ret;
@ -127,7 +127,7 @@ struct CsSharedState {
} }
template<typename T> template<typename T>
void destroy_array(T *v, ostd::Size len) noexcept { void destroy_array(T *v, size_t len) noexcept {
v->~T(); v->~T();
alloc(v, len * sizeof(T), 0); alloc(v, len * sizeof(T), 0);
} }
@ -140,7 +140,7 @@ struct CsContinueException {
}; };
template<typename T> template<typename T>
constexpr ostd::Size CsTypeStorageSize = constexpr size_t CsTypeStorageSize =
(sizeof(T) - 1) / sizeof(ostd::Uint32) + 1; (sizeof(T) - 1) / sizeof(ostd::Uint32) + 1;
struct GenState { struct GenState {
@ -149,7 +149,7 @@ struct GenState {
bool parsing = true; bool parsing = true;
CsVector<ostd::Uint32> code; CsVector<ostd::Uint32> code;
ostd::ConstCharRange source; ostd::ConstCharRange source;
ostd::Size current_line; size_t current_line;
ostd::ConstCharRange src_name; ostd::ConstCharRange src_name;
GenState() = delete; GenState() = delete;
@ -180,7 +180,7 @@ struct GenState {
void gen_str(ostd::ConstCharRange word, bool macro = false) { void gen_str(ostd::ConstCharRange word, bool macro = false) {
if (word.size() <= 3 && !macro) { if (word.size() <= 3 && !macro) {
ostd::Uint32 op = CsCodeValInt | CsRetString; ostd::Uint32 op = CsCodeValInt | CsRetString;
for (ostd::Size i = 0; i < word.size(); ++i) { for (size_t i = 0; i < word.size(); ++i) {
op |= ostd::Uint32(ostd::byte(word[i])) << ((i + 1) * 8); op |= ostd::Uint32(ostd::byte(word[i])) << ((i + 1) * 8);
} }
code.push_back(op); code.push_back(op);
@ -193,7 +193,7 @@ struct GenState {
code.insert( code.insert(
code.end(), it, it + (word.size() / sizeof(ostd::Uint32)) code.end(), it, it + (word.size() / sizeof(ostd::Uint32))
); );
ostd::Size esz = word.size() % sizeof(ostd::Uint32); size_t esz = word.size() % sizeof(ostd::Uint32);
union { union {
char c[sizeof(ostd::Uint32)]; char c[sizeof(ostd::Uint32)];
ostd::Uint32 u; ostd::Uint32 u;
@ -277,7 +277,7 @@ struct GenState {
source.pop_front(); source.pop_front();
} }
char current(ostd::Size ahead = 0) { char current(size_t ahead = 0) {
if (source.size() <= ahead) { if (source.size() <= ahead) {
return '\0'; return '\0';
} }

View File

@ -341,7 +341,7 @@ CsState::CsState(CsAllocCb func, void *data):
if (args.empty()) { if (args.empty()) {
res.set_int(1); res.set_int(1);
} else { } else {
for (ostd::Size i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
CsBytecode *code = args[i].get_code(); CsBytecode *code = args[i].get_code();
if (code) { if (code) {
cs.run(code, res); cs.run(code, res);
@ -359,7 +359,7 @@ CsState::CsState(CsAllocCb func, void *data):
if (args.empty()) { if (args.empty()) {
res.set_int(0); res.set_int(0);
} else { } else {
for (ostd::Size i = 0; i < args.size(); ++i) { for (size_t i = 0; i < args.size(); ++i) {
CsBytecode *code = args[i].get_code(); CsBytecode *code = args[i].get_code();
if (code) { if (code) {
cs.run(code, res); cs.run(code, res);
@ -424,7 +424,7 @@ CsHookCb &CsState::get_call_hook() {
return p_callhook; return p_callhook;
} }
void *CsState::alloc(void *ptr, ostd::Size os, ostd::Size ns) { void *CsState::alloc(void *ptr, size_t os, size_t ns) {
return p_state->alloc(ptr, os, ns); return p_state->alloc(ptr, os, ns);
} }
@ -1073,7 +1073,7 @@ void cs_init_lib_base(CsState &gcs) {
}); });
gcs.new_command("cond", "ee2V", [](auto &cs, auto args, auto &res) { gcs.new_command("cond", "ee2V", [](auto &cs, auto args, auto &res) {
for (ostd::Size i = 0; i < args.size(); i += 2) { for (size_t i = 0; i < args.size(); i += 2) {
if ((i + 1) < args.size()) { if ((i + 1) < args.size()) {
if (cs.run_bool(args[i].get_code())) { if (cs.run_bool(args[i].get_code())) {
cs.run(args[i + 1].get_code(), res); cs.run(args[i + 1].get_code(), res);
@ -1088,7 +1088,7 @@ void cs_init_lib_base(CsState &gcs) {
gcs.new_command("case", "ite2V", [](auto &cs, auto args, auto &res) { gcs.new_command("case", "ite2V", [](auto &cs, auto args, auto &res) {
CsInt val = args[0].get_int(); CsInt val = args[0].get_int();
for (ostd::Size i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == CsValueType::Null) || (args[i].get_type() == CsValueType::Null) ||
(args[i].get_int() == val) (args[i].get_int() == val)
@ -1101,7 +1101,7 @@ void cs_init_lib_base(CsState &gcs) {
gcs.new_command("casef", "fte2V", [](auto &cs, auto args, auto &res) { gcs.new_command("casef", "fte2V", [](auto &cs, auto args, auto &res) {
CsFloat val = args[0].get_float(); CsFloat val = args[0].get_float();
for (ostd::Size i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == CsValueType::Null) || (args[i].get_type() == CsValueType::Null) ||
(args[i].get_float() == val) (args[i].get_float() == val)
@ -1114,7 +1114,7 @@ void cs_init_lib_base(CsState &gcs) {
gcs.new_command("cases", "ste2V", [](auto &cs, auto args, auto &res) { gcs.new_command("cases", "ste2V", [](auto &cs, auto args, auto &res) {
CsString val = args[0].get_str(); CsString val = args[0].get_str();
for (ostd::Size i = 1; (i + 1) < args.size(); i += 2) { for (size_t i = 1; (i + 1) < args.size(); i += 2) {
if ( if (
(args[i].get_type() == CsValueType::Null) || (args[i].get_type() == CsValueType::Null) ||
(args[i].get_str() == val) (args[i].get_str() == val)

View File

@ -149,7 +149,7 @@ void cs_init_lib_list(CsState &gcs) {
CsString str = std::move(args[0].get_str()); CsString str = std::move(args[0].get_str());
util::ListParser p(cs, str); util::ListParser p(cs, str);
p.get_raw_item() = str; p.get_raw_item() = str;
for (ostd::Size i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
p.get_input() = str; p.get_input() = str;
CsInt pos = args[i].get_int(); CsInt pos = args[i].get_int();
for (; pos > 0; --pos) { for (; pos > 0; --pos) {
@ -422,8 +422,8 @@ end:
auto buf = ostd::appender<CsString>(); auto buf = ostd::appender<CsString>();
ostd::ConstCharRange s = args[0].get_strr(); ostd::ConstCharRange s = args[0].get_strr();
ostd::ConstCharRange conj = args[1].get_strr(); ostd::ConstCharRange conj = args[1].get_strr();
ostd::Size len = util::ListParser(cs, s).count(); size_t len = util::ListParser(cs, s).count();
ostd::Size n = 0; size_t n = 0;
for (util::ListParser p(cs, s); p.parse(); ++n) { for (util::ListParser p(cs, s); p.parse(); ++n) {
if (!p.get_raw_item(true).empty() && if (!p.get_raw_item(true).empty() &&
(p.get_raw_item(true).front() == '"')) { (p.get_raw_item(true).front() == '"')) {
@ -540,7 +540,7 @@ static void cs_list_sort(
CsAlias *xa = static_cast<CsAlias *>(x), *ya = static_cast<CsAlias *>(y); CsAlias *xa = static_cast<CsAlias *>(x), *ya = static_cast<CsAlias *>(y);
CsVector<ListSortItem> items; CsVector<ListSortItem> items;
ostd::Size total = 0; size_t total = 0;
for (util::ListParser p(cs, list); p.parse();) { for (util::ListParser p(cs, list); p.parse();) {
ListSortItem item = { p.get_raw_item(), p.get_raw_item(true) }; ListSortItem item = { p.get_raw_item(), p.get_raw_item(true) };
@ -559,8 +559,8 @@ static void cs_list_sort(
xval.push(); xval.push();
yval.push(); yval.push();
ostd::Size totaluniq = total; size_t totaluniq = total;
ostd::Size nuniq = items.size(); size_t nuniq = items.size();
if (body) { if (body) {
ListSortFun f = { cs, xval, yval, body }; ListSortFun f = { cs, xval, yval, body };
ostd::sort_cmp(ostd::iter(items), f); ostd::sort_cmp(ostd::iter(items), f);
@ -568,7 +568,7 @@ static void cs_list_sort(
f.body = unique; f.body = unique;
totaluniq = items[0].quote.size(); totaluniq = items[0].quote.size();
nuniq = 1; nuniq = 1;
for (ostd::Size i = 1; i < items.size(); i++) { for (size_t i = 1; i < items.size(); i++) {
ListSortItem &item = items[i]; ListSortItem &item = items[i];
if (f(items[i - 1], item)) { if (f(items[i - 1], item)) {
item.quote = nullptr; item.quote = nullptr;
@ -582,9 +582,9 @@ static void cs_list_sort(
ListSortFun f = { cs, xval, yval, unique }; ListSortFun f = { cs, xval, yval, unique };
totaluniq = items[0].quote.size(); totaluniq = items[0].quote.size();
nuniq = 1; nuniq = 1;
for (ostd::Size i = 1; i < items.size(); i++) { for (size_t i = 1; i < items.size(); i++) {
ListSortItem &item = items[i]; ListSortItem &item = items[i];
for (ostd::Size j = 0; j < i; ++j) { for (size_t j = 0; j < i; ++j) {
ListSortItem &prev = items[j]; ListSortItem &prev = items[j];
if (!prev.quote.empty() && f(item, prev)) { if (!prev.quote.empty() && f(item, prev)) {
item.quote = nullptr; item.quote = nullptr;
@ -602,8 +602,8 @@ static void cs_list_sort(
yval.pop(); yval.pop();
CsString sorted; CsString sorted;
sorted.reserve(totaluniq + ostd::max(nuniq - 1, ostd::Size(0))); sorted.reserve(totaluniq + ostd::max(nuniq - 1, size_t(0)));
for (ostd::Size i = 0; i < items.size(); ++i) { for (size_t i = 0; i < items.size(); ++i) {
ListSortItem &item = items[i]; ListSortItem &item = items[i];
if (item.quote.empty()) { if (item.quote.empty()) {
continue; continue;

View File

@ -47,7 +47,7 @@ static inline void cs_mathop(
T val; T val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = binop(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1])); val = binop(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
for (ostd::Size i = 2; i < args.size(); ++i) { for (size_t i = 2; i < args.size(); ++i) {
val = binop(val, CsMathVal<T>::get(args[i])); val = binop(val, CsMathVal<T>::get(args[i]));
} }
} else { } else {
@ -61,7 +61,7 @@ static inline void cs_cmpop(CsValueRange args, CsValue &res, F cmp) {
bool val; bool val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = cmp(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1])); val = cmp(CsMathVal<T>::get(args[0]), CsMathVal<T>::get(args[1]));
for (ostd::Size i = 2; (i < args.size()) && val; ++i) { 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(CsMathVal<T>::get(args[i - 1]), CsMathVal<T>::get(args[i]));
} }
} else { } else {
@ -178,28 +178,28 @@ void cs_init_lib_math(CsState &cs) {
cs.new_command("min", "i1V", [](auto &, auto args, auto &res) { cs.new_command("min", "i1V", [](auto &, auto args, auto &res) {
CsInt v = (!args.empty() ? args[0].get_int() : 0); CsInt v = (!args.empty() ? args[0].get_int() : 0);
for (ostd::Size i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
v = ostd::min(v, args[i].get_int()); v = ostd::min(v, args[i].get_int());
} }
res.set_int(v); res.set_int(v);
}); });
cs.new_command("max", "i1V", [](auto &, auto args, auto &res) { cs.new_command("max", "i1V", [](auto &, auto args, auto &res) {
CsInt v = (!args.empty() ? args[0].get_int() : 0); CsInt v = (!args.empty() ? args[0].get_int() : 0);
for (ostd::Size i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
v = ostd::max(v, args[i].get_int()); v = ostd::max(v, args[i].get_int());
} }
res.set_int(v); res.set_int(v);
}); });
cs.new_command("minf", "f1V", [](auto &, auto args, auto &res) { cs.new_command("minf", "f1V", [](auto &, auto args, auto &res) {
CsFloat v = (!args.empty() ? args[0].get_float() : 0); CsFloat v = (!args.empty() ? args[0].get_float() : 0);
for (ostd::Size i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
v = ostd::min(v, args[i].get_float()); v = ostd::min(v, args[i].get_float());
} }
res.set_float(v); res.set_float(v);
}); });
cs.new_command("maxf", "f1V", [](auto &, auto args, auto &res) { cs.new_command("maxf", "f1V", [](auto &, auto args, auto &res) {
CsFloat v = (!args.empty() ? args[0].get_float() : 0); CsFloat v = (!args.empty() ? args[0].get_float() : 0);
for (ostd::Size i = 1; i < args.size(); ++i) { for (size_t i = 1; i < args.size(); ++i) {
v = ostd::max(v, args[i].get_float()); v = ostd::max(v, args[i].get_float());
} }
res.set_float(v); res.set_float(v);
@ -271,7 +271,7 @@ void cs_init_lib_math(CsState &cs) {
CsInt val; CsInt val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = args[0].get_int() ^ ~args[1].get_int(); val = args[0].get_int() ^ ~args[1].get_int();
for (ostd::Size i = 2; i < args.size(); ++i) { for (size_t i = 2; i < args.size(); ++i) {
val ^= ~args[i].get_int(); val ^= ~args[i].get_int();
} }
} else { } else {
@ -283,7 +283,7 @@ void cs_init_lib_math(CsState &cs) {
CsInt val; CsInt val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = args[0].get_int() & ~args[1].get_int(); val = args[0].get_int() & ~args[1].get_int();
for (ostd::Size i = 2; i < args.size(); ++i) { for (size_t i = 2; i < args.size(); ++i) {
val &= ~args[i].get_int(); val &= ~args[i].get_int();
} }
} else { } else {
@ -295,7 +295,7 @@ void cs_init_lib_math(CsState &cs) {
CsInt val; CsInt val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = args[0].get_int() | ~args[1].get_int(); val = args[0].get_int() | ~args[1].get_int();
for (ostd::Size i = 2; i < args.size(); ++i) { for (size_t i = 2; i < args.size(); ++i) {
val |= ~args[i].get_int(); val |= ~args[i].get_int();
} }
} else { } else {
@ -307,7 +307,7 @@ void cs_init_lib_math(CsState &cs) {
cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) { cs.new_command("<<", "i1V", [](auto &, auto args, auto &res) {
cs_mathop<CsInt>( cs_mathop<CsInt>(
args, res, 0, [](CsInt val1, CsInt val2) { args, res, 0, [](CsInt val1, CsInt val2) {
return (val2 < CsInt(ostd::SizeInBits<CsInt>)) return (val2 < CsInt(size_tInBits<CsInt>))
? (val1 << ostd::max(val2, CsInt(0))) ? (val1 << ostd::max(val2, CsInt(0)))
: 0; : 0;
}, CsMathNoop<CsInt>() }, CsMathNoop<CsInt>()
@ -317,7 +317,7 @@ void cs_init_lib_math(CsState &cs) {
cs_mathop<CsInt>( cs_mathop<CsInt>(
args, res, 0, [](CsInt val1, CsInt val2) { args, res, 0, [](CsInt val1, CsInt val2) {
return val1 >> ostd::clamp( return val1 >> ostd::clamp(
val2, CsInt(0), CsInt(ostd::SizeInBits<CsInt>) val2, CsInt(0), CsInt(size_tInBits<CsInt>)
); );
}, CsMathNoop<CsInt>() }, CsMathNoop<CsInt>()
); );

View File

@ -9,7 +9,7 @@ static inline void cs_strgcmp(CsValueRange args, CsValue &res, F cfunc) {
bool val; bool val;
if (args.size() >= 2) { if (args.size() >= 2) {
val = cfunc(args[0].get_strr(), args[1].get_strr()); val = cfunc(args[0].get_strr(), args[1].get_strr());
for (ostd::Size i = 2; (i < args.size()) && val; ++i) { for (size_t i = 2; (i < args.size()) && val; ++i) {
val = cfunc(args[i - 1].get_strr(), args[i].get_strr()); val = cfunc(args[i - 1].get_strr(), args[i].get_strr());
} }
} else { } else {
@ -108,7 +108,7 @@ void cs_init_lib_string(CsState &cs) {
++f; ++f;
if (ic >= '1' && ic <= '9') { if (ic >= '1' && ic <= '9') {
int i = ic - '0'; int i = ic - '0';
if (ostd::Size(i) < args.size()) { if (size_t(i) < args.size()) {
s += args[i].get_str(); s += args[i].get_str();
} }
} else { } else {
@ -178,7 +178,7 @@ void cs_init_lib_string(CsState &cs) {
res.set_str(s); res.set_str(s);
return; return;
} }
for (ostd::Size i = 0;; ++i) { for (size_t i = 0;; ++i) {
ostd::ConstCharRange found; ostd::ConstCharRange found;
ostd::ConstCharRange trys = s; ostd::ConstCharRange trys = s;
for (; oldval.size() <= trys.size(); ++trys) { for (; oldval.size() <= trys.size(); ++trys) {