From 8e31583612ab5602fcd51a81336aaa52cfdb2946 Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 25 Jan 2017 02:10:17 +0100 Subject: [PATCH] use uint32_t --- src/cs_gen.cc | 34 +++++++++++----------- src/cs_val.cc | 4 +-- src/cs_vm.cc | 80 +++++++++++++++++++++++++-------------------------- src/cs_vm.hh | 30 +++++++++---------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 0550f72..0e6099d 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -192,7 +192,7 @@ static inline ostd::Pair compileblock( } if (gs.code.size() > start + 2) { gs.code.push_back(CsCodeExit | rettype); - gs.code[start] |= ostd::Uint32(gs.code.size() - (start + 1)) << 8; + gs.code[start] |= uint32_t(gs.code.size() - (start + 1)) << 8; } else { gs.code.resize(start); gs.code.push_back(CsCodeEmpty | rettype); @@ -204,16 +204,16 @@ static inline void compileunescapestr(GenState &gs, bool macro = false) { auto str = gs.get_str(); gs.code.push_back(macro ? CsCodeMacro : (CsCodeVal | CsRetString)); gs.code.reserve( - gs.code.size() + str.size() / sizeof(ostd::Uint32) + 1 + gs.code.size() + str.size() / sizeof(uint32_t) + 1 ); - size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(ostd::Uint32); + size_t bufs = (gs.code.capacity() - gs.code.size()) * sizeof(uint32_t); char *buf = new char[bufs + 1]; auto writer = ostd::CharRange(buf, bufs); size_t len = util::unescape_string(writer, str); - memset(&buf[len], 0, sizeof(ostd::Uint32) - len % sizeof(ostd::Uint32)); + memset(&buf[len], 0, sizeof(uint32_t) - len % sizeof(uint32_t)); gs.code.back() |= len << 8; uint32_t *ubuf = reinterpret_cast(buf); - gs.code.insert(gs.code.end(), ubuf, ubuf + (len / sizeof(ostd::Uint32) + 1)); + gs.code.insert(gs.code.end(), ubuf, ubuf + (len / sizeof(uint32_t) + 1)); delete[] buf; } @@ -482,7 +482,7 @@ invalid: static bool compileblockstr(GenState &gs, ostd::ConstCharRange str, bool macro) { int startc = gs.code.size(); gs.code.push_back(macro ? CsCodeMacro : CsCodeVal | CsRetString); - gs.code.reserve(gs.code.size() + str.size() / sizeof(ostd::Uint32) + 1); + gs.code.reserve(gs.code.size() + str.size() / sizeof(uint32_t) + 1); char *buf = new char[(str.size() / sizeof(uint32_t) + 1) * sizeof(uint32_t)]; int len = 0; while (!str.empty()) { @@ -521,9 +521,9 @@ static bool compileblockstr(GenState &gs, ostd::ConstCharRange str, bool macro) } } done: - memset(&buf[len], '\0', sizeof(ostd::Uint32) - len % sizeof(ostd::Uint32)); + memset(&buf[len], '\0', sizeof(uint32_t) - len % sizeof(uint32_t)); uint32_t *ubuf = reinterpret_cast(buf); - gs.code.insert(gs.code.end(), ubuf, ubuf + (len / sizeof(ostd::Uint32) + 1)); + gs.code.insert(gs.code.end(), ubuf, ubuf + (len / sizeof(uint32_t) + 1)); gs.code[startc] |= len << 8; delete[] buf; return true; @@ -1145,9 +1145,9 @@ static void compile_if( } else { int start2 = gs.code.size(); more = compilearg(gs, CsValCode, prevargs + 2); - ostd::Uint32 inst1 = gs.code[start1]; - ostd::Uint32 op1 = inst1 & ~CsCodeRetMask; - ostd::Uint32 len1 = start2 - (start1 + 1); + uint32_t inst1 = gs.code[start1]; + uint32_t op1 = inst1 & ~CsCodeRetMask; + uint32_t len1 = start2 - (start1 + 1); if (!more) { if (op1 == (CsCodeBlock | (len1 << 8))) { gs.code[start1] = (len1 << 8) | CsCodeJumpB | CsCodeFlagFalse; @@ -1159,9 +1159,9 @@ static void compile_if( } compileblock(gs); } else { - ostd::Uint32 inst2 = gs.code[start2]; - ostd::Uint32 op2 = inst2 & ~CsCodeRetMask; - ostd::Uint32 len2 = gs.code.size() - (start2 + 1); + uint32_t inst2 = gs.code[start2]; + uint32_t op2 = inst2 & ~CsCodeRetMask; + uint32_t len2 = gs.code.size() - (start2 + 1); if (op2 == (CsCodeBlock | (len2 << 8))) { if (op1 == (CsCodeBlock | (len1 << 8))) { gs.code[start1] = ((start2 - start1) << 8) @@ -1214,7 +1214,7 @@ static void compile_and_or( } numargs++; if ((gs.code[end] & ~CsCodeRetMask) != ( - CsCodeBlock | (ostd::Uint32(gs.code.size() - (end + 1)) << 8) + CsCodeBlock | (uint32_t(gs.code.size() - (end + 1)) << 8) )) { break; } @@ -1233,13 +1233,13 @@ static void compile_and_or( (numargs << 8) | (id->get_index() << 13) ); } else { - ostd::Uint32 op = (id->get_type_raw() == CsIdAnd) + uint32_t op = (id->get_type_raw() == CsIdAnd) ? (CsCodeJumpResult | CsCodeFlagFalse) : (CsCodeJumpResult | CsCodeFlagTrue); gs.code.push_back(op); end = gs.code.size(); while ((start + 1) < end) { - ostd::Uint32 len = gs.code[start] >> 8; + uint32_t len = gs.code[start] >> 8; gs.code[start] = ((end - (start + 1)) << 8) | op; gs.code[start + 1] = CsCodeEnter; gs.code[start + len] = ( diff --git a/src/cs_val.cc b/src/cs_val.cc index dc365dd..bf442ad 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -17,7 +17,7 @@ static inline void csv_cleanup(CsValueType tv, T &stor) { delete[] csv_get(stor); break; case CsValueType::Code: { - ostd::Uint32 *bcode = csv_get(stor); + uint32_t *bcode = csv_get(stor); if (bcode[-1] == CsCodeStart) { delete[] &bcode[-1]; } @@ -319,7 +319,7 @@ OSTD_EXPORT bool cs_code_is_empty(CsBytecode *code) { return true; } return ( - *reinterpret_cast(code) & CsCodeOpMask + *reinterpret_cast(code) & CsCodeOpMask ) == CsCodeExit; } diff --git a/src/cs_vm.cc b/src/cs_vm.cc index 32ce743..005f7f6 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -131,7 +131,7 @@ ostd::ConstCharRange CsErrorException::save_msg( return ostd::ConstCharRange(cs.p_errbuf, msg.size()); } -static void bcode_ref(ostd::Uint32 *code) { +static void bcode_ref(uint32_t *code) { if (!code) { return; } @@ -150,7 +150,7 @@ static void bcode_ref(ostd::Uint32 *code) { } } -static void bcode_unref(ostd::Uint32 *code) { +static void bcode_unref(uint32_t *code) { if (!code) { return; } @@ -170,32 +170,32 @@ static void bcode_unref(ostd::Uint32 *code) { } CsBytecodeRef::CsBytecodeRef(CsBytecode *v): p_code(v) { - bcode_ref(reinterpret_cast(p_code)); + bcode_ref(reinterpret_cast(p_code)); } CsBytecodeRef::CsBytecodeRef(CsBytecodeRef const &v): p_code(v.p_code) { - bcode_ref(reinterpret_cast(p_code)); + bcode_ref(reinterpret_cast(p_code)); } CsBytecodeRef::~CsBytecodeRef() { - bcode_unref(reinterpret_cast(p_code)); + bcode_unref(reinterpret_cast(p_code)); } CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef const &v) { - bcode_unref(reinterpret_cast(p_code)); + bcode_unref(reinterpret_cast(p_code)); p_code = v.p_code; - bcode_ref(reinterpret_cast(p_code)); + bcode_ref(reinterpret_cast(p_code)); return *this; } CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef &&v) { - bcode_unref(reinterpret_cast(p_code)); + bcode_unref(reinterpret_cast(p_code)); p_code = v.p_code; v.p_code = nullptr; return *this; } -static inline ostd::Uint32 *forcecode(CsState &cs, CsValue &v) { - ostd::Uint32 *code = reinterpret_cast(v.get_code()); +static inline uint32_t *forcecode(CsState &cs, CsValue &v) { + uint32_t *code = reinterpret_cast(v.get_code()); if (!code) { GenState gs(cs); gs.code.reserve(64); @@ -204,7 +204,7 @@ static inline ostd::Uint32 *forcecode(CsState &cs, CsValue &v) { uint32_t *cbuf = new uint32_t[gs.code.size()]; memcpy(cbuf, gs.code.data(), gs.code.size() * sizeof(uint32_t)); v.set_code(reinterpret_cast(cbuf + 1)); - code = reinterpret_cast(v.get_code()); + code = reinterpret_cast(v.get_code()); } return code; } @@ -225,7 +225,7 @@ static inline void forcecond(CsState &cs, CsValue &v) { } } -static ostd::Uint32 emptyblock[CsValAny][2] = { +static uint32_t emptyblock[CsValAny][2] = { { CsCodeStart + 0x100, CsCodeExit | CsRetNull }, { CsCodeStart + 0x100, CsCodeExit | CsRetInt }, { CsCodeStart + 0x100, CsCodeExit | CsRetFloat }, @@ -252,15 +252,15 @@ static inline void force_arg(CsValue &v, int type) { } } -static ostd::Uint32 *skipcode(ostd::Uint32 *code) { +static uint32_t *skipcode(uint32_t *code) { int depth = 0; for (;;) { - ostd::Uint32 op = *code++; + uint32_t op = *code++; switch (op & 0xFF) { case CsCodeMacro: case CsCodeVal | CsRetString: { - ostd::Uint32 len = op >> 8; - code += len / sizeof(ostd::Uint32) + 1; + uint32_t len = op >> 8; + code += len / sizeof(uint32_t) + 1; continue; } case CsCodeBlock: @@ -269,7 +269,7 @@ static ostd::Uint32 *skipcode(ostd::Uint32 *code) { case CsCodeJumpB | CsCodeFlagFalse: case CsCodeJumpResult | CsCodeFlagTrue: case CsCodeJumpResult | CsCodeFlagFalse: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; code += len; continue; } @@ -291,11 +291,11 @@ static ostd::Uint32 *skipcode(ostd::Uint32 *code) { } CsBytecode *cs_copy_code(CsBytecode *c) { - ostd::Uint32 *bcode = reinterpret_cast(c); - ostd::Uint32 *end = skipcode(bcode); - ostd::Uint32 *dst = new ostd::Uint32[end - bcode + 1]; + uint32_t *bcode = reinterpret_cast(c); + uint32_t *end = skipcode(bcode); + uint32_t *dst = new uint32_t[end - bcode + 1]; *dst++ = CsCodeStart; - memcpy(dst, bcode, (end - bcode) * sizeof(ostd::Uint32)); + memcpy(dst, bcode, (end - bcode) * sizeof(uint32_t)); return reinterpret_cast(dst); } @@ -454,11 +454,11 @@ static inline void callcommand( CsCommandInternal::call(cs, id, CsValueRange(args, i), res); } -static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result); +static uint32_t *runcode(CsState &cs, uint32_t *code, CsValue &result); static inline void cs_call_alias( CsState &cs, CsAlias *a, CsValue *args, CsValue &result, - int callargs, int &nargs, int offset, int skip, ostd::Uint32 op + int callargs, int &nargs, int offset, int skip, uint32_t op ) { CsIvar *anargs = static_cast(cs.p_state->identmap[NumargsIdx]); CsIdentStack argstack[MaxArguments]; @@ -476,7 +476,7 @@ static inline void cs_call_alias( a, cs.p_callstack, (1<( + uint32_t *codep = reinterpret_cast( CsAliasInternal::compile_code(a, cs) ); bcode_incr(codep); @@ -522,7 +522,7 @@ struct RunDepthRef { ~RunDepthRef() { --rundepth; } }; -static inline CsAlias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) { +static inline CsAlias *cs_get_lookup_id(CsState &cs, uint32_t op) { CsIdent *id = cs.p_state->identmap[op >> 8]; if (id->get_flags() & CsIdfUnknown) { throw CsErrorException(cs, "unknown alias lookup: %s", id->get_name()); @@ -530,7 +530,7 @@ static inline CsAlias *cs_get_lookup_id(CsState &cs, ostd::Uint32 op) { return static_cast(id); } -static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) { +static inline CsAlias *cs_get_lookuparg_id(CsState &cs, uint32_t op) { CsIdent *id = cs.p_state->identmap[op >> 8]; if (!cs_is_arg_used(cs, id)) { return nullptr; @@ -539,7 +539,7 @@ static inline CsAlias *cs_get_lookuparg_id(CsState &cs, ostd::Uint32 op) { } static inline int cs_get_lookupu_type( - CsState &cs, CsValue &arg, CsIdent *&id, ostd::Uint32 op + CsState &cs, CsValue &arg, CsIdent *&id, uint32_t op ) { if ( arg.get_type() != CsValueType::String && @@ -579,7 +579,7 @@ static inline int cs_get_lookupu_type( throw CsErrorException(cs, "unknown alias lookup: %s", arg.get_strr()); } -static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { +static uint32_t *runcode(CsState &cs, uint32_t *code, CsValue &result) { result.set_null(); RunDepthRef level{cs}; /* incr and decr on scope exit */ int numargs = 0; @@ -589,7 +589,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { chook(cs); } for (;;) { - ostd::Uint32 op = *code++; + uint32_t op = *code++; switch (op & 0xFF) { case CsCodeStart: case CsCodeOffset: @@ -707,26 +707,26 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { continue; case CsCodeJump: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; code += len; continue; } case CsCodeJumpB | CsCodeFlagTrue: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; if (args[--numargs].get_bool()) { code += len; } continue; } case CsCodeJumpB | CsCodeFlagFalse: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; if (!args[--numargs].get_bool()) { code += len; } continue; } case CsCodeJumpResult | CsCodeFlagTrue: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; --numargs; if (args[numargs].get_type() == CsValueType::Code) { cs.run(args[numargs].get_code(), result); @@ -739,7 +739,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { continue; } case CsCodeJumpResult | CsCodeFlagFalse: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; --numargs; if (args[numargs].get_type() == CsValueType::Code) { cs.run(args[numargs].get_code(), result); @@ -767,20 +767,20 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { break; case CsCodeMacro: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; args[numargs++].set_macro(ostd::ConstCharRange( reinterpret_cast(code), len )); - code += len / sizeof(ostd::Uint32) + 1; + code += len / sizeof(uint32_t) + 1; continue; } case CsCodeVal | CsRetString: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; args[numargs++].set_str(ostd::ConstCharRange( reinterpret_cast(code), len )); - code += len / sizeof(ostd::Uint32) + 1; + code += len / sizeof(uint32_t) + 1; continue; } case CsCodeValInt | CsRetString: { @@ -874,7 +874,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) { ); break; case CsCodeBlock: { - ostd::Uint32 len = op >> 8; + uint32_t len = op >> 8; args[numargs++].set_code( reinterpret_cast(code + 1) ); @@ -1602,7 +1602,7 @@ noid: } void CsState::run(CsBytecode *code, CsValue &ret) { - runcode(*this, reinterpret_cast(code), ret); + runcode(*this, reinterpret_cast(code), ret); } static void cs_run( diff --git a/src/cs_vm.hh b/src/cs_vm.hh index be1e239..854b5a2 100644 --- a/src/cs_vm.hh +++ b/src/cs_vm.hh @@ -141,13 +141,13 @@ struct CsContinueException { template constexpr size_t CsTypeStorageSize = - (sizeof(T) - 1) / sizeof(ostd::Uint32) + 1; + (sizeof(T) - 1) / sizeof(uint32_t) + 1; struct GenState { CsState &cs; GenState *prevps; bool parsing = true; - CsVector code; + CsVector code; ostd::ConstCharRange source; size_t current_line; ostd::ConstCharRange src_name; @@ -179,9 +179,9 @@ struct GenState { void gen_str(ostd::ConstCharRange word, bool macro = false) { if (word.size() <= 3 && !macro) { - ostd::Uint32 op = CsCodeValInt | CsRetString; + uint32_t op = CsCodeValInt | CsRetString; for (size_t i = 0; i < word.size(); ++i) { - op |= ostd::Uint32(ostd::byte(word[i])) << ((i + 1) * 8); + op |= uint32_t(ostd::byte(word[i])) << ((i + 1) * 8); } code.push_back(op); return; @@ -189,14 +189,14 @@ struct GenState { code.push_back( (macro ? CsCodeMacro : (CsCodeVal | CsRetString)) | (word.size() << 8) ); - auto it = reinterpret_cast(word.data()); + auto it = reinterpret_cast(word.data()); code.insert( - code.end(), it, it + (word.size() / sizeof(ostd::Uint32)) + code.end(), it, it + (word.size() / sizeof(uint32_t)) ); - size_t esz = word.size() % sizeof(ostd::Uint32); + size_t esz = word.size() % sizeof(uint32_t); union { - char c[sizeof(ostd::Uint32)]; - ostd::Uint32 u; + char c[sizeof(uint32_t)]; + uint32_t u; } end; end.u = 0; memcpy(end.c, word.data() + word.size() - esz, esz); @@ -217,7 +217,7 @@ struct GenState { } else { union { CsInt i; - ostd::Uint32 u[CsTypeStorageSize]; + uint32_t u[CsTypeStorageSize]; } c; c.i = i; code.push_back(CsCodeVal | CsRetInt); @@ -233,7 +233,7 @@ struct GenState { } else { union { CsFloat f; - ostd::Uint32 u[CsTypeStorageSize]; + uint32_t u[CsTypeStorageSize]; } c; c.f = f; code.push_back(CsCodeVal | CsRetFloat); @@ -297,11 +297,11 @@ CsString floatstr(CsFloat v); bool cs_check_num(ostd::ConstCharRange s); -static inline void bcode_incr(ostd::Uint32 *bc) { +static inline void bcode_incr(uint32_t *bc) { *bc += 0x100; } -static inline void bcode_decr(ostd::Uint32 *bc) { +static inline void bcode_decr(uint32_t *bc) { *bc -= 0x100; if (ostd::Int32(*bc) < 0x100) { delete[] bc; @@ -379,7 +379,7 @@ struct CsAliasInternal { } static void clean_code(CsAlias *a) { - ostd::Uint32 *bcode = reinterpret_cast(a->p_acode); + uint32_t *bcode = reinterpret_cast(a->p_acode); if (bcode) { bcode_decr(bcode); a->p_acode = nullptr; @@ -392,7 +392,7 @@ struct CsAliasInternal { gs.code.reserve(64); gs.gen_main(a->get_value().get_str()); /* i wish i could steal the memory somehow */ - ostd::Uint32 *code = new ostd::Uint32[gs.code.size()]; + uint32_t *code = new uint32_t[gs.code.size()]; memcpy(code, gs.code.data(), gs.code.size() * sizeof(uint32_t)); bcode_incr(code); a->p_acode = reinterpret_cast(code);