Make a few more things classes.
This commit is contained in:
@@ -16,13 +16,12 @@
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
|
||||
void compiler::add_default_types() {
|
||||
global_env->bind_type("Int", type_ptr(new type_internal("Int")));
|
||||
global_env->bind_type("Bool", type_ptr(new type_internal("Bool")));
|
||||
global_env->bind_type("Int", type_ptr(new type_base("Int")));
|
||||
global_env->bind_type("Bool", type_ptr(new type_base("Bool")));
|
||||
}
|
||||
|
||||
void compiler::add_binop_type(binop op, type_ptr type) {
|
||||
auto name = mng.new_mangled_name(op_action(op));
|
||||
binop_names[op] = name;
|
||||
global_env->bind(op_name(op), std::move(type), visibility::global);
|
||||
global_env->set_mangled_name(op_name(op), name);
|
||||
}
|
||||
@@ -53,7 +52,7 @@ void compiler::add_default_function_types() {
|
||||
}
|
||||
|
||||
void compiler::parse() {
|
||||
if(!driver.run_parse())
|
||||
if(!driver())
|
||||
throw compiler_error("failed to open file");
|
||||
}
|
||||
|
||||
@@ -78,7 +77,8 @@ void compiler::compile() {
|
||||
}
|
||||
|
||||
void compiler::create_llvm_binop(binop op) {
|
||||
auto new_function = ctx.create_custom_function(binop_names.at(op), 2);
|
||||
auto new_function =
|
||||
ctx.create_custom_function(global_env->get_mangled_name(op_name(op)), 2);
|
||||
std::vector<instruction_ptr> instructions;
|
||||
instructions.push_back(instruction_ptr(new instruction_push(1)));
|
||||
instructions.push_back(instruction_ptr(new instruction_eval()));
|
||||
@@ -95,7 +95,8 @@ void compiler::create_llvm_binop(binop op) {
|
||||
}
|
||||
|
||||
void compiler::create_llvm_bool(bool b) {
|
||||
auto new_function = ctx.create_custom_function(b ? "True" : "False", 0);
|
||||
auto new_function = ctx.create_custom_function(
|
||||
global_env->get_mangled_name(b ? "True" : "False"), 0);
|
||||
std::vector<instruction_ptr> instructions;
|
||||
instructions.push_back(instruction_ptr(new instruction_pushint(b)));
|
||||
instructions.push_back(instruction_ptr(new instruction_update(0)));
|
||||
@@ -158,7 +159,7 @@ void compiler::output_llvm(const std::string& into) {
|
||||
|
||||
compiler::compiler(const std::string& filename)
|
||||
: file_m(), global_defs(), driver(file_m, global_defs, filename),
|
||||
mng(), global_scp(mng), global_env(new type_env), type_m(), ctx() {
|
||||
global_env(new type_env), type_m(), mng(), global_scp(mng), ctx() {
|
||||
add_default_types();
|
||||
add_default_function_types();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user