From 64130a12bf73a1a4dc3c6684d1e35561d489a64a Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Wed, 17 Mar 2021 20:40:32 +0100 Subject: [PATCH] remove handling of constants from codegen, bytecode and cs_value also drop move semantics on cs_value --- include/cubescript/cubescript.hh | 12 +-- src/cs_gen.cc | 155 ++++++++++--------------------- src/cs_val.cc | 60 +----------- src/cs_vm.cc | 63 ++----------- src/cs_vm.hh | 17 ++-- src/cubescript.cc | 37 +++----- src/lib_list.cc | 4 +- 7 files changed, 82 insertions(+), 266 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index 1e0f5e8..2765866 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -94,7 +94,7 @@ private: }; enum class cs_value_type { - Null = 0, Int, Float, String, Cstring, Code, Macro, Ident + Null = 0, Int, Float, String, Code, Ident }; struct OSTD_EXPORT cs_value { @@ -105,21 +105,17 @@ struct OSTD_EXPORT cs_value { cs_value(cs_shared_state &); cs_value(cs_value const &); - cs_value(cs_value &&); cs_value &operator=(cs_value const &); - cs_value &operator=(cs_value &&); cs_value_type get_type() const; void set_int(cs_int val); void set_float(cs_float val); - void set_str(cs_string val); + void set_str(ostd::string_range val); void set_null(); void set_code(cs_bcode *val); - void set_cstr(ostd::string_range val); void set_ident(cs_ident *val); - void set_macro(ostd::string_range val); cs_string get_str() const; ostd::string_range get_strr() const; @@ -868,9 +864,7 @@ private: ); break; } - case cs_value_type::String: - case cs_value_type::Cstring: - case cs_value_type::Macro: { + case cs_value_type::String: { ostd::range_put_all(writer, vals[i].get_strr()); break; } diff --git a/src/cs_gen.cc b/src/cs_gen.cc index 2e017e2..0b06566 100644 --- a/src/cs_gen.cc +++ b/src/cs_gen.cc @@ -100,7 +100,7 @@ ostd::string_range cs_gen_state::get_word() { static inline int cs_ret_code(int type, int def = 0) { if (type >= CsValAny) { - return (type == CsValCstring) ? CsRetString : def; + return (type == CsValString) ? CsRetString : def; } return type << CsCodeRet; } @@ -123,16 +123,6 @@ void cs_gen_state::gen_float(ostd::string_range word) { void cs_gen_state::gen_value(int wordtype, ostd::string_range word, int line) { switch (wordtype) { - case CsValCany: - if (!word.empty()) { - gen_str(word, true); - } else { - gen_null(); - } - break; - case CsValCstring: - gen_str(word, true); - break; case CsValAny: if (!word.empty()) { gen_str(word); @@ -199,9 +189,9 @@ static inline std::pair compileblock( return std::make_pair(p, retline); } -static inline void compileunescapestr(cs_gen_state &gs, bool macro = false) { +static inline void compileunescapestr(cs_gen_state &gs) { auto str = gs.get_str(); - gs.code.push_back(macro ? CsCodeMacro : (CsCodeVal | CsRetString)); + gs.code.push_back(CsCodeVal | CsRetString); gs.code.reserve( gs.code.size() + str.size() / sizeof(uint32_t) + 1 ); @@ -227,12 +217,12 @@ static void compilelookup(cs_gen_state &gs, int ltype, int prevargs = MaxResults switch (gs.current()) { case '(': case '[': - if (!compilearg(gs, CsValCstring, prevargs)) { + if (!compilearg(gs, CsValString, prevargs)) { goto invalid; } break; case '$': - compilelookup(gs, CsValCstring, prevargs); + compilelookup(gs, CsValString, prevargs); break; case '\"': lookup = gs.get_str_dup(); @@ -282,15 +272,6 @@ lookupid: switch (ltype) { case CsValPop: return; - case CsValCany: - case CsValCstring: - case CsValCode: - case CsValIdent: - case CsValCond: - gs.code.push_back( - CsCodeSvarM | (id->get_index() << 8) - ); - break; default: gs.code.push_back( CsCodeSvar | cs_ret_code(ltype, CsRetString) | @@ -303,7 +284,6 @@ lookupid: switch (ltype) { case CsValPop: return; - case CsValCany: case CsValCond: gs.code.push_back( (id->get_index() < MaxArguments @@ -312,7 +292,6 @@ lookupid: ) | (id->get_index() << 8) ); break; - case CsValCstring: case CsValCode: case CsValIdent: gs.code.push_back( @@ -346,7 +325,7 @@ lookupid: numargs++; break; case 's': - gs.gen_str(ostd::string_range(), true); + gs.gen_str(ostd::string_range()); numargs++; break; case 'i': @@ -427,16 +406,14 @@ lookupid: goto invalid; } } - gs.gen_str(lookup, true); + gs.gen_str(lookup); break; } } switch (ltype) { - case CsValCany: case CsValCond: gs.code.push_back(CsCodeLookupMu); break; - case CsValCstring: case CsValCode: case CsValIdent: gs.code.push_back(CsCodeLookupMu | CsRetString); @@ -467,7 +444,6 @@ invalid: break; case CsValNull: case CsValAny: - case CsValCany: case CsValWord: case CsValCond: gs.gen_null(); @@ -478,9 +454,9 @@ invalid: } } -static bool compileblockstr(cs_gen_state &gs, ostd::string_range str, bool macro) { +static bool compileblockstr(cs_gen_state &gs, ostd::string_range str) { int startc = gs.code.size(); - gs.code.push_back(macro ? CsCodeMacro : CsCodeVal | CsRetString); + gs.code.push_back(CsCodeVal | CsRetString); 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; @@ -532,12 +508,12 @@ static bool compileblocksub(cs_gen_state &gs, int prevargs) { cs_string lookup; switch (gs.current()) { case '(': - if (!compilearg(gs, CsValCany, prevargs)) { + if (!compilearg(gs, CsValAny, prevargs)) { return false; } break; case '[': - if (!compilearg(gs, CsValCstring, prevargs)) { + if (!compilearg(gs, CsValString, prevargs)) { return false; } gs.code.push_back(CsCodeLookupMu); @@ -561,7 +537,7 @@ lookupid: gs.code.push_back(CsCodeFvar | (id->get_index() << 8)); goto done; case cs_ident_type::Svar: - gs.code.push_back(CsCodeSvarM | (id->get_index() << 8)); + gs.code.push_back(CsCodeSvar | (id->get_index() << 8)); goto done; case cs_ident_type::Alias: gs.code.push_back( @@ -575,7 +551,7 @@ lookupid: break; } } - gs.gen_str(lookup, true); + gs.gen_str(lookup); gs.code.push_back(CsCodeLookupMu); done: break; @@ -630,9 +606,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) { gs.code.push_back(CsCodeConcW | CsRetString | (concs << 8)); concs = 1; } - if (compileblockstr( - gs, ostd::string_range(start, esc), true - )) { + if (compileblockstr(gs, ostd::string_range(start, esc))) { concs++; } if (compileblocksub(gs, prevargs + concs)) { @@ -670,22 +644,7 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) { return; } } - switch (wordtype) { - case CsValCstring: - case CsValCode: - case CsValIdent: - case CsValCany: - case CsValCond: - compileblockstr( - gs, ostd::string_range(start, gs.source.data() - 1), true - ); - break; - default: - compileblockstr( - gs, ostd::string_range(start, gs.source.data() - 1), concs > 0 - ); - break; - } + compileblockstr(gs, ostd::string_range(start, gs.source.data() - 1)); if (concs > 1) { concs++; } @@ -725,12 +684,6 @@ static void compileblockmain(cs_gen_state &gs, int wordtype, int prevargs) { gs.code.push_back(CsCodeIdentU); } break; - case CsValCstring: - case CsValCany: - if (!concs && gs.source.data() - 1 <= start) { - gs.gen_str(ostd::string_range(), true); - } - break; case CsValString: case CsValNull: case CsValAny: @@ -785,10 +738,6 @@ static bool compilearg( case CsValString: compileunescapestr(gs); break; - case CsValCany: - case CsValCstring: - compileunescapestr(gs, true); - break; default: { size_t line = gs.current_line; auto s = gs.get_str_dup(); @@ -804,15 +753,11 @@ static bool compilearg( gs.next_char(); if (prevargs >= MaxResults) { gs.code.push_back(CsCodeEnter); - compilestatements( - gs, wordtype > CsValAny ? CsValCany : CsValAny, ')' - ); + compilestatements(gs, CsValAny, ')'); gs.code.push_back(CsCodeExit | cs_ret_code(wordtype)); } else { size_t start = gs.code.size(); - compilestatements( - gs, wordtype > CsValAny ? CsValCany : CsValAny, ')', prevargs - ); + compilestatements(gs, CsValAny, ')', prevargs); if (gs.code.size() > start) { gs.code.push_back(CsCodeResultArg | cs_ret_code(wordtype)); } else { @@ -890,25 +835,21 @@ static void compile_cmd( auto fmt = id->get_args(); for (; !fmt.empty(); ++fmt) { switch (*fmt) { - case 'S': - case 's': + case 's': /* string */ if (more) { - more = compilearg( - gs, *fmt == 's' ? CsValCstring : CsValString, - prevargs + numargs - ); + more = compilearg(gs, CsValString, prevargs + numargs); } if (!more) { if (rep) { break; } - gs.gen_str(ostd::string_range(), *fmt == 's'); + gs.gen_str(ostd::string_range()); fakeargs++; } else if (fmt.size() == 1) { int numconc = 1; while ((numargs + numconc) < MaxArguments) { more = compilearg( - gs, CsValCstring, prevargs + numargs + numconc + gs, CsValString, prevargs + numargs + numconc ); if (!more) { break; @@ -921,7 +862,7 @@ static void compile_cmd( } numargs++; break; - case 'i': + case 'i': /* integer */ if (more) { more = compilearg(gs, CsValInt, prevargs + numargs); } @@ -934,7 +875,7 @@ static void compile_cmd( } numargs++; break; - case 'b': + case 'b': /* integer, INT_MIN default */ if (more) { more = compilearg(gs, CsValInt, prevargs + numargs); } @@ -947,7 +888,7 @@ static void compile_cmd( } numargs++; break; - case 'f': + case 'f': /* float */ if (more) { more = compilearg(gs, CsValFloat, prevargs + numargs); } @@ -960,7 +901,7 @@ static void compile_cmd( } numargs++; break; - case 'F': + case 'F': /* float, prev-argument default */ if (more) { more = compilearg(gs, CsValFloat, prevargs + numargs); } @@ -973,11 +914,10 @@ static void compile_cmd( } numargs++; break; - case 'T': - case 't': + case 't': /* any arg */ if (more) { more = compilearg( - gs, *fmt == 't' ? CsValCany : CsValAny, + gs, CsValAny, prevargs + numargs ); } @@ -990,7 +930,7 @@ static void compile_cmd( } numargs++; break; - case 'E': + case 'E': /* condition */ if (more) { more = compilearg(gs, CsValCond, prevargs + numargs); } @@ -1003,7 +943,7 @@ static void compile_cmd( } numargs++; break; - case 'e': + case 'e': /* code */ if (more) { more = compilearg(gs, CsValCode, prevargs + numargs); } @@ -1016,7 +956,7 @@ static void compile_cmd( } numargs++; break; - case 'r': + case 'r': /* ident */ if (more) { more = compilearg(gs, CsValIdent, prevargs + numargs); } @@ -1029,19 +969,19 @@ static void compile_cmd( } numargs++; break; - case '$': + case '$': /* self */ gs.gen_ident(id); numargs++; break; - case 'N': + case 'N': /* number of arguments */ gs.gen_int(numargs - fakeargs); numargs++; break; - case 'C': + case 'C': /* concatenated string */ comtype = CsCodeComC; if (more) { while (numargs < MaxArguments) { - more = compilearg(gs, CsValCany, prevargs + numargs); + more = compilearg(gs, CsValAny, prevargs + numargs); if (!more) { break; } @@ -1049,11 +989,11 @@ static void compile_cmd( } } goto compilecomv; - case 'V': + case 'V': /* varargs */ comtype = CsCodeComV; if (more) { while (numargs < MaxArguments) { - more = compilearg(gs, CsValCany, prevargs + numargs); + more = compilearg(gs, CsValAny, prevargs + numargs); if (!more) { break; } @@ -1061,7 +1001,7 @@ static void compile_cmd( } } goto compilecomv; - case '1': + case '1': /* vararg repetition */ case '2': case '3': case '4': @@ -1131,7 +1071,7 @@ static void compile_if( cs_gen_state &gs, cs_ident *id, bool &more, int prevargs, int rettype ) { if (more) { - more = compilearg(gs, CsValCany, prevargs); + more = compilearg(gs, CsValAny, prevargs); } if (!more) { gs.code.push_back(CsCodeNull | cs_ret_code(rettype)); @@ -1310,7 +1250,7 @@ static void compilestatements(cs_gen_state &gs, int rettype, int brak, int preva ); goto endstatement; case cs_ident_type::Svar: - more = compilearg(gs, CsValCstring, prevargs); + more = compilearg(gs, CsValString, prevargs); if (!more) { gs.gen_str(); } @@ -1322,7 +1262,7 @@ static void compilestatements(cs_gen_state &gs, int rettype, int brak, int preva break; } } - gs.gen_str(idname, true); + gs.gen_str(idname); } more = compilearg(gs, CsValAny); if (!more) { @@ -1336,7 +1276,7 @@ static void compilestatements(cs_gen_state &gs, int rettype, int brak, int preva noid: int numargs = 0; while (numargs < MaxArguments) { - more = compilearg(gs, CsValCany, prevargs + numargs); + more = compilearg(gs, CsValAny, prevargs + numargs); if (!more) { break; } @@ -1347,16 +1287,15 @@ noid: cs_ident *id = gs.cs.get_ident(idname); if (!id) { if (!cs_check_num(idname)) { - gs.gen_str(idname, true); + gs.gen_str(idname); goto noid; } switch (rettype) { - case CsValAny: - case CsValCany: { + case CsValAny: { ostd::string_range end = idname; cs_int val = cs_parse_int(end, &end); if (!end.empty()) { - gs.gen_str(idname, rettype == CsValCany); + gs.gen_str(idname); } else { gs.gen_int(val); } @@ -1409,7 +1348,7 @@ noid: break; case CsIdNot: if (more) { - more = compilearg(gs, CsValCany, prevargs); + more = compilearg(gs, CsValAny, prevargs); } gs.code.push_back( (more ? CsCodeNot : CsCodeTrue) | cs_ret_code(rettype) @@ -1442,7 +1381,7 @@ noid: } break; case CsIdSvar: - if (!(more = compilearg(gs, CsValCstring, prevargs))) { + if (!(more = compilearg(gs, CsValString, prevargs))) { gs.code.push_back(CsCodePrint | (id->get_index() << 8)); } else { int numargs = 0; @@ -1450,7 +1389,7 @@ noid: ++numargs; } while (numargs < MaxArguments && ( more = compilearg( - gs, CsValCany, prevargs + numargs + gs, CsValAny, prevargs + numargs ) )); if (numargs > 1) { diff --git a/src/cs_val.cc b/src/cs_val.cc index eb2cae1..2e8b611 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -20,8 +20,6 @@ template static inline void csv_cleanup(cs_value_type tv, T &stor) { switch (tv) { case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: reinterpret_cast(&stor)->~cs_strref(); break; case cs_value_type::Code: { @@ -52,10 +50,6 @@ cs_value::cs_value(cs_value const &v): cs_value(*v.state()) { *this = v; } -cs_value::cs_value(cs_value &&v): cs_value(*v.state()) { - *this = std::move(v); -} - cs_value &cs_value::operator=(cs_value const &v) { csv_cleanup(p_type, p_stor); p_type = cs_value_type::Null; @@ -68,8 +62,6 @@ cs_value &cs_value::operator=(cs_value const &v) { p_stor = v.p_stor; break; case cs_value_type::String: - case cs_value_type::Cstring: - case cs_value_type::Macro: p_type = cs_value_type::String; p_len = v.p_len; new (&p_stor) cs_strref{ @@ -85,15 +77,6 @@ cs_value &cs_value::operator=(cs_value const &v) { return *this; } -cs_value &cs_value::operator=(cs_value &&v) { - csv_cleanup(p_type, p_stor); - p_stor = v.p_stor; - p_type = v.p_type; - p_len = v.p_len; - v.p_type = cs_value_type::Null; - return *this; -} - cs_value_type cs_value::get_type() const { return p_type; } @@ -110,11 +93,9 @@ void cs_value::set_float(cs_float val) { csv_get(p_stor) = val; } -void cs_value::set_str(cs_string val) { +void cs_value::set_str(ostd::string_range val) { csv_cleanup(p_type, p_stor); - new (&p_stor) cs_strref{ - *state(), ostd::string_range{&val[0], &val[val.size()] - }}; + new (&p_stor) cs_strref{*state(), val}; p_type = cs_value_type::String; p_len = val.size(); } @@ -130,26 +111,12 @@ void cs_value::set_code(cs_bcode *val) { csv_get(p_stor) = val; } -void cs_value::set_cstr(ostd::string_range val) { - csv_cleanup(p_type, p_stor); - new (&p_stor) cs_strref{*state(), val}; - p_type = cs_value_type::Cstring; - p_len = val.size(); -} - void cs_value::set_ident(cs_ident *val) { csv_cleanup(p_type, p_stor); p_type = cs_value_type::Ident; csv_get(p_stor) = val; } -void cs_value::set_macro(ostd::string_range val) { - csv_cleanup(p_type, p_stor); - new (&p_stor) cs_strref{*state(), val}; - p_type = cs_value_type::Macro; - p_len = val.size(); -} - void cs_value::force_null() { if (get_type() == cs_value_type::Null) { return; @@ -164,8 +131,6 @@ cs_float cs_value::force_float() { rf = csv_get(p_stor); break; case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: rf = cs_parse_float(ostd::string_range( csv_get(p_stor), csv_get(p_stor) + p_len @@ -187,8 +152,6 @@ cs_int cs_value::force_int() { ri = csv_get(p_stor); break; case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: ri = cs_parse_int(ostd::string_range( csv_get(p_stor), csv_get(p_stor) + p_len @@ -212,13 +175,6 @@ ostd::string_range cs_value::force_str() { case cs_value_type::Int: rs = intstr(csv_get(p_stor)); break; - case cs_value_type::Macro: - case cs_value_type::Cstring: - rs = ostd::string_range( - csv_get(p_stor), - csv_get(p_stor) + p_len - ); - break; case cs_value_type::String: return ostd::string_range( csv_get(p_stor), @@ -241,8 +197,6 @@ cs_int cs_value::get_int() const { case cs_value_type::Int: return csv_get(p_stor); case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: return cs_parse_int(ostd::string_range( csv_get(p_stor), csv_get(p_stor) + p_len @@ -260,8 +214,6 @@ cs_float cs_value::get_float() const { case cs_value_type::Int: return cs_float(csv_get(p_stor)); case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: return cs_parse_float(ostd::string_range( csv_get(p_stor), csv_get(p_stor) + p_len @@ -289,8 +241,6 @@ cs_ident *cs_value::get_ident() const { cs_string cs_value::get_str() const { switch (get_type()) { case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: return cs_string{csv_get(p_stor), p_len}; case cs_value_type::Int: return intstr(csv_get(p_stor)); @@ -305,8 +255,6 @@ cs_string cs_value::get_str() const { ostd::string_range cs_value::get_strr() const { switch (get_type()) { case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: return ostd::string_range( csv_get(p_stor), csv_get(p_stor)+ p_len @@ -320,8 +268,6 @@ ostd::string_range cs_value::get_strr() const { void cs_value::get_val(cs_value &r) const { switch (get_type()) { case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: r = *this; break; case cs_value_type::Int: @@ -376,8 +322,6 @@ bool cs_value::get_bool() const { case cs_value_type::Int: return csv_get(p_stor) != 0; case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: return cs_get_bool(ostd::string_range( csv_get(p_stor), csv_get(p_stor) + p_len diff --git a/src/cs_vm.cc b/src/cs_vm.cc index af39e8f..04f5b9f 100644 --- a/src/cs_vm.cc +++ b/src/cs_vm.cc @@ -252,8 +252,6 @@ static inline uint32_t *forcecode(cs_state &cs, cs_value &v) { static inline void forcecond(cs_state &cs, cs_value &v) { switch (v.get_type()) { case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: if (!v.get_strr().empty()) { forcecode(cs, v); } else { @@ -297,7 +295,6 @@ static uint32_t *skipcode(uint32_t *code) { for (;;) { uint32_t op = *code++; switch (op & 0xFF) { - case CsCodeMacro: case CsCodeVal | CsRetString: { uint32_t len = op >> 8; code += len / sizeof(uint32_t) + 1; @@ -391,23 +388,12 @@ static inline void callcommand( args[i].force_float(); } break; - case 'S': - if (++i >= numargs) { - if (rep) { - break; - } - args[i].set_str(""); - fakeargs++; - } else { - args[i].force_str(); - } - break; case 's': if (++i >= numargs) { if (rep) { break; } - args[i].set_cstr(""); + args[i].set_str(""); fakeargs++; } else { args[i].force_str(); @@ -583,11 +569,7 @@ static inline cs_alias *cs_get_lookuparg_id(cs_state &cs, uint32_t op) { static inline int cs_get_lookupu_type( cs_state &cs, cs_value &arg, cs_ident *&id, uint32_t op ) { - if ( - arg.get_type() != cs_value_type::String && - arg.get_type() != cs_value_type::Macro && - arg.get_type() != cs_value_type::Cstring - ) { + if (arg.get_type() != cs_value_type::String) { return -2; /* default case */ } id = cs.get_ident(arg.get_strr()); @@ -808,16 +790,6 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { } break; - case CsCodeMacro: { - uint32_t len = op >> 8; - args[numargs++].set_macro(ostd::string_range( - reinterpret_cast(code), - reinterpret_cast(code) + len - )); - code += len / sizeof(uint32_t) + 1; - continue; - } - case CsCodeVal | CsRetString: { uint32_t len = op >> 8; args[numargs++].set_str(cs_string{ @@ -944,8 +916,6 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { gs.code.push_back(CsCodeExit); break; case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: gs.code.reserve(64); gs.gen_main(arg.get_strr()); break; @@ -968,9 +938,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { case CsCodeCond: { cs_value &arg = args[numargs - 1]; switch (arg.get_type()) { - case cs_value_type::String: - case cs_value_type::Macro: - case cs_value_type::Cstring: { + case cs_value_type::String: { ostd::string_range s = arg.get_strr(); if (!s.empty()) { cs_gen_state gs(cs); @@ -1014,11 +982,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { case CsCodeIdentU: { cs_value &arg = args[numargs - 1]; cs_ident *id = cs.p_state->identmap[DummyIdx]; - if ( - arg.get_type() == cs_value_type::String || - arg.get_type() == cs_value_type::Macro || - arg.get_type() == cs_value_type::Cstring - ) { + if (arg.get_type() == cs_value_type::String) { id = cs.new_ident(arg.get_strr()); } if ((id->get_index() < MaxArguments) && !cs_is_arg_used(cs, id)) { @@ -1214,7 +1178,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { static_cast(id)->get_cstr(arg); continue; case CsIdSvar: - arg.set_cstr(static_cast(id)->get_value()); + arg.set_str(static_cast(id)->get_value()); continue; case CsIdIvar: arg.set_str( @@ -1227,7 +1191,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { ); continue; case CsIdUnknown: - arg.set_cstr(""); + arg.set_str(""); continue; default: continue; @@ -1239,7 +1203,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { case CsCodeLookupMarg | CsRetString: { cs_alias *a = cs_get_lookuparg_id(cs, op); if (!a) { - args[numargs++].set_cstr(""); + args[numargs++].set_str(""); } else { a->get_cstr(args[numargs++]); } @@ -1253,7 +1217,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { static_cast(id)->get_cval(arg); continue; case CsIdSvar: - arg.set_cstr(static_cast(id)->get_value()); + arg.set_str(static_cast(id)->get_value()); continue; case CsIdIvar: arg.set_int(static_cast(id)->get_value()); @@ -1297,11 +1261,6 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { cs.p_state->identmap[op >> 8] )->get_value())); continue; - case CsCodeSvarM: - args[numargs++].set_cstr(static_cast( - cs.p_state->identmap[op >> 8] - )->get_value()); - continue; case CsCodeSvar1: cs.set_var_str_checked( static_cast(cs.p_state->identmap[op >> 8]), @@ -1528,11 +1487,7 @@ static uint32_t *runcode(cs_state &cs, uint32_t *code, cs_value &result) { case CsCodeCallU | CsRetInt: { int callargs = op >> 8, offset = numargs - callargs; cs_value &idarg = args[offset - 1]; - if ( - idarg.get_type() != cs_value_type::String && - idarg.get_type() != cs_value_type::Macro && - idarg.get_type() != cs_value_type::Cstring - ) { + if (idarg.get_type() != cs_value_type::String) { litval: result = std::move(idarg); force_arg(result, op & CsCodeRetMask); diff --git a/src/cs_vm.hh b/src/cs_vm.hh index 506152a..73af673 100644 --- a/src/cs_vm.hh +++ b/src/cs_vm.hh @@ -55,13 +55,11 @@ struct cs_valarray { enum { CsValNull = 0, CsValInt, CsValFloat, CsValString, - CsValAny, CsValCode, CsValMacro, CsValIdent, CsValCstring, - CsValCany, CsValWord, CsValPop, CsValCond + CsValAny, CsValCode, CsValIdent, CsValWord, CsValPop, CsValCond }; static const int cs_valtypet[] = { - CsValNull, CsValInt, CsValFloat, CsValString, - CsValCstring, CsValCode, CsValMacro, CsValIdent + CsValNull, CsValInt, CsValFloat, CsValString, CsValCode, CsValIdent }; static inline int cs_vtype_to_int(cs_value_type v) { @@ -78,7 +76,6 @@ enum { CsCodeExit, CsCodeResultArg, CsCodeVal, CsCodeValInt, CsCodeDup, - CsCodeMacro, CsCodeBool, CsCodeBlock, CsCodeEmpty, CsCodeCompile, CsCodeCond, @@ -87,7 +84,7 @@ enum { CsCodeIdent, CsCodeIdentU, CsCodeIdentArg, CsCodeCom, CsCodeComC, CsCodeComV, CsCodeConc, CsCodeConcW, CsCodeConcM, - CsCodeSvar, CsCodeSvarM, CsCodeSvar1, + CsCodeSvar, CsCodeSvar1, CsCodeIvar, CsCodeIvar1, CsCodeIvar2, CsCodeIvar3, CsCodeFvar, CsCodeFvar1, CsCodeLookup, CsCodeLookupU, CsCodeLookupArg, @@ -199,8 +196,8 @@ struct cs_gen_state { ostd::string_range get_word(); - void gen_str(ostd::string_range word, bool macro = false) { - if (word.size() <= 3 && !macro) { + void gen_str(ostd::string_range word) { + if (word.size() <= 3) { uint32_t op = CsCodeValInt | CsRetString; for (size_t i = 0; i < word.size(); ++i) { op |= uint32_t( @@ -210,9 +207,7 @@ struct cs_gen_state { code.push_back(op); return; } - code.push_back( - (macro ? CsCodeMacro : (CsCodeVal | CsRetString)) | (word.size() << 8) - ); + code.push_back(CsCodeVal | CsRetString | (word.size() << 8)); auto it = reinterpret_cast(word.data()); code.insert( code.end(), it, it + (word.size() / sizeof(uint32_t)) diff --git a/src/cubescript.cc b/src/cubescript.cc index a631404..e3fd748 100644 --- a/src/cubescript.cc +++ b/src/cubescript.cc @@ -352,7 +352,7 @@ cs_state::cs_state(cs_alloc_cb func, void *data): cs.run((args[0].get_bool() ? args[1] : args[2]).get_code(), res); })->p_type = CsIdIf; - new_command("result", "T", [](auto &, auto args, auto &res) { + new_command("result", "t", [](auto &, auto args, auto &res) { res = std::move(args[0]); })->p_type = CsIdResult; @@ -532,8 +532,6 @@ OSTD_EXPORT cs_ident *cs_state::force_ident(cs_value &v) { switch (v.get_type()) { case cs_value_type::Ident: return v.get_ident(); - case cs_value_type::Macro: - case cs_value_type::Cstring: case cs_value_type::String: { cs_ident *id = new_ident(v.get_strr()); v.set_ident(id); @@ -663,12 +661,8 @@ OSTD_EXPORT void cs_state::print_var(cs_var *v) { void cs_alias::get_cstr(cs_value &v) const { switch (p_val.get_type()) { - case cs_value_type::Macro: - v.set_macro(p_val.get_strr()); - break; case cs_value_type::String: - case cs_value_type::Cstring: - v.set_cstr(p_val.get_strr()); + v = p_val; break; case cs_value_type::Int: v.set_str(intstr(p_val.get_int())); @@ -677,19 +671,15 @@ void cs_alias::get_cstr(cs_value &v) const { v.set_str(floatstr(p_val.get_float())); break; default: - v.set_cstr(""); + v.set_str(""); break; } } void cs_alias::get_cval(cs_value &v) const { switch (p_val.get_type()) { - case cs_value_type::Macro: - v.set_macro(p_val.get_strr()); - break; case cs_value_type::String: - case cs_value_type::Cstring: - v.set_cstr(p_val.get_strr()); + v = p_val; break; case cs_value_type::Int: v.set_int(p_val.get_int()); @@ -989,7 +979,6 @@ OSTD_EXPORT cs_command *cs_state::new_command( case 'T': case 'E': case 'N': - case 'S': case 's': case 'e': case 'r': @@ -1112,11 +1101,11 @@ void cs_init_lib_base(cs_state &gcs) { cs_alias_internal::set_alias(css, cs, tback); }); - gcs.new_command("?", "tTT", [](auto &, auto args, auto &res) { + gcs.new_command("?", "ttt", [](auto &, auto args, auto &res) { if (args[0].get_bool()) { - res = std::move(args[1]); + res = args[1]; } else { - res = std::move(args[2]); + res = args[2]; } }); @@ -1173,13 +1162,13 @@ void cs_init_lib_base(cs_state &gcs) { } }); - gcs.new_command("pushif", "rTe", [](auto &cs, auto args, auto &res) { + gcs.new_command("pushif", "rte", [](auto &cs, auto args, auto &res) { cs_stacked_value idv{cs, args[0].get_ident()}; if (!idv.has_alias() || (idv.get_alias()->get_index() < MaxArguments)) { return; } if (args[1].get_bool()) { - idv = std::move(args[1]); + idv = args[1]; idv.push(); cs.run(args[2].get_code(), res); } @@ -1317,12 +1306,12 @@ end: ); }); - gcs.new_command("push", "rTe", [](auto &cs, auto args, auto &res) { + gcs.new_command("push", "rte", [](auto &cs, auto args, auto &res) { cs_stacked_value idv{cs, args[0].get_ident()}; if (!idv.has_alias() || (idv.get_alias()->get_index() < MaxArguments)) { return; } - idv = std::move(args[1]); + idv = args[1]; idv.push(); cs.run(args[2].get_code(), res); }); @@ -1331,8 +1320,8 @@ end: cs.reset_var(args[0].get_strr()); }); - gcs.new_command("alias", "sT", [](auto &cs, auto args, auto &) { - cs.set_alias(args[0].get_strr(), std::move(args[1])); + gcs.new_command("alias", "st", [](auto &cs, auto args, auto &) { + cs.set_alias(args[0].get_strr(), args[1]); }); gcs.new_command("getvarmin", "s", [](auto &cs, auto args, auto &res) { diff --git a/src/lib_list.cc b/src/lib_list.cc index c383e16..27e8792 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -524,8 +524,8 @@ struct ListSortFun { cs_bcode *body; bool operator()(ListSortItem const &xval, ListSortItem const &yval) { - xv.set_cstr(xval.str); - yv.set_cstr(yval.str); + xv.set_str(xval.str); + yv.set_str(yval.str); xv.push(); yv.push(); return cs.run_bool(body);