00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00033
00034
00035 #ifndef _XST_CONST_SCALAR_H_INCLUDED_
00036 #define _XST_CONST_SCALAR_H_INCLUDED_
00037
00039 #define const_scalar_type( T ) cttl_impl::xst_lambda_wrap< cttl_impl::xst_const_scalar< T > >
00040
00041 namespace cttl_impl {
00042
00055 template< int ValueT >
00056 struct xst_const_scalar {
00057
00058
00059 template< typename D > friend struct xst_lambda_wrap;
00060
00061
00062 template< typename L, typename R > friend struct xst_pair;
00063
00064 enum {
00066 const_value_ = ValueT,
00067
00069 depth_ = 1,
00070
00072 capacity_ = 1,
00073
00075 primitive_id_ = primitive_id_const_scalar
00076 };
00077
00079 typedef int value_T;
00080
00082 typedef int dereferenced_value_T;
00083
00085 typedef xst_const_scalar< ValueT > left_T;
00086
00088 typedef xst_const_scalar< ValueT > right_T;
00089
00091 typedef xst_const_scalar< ValueT > reference_T;
00092
00094 static reference_T make_reference()
00095 {
00096 return reference_T();
00097 }
00098
00100 template< int LocationT >
00101 static dereferenced_value_T dereferenced_value( xst_lambda_wrap< xst_const_scalar< LocationT > > )
00102 {
00103 return dereferenced_value_T();
00104 }
00105
00107
00109 left_T const& left_lambda() const
00110 {
00111 return xstatic_const_instance();
00112 }
00113
00114 right_T const& right_lambda() const
00115 {
00116 return xstatic_const_instance();
00117 }
00118
00119
00121
00123 template< typename FunctorT >
00124 static void subscript_top_down( FunctorT& functor_ )
00125 {
00126 functor_( const_scalar( 0 ) );
00127 }
00128
00129 template< typename FunctorT >
00130 static void subscript_bottom_up( FunctorT& functor_ )
00131 {
00132 functor_( const_scalar( 0 ) );
00133 }
00134
00135 template< typename FunctorT >
00136 void traverse_bottom_up( FunctorT& functor_ ) const
00137 {
00138 functor_( xstatic_const_instance() );
00139 }
00140
00141 template< typename FunctorT >
00142 void traverse_top_down( FunctorT& functor_ ) const
00143 {
00144 functor_( xstatic_const_instance() );
00145 }
00146
00147
00149
00151
00153 template<
00154 int LocationT,
00155 typename InputValueT
00156 >
00157 static void push(
00158 xst_lambda_wrap< xst_const_scalar< LocationT > >,
00159 InputValueT const& data_
00160 )
00161 {
00162 xpush_descend< depth_ - LocationT - 1 >( data_ );
00163 }
00164
00166 template<
00167 int LocationT
00168 >
00169 static void pop(
00170 xst_lambda_wrap< xst_const_scalar< LocationT > >
00171 )
00172 {
00173 xpop_descend< depth_ - LocationT - 1 >();
00174 }
00175
00177 template< int LocationT >
00178 static value_T const& top( xst_lambda_wrap< xst_const_scalar< LocationT > > )
00179 {
00180 return xstatic_const_value();
00181 }
00182
00184 template<
00185 int LocationT
00186 >
00187 static size_t size(
00188 xst_lambda_wrap< xst_const_scalar< LocationT > >
00189 )
00190 {
00191 return const_value_;
00192 }
00193
00195 template<
00196 int LocationT
00197 >
00198 static std::stack< value_T > const*
00199 stack_ptr(
00200 xst_lambda_wrap< xst_const_scalar< LocationT > >
00201 )
00202 {
00203 assert( !LocationT );
00204 return NULL;
00205 }
00206
00207 #ifdef CTTL_LAMBDA_REFLECTION
00208 typedef xst_const_scalar< ValueT > reflection_T;
00209
00210 static reflection_T reflection()
00211 {
00212 return reflection_T();
00213 }
00214 #endif // CTTL_LAMBDA_REFLECTION
00215
00216 private:
00218
00220
00222 static value_T const& xstatic_const_value()
00223 {
00224 static const value_T static_const_value = ValueT;
00225 CTTL_TRACE_DEPOSIT_TEXT( const_value_ );
00226 CTTL_TRACE_DEPOSIT_TEXT( "C " );
00227 return static_const_value;
00228 }
00229
00231 reference_T const& xstatic_const_instance() const
00232 {
00233 return *this;
00234 }
00235
00237 template< int LocationT, typename InputValueT >
00238 static void xpush_at_location( InputValueT const& )
00239 {
00240 assert( !LocationT );
00241 }
00242
00244 template< int LocationT >
00245 static void xpop_at_location()
00246 {
00247 assert( !LocationT );
00248 }
00249
00251 template< int LocationT >
00252 static value_T const& xtop_at_location()
00253 {
00254 assert( !LocationT );
00255 return xstatic_const_value();
00256 }
00257
00258
00260 template< int LocationT, typename InputValueT >
00261 static void xpush_descend( InputValueT const& data_ )
00262 {
00263
00264 xpush_at_location< LocationT >( data_ );
00265 }
00266
00268 template< int LocationT >
00269 static void xpop_descend()
00270 {
00271 xpop_at_location< LocationT >();
00272 }
00273
00275 template< int LocationT >
00276 static value_T const& xtop_descend()
00277 {
00278 return xstatic_const_value();
00279 }
00280
00282 template< typename SubscriptLambdaT, typename FunctorT >
00283 static void xsubscript_top_down_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00284 {
00285 functor_( subscript_ );
00286 }
00287
00289 template< int LocationT, typename FunctorT >
00290 static void xsubscript_top_down_descend( FunctorT& )
00291 {
00292 assert( false );
00293 }
00294
00296 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00297 static void xsubscript_top_down_subtree_descend( SubscriptLambdaT, FunctorT& )
00298 {
00299 assert( false );
00300 }
00301
00303 template< typename SubscriptLambdaT, typename FunctorT >
00304 static void xsubscript_bottom_up_subtree_switch( SubscriptLambdaT subscript_, FunctorT& functor_ )
00305 {
00306 functor_( subscript_ );
00307 }
00308
00310 template< int LocationT, typename FunctorT >
00311 static void xsubscript_bottom_up_descend( FunctorT& )
00312 {
00313 assert( false );
00314 }
00315
00317 template< int LocationT, typename SubscriptLambdaT, typename FunctorT >
00318 static void xsubscript_bottom_up_subtree_descend( SubscriptLambdaT, FunctorT& )
00319 {
00320 assert( false );
00321 }
00322
00324 template< typename SubscriptLambdaT, typename InputValueT >
00325 static void xpush_sub_split( SubscriptLambdaT, InputValueT const& )
00326 {
00327 assert( false );
00328 }
00329
00331 template< int LocationT, typename SubscriptLambdaT, typename InputValueT >
00332 static void xpush_sub_descend( SubscriptLambdaT, InputValueT const& )
00333 {
00334 assert( false );
00335 }
00336
00338 template< typename SubscriptLambdaT >
00339 static void xpop_sub_split( SubscriptLambdaT )
00340 {
00341 assert( false );
00342 }
00343
00345 template< int LocationT, typename SubscriptLambdaT >
00346 static void xpop_sub_descend( SubscriptLambdaT )
00347 {
00348 assert( false );
00349 }
00350
00351
00353 template< typename SubscriptLambdaT >
00354 static value_T const& xtop_sub_split( SubscriptLambdaT )
00355 {
00356 assert( false );
00357 return xstatic_const_value();
00358 }
00359
00361 template< int LocationT, typename SubscriptLambdaT >
00362 static value_T const& xtop_sub_descend( SubscriptLambdaT )
00363 {
00364 assert( false );
00365 return xstatic_const_value();
00366 }
00367
00368
00370 template< int LocationT >
00371 static size_t xsize_at_location()
00372 {
00373 assert( !LocationT );
00374 return const_value_;
00375 }
00376
00378 template< int LocationT >
00379 static size_t xsize_descend()
00380 {
00381 assert( !LocationT );
00382 return const_value_;
00383 }
00384
00386 template< typename SubscriptLambdaT >
00387 static size_t xsize_sub_split( SubscriptLambdaT )
00388 {
00389 assert( false );
00390 return const_value_;
00391 }
00392
00394 template< int LocationT, typename SubscriptLambdaT >
00395 static size_t xsize_sub_descend( SubscriptLambdaT )
00396 {
00397 assert( false );
00398 return const_value_;
00399 }
00400
00401
00403
00405
00407 template< int LocationT >
00408 static std::stack< value_T > const* xstack_ptr_at_location()
00409 {
00410 assert( !LocationT );
00411 return NULL;
00412 }
00413
00415 template< int LocationT >
00416 static std::stack< value_T > const* xstack_ptr_descend()
00417 {
00418 assert( !LocationT );
00419 return NULL;
00420 }
00421
00423 template< typename SubscriptLambdaT >
00424 static std::stack< value_T > const* xstack_ptr_sub_split( SubscriptLambdaT )
00425 {
00426 assert( false );
00427 return NULL;
00428 }
00429
00431 template< int LocationT, typename SubscriptLambdaT >
00432 static std::stack< value_T > const* xstack_ptr_sub_descend( SubscriptLambdaT )
00433 {
00434 assert( false );
00435 return NULL;
00436 }
00437
00438
00440
00442
00451 template< typename TargetLambdaT >
00452 static void xinstruction_opcode( TargetLambdaT& )
00453 {
00454 CTTL_TRACE_DEPOSIT_JUSTIFY();
00455 CTTL_TRACE_DEPOSIT_TEXT( ';' );
00456 CTTL_TRACE_DEPOSIT_TEXT( std::endl );
00457 }
00458
00460 template< int OpcodeT, typename TargetLambdaT >
00461 static void xinstruction_1st( TargetLambdaT& lambda_ )
00462 {
00463 xst_instruction_1_operand< const_value_, OpcodeT >::instruction( lambda_ );
00464 CTTL_TRACE_DEPOSIT_JUSTIFY();
00465 CTTL_TRACE_DEPOSIT_TEXT( ';' );
00466 CTTL_TRACE_DEPOSIT_TEXT( std::endl );
00467 }
00468
00470 template< int OpcodeT, int FirstOperandT, typename TargetLambdaT >
00471 static void xinstruction_2nd( TargetLambdaT& lambda_ )
00472 {
00473 xst_instruction_2_operand< FirstOperandT, const_value_, OpcodeT >::instruction( lambda_ );
00474 CTTL_TRACE_DEPOSIT_JUSTIFY();
00475 CTTL_TRACE_DEPOSIT_TEXT( ';' );
00476 CTTL_TRACE_DEPOSIT_TEXT( std::endl );
00477 }
00478
00479 };
00480
00481 }
00482
00483
00484 #endif //_XST_CONST_SCALAR_H_INCLUDED_