Verified Commit fd77caab authored by nagayama15's avatar nagayama15

fix embedding method

parent 8b368114
...@@ -105,7 +105,10 @@ namespace kyut { ...@@ -105,7 +105,10 @@ namespace kyut {
const auto it = chunk_begin + i; const auto it = chunk_begin + i;
// Find the position of `begin + i`. // Find the position of `begin + i`.
const auto found = std::find(it, std::end(chunk), begin + i); const auto found = std::find_if(it, std::end(chunk), [&](const auto& a) {
return !less(*a, *(begin + i)) && !less(*(begin + i), *a);
});
assert(found != std::end(chunk)); assert(found != std::end(chunk));
const std::size_t pos = std::distance(it, found); const std::size_t pos = std::distance(it, found);
......
...@@ -15,15 +15,14 @@ namespace kyut { ...@@ -15,15 +15,14 @@ namespace kyut {
std::vector<typename std::iterator_traits<Iterator>::value_type> a, b; std::vector<typename std::iterator_traits<Iterator>::value_type> a, b;
auto it = begin; auto it = begin;
a.emplace_back(std::move(*it++)); a.emplace_back(std::move(*it));
while (it != end) { while (++it != end) {
if (pred(a.back(), *it)) { if (pred(a.back(), *it)) {
b.emplace_back(std::move(*it)); b.emplace_back(std::move(*it));
} else { } else {
a.emplace_back(std::move(*it)); a.emplace_back(std::move(*it));
} }
++it;
} }
it = begin; it = begin;
......
...@@ -22,6 +22,10 @@ namespace wasm { ...@@ -22,6 +22,10 @@ namespace wasm {
return *p; return *p;
}; };
if (&a == &b) {
return false;
}
if (a._id != b._id) { if (a._id != b._id) {
return a._id < b._id; return a._id < b._id;
} }
...@@ -347,6 +351,10 @@ namespace wasm { ...@@ -347,6 +351,10 @@ namespace wasm {
} }
inline bool operator<(const ExpressionList& a, const ExpressionList& b) { inline bool operator<(const ExpressionList& a, const ExpressionList& b) {
if (&a == &b) {
return false;
}
if (a.size() != b.size()) { if (a.size() != b.size()) {
return a.size() < b.size(); return a.size() < b.size();
} }
...@@ -362,6 +370,10 @@ namespace wasm { ...@@ -362,6 +370,10 @@ namespace wasm {
} }
inline bool operator<(const Function& a, const Function& b) { inline bool operator<(const Function& a, const Function& b) {
if (&a == &b) {
return false;
}
// wasm::Function::getNumVars() does not modify states // wasm::Function::getNumVars() does not modify states
return std::forward_as_tuple(a.sig, const_cast<Function&>(a).getNumVars(), *a.body) < return std::forward_as_tuple(a.sig, const_cast<Function&>(a).getNumVars(), *a.body) <
std::forward_as_tuple(b.sig, const_cast<Function&>(b).getNumVars(), *b.body); std::forward_as_tuple(b.sig, const_cast<Function&>(b).getNumVars(), *b.body);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment