Fix memory errors wrt stashed function names
This commit is contained in:
@ -31,7 +31,11 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
||||
if( C::debug ) std::cerr << "After processing stack is now: " << std::endl;
|
||||
if( C::debug ) for( const auto &element: stack )
|
||||
{
|
||||
std::cerr << std::get< std::string >( element ) << std::endl;
|
||||
std::visit
|
||||
(
|
||||
[&]( const auto &thing ) { std::cerr << thing << std::endl; },
|
||||
element
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,6 +60,21 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
||||
{
|
||||
if( C::debug ) std::cerr << "Processing token: " << word << std::endl;
|
||||
if( C::debug ) std::cerr << "Conditional depth is: " << conditionals.size() << std::endl;
|
||||
if( C::debug )
|
||||
{
|
||||
std::cerr << "The following cached named functions exist: " << std::endl;
|
||||
for( const auto &name: wordNames )
|
||||
{
|
||||
std::cerr << name << std::endl;
|
||||
}
|
||||
|
||||
std::cerr << "The following named functions exist: " << std::endl;
|
||||
for( const auto &[ name, _ ]: words )
|
||||
{
|
||||
std::cerr << name << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
const bool inConditional= not conditionals.empty();
|
||||
|
||||
if( false );
|
||||
@ -177,13 +196,15 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
||||
{
|
||||
if( definition.has_value() ) throw std::runtime_error{ "Nested definitions not supported." };
|
||||
|
||||
definition= pop< std::string >();
|
||||
wordNames.push_back( pop< std::string >() );
|
||||
definition= wordNames.back();
|
||||
words[ wordNames.back() ]= {};
|
||||
|
||||
if( C::debug ) std::cerr << "Starting function definition for " << definition.value() << std::endl;
|
||||
}
|
||||
else if( word.at( 0 ) == '@' )
|
||||
{
|
||||
const std::string invoke{ word.substr( 1 ) };
|
||||
const auto invoke= word.substr( 1 );
|
||||
if( not words.contains( invoke ) )
|
||||
{
|
||||
throw std::runtime_error{ "Unknown keyword: `"s + std::string{ word }
|
||||
@ -192,10 +213,6 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
||||
|
||||
const auto &def= words.at( invoke );
|
||||
|
||||
//std::copy( rbegin( def ), rend( def ), front_inserter( tokens ) );
|
||||
|
||||
//if( tokens.size() >= 1000 ) abort();
|
||||
|
||||
tokenStack.emplace_back( def );
|
||||
}
|
||||
else
|
||||
@ -216,7 +233,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
||||
std::variant< std::string, StackMachine::Integer >
|
||||
StackMachine::pop()
|
||||
{
|
||||
const auto rv= peek();
|
||||
const auto rv= std::move( peek() );
|
||||
stack.pop_back();
|
||||
return rv;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user