You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.4 KiB
C++

#ifndef FORSPLL_AST_HPP
#define FORSPLL_AST_HPP
#include "llvm.hpp"
#include "var.hpp"
#include <list>
#include <memory>
#include <string>
struct BaseAST
{
std::string name;
BaseAST(const std::string& n): name(n) {}
virtual ~BaseAST() = default;
virtual llvm::Value *codegen(LLVMState&) const = 0;
};
struct NumberAST : public BaseAST
{
// push number onto stack
explicit NumberAST(const std::string& n);
llvm::Value *codegen(LLVMState& llvmState) const override;
};
struct PushAST : public BaseAST
{
// push named value to stack
explicit PushAST(const std::string& n);
llvm::Value *codegen(LLVMState& llvmState) const override;
};
struct PopAST : public BaseAST
{
// pop value on stack to named var
explicit PopAST(const std::string& n);
llvm::Value *codegen(LLVMState& llvmState) const override;
};
struct CallAST : public BaseAST
{
// invoke named invocable
explicit CallAST(const std::string& n);
llvm::Value *codegen(LLVMState& llvmState) const override;
};
struct ThunkAST : public BaseAST
{
static int tcount;
std::list<std::unique_ptr<BaseAST>> body;
llvm::IRBuilderBase::InsertPoint parent;
llvm::Function *func;
explicit ThunkAST(LLVMState& llvmState);
explicit ThunkAST(LLVMState& llvmState, std::string n);
llvm::Value *codegen(LLVMState& llvmState) const override;
};
#endif // FORSPLL_AST_HPP