ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
Arithmetics Struct Reference

Description:


This built-in CompilerPlugin of ALib Expressions primarily compiles unary and binary operators for permutations of types Boolean, Integer and Float.

By default, this plug-in is automatically created and inserted into each instance of class Compiler with the invocation of SetupDefaults.

General Notes:

  • All identifier and function names are defined case insensitive.
  • All callback functions are defined compile-time invokable. This means that redundancies in expressions emerging from operations on constant numbers are optimized (pruned) by the compiler. For example, the two expressions:
          size > 81920
          size > 8 * 1024
    are resulting in an identical expression program and thus the latter has no evaluation penalty.
  • The following additional binary operator optimization are defined:
    • Addition and subtraction of 0.
    • Multiplication by 0 and 1.
    • Division by 1.
    • Modulo by 1.
    • Boolean or with true and false.
    • Boolean and with true and false.
  • Dependent on configuration flags of the given Compiler, the following alias operators are defined:

Constant Identifiers:
The following constant identifiers provide variants for boolean values. No abbreviation is allowed.


Return Type Name Description
Boolean True Returns constant true.
Boolean False Returns constant false.
Boolean Yes Returns constant true.
Boolean No Returns constant false.
Boolean On Returns constant true.
Boolean Off Returns constant false.


Type Conversion Functions:

Return Type Name Min. Abbreviation Signature Description
Boolean Boolean bool <any> Converts any type of boxed value by invoking box-function FIsTrue.
Integer Integer int Boolean Converts true to 1, false to 0.
Integer Integer int Integer Does nothing (identity function).
Integer Integer int Float Returns the integral part of a floating point number.
Float Float float Boolean Converts true to 1.0, false to 0.0.
Float Float float Integer Converts an integral value to floating point.
Float Float float Float Does nothing (identity function).


Functions:

Return Type Name Min. Abbreviation Signature Description
Integer Length len <any array> Returns the length of an array.
Note
Because built-in type String is a boxed character array, this function can be used to determine the length of strings.


Unary Operators:

Return Type Operator Argument Type Description
Integer + Boolean Converts the boolean value to integer.
Integer + Integer Identity operator (has no effect).
Float + Float Identity operator (has no effect).
Integer - Boolean Converts the boolean value to integer and negates it.
Integer - Integer Negates an integral value.
Float - Float Negates a floating point value.
Boolean ! Boolean Boolean not operator.
Boolean ! Integer Returns the result of the comparison with 0.
Boolean ! Float Returns the result of the comparison with 0.0.
Integer ~ Integer Bitwise integral negation.


Binary Operators:

Return Type Lhs Type Operator Rhs Type Description
Integer Boolean * Boolean Multiplication with interpreting both boolean operands as integral value 0 or 1.
Integer Boolean * Integer Multiplication with interpreting the boolean operand as integral value 0 or 1.
Float Boolean * Float Multiplication with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer * Boolean Multiplication with interpreting the boolean operand as integral value 0 or 1.
Integer Integer * Integer Multiplication.
Float Integer * Float Multiplication.
Float Float * Boolean Multiplication with interpreting the boolean operand as floating point value 0.0 or 1.0.
Float Float * Integer Multiplication.
Float Float * Float Multiplication.
Integer Boolean / Integer Division with interpreting the boolean operand as integral value 0 or 1.
Float Boolean / Float Division with interpreting the boolean operand as integral value 0 or 1.
Integer Integer / Integer Division.
Float Integer / Float Division.
Float Float / Integer Division.
Float Float / Float Division.
Integer Boolean % Integer Modulo with interpreting the boolean operand as integral value 0 or 1.
Float Boolean % Float Modulo with interpreting the boolean operand as integral value 0 or 1.
Integer Integer % Integer Modulo.
Float Integer % Float Modulo.
Float Float % Integer Modulo.
Float Float % Float Modulo.
Integer Boolean + Boolean Addition with interpreting both boolean operands as integral value 0 or 1.
Integer Boolean + Integer Addition with interpreting the boolean operand as integral value 0 or 1.
Float Boolean + Float Addition with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer + Boolean Addition with interpreting the boolean operand as integral value 0 or 1.
Integer Integer + Integer Addition.
Float Integer + Float Addition.
Float Float + Boolean Addition with interpreting the boolean operand as floating point value 0.0 or 1.0.
Float Float + Integer Addition.
Float Float + Float Addition.
Integer Boolean - Boolean Subtraction with interpreting both boolean operands as integral value 0 or 1.
Integer Boolean - Integer Subtraction with interpreting the boolean operand as integral value 0 or 1.
Float Boolean - Float Subtraction with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer - Boolean Subtraction with interpreting the boolean operand as integral value 0 or 1.
Integer Integer - Integer Subtraction.
Float Integer - Float Subtraction.
Float Float - Boolean Subtraction with interpreting the boolean operand as floating point value 0.0 or 1.0.
Float Float - Integer Subtraction.
Float Float - Float Subtraction.
Integer Boolean << Integer Bitwise shift left with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer << Boolean Bitwise shift left with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer << Integer Bitwise shift left.
Integer Boolean >> Integer Bitwise shift right with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer >> Boolean Bitwise shift right with interpreting the boolean operand as floating point value 0.0 or 1.0.
Integer Integer >> Integer Bitwise shift right.
Boolean Boolean < Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean < Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean < Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer < Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer < Integer Comparison operator.
Boolean Integer < Float Comparison operator.
Boolean Float < Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float < Integer Comparison operator.
Boolean Float < Float Comparison operator.
Boolean Boolean <= Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean <= Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean <= Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer <= Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer <= Integer Comparison operator.
Boolean Integer <= Float Comparison operator.
Boolean Float <= Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float <= Integer Comparison operator.
Boolean Float <= Float Comparison operator.
Boolean Boolean > Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean > Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean > Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer > Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer > Integer Comparison operator.
Boolean Integer > Float Comparison operator.
Boolean Float > Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float > Integer Comparison operator.
Boolean Float > Float Comparison operator.
Boolean Boolean >= Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean >= Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean >= Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer >= Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer >= Integer Comparison operator.
Boolean Integer >= Float Comparison operator.
Boolean Float >= Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float >= Integer Comparison operator.
Boolean Float >= Float Comparison operator.
Boolean Boolean == Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean == Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean == Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer == Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer == Integer Comparison operator.
Boolean Integer == Float Comparison operator.
Boolean Float == Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float == Integer Comparison operator.
Boolean Float == Float Comparison operator.
Boolean Boolean != Boolean Comparison operator with interpreting both boolean operands as integral value 0 or 1.
Boolean Boolean != Integer Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Boolean != Float Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Integer != Boolean Comparison operator with interpreting the boolean operand as integral value 0 or 1.
Boolean Integer != Integer Comparison operator.
Boolean Integer != Float Comparison operator.
Boolean Float != Boolean Comparison operator with interpreting the boolean operand as floating point value 0.0 or 1.0.
Boolean Float != Integer Comparison operator.
Boolean Float != Float Comparison operator.
Integer Integer & Integer Bitwise boolean "and" operator.
Integer Integer | Integer Bitwise boolean "or" operator.
Integer Integer ^ Integer Bitwise boolean "xor" operator.
Boolean Boolean && Boolean Logical boolean "and" operator.
Boolean Boolean && Integer Logical boolean "and" operator. The integral operand is tested for a non-zero value.
Boolean Boolean && Float Logical boolean "and" operator. The floating point operand is tested for a non-zero value.
Boolean Integer && Boolean Logical boolean "and" operator. The integral operand is tested for a non-zero value.
Boolean Integer && Integer Logical boolean "and" operator. The integral operands are tested for a non-zero value.
Boolean Integer && Float Logical boolean "and" operator. The integral and floating point operands are tested for a non-zero value.
Boolean Float && Boolean Logical boolean "and" operator. The floating point operand is tested for a non-zero value.
Boolean Float && Integer Logical boolean "and" operator. The integral and floating point operands are tested for a non-zero value.
Boolean Float && Float Logical boolean "and" operator. The floating point operands are tested for a non-zero value.
Boolean Boolean || Boolean Logical boolean "or" operator.
Boolean Boolean || Integer Logical boolean "or" operator. The integral operand is tested for a non-zero value.
Boolean Boolean || Float Logical boolean "or" operator. The floating point operand is tested for a non-zero value.
Boolean Integer || Boolean Logical boolean "or" operator. The integral operand is tested for a non-zero value.
Boolean Integer || Integer Logical boolean "or" operator. The integral operands are tested for a non-zero value.
Boolean Integer || Float Logical boolean "or" operator. The integral and floating point operands are tested for a non-zero value.
Boolean Float || Boolean Logical boolean "or" operator. The floating point operand is tested for a non-zero value.
Boolean Float || Integer Logical boolean "or" operator. The integral and floating point operands are tested for a non-zero value.
Boolean Float || Float Logical boolean "or" operator. The floating point operands are tested for a non-zero value.

Definition at line 231 of file arithmetics.hpp.

#include <arithmetics.hpp>

Inheritance diagram for Arithmetics:
[legend]
Collaboration diagram for Arithmetics:
[legend]

Public Method Index:

ALIB_API Arithmetics (Compiler &compiler)
 
virtual ~Arithmetics () override
 Virtual destructor.
 
virtual ALIB_API bool TryCompilation (CIFunction &ciFunction) override
 
- Public Method Index: inherited from Calculus
 Calculus (const NString &name, Compiler &compiler, CompilePriorities pPriority)
 
virtual ~Calculus () override
 Virtual destructor.
 
ALIB_API void AddBinaryOpOptimizations (BinaryOpOptimizationsTableEntry *table, size_t length)
 
template<size_t TCapacity>
void AddBinaryOpOptimizations (BinaryOpOptimizationsTableEntry(&table)[TCapacity])
 
void AddOperator (const String &op, Type lhsType, Type rhsType, CallbackDecl callback, const char *dbgCallbackName, Type resultType, CTInvokable cti)
 
void AddOperatorAlias (const String &alias, Type lhsType, Type rhsType, const String &op)
 
void AddOperatorAliases (OperatorAliasTableEntry *table, size_t length)
 
template<size_t TCapacity>
void AddOperatorAliases (OperatorAliasTableEntry(&table)[TCapacity])
 
ALIB_API void AddOperators (OperatorTableEntry *table, size_t length)
 
template<size_t TCapacity>
void AddOperators (OperatorTableEntry(&table)[TCapacity])
 
virtual ALIB_API bool TryCompilation (CIAutoCast &autoCast) override
 
virtual ALIB_API bool TryCompilation (CIBinaryOp &ciBinaryOp) override
 
virtual ALIB_API bool TryCompilation (CIUnaryOp &ciUnaryOp) override
 
- Public Method Index: inherited from CompilerPlugin
 CompilerPlugin (const NString &name, Compiler &compiler, CompilePriorities pPriority)
 
virtual ~CompilerPlugin ()
 Virtual destructor.
 
- Public Method Index: inherited from Plugin< Compiler, CompilePriorities >
PrioritiesType GetPriority () const
 

Additional Inherited Members

- Public Type Index: inherited from Calculus
using BinaryOpOptimizationsTableEntry = const std::tuple<String, lang::Side, Type, const Box&, const Box&>
 
using CTInvokable = bool
 
using OperatorAliasTableEntry = const std::tuple<String, Type, Type, String>
 
using OperatorTableEntry
 
- Public Type Index: inherited from Plugin< Compiler, CompilePriorities >
using PluginType
 This exposes the template parameter TPlugin to the outer world.
 
using PrioritiesType
 This exposes the template parameter pTPlugin to the outer world.
 
- Public Static Field Index: inherited from Calculus
static constexpr CTInvokable CTI = true
 
static constexpr CTInvokable ETI = false
 
- Public Field Index: inherited from Calculus
MonoAllocator allocator
 
std::vector< AutoCastEntryAutoCasts
 List of auto-casts to be compiled by this plug-in.
 
HashMap< MonoAllocator, BinOpOptKey, Box, BinOpOptKey::Hash, BinOpOptKey::EqualToBinaryOperatorOptimizations
 
std::vector< ConstantIdentifierEntryConstantIdentifiers
 List of identifiers that return constant values to be compiled by this plug-in.
 
std::vector< FunctionEntryFunctions
 List of functions to be compiled by this plug-in.
 
HashMap< MonoAllocator, OperatorKey, String, OperatorKey::Hash, OperatorKey::EqualToOperatorAliases
 
HashMap< MonoAllocator, OperatorKey, std::tuple< CallbackDecl, Box, CTInvokable ALIB_DBG(, const char *) >, OperatorKey::Hash, OperatorKey::EqualToOperators
 
- Public Field Index: inherited from CompilerPlugin
CompilerCmplr
 The compiler that this plug-in is attached to.
 
const NString Name
 
- Protected Field Index: inherited from Plugin< Compiler, CompilePriorities >
PrioritiesType priority
 The priority of this plug-in.
 
- Protected Method Index: inherited from Plugin< Compiler, CompilePriorities >
 Plugin (PrioritiesType pPriority)
 

Constructor(s) / Destructor Details:

◆ Arithmetics()

ALIB_API Arithmetics ( Compiler & compiler)

Constructor. Creates the hash maps.

Parameters
compilerThe compiler we will get attached to.

◆ ~Arithmetics()

virtual ~Arithmetics ( )
inlineoverridevirtual

Virtual destructor.

Definition at line 242 of file arithmetics.hpp.

Method Details:

◆ TryCompilation()

virtual ALIB_API bool TryCompilation ( CIFunction & ciFunction)
overridevirtual

Invokes parent's method. On failure, tries to compile function Length(array).

Parameters
[in,out]ciFunctionThe compilation information.
Returns
true if an entry was found. false otherwise.

Reimplemented from Calculus.


The documentation for this struct was generated from the following file: