Skip to content

Commit

Permalink
Simplify QualifiedType api.
Browse files Browse the repository at this point in the history
  • Loading branch information
asoffer committed Oct 7, 2023
1 parent 727bd36 commit 44ce6b3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
42 changes: 19 additions & 23 deletions ir/builtin_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<type::ParametersType::Parameter>{
{.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<type::ParametersType::Parameter>{
{.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<type::ParametersType::Parameter>{
{.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<type::ParametersType::Parameter>{
{.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);

Expand Down
4 changes: 2 additions & 2 deletions ir/ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ void HandleParseTreeNodeCallExpression(ParseTree::Node::Index index,
jasmin::Execute(*static_cast<IrFunction const*>(
invocable_type.type().AsGenericFunction().data()),
value_stack);
context.type_stack.push_back(type::QualifiedType(
type::Qualifier::Constant(), value_stack.pop<type::Type>()));
context.type_stack.push_back(
type::QualifiedType::Constant(value_stack.pop<type::Type>()));
} else {
NTH_UNIMPLEMENTED("{}") <<= {node};
}
Expand Down
8 changes: 8 additions & 0 deletions type/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(q.data_) << 56 | t.data_) {}

Expand Down

0 comments on commit 44ce6b3

Please sign in to comment.