Remove the old implementations to keep the source tree as clean as possible
This commit is contained in:
parent
17b778bc49
commit
4fde47311e
|
@ -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 <iostream>
|
||||
#include <llvm/Support/CommandLine.h>
|
||||
|
||||
|
@ -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: {
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
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
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
#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<reader::LocationRange> 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<AExpr>;
|
||||
using ast_tree = std::vector<ast_node>;
|
||||
|
||||
} // namespace serene
|
||||
|
||||
#endif
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <list>
|
||||
#include <string>
|
||||
|
||||
namespace serene {
|
||||
|
||||
class List : public AExpr {
|
||||
std::vector<ast_node> nodes_;
|
||||
|
||||
public:
|
||||
List(){};
|
||||
List(std::vector<ast_node> 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<List> from(uint begin);
|
||||
llvm::Optional<ast_node> at(uint index) const;
|
||||
|
||||
std::vector<ast_node>::const_iterator begin();
|
||||
std::vector<ast_node>::const_iterator end();
|
||||
llvm::ArrayRef<ast_node> asArrayRef();
|
||||
|
||||
static bool classof(const AExpr *);
|
||||
};
|
||||
|
||||
std::unique_ptr<List> makeList(reader::Location);
|
||||
std::unique_ptr<List> makeList(reader::Location, List *);
|
||||
|
||||
using ast_list_node = std::unique_ptr<List>;
|
||||
} // namespace serene
|
||||
|
||||
#endif
|
|
@ -1,37 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <fmt/core.h>
|
||||
|
||||
// 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
|
|
@ -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 <llvm/IR/Module.h>
|
||||
#include <string>
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
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<Number> makeNumber(reader::LocationRange, std::string, bool,
|
||||
bool);
|
||||
} // namespace serene
|
||||
|
||||
#endif
|
|
@ -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"
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <llvm/IR/Module.h>
|
||||
#include <string>
|
||||
|
||||
#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
|
|
@ -1,54 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <string>
|
||||
|
||||
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<Symbol> makeSymbol(reader::LocationRange, std::string);
|
||||
} // namespace serene
|
||||
|
||||
#endif
|
|
@ -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})
|
||||
|
||||
|
||||
|
|
|
@ -1,139 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <bits/c++config.h>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
namespace serene {
|
||||
|
||||
List::List(reader::Location startLoc) {
|
||||
this->location.reset(new reader::LocationRange(startLoc));
|
||||
}
|
||||
|
||||
List::List(std::vector<ast_node> 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<ast_node> List::at(uint index) const {
|
||||
if (index >= nodes_.size()) {
|
||||
return llvm::None;
|
||||
}
|
||||
|
||||
return llvm::Optional<ast_node>(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("<List [loc: {} | {}]: {} >",
|
||||
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<ast_node>::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<ast_node>::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> List::from(uint begin) {
|
||||
if (this->count() - begin < 1) {
|
||||
return makeList(this->location->end);
|
||||
}
|
||||
|
||||
std::vector<ast_node>::const_iterator first = this->nodes_.begin() + begin;
|
||||
std::vector<ast_node>::const_iterator last = this->nodes_.end();
|
||||
|
||||
std::vector<ast_node> newCopy(first, last);
|
||||
|
||||
return std::make_unique<List>(newCopy);
|
||||
};
|
||||
|
||||
llvm::ArrayRef<ast_node> List::asArrayRef() {
|
||||
return llvm::makeArrayRef<ast_node>(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<List> makeList(reader::Location loc) {
|
||||
return std::make_unique<List>(loc);
|
||||
}
|
||||
/**
|
||||
* Make a list out of the given pointer to a List
|
||||
*/
|
||||
std::unique_ptr<List> makeList(List *list) {
|
||||
return std::unique_ptr<List>(list);
|
||||
}
|
||||
|
||||
} // namespace serene
|
|
@ -1,71 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <assert.h>
|
||||
#include <fmt/core.h>
|
||||
#include <llvm/IR/Constants.h>
|
||||
#include <llvm/IR/Type.h>
|
||||
#include <string>
|
||||
|
||||
namespace serene {
|
||||
|
||||
std::string Number::string_repr() const { return num_; }
|
||||
|
||||
std::string Number::dumpAST() const {
|
||||
return fmt::format("<Number [loc: {} | {}]: {}>",
|
||||
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<Number> makeNumber(reader::LocationRange loc, std::string num,
|
||||
bool isNeg, bool isFloat) {
|
||||
return std::make_unique<Number>(loc, num, isNeg, isFloat);
|
||||
}
|
||||
|
||||
} // namespace serene
|
|
@ -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<exprs::ast>::Error(llvm::make_error<MissingFileError>(file));
|
||||
}
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <fmt/core.h>
|
||||
#include <string>
|
||||
|
||||
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<string, Namespace *>::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
|
|
@ -1,69 +0,0 @@
|
|||
/**
|
||||
* Serene programming language.
|
||||
*
|
||||
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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 <assert.h>
|
||||
#include <fmt/core.h>
|
||||
#include <llvm/IR/Constants.h>
|
||||
#include <llvm/IR/Type.h>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace llvm;
|
||||
|
||||
namespace serene {
|
||||
|
||||
string Symbol::string_repr() const { return name_; }
|
||||
|
||||
string Symbol::dumpAST() const {
|
||||
return fmt::format("<Symbol [loc: {} | {}]: {}>",
|
||||
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<Symbol> makeSymbol(reader::LocationRange loc,
|
||||
std::string name) {
|
||||
return std::make_unique<Symbol>(loc, name);
|
||||
}
|
||||
} // namespace serene
|
Loading…
Reference in New Issue