diff --git a/js4g/StackMachine.cc b/js4g/StackMachine.cc index 8a36414..14ae3c5 100644 --- a/js4g/StackMachine.cc +++ b/js4g/StackMachine.cc @@ -7,6 +7,7 @@ static_assert( __cplusplus >= 2023'02 ); namespace { using namespace std::literals::string_literals; + using namespace std::literals::string_view_literals; namespace C { @@ -79,7 +80,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m if( false ); else if( word.empty() ); - else if( word == "}" ) + else if( word == "}"sv ) { if( not definition.has_value() ) { @@ -96,11 +97,11 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m if( C::debug ) std::cerr << "Adding word: " << word << " to function definition: " << definition.value() << std::endl; words[ definition.value() ].emplace_back( word ); } - else if( inConditional and word == "@else" and currentState != Else ) + else if( inConditional and word == "@else"sv and currentState != Else ) { currentState= Else; } - else if( inConditional and word == "@endif" ) + else if( inConditional and word == "@endif"sv ) { conditionals.pop_back(); currentState= resumeConditionals.back(); @@ -108,7 +109,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m } else if( inConditional and currentState != conditionals.back() ) { - if( word == "@if" ) + if( word == "@if"sv ) { conditionals.push_back( Skipped ); resumeConditionals.push_back( currentState ); @@ -116,83 +117,83 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m } else ; // We skip the statement. } - else if( word == "@else" ) + else if( word == "@else"sv ) { throw std::runtime_error{ "Syntax error: unexpected `@else`" }; } - else if( word == "@endif" ) + else if( word == "@endif"sv ) { throw std::runtime_error{ "Syntax error: unexpected `@endif`" }; } - else if( word == "@dup" ) + else if( word == "@dup"sv ) { auto val= peek(); push( std::move( val ) ); } - else if( word == "@swap" ) + else if( word == "@swap"sv ) { auto a= pop(); auto b= pop(); push( std::move( a ) ); push( std::move( b ) ); } - else if( word == "@drop" ) + else if( word == "@drop"sv ) { std::ignore= pop(); } - else if( word == "@not" ) + else if( word == "@not"sv ) { auto val= pop< Integer >(); push( val == 0 ? 1 : 0 ); } - else if( word == "@i_inc" ) + else if( word == "@i_inc"sv ) { push( pop< Integer >() + 1 ); } - else if( word == "@i_dec" ) + else if( word == "@i_dec"sv ) { push( pop< Integer >() - 1 ); } - else if( word == "@i_add" ) + else if( word == "@i_add"sv ) { const auto lhs= pop< Integer >(); const auto rhs= pop< Integer >(); push( lhs + rhs ); } - else if( word == "@i_sub" ) + else if( word == "@i_sub"sv ) { const auto lhs= pop< Integer >(); const auto rhs= pop< Integer >(); push( lhs - rhs ); } - else if( word == "@i_mul" ) + else if( word == "@i_mul"sv ) { const auto lhs= pop< Integer >(); const auto rhs= pop< Integer >(); push( lhs * rhs ); } - else if( word == "@i_div" ) + else if( word == "@i_div"sv ) { const auto lhs= pop< Integer >(); const auto rhs= pop< Integer >(); push( lhs / rhs ); } - else if( word == "@print" ) + else if( word == "@print"sv ) { output << pop< std::string >() << std::endl; } - else if( word == "@if" ) + else if( word == "@if"sv ) { const auto val= pop< Integer >(); conditionals.push_back( val ? If : Else ); resumeConditionals.push_back( currentState ); currentState= If; } - else if( word == "{" ) + else if( word == "{"sv ) { if( definition.has_value() ) throw std::runtime_error{ "Nested definitions not supported." }; @@ -238,7 +239,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m return rv; } - const std::variant< std::string, StackMachine::Integer > & + std::variant< std::string, StackMachine::Integer > & StackMachine::peek() { if( stack.empty() ) throw std::runtime_error{ "FATAL: No more elements in stack." };