diff --git a/ir/builtin_module.cc b/ir/builtin_module.cc index bf1214d3..381b85d0 100644 --- a/ir/builtin_module.cc +++ b/ir/builtin_module.cc @@ -41,39 +41,35 @@ Module BuiltinModule(GlobalFunctionRegistry& registry) { Module m(registry); m.Insert(resources.IdentifierIndex("print"), - {.qualified_type = type::QualifiedType( - type::Qualifier::Constant(), - type::Function(type::Parameters( - std::vector{ - {.name = resources.IdentifierIndex(""), - .type = type::Slice(type::Char)}, - }), - {type::Bool})), - .value = {jasmin::Value(&*PrintFn)}}); + {.qualified_type = type::QualifiedType::Constant(type::Function( + type::Parameters(std::vector{ + {.name = resources.IdentifierIndex(""), + .type = type::Slice(type::Char)}, + }), + {type::Bool})), + .value = {jasmin::Value(&*PrintFn)}}); registry.Register(FunctionId(ModuleId::Builtin(), LocalFunctionId(next_id++)), &*PrintFn); - m.Insert( - resources.IdentifierIndex("foreign"), - {.qualified_type = type::QualifiedType( - type::Qualifier::Constant(), type::GenericFunction(&*ForeignType)), - .value = {}}); + m.Insert(resources.IdentifierIndex("foreign"), + {.qualified_type = type::QualifiedType::Constant( + type::GenericFunction(&*ForeignType)), + .value = {}}); registry.Register(FunctionId(ModuleId::Builtin(), LocalFunctionId(next_id++)), &*Foreign); m.Insert( resources.IdentifierIndex("b2b"), - {.qualified_type = - type::QualifiedType(type::Qualifier::Constant(), type::Type_), - .value = {jasmin::Value(type::Type(type::Function( - type::Parameters(std::vector{ - {.name = resources.IdentifierIndex(""), .type = type::Bool}}), - {type::Bool})))}}); + {.qualified_type = type::QualifiedType::Constant(type::Type_), + .value = {jasmin::Value(type::Type(type::Function( + type::Parameters(std::vector{ + {.name = resources.IdentifierIndex(""), .type = type::Bool}}), + {type::Bool})))}}); m.Insert(resources.IdentifierIndex("function"), - {.qualified_type = type::QualifiedType(type::Qualifier::Constant(), - type::Pattern(type::Type_)), - .value = {jasmin::Value(&*Function)}}); + {.qualified_type = + type::QualifiedType::Constant(type::Pattern(type::Type_)), + .value = {jasmin::Value(&*Function)}}); registry.Register(FunctionId(ModuleId::Builtin(), LocalFunctionId(next_id++)), &*Function); diff --git a/ir/ir.cc b/ir/ir.cc index 8ab3ead1..4328cb58 100644 --- a/ir/ir.cc +++ b/ir/ir.cc @@ -214,8 +214,8 @@ void HandleParseTreeNodeCallExpression(ParseTree::Node::Index index, jasmin::Execute(*static_cast( invocable_type.type().AsGenericFunction().data()), value_stack); - context.type_stack.push_back(type::QualifiedType( - type::Qualifier::Constant(), value_stack.pop())); + context.type_stack.push_back( + type::QualifiedType::Constant(value_stack.pop())); } else { NTH_UNIMPLEMENTED("{}") <<= {node}; } diff --git a/type/type.h b/type/type.h index d6b3f98b..c5c8d6a0 100644 --- a/type/type.h +++ b/type/type.h @@ -98,6 +98,14 @@ struct Qualifier { struct QualifiedType { constexpr explicit QualifiedType() = default; + static constexpr QualifiedType Unqualified(Type t) { + return QualifiedType(Qualifier::Unqualified(), t); + } + + static constexpr QualifiedType Constant(Type t) { + return QualifiedType(Qualifier::Constant(), t); + } + constexpr explicit QualifiedType(Qualifier q, Type t) : data_(static_cast(q.data_) << 56 | t.data_) {}