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.

86 lines
2.2 KiB
C++

/**
* forspll - LLVM-based Forsp compiler
* Copyright (C) 2024 Clyne Sullivan <clyne@bitgloo.com>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#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>> ast;
llvm::IRBuilderBase::InsertPoint parent;
llvm::Function *func;
llvm::BasicBlock *entry, *body;
llvm::Value *env;
llvm::Value *lastSp;
explicit ThunkAST();
llvm::Value *codegen(LLVMState& llvmState) const override;
void beginGen(LLVMState& llvmState);
void endGen(LLVMState& llvmState);
};
#endif // FORSPLL_AST_HPP