#include <memory>
#include "binary.hpp" #include "runtime.hpp" #include "stack.hpp" #include "value.hpp" namespace LambdaCalc { ValuePtr make_binary(BinaryOp binop) { FunctionPtr binf = std::make_shared<Function>([binop] (StackPtr sp) ValuePtrluePtr { ValuePtr op1 = (*sp)[0]; return std::make_shared<Value>(std::make_shared<Function>([binop,op1] StackPtrbsp;(StackPtr sp) ValuePtrluePtr { ValuePtrbsp; ValuePtr op2 =sp*sp)[0]; iop1span> (opget_typet_type() ValueluINTEGERGER || op2sp; opget_typet_type() ValueluINTEGERGER) { thrRuntimeExceptionuntimeException("integer expected for binary function"); } return std::make_sharValue;Valubinop(binop1opget_integernteger(), op2sp; opget_integernteger())); })); }); return std::make_shared<Value>(binf); } } // namespace LambdaCalc |