2017-10-14 12:00:47 +02:00
|
|
|
#include "externals.hh"
|
|
|
|
#include "control.hh"
|
2017-10-30 18:29:52 +01:00
|
|
|
#include "globals.hh"
|
2017-10-14 12:00:47 +02:00
|
|
|
#include "sync.hh"
|
|
|
|
|
|
|
|
using namespace cops;
|
|
|
|
|
|
|
|
|
2017-10-14 21:10:46 +02:00
|
|
|
/*= Command execution ========================================================*/
|
|
|
|
|
|
|
|
void cops::Execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Operations const& operations ,
|
|
|
|
T_Context& context )
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
for ( auto const& op : operations ) {
|
|
|
|
op->execute( context );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-15 10:22:24 +02:00
|
|
|
T_Operations& T_Program::function(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& name ,
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t args )
|
2017-10-15 10:22:24 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
T_Function* op( functions.get( name ) );
|
|
|
|
if ( !op ) {
|
|
|
|
functions.add( T_Function{ name , args } );
|
|
|
|
op = functions.get( name );
|
2017-10-15 10:22:24 +02:00
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
assert( op->arguments == args );
|
|
|
|
return op->operations;
|
2017-10-15 10:22:24 +02:00
|
|
|
}
|
|
|
|
|
2017-10-14 21:10:46 +02:00
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
/*= X_OpFailure ==============================================================*/
|
|
|
|
|
|
|
|
X_OpFailure::X_OpFailure(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& source ,
|
2017-11-03 09:08:19 +01:00
|
|
|
uint32_t line ,
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String&& error ) noexcept
|
2017-10-14 12:00:47 +02:00
|
|
|
: std::exception( ) , source_( source ) , line_( line ) ,
|
2017-11-03 11:55:26 +01:00
|
|
|
error_( std::move( error ) )
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb;
|
|
|
|
sb << "Program error (" << source << ", l. " << line << "): " << error
|
|
|
|
<< '\0';
|
|
|
|
fullMessage_ = std::move( sb );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char const* X_OpFailure::what( ) const noexcept
|
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
return fullMessage_.data( );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-15 09:34:03 +02:00
|
|
|
/*= T_Context ================================================================*/
|
|
|
|
|
|
|
|
T_Context& T_Context::store(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& name ,
|
2017-11-03 09:08:19 +01:00
|
|
|
const float value )
|
2017-10-15 09:34:03 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
vars.set( name , value );
|
2017-10-15 09:34:03 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
/*= T_Op =====================================================================*/
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Op::T_Op( const E_Op op )
|
2017-10-14 12:00:47 +02:00
|
|
|
: op_( op )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
T_Op::~T_Op( ) { }
|
|
|
|
|
|
|
|
|
|
|
|
X_OpFailure T_Op::error(
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder& message ) const noexcept
|
|
|
|
{
|
|
|
|
return X_OpFailure( source , line , std::move( message ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
X_OpFailure T_Op::error(
|
|
|
|
T_String const& message ) const noexcept
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
return X_OpFailure( source , line , T_String( message ) );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPLoadConstant ===========================================================*/
|
|
|
|
|
|
|
|
OPLoadConstant::OPLoadConstant(
|
2017-11-03 09:08:19 +01:00
|
|
|
const float constant )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_LOAD_CONSTANT ) , constant( constant )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPLoadConstant::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.add( constant );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPLoadVariable ===========================================================*/
|
|
|
|
|
|
|
|
OPLoadVariable::OPLoadVariable(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& variable )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_LOAD_VARIABLE ) , variable( variable )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPLoadVariable::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
auto const* v( ctx.vars.get( variable ) );
|
|
|
|
if ( !v ) {
|
|
|
|
ebcl::T_StringBuilder sb;
|
|
|
|
sb << "variable '" << variable << "' not found" << '\0';
|
|
|
|
throw error( sb );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.add( *v );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPLoadInput ==============================================================*/
|
|
|
|
|
|
|
|
OPLoadInput::OPLoadInput(
|
2017-11-03 09:08:19 +01:00
|
|
|
std::string const& input )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_LOAD_VARIABLE ) , input( input )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPLoadInput::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 09:08:19 +01:00
|
|
|
const auto i( Globals::Sync( ).inputPos( input.c_str( ) ) );
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.add( Globals::Sync( ).inputs( )[ i ] );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPStoreVariable ==========================================================*/
|
|
|
|
|
|
|
|
OPStoreVariable::OPStoreVariable(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& variable )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_LOAD_VARIABLE ) , variable( variable )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPStoreVariable::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.empty( ) ) {
|
|
|
|
throw error( "stack is empty" );
|
|
|
|
}
|
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.store( variable , ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= Arithmetic operators =====================================================*/
|
|
|
|
|
|
|
|
void OPAdd::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) < 2 ) {
|
|
|
|
throw error( "missing operands in stack" );
|
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
const float v( ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
|
|
|
ctx.opStack.last( ) += v;
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OPMul::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) < 2 ) {
|
|
|
|
throw error( "missing operands in stack" );
|
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
const float v( ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
|
|
|
ctx.opStack.last( ) *= v;
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OPNeg::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.empty( ) ) {
|
|
|
|
throw error( "missing operand in stack" );
|
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.last( ) = -ctx.opStack.last( );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OPInv::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
if ( ctx.opStack.empty( ) || ctx.opStack.last( ) == 0 ) {
|
2017-10-14 12:00:47 +02:00
|
|
|
throw error( "missing operand in stack" );
|
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.last( ) = 1.0f / ctx.opStack.last( );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= Stack operations =========================================================*/
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
OPDup::OPDup( const uint32_t stackIndex )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_DUP ) , stackIndex( stackIndex )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPDup::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) <= stackIndex ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb;
|
|
|
|
sb << "stack does not have " << ( stackIndex + 1 )
|
2017-10-15 10:22:24 +02:00
|
|
|
<< " items (only " << ctx.opStack.size( ) << ")";
|
2017-11-03 11:55:26 +01:00
|
|
|
throw error( sb );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
2017-11-03 11:55:26 +01:00
|
|
|
ctx.opStack.add( *( ctx.opStack.end( ) - stackIndex - 1 ) );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
2017-11-03 09:08:19 +01:00
|
|
|
OPXchg::OPXchg( const uint32_t stackIndex )
|
2017-10-14 12:00:47 +02:00
|
|
|
: T_Op( OP_XCHG ) , stackIndex( stackIndex )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPXchg::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) <= stackIndex ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb( "stack does not have " );
|
|
|
|
sb << ( stackIndex + 1 ) << " items";
|
|
|
|
throw error( sb );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
if ( stackIndex ) {
|
|
|
|
std::swap( *( ctx.opStack.end( ) - 1 ) , *( ctx.opStack.end( ) - stackIndex - 1 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPSetUniform =============================================================*/
|
|
|
|
|
2017-10-14 21:10:46 +02:00
|
|
|
// GENERAL FIXME
|
|
|
|
// program identifier should be an entry in a table
|
|
|
|
// or, you know, a program name
|
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
OPSetUniform::OPSetUniform(
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t count ,
|
|
|
|
const bool integer )
|
2017-10-15 10:22:24 +02:00
|
|
|
: T_Op( OP_SET_UNIFORM ) , count( count ) , integer( integer )
|
2017-10-14 12:00:47 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPSetUniform::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 12:00:47 +02:00
|
|
|
{
|
2017-10-15 10:22:24 +02:00
|
|
|
if ( count == 0 || ctx.opStack.size( ) < count + 2 ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb( "stack does not have " );
|
|
|
|
sb << ( count + 2 ) << " items";
|
|
|
|
throw error( sb );
|
2017-10-14 12:00:47 +02:00
|
|
|
}
|
|
|
|
|
2017-10-15 09:34:03 +02:00
|
|
|
typedef void (*F_SetUniform_)( int , int , int , void* );
|
|
|
|
void const* const funcs[] = {
|
2017-10-14 12:00:47 +02:00
|
|
|
&glProgramUniform1fv , &glProgramUniform2fv , &glProgramUniform3fv , &glProgramUniform4fv ,
|
|
|
|
&glProgramUniform1iv , &glProgramUniform2iv , &glProgramUniform3iv , &glProgramUniform4iv ,
|
|
|
|
};
|
2017-10-15 09:34:03 +02:00
|
|
|
const F_SetUniform_ func{ *(F_SetUniform_*) funcs[ count + ( integer ? 4 : 0 ) - 1 ] };
|
2017-10-14 12:00:47 +02:00
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
const GLuint program( ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
|
|
|
const GLuint uniform( ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
2017-10-15 10:22:24 +02:00
|
|
|
|
2017-10-14 12:00:47 +02:00
|
|
|
if ( integer ) {
|
|
|
|
int values[ count ];
|
|
|
|
auto i = count;
|
|
|
|
while ( i != 0 ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
values[ count - i ] = int( ctx.opStack.last( ) );
|
|
|
|
ctx.opStack.removeLast( );
|
2017-10-14 12:00:47 +02:00
|
|
|
i --;
|
|
|
|
}
|
|
|
|
func( program , uniform , 1 , values );
|
|
|
|
} else {
|
|
|
|
float values[ count ];
|
|
|
|
auto i = count;
|
|
|
|
while ( i != 0 ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
values[ count - i ] = ctx.opStack.last( );
|
|
|
|
ctx.opStack.removeLast( );
|
2017-10-14 12:00:47 +02:00
|
|
|
i --;
|
|
|
|
}
|
|
|
|
func( program , uniform , 1 , values );
|
|
|
|
}
|
|
|
|
}
|
2017-10-14 21:10:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*= OPUsePipeline ============================================================*/
|
|
|
|
|
|
|
|
// GENERAL FIXME
|
|
|
|
// pipeline identifier should be an entry in a table
|
|
|
|
// or, you know, a program name
|
|
|
|
|
|
|
|
OPUsePipeline::OPUsePipeline(
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t index )
|
2017-10-14 21:10:46 +02:00
|
|
|
: T_Op( OP_USE_PIPELINE ) , pipeline( index )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPUsePipeline::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
glBindProgramPipeline( pipeline );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPUseTexture =============================================================*/
|
|
|
|
|
|
|
|
// GENERAL FIXME
|
|
|
|
// texture & sampler identifiers should be entries in a table
|
|
|
|
|
|
|
|
OPUseTexture::OPUseTexture(
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t binding ,
|
|
|
|
const uint32_t texture ,
|
|
|
|
const uint32_t sampler )
|
2017-10-14 21:10:46 +02:00
|
|
|
: T_Op( OP_USE_TEXTURE ) , binding( binding ) ,
|
|
|
|
texture( texture ) , sampler( sampler )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPUseTexture::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
glBindTextureUnit( binding , texture );
|
|
|
|
glBindSampler( binding , sampler );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPUseFramebuffer =========================================================*/
|
|
|
|
|
|
|
|
// GENERAL FIXME
|
|
|
|
// framebuffer identifier should be an entry in a table
|
|
|
|
|
|
|
|
OPUseFramebuffer::OPUseFramebuffer(
|
2017-11-03 09:08:19 +01:00
|
|
|
const uint32_t framebuffer )
|
2017-10-14 21:10:46 +02:00
|
|
|
: T_Op( OP_USE_FRAMEBUFFER ) , framebuffer( framebuffer )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPUseFramebuffer::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
glBindFramebuffer( GL_FRAMEBUFFER , framebuffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= OPSetViewport ============================================================*/
|
|
|
|
|
|
|
|
void OPSetViewport::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) < 4 ) {
|
|
|
|
throw error( "stack does not have 4 items" );
|
|
|
|
}
|
|
|
|
glViewport(
|
|
|
|
*( ctx.opStack.end( ) - 1 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 2 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 3 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 4 ) );
|
|
|
|
ctx.opStack.resize( ctx.opStack.size( ) - 4 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*= Draw commands ============================================================*/
|
|
|
|
|
|
|
|
void OPClear::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
if ( ctx.opStack.size( ) < 4 ) {
|
|
|
|
throw error( "stack does not have 4 items" );
|
|
|
|
}
|
|
|
|
glClearColor(
|
|
|
|
*( ctx.opStack.end( ) - 1 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 2 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 3 ) ,
|
|
|
|
*( ctx.opStack.end( ) - 4 ) );
|
|
|
|
ctx.opStack.resize( ctx.opStack.size( ) - 4 );
|
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
|
|
}
|
|
|
|
|
|
|
|
void OPFullscreen::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ) const
|
2017-10-14 21:10:46 +02:00
|
|
|
{
|
|
|
|
glBindVertexArray( 0 );
|
|
|
|
glDrawArrays( GL_TRIANGLE_STRIP , 0 , 4 );
|
|
|
|
}
|
2017-10-15 10:22:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*= Flow control =============================================================*/
|
|
|
|
|
|
|
|
OPCall::OPCall(
|
2017-11-03 11:55:26 +01:00
|
|
|
T_String const& function )
|
2017-10-15 10:22:24 +02:00
|
|
|
: T_Op( OP_CALL ) , function( function )
|
|
|
|
{ }
|
|
|
|
|
|
|
|
void OPCall::execute(
|
2017-11-03 09:08:19 +01:00
|
|
|
T_Context& ctx ) const
|
2017-10-15 10:22:24 +02:00
|
|
|
{
|
2017-11-03 11:55:26 +01:00
|
|
|
auto const* fp( ctx.program->functions.get( function ) );
|
|
|
|
if ( !fp ) {
|
|
|
|
ebcl::T_StringBuilder sb( "function '" );
|
|
|
|
sb << function << "' not found" << '\0';
|
|
|
|
throw error( sb );
|
2017-10-15 10:22:24 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 11:55:26 +01:00
|
|
|
auto const& func( *fp );
|
2017-10-15 10:22:24 +02:00
|
|
|
const auto ssz( ctx.opStack.size( ) );
|
|
|
|
if ( ssz < func.arguments ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb( "function '" );
|
|
|
|
sb << function << "' requires " << func.arguments << " argument"
|
|
|
|
<< ( func.arguments > 1 ? "s" : "" ) << '\0';
|
|
|
|
throw error( sb );
|
2017-10-15 10:22:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Execute( func.operations , ctx );
|
|
|
|
if ( ctx.opStack.size( ) < ssz ) {
|
2017-11-03 11:55:26 +01:00
|
|
|
ebcl::T_StringBuilder sb( "function '" );
|
|
|
|
sb << function << "' ate the stack" << '\0';
|
|
|
|
throw error( sb );
|
2017-10-15 10:22:24 +02:00
|
|
|
}
|
|
|
|
ctx.opStack.resize( ssz - func.arguments );
|
|
|
|
}
|