-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a rather large change because to implement let-values, we fixed a couple of things along the way. * `define-values` should not create a new environment. Just adds to the current one. * as a consequence of the previous point, we need to add an empty env at interpreter construction time. * implement a downcast function from expr to value as that is needed around a few places. * add more implementations for dumper. Fixes #7
- Loading branch information
Showing
22 changed files
with
487 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "ast/letvalues.h" | ||
|
||
#include <utility> | ||
|
||
#include "exprnode_inc.h" | ||
|
||
using namespace nir; | ||
|
||
LetValues::LetValues(const LetValues &DV) { | ||
for (auto const &Id : DV.Ids) { | ||
Ids.emplace_back(Id); | ||
} | ||
for (auto const &Expr : DV.Exprs) { | ||
Exprs.emplace_back(std::make_unique<nir::ExprNode>(*Expr)); | ||
} | ||
for (auto const &Expr : DV.Body) { | ||
Body.emplace_back(std::make_unique<nir::ExprNode>(*Expr)); | ||
} | ||
} | ||
|
||
void LetValues::appendBinding(std::vector<Identifier> &&Ids, | ||
std::unique_ptr<ExprNode> Expr) { | ||
this->Ids.emplace_back(std::move(Ids)); | ||
this->Exprs.emplace_back(std::move(Expr)); | ||
} | ||
|
||
void LetValues::appendBody(std::unique_ptr<ExprNode> Expr) { | ||
Body.emplace_back(std::move(Expr)); | ||
} | ||
nir::LetValues::IdRange LetValues::getBindingIds(size_t Idx) const { | ||
assert(Idx < Ids.size()); | ||
return IdRange{Ids[Idx]}; | ||
} | ||
ExprNode const &LetValues::getBindingExpr(size_t Idx) const { | ||
return *Exprs[Idx]; | ||
} | ||
ExprNode const &LetValues::getBodyExpr(size_t Idx) const { return *Body[Idx]; } | ||
size_t nir::LetValues::exprsCount() const { return Exprs.size(); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ ASTNodes | |
|- +Application | ||
|- +SetBang | ||
|- +IfCond | ||
|- +LetValues | ||
|- Value | ||
|- +Integer | ||
|- +Values | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#pragma once | ||
|
||
#include <cassert> | ||
#include <memory> | ||
#include <vector> | ||
|
||
#include "../exprnode.h" | ||
#include "identifier.h" | ||
|
||
namespace nir { | ||
|
||
class LetValues { | ||
public: | ||
LetValues() = default; | ||
LetValues(const LetValues &DV); | ||
LetValues(LetValues &&DV) = default; | ||
LetValues &operator=(const LetValues &DV) = delete; | ||
LetValues &operator=(LetValues &&DV) = default; | ||
~LetValues() = default; | ||
|
||
// View over the Ids | ||
// FIXME: we should be able to use C++20 view_interface here | ||
// although my initial attempt failed. | ||
class IdRange { | ||
public: | ||
IdRange() = delete; | ||
IdRange(const std::vector<Identifier> &Ids) | ||
: BeginIt(Ids.cbegin()), EndIt(Ids.cend()) {} | ||
[[nodiscard]] auto begin() const { return BeginIt; } | ||
[[nodiscard]] auto end() const { return EndIt; } | ||
[[nodiscard]] Identifier const &operator[](size_t Idx) const { | ||
return *(BeginIt + Idx); | ||
} | ||
|
||
private: | ||
std::vector<Identifier>::const_iterator BeginIt, EndIt; | ||
}; | ||
|
||
IdRange getBindingIds(size_t Idx) const; | ||
ExprNode const &getBindingExpr(size_t Idx) const; | ||
ExprNode const &getBodyExpr(size_t Idx) const; | ||
|
||
void appendBinding(std::vector<Identifier> &&Ids, | ||
std::unique_ptr<ExprNode> Expr); | ||
void appendBody(std::unique_ptr<ExprNode> Expr); | ||
|
||
size_t bindingCount() const { | ||
assert(Ids.size() == Exprs.size()); | ||
return Ids.size(); | ||
} | ||
size_t idsCount() const { return Ids.size(); } | ||
size_t exprsCount() const; | ||
size_t bodyCount() const { return Body.size(); } | ||
|
||
private: | ||
std::vector<std::vector<Identifier>> Ids; | ||
std::vector<std::unique_ptr<ExprNode>> Exprs; | ||
std::vector<std::unique_ptr<ExprNode>> Body; | ||
}; | ||
|
||
}; // namespace nir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include "exprnode.h" | ||
#include "valuenode.h" | ||
|
||
std::unique_ptr<nir::ValueNode> | ||
downcastExprToValueNode(std::unique_ptr<nir::ExprNode> &&E); |
Oops, something went wrong.