/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * File:   lambdas.h
 * Author: pgess <v.melnychenko@xreate.org>
 *
 * Created in April, 2020
 */

#ifndef XREATE_LAMBDAS_H
#define XREATE_LAMBDAS_H

#include "pass/compilepass.h"

namespace llvm {
  class Function;
}

namespace xreate { namespace compilation {

class LambdaBruteFn: public IBruteFunction {
public:
  LambdaBruteFn(CodeScope* entry, CompilePass* p, const std::string& hintAlias)
    : IBruteFunction(entry, p), __hintAlias(hintAlias) {
    IBruteFunction::isLambda = true;
  }

  virtual std::string prepareName() override;

protected:
  virtual std::vector<llvm::Type*>  prepareSignature() override;
  virtual llvm::Function::arg_iterator prepareBindings() override;
  virtual llvm::Type* prepareResult() override;
  virtual void applyAttributes() override;

private:
  std::string __hintAlias;
  static unsigned __counter;
};

class LambdaIR{
public:
  LambdaIR(CompilePass* p): __pass(p){}
  llvm::Function* compile(CodeScope* body, const std::string& hintAlias);

private:
  compilation::Context __context;
  CompilePass* __pass;

};

}}

#endif //XREATE_LAMBDAS_H
