Compare commits

..

2 Commits

Author SHA1 Message Date
7ee084385c Add makefile. 2019-06-12 20:35:50 -07:00
d32d92e241 Fix c++11 compatibility. 2019-06-12 20:35:42 -07:00
8 changed files with 33 additions and 12 deletions

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
CPPFLAGS := -std=c++11 `llvm-config-7.0-64 --cppflags --ldflags --libs --system-libs all`
CC := g++
TARGET := lily
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard src/*.cpp)
# # $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS := $(patsubst src/%.cpp,%.o,$(SRCS))
all: $(TARGET)
$(TARGET): $(OBJS) parser-c.o
$(CC) $(CPPFLAGS) -o $@ $^
%.o: src/%.cpp
$(CC) $(CPPFLAGS) -c $<
clean:
rm -rf $(TARGET) *.o
parser-c.o:
gcc -c -o parser-c.o src/parser.c
.PHONY: all clean

View File

@ -15,12 +15,12 @@ namespace lily {
struct instruction_slide : instruction {
int amount;
instruction_slide(int a) : amount(a) {}
std::ostream& to_stream(std::ostream& os);
void gen_llvm(llvm_context& ctx);
};
struct instruction_alloc : instruction {
int amount;
@ -44,7 +44,7 @@ namespace lily {
struct instruction_push_global : instruction {
std::string name;
instruction_push_global(std::string n) : name(std::move(n)) {}
std::ostream& to_stream(std::ostream& os);
void gen_llvm(llvm_context& ctx);
@ -145,7 +145,7 @@ namespace lily {
public:
template <typename T, typename ... Ts>
T* add_instruction(Ts ... ts) {
auto new_inst = std::make_unique<T>(ts...);
auto new_inst = std::unique_ptr<T>(new T(ts...));
T* raw = new_inst.get();
instructions.push_back(std::move(new_inst));
return raw;

View File

@ -117,7 +117,7 @@ namespace lily {
ast_case* new_case = new ast_case();
ast_ptr case_ptr = ast_ptr(new_case);
new_case->of = expr_tree(PGS_TREE_NT_CHILD(*c, 1), source);
pgs_tree* branches = PGS_TREE_NT_CHILD(*c, 4);
while(PGS_TREE_NT_COUNT(*branches) == 2) {
pgs_tree* branch = PGS_TREE_NT_CHILD(*branches, 0);
@ -216,7 +216,7 @@ namespace lily {
}
static program_ptr build_program(pgs_tree* tree, const char* source) {
program_ptr prog = std::make_unique<program>();
program_ptr prog = std::unique_ptr<program>(new program);
pgs_tree* program = PGS_TREE_NT_CHILD(*tree, 0);
do {
@ -239,7 +239,7 @@ namespace lily {
if((err = pgs_do_all(&state, &into, s.c_str())) != PGS_NONE) {
throw error("failed to parse input string");
}
program_ptr prog = build_program(into, s.c_str());
prog->check();
pgs_free_tree(into);

View File

@ -4,7 +4,7 @@
namespace lily {
type_data::constructor* type_data::create_constructor(const std::string& name,
std::vector<type*>&& params) {
auto new_constructor = std::make_unique<constructor>();
auto new_constructor = std::unique_ptr<constructor>(new constructor());
new_constructor->id = constructors.size();
new_constructor->parent = this;
new_constructor->params = std::move(params);

View File

@ -2,6 +2,7 @@
#include <string>
#include <vector>
#include <map>
#include <memory>
namespace lily {
enum reserved_types {

View File

@ -1,5 +1,6 @@
#pragma once
#include <map>
#include <memory>
#include "type.hpp"
#include "ast.hpp"

View File

@ -12,7 +12,7 @@ namespace lily {
}
type_internal* type_manager::create_int_type() {
auto new_type = std::make_unique<type_internal>(next_id++);
auto new_type = std::unique_ptr<type_internal>(new type_internal(next_id++));
type_internal* raw_ptr = new_type.get();
types.push_back(std::move(new_type));
type_names["Int"] = raw_ptr;
@ -20,7 +20,7 @@ namespace lily {
}
type_internal* type_manager::create_str_type() {
auto new_type = std::make_unique<type_internal>(next_id++);
auto new_type = std::unique_ptr<type_internal>(new type_internal(next_id++));
type_internal* raw_ptr = new_type.get();
types.push_back(std::move(new_type));
type_names["Str"] = raw_ptr;
@ -29,7 +29,7 @@ namespace lily {
type_data* type_manager::create_data_type(const std::string& name) {
if(type_names.count(name)) throw error("redefinition of type");
auto new_type = std::make_unique<type_data>(next_id++);
auto new_type = std::unique_ptr<type_data>(new type_data(next_id++));
type_data* raw_ptr = new_type.get();
types.push_back(std::move(new_type));
type_names[name] = raw_ptr;

View File

@ -21,7 +21,7 @@ namespace lily {
type_data* create_data_type(const std::string& name);
template <typename T, typename ... Args>
T* create_type(Args...as) {
auto new_type = std::make_unique<T>(as...);
auto new_type = std::unique_ptr<T>(new T(as...));
T* raw_ptr = new_type.get();
types.push_back(std::move(new_type));
return raw_ptr;