Merge branch 'ht/mem-debug' into ht/graphs
[shapes.git] / source / astfun.cc
blobaaf3f47129a16a0601c3efe59ebf875401c03035
1 /* This file is part of Shapes.
3 * Shapes is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * any later version.
8 * Shapes is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 * Copyright 2008, 2013, 2014 Henrik Tidefelt
19 #include "Shapes_Helpers_decls.h"
21 #include "astfun.h"
22 #include "astfun_impl.h"
23 #include "shapesexceptions.h"
24 #include "shapescore.h"
25 #include "consts.h"
26 #include "globals.h"
27 #include "continuations.h"
28 #include "astvar.h"
29 #include "astvalues.h"
30 #include "texlabelmanager.h"
32 #include <sstream>
34 using namespace Shapes;
35 using namespace std;
38 Kernel::Formals::Formals( )
39 : loc_( Ast::THE_UNKNOWN_LOCATION, bool( ) ),
40 seenDefault_( false ), argumentOrder_( new std::map< const char *, size_t, charPtrLess > ),
41 sink_( 0 ),
42 stateOrder_( new std::map< const char *, size_t, charPtrLess > )
43 { }
45 Kernel::Formals::Formals( size_t numberOfDummyDefaultExprs )
46 : loc_( Ast::THE_UNKNOWN_LOCATION, bool( ) ),
47 seenDefault_( false ), argumentOrder_( new std::map< const char *, size_t, charPtrLess > ),
48 sink_( 0 ),
49 stateOrder_( new std::map< const char *, size_t, charPtrLess > )
51 // Pushing null expressions is just a way of specifying how many non-sink arguments there are.
52 for( size_t i = 0; i < numberOfDummyDefaultExprs; ++i )
54 defaultExprs_.push_back( 0 );
58 Kernel::Formals::~Formals( )
60 delete argumentOrder_;
61 delete stateOrder_;
62 if( sink_ != 0 )
64 delete sink_;
68 void
69 Kernel::Formals::setLoc( const Ast::SourceLocation & loc )
71 loc_ = loc;
75 void
76 Kernel::Formals::push_exprs( Ast::ArgListExprs * args ) const
78 typedef typeof defaultExprs_ ListType;
79 for( ListType::const_iterator i = defaultExprs_.begin( ); i != defaultExprs_.end( ); ++i )
81 if( *i != 0 )
83 args->orderedExprs_->push_back( *i );
88 Kernel::EvaluatedFormals *
89 Kernel::Formals::newEvaluatedFormals( Kernel::Arguments & args ) const
91 size_t pos = 0;
92 return newEvaluatedFormals( args, & pos );
95 Kernel::EvaluatedFormals *
96 Kernel::Formals::newEvaluatedFormals( Kernel::Arguments & args, size_t * pos ) const
98 Kernel::EvaluatedFormals * res = new Kernel::EvaluatedFormals( const_cast< Kernel::Formals * >( this ) );
99 res->isSink_ = false; // The formals created here belong to user functions, which are exactly those which are not sinks.
101 res->defaults_.reserve( defaultExprs_.size( ) );
102 res->locations_.reserve( defaultExprs_.size( ) );
104 typedef typeof defaultExprs_ ListType;
105 for( ListType::const_iterator i = defaultExprs_.begin( ); i != defaultExprs_.end( ); ++i )
107 if( *i != 0 )
109 res->defaults_.push_back( args.getHandle( *pos ) );
110 res->locations_.push_back( args.getNode( *pos ) );
111 ++(*pos);
113 else
115 res->defaults_.push_back( Kernel::THE_SLOT_VARIABLE );
116 res->locations_.push_back( 0 ); // I really hope this is never dereferenced!
120 return res;
123 std::vector< bool > *
124 Kernel::Formals::newArgListForcePos( const Ast::ArgListExprs * argList ) const
126 /* Here, we use the knowledge that ordered arguments are evaluated backwards, and named arguments
127 * in the natural order (the lexiographic order of std::map).
130 std::vector< bool > * res = new std::vector< bool >;
131 res->resize( argList->orderedExprs_->size( ) );
132 res->reserve( argList->orderedExprs_->size( ) + argList->namedExprs_->size( ) );
134 if( ! argList->orderedExprs_->empty( ) )
136 typedef typeof forcePos_ SrcType;
137 SrcType::const_iterator src = forcePos_.begin( );
138 for( size_t arg = argList->orderedExprs_->size( ) - 1; ; --arg, ++src )
140 (*res)[ arg ] = *src;
141 if( arg == 0 )
143 break;
149 typedef typeof *argList->namedExprs_ MapType;
150 MapType::const_iterator end = argList->namedExprs_->end( );
151 for( MapType::const_iterator arg = argList->namedExprs_->begin( ); arg != end; ++arg )
153 res->push_back( forcePos_[ (*argumentOrder_)[ arg->first ] ] );
157 return res;
160 std::vector< bool > *
161 Kernel::Formals::newArgListForcePos( const Ast::ArgListExprs * argList, const Kernel::Arguments & curryArgs ) const
163 /* Compare with the non-curry version!
166 std::vector< bool > * res = new std::vector< bool >;
167 res->resize( argList->orderedExprs_->size( ) );
168 res->reserve( argList->orderedExprs_->size( ) + argList->namedExprs_->size( ) );
170 if( ! argList->orderedExprs_->empty( ) )
172 typedef typeof forcePos_ SrcType;
173 SrcType::const_iterator src = forcePos_.begin( );
174 size_t curryPos = 0;
175 while( curryPos < curryArgs.size( ) &&
176 ! curryArgs.isSlot( curryPos ) )
178 ++src;
179 ++curryPos;
181 for( size_t arg = argList->orderedExprs_->size( ) - 1; ; --arg )
183 (*res)[ arg ] = *src;
184 if( arg == 0 )
186 break;
188 ++src;
189 ++curryPos;
190 while( curryPos < curryArgs.size( ) &&
191 ! curryArgs.isSlot( curryPos ) )
193 ++src;
194 ++curryPos;
200 typedef typeof *argList->namedExprs_ MapType;
201 MapType::const_iterator end = argList->namedExprs_->end( );
202 for( MapType::const_iterator arg = argList->namedExprs_->begin( ); arg != end; ++arg )
204 res->push_back( forcePos_[ (*argumentOrder_)[ arg->first ] ] );
208 return res;
211 const Ast::SourceLocation &
212 Kernel::Formals::loc( ) const
214 return loc_;
219 Ast::ArgListExprs::ConstIterator::ConstIterator( std::list< Ast::Expression * >::const_reverse_iterator i1, std::map< const char *, Ast::Expression *, charPtrLess >::const_iterator i2, const size_t & index )
220 : i1_( i1 ), i2_( i2 ), index_( index )
223 Ast::ArgListExprs::ConstIterator::ConstIterator( const Ast::ArgListExprs::ConstIterator & orig )
224 : i1_( orig.i1_ ), i2_( orig.i2_ ), index_( orig.index_ )
227 Ast::ArgListExprs::ArgListExprs( bool exprOwner )
228 : exprOwner_( exprOwner ), firstOrderedStateOwner_( exprOwner ), orderedExprs_( new std::list< Ast::Expression * > ), namedExprs_( new std::map< const char *, Ast::Expression *, charPtrLess > ),
229 orderedStates_( new std::list< Ast::StateReference * > ), namedStates_( new std::map< const char *, Ast::StateReference *, charPtrLess > )
232 Ast::ArgListExprs::ArgListExprs( bool exprOwner, bool firstOrderedStateOwner )
233 : exprOwner_( exprOwner ), firstOrderedStateOwner_( firstOrderedStateOwner ), orderedExprs_( new std::list< Ast::Expression * > ), namedExprs_( new std::map< const char *, Ast::Expression *, charPtrLess > ),
234 orderedStates_( new std::list< Ast::StateReference * > ), namedStates_( new std::map< const char *, Ast::StateReference *, charPtrLess > )
238 Ast::ArgListExprs::ArgListExprs( std::list< Ast::Expression * > * orderedExprs, std::map< const char *, Ast::Expression *, charPtrLess > * namedExprs, std::list< Ast::StateReference * > * orderedStates, std::map< const char *, Ast::StateReference *, charPtrLess > * namedStates )
239 : exprOwner_( true ), firstOrderedStateOwner_( true ), orderedExprs_( orderedExprs ), namedExprs_( namedExprs ), orderedStates_( orderedStates ), namedStates_( namedStates )
242 Ast::ArgListExprs::~ArgListExprs( )
245 if( exprOwner_ )
247 typedef list< Ast::Expression * >::iterator I;
248 for( I i = orderedExprs_->begin( ); i != orderedExprs_->end( ); ++i )
250 delete *i;
253 delete orderedExprs_;
257 if( exprOwner_ )
259 typedef std::map< const char *, Ast::Expression *, charPtrLess >::const_iterator I;
260 for( I i = namedExprs_->begin( ); i != namedExprs_->end( ); ++i )
262 delete i->first;
263 delete i->second;
266 delete namedExprs_;
270 if( exprOwner_ )
272 typedef std::list< Ast::StateReference * >::iterator I;
273 I i = orderedStates_->begin( );
274 if( i != orderedStates_->end( ) ){
275 if( firstOrderedStateOwner_ ){
276 delete *i;
278 for( ++i; i != orderedStates_->end( ); ++i )
280 delete *i;
284 delete orderedStates_;
288 if( exprOwner_ )
290 typedef std::map< const char *, Ast::StateReference *, charPtrLess >::const_iterator I;
291 for( I i = namedStates_->begin( ); i != namedStates_->end( ); ++i )
293 delete i->first;
294 delete i->second;
297 delete namedStates_;
301 Ast::ArgListExprs::ArgListExprs( size_t numberOfOrderedDummyExprs )
302 : exprOwner_( true ), firstOrderedStateOwner_( true ), orderedExprs_( new std::list< Ast::Expression * > ), namedExprs_( new std::map< const char *, Ast::Expression *, charPtrLess > ), orderedStates_( new typeof *orderedStates_ ), namedStates_( new typeof *namedStates_ )
304 for( size_t i = 0; i < numberOfOrderedDummyExprs; ++i )
306 orderedExprs_->push_back( new Ast::DummyExpression );
310 void
311 Ast::ArgListExprs::evaluate( const RefCountPtr< const Kernel::CallContInfo > & info, const Ast::ArgListExprs::ConstIterator & pos, const RefCountPtr< const Lang::SingleList > & vals, Kernel::EvalState * evalState ) const
313 std::list< Ast::Expression * >::const_reverse_iterator i1end = orderedExprs_->rend( );
315 if( pos.i1_ == i1end &&
316 pos.i2_ == namedExprs_->end( ) )
318 evalState->cont_ = info->cont_;
319 info->cont_->takeValue( vals, evalState );
320 return;
323 if( pos.i1_ != i1end )
325 /* Note that it is necessary that the evaluation of expressions with free states is not delayed.
326 * If it would, it would be very strange for the calling function if a passed state would change
327 * value in response to the accessing of a formal parameter.
329 bool force = info->force( pos.index_ );
330 if( force || (*(pos.i1_))->immediate_ )
332 typedef typeof const_cast< Ast::ArgListExprs::ConstIterator & >( pos ).i1_ Iterator;
333 Iterator next = pos.i1_;
334 ++next;
335 evalState->expr_ = *(pos.i1_);
336 evalState->env_ = info->env_;
337 evalState->dyn_ = info->dyn_;
338 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_n( evalState->expr_->loc( ),
339 info,
340 Ast::ArgListExprs::ConstIterator( next, pos.i2_, pos.index_ + 1 ),
341 vals,
342 force ) );
343 return;
345 else
347 /* Delay evaluation of this argument by just putting a thunk in the list.
349 typedef typeof const_cast< Ast::ArgListExprs::ConstIterator & >( pos ).i1_ Iterator;
350 Iterator next = pos.i1_;
351 ++next;
352 evaluate( info,
353 Ast::ArgListExprs::ConstIterator( next, pos.i2_, pos.index_ + 1 ),
354 RefCountPtr< const Lang::SingleListPair >( new Lang::SingleListPair( Kernel::VariableHandle( new Kernel::Variable( new Kernel::Thunk( info->env_, info->dyn_, *pos.i1_ ) ) ),
355 vals ) ),
356 evalState );
357 return; /* It is not really important that the above compiles to a tail call. Hopefully, it does, but otherwise it is easy to see that the chain of recursive calls to this function
358 * will always completes without evaluation of expressions. */
361 else
363 bool force = info->force( pos.index_ );
364 if( force || pos.i2_->second->immediate_ )
366 typedef typeof const_cast< Ast::ArgListExprs::ConstIterator & >( pos ).i2_ Iterator;
367 Iterator next = pos.i2_;
368 ++next;
369 evalState->expr_ = pos.i2_->second;
370 evalState->env_ = info->env_;
371 evalState->dyn_ = info->dyn_;
372 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_n( evalState->expr_->loc( ),
373 info,
374 Ast::ArgListExprs::ConstIterator( pos.i1_, next, pos.index_ + 1 ),
375 vals,
376 force ) );
377 return;
379 else
381 /* Delay evaluation of this argument by just putting a thunk in the list.
383 typedef typeof const_cast< Ast::ArgListExprs::ConstIterator & >( pos ).i2_ Iterator;
384 Iterator next = pos.i2_;
385 ++next;
386 evaluate( info,
387 Ast::ArgListExprs::ConstIterator( pos.i1_, next, pos.index_ + 1 ),
388 RefCountPtr< const Lang::SingleListPair >( new Lang::SingleListPair( Kernel::VariableHandle( new Kernel::Variable( new Kernel::Thunk( info->env_, info->dyn_, pos.i2_->second ) ) ),
389 vals ) ),
390 evalState );
391 return; /* It is not really important that the above compiles to a tail call. Hopefully, it does, but otherwise it is easy to see that the chain of recursive calls to this function
392 * will always complete without evaluation of expressions. */
397 void
398 Ast::ArgListExprs::evaluate_Structure( const RefCountPtr< const Kernel::CallContInfo > & info, size_t pos, const RefCountPtr< const Lang::SingleList > & values, Kernel::EvalState * evalState ) const
400 const Lang::SingleListPair * valuesPtr = dynamic_cast< const Lang::SingleListPair * >( values.getPtr( ) );
401 if( valuesPtr == NULL ){
402 /* Finished, let the waiting CallCont_Structure_last do the rest. */
403 evalState->cont_ = info->cont_;
404 info->cont_->takeValue( Lang::THE_VOID, /* The continuation already has all values; Lang::THE_VOID is just a dummy. */
405 evalState );
406 return;
409 Kernel::VariableHandle first = valuesPtr->car_;
411 if( info->force( pos ) && first->isThunk( ) )
413 evalState->env_ = info->env_;
414 evalState->dyn_ = info->dyn_;
415 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_Structure_n
416 ( evalState->expr_->loc( ),
417 info,
418 pos - 1,
419 valuesPtr->cdr_ ) );
420 first->force( first, evalState );
421 return;
423 else
425 evaluate_Structure( info, pos - 1, valuesPtr->cdr_, evalState );
426 return;
430 void
431 Ast::ArgListExprs::bind( Kernel::Arguments * dst, RefCountPtr< const Lang::SingleList > vals, Kernel::PassedEnv env, Kernel::PassedDyn dyn ) const
433 typedef const Lang::SingleListPair ConsType;
435 /* Note that the arguments are bound in backwards-order, since that is how the values are accessed.
439 typedef std::map< const char *, Ast::Expression *, charPtrLess >::const_reverse_iterator I;
440 I i = namedExprs_->rbegin( );
441 I end = namedExprs_->rend( );
442 for( ; i != end; ++i )
444 RefCountPtr< ConsType > lst = vals.down_cast< ConsType >( );
445 if( lst == NullPtr< ConsType >( ) )
447 throw Exceptions::InternalError( strrefdup( "Out of argument values when binding application." ) );
449 dst->addNamedArgument( i->first, lst->car_, i->second );
450 vals = lst->cdr_;
455 typedef list< Ast::Expression * >::const_iterator I;
456 I i = orderedExprs_->begin( );
457 I end = orderedExprs_->end( );
458 for( ; i != end; ++i )
460 RefCountPtr< ConsType > lst = vals.down_cast< ConsType >( );
461 if( lst == NullPtr< ConsType >( ) )
463 throw Exceptions::InternalError( strrefdup( "Out of argument values when binding application." ) );
465 dst->addOrderedArgument( lst->car_, *i );
466 vals = lst->cdr_;
470 /* Here, it could/should be verified that vals is null. However, it only isn't in case of an internal error...
473 /* Next, we turn to the states. The states need no evaluation, as they are always passed by reference.
477 typedef std::map< const char *, Ast::StateReference *, charPtrLess >::const_iterator I;
478 I i = namedStates_->begin( );
479 I end = namedStates_->end( );
480 for( ; i != end; ++i )
482 dst->addNamedState( i->first, i->second->getHandle( env, dyn ) , i->second );
487 typedef list< Ast::StateReference * >::const_iterator I;
488 I i = orderedStates_->begin( );
489 I end = orderedStates_->end( );
490 for( ; i != end; ++i )
492 dst->addOrderedState( (*i)->getHandle( env, dyn ), *i );
499 Kernel::VariableHandle
500 Ast::ArgListExprs::findNamed( RefCountPtr< const Lang::SingleList > vals, const char * name ) const
502 /* This function is called when a Lang::Structure is asked for a field by name.
503 * This is reflected in the generated error in case the name is not found.
506 typedef const Lang::SingleListPair ConsType;
508 /* Note that the arguments are bound in backwards-order, since that is how the values are accessed.
511 typedef std::map< const char *, Ast::Expression *, charPtrLess >::const_reverse_iterator I;
512 I i = namedExprs_->rbegin( );
513 I end = namedExprs_->rend( );
514 for( ; i != end; ++i )
516 RefCountPtr< ConsType > lst = vals.down_cast< ConsType >( );
517 if( lst == NullPtr< ConsType >( ) )
519 throw Exceptions::InternalError( strrefdup( "Out of argument values when searching fields." ) );
521 if( strcmp( i->first, name ) == 0 )
523 return lst->car_;
525 vals = lst->cdr_;
528 throw Exceptions::NonExistentMember( strrefdup( "< user union >" ), name );
531 Kernel::VariableHandle
532 Ast::ArgListExprs::getOrdered( RefCountPtr< const Lang::SingleList > vals, size_t pos ) const
534 /* This function is called when a Lang::Structure is asked for a field by position.
535 * This is reflected in the generated error in case the position is not found.
538 typedef const Lang::SingleListPair ConsType;
540 /* Note that the arguments are bound in backwards-order, since that is how the values are accessed.
543 size_t i = 0;
545 typedef list< Ast::Expression * >::const_iterator I;
546 while( true )
548 RefCountPtr< ConsType > lst = vals.down_cast< ConsType >( );
549 if( lst == NullPtr< ConsType >( ) )
551 break;
553 if( i == pos )
555 return lst->car_;
557 vals = lst->cdr_;
558 ++i;
562 throw Exceptions::NonExistentPosition( pos, i - 1 );
565 void
566 Ast::ArgListExprs::analyze( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst )
568 parent_ = parent;
570 RefCountPtr< Ast::StateIDSet > passedStates( new Ast::StateIDSet );
572 /* First traverse state arguments, so that we know which states that must not appear in the value arguments.
575 typedef typeof *orderedStates_ ListType;
576 for( ListType::iterator i = orderedStates_->begin( ); i != orderedStates_->end( ); ++i )
578 (*i)->analyze( parent_, env, passedStates.getPtr( ) );
582 typedef typeof *namedStates_ ListType;
583 for( ListType::iterator i = namedStates_->begin( ); i != namedStates_->end( ); ++i )
585 i->second->analyze( parent_, env, passedStates.getPtr( ) );
588 if( passedStates->size( ) < orderedStates_->size( ) + namedStates_->size( ) )
590 Ast::theAnalysisErrorsList.push_back( new Exceptions::RepeatedStateArgument( parent_->loc( ), passedStates ) );
593 /* Traverse children
596 typedef typeof *orderedExprs_ ListType;
597 for( ListType::iterator i = orderedExprs_->begin( ); i != orderedExprs_->end( ); ++i )
599 if( (*i)->immediate_ )
601 (*i)->analyze( parent_, env, freeStatesDst );
603 else
605 Ast::StateIDSet freeStates;
606 (*i)->analyze( parent_, env, & freeStates );
607 for( Ast::StateIDSet::const_iterator j = freeStates.begin( ); j != freeStates.end( ); ++j )
609 if( passedStates->find( *j ) != passedStates->end( ) )
611 Ast::theAnalysisErrorsList.push_back( new Exceptions::FreeStateIsAlsoPassed( (*i)->loc( ), *j ) );
613 freeStatesDst->insert( *j );
619 typedef typeof *namedExprs_ ListType;
620 for( ListType::iterator i = namedExprs_->begin( ); i != namedExprs_->end( ); ++i )
622 if( i->second->immediate_ )
624 i->second->analyze( parent_, env, freeStatesDst );
626 else
628 Ast::StateIDSet freeStates;
629 i->second->analyze( parent_, env, & freeStates );
630 for( Ast::StateIDSet::const_iterator j = freeStates.begin( ); j != freeStates.end( ); ++j )
632 if( passedStates->find( *j ) != passedStates->end( ) )
634 Ast::theAnalysisErrorsList.push_back( new Exceptions::FreeStateIsAlsoPassed( i->second->loc( ), *j ) );
636 freeStatesDst->insert( *j );
643 for( Ast::StateIDSet::const_iterator i = passedStates->begin( ); i != passedStates->end( ); ++i )
645 freeStatesDst->insert( *i );
650 Ast::ArgListExprs::ConstIterator
651 Ast::ArgListExprs::begin( ) const
653 return Ast::ArgListExprs::ConstIterator( orderedExprs_->rbegin( ), namedExprs_->begin( ), 0 );
657 Ast::FunctionFunction::FunctionFunction( const Ast::SourceLocation & loc, const Kernel::Formals * formals, Ast::Expression * body, const Ast::FunctionMode & functionMode )
658 : Lang::Function( new Kernel::EvaluatedFormals( Ast::FileID::build_internal( "< function construction >" ), false ) ), loc_( loc, bool( ) ), formals_( formals ), body_( body ), functionMode_( functionMode )
661 Ast::FunctionFunction::~FunctionFunction( )
663 delete formals_;
664 delete body_;
667 void
668 Ast::FunctionFunction::push_exprs( Ast::ArgListExprs * args ) const
670 formals_->push_exprs( args );
673 void
674 Ast::FunctionFunction::analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * parentEnv, Ast::StateIDSet * freeStatesDst )
676 Ast::AnalysisEnvironment * env( new Ast::AnalysisEnvironment( Ast::theAnalysisEnvironmentList, parentEnv, formals_->argumentOrder_, formals_->stateOrder_ ) );
677 env->activateFunctionBoundary( );
679 /* We know that the body does not access states outside the function's scope, so we can simply
680 * leave freeStatesDst without change.
682 Ast::StateIDSet freeStates;
683 body_->analyze( parent, env, & freeStates );
686 void
687 Ast::FunctionFunction::call( Kernel::EvalState * evalState, Kernel::Arguments & args, const Ast::SourceLocation & callLoc ) const
689 Kernel::ContRef cont = evalState->cont_;
690 cont->takeValue( Kernel::ValueRef( new Lang::UserFunction( formals_->newEvaluatedFormals( args ),
691 body_, evalState->env_, functionMode_ ) ),
692 evalState );
696 Kernel::CallCont_last::CallCont_last( const RefCountPtr< const Lang::Function > & fun, const Ast::ArgListExprs * argList, bool curry, Kernel::StateHandle mutatorSelf, const Kernel::PassedEnv & env, const Kernel::PassedDyn & dyn, const Kernel::ContRef & cont, const Ast::SourceLocation & callLoc )
697 : Kernel::Continuation( callLoc ), fun_( fun ), argList_( argList ), curry_( curry ), mutatorSelf_( mutatorSelf ), env_( env ), dyn_( dyn ), cont_( cont )
700 Kernel::CallCont_last::~CallCont_last( )
703 void
704 Kernel::CallCont_last::takeValue( const RefCountPtr< const Lang::Value > & valsUntyped, Kernel::EvalState * evalState, bool dummy ) const
706 typedef const Lang::SingleList ArgType;
707 RefCountPtr< ArgType > vals = Helpers::down_cast< ArgType >( valsUntyped, "< Internal error situation in CallCont_last >" );
709 Kernel::Arguments args = fun_->newCurriedArguments( );
710 argList_->bind( & args, vals, env_, dyn_ );
711 if( mutatorSelf_ != 0 )
713 args.setMutatorSelf( mutatorSelf_ );
716 if( curry_ )
718 evalState->cont_ = cont_;
719 cont_->takeValue( Kernel::ValueRef( new Lang::CuteFunction( fun_, args ) ), evalState );
721 else
723 evalState->env_ = env_; /* This matters only when the function being called is FunctionFunction! */
724 evalState->dyn_ = dyn_;
725 evalState->cont_ = cont_;
726 fun_->call( evalState, args, traceLoc_ );
730 Kernel::ContRef
731 Kernel::CallCont_last::up( ) const
733 return cont_;
736 RefCountPtr< const char >
737 Kernel::CallCont_last::description( ) const
739 return strrefdup( "function call's application" );
742 void
743 Kernel::CallCont_last::gcMark( Kernel::GCMarkedSet & marked )
745 const_cast< Lang::Function * >( fun_.getPtr( ) )->gcMark( marked );
746 dyn_->gcMark( marked );
747 cont_->gcMark( marked );
751 Kernel::CallCont_Structure_last::CallCont_Structure_last( const RefCountPtr< const Lang::Function > & fun, const Ast::ArgListExprs * argList, const RefCountPtr< const Lang::SingleList > & values, bool curry, const Kernel::PassedEnv & env, const Kernel::PassedDyn & dyn, const Kernel::ContRef & cont, const Ast::SourceLocation & callLoc )
752 : Kernel::Continuation( callLoc ), fun_( fun ), argList_( argList ), values_( values ), curry_( curry ), env_( env ), dyn_( dyn ), cont_( cont )
755 Kernel::CallCont_Structure_last::~CallCont_Structure_last( )
758 void
759 Kernel::CallCont_Structure_last::takeValue( const RefCountPtr< const Lang::Value > & valDummy, Kernel::EvalState * evalState, bool dummy ) const
761 Kernel::Arguments args = fun_->newCurriedArguments( );
762 argList_->bind( & args, values_, env_, dyn_ );
764 if( curry_ )
766 evalState->cont_ = cont_;
767 cont_->takeValue( Kernel::ValueRef( new Lang::CuteFunction( fun_, args ) ), evalState );
769 else
771 evalState->env_ = env_; /* This matters only when the function being called is FunctionFunction! */
772 evalState->dyn_ = dyn_;
773 evalState->cont_ = cont_;
774 fun_->call( evalState, args, traceLoc_ );
778 Kernel::ContRef
779 Kernel::CallCont_Structure_last::up( ) const
781 return cont_;
784 RefCountPtr< const char >
785 Kernel::CallCont_Structure_last::description( ) const
787 return strrefdup( "split structure application" );
790 void
791 Kernel::CallCont_Structure_last::gcMark( Kernel::GCMarkedSet & marked )
793 const_cast< Lang::Function * >( fun_.getPtr( ) )->gcMark( marked );
794 const_cast< Lang::SingleList * >( values_.getPtr( ) )->gcMark( marked );
795 dyn_->gcMark( marked );
796 cont_->gcMark( marked );
800 Kernel::CallContInfo::CallContInfo( const Ast::ArgListExprs * argList, const Kernel::EvalState & evalState, std::vector< bool > * forcePos )
801 : forcePos_( forcePos ), forceAll_( false ), argList_( argList ), env_( evalState.env_ ), dyn_( evalState.dyn_ ), cont_( evalState.cont_ )
804 Kernel::CallContInfo::CallContInfo( const Ast::ArgListExprs * argList, const Kernel::EvalState & evalState, bool forceAll )
805 : forcePos_( 0 ), forceAll_( forceAll ), argList_( argList ), env_( evalState.env_ ), dyn_( evalState.dyn_ ), cont_( evalState.cont_ )
808 Kernel::CallContInfo::~CallContInfo( )
810 if( forcePos_ != 0 )
812 delete forcePos_;
816 bool
817 Kernel::CallContInfo::force( const size_t & pos ) const
819 if( forcePos_ != 0 )
821 return (*forcePos_)[ pos ];
823 return forceAll_;
826 bool
827 Kernel::CallContInfo::isSelective( ) const
829 return forcePos_ != 0;
832 bool
833 Kernel::CallContInfo::forceNone( ) const
835 if( isSelective( ) )
836 return false;
837 return ! forceAll_;
840 bool
841 Kernel::CallContInfo::forceAll( ) const
843 if( isSelective( ) )
844 return false;
845 return forceAll_;
848 void
849 Kernel::CallContInfo::gcMark( Kernel::GCMarkedSet & marked )
851 env_->gcMark( marked );
852 dyn_->gcMark( marked );
853 cont_->gcMark( marked );
857 Kernel::CallCont_n::CallCont_n( const Ast::SourceLocation & traceLoc, const RefCountPtr< const Kernel::CallContInfo > & info, const Ast::ArgListExprs::ConstIterator & pos, RefCountPtr< const Lang::SingleList > vals, bool force )
858 : Kernel::Continuation( traceLoc ), info_( info ), pos_( pos ), vals_( vals ), force_( force )
861 Kernel::CallCont_n::~CallCont_n( )
864 void
865 Kernel::CallCont_n::takeHandle( Kernel::VariableHandle val, Kernel::EvalState * evalState, bool dummy ) const
867 /* Even if force_ is set, this continuation takes handles since handles is what goes into the argument list.
870 if( force_ && val->isThunk( ) )
872 val->force( val, evalState );
873 return;
875 if( val == Kernel::THE_SLOT_VARIABLE )
877 /* If we don't detect this, the error messages that will be printed later would be very confusing,
878 * saying that the argument is missing, when the problem is likely to be that some internal
879 * computation should result in THE_VOID_VARIABLE rather than THE_SLOT_VARIABLE.
881 throw Exceptions::InternalError( "An argument expression evaluated to THE_SLOT_VARIABLE." );
883 info_->argList_->evaluate( info_,
884 pos_,
885 RefCountPtr< const Lang::SingleListPair >( new Lang::SingleListPair( val, vals_ ) ),
886 evalState );
889 Kernel::ContRef
890 Kernel::CallCont_n::up( ) const
892 return info_->cont_;
895 RefCountPtr< const char >
896 Kernel::CallCont_n::description( ) const
898 return strrefdup( force_ ? "function call's forced argument" : "function call's immediate argument" );
901 void
902 Kernel::CallCont_n::gcMark( Kernel::GCMarkedSet & marked )
904 const_cast< Kernel::CallContInfo * >( info_.getPtr( ) )->gcMark( marked );
905 const_cast< Lang::SingleList * >( vals_.getPtr( ) )->gcMark( marked );
909 Kernel::CallCont_Structure_n::CallCont_Structure_n( const Ast::SourceLocation & traceLoc, const RefCountPtr< const Kernel::CallContInfo > & info, size_t pos, RefCountPtr< const Lang::SingleList > rest )
910 : Kernel::Continuation( traceLoc ), info_( info ), pos_( pos ), rest_( rest )
913 Kernel::CallCont_Structure_n::~CallCont_Structure_n( )
916 void
917 Kernel::CallCont_Structure_n::takeValue( const RefCountPtr< const Lang::Value > & forcedValue, Kernel::EvalState * evalState, bool dummy ) const
919 info_->argList_->evaluate_Structure( info_, pos_, rest_, evalState );
922 Kernel::ContRef
923 Kernel::CallCont_Structure_n::up( ) const
925 return info_->cont_;
928 RefCountPtr< const char >
929 Kernel::CallCont_Structure_n::description( ) const
931 return strrefdup( "split structure application forced argument" );
934 void
935 Kernel::CallCont_Structure_n::gcMark( Kernel::GCMarkedSet & marked )
937 const_cast< Kernel::CallContInfo * >( info_.getPtr( ) )->gcMark( marked );
938 const_cast< Lang::SingleList * >( rest_.getPtr( ) )->gcMark( marked );
942 Kernel::CallCont_1::CallCont_1( const Ast::SourceLocation & traceLoc, const Ast::ArgListExprs * argList, bool curry, Kernel::StateHandle mutatorSelf, const Kernel::EvalState & evalState, const Ast::SourceLocation & callLoc )
943 : Kernel::Continuation( traceLoc ), argList_( argList ), curry_( curry ), mutatorSelf_( mutatorSelf ), env_( evalState.env_ ), dyn_( evalState.dyn_ ), cont_( evalState.cont_ ), callLoc_( callLoc )
946 Kernel::CallCont_1::~CallCont_1( )
949 void
950 Kernel::CallCont_1::takeValue( const RefCountPtr< const Lang::Value > & funUntyped, Kernel::EvalState * evalState, bool dummy ) const
953 typedef const Lang::Function ArgType;
954 RefCountPtr< ArgType > fun = funUntyped.down_cast< const Lang::Function >( );
955 if( fun != NullPtr< ArgType >( ) )
957 evalState->env_ = env_;
958 evalState->dyn_ = dyn_;
959 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_last( fun, argList_, curry_, mutatorSelf_, env_, dyn_, cont_, callLoc_ ) );
960 argList_->evaluate( fun->newCallContInfo( argList_, *evalState ),
961 argList_->begin( ), Lang::THE_CONS_NULL,
962 evalState );
963 return;
967 typedef const Lang::Transform2D ArgType;
968 ArgType * transformVal = dynamic_cast< ArgType * >( funUntyped.getPtr( ) );
969 if( transformVal != 0 )
971 if( curry_ )
973 throw Exceptions::MiscellaneousRequirement( strrefdup( "Don't Curry transform applications. It's useless anyway!" ) );
975 if( argList_->orderedExprs_->size( ) != 1 )
977 throw Exceptions::CoreArityMismatch( "<transform application>", 1, argList_->orderedExprs_->size( ) );
979 if( ! argList_->namedExprs_->empty( ) )
981 throw Exceptions::CoreNoNamedFormals( "<transform application>" );
983 evalState->expr_ = argList_->orderedExprs_->front( );
984 evalState->env_ = env_;
985 evalState->dyn_ = dyn_;
986 evalState->cont_ = Kernel::ContRef( new Kernel::Transform2DCont( *transformVal, cont_, callLoc_ ) );
987 return;
991 typedef const Lang::Transform3D ArgType;
992 ArgType * transformVal = dynamic_cast< ArgType * >( funUntyped.getPtr( ) );
993 if( transformVal != 0 )
995 if( curry_ )
997 throw Exceptions::MiscellaneousRequirement( strrefdup( "Don't Curry transform applications. It's useless anyway!" ) );
999 if( argList_->orderedExprs_->size( ) != 1 )
1001 throw Exceptions::CoreArityMismatch( "<transform application>", 1, argList_->orderedExprs_->size( ) );
1003 if( ! argList_->namedExprs_->empty( ) )
1005 throw Exceptions::CoreNoNamedFormals( "<transform application>" );
1007 evalState->expr_ = argList_->orderedExprs_->front( );
1008 evalState->env_ = env_;
1009 evalState->dyn_ = dyn_;
1010 evalState->cont_ = Kernel::ContRef( new Kernel::Transform3DCont( *transformVal, cont_, callLoc_ ) );
1011 return;
1016 typedef const Lang::ElementaryPath2D ArgType;
1017 RefCountPtr< ArgType > path = NullPtr< ArgType >( );
1020 path = Helpers::elementaryPathCast2D( funUntyped, this );
1022 catch( const Exceptions::ContinuationTypeMismatch & ball )
1024 goto nextType1;
1027 if( curry_ )
1029 throw Exceptions::MiscellaneousRequirement( strrefdup( "Don't Curry path point selection. It's useless anyway!" ) );
1031 if( argList_->orderedExprs_->size( ) != 1 )
1033 throw Exceptions::CoreArityMismatch( "<path point selection>", 1, argList_->orderedExprs_->size( ) );
1035 if( ! argList_->namedExprs_->empty( ) )
1037 throw Exceptions::CoreNoNamedFormals( "<path point selection>" );
1040 evalState->expr_ = argList_->orderedExprs_->front( );
1041 evalState->env_ = env_;
1042 evalState->dyn_ = dyn_;
1043 evalState->cont_ = Kernel::ContRef( new Kernel::PathApplication2DCont( path,
1044 cont_,
1045 callLoc_ ) );
1046 return;
1048 nextType1:
1051 typedef const Lang::ElementaryPath3D ArgType;
1052 RefCountPtr< ArgType > path = NullPtr< ArgType >( );
1055 path = Helpers::elementaryPathCast3D( funUntyped, this );
1057 catch( const Exceptions::ContinuationTypeMismatch & ball )
1059 goto nextType2;
1062 if( curry_ )
1064 throw Exceptions::MiscellaneousRequirement( strrefdup( "Don't Curry path point selection. It's useless anyway!" ) );
1066 if( argList_->orderedExprs_->size( ) != 1 )
1068 throw Exceptions::CoreArityMismatch( "<path point selection>", 1, argList_->orderedExprs_->size( ) );
1070 if( ! argList_->namedExprs_->empty( ) )
1072 throw Exceptions::CoreNoNamedFormals( "<path point selection>" );
1075 evalState->expr_ = argList_->orderedExprs_->front( );
1076 evalState->env_ = env_;
1077 evalState->dyn_ = dyn_;
1078 evalState->cont_ = Kernel::ContRef( new Kernel::PathApplication3DCont( path,
1079 cont_,
1080 callLoc_ ) );
1081 return;
1083 nextType2:
1085 throw Exceptions::TypeMismatch( traceLoc_,
1086 funUntyped->getTypeName( ),
1087 Helpers::typeSetString( Lang::Function::staticTypeName( ),
1088 Lang::Transform2D::staticTypeName( ),
1089 Lang::Transform3D::staticTypeName( ),
1090 Lang::ElementaryPath2D::staticTypeName( ),
1091 Lang::ElementaryPath3D::staticTypeName( ) ) );
1094 Kernel::ContRef
1095 Kernel::CallCont_1::up( ) const
1097 return cont_;
1100 RefCountPtr< const char >
1101 Kernel::CallCont_1::description( ) const
1103 return strrefdup( "function call's function" );
1106 void
1107 Kernel::CallCont_1::gcMark( Kernel::GCMarkedSet & marked )
1109 dyn_->gcMark( marked );
1110 cont_->gcMark( marked );
1115 Ast::CallExpr::CallExpr( const Ast::SourceLocation & loc, Ast::Expression * funExpr, Ast::ArgListExprs * argList, bool curry )
1116 : Ast::Expression( loc ), curry_( curry ), constFun_( Kernel::THE_NO_FUNCTION ), mutatorSelf_( 0 ), funExpr_( funExpr ), argList_( argList )
1119 Ast::CallExpr::CallExpr( const Ast::SourceLocation & loc, const RefCountPtr< const Lang::Function > & constFun, Ast::ArgListExprs * argList, bool curry )
1120 : Ast::Expression( loc ), curry_( curry ), constFun_( constFun ), mutatorSelf_( 0 ), funExpr_( 0 ), argList_( argList )
1123 Ast::CallExpr::~CallExpr( )
1125 if( funExpr_ != 0 )
1127 delete funExpr_;
1129 if( mutatorSelf_ != 0 )
1131 delete mutatorSelf_;
1133 delete argList_;
1136 void
1137 Ast::CallExpr::setMutatorSelf( Ast::StateReference * mutatorSelf )
1139 mutatorSelf_ = mutatorSelf;
1142 void
1143 Ast::CallExpr::analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst )
1145 if( mutatorSelf_ != 0 )
1147 mutatorSelf_->analyze( this, env, freeStatesDst );
1149 if( funExpr_ != 0 )
1151 funExpr_->analyze( this, env, freeStatesDst );
1153 else
1155 const_cast< Lang::Function * >( constFun_.getPtr( ) )->analyze( this, env );
1157 argList_->analyze( this, env, freeStatesDst );
1159 if( funExpr_ != 0 )
1161 Ast::LexiographicVariable * var = dynamic_cast< Ast::LexiographicVariable * >( funExpr_ );
1162 if( var != 0 &&
1163 var->scope_level( ) == 0 )
1165 /* The callee is bound in the base environment. */
1166 if( strcmp( var->id( ), Lang::TEX_SYNTAX_ID ) == 0 )
1168 /* Someone is calling TeX. If the argument is a string literal, it should be announced. */
1169 if( argList_->orderedExprs_ != 0 && ! argList_->orderedExprs_->empty( ) )
1171 /* If there are named arguments or more than one ordered argument, they are ignored; only the first ordered argument is checked. */
1172 Ast::Constant * carg = dynamic_cast< Ast::Constant * >( argList_->orderedExprs_->front( ) );
1173 if( carg != 0 )
1177 typedef const Lang::String ArgType;
1178 RefCountPtr< ArgType > strArg = carg->val( )->tryVal< ArgType >( );
1179 Kernel::theTeXLabelManager.announce( std::string( strArg->val_.getPtr( ) ), carg->loc( ) );
1181 catch( const NonLocalExit::NotThisType & ball )
1183 /* This is probably a type mismatch error, but we let the callee make the decision. */
1192 void
1193 Ast::CallExpr::eval( Kernel::EvalState * evalState ) const
1195 if( funExpr_ != 0 )
1197 evalState->expr_ = funExpr_;
1198 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_1( evalState->expr_->loc( ), argList_, curry_, mutatorSelf_ ? (mutatorSelf_->getHandle( evalState->env_, evalState->dyn_ )) : 0, *evalState, loc_ ) );
1200 else
1202 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_last( constFun_, argList_, curry_, mutatorSelf_ ? (mutatorSelf_->getHandle( evalState->env_, evalState->dyn_ )) : 0, evalState->env_, evalState->dyn_, evalState->cont_, loc_ ) );
1203 argList_->evaluate( constFun_->newCallContInfo( argList_, *evalState ),
1204 argList_->begin( ), Lang::THE_CONS_NULL,
1205 evalState );
1209 Kernel::UnionCont_last::UnionCont_last( const Ast::ArgListExprs * argList, const Kernel::ContRef & cont, const Ast::SourceLocation & callLoc )
1210 : Kernel::Continuation( callLoc ), argList_( argList ), cont_( cont )
1213 Kernel::UnionCont_last::~UnionCont_last( )
1216 void
1217 Kernel::UnionCont_last::takeValue( const RefCountPtr< const Lang::Value > & valsUntyped, Kernel::EvalState * evalState, bool dummy ) const
1219 typedef const Lang::SingleList ArgType;
1220 RefCountPtr< ArgType > vals = Helpers::down_cast< ArgType >( valsUntyped, "< Internal error situation in UnionCont_last >" );
1222 evalState->cont_ = cont_;
1223 cont_->takeValue( Kernel::ValueRef( new Lang::Structure( argList_, vals ) ),
1224 evalState );
1227 Kernel::ContRef
1228 Kernel::UnionCont_last::up( ) const
1230 return cont_;
1233 RefCountPtr< const char >
1234 Kernel::UnionCont_last::description( ) const
1236 return strrefdup( "union" );
1239 void
1240 Kernel::UnionCont_last::gcMark( Kernel::GCMarkedSet & marked )
1242 cont_->gcMark( marked );
1246 Ast::UnionExpr::UnionExpr( const Ast::SourceLocation & loc, Ast::ArgListExprs * argList )
1247 : Ast::Expression( loc ), argList_( argList )
1250 Ast::UnionExpr::~UnionExpr( )
1252 delete argList_;
1256 void
1257 Ast::UnionExpr::analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst )
1259 argList_->analyze( this, env, freeStatesDst );
1262 void
1263 Ast::UnionExpr::eval( Kernel::EvalState * evalState ) const
1265 evalState->cont_ = Kernel::ContRef( new Kernel::UnionCont_last( argList_, evalState->cont_, loc_ ) );
1267 argList_->evaluate( RefCountPtr< Kernel::CallContInfo >( new Kernel::CallContInfo( argList_, *evalState, false ) ),
1268 argList_->begin( ), Lang::THE_CONS_NULL,
1269 evalState );
1273 Kernel::SplitCont_1::SplitCont_1( const Ast::SourceLocation & traceLoc, Ast::Expression * argList, bool curry, const Kernel::EvalState & evalState, const Ast::SourceLocation & callLoc )
1274 : Kernel::Continuation( traceLoc ), argList_( argList ), curry_( curry ), env_( evalState.env_ ), dyn_( evalState.dyn_ ), cont_( evalState.cont_ ), callLoc_( callLoc )
1277 Kernel::SplitCont_1::~SplitCont_1( )
1280 void
1281 Kernel::SplitCont_1::takeValue( const RefCountPtr< const Lang::Value > & funUntyped, Kernel::EvalState * evalState, bool dummy ) const
1283 typedef const Lang::Function ArgType;
1284 RefCountPtr< ArgType > fun = Helpers::down_cast< ArgType >( funUntyped, "Split's function" );
1286 evalState->env_ = env_;
1287 evalState->dyn_ = dyn_;
1288 evalState->cont_ = Kernel::ContRef( new Kernel::SplitCont_2( fun, curry_, env_, dyn_, cont_, callLoc_ ) );
1289 evalState->expr_ = argList_;
1292 Kernel::ContRef
1293 Kernel::SplitCont_1::up( ) const
1295 return cont_;
1298 RefCountPtr< const char >
1299 Kernel::SplitCont_1::description() const
1301 return strrefdup( "split call's function" );
1304 void
1305 Kernel::SplitCont_1::gcMark( Kernel::GCMarkedSet & marked )
1307 dyn_->gcMark( marked );
1308 cont_->gcMark( marked );
1312 Kernel::SplitCont_2::SplitCont_2( const RefCountPtr< const Lang::Function > & fun, bool curry, const Kernel::PassedEnv & env, const Kernel::PassedDyn & dyn, const Kernel::ContRef & cont, const Ast::SourceLocation & callLoc )
1313 : Kernel::Continuation( callLoc ), fun_( fun ), curry_( curry ), env_( env ), dyn_( dyn ), cont_( cont )
1316 Kernel::SplitCont_2::~SplitCont_2( )
1319 void
1320 Kernel::SplitCont_2::takeValue( const RefCountPtr< const Lang::Value > & valsUntyped, Kernel::EvalState * evalState, bool dummy ) const
1322 /* This continuation shall mimic the behavior Kernel::CallCont_1.
1325 typedef const Lang::Structure ArgType;
1326 RefCountPtr< ArgType > structure = Helpers::down_cast< ArgType >( valsUntyped, "Split" );
1328 const Ast::ArgListExprs * argList = structure->argList_;
1330 evalState->env_ = env_;
1331 evalState->dyn_ = dyn_;
1332 evalState->cont_ = Kernel::ContRef( new Kernel::CallCont_Structure_last( fun_, argList, structure->values_, curry_, env_, dyn_, cont_, traceLoc_ ) );
1333 RefCountPtr< Kernel::CallContInfo > callContInfo = fun_->newCallContInfo( argList, *evalState );
1335 if( callContInfo->forceNone( ) ){
1337 /* Bypass forcing.
1339 Kernel::ContRef cont = evalState->cont_;
1340 cont->takeValue( structure->values_, evalState );
1342 }else{
1344 argList->evaluate_Structure( callContInfo,
1345 structure->valueCount( ) - 1, /* Reverse index of first element in structure->values_. */
1346 structure->values_,
1347 evalState );
1352 Kernel::ContRef
1353 Kernel::SplitCont_2::up( ) const
1355 return cont_;
1358 RefCountPtr< const char >
1359 Kernel::SplitCont_2::description( ) const
1361 return strrefdup( "Split/splice" );
1364 void
1365 Kernel::SplitCont_2::gcMark( Kernel::GCMarkedSet & marked )
1367 cont_->gcMark( marked );
1371 Ast::CallSplitExpr::CallSplitExpr( const Ast::SourceLocation & loc, Ast::Expression * funExpr, Ast::Expression * argList, bool curry )
1372 : Ast::Expression( loc ), curry_( curry ), funExpr_( funExpr ), argList_( argList )
1375 Ast::CallSplitExpr::~CallSplitExpr( )
1377 delete funExpr_;
1378 delete argList_;
1382 void
1383 Ast::CallSplitExpr::analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst )
1385 funExpr_->analyze( this, env, freeStatesDst );
1386 argList_->analyze( this, env, freeStatesDst );
1389 void
1390 Ast::CallSplitExpr::eval( Kernel::EvalState * evalState ) const
1392 evalState->expr_ = funExpr_;
1393 evalState->cont_ = Kernel::ContRef( new Kernel::SplitCont_1( evalState->expr_->loc( ), argList_, curry_, *evalState, loc_ ) );
1397 Ast::DummyExpression::DummyExpression( )
1398 : Ast::Expression( Ast::THE_UNKNOWN_LOCATION )
1401 Ast::DummyExpression::DummyExpression( const Ast::SourceLocation & loc )
1402 : Ast::Expression( loc )
1405 Ast::DummyExpression::~DummyExpression( )
1408 void
1409 Ast::DummyExpression::analyze_impl( Ast::Node * parent, Ast::AnalysisEnvironment * env, Ast::StateIDSet * freeStatesDst )
1411 /* Nothing to do! */
1414 void
1415 Ast::DummyExpression::eval( Kernel::EvalState * evalState ) const
1417 throw Exceptions::InternalError( strrefdup( "A DummyExpression must never be evaluated." ) );