14#define ARG1 (*(args+1))
15#define BOL(box) (box).Unbox<bool >()
16#define INT(box) (box).Unbox<integer>()
17#define ITF(box) static_cast<double>((box).Unbox<integer>() )
18#define BTF(box) static_cast<double>((box).Unbox<bool >() )
19#define FLT(box) (box).Unbox<double >()
20#define FUNC( name,...) Box name( Scope& scope, \
23 { (void) scope; (void) args; (void) end; __VA_ARGS__ }
25#if !ALIB_FEAT_BOXING_BIJECTIVE_INTEGRALS
26# define TOINT(arg) arg
28# define TOINT(arg) static_cast<integer>(arg)
32namespace alib {
namespace expressions {
namespace plugins {
45Box constFalse =
false;
46Box identity =
nullptr;
47Box bool_false =
false;
58FUNC( toInt_B ,
return static_cast<integer>(BOL(ARG0)); )
59FUNC( toInt_I ,
return ARG0; )
60FUNC( toInt_F ,
return static_cast<integer>(FLT(ARG0)); )
61FUNC( toFloat_B,
return static_cast<double >(BOL(ARG0)); )
62FUNC( toFloat_I,
return static_cast<double >(INT(ARG0)); )
63FUNC( toFloat_F,
return ARG0; )
65FUNC( arrLen,
return ARG0.UnboxLength(); )
72FUNC( pos , return ARG0; )
73FUNC( pos_B , return static_cast<
integer>(BOL(ARG0)); )
74FUNC( neg_B , return -static_cast<
integer>(BOL(ARG0)); )
75FUNC( neg_I , return -INT(ARG0); )
76FUNC( neg_F , return -FLT(ARG0); )
77FUNC( bitNot , return ~INT(ARG0); )
78FUNC( boolNot_B, return !BOL(ARG0); )
79FUNC( boolNot_I, return INT(ARG0) == static_cast<
integer>(0); )
80FUNC( boolNot_F, return FLT(ARG0) == 0.0; )
88 #pragma warning( push )
89 #pragma warning( disable : 4804 )
90 #pragma warning( disable : 4805 )
93FUNC( mul_BB,
return BOL(ARG0) * BOL(ARG1) ; )
94FUNC( mul_BI,
return BOL(ARG0) * INT(ARG1) ; )
95FUNC( mul_BF,
return BOL(ARG0) * FLT(ARG1) ; )
96FUNC( mul_IB,
return INT(ARG0) * BOL(ARG1) ; )
97FUNC( mul_II,
return INT(ARG0) * INT(ARG1) ; )
98FUNC( mul_IF,
return ITF(ARG0) * FLT(ARG1) ; )
99FUNC( mul_FB,
return FLT(ARG0) * BTF(ARG1) ; )
100FUNC( mul_FI,
return FLT(ARG0) * ITF(ARG1) ; )
101FUNC( mul_FF,
return FLT(ARG0) * FLT(ARG1) ; )
102FUNC( div_BI,
return BOL(ARG0) / INT(ARG1) ; )
103FUNC( div_BF,
return BOL(ARG0) / FLT(ARG1) ; )
104FUNC( div_II,
return INT(ARG0) / INT(ARG1) ; )
105FUNC( div_IF,
return ITF(ARG0) / FLT(ARG1) ; )
106FUNC( div_FI,
return FLT(ARG0) / ITF(ARG1) ; )
107FUNC( div_FF,
return FLT(ARG0) / FLT(ARG1) ; )
108FUNC( mod_BI,
return BOL(ARG0) % INT(ARG1) ; )
109FUNC( mod_II,
return INT(ARG0) % INT(ARG1) ; )
110FUNC( mod_BF,
return fmod(BOL(ARG0), FLT(ARG1)); )
111FUNC( mod_FI,
return fmod(FLT(ARG0), INT(ARG1)); )
112FUNC( mod_IF,
return fmod(INT(ARG0), FLT(ARG1)); )
113FUNC( mod_FF,
return fmod(FLT(ARG0), FLT(ARG1)); )
115FUNC( add_BB,
return BOL(ARG0) + BOL(ARG1) ; )
116FUNC( add_BI,
return BOL(ARG0) + INT(ARG1) ; )
117FUNC( add_BF,
return BOL(ARG0) + FLT(ARG1) ; )
118FUNC( add_IB,
return INT(ARG0) + BOL(ARG1) ; )
119FUNC( add_II,
return INT(ARG0) + INT(ARG1) ; )
120FUNC( add_IF,
return ITF(ARG0) + FLT(ARG1) ; )
121FUNC( add_FB,
return FLT(ARG0) + BOL(ARG1) ; )
122FUNC( add_FI,
return FLT(ARG0) + ITF(ARG1) ; )
123FUNC( add_FF,
return FLT(ARG0) + FLT(ARG1) ; )
124FUNC( sub_BB,
return BOL(ARG0) - BOL(ARG1) ; )
125FUNC( sub_BI,
return BOL(ARG0) - INT(ARG1) ; )
126FUNC( sub_BF,
return BOL(ARG0) - FLT(ARG1) ; )
127FUNC( sub_IB,
return INT(ARG0) - BOL(ARG1) ; )
128FUNC( sub_II,
return INT(ARG0) - INT(ARG1) ; )
129FUNC( sub_IF,
return ITF(ARG0) - FLT(ARG1) ; )
130FUNC( sub_FB,
return FLT(ARG0) - BOL(ARG1) ; )
131FUNC( sub_FI,
return FLT(ARG0) - ITF(ARG1) ; )
132FUNC( sub_FF,
return FLT(ARG0) - FLT(ARG1) ; )
134FUNC( shfL_BI,
return TOINT( BOL(ARG0) << INT(ARG1) ); )
135FUNC( shfL_IB,
return INT(ARG0) << BOL(ARG1) ; )
136FUNC( shfL_II,
return INT(ARG0) << INT(ARG1) ; )
137FUNC( shfR_BI,
return TOINT( BOL(ARG0) << INT(ARG1) ); )
138FUNC( shfR_IB,
return INT(ARG0) << BOL(ARG1) ; )
139FUNC( shfR_II,
return INT(ARG0) >> INT(ARG1) ; )
141FUNC( sm_BB,
return BOL(ARG0) < BOL(ARG1) ; )
142FUNC( sm_BI,
return BOL(ARG0) < INT(ARG1) ; )
143FUNC( sm_BF,
return isless(
static_cast<double>(BOL(ARG0)), FLT(ARG1) ); )
144FUNC( sm_IB,
return INT(ARG0) < BOL(ARG1) ; )
145FUNC( sm_II,
return INT(ARG0) < INT(ARG1) ; )
146FUNC( sm_IF,
return isless(
static_cast<double>(INT(ARG0)), FLT(ARG1) ); )
147FUNC( sm_FB,
return isless( FLT(ARG0) ,
static_cast<double>(BOL(ARG1))); )
148FUNC( sm_FI,
return isless( FLT(ARG0) ,
static_cast<double>(INT(ARG1))); )
149FUNC( sm_FF,
return isless( FLT(ARG0) , FLT(ARG1) ); )
150FUNC( smeq_BB,
return BOL(ARG0) <= BOL(ARG1) ; )
151FUNC( smeq_BI,
return BOL(ARG0) <= INT(ARG1) ; )
152FUNC( smeq_BF,
return islessequal(
static_cast<double>(BOL(ARG0)), FLT(ARG1) ); )
153FUNC( smeq_IB,
return INT(ARG0) <= BOL(ARG1) ; )
154FUNC( smeq_II,
return INT(ARG0) <= INT(ARG1) ; )
155FUNC( smeq_IF,
return islessequal(
static_cast<double>(INT(ARG0)), FLT(ARG1) ); )
156FUNC( smeq_FB,
return islessequal( FLT(ARG0) ,
static_cast<double>(BOL(ARG1))); )
157FUNC( smeq_FI,
return islessequal( FLT(ARG0) ,
static_cast<double>(INT(ARG1))); )
158FUNC( smeq_FF,
return islessequal( FLT(ARG0) , FLT(ARG1) ); )
159FUNC( gt_BB,
return BOL(ARG0) > BOL(ARG1) ; )
160FUNC( gt_BI,
return BOL(ARG0) > INT(ARG1) ; )
161FUNC( gt_BF,
return isgreater(
static_cast<double>(BOL(ARG0)), FLT(ARG1) ); )
162FUNC( gt_IB,
return INT(ARG0) > BOL(ARG1) ; )
163FUNC( gt_II,
return INT(ARG0) > INT(ARG1) ; )
164FUNC( gt_IF,
return isgreater(
static_cast<double>(INT(ARG0)), FLT(ARG1) ); )
165FUNC( gt_FB,
return isgreater( FLT(ARG0) ,
static_cast<double>(BOL(ARG1))); )
166FUNC( gt_FI,
return isgreater( FLT(ARG0) ,
static_cast<double>(INT(ARG1))); )
167FUNC( gt_FF,
return isgreater( FLT(ARG0) , FLT(ARG1) ); )
168FUNC( gteq_BB,
return BOL(ARG0) >= BOL(ARG1) ; )
169FUNC( gteq_BI,
return BOL(ARG0) >= INT(ARG1) ; )
170FUNC( gteq_BF,
return isgreaterequal(
static_cast<double>(BOL(ARG0)), FLT(ARG1) ); )
171FUNC( gteq_IB,
return INT(ARG0) >= BOL(ARG1) ; )
172FUNC( gteq_II,
return INT(ARG0) >= INT(ARG1) ; )
173FUNC( gteq_IF,
return isgreaterequal(
static_cast<double>(INT(ARG0)), FLT(ARG1) ); )
174FUNC( gteq_FB,
return isgreaterequal( FLT(ARG0) ,
static_cast<double>(BOL(ARG1))); )
175FUNC( gteq_FI,
return isgreaterequal( FLT(ARG0) ,
static_cast<double>(INT(ARG1))); )
176FUNC( gteq_FF,
return isgreaterequal( FLT(ARG0) , FLT(ARG1) ); )
178FUNC( eq_BB,
return BOL(ARG0) == BOL(ARG1) ; )
179FUNC( eq_BI,
return BOL(ARG0) == INT(ARG1) ; )
180FUNC( eq_BF,
return std::fabs( BOL(ARG0) - FLT(ARG1) ) <= std::numeric_limits<double>::epsilon(); )
181FUNC( eq_IB,
return INT(ARG0) == BOL(ARG1) ; )
182FUNC( eq_II,
return INT(ARG0) == INT(ARG1) ; )
183FUNC( eq_IF,
return std::fabs( ITF(ARG0) - FLT(ARG1) ) <= std::numeric_limits<double>::epsilon(); )
184FUNC( eq_FB,
return std::fabs( FLT(ARG0) - BOL(ARG1) ) <= std::numeric_limits<double>::epsilon(); )
185FUNC( eq_FI,
return std::fabs( FLT(ARG0) - ITF(ARG1) ) <= std::numeric_limits<double>::epsilon(); )
186FUNC( eq_FF,
return std::fabs( FLT(ARG0) - FLT(ARG1) ) <= std::numeric_limits<double>::epsilon(); )
190FUNC( neq_BB,
return BOL(ARG0) != BOL(ARG1) ; )
191FUNC( neq_BI,
return BOL(ARG0) != INT(ARG1) ; )
192FUNC( neq_BF,
return std::fabs( BOL(ARG0) - FLT(ARG1) ) > std::numeric_limits<double>::epsilon(); )
193FUNC( neq_IB,
return INT(ARG0) != BOL(ARG1) ; )
194FUNC( neq_II,
return INT(ARG0) != INT(ARG1) ; )
195FUNC( neq_IF,
return std::fabs( INT(ARG0) - INT(ARG1) ) > std::numeric_limits<double>::epsilon(); )
196FUNC( neq_FB,
return std::fabs( FLT(ARG0) - BOL(ARG1) ) > std::numeric_limits<double>::epsilon(); )
197FUNC( neq_FI,
return std::fabs( FLT(ARG0) - ITF(ARG1) ) > std::numeric_limits<double>::epsilon(); )
198FUNC( neq_FF,
return std::fabs( FLT(ARG0) - FLT(ARG1) ) > std::numeric_limits<double>::epsilon(); )
201FUNC( bitAnd,
return INT(ARG0) & INT(ARG1) ; )
202FUNC( bitXOr,
return INT(ARG0) ^ INT(ARG1) ; )
203FUNC( bitOr ,
return INT(ARG0) | INT(ARG1) ; )
204FUNC( boolAnd_BB,
return BOL(ARG0) && BOL(ARG1) ; )
205FUNC( boolAnd_BI,
return BOL(ARG0) && INT(ARG1) != 0 ; )
206FUNC( boolAnd_BF,
return BOL(ARG0) && FLT(ARG1) != 0.0 ; )
207FUNC( boolAnd_IB,
return INT(ARG0) != 0 && BOL(ARG1) ; )
208FUNC( boolAnd_II,
return INT(ARG0) != 0 && INT(ARG1) != 0 ; )
209FUNC( boolAnd_IF,
return INT(ARG0) != 0 && FLT(ARG1) != 0.0 ; )
210FUNC( boolAnd_FB,
return FLT(ARG0) != 0.0 && BOL(ARG1) ; )
211FUNC( boolAnd_FI,
return FLT(ARG0) != 0.0 && INT(ARG1) != 0 ; )
212FUNC( boolAnd_FF,
return FLT(ARG0) != 0.0 && FLT(ARG1) != 0.0 ; )
213FUNC( boolOr_BB,
return BOL(ARG0) || BOL(ARG1) ; )
214FUNC( boolOr_BI,
return BOL(ARG0) || INT(ARG1) != 0 ; )
215FUNC( boolOr_BF,
return BOL(ARG0) || FLT(ARG1) != 0.0 ; )
216FUNC( boolOr_IB,
return INT(ARG0) != 0 || BOL(ARG1) ; )
217FUNC( boolOr_II,
return INT(ARG0) != 0 || INT(ARG1) != 0 ; )
218FUNC( boolOr_IF,
return INT(ARG0) != 0 || FLT(ARG1) != 0.0 ; )
219FUNC( boolOr_FB,
return FLT(ARG0) != 0.0 || BOL(ARG1) ; )
220FUNC( boolOr_FI,
return FLT(ARG0) != 0.0 || INT(ARG1) != 0 ; )
221FUNC( boolOr_FF,
return FLT(ARG0) != 0.0 || FLT(ARG1) != 0.0 ; )
224 #pragma warning( pop )
433 constexpr int tableSize= 9;
434 Token functionNames[tableSize];
435 Token::LoadResourcedTokens( EXPRESSIONS,
"CPA", functionNames
438 Token* descriptor= functionNames;
441 { *descriptor++, constTrue },
442 { *descriptor++, constFalse },
443 { *descriptor++, constTrue },
444 { *descriptor++, constFalse },
445 { *descriptor++, constTrue },
446 { *descriptor++, constFalse },
460 AddOperators( OperatorTable );
462 if(
HasBits(compiler.CfgCompilation, Compilation::AllowBitwiseBooleanOperators ) )
464 AddOperatorAliases( bitwiseOpsAliasBooleanOps );
465 AddOperatorAlias (
A_CHAR(
"~"), Types::Boolean, Types::Void,
A_CHAR(
"!") );
468 AddBinaryOpOptimizations( binaryOperatorOptimizations);
471 "Descriptor table size mismatch: Consumed {} descriptors, {} available.",
472 descriptor - functionNames, tableSize)
476bool Arithmetics::TryCompilation( CIFunction& ciFunction )
478 if( Calculus::TryCompilation( ciFunction ) )
481 if( ciFunction.QtyArgs() == 1 && ciFunction.ArgsBegin->IsArray() )
483 constexpr int tableSize= 1;
484 Token functionNames[tableSize];
486 Token::LoadResourcedTokens( EXPRESSIONS,
"CPALen", functionNames
489 if( functionNames[0].Match( ciFunction.Name ) )
491 ciFunction.Name.Reset( functionNames[0] );
492ALIB_DBG( ciFunction.DbgCallbackName =
"arrLen"; )
495 if( ciFunction.AllArgsAreConst )
497 ciFunction.TypeOrValue = ciFunction.ArgsBegin->UnboxLength();
501 ciFunction.Callback = arrLen;
502 ciFunction.TypeOrValue = Types::Integer;
520#undef BIN_ALIAS_ENTRY
decltype(std::declval< typename TFDecl::Signature >()(std::declval< Box & >(), std::declval< TArgs >()...)) Call(TArgs &&... args) const
#define ALIB_WARNINGS_RESTORE
#define CALCULUS_CALLBACK(func)
#define CALCULUS_SIGNATURE(BoxPointerArray)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
constexpr bool HasBits(TEnum element, TEnum selection) noexcept
ALIB_API Box ToBoolean(Scope &scope, ArgIterator args, ArgIterator)
@ Arithmetics
Collection of built-in unary and binary operators for boolean, integer and floating point values.
@ Right
Denotes the right side of something.
@ Left
Denotes the left side of something.
expressions::plugins::Calculus Calculus
Type alias in namespace alib.
boxing::FIsTrue FIsTrue
Type alias in namespace alib.
strings::util::Token Token
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
expressions::Compiler Compiler
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
static ALIB_API Box Void
Sample type-box for C++ type void.
static ALIB_API Box Integer
Sample type-box for integer types. (Precisely for type integer.)
static ALIB_API Box Boolean
Sample type-box for C++ type bool.
static ALIB_API Box Float
Sample type-box for C++ type double.
ALIB_API Arithmetics(Compiler &compiler)
const std::tuple< String, Type, Type, CallbackDecl, Type, CTInvokable > OperatorTableEntry
static constexpr CTInvokable CTI
const std::tuple< String, lang::Side, Type, const Box &, const Box & > BinaryOpOptimizationsTableEntry
const std::tuple< String, Type, Type, String > OperatorAliasTableEntry