summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/hir/type.cpp2
-rw-r--r--src/hir_typeck/expr.cpp67
-rw-r--r--src/include/tagged_union.hpp4
-rw-r--r--src/resolve/absolute.cpp2
4 files changed, 50 insertions, 25 deletions
diff --git a/src/hir/type.cpp b/src/hir/type.cpp
index e4931dbf..f3ba220f 100644
--- a/src/hir/type.cpp
+++ b/src/hir/type.cpp
@@ -341,7 +341,7 @@ namespace {
(Struct , return ::HIR::TypeRef::TypePathBinding(e); ),
(Enum , return ::HIR::TypeRef::TypePathBinding(e); )
)
- throw "";
+ assert(!"Fell off end of clone_binding");
}
}
diff --git a/src/hir_typeck/expr.cpp b/src/hir_typeck/expr.cpp
index 5446a299..b15abc4d 100644
--- a/src/hir_typeck/expr.cpp
+++ b/src/hir_typeck/expr.cpp
@@ -2214,7 +2214,6 @@ namespace {
const ::HIR::Function* fcn_ptr = nullptr;
::std::function<const ::HIR::TypeRef&(const ::HIR::TypeRef&)> monomorph_cb;
- // TODO: Construct method to get a reference to an item along with the params decoded out of the path?
TU_MATCH(::HIR::Path::Data, (path.m_data), (e),
(Generic,
const auto& fcn = this->context.m_crate.get_function_by_path(sp, e.m_path);
@@ -2227,12 +2226,19 @@ namespace {
const auto& e = gt.m_data.as_Generic();
if( e.name == "Self" )
TODO(sp, "Handle 'Self' when monomorphising");
- //if( e.binding >= params_def.m_types.size() ) {
- //}
- if( e.binding >= path_params.m_types.size() ) {
- BUG(sp, "Generic param out of input range - " << e.binding << " '"<<e.name<<"' >= " << path_params.m_types.size());
+ if( e.binding < 256 ) {
+ BUG(sp, "Impl-level parameter on free function (#" << e.binding << " " << e.name << ")");
+ }
+ else if( e.binding < 512 ) {
+ auto idx = e.binding - 256;
+ if( idx >= path_params.m_types.size() ) {
+ BUG(sp, "Generic param out of input range - " << idx << " '"<<e.name<<"' >= " << path_params.m_types.size());
+ }
+ return path_params.m_types[idx];
+ }
+ else {
+ BUG(sp, "Generic bounding out of total range");
}
- return path_params.m_types[e.binding];
};
),
(UfcsKnown,
@@ -2243,19 +2249,30 @@ namespace {
fcn_ptr = &fcn;
- //const auto& path_params = e.params;
+ const auto& trait_params = e.trait.m_params;
+ const auto& path_params = e.params;
monomorph_cb = [&](const auto& gt)->const auto& {
const auto& ge = gt.m_data.as_Generic();
if( ge.binding == 0xFFFF ) {
return *e.type;
}
- // TODO: Don't the function-level params use 256-511?
- //else if( ge.binding < 256 ) {
- // return path_params.m_types[ge.binding];
- //}
- //else {
- //}
- TODO(sp, "Monomorphise for trait method "<<path<<" - Param " << ge.name << " (" << ge.binding << ")");
+ else if( ge.binding < 256 ) {
+ auto idx = ge.binding;
+ if( idx >= trait_params.m_types.size() ) {
+ BUG(sp, "Generic param (impl) out of input range - " << idx << " '"<<ge.name<<"' >= " << trait_params.m_types.size());
+ }
+ return trait_params.m_types[idx];
+ }
+ else if( ge.binding < 512 ) {
+ auto idx = ge.binding - 256;
+ if( idx >= path_params.m_types.size() ) {
+ BUG(sp, "Generic param out of input range - " << idx << " '"<<ge.name<<"' >= " << path_params.m_types.size());
+ }
+ return path_params.m_types[idx];
+ }
+ else {
+ BUG(sp, "Generic bounding out of total range");
+ }
};
),
(UfcsUnknown,
@@ -2283,18 +2300,26 @@ namespace {
assert(impl_ptr);
this->fix_param_count(sp, path, fcn_ptr->m_params, e.params);
+ //const auto& impl_params = .m_params;
+ const auto& fcn_params = e.params;
monomorph_cb = [&](const auto& gt)->const auto& {
const auto& ge = gt.m_data.as_Generic();
if( ge.binding == 0xFFFF ) {
return *e.type;
}
- // TODO: Don't the function-level params use 256-511?
- //else if( ge.binding < 256 ) {
- // return path_params.m_types[ge.binding];
- //}
- //else {
- //}
- TODO(sp, "Monomorphise for type method - " << ge.name << " " << ge.binding);
+ else if( ge.binding < 256 ) {
+ TODO(sp, "Expand impl-leve generic params in UfcsInherent (path = " << path << ", param = #" << ge.binding << " '" << ge.name << "')");
+ }
+ else if( ge.binding < 512 ) {
+ auto idx = ge.binding - 256;
+ if( idx >= fcn_params.m_types.size() ) {
+ BUG(sp, "Generic param out of input range - " << idx << " '" << ge.name << "' >= " << fcn_params.m_types.size());
+ }
+ return fcn_params.m_types[idx];
+ }
+ else {
+ BUG(sp, "Generic bounding out of total range");
+ }
};
)
)
diff --git a/src/include/tagged_union.hpp b/src/include/tagged_union.hpp
index e0a30dd0..fcf924c8 100644
--- a/src/include/tagged_union.hpp
+++ b/src/include/tagged_union.hpp
@@ -99,11 +99,11 @@
// "match"-like statement
// TU_MATCH(Class, m_data, ent, (Variant, CODE), (Variant2, CODE))
#define TU_MATCH(CLASS, VAR, NAME, ...) switch( (TU_FIRST VAR).tag()) {/*
-*/ case CLASS::TAGDEAD: throw "ERROR: destructed tagged union used";/*
+*/ case CLASS::TAGDEAD: assert(!"ERROR: destructed tagged union used");/*
*/ TU_MATCH_ARMS(CLASS, VAR, NAME, __VA_ARGS__)/*
*/}
#define TU_MATCH_DEF(CLASS, VAR, NAME, DEF, ...) switch( (TU_FIRST VAR).tag()) {/*
-*/ case CLASS::TAGDEAD: throw "ERROR: destructed tagged union used";/*
+*/ case CLASS::TAGDEAD: assert(!"ERROR: destructed tagged union used");/*
*/ TU_MATCH_ARMS(CLASS, VAR, NAME, __VA_ARGS__)/*
*/ default: {TU_EXP DEF;} break;/*
*/}
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index 4b749e33..4c1eb927 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -1328,7 +1328,7 @@ void Resolve_Absolute_Mod( Context item_context, ::AST::Module& mod )
),
(Function,
DEBUG("Function - " << i.name);
- item_context.push( e.params(), GenericSlot::Level::Top );
+ item_context.push( e.params(), GenericSlot::Level::Method );
Resolve_Absolute_Generic(item_context, e.params());
Resolve_Absolute_Type( item_context, e.rettype() );