Fixed build errors. Switched to CMake build system completely.

This commit is contained in:
yhirose 2015-11-30 17:26:06 -05:00
parent 30da6961d4
commit 69ede706f0
10 changed files with 49 additions and 97 deletions

View File

@ -1,24 +1,8 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
include_directories(.)
add_definitions("-std=c++1y") add_definitions("-std=c++1y")
add_executable(peglint lint/peglint.cc lint/server.cc) add_subdirectory(lint)
target_link_libraries(peglint pthread) add_subdirectory(test)
add_subdirectory(example)
add_executable(test-main test/test.cc) add_subdirectory(language/pl0)
target_link_libraries(test-main pthread) add_subdirectory(language/culebra)
add_executable(calc example/calc.cc)
target_link_libraries(calc pthread)
add_executable(calc2 example/calc2.cc)
target_link_libraries(calc2 pthread)
add_executable(calc3 example/calc3.cc)
target_link_libraries(calc3 pthread)
add_executable(pl0 language/pl0/pl0.cc)
target_link_libraries(pl0 pthread)
add_executable(culebra language/culebra/main.cc)
target_link_libraries(culebra pthread)

12
example/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.0)
include_directories(..)
add_definitions("-std=c++1y")
add_executable(calc calc.cc)
target_link_libraries(calc pthread)
add_executable(calc2 calc2.cc)
target_link_libraries(calc2 pthread)
add_executable(calc3 calc3.cc)
target_link_libraries(calc3 pthread)

View File

@ -1,21 +0,0 @@
USE_CLANG = 1
ifdef USE_CLANG
CC = clang++
CFLAGS = -std=c++1y -stdlib=libc++ -g
else
CC = g++
CFLAGS = -std=c++1y -g
endif
all: calc calc2 calc3
calc : calc.cc ../peglib.h
$(CC) -o calc $(CFLAGS) -I.. calc.cc
calc2 : calc2.cc ../peglib.h
$(CC) -o calc2 $(CFLAGS) -I.. calc2.cc
calc3 : calc3.cc ../peglib.h
$(CC) -o calc3 $(CFLAGS) -I.. calc3.cc

View File

@ -141,21 +141,21 @@ struct FunctionValue {
}; };
struct ObjectValue { struct ObjectValue {
ObjectValue() : properties(std::make_shared<std::map<std::string, Symbol>>()) {}
bool has(const std::string& name) const; bool has(const std::string& name) const;
const Value& get(const std::string& name) const; const Value& get(const std::string& name) const;
void assign(const std::string& name, const Value& val); void assign(const std::string& name, const Value& val);
void initialize(const std::string& name, const Value& val, bool mut); void initialize(const std::string& name, const Value& val, bool mut);
virtual std::map<std::string, Value>& builtins(); virtual std::map<std::string, Value>& builtins();
std::shared_ptr<std::map<std::string, Symbol>> properties = std::shared_ptr<std::map<std::string, Symbol>> properties;
std::make_shared<std::map<std::string, Symbol>>();
}; };
struct ArrayValue : public ObjectValue { struct ArrayValue : public ObjectValue {
ArrayValue() : values(std::make_shared<std::vector<Value>>()) {}
std::map<std::string, Value>& builtins() override; std::map<std::string, Value>& builtins() override;
std::shared_ptr<std::vector<Value>> values = std::shared_ptr<std::vector<Value>> values;
std::make_shared<std::vector<Value>>();
}; };
struct Value struct Value

View File

@ -5,7 +5,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
using namespace culebra;
using namespace peg; using namespace peg;
using namespace std; using namespace std;
@ -28,7 +27,7 @@ bool read_file(const char* path, vector<char>& buff)
struct CommandLineDebugger struct CommandLineDebugger
{ {
void operator()(const Ast& ast, Environment& env, bool force_to_break) { void operator()(const Ast& ast, culebra::Environment& env, bool force_to_break) {
if (quit) { if (quit) {
return; return;
} }
@ -130,7 +129,7 @@ struct CommandLineDebugger
} }
} }
void print(const Ast& ast, Environment& env, const string& symbol) { void print(const Ast& ast, culebra::Environment& env, const string& symbol) {
if (symbol.empty()) { if (symbol.empty()) {
print_all(ast, env); print_all(ast, env);
} else if (env.has(symbol)) { } else if (env.has(symbol)) {
@ -140,14 +139,14 @@ struct CommandLineDebugger
} }
} }
void print_all(const Ast& ast, Environment& env) { void print_all(const Ast& ast, culebra::Environment& env) {
auto node = find_function_node(ast); auto node = find_function_node(ast);
set<string> references; set<string> references;
enum_identifiers(*node, references); enum_identifiers(*node, references);
for (const auto& symbol: references) { for (const auto& symbol: references) {
if (env.has(symbol)) { if (env.has(symbol)) {
const auto& val = env.get(symbol); const auto& val = env.get(symbol);
if (val.type != Value::Function) { if (val.type != culebra::Value::Function) {
cout << symbol << ": " << val.str() << endl; cout << symbol << ": " << val.str() << endl;
} }
} }
@ -212,7 +211,7 @@ struct CommandLineDebugger
map<string, vector<size_t>> sources_; map<string, vector<size_t>> sources_;
}; };
int repl(shared_ptr<Environment> env, bool print_ast) int repl(shared_ptr<culebra::Environment> env, bool print_ast)
{ {
for (;;) { for (;;) {
auto line = linenoise::Readline("cul> "); auto line = linenoise::Readline("cul> ");
@ -223,13 +222,13 @@ int repl(shared_ptr<Environment> env, bool print_ast)
if (!line.empty()) { if (!line.empty()) {
vector<string> msgs; vector<string> msgs;
auto ast = parse("(repl)", line.data(), line.size(), msgs); auto ast = culebra::parse("(repl)", line.data(), line.size(), msgs);
if (ast) { if (ast) {
if (print_ast) { if (print_ast) {
cout << peg::ast_to_s(ast); cout << peg::ast_to_s(ast);
} }
Value val; culebra::Value val;
if (interpret(ast, env, val, msgs)) { if (interpret(ast, env, val, msgs)) {
cout << val << endl; cout << val << endl;
linenoise::AddHistory(line.c_str()); linenoise::AddHistory(line.c_str());
@ -272,7 +271,7 @@ int main(int argc, const char** argv)
} }
try { try {
auto env = make_shared<Environment>(); auto env = make_shared<culebra::Environment>();
setup_built_in_functions(*env); setup_built_in_functions(*env);
for (auto path: path_list) { for (auto path: path_list) {
@ -283,14 +282,14 @@ int main(int argc, const char** argv)
} }
vector<string> msgs; vector<string> msgs;
auto ast = parse(path, buff.data(), buff.size(), msgs); auto ast = culebra::parse(path, buff.data(), buff.size(), msgs);
if (ast) { if (ast) {
if (print_ast) { if (print_ast) {
cout << peg::ast_to_s(ast); cout << peg::ast_to_s(ast);
} }
Value val; culebra::Value val;
auto dbg = debug ? CommandLineDebugger() : Debugger(); auto dbg = debug ? CommandLineDebugger() : culebra::Debugger();
if (interpret(ast, env, val, msgs, dbg)) { if (interpret(ast, env, val, msgs, dbg)) {
return 0; return 0;
} }

5
lint/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.0)
include_directories(..)
add_definitions("-std=c++1y")
add_executable(peglint peglint.cc server.cc)

View File

@ -1,15 +0,0 @@
USE_CLANG = 1
ifdef USE_CLANG
CC = clang++
CFLAGS = -std=c++1y -stdlib=libc++ -g
else
CC = g++
CFLAGS = -std=c++1y -g
endif
all: peglint
peglint : peglint.cc server.cc ../peglib.h
$(CC) -o peglint $(CFLAGS) -I.. peglint.cc server.cc

View File

@ -158,7 +158,7 @@ private:
* scope_exit * scope_exit
*---------------------------------------------------------------------------*/ *---------------------------------------------------------------------------*/
// This is from "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189". // This is based on "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189".
template <typename EF> template <typename EF>
struct scope_exit struct scope_exit
@ -173,7 +173,7 @@ struct scope_exit
rhs.release(); rhs.release();
} }
~scope_exit() noexcept(noexcept(this->exit_function())) { ~scope_exit() noexcept {
if (execute_on_destruction) { if (execute_on_destruction) {
this->exit_function(); this->exit_function();
} }
@ -2232,14 +2232,12 @@ void ast_to_s(const std::shared_ptr<T>& ptr, std::string& s, int level = 0) {
std::string name; std::string name;
if (ast.name == ast.original_name) { if (ast.name == ast.original_name) {
name = ast.name; name = ast.name;
} } else {
else { name = ast.original_name + "[" + ast.name + "]";
name = ast.original_name + " (" + ast.name + ")";
} }
if (ast.is_token) { if (ast.is_token) {
s += "- " + name + "(" + ast.token + ")\n"; s += "- " + name + " (" + ast.token + ")\n";
} } else {
else {
s += "+ " + name + "\n"; s += "+ " + name + "\n";
} }
for (auto node : ast.nodes) { for (auto node : ast.nodes) {

6
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.0)
include_directories(..)
add_definitions("-std=c++1y")
add_executable(test-main test.cc)
target_link_libraries(test-main pthread)

View File

@ -1,16 +0,0 @@
USE_CLANG = 1
ifdef USE_CLANG
CC = clang++
CCFLAGS = -std=c++1y -stdlib=libc++ -g
else
CC = g++
CCFLAGS = -std=c++1y -g
endif
all : test
./test
test : test.cc ../peglib.h
$(CC) -o test $(CCFLAGS) -I.. -I. test.cc