diff --git a/bin/serene.cpp b/bin/serene.cpp index 1697611..f78216a 100644 --- a/bin/serene.cpp +++ b/bin/serene.cpp @@ -1,3 +1,4 @@ + /** * Serene programming language. * @@ -25,7 +26,7 @@ #include "serene/serene.h" #include "serene/reader/reader.h" #include "serene/reader/semantics.h" -#include "serene/sir/sir.hpp" +// #include "serene/sir/sir.hpp" #include #include @@ -86,15 +87,15 @@ int main(int argc, char *argv[]) { return 0; }; case Action::DumpIR: { - reader::FileReader *r = new reader::FileReader(inputFile); - auto ast = r->read(); + // reader::FileReader *r = new reader::FileReader(inputFile); + // auto ast = r->read(); - if (!ast) { - throw std::move(ast.getError()); - } + // if (!ast) { + // throw std::move(ast.getError()); + // } - serene::sir::dumpSIR(ast.getValue()); - delete r; + // serene::sir::dumpSIR(ast.getValue()); + // delete r; return 0; } default: { diff --git a/include/serene/error.hpp b/include/serene/error.hpp deleted file mode 100644 index c01010c..0000000 --- a/include/serene/error.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef ERROR_H -#define ERROR_H - -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/state.hpp" -#include - -namespace serene { -class Error : public AExpr { - const std::string msg; - -public: - Error(const std::string &msg) : msg(msg) {} - virtual ~Error(); - - const std::string &message() const; - - SereneType getType() const override { return SereneType::Error; } - std::string string_repr() const override; - std::string dumpAST() const override; -}; -} // namespace serene - -#endif diff --git a/include/serene/expr.hpp b/include/serene/expr.hpp deleted file mode 100644 index 3ca5f2a..0000000 --- a/include/serene/expr.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef EXPR_H -#define EXPR_H - -#include "serene/logger.hpp" -#include "serene/reader/location.h" -#include - -#if defined(ENABLE_LOG) || defined(ENABLE_EXPR_LOG) -#define EXPR_LOG(...) __LOG("EXPR", __VA_ARGS__); -#else -#define EXPR_LOG(...) ; -#endif - -namespace serene { - -enum class SereneType { - Expression, - Symbol, - List, - Error, - Number, -}; - -class AExpr { -public: - std::unique_ptr location; - - virtual ~AExpr() = default; - - virtual SereneType getType() const = 0; - virtual std::string string_repr() const = 0; - virtual std::string dumpAST() const = 0; -}; - -using ast_node = std::shared_ptr; -using ast_tree = std::vector; - -} // namespace serene - -#endif diff --git a/include/serene/list.hpp b/include/serene/list.hpp deleted file mode 100644 index 37817c7..0000000 --- a/include/serene/list.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef LIST_H -#define LIST_H - -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/reader/location.h" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" -#include -#include - -namespace serene { - -class List : public AExpr { - std::vector nodes_; - -public: - List(){}; - List(std::vector elements); - List(reader::Location start); - - SereneType getType() const override { return SereneType::List; } - - std::string dumpAST() const override; - std::string string_repr() const override; - size_t count() const; - void append(ast_node t); - - std::unique_ptr from(uint begin); - llvm::Optional at(uint index) const; - - std::vector::const_iterator begin(); - std::vector::const_iterator end(); - llvm::ArrayRef asArrayRef(); - - static bool classof(const AExpr *); -}; - -std::unique_ptr makeList(reader::Location); -std::unique_ptr makeList(reader::Location, List *); - -using ast_list_node = std::unique_ptr; -} // namespace serene - -#endif diff --git a/include/serene/logger.hpp b/include/serene/logger.hpp deleted file mode 100644 index a592453..0000000 --- a/include/serene/logger.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef LOGGER_H -#define LOGGER_H - -#include "config.h" -#include - -// DO NOT USE this macro directly. USE module specific macro. -// Checkout `reader.cpp` for example. -#define __LOG(M, ...) \ - fmt::print("[{}] <{}:{}> in '{}': {}\n", M, __FILE__, __LINE__, __func__, \ - fmt::format(__VA_ARGS__)); - -#endif diff --git a/include/serene/namespace.h b/include/serene/namespace.h index d1cd9eb..3843b7a 100644 --- a/include/serene/namespace.h +++ b/include/serene/namespace.h @@ -29,7 +29,6 @@ #include "mlir/IR/Value.h" #include "serene/exprs/expression.h" #include "serene/llvm/IR/Value.h" -#include "serene/logger.hpp" #include "llvm/ADT/DenseMap.h" #include #include diff --git a/include/serene/number.hpp b/include/serene/number.hpp deleted file mode 100644 index cd89a7e..0000000 --- a/include/serene/number.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef NUMBER_H -#define NUMBER_H - -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/reader/location.h" -#include "serene/state.hpp" -#include - -namespace serene { -class Number : public AExpr { - const std::string num_; - -public: - bool isNeg; - bool isFloat; - - Number(reader::LocationRange loc, const std::string &, bool, bool); - ~Number(); - - SereneType getType() const override { return SereneType::Number; } - std::string string_repr() const override; - std::string dumpAST() const override; - - int64_t toI64(); - - static bool classof(const AExpr *); -}; - -std::unique_ptr makeNumber(reader::LocationRange, std::string, bool, - bool); -} // namespace serene - -#endif diff --git a/include/serene/reader/reader.h b/include/serene/reader/reader.h index d8ca33b..f49f2ca 100644 --- a/include/serene/reader/reader.h +++ b/include/serene/reader/reader.h @@ -36,7 +36,6 @@ #include "serene/exprs/expression.h" #include "serene/exprs/list.h" #include "serene/exprs/symbol.h" -#include "serene/logger.hpp" #include "serene/reader/errors.h" #include "serene/reader/location.h" #include "serene/serene.h" diff --git a/include/serene/state.hpp b/include/serene/state.hpp deleted file mode 100644 index 5d4e0b5..0000000 --- a/include/serene/state.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef STATE_H -#define STATE_H - -#include "serene/llvm/IR/Value.h" -#include "serene/logger.hpp" -//#include "serene/namespace.h" -#include -#include - -#if defined(ENABLE_LOG) || defined(ENABLE_STATE_LOG) -#define STATE_LOG(...) __LOG("STATE", __VA_ARGS__); -#else -#define STATE_LOG(...) ; -#endif - -namespace serene {} // namespace serene - -#endif diff --git a/include/serene/symbol.hpp b/include/serene/symbol.hpp deleted file mode 100644 index fbdd735..0000000 --- a/include/serene/symbol.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef SYMBOL_H -#define SYMBOL_H - -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/reader/location.h" -#include "serene/state.hpp" -#include - -namespace serene { -class Symbol : public AExpr { - const std::string name_; - -public: - Symbol(reader::LocationRange loc, const std::string &); - virtual ~Symbol(); - - const std::string &getName() const; - - SereneType getType() const override { return SereneType::Symbol; } - std::string string_repr() const override; - std::string dumpAST() const override; - - static bool classof(const AExpr *); -}; - -std::unique_ptr makeSymbol(reader::LocationRange, std::string); -} // namespace serene - -#endif diff --git a/src/serene/CMakeLists.txt b/src/serene/CMakeLists.txt index 253653b..eaea3a7 100644 --- a/src/serene/CMakeLists.txt +++ b/src/serene/CMakeLists.txt @@ -20,19 +20,9 @@ set(HEADER_LIST "${INCLUDE_DIR}/serene/errors/constants.h" - "${INCLUDE_DIR}/serene/expr.hpp" - - "${INCLUDE_DIR}/serene/number.hpp" - "${INCLUDE_DIR}/serene/symbol.hpp" - "${INCLUDE_DIR}/serene/list.hpp" - "${INCLUDE_DIR}/serene/error.hpp" - - "${INCLUDE_DIR}/serene/state.hpp" - - - "${INCLUDE_DIR}/serene/sir/sir.hpp" - "${INCLUDE_DIR}/serene/sir/dialect.hpp" - "${INCLUDE_DIR}/serene/sir/generator.hpp" + # "${INCLUDE_DIR}/serene/sir/sir.hpp" + # "${INCLUDE_DIR}/serene/sir/dialect.hpp" + # "${INCLUDE_DIR}/serene/sir/generator.hpp" "${INCLUDE_DIR}/serene/namespace.h") # Make an automatic library - will be static or dynamic based on user setting @@ -45,11 +35,7 @@ add_library(serene serene.cpp - symbol.cpp - list.cpp namespace.cpp - state.cpp - number.cpp # Reader reader/reader.cpp @@ -61,10 +47,10 @@ add_library(serene errors/error.cpp # IR - sir/sir.cpp - sir/dialect.cpp - sir/value_op.cpp - sir/generator.cpp + # sir/sir.cpp + # sir/dialect.cpp + # sir/value_op.cpp + # sir/generator.cpp ${HEADER_LIST}) diff --git a/src/serene/list.cpp b/src/serene/list.cpp deleted file mode 100644 index bd77527..0000000 --- a/src/serene/list.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "serene/list.hpp" -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/symbol.hpp" -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/Optional.h" -#include -#include -#include - -using namespace llvm; - -namespace serene { - -List::List(reader::Location startLoc) { - this->location.reset(new reader::LocationRange(startLoc)); -} - -List::List(std::vector elements) { - auto startLoc = elements[0]->location->start; - auto endLoc = elements[elements.size() - 1]->location->end; - this->location.reset(new reader::LocationRange(startLoc, endLoc)); - this->nodes_ = elements; -} - -llvm::Optional List::at(uint index) const { - if (index >= nodes_.size()) { - return llvm::None; - } - - return llvm::Optional(this->nodes_[index]); -} - -void List::append(ast_node node) { nodes_.push_back(std::move(node)); } - -std::string List::string_repr() const { - std::string s; - - for (auto &n : nodes_) { - // TODO: Fix the tailing space for the last element - s = s + n->string_repr() + " "; - } - - return fmt::format("({})", s); -} - -std::string List::dumpAST() const { - std::string s; - - for (auto &n : nodes_) { - s = fmt::format("{} {}", s, n->dumpAST()); - } - - return fmt::format("", - this->location->start.toString(), - this->location->end.toString(), s); -} -/** - * Return an iterator to be used with the `for` loop. It's implicitly called by - * the for loop. - */ -std::vector::const_iterator List::begin() { return nodes_.begin(); } - -/** - * Return an iterator to be used with the `for` loop. It's implicitly called by - * the for loop. - */ -std::vector::const_iterator List::end() { return nodes_.end(); } - -/** - * Return a sub set of elements starting from the `begin` index to the end - * and an empty list otherwise. - */ - -std::unique_ptr List::from(uint begin) { - if (this->count() - begin < 1) { - return makeList(this->location->end); - } - - std::vector::const_iterator first = this->nodes_.begin() + begin; - std::vector::const_iterator last = this->nodes_.end(); - - std::vector newCopy(first, last); - - return std::make_unique(newCopy); -}; - -llvm::ArrayRef List::asArrayRef() { - return llvm::makeArrayRef(this->nodes_); -} - -size_t List::count() const { return nodes_.size(); } - -/** - * `classof` is a enabler static method that belongs to the LLVM RTTI interface - * `llvm::isa`, `llvm::cast` and `llvm::dyn_cast` use this method. - */ -bool List::classof(const AExpr *expr) { - return expr->getType() == SereneType::List; -} - -/** - * Make an empty List in starts at the given location `loc`. - */ -std::unique_ptr makeList(reader::Location loc) { - return std::make_unique(loc); -} -/** - * Make a list out of the given pointer to a List - */ -std::unique_ptr makeList(List *list) { - return std::unique_ptr(list); -} - -} // namespace serene diff --git a/src/serene/number.cpp b/src/serene/number.cpp deleted file mode 100644 index 4977d92..0000000 --- a/src/serene/number.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "serene/number.hpp" -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/namespace.h" -#include "serene/state.hpp" -#include -#include -#include -#include -#include - -namespace serene { - -std::string Number::string_repr() const { return num_; } - -std::string Number::dumpAST() const { - return fmt::format("", - this->location->start.toString(), - this->location->end.toString(), this->num_); -} - -Number::Number(reader::LocationRange loc, const std::string &num, bool isNeg, - bool isFloat) - : num_(num), isNeg(isNeg), isFloat(isFloat) { - this->location.reset(new reader::LocationRange(loc)); -} -int64_t Number::toI64() { - // TODO: Handle float case as well - return std::stoi(num_); -}; - -/** - * `classof` is a enabler static method that belongs to the LLVM RTTI interface - * `llvm::isa`, `llvm::cast` and `llvm::dyn_cast` use this method. - */ -bool Number::classof(const AExpr *expr) { - return expr->getType() == SereneType::Number; -} - -Number::~Number() { EXPR_LOG("Destroying number"); } - -std::unique_ptr makeNumber(reader::LocationRange loc, std::string num, - bool isNeg, bool isFloat) { - return std::make_unique(loc, num, isNeg, isFloat); -} - -} // namespace serene diff --git a/src/serene/reader/reader.cpp b/src/serene/reader/reader.cpp index 83a5908..64760f1 100644 --- a/src/serene/reader/reader.cpp +++ b/src/serene/reader/reader.cpp @@ -23,7 +23,6 @@ */ #include "serene/reader/reader.h" -#include "serene/error.hpp" #include "serene/exprs/list.h" #include "serene/exprs/number.h" #include "serene/exprs/symbol.h" @@ -302,7 +301,7 @@ exprs::maybe_ast FileReader::read() { if (std::error_code EC = fileOrErr.getError()) { llvm::errs() << "Could not open input file: " << EC.message() << "\n"; - llvm::errs() << fmt::format("File: '{}'\n", file); + llvm::errs() << llvm::formatv("File: '{0}'\n", file); llvm::errs() << "Use absolute path for now\n"; return Result::Error(llvm::make_error(file)); } diff --git a/src/serene/state.cpp b/src/serene/state.cpp deleted file mode 100644 index ffc59e4..0000000 --- a/src/serene/state.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "serene/state.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/namespace.h" -#include -#include - -using namespace std; -using namespace llvm; - -namespace serene { -// State::State() { current_ns = nullptr; }; - -// void State::add_namespace(Namespace *ns, bool set_current, bool overwrite) { -// if (ns->name.empty()) { -// // TODO: Better error handling -// fmt::print("Error: namespace name is missing\n."); -// exit(1); -// } - -// Namespace *already_exist_ns = namespaces[ns->name]; - -// if (already_exist_ns && !overwrite) { -// return; -// } - -// if (already_exist_ns) { -// delete namespaces[ns->name]; -// } - -// namespaces[ns->name] = ns; - -// if (set_current) { -// set_current_ns(ns); -// } -// }; - -// bool State::set_current_ns(Namespace *ns) { -// Namespace *already_exist_ns = namespaces[ns->name]; -// if (already_exist_ns) { -// current_ns = ns; -// return true; -// } -// return false; -// }; - -// Value *State::lookup_in_current_scope(const string &name) { -// if (current_ns) { -// return current_ns->lookup(name); -// } - -// fmt::print("FATAL ERROR: Current ns is not set."); -// // TODO: Come up with the ERRNO table and return the proper ERRNO -// exit(1); -// }; - -// void State::set_in_current_ns_root_scope(string name, Value *v) { -// if (current_ns) { -// current_ns->insert_symbol(name, v); -// return; -// } - -// fmt::print("FATAL ERROR: Current ns is not set."); -// // TODO: Come up with the ERRNO table and return the proper ERRNO -// exit(1); -// }; - -// State::~State() { -// STATE_LOG("Deleting namespaces...") -// std::map::iterator it = namespaces.begin(); -// while (it != namespaces.end()) { -// STATE_LOG("DELETING {}", it->first); -// Namespace *tmp = it->second; -// namespaces[it->first] = nullptr; -// delete tmp; -// it++; -// } -// STATE_LOG("Clearing namespaces..."); -// namespaces.clear(); -// }; -} // namespace serene diff --git a/src/serene/symbol.cpp b/src/serene/symbol.cpp deleted file mode 100644 index 5a644c7..0000000 --- a/src/serene/symbol.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Serene programming language. - * - * Copyright (c) 2020 Sameer Rahmani - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "serene/symbol.hpp" -#include "serene/expr.hpp" -#include "serene/llvm/IR/Value.h" -#include "serene/namespace.h" -#include "serene/state.hpp" -#include -#include -#include -#include -#include - -using namespace std; -using namespace llvm; - -namespace serene { - -string Symbol::string_repr() const { return name_; } - -string Symbol::dumpAST() const { - return fmt::format("", - this->location->start.toString(), - this->location->end.toString(), this->getName()); -} - -const string &Symbol::getName() const { return name_; } - -Symbol::Symbol(reader::LocationRange loc, const string &name) : name_(name) { - this->location.reset(new reader::LocationRange(loc)); -} - -/** - * `classof` is a enabler static method that belongs to the LLVM RTTI interface - * `llvm::isa`, `llvm::cast` and `llvm::dyn_cast` use this method. - */ -bool Symbol::classof(const AExpr *expr) { - return expr->getType() == SereneType::Symbol; -} - -Symbol::~Symbol() { EXPR_LOG("Destroying symbol"); } - -std::unique_ptr makeSymbol(reader::LocationRange loc, - std::string name) { - return std::make_unique(loc, name); -} -} // namespace serene