/* ** Copyright (c) Terminal Click - All rights Reserved ** ** @author: Abner Coimbre **/ #ifndef CALC_H #define CALC_H /* * ============================================================== * * DATA TYPES * * =============================================================== */ typedef enum { CALC_FORMAT_DECIMAL, CALC_FORMAT_HEX, CALC_FORMAT_BINARY, CALC_FORMAT_MAX, } calc_FormatKind; /* * ============================================================== * * PUBLIC ROUTINES * * =============================================================== */ /* * NOTE: The gcc/clang cold attribute below is specifically designed for functions that: * * 1. Are unlikely to be executed during normal program flow * 2. Should be optimized for size rather than speed * 3. Handle uncommon conditions or paths in the code * * Our calculator routines fit this profile because: * * - They're only called when users explicitly invoke the calculator feature * - In a terminal emulator, most operations would be text display/input rather than calculations * - The calculations only happen after a specific user action (pressing Enter) */ function __attribute__((cold)) char* calc_format_result(double value, calc_FormatKind format); function __attribute__((cold)) double calc_eval_formatted(char *expr, calc_FormatKind format, char *result_str); function __attribute__((cold)) double calc_eval(char *expr); function __attribute__((cold)) int calc_match(char expected); function __attribute__((cold)) double calc_expr(void); function __attribute__((cold)) double calc_term(void); function __attribute__((cold)) double calc_exponent(void); function __attribute__((cold)) double calc_factor(void); function __attribute__((cold)) double calc_bitwise_or(void); function __attribute__((cold)) double calc_bitwise_xor(void); function __attribute__((cold)) double calc_bitwise_and(void); function __attribute__((cold)) double calc_shift(void); #endif /* CALC_H */