cgExpr :: AST -> CodeGen Operand
cgExpr (AST _ v) = cg v
  where
    cg (App (AST _ (Ref (AST.Global f))) xs) = fromJust <$> (call' f =<< mapM cgExpr xs)
    cg (Ref v) = fromJust <$> lookupVar v
    cg (Num n) = pure . ConstantOperand $ C.Int 32 (round n)
    cg (ASTError _ _) = call intrinsicTrap []
    cg (Abs args value) = do
      func <- runFunctionGen "lambda" i32 (map (\(name, ty) -> (T.unpack name, cgType ty, [])) args) False functionDefaults (runCodeGen . funcgen value)
      pure . ConstantOperand . C.GlobalReference (typeOf func) $ (name func)
cgExpr :: AST -> CodeGen Operand
cgExpr (AST _ v) = cg v
  where
    cg (App (AST _ (Ref (AST.Global f))) xs) = fromJust <$> (call' f =<< mapM cgExpr xs)
    cg (Ref v) = fromJust <$> lookupVar v
    cg (Num n) = pure . ConstantOperand $ C.Int 32 (round n)
    cg (ASTError _ _) = call intrinsicTrap []
    cg (Abs args value) = do
      func <- runFunctionGen "lambda" i32 (map (\(name, ty) -> (T.unpack name, cgType ty, [])) args) False functionDefaults (runCodeGen . funcgen value)
      pure . ConstantOperand . C.GlobalReference (typeOf func) $ (name func)
cgExpr (AST _ v) = cg v
  where
    cg (App (AST _ (Ref (AST.Global f))) xs) = fromJust <$> (call' f =<< mapM cgExpr xs)
    cg (Ref v) = fromJust <$> lookupVar v
    cg (Num n) = pure . ConstantOperand $ C.Int 32 (round n)
    cg (ASTError _ _) = call intrinsicTrap []
    cg (Abs args value) = do
      func <- runFunctionGen "lambda" i32 (map (\(name, ty) -> (T.unpack name, cgType ty, [])) args) False functionDefaults (runCodeGen . funcgen value)
      pure . ConstantOperand . C.GlobalReference (typeOf func) $ (name func)