From 87feeb5135fa0fe97f8724b77b02759aa283e1ff Mon Sep 17 00:00:00 2001 From: Luke Boswell Date: Wed, 24 Apr 2024 08:45:29 +1000 Subject: [PATCH] add abilities for glue types --- crates/glue/platform/TypeId.roc | 14 ++++++++------ crates/glue/platform/Types.roc | 18 +++++++++--------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/crates/glue/platform/TypeId.roc b/crates/glue/platform/TypeId.roc index e5e4f1f93a5..21b5c26bfc0 100644 --- a/crates/glue/platform/TypeId.roc +++ b/crates/glue/platform/TypeId.roc @@ -1,11 +1,13 @@ interface TypeId - exposes [TypeId, fromU64, toU64] + exposes [TypeId, typeIDfromU64, typeIDtoU64] imports [] -TypeId := U64 implements [Eq, Hash] +TypeId := U64 implements [Eq, Hash, Inspect, Encoding] -toU64 : TypeId -> U64 -toU64 = \@TypeId x -> x +# renamed here so we can import the functions directly as a workaround for +# https://github.com/roc-lang/roc/issues/5477 +typeIDtoU64 : TypeId -> U64 +typeIDtoU64 = \@TypeId x -> x -fromU64 : U64 -> TypeId -fromU64 = @TypeId +typeIDfromU64 : U64 -> TypeId +typeIDfromU64 = @TypeId diff --git a/crates/glue/platform/Types.roc b/crates/glue/platform/Types.roc index f4930759c1a..3389e8cfcc7 100644 --- a/crates/glue/platform/Types.roc +++ b/crates/glue/platform/Types.roc @@ -1,6 +1,6 @@ interface Types exposes [Types, shape, size, alignment, target, walkShapes, entryPoints] - imports [Shape.{ Shape }, TypeId.{ TypeId }, Target.{ Target }, TypeId] + imports [Shape.{ Shape }, TypeId.{ TypeId, typeIDfromU64, typeIDtoU64 }, Target.{ Target }] # TODO: switch AssocList uses to Dict once roc_std is updated. Tuple1 : [T Str TypeId] @@ -23,7 +23,7 @@ Types := { ## Names and types of the entry points of the program (e.g. mainForHost) entrypoints : List Tuple1, target : Target, -} +} implements [Inspect, Encoding] target : Types -> Target target = \@Types types -> types.target @@ -34,33 +34,33 @@ entryPoints = \@Types { entrypoints } -> entrypoints walkShapes : Types, state, (state, Shape, TypeId -> state) -> state walkShapes = \@Types { types: shapes }, originalState, update -> List.walkWithIndex shapes originalState \state, elem, index -> - id = TypeId.fromU64 index + id = typeIDfromU64 index update state elem id shape : Types, TypeId -> Shape shape = \@Types types, id -> - when List.get types.types (TypeId.toU64 id) is + when List.get types.types (typeIDtoU64 id) is Ok answer -> answer Err OutOfBounds -> - idStr = Num.toStr (TypeId.toU64 id) + idStr = Num.toStr (typeIDtoU64 id) crash "TypeId #$(idStr) was not found in Types. This should never happen, and means there was a bug in `roc glue`. If you have time, please open an issue at " alignment : Types, TypeId -> U32 alignment = \@Types types, id -> - when List.get types.aligns (TypeId.toU64 id) is + when List.get types.aligns (typeIDtoU64 id) is Ok answer -> answer Err OutOfBounds -> - idStr = Num.toStr (TypeId.toU64 id) + idStr = Num.toStr (typeIDtoU64 id) crash "TypeId #$(idStr) was not found in Types. This should never happen, and means there was a bug in `roc glue`. If you have time, please open an issue at " size : Types, TypeId -> U32 size = \@Types types, id -> - when List.get types.sizes (TypeId.toU64 id) is + when List.get types.sizes (typeIDtoU64 id) is Ok answer -> answer Err OutOfBounds -> - idStr = Num.toStr (TypeId.toU64 id) + idStr = Num.toStr (typeIDtoU64 id) crash "TypeId #$(idStr) was not found in Types. This should never happen, and means there was a bug in `roc glue`. If you have time, please open an issue at "