#include "alfe/main.h" #ifndef INCLUDED_INTEGER_FUNCTIONS_H #define INCLUDED_INTEGER_FUNCTIONS_H #include "alfe/function.h" class AddIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l + i->value()); } Identifier identifier() const { return OperatorPlus(); } FunctionType type() const { return FunctionType(IntegerType(), IntegerType(), IntegerType()); } }; }; class SubtractIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l - i->value()); } Identifier identifier() const { return OperatorMinus(); } FunctionType type() const { return FunctionType(IntegerType(), IntegerType(), IntegerType()); } }; }; class MultiplyIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l * i->value()); } Identifier identifier() const { return OperatorStar(); } FunctionType type() const { return FunctionType(IntegerType(), IntegerType(), IntegerType()); } }; }; class ShiftLeftIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; int r = i->value(); if (r < 0) return Rational(l, 1 << -r); return l << r; } Identifier identifier() const { return OperatorShiftLeft(); } FunctionType type() const { return FunctionType(RationalType(), IntegerType(), IntegerType()); } }; }; class ShiftRightIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; int r = i->value(); if (r < 0) return l << -r; return Rational(l, 1 << r); } Identifier identifier() const { return OperatorShiftRight(); } FunctionType type() const { return FunctionType(RationalType(), IntegerType(), IntegerType()); } }; }; class LessThanIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l < i->value()); } Identifier identifier() const { return OperatorLessThan(); } FunctionType type() const { return FunctionType(BooleanType(), IntegerType(), IntegerType()); } }; }; class GreaterThanIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l > i->value()); } Identifier identifier() const { return OperatorGreaterThan(); } FunctionType type() const { return FunctionType(BooleanType(), IntegerType(), IntegerType()); } }; }; class LessThanOrEqualToIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l <= i->value()); } Identifier identifier() const { return OperatorLessThanOrEqualTo(); } FunctionType type() const { return FunctionType(BooleanType(), IntegerType(), IntegerType()); } }; }; class GreaterThanOrEqualToIntegerInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { auto i = arguments.begin(); int l = i->value(); ++i; return Value(l >= i->value()); } Identifier identifier() const { return OperatorGreaterThanOrEqualTo(); } FunctionType type() const { return FunctionType(BooleanType(), IntegerType(), IntegerType()); } }; }; class NegativeInteger : public Nullary { public: class Body : public Nullary::Body { public: Value evaluate(List arguments, Span span) const { return Value( - arguments.begin()->value()); } Identifier identifier() const { return OperatorMinus(); } FunctionType type() const { return FunctionType(IntegerType(), IntegerType()); } }; }; #endif // INCLUDED_INTEGER_FUNCTIONS_H