mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Introduce FunctionReferenceRegistrar - Track function references created by functors - Remove ValueStack-held attributes for functors - Add Function References section to escript program - Use Function References section in ins_functor - Update escript version * Update listfile snapshots - Remove ValueStack-held attributes created by functors * Add function reference tracking to function references - `emit.function_reference` uses funcref registrar + emits that index - `ins_funcref` uses parameter count + is variadic from prog funcref table - update listfile snapshots * Add core-changes
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
#include "FunctionReferenceRegistrar.h"
|
|
|
|
#include "bscript/compiler/ast/FunctionReference.h"
|
|
#include "bscript/compiler/ast/UserFunction.h"
|
|
#include "bscript/compiler/model/FunctionLink.h"
|
|
#include "bscript/compiler/representation/FunctionReferenceDescriptor.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
FunctionReferenceRegistrar::FunctionReferenceRegistrar() = default;
|
|
|
|
void FunctionReferenceRegistrar::register_function_reference( const UserFunction& node )
|
|
{
|
|
auto& function_name = node.name;
|
|
auto reference_itr = registered_references.find( function_name );
|
|
if ( reference_itr == registered_references.end() )
|
|
{
|
|
auto reference_index = static_cast<unsigned>( registered_references.size() );
|
|
|
|
registered_references[function_name] =
|
|
std::make_unique<EmittedReference>( reference_index, node );
|
|
reference_names_in_order.push_back( function_name );
|
|
}
|
|
}
|
|
|
|
std::vector<FunctionReferenceDescriptor> FunctionReferenceRegistrar::take_descriptors()
|
|
{
|
|
std::vector<FunctionReferenceDescriptor> descriptors;
|
|
|
|
for ( const auto& k : reference_names_in_order )
|
|
{
|
|
const auto& v = registered_references[k];
|
|
descriptors.emplace_back( v->user_function.parameter_count(), v->user_function.capture_count(),
|
|
v->user_function.is_variadic() );
|
|
}
|
|
|
|
registered_references.clear();
|
|
reference_names_in_order.clear();
|
|
|
|
return descriptors;
|
|
}
|
|
|
|
void FunctionReferenceRegistrar::lookup_or_register_reference( const UserFunction& node,
|
|
unsigned& reference_index )
|
|
{
|
|
auto& function_name = node.name;
|
|
|
|
auto reference_itr = registered_references.find( function_name );
|
|
if ( reference_itr != registered_references.end() )
|
|
{
|
|
reference_index = ( *reference_itr ).second->index;
|
|
return;
|
|
}
|
|
|
|
register_function_reference( node );
|
|
|
|
reference_index = registered_references[function_name]->index;
|
|
}
|
|
|
|
FunctionReferenceRegistrar::EmittedReference::EmittedReference( unsigned index,
|
|
const UserFunction& user_function )
|
|
: index( index ), user_function( user_function )
|
|
{
|
|
}
|
|
|
|
FunctionReferenceRegistrar::EmittedReference::~EmittedReference() = default;
|
|
|
|
} // namespace Pol::Bscript::Compiler
|