polserver/pol-core/bscript/continueimp.cpp
Kevin Eady 93645f0770
Add variable arguments to user functions (#679)
* Update grammar

* Update parser and AST generator

* Update semantic analysis

* Executor implementation
- Move Executor stack modification logic to BFunctionRef
- Handle user function calls
- Handle expression function calls

* Tests

* Update existing listfile snapshots
- Adds variadic boolean to instruction stack
- Changes instruction counts and offsets

* Fix test issue

* Better implementation of calling user functions

* Add var-args-captures test

* Refactor continuation handling + handle variadic args
- Move stack modifications from make/withContinuation into the executor's handling of the continuation
- Only trim args in continuation call if function is not variadic

* Add var-args-continuation test (via array.filter)

* update escriptguide + formatting, docs

* Fix CI annotations
- '=': conversion from 'size_t' to 'unsigned int', possible loss of data
- declaration of 'continuation' hides previous local declaration
2024-08-04 17:13:30 +02:00

48 lines
1 KiB
C++

#include "continueimp.h"
#include "executor.h"
namespace Pol
{
namespace Bscript
{
BContinuation::BContinuation( BObjectRef funcref, BObjectRefVec args,
ContinuationCallbackWrapper wrapper, void* wrapperData )
: BObjectImp( BObjectImp::OTContinuation ),
funcref_( std::move( funcref ) ),
wrapper_( wrapper ),
wrapperData_( wrapperData ),
args( std::move( args ) )
{
}
BContinuation::~BContinuation()
{
wrapper_.free( wrapperData_ );
}
BObjectImp* BContinuation::continueWith( Executor& exec, BObjectRef result )
{
return wrapper_.call( exec, this, wrapperData_, std::move( result ) );
}
BFunctionRef* BContinuation::func()
{
return funcref_->impptr<BFunctionRef>();
}
BObjectImp* BContinuation::copy( void ) const
{
return nullptr;
}
size_t BContinuation::sizeEstimate() const
{
return sizeof( BContinuation ) + wrapper_.size();
}
std::string BContinuation::getStringRep() const
{
return "<continuation>";
}
} // namespace Bscript
} // namespace Pol