generated from TheLartians/ModernCppStarter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6157a44
commit 47aa027
Showing
21 changed files
with
1,850 additions
and
1,361 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
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,146 @@ | ||
#include "flatten.hpp" | ||
|
||
// #include <any> | ||
// #include <cassert> | ||
// #include <cmath> | ||
// #include <cstring> | ||
// #include <map> | ||
// #include <random> | ||
// #include <sstream> | ||
|
||
const int MAX_FLAT_PARAMS = 16; | ||
const int MAX_FLAT_RESULTS = 1; | ||
|
||
std::vector<std::string> flatten_type(ValType kind); | ||
std::vector<std::string> flatten_types(const std::vector<ValType> &ts); | ||
|
||
// CoreFuncType flatten_functype(FuncTypePtr ft, std::string context) | ||
// { | ||
// std::vector<std::string> flat_params = flatten_types(ft->param_types()); | ||
// if (flat_params.size() > MAX_FLAT_PARAMS) | ||
// { | ||
// flat_params = {"i32"}; | ||
// } | ||
|
||
// std::vector<std::string> flat_results = flatten_types(ft->result_types()); | ||
// if (flat_results.size() > MAX_FLAT_RESULTS) | ||
// { | ||
// if (context == "lift") | ||
// { | ||
// flat_results = {"i32"}; | ||
// } | ||
// else if (context == "lower") | ||
// { | ||
// flat_params.push_back("i32"); | ||
// flat_results = {}; | ||
// } | ||
// } | ||
|
||
// return CoreFuncType(flat_params, flat_results); | ||
// } | ||
|
||
std::vector<std::string> flatten_types(const std::vector<Val> &vs) | ||
{ | ||
std::vector<std::string> result; | ||
for (Val v : vs) | ||
{ | ||
std::vector<std::string> flattened = flatten_type(v.kind()); | ||
result.insert(result.end(), flattened.begin(), flattened.end()); | ||
} | ||
return result; | ||
} | ||
|
||
std::vector<std::string> flatten_types(const std::vector<ValType> &ts) | ||
{ | ||
std::vector<std::string> result; | ||
for (ValType t : ts) | ||
{ | ||
std::vector<std::string> flattened = flatten_type(t); | ||
result.insert(result.end(), flattened.begin(), flattened.end()); | ||
} | ||
return result; | ||
} | ||
|
||
std::vector<std::string> flatten_record(const std::vector<Field> &fields); | ||
std::vector<std::string> flatten_variant(const std::vector<Case> &cases); | ||
|
||
std::vector<std::string> flatten_type(ValType kind) | ||
{ | ||
switch (kind) | ||
{ | ||
case ValType::Bool: | ||
return {"i32"}; | ||
case ValType::U8: | ||
case ValType::U16: | ||
case ValType::U32: | ||
return {"i32"}; | ||
case ValType::U64: | ||
return {"i64"}; | ||
case ValType::S8: | ||
case ValType::S16: | ||
case ValType::S32: | ||
return {"i32"}; | ||
case ValType::S64: | ||
return {"i64"}; | ||
case ValType::Float32: | ||
return {"f32"}; | ||
case ValType::Float64: | ||
return {"f64"}; | ||
case ValType::Char: | ||
return {"i32"}; | ||
case ValType::String: | ||
return {"i32", "i32"}; | ||
case ValType::List: | ||
return {"i32", "i32"}; | ||
// case ValType::Record: | ||
// return flatten_record(static_cast<const Record &>(t).fields); | ||
// case ValType::Variant: | ||
// return flatten_variant(static_cast<const Variant &>(t).cases); | ||
// case ValType::Flags: | ||
// return std::vector<std::string>(num_i32_flags(static_cast<const Flags &>(t).labels), | ||
// "i32"); | ||
// case ValType::Own: | ||
// case ValType::Borrow: | ||
// return {"i32"}; | ||
default: | ||
throw std::runtime_error("Invalid type"); | ||
} | ||
} | ||
|
||
std::vector<std::string> flatten_record(const std::vector<Field> &fields) | ||
{ | ||
std::vector<std::string> flat; | ||
for (const Field &f : fields) | ||
{ | ||
auto flattened = flatten_type(f.v.value().kind()); | ||
flat.insert(flat.end(), flattened.begin(), flattened.end()); | ||
} | ||
return flat; | ||
} | ||
|
||
// std::string join(const std::string &a, const std::string &b); | ||
// std::vector<std::string> flatten_variant(const std::vector<Case> &cases) | ||
// { | ||
// std::vector<std::string> flat; | ||
// for (const auto &c : cases) | ||
// { | ||
// if (c.t.has_value()) | ||
// { | ||
// auto flattened = flatten_type(c.t.value()); | ||
// for (size_t i = 0; i < flattened.size(); ++i) | ||
// { | ||
// if (i < flat.size()) | ||
// { | ||
// flat[i] = join(flat[i], flattened[i]); | ||
// } | ||
// else | ||
// { | ||
// flat.push_back(flattened[i]); | ||
// } | ||
// } | ||
// } | ||
// } | ||
// auto discriminantFlattened = flatten_type(discriminant_type(cases)); | ||
// flat.insert(flat.begin(), discriminantFlattened.begin(), discriminantFlattened.end()); | ||
// return flat; | ||
// } |
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,7 @@ | ||
#ifndef FLATTEN_HPP | ||
#define FLATTEN_HPP | ||
|
||
#include "context.hpp" | ||
#include "val.hpp" | ||
|
||
#endif |
Oops, something went wrong.