Start getting ready for relocations.
This commit is contained in:
@ -27,7 +27,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
{
|
{
|
||||||
while( not tokenStack.empty() and tokenStack.back().hasNext() )
|
while( not tokenStack.empty() and tokenStack.back().hasNext() )
|
||||||
{
|
{
|
||||||
runWord( next() );
|
runWord( std::get< std::string_view >( next() ) );
|
||||||
|
|
||||||
if( C::debug ) std::cerr << "After processing stack is now: " << std::endl;
|
if( C::debug ) std::cerr << "After processing stack is now: " << std::endl;
|
||||||
if( C::debug ) for( const auto &element: stack )
|
if( C::debug ) for( const auto &element: stack )
|
||||||
@ -43,7 +43,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
if( C::debug ) std::cerr << "Run done with stack at size: " << stack.size() << std::endl;
|
if( C::debug ) std::cerr << "Run done with stack at size: " << stack.size() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view
|
StackMachine::Token
|
||||||
StackMachine::next()
|
StackMachine::next()
|
||||||
{
|
{
|
||||||
if( tokenStack.empty() )
|
if( tokenStack.empty() )
|
||||||
@ -88,8 +88,8 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( C::debug ) std::cerr << "Definition of " << definition.value() << " is done. It is: " << std::endl;
|
if( C::debug ) std::cerr << "Definition of " << definition.value() << " is done. It is: " << std::endl;
|
||||||
if( C::debug ) std::copy( begin( words.at( definition.value() ) ), end( words.at( definition.value() ) ),
|
//if( C::debug ) std::copy( begin( words.at( definition.value() ) ), end( words.at( definition.value() ) ),
|
||||||
std::ostream_iterator< std::string >{ std::cout, "\n" } );
|
//std::ostream_iterator< std::string >{ std::cout, "\n" } );
|
||||||
definition= std::nullopt;
|
definition= std::nullopt;
|
||||||
}
|
}
|
||||||
else if( definition.has_value() )
|
else if( definition.has_value() )
|
||||||
@ -203,6 +203,8 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
|
|
||||||
if( C::debug ) std::cerr << "Starting function definition for " << definition.value() << std::endl;
|
if( C::debug ) std::cerr << "Starting function definition for " << definition.value() << std::endl;
|
||||||
}
|
}
|
||||||
|
else if( word == "0"sv ) push( 0 );
|
||||||
|
else if( word == "1"sv ) push( 1 );
|
||||||
else if( word.at( 0 ) == '@' )
|
else if( word.at( 0 ) == '@' )
|
||||||
{
|
{
|
||||||
const auto invoke= word.substr( 1 );
|
const auto invoke= word.substr( 1 );
|
||||||
|
|||||||
@ -50,10 +50,11 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
|
|
||||||
// It's `void *` to break the cycle with itself
|
// It's `void *` to break the cycle with itself
|
||||||
struct TokenHolder;
|
struct TokenHolder;
|
||||||
//using Token= std::variant< std::string, TokenHolder * >;
|
using Token= std::variant< std::string_view, TokenHolder *>;
|
||||||
using Token= std::string;
|
|
||||||
|
|
||||||
std::vector< std::string > tokens;
|
std::vector< std::string > backing;
|
||||||
|
|
||||||
|
std::vector< Token > tokens;
|
||||||
|
|
||||||
struct Tokenizer
|
struct Tokenizer
|
||||||
{
|
{
|
||||||
@ -66,14 +67,14 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
|
|
||||||
bool hasNext() const { return pos != end; }
|
bool hasNext() const { return pos != end; }
|
||||||
|
|
||||||
std::string_view next() { return *pos++; }
|
Token next() { return *pos++; }
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector< Tokenizer > tokenStack;
|
std::vector< Tokenizer > tokenStack;
|
||||||
|
|
||||||
|
|
||||||
std::list< std::string > wordNames;
|
std::list< std::string > wordNames;
|
||||||
std::unordered_map< std::string_view, std::vector< std::string > > words;
|
std::unordered_map< std::string_view, std::vector< Token > > words;
|
||||||
|
|
||||||
// Which side of the current conditional to take.
|
// Which side of the current conditional to take.
|
||||||
enum ConditionalState { If, Else, Skipped };
|
enum ConditionalState { If, Else, Skipped };
|
||||||
@ -104,7 +105,7 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
void push( const T &t );
|
void push( const T &t );
|
||||||
|
|
||||||
|
|
||||||
std::string_view next();
|
Token next();
|
||||||
|
|
||||||
void recurse( std::string_view func );
|
void recurse( std::string_view func );
|
||||||
|
|
||||||
@ -114,7 +115,9 @@ namespace Dillo::Hydrogen::JavaScriptForge ::detail:: StackMachine_m
|
|||||||
void
|
void
|
||||||
loadProgram( std::vector< std::string > tokens )
|
loadProgram( std::vector< std::string > tokens )
|
||||||
{
|
{
|
||||||
this->tokens= std::move( tokens );
|
backing= std::move( tokens );
|
||||||
|
this->tokens.clear();
|
||||||
|
std::copy( begin( backing ), end( backing ), back_inserter( this->tokens ) );
|
||||||
tokenStack.clear();
|
tokenStack.clear();
|
||||||
tokenStack.emplace_back( this->tokens );
|
tokenStack.emplace_back( this->tokens );
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user