42#ifndef COMPILER_OPERATOR_H
43#define COMPILER_OPERATOR_H
347 const long long rhs)
noexcept
350 constexpr long long max = std::numeric_limits<long long>::max();
351 constexpr long long min = std::numeric_limits<long long>::min();
356 if ((rhs > 0
and lhs >
max - rhs) or (rhs < 0
and lhs <
min - rhs))
357 return {Status::Overflow, 0};
358 return {Status::Ok, lhs + rhs};
361 if ((rhs < 0 and lhs >
max + rhs) or (rhs > 0
and lhs <
min + rhs))
362 return {Status::Overflow, 0};
363 return {Status::Ok, lhs - rhs};
366 if (lhs > 0 ? (rhs > 0 ? lhs >
max / rhs : rhs <
min / lhs)
367 : (rhs > 0 ? lhs <
min / rhs : lhs != 0
and rhs <
max / lhs))
368 return {Status::Overflow, 0};
369 return {Status::Ok, lhs * rhs};
373 return {Status::Division_By_Zero, 0};
374 if (lhs ==
min and rhs == -1)
375 return {Status::Overflow, 0};
376 return {Status::Ok, lhs / rhs};
380 return {Status::Modulo_By_Zero, 0};
382 return {Status::Ok, 0};
383 return {Status::Ok, lhs % rhs};
386 return {Status::Ok, lhs & rhs};
389 return {Status::Ok, lhs | rhs};
392 return {Status::Ok, lhs ^ rhs};
398 assert(
false and "compiler_integer_binary(): not an integer operator");
399 return {Status::Overflow, 0};
410 if (operand == std::numeric_limits<long long>::min())
Token model and parser-facing metadata for compiler front-ends.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
@ Invalid
Uninitialized register/slot or explicit invalid placeholder.
const char * compiler_operator_name(const Compiler_Operator_Kind kind) noexcept
Returns a stable debug name for one operator kind.
Compiler_Integer_Result compiler_integer_negate(const long long operand) noexcept
Negates one integer of the language.
Compiler_Integer_Status
Outcome of one integer operation of the language.
@ Overflow
The result does not fit in a signed 64-bit integer.
@ Division_By_Zero
/ with a zero divisor.
@ Modulo_By_Zero
% with a zero divisor.
@ Ok
The result is in value.
and
Check uniqueness with explicit hash + equality functors.
Compiler_Token_Kind compiler_operator_to_token_kind(const Compiler_Operator_Kind kind) noexcept
Maps one reusable operator kind back into the MVP token kind.
Compiler_Token_Kind
Token kinds supported by the compiler MVP.
@ Invalid
Sentinel for lexer errors or uninitialized tokens.
Compiler_Integer_Result compiler_integer_binary(const Compiler_Operator_Kind op, const long long lhs, const long long rhs) noexcept
Applies one integer operator of the language to two values.
Compiler_Operator_Kind compiler_operator_compound_base(const Compiler_Operator_Kind kind) noexcept
Returns the arithmetic operator underlying one compound assignment.
bool compiler_operator_is_compound_assignment(const Compiler_Operator_Kind kind) noexcept
Returns whether kind is one compound-assignment operator.
Compiler_Operator_Kind compiler_operator_from_token_kind(const Compiler_Token_Kind kind) noexcept
Maps one reference-frontend token kind into a reusable operator kind.
Compiler_Operator_Kind
Stable operator kinds shared by reusable compiler layers.
Result of compiler_integer_binary() and compiler_integer_negate().
long long value
The result, when status is Ok.
Compiler_Integer_Status status
What happened.