8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
19 module ALib.Expressions.Impl;
20 import ALib.Characters.Functions;
29#define BOL(box) (box).Unbox<bool >()
30#define INT(box) (box).Unbox<integer>()
32#define FUNC( name,...) Box name( Scope& scope, \
35 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
54SortedTypes SortedType( Type type ) {
55 if( type.IsType<
bool >() )
return SortedTypes::Bool;
56 if( type.IsType<integer>() )
return SortedTypes::Integer;
57 if( type.IsType<
double >() )
return SortedTypes::Float;
58 if( type.IsType<String >() )
return SortedTypes::String;
59 return SortedTypes::UNKNOWN;
63FUNC( castI2F ,
return double ( INT(ARG0) ); )
64FUNC( castB2F ,
return double ( BOL(ARG0) ); )
65FUNC( castB2I ,
return integer( BOL(ARG0)); )
73bool AutoCast::TryCompilation( CIAutoCast& ciAutoCast ) {
75 if ( ciAutoCast.ArgsBegin + 1 >= ciAutoCast.ArgsEnd )
79 SortedTypes t1= SortedType( * ciAutoCast.ArgsBegin );
80 SortedTypes t2= SortedType( *(ciAutoCast.ArgsBegin+1) );
85 if( t1 > t2 ) { major= t1; minor= t2; }
86 else { major= t2; minor= t1; }
90 String decompileFunctionCall;
91 ALIB_DBG(
const char* upgradeCastDBG; )
94 if( major == SortedTypes::String ) {
96 decompileFunctionCall =
A_CHAR(
"String");
97ALIB_DBG(upgradeCastDBG =
"CBToString"; )
101 else if( major == SortedTypes::Float && minor == SortedTypes::Integer ) {
102 upgradeCast = castI2F;
103 decompileFunctionCall =
A_CHAR(
"Float");
104ALIB_DBG(upgradeCastDBG =
"castI2F"; )
109 else if( major == SortedTypes::Float && minor == SortedTypes::Bool ) {
110 upgradeCast = castB2F;
111 decompileFunctionCall =
A_CHAR(
"Float");
112ALIB_DBG(upgradeCastDBG =
"castB2F"; )
117 else if( major == SortedTypes::Integer && minor == SortedTypes::Bool ) {
118 upgradeCast = castB2I;
119 decompileFunctionCall =
A_CHAR(
"Integer");
120ALIB_DBG(upgradeCastDBG =
"castB2I"; )
124 else if( major == SortedTypes::Bool ) {
126 decompileFunctionCall =
A_CHAR(
"Boolean");
127ALIB_DBG(upgradeCastDBG =
"ToBoolean"; )
135 ciAutoCast.Callback = upgradeCast;
136 ciAutoCast.TypeOrValue = *(ciAutoCast.ArgsBegin + 1);
137 ciAutoCast.ReverseCastFunctionName = decompileFunctionCall;
138ALIB_DBG(ciAutoCast.DbgCallbackName = upgradeCastDBG; )
140 ciAutoCast.CallbackRhs = upgradeCast;
141 ciAutoCast.TypeOrValueRhs = *(ciAutoCast.ArgsBegin );
142 ciAutoCast.ReverseCastFunctionNameRhs = decompileFunctionCall;
143ALIB_DBG(ciAutoCast.DbgCallbackNameRhs = upgradeCastDBG; )
147 if( ciAutoCast.IsConst && ciAutoCast.Callback !=
nullptr ) {
148 ciAutoCast.TypeOrValue = ciAutoCast.Callback( ciAutoCast.CompileTimeScope,
149 ciAutoCast.ArgsBegin ,
150 ciAutoCast.ArgsEnd - 1 );
151 ciAutoCast.Callback =
nullptr;
153 else if( ciAutoCast.RhsIsConst && ciAutoCast.CallbackRhs !=
nullptr ) {
154 ciAutoCast.TypeOrValueRhs= ciAutoCast.CallbackRhs( ciAutoCast.CompileTimeScope,
155 ciAutoCast.ArgsBegin + 1 ,
156 ciAutoCast.ArgsEnd );
157 ciAutoCast.CallbackRhs =
nullptr;
ALIB_DLL Box ToBoolean(Scope &scope, ArgIterator args, ArgIterator)
ALIB_DLL Box CBToString(Scope &scope, ArgIterator args, ArgIterator)
Box(*)(Scope &scope, ArgIterator argsBegin, ArgIterator argsEnd) CallbackDecl
platform_specific integer
expressions::CompilerPlugin CompilerPlugin
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
ALIB_DLL AutoCast(Compiler &compiler)