<commit_before>#ifndef MICO_EVAL_INT_OPRATIONS_H
#define MICO_EVAL_INT_OPRATIONS_H

#include "mico/eval/operation.h"
#include "mico/tokens.h"
#include "mico/eval/operations/common.h"

#include "mico/ast.h"

namespace mico { namespace eval { namespace operations {

    template <>
    struct operation<objects::type::INTEGER> {

        using float_type    = objects::impl<objects::type::FLOAT>;
        using value_type    = objects::impl<objects::type::INTEGER>;
        using error_type    = objects::impl<objects::type::FAILURE>;
        using bool_type     = objects::impl<objects::type::BOOLEAN>;
        using builtin_type  = objects::impl<objects::type::BUILTIN>;
        using function_type = objects::impl<objects::type::FUNCTION>;

        using prefix = ast::expressions::prefix;
        using infix  = ast::expressions::infix;

        static const objects::type type_value = objects::type::INTEGER;
        static const objects::type float_type_value = objects::type::FLOAT;
        static const objects::type bool_type_value = objects::type::BOOLEAN;

        static
        objects::sptr eval_prefix( prefix *pref, objects::sptr obj )
        {
            common::reference<objects::type::INTEGER> ref(obj);

            auto val = ref.unref( );
            auto uval = static_cast<std::uint64_t>(val->value( ));

            switch (pref->token( )) {
            case tokens::type::MINUS:
                return value_type::make( -1 * val->value( ) );
            case tokens::type::TILDA:
                return value_type::make( ~uval );
            case tokens::type::BANG:
                return value_type::make( uval != 0 );
            default:
                break;
            }
            return error_type::make(pref->pos( ), "Prefix operator '",
                                    pref->token( ), "' is not defined for "
                                                    "integers");
        }

        static
        objects::sptr eval_float( infix *inf, double lft, double rht )
        {
            switch (inf->token( )) {
            case tokens::type::MINUS:
                return float_type::make( lft  - rht );
            case tokens::type::PLUS:
                return float_type::make( lft  + rht );
            case tokens::type::ASTERISK:
                return float_type::make( lft  * rht );
            case tokens::type::SLASH:
                if( rht != 0 ) {
                    return float_type::make( lft  / rht );
                } else {
                    return error_type::make( inf->pos( ),
                                             "Division by zero. '/'" );
                }

            case tokens::type::LOGIC_AND:
                return  bool_type::make( lft && rht );
            case tokens::type::LOGIC_OR:
                return  bool_type::make( lft || rht );
            case tokens::type::GT:
                return  bool_type::make( lft  > rht );
            case tokens::type::LT:
                return  bool_type::make( lft  < rht );
            case tokens::type::GT_EQ:
                return  bool_type::make( lft >= rht );
            case tokens::type::LT_EQ:
                return  bool_type::make( lft <= rht );
            case tokens::type::EQ:
                return  bool_type::make( lft == rht );
            case tokens::type::NOT_EQ:
                return  bool_type::make( lft != rht );
            default:
                break;
            }
            return error_type::make(inf->pos( ), "Infix operation '",
                                    inf->token( ), "' is not defined for "
                                                    "float");
        }

        static
        objects::sptr eval_int( infix *inf, std::int64_t lft, std::int64_t rht )
        {
            auto ulft = static_cast<std::uint64_t>(lft);
            auto urgt = static_cast<std::uint64_t>(rht);

            switch (inf->token( )) {
            case tokens::type::MINUS:
                return value_type::make( lft  - rht );<commit_msg>operations<commit_after>#ifndef MICO_EVAL_INT_OPRATIONS_H
#define MICO_EVAL_INT_OPRATIONS_H

#include "mico/eval/operation.h"
#include "mico/tokens.h"
#include "mico/eval/operations/common.h"

#include "mico/ast.h"

namespace mico { namespace eval { namespace operations {

    template <>
    struct operation<objects::type::INTEGER> {

        using float_type    = objects::impl<objects::type::FLOAT>;
        using value_type    = objects::impl<objects::type::INTEGER>;
        using error_type    = objects::impl<objects::type::FAILURE>;
        using bool_type     = objects::impl<objects::type::BOOLEAN>;
        using builtin_type  = objects::impl<objects::type::BUILTIN>;
        using function_type = objects::impl<objects::type::FUNCTION>;

        using prefix = ast::expressions::prefix;
        using infix  = ast::expressions::infix;

        static const objects::type type_value = objects::type::INTEGER;
        static const objects::type float_type_value = objects::type::FLOAT;
        static const objects::type bool_type_value = objects::type::BOOLEAN;

        static
        objects::sptr eval_prefix( prefix *pref, objects::sptr obj )
        {
            common::reference<objects::type::INTEGER> ref(obj);

            auto val = ref.unref( );
            auto uval = static_cast<std::uint64_t>(val->value( ));

            switch (pref->token( )) {
            case tokens::type::MINUS:
                return value_type::make( -1 * val->value( ) );
            case tokens::type::TILDA:
                return value_type::make( ~uval );
            case tokens::type::BANG:
                return value_type::make( uval != 0 );
            default:
                break;
            }
            return error_type::make(pref->pos( ), "Prefix operator '",
                                    pref->token( ), "' is not defined for "
                                                    "integers");
        }

        static
        objects::sptr eval_float( infix *inf, double lft, double rht )
        {
            switch (inf->token( )) {
            case tokens::type::MINUS:
                return float_type::make( lft  - rht );
            case tokens::type::PLUS:
                return float_type::make( lft  + rht );
            case tokens::type::ASTERISK:
                return float_type::make( lft  * rht );
            case tokens::type::SLASH:
                if( rht != 0 ) {
                    return float_type::make( lft  / rht );
                } else {
                    return error_type::make( inf->pos( ),
                                             "Division by zero. '/'" );
                }

            case tokens::type::LOGIC_AND:
                return  bool_type::make( (lft != 0.0) && (rht != 0.0) );
            case tokens::type::LOGIC_OR:
                return  bool_type::make( (lft != 0.0) || (rht != 0.0) );
            case tokens::type::GT:
                return  bool_type::make( lft  > rht );
            case tokens::type::LT:
                return  bool_type::make( lft  < rht );
            case tokens::type::GT_EQ:
                return  bool_type::make( lft >= rht );
            case tokens::type::LT_EQ:
                return  bool_type::make( lft <= rht );
            case tokens::type::EQ:
                return  bool_type::make( lft == rht );
            case tokens::type::NOT_EQ:
                return  bool_type::make( lft != rht );
            default:
                break;
            }
            return error_type::make(inf->pos( ), "Infix operation '",
                                    inf->token( ), "' is not defined for "
                                                    "float");
        }

        static
        objects::sptr eval_int( infix *inf, std::int64_t lft, std::int64_t rht )
        {
            auto ulft = static_cast<std::uint64_t>(lft);
            auto urgt = static_cast<std::uint64_t>(rht);

            switch (inf->token( )) {
            case tokens::type::MINUS:
                return value_type::make( lft  - rht );
{'fraction_non_alphanumeric': 0.12557162279075515, 'fraction_numerical': 0.004202199975281176, 'mean_word_length': 1.6522451655195018, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3938187', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2234, 'n_words': 472}