Add binops.h and binops.cpp

This commit is contained in:
Sofia 2026-04-13 18:00:47 +03:00
parent e3e0cd9f9f
commit 9791c9c8da
6 changed files with 44 additions and 11 deletions

View File

@ -23,6 +23,7 @@ add_executable(${PROJECT_NAME}
src/codegen.cpp src/codegen.cpp
src/types.cpp src/types.cpp
src/typechecker.cpp src/typechecker.cpp
src/binops.cpp
) )
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Weffc++ -Wextra -Wpedantic -Werror) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Weffc++ -Wextra -Wpedantic -Werror)

View File

@ -7,6 +7,7 @@
#include "codegen.h" #include "codegen.h"
#include "types.h" #include "types.h"
#include "binops.h"
#include "tokens.h" #include "tokens.h"
#include "typechecker.h" #include "typechecker.h"

8
src/binops.cpp Normal file
View File

@ -0,0 +1,8 @@
#include "binops.h"
namespace types {
std::vector<BinopDefinition> create_binops() {
return {};
}
}

33
src/binops.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef BINOP_H
#define BINOP_H
#include <memory>
#include "types.h"
namespace types {
enum class BinOp {
Assignment,
Add,
Sub,
LessThan,
GreaterThan,
};
int operator_precedence(BinOp& op);
std::string format_operator(BinOp& op);
struct BinopDefinition {
std::shared_ptr<Type> lhs;
BinOp op;
std::shared_ptr<Type> rhs;
std::shared_ptr<Type> result;
llvm::Value* (*codegen)(codegen::Builder& builder);
};
std::vector<BinopDefinition> create_binops();
}
#endif

View File

@ -2,6 +2,7 @@
#include <sstream> #include <sstream>
#include "types.h" #include "types.h"
#include "binops.h"
namespace types { namespace types {
int operator_precedence(BinOp& op) { int operator_precedence(BinOp& op) {

View File

@ -7,17 +7,6 @@
#include <memory> #include <memory>
namespace types { namespace types {
enum class BinOp {
Assignment,
Add,
Sub,
LessThan,
GreaterThan,
};
int operator_precedence(BinOp& op);
std::string format_operator(BinOp& op);
enum class TypeKind { enum class TypeKind {
Fundamental, Fundamental,
Function, Function,