use uint32_t

master
Daniel Kolesa 2017-01-25 02:10:17 +01:00
parent 1c5c0939e1
commit 8e31583612
4 changed files with 74 additions and 74 deletions

View File

@ -192,7 +192,7 @@ static inline ostd::Pair<ostd::ConstCharRange, size_t> compileblock(
} }
if (gs.code.size() > start + 2) { if (gs.code.size() > start + 2) {
gs.code.push_back(CsCodeExit | rettype); 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 { } else {
gs.code.resize(start); gs.code.resize(start);
gs.code.push_back(CsCodeEmpty | rettype); gs.code.push_back(CsCodeEmpty | rettype);
@ -204,16 +204,16 @@ static inline void compileunescapestr(GenState &gs, bool macro = false) {
auto str = gs.get_str(); auto str = gs.get_str();
gs.code.push_back(macro ? CsCodeMacro : (CsCodeVal | CsRetString)); gs.code.push_back(macro ? CsCodeMacro : (CsCodeVal | CsRetString));
gs.code.reserve( 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]; char *buf = new char[bufs + 1];
auto writer = ostd::CharRange(buf, bufs); auto writer = ostd::CharRange(buf, bufs);
size_t 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(uint32_t) - len % sizeof(uint32_t));
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);
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; delete[] buf;
} }
@ -482,7 +482,7 @@ invalid:
static bool compileblockstr(GenState &gs, ostd::ConstCharRange str, bool macro) { static bool compileblockstr(GenState &gs, ostd::ConstCharRange str, bool macro) {
int startc = gs.code.size(); int startc = gs.code.size();
gs.code.push_back(macro ? CsCodeMacro : CsCodeVal | CsRetString); 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)]; char *buf = new char[(str.size() / sizeof(uint32_t) + 1) * sizeof(uint32_t)];
int len = 0; int len = 0;
while (!str.empty()) { while (!str.empty()) {
@ -521,9 +521,9 @@ static bool compileblockstr(GenState &gs, ostd::ConstCharRange str, bool macro)
} }
} }
done: 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<uint32_t *>(buf); uint32_t *ubuf = reinterpret_cast<uint32_t *>(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; gs.code[startc] |= len << 8;
delete[] buf; delete[] buf;
return true; return true;
@ -1145,9 +1145,9 @@ static void compile_if(
} else { } else {
int start2 = gs.code.size(); int start2 = gs.code.size();
more = compilearg(gs, CsValCode, prevargs + 2); more = compilearg(gs, CsValCode, prevargs + 2);
ostd::Uint32 inst1 = gs.code[start1]; uint32_t inst1 = gs.code[start1];
ostd::Uint32 op1 = inst1 & ~CsCodeRetMask; uint32_t op1 = inst1 & ~CsCodeRetMask;
ostd::Uint32 len1 = start2 - (start1 + 1); uint32_t len1 = start2 - (start1 + 1);
if (!more) { if (!more) {
if (op1 == (CsCodeBlock | (len1 << 8))) { if (op1 == (CsCodeBlock | (len1 << 8))) {
gs.code[start1] = (len1 << 8) | CsCodeJumpB | CsCodeFlagFalse; gs.code[start1] = (len1 << 8) | CsCodeJumpB | CsCodeFlagFalse;
@ -1159,9 +1159,9 @@ static void compile_if(
} }
compileblock(gs); compileblock(gs);
} else { } else {
ostd::Uint32 inst2 = gs.code[start2]; uint32_t inst2 = gs.code[start2];
ostd::Uint32 op2 = inst2 & ~CsCodeRetMask; uint32_t op2 = inst2 & ~CsCodeRetMask;
ostd::Uint32 len2 = gs.code.size() - (start2 + 1); uint32_t len2 = gs.code.size() - (start2 + 1);
if (op2 == (CsCodeBlock | (len2 << 8))) { if (op2 == (CsCodeBlock | (len2 << 8))) {
if (op1 == (CsCodeBlock | (len1 << 8))) { if (op1 == (CsCodeBlock | (len1 << 8))) {
gs.code[start1] = ((start2 - start1) << 8) gs.code[start1] = ((start2 - start1) << 8)
@ -1214,7 +1214,7 @@ static void compile_and_or(
} }
numargs++; numargs++;
if ((gs.code[end] & ~CsCodeRetMask) != ( if ((gs.code[end] & ~CsCodeRetMask) != (
CsCodeBlock | (ostd::Uint32(gs.code.size() - (end + 1)) << 8) CsCodeBlock | (uint32_t(gs.code.size() - (end + 1)) << 8)
)) { )) {
break; break;
} }
@ -1233,13 +1233,13 @@ static void compile_and_or(
(numargs << 8) | (id->get_index() << 13) (numargs << 8) | (id->get_index() << 13)
); );
} else { } else {
ostd::Uint32 op = (id->get_type_raw() == CsIdAnd) uint32_t op = (id->get_type_raw() == CsIdAnd)
? (CsCodeJumpResult | CsCodeFlagFalse) ? (CsCodeJumpResult | CsCodeFlagFalse)
: (CsCodeJumpResult | CsCodeFlagTrue); : (CsCodeJumpResult | CsCodeFlagTrue);
gs.code.push_back(op); gs.code.push_back(op);
end = gs.code.size(); end = gs.code.size();
while ((start + 1) < end) { 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] = ((end - (start + 1)) << 8) | op;
gs.code[start + 1] = CsCodeEnter; gs.code[start + 1] = CsCodeEnter;
gs.code[start + len] = ( gs.code[start + len] = (

View File

@ -17,7 +17,7 @@ static inline void csv_cleanup(CsValueType tv, T &stor) {
delete[] csv_get<char *>(stor); delete[] csv_get<char *>(stor);
break; break;
case CsValueType::Code: { case CsValueType::Code: {
ostd::Uint32 *bcode = csv_get<ostd::Uint32 *>(stor); uint32_t *bcode = csv_get<uint32_t *>(stor);
if (bcode[-1] == CsCodeStart) { if (bcode[-1] == CsCodeStart) {
delete[] &bcode[-1]; delete[] &bcode[-1];
} }
@ -319,7 +319,7 @@ OSTD_EXPORT bool cs_code_is_empty(CsBytecode *code) {
return true; return true;
} }
return ( return (
*reinterpret_cast<ostd::Uint32 *>(code) & CsCodeOpMask *reinterpret_cast<uint32_t *>(code) & CsCodeOpMask
) == CsCodeExit; ) == CsCodeExit;
} }

View File

@ -131,7 +131,7 @@ ostd::ConstCharRange CsErrorException::save_msg(
return ostd::ConstCharRange(cs.p_errbuf, msg.size()); return ostd::ConstCharRange(cs.p_errbuf, msg.size());
} }
static void bcode_ref(ostd::Uint32 *code) { static void bcode_ref(uint32_t *code) {
if (!code) { if (!code) {
return; 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) { if (!code) {
return; return;
} }
@ -170,32 +170,32 @@ static void bcode_unref(ostd::Uint32 *code) {
} }
CsBytecodeRef::CsBytecodeRef(CsBytecode *v): p_code(v) { CsBytecodeRef::CsBytecodeRef(CsBytecode *v): p_code(v) {
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_ref(reinterpret_cast<uint32_t *>(p_code));
} }
CsBytecodeRef::CsBytecodeRef(CsBytecodeRef const &v): p_code(v.p_code) { CsBytecodeRef::CsBytecodeRef(CsBytecodeRef const &v): p_code(v.p_code) {
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_ref(reinterpret_cast<uint32_t *>(p_code));
} }
CsBytecodeRef::~CsBytecodeRef() { CsBytecodeRef::~CsBytecodeRef() {
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_unref(reinterpret_cast<uint32_t *>(p_code));
} }
CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef const &v) { CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef const &v) {
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_unref(reinterpret_cast<uint32_t *>(p_code));
p_code = v.p_code; p_code = v.p_code;
bcode_ref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_ref(reinterpret_cast<uint32_t *>(p_code));
return *this; return *this;
} }
CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef &&v) { CsBytecodeRef &CsBytecodeRef::operator=(CsBytecodeRef &&v) {
bcode_unref(reinterpret_cast<ostd::Uint32 *>(p_code)); bcode_unref(reinterpret_cast<uint32_t *>(p_code));
p_code = v.p_code; p_code = v.p_code;
v.p_code = nullptr; v.p_code = nullptr;
return *this; return *this;
} }
static inline ostd::Uint32 *forcecode(CsState &cs, CsValue &v) { static inline uint32_t *forcecode(CsState &cs, CsValue &v) {
ostd::Uint32 *code = reinterpret_cast<ostd::Uint32 *>(v.get_code()); uint32_t *code = reinterpret_cast<uint32_t *>(v.get_code());
if (!code) { if (!code) {
GenState gs(cs); GenState gs(cs);
gs.code.reserve(64); 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()]; uint32_t *cbuf = new uint32_t[gs.code.size()];
memcpy(cbuf, gs.code.data(), gs.code.size() * sizeof(uint32_t)); memcpy(cbuf, gs.code.data(), gs.code.size() * sizeof(uint32_t));
v.set_code(reinterpret_cast<CsBytecode *>(cbuf + 1)); v.set_code(reinterpret_cast<CsBytecode *>(cbuf + 1));
code = reinterpret_cast<ostd::Uint32 *>(v.get_code()); code = reinterpret_cast<uint32_t *>(v.get_code());
} }
return 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 | CsRetNull },
{ CsCodeStart + 0x100, CsCodeExit | CsRetInt }, { CsCodeStart + 0x100, CsCodeExit | CsRetInt },
{ CsCodeStart + 0x100, CsCodeExit | CsRetFloat }, { 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; int depth = 0;
for (;;) { for (;;) {
ostd::Uint32 op = *code++; uint32_t op = *code++;
switch (op & 0xFF) { switch (op & 0xFF) {
case CsCodeMacro: case CsCodeMacro:
case CsCodeVal | CsRetString: { case CsCodeVal | CsRetString: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
code += len / sizeof(ostd::Uint32) + 1; code += len / sizeof(uint32_t) + 1;
continue; continue;
} }
case CsCodeBlock: case CsCodeBlock:
@ -269,7 +269,7 @@ static ostd::Uint32 *skipcode(ostd::Uint32 *code) {
case CsCodeJumpB | CsCodeFlagFalse: case CsCodeJumpB | CsCodeFlagFalse:
case CsCodeJumpResult | CsCodeFlagTrue: case CsCodeJumpResult | CsCodeFlagTrue:
case CsCodeJumpResult | CsCodeFlagFalse: { case CsCodeJumpResult | CsCodeFlagFalse: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
code += len; code += len;
continue; continue;
} }
@ -291,11 +291,11 @@ static ostd::Uint32 *skipcode(ostd::Uint32 *code) {
} }
CsBytecode *cs_copy_code(CsBytecode *c) { CsBytecode *cs_copy_code(CsBytecode *c) {
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(c); uint32_t *bcode = reinterpret_cast<uint32_t *>(c);
ostd::Uint32 *end = skipcode(bcode); uint32_t *end = skipcode(bcode);
ostd::Uint32 *dst = new ostd::Uint32[end - bcode + 1]; uint32_t *dst = new uint32_t[end - bcode + 1];
*dst++ = CsCodeStart; *dst++ = CsCodeStart;
memcpy(dst, bcode, (end - bcode) * sizeof(ostd::Uint32)); memcpy(dst, bcode, (end - bcode) * sizeof(uint32_t));
return reinterpret_cast<CsBytecode *>(dst); return reinterpret_cast<CsBytecode *>(dst);
} }
@ -454,11 +454,11 @@ static inline void callcommand(
CsCommandInternal::call(cs, id, CsValueRange(args, i), res); 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( static inline void cs_call_alias(
CsState &cs, CsAlias *a, CsValue *args, CsValue &result, 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<CsIvar *>(cs.p_state->identmap[NumargsIdx]); CsIvar *anargs = static_cast<CsIvar *>(cs.p_state->identmap[NumargsIdx]);
CsIdentStack argstack[MaxArguments]; CsIdentStack argstack[MaxArguments];
@ -476,7 +476,7 @@ static inline void cs_call_alias(
a, cs.p_callstack, (1<<callargs)-1, argstack a, cs.p_callstack, (1<<callargs)-1, argstack
}; };
cs.p_callstack = &aliaslink; cs.p_callstack = &aliaslink;
ostd::Uint32 *codep = reinterpret_cast<ostd::Uint32 *>( uint32_t *codep = reinterpret_cast<uint32_t *>(
CsAliasInternal::compile_code(a, cs) CsAliasInternal::compile_code(a, cs)
); );
bcode_incr(codep); bcode_incr(codep);
@ -522,7 +522,7 @@ struct RunDepthRef {
~RunDepthRef() { --rundepth; } ~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]; CsIdent *id = cs.p_state->identmap[op >> 8];
if (id->get_flags() & CsIdfUnknown) { if (id->get_flags() & CsIdfUnknown) {
throw CsErrorException(cs, "unknown alias lookup: %s", id->get_name()); 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<CsAlias *>(id); return static_cast<CsAlias *>(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]; CsIdent *id = cs.p_state->identmap[op >> 8];
if (!cs_is_arg_used(cs, id)) { if (!cs_is_arg_used(cs, id)) {
return nullptr; 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( 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 ( if (
arg.get_type() != CsValueType::String && 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()); 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(); result.set_null();
RunDepthRef level{cs}; /* incr and decr on scope exit */ RunDepthRef level{cs}; /* incr and decr on scope exit */
int numargs = 0; int numargs = 0;
@ -589,7 +589,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
chook(cs); chook(cs);
} }
for (;;) { for (;;) {
ostd::Uint32 op = *code++; uint32_t op = *code++;
switch (op & 0xFF) { switch (op & 0xFF) {
case CsCodeStart: case CsCodeStart:
case CsCodeOffset: case CsCodeOffset:
@ -707,26 +707,26 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
continue; continue;
case CsCodeJump: { case CsCodeJump: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
code += len; code += len;
continue; continue;
} }
case CsCodeJumpB | CsCodeFlagTrue: { case CsCodeJumpB | CsCodeFlagTrue: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
if (args[--numargs].get_bool()) { if (args[--numargs].get_bool()) {
code += len; code += len;
} }
continue; continue;
} }
case CsCodeJumpB | CsCodeFlagFalse: { case CsCodeJumpB | CsCodeFlagFalse: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
if (!args[--numargs].get_bool()) { if (!args[--numargs].get_bool()) {
code += len; code += len;
} }
continue; continue;
} }
case CsCodeJumpResult | CsCodeFlagTrue: { case CsCodeJumpResult | CsCodeFlagTrue: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
--numargs; --numargs;
if (args[numargs].get_type() == CsValueType::Code) { if (args[numargs].get_type() == CsValueType::Code) {
cs.run(args[numargs].get_code(), result); cs.run(args[numargs].get_code(), result);
@ -739,7 +739,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
continue; continue;
} }
case CsCodeJumpResult | CsCodeFlagFalse: { case CsCodeJumpResult | CsCodeFlagFalse: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
--numargs; --numargs;
if (args[numargs].get_type() == CsValueType::Code) { if (args[numargs].get_type() == CsValueType::Code) {
cs.run(args[numargs].get_code(), result); cs.run(args[numargs].get_code(), result);
@ -767,20 +767,20 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
break; break;
case CsCodeMacro: { case CsCodeMacro: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
args[numargs++].set_macro(ostd::ConstCharRange( args[numargs++].set_macro(ostd::ConstCharRange(
reinterpret_cast<char const *>(code), len reinterpret_cast<char const *>(code), len
)); ));
code += len / sizeof(ostd::Uint32) + 1; code += len / sizeof(uint32_t) + 1;
continue; continue;
} }
case CsCodeVal | CsRetString: { case CsCodeVal | CsRetString: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
args[numargs++].set_str(ostd::ConstCharRange( args[numargs++].set_str(ostd::ConstCharRange(
reinterpret_cast<char const *>(code), len reinterpret_cast<char const *>(code), len
)); ));
code += len / sizeof(ostd::Uint32) + 1; code += len / sizeof(uint32_t) + 1;
continue; continue;
} }
case CsCodeValInt | CsRetString: { case CsCodeValInt | CsRetString: {
@ -874,7 +874,7 @@ static ostd::Uint32 *runcode(CsState &cs, ostd::Uint32 *code, CsValue &result) {
); );
break; break;
case CsCodeBlock: { case CsCodeBlock: {
ostd::Uint32 len = op >> 8; uint32_t len = op >> 8;
args[numargs++].set_code( args[numargs++].set_code(
reinterpret_cast<CsBytecode *>(code + 1) reinterpret_cast<CsBytecode *>(code + 1)
); );
@ -1602,7 +1602,7 @@ noid:
} }
void CsState::run(CsBytecode *code, CsValue &ret) { void CsState::run(CsBytecode *code, CsValue &ret) {
runcode(*this, reinterpret_cast<ostd::Uint32 *>(code), ret); runcode(*this, reinterpret_cast<uint32_t *>(code), ret);
} }
static void cs_run( static void cs_run(

View File

@ -141,13 +141,13 @@ struct CsContinueException {
template<typename T> template<typename T>
constexpr size_t CsTypeStorageSize = constexpr size_t CsTypeStorageSize =
(sizeof(T) - 1) / sizeof(ostd::Uint32) + 1; (sizeof(T) - 1) / sizeof(uint32_t) + 1;
struct GenState { struct GenState {
CsState &cs; CsState &cs;
GenState *prevps; GenState *prevps;
bool parsing = true; bool parsing = true;
CsVector<ostd::Uint32> code; CsVector<uint32_t> code;
ostd::ConstCharRange source; ostd::ConstCharRange source;
size_t current_line; size_t current_line;
ostd::ConstCharRange src_name; ostd::ConstCharRange src_name;
@ -179,9 +179,9 @@ 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; uint32_t op = CsCodeValInt | CsRetString;
for (size_t 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 |= uint32_t(ostd::byte(word[i])) << ((i + 1) * 8);
} }
code.push_back(op); code.push_back(op);
return; return;
@ -189,14 +189,14 @@ struct GenState {
code.push_back( code.push_back(
(macro ? CsCodeMacro : (CsCodeVal | CsRetString)) | (word.size() << 8) (macro ? CsCodeMacro : (CsCodeVal | CsRetString)) | (word.size() << 8)
); );
auto it = reinterpret_cast<ostd::Uint32 const *>(word.data()); auto it = reinterpret_cast<uint32_t const *>(word.data());
code.insert( 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 { union {
char c[sizeof(ostd::Uint32)]; char c[sizeof(uint32_t)];
ostd::Uint32 u; uint32_t u;
} end; } end;
end.u = 0; end.u = 0;
memcpy(end.c, word.data() + word.size() - esz, esz); memcpy(end.c, word.data() + word.size() - esz, esz);
@ -217,7 +217,7 @@ struct GenState {
} else { } else {
union { union {
CsInt i; CsInt i;
ostd::Uint32 u[CsTypeStorageSize<CsInt>]; uint32_t u[CsTypeStorageSize<CsInt>];
} c; } c;
c.i = i; c.i = i;
code.push_back(CsCodeVal | CsRetInt); code.push_back(CsCodeVal | CsRetInt);
@ -233,7 +233,7 @@ struct GenState {
} else { } else {
union { union {
CsFloat f; CsFloat f;
ostd::Uint32 u[CsTypeStorageSize<CsFloat>]; uint32_t u[CsTypeStorageSize<CsFloat>];
} c; } c;
c.f = f; c.f = f;
code.push_back(CsCodeVal | CsRetFloat); code.push_back(CsCodeVal | CsRetFloat);
@ -297,11 +297,11 @@ CsString floatstr(CsFloat v);
bool cs_check_num(ostd::ConstCharRange s); 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; *bc += 0x100;
} }
static inline void bcode_decr(ostd::Uint32 *bc) { static inline void bcode_decr(uint32_t *bc) {
*bc -= 0x100; *bc -= 0x100;
if (ostd::Int32(*bc) < 0x100) { if (ostd::Int32(*bc) < 0x100) {
delete[] bc; delete[] bc;
@ -379,7 +379,7 @@ struct CsAliasInternal {
} }
static void clean_code(CsAlias *a) { static void clean_code(CsAlias *a) {
ostd::Uint32 *bcode = reinterpret_cast<ostd::Uint32 *>(a->p_acode); uint32_t *bcode = reinterpret_cast<uint32_t *>(a->p_acode);
if (bcode) { if (bcode) {
bcode_decr(bcode); bcode_decr(bcode);
a->p_acode = nullptr; a->p_acode = nullptr;
@ -392,7 +392,7 @@ struct CsAliasInternal {
gs.code.reserve(64); gs.code.reserve(64);
gs.gen_main(a->get_value().get_str()); gs.gen_main(a->get_value().get_str());
/* i wish i could steal the memory somehow */ /* 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)); memcpy(code, gs.code.data(), gs.code.size() * sizeof(uint32_t));
bcode_incr(code); bcode_incr(code);
a->p_acode = reinterpret_cast<CsBytecode *>(code); a->p_acode = reinterpret_cast<CsBytecode *>(code);