Move common code into loops.

This commit is contained in:
Danila Fedorin 2020-09-10 14:50:03 -07:00
parent 72d8179cc5
commit ad2576eae2

View File

@ -9,6 +9,7 @@
#include "error.hpp" #include "error.hpp"
#include "type.hpp" #include "type.hpp"
#include "parse_driver.hpp" #include "parse_driver.hpp"
#include "type_env.hpp"
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetSelect.h"
@ -37,13 +38,15 @@ void prelude_types(definition_group& defs, type_env_ptr env) {
type_ptr cmp_type = type_ptr(new type_arr( type_ptr cmp_type = type_ptr(new type_arr(
int_type_app, int_type_app,
type_ptr(new type_arr(int_type_app, bool_type_app)))); type_ptr(new type_arr(int_type_app, bool_type_app))));
env->bind("+", binop_type, visibility::global);
env->bind("-", binop_type, visibility::global); constexpr binop number_ops[] = { PLUS, MINUS, TIMES, DIVIDE, MODULO };
env->bind("*", binop_type, visibility::global); constexpr binop cmp_ops[] = { EQUALS, LESS_EQUALS };
env->bind("/", binop_type, visibility::global); for(auto& op : number_ops) {
env->bind("%", binop_type, visibility::global); env->bind(op_name(op), binop_type, visibility::global);
env->bind("==", cmp_type, visibility::global); }
env->bind("<=", cmp_type, visibility::global); for(auto& op : cmp_ops) {
env->bind(op_name(op), cmp_type, visibility::global);
}
env->bind("True", bool_type_app, visibility::global); env->bind("True", bool_type_app, visibility::global);
env->bind("False", bool_type_app, visibility::global); env->bind("False", bool_type_app, visibility::global);