Setup the minimal rewrite wiring to rewrite 'def' to Def
This commit is contained in:
parent
30c54f9e73
commit
9f90e42bbb
|
@ -44,7 +44,7 @@ public:
|
||||||
node value;
|
node value;
|
||||||
|
|
||||||
Def(reader::LocationRange &loc, llvm::StringRef binding, node &v)
|
Def(reader::LocationRange &loc, llvm::StringRef binding, node &v)
|
||||||
: Expression(loc), binding(binding), value(std::move(v)){};
|
: Expression(loc), binding(binding), value(v){};
|
||||||
|
|
||||||
ExprType getType() const;
|
ExprType getType() const;
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
|
@ -46,7 +46,6 @@ public:
|
||||||
|
|
||||||
List(const reader::LocationRange &loc) : Expression(loc){};
|
List(const reader::LocationRange &loc) : Expression(loc){};
|
||||||
List(const reader::LocationRange &loc, node &e);
|
List(const reader::LocationRange &loc, node &e);
|
||||||
// List(const reader::LocationRange &loc, llvm::MutableArrayRef<node> elems);
|
|
||||||
List(const reader::LocationRange &loc, ast elems);
|
List(const reader::LocationRange &loc, ast elems);
|
||||||
|
|
||||||
ExprType getType() const;
|
ExprType getType() const;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "serene/exprs/def.h"
|
#include "serene/exprs/def.h"
|
||||||
#include "serene/exprs/symbol.h"
|
#include "serene/exprs/symbol.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/FormatVariadic.h"
|
#include "llvm/Support/FormatVariadic.h"
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
|
||||||
|
@ -37,10 +38,6 @@ List::List(const reader::LocationRange &loc, node &e) : Expression(loc) {
|
||||||
elements.push_back(e);
|
elements.push_back(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// List::List(const reader::LocationRange &loc, llvm::MutableArrayRef<node>
|
|
||||||
// elems)
|
|
||||||
// : Expression(loc), elements(elems.begin(), elems.end()) {};
|
|
||||||
|
|
||||||
List::List(const reader::LocationRange &loc, ast elems)
|
List::List(const reader::LocationRange &loc, ast elems)
|
||||||
: Expression(loc), elements(elems){};
|
: Expression(loc), elements(elems){};
|
||||||
|
|
||||||
|
@ -58,24 +55,34 @@ std::string List::toString() const {
|
||||||
};
|
};
|
||||||
|
|
||||||
maybe_node List::analyze(reader::SemanticContext &ctx) {
|
maybe_node List::analyze(reader::SemanticContext &ctx) {
|
||||||
// if (!elements.empty()) {
|
if (!elements.empty()) {
|
||||||
// auto *first = elements[0].get();
|
auto *first = elements[0].get();
|
||||||
|
|
||||||
// if (first->getType() == ExprType::Symbol) {
|
if (first->getType() == ExprType::Symbol) {
|
||||||
// auto *sym = llvm::dyn_cast<Symbol>(first);
|
auto *sym = llvm::dyn_cast<Symbol>(first);
|
||||||
|
|
||||||
// if (sym->name == "def") {
|
if (sym) {
|
||||||
// if (auto err = Def::isValid(this)) {
|
if (sym->name == "def") {
|
||||||
// // Not a valid `def` form
|
if (auto err = Def::isValid(this)) {
|
||||||
// return Result<node>::Error(std::move(err));
|
// Not a valid `def` form
|
||||||
// }
|
return Result<node>::Error(std::move(err));
|
||||||
|
}
|
||||||
|
|
||||||
// auto *binding = llvm::dyn_cast<Symbol>(elements[1].get());
|
Symbol *binding = llvm::dyn_cast<Symbol>(elements[1].get());
|
||||||
// auto def = make<Def>(binding->name, std::move(elements[2]));
|
|
||||||
// return Result<node>::Success(std::move(def));
|
if (!binding) {
|
||||||
// }
|
llvm_unreachable("Def::isValid should of catch this.");
|
||||||
// }
|
}
|
||||||
// }
|
|
||||||
|
node def = make<Def>(location, binding->name, elements[2]);
|
||||||
|
return Result<node>::Success(def);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Return an error saying the binding has to be
|
||||||
|
// a symbol
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Result<node>::Success(nullptr);
|
return Result<node>::Success(nullptr);
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,10 +39,9 @@ exprs::maybe_ast Semantics::analyze(exprs::ast &inputAst) {
|
||||||
auto &node = maybeNode.getValue();
|
auto &node = maybeNode.getValue();
|
||||||
|
|
||||||
if (node) {
|
if (node) {
|
||||||
llvm::outs() << "HERE\n" << node->toString() << " n\n";
|
ast.push_back(node);
|
||||||
ast.push_back(std::move(node));
|
|
||||||
} else {
|
} else {
|
||||||
ast.push_back(std::move(element));
|
ast.push_back(element);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Result<exprs::ast>::Error(std::move(maybeNode.getError()));
|
Result<exprs::ast>::Error(std::move(maybeNode.getError()));
|
||||||
|
|
Loading…
Reference in New Issue