1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
#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