mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 08:34:33 +00:00
fix glue TypeId
This commit is contained in:
parent
62ec6ad8ea
commit
be5c538763
4 changed files with 25 additions and 24 deletions
|
@ -1,11 +0,0 @@
|
|||
interface InternalTypeId
|
||||
exposes [InternalTypeId, fromU64, toU64]
|
||||
imports []
|
||||
|
||||
InternalTypeId := U64
|
||||
|
||||
toU64 : InternalTypeId -> U64
|
||||
toU64 = \@InternalTypeId x -> x
|
||||
|
||||
fromU64 : U64 -> InternalTypeId
|
||||
fromU64 = @InternalTypeId
|
|
@ -1,5 +1,11 @@
|
|||
interface TypeId
|
||||
exposes [TypeId]
|
||||
imports [InternalTypeId.{ InternalTypeId }]
|
||||
exposes [TypeId, fromU64, toU64]
|
||||
imports []
|
||||
|
||||
TypeId : InternalTypeId
|
||||
TypeId := U64 implements [Eq, Hash]
|
||||
|
||||
toU64 : TypeId -> U64
|
||||
toU64 = \@TypeId x -> x
|
||||
|
||||
fromU64 : U64 -> TypeId
|
||||
fromU64 = @TypeId
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
interface Types
|
||||
exposes [Types, shape, size, alignment, target, walkShapes, entryPoints]
|
||||
imports [Shape.{ Shape }, TypeId.{ TypeId }, Target.{ Target }, InternalTypeId]
|
||||
imports [Shape.{ Shape }, TypeId.{ TypeId }, Target.{ Target }, TypeId]
|
||||
|
||||
# TODO: switch AssocList uses to Dict once roc_std is updated.
|
||||
Tuple1 : [T Str TypeId]
|
||||
|
@ -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 = InternalTypeId.fromU64 index
|
||||
id = TypeId.fromU64 index
|
||||
|
||||
update state elem id
|
||||
|
||||
shape : Types, TypeId -> Shape
|
||||
shape = \@Types types, id ->
|
||||
when List.get types.types (InternalTypeId.toU64 id) is
|
||||
when List.get types.types (TypeId.toU64 id) is
|
||||
Ok answer -> answer
|
||||
Err OutOfBounds ->
|
||||
idStr = Num.toStr (InternalTypeId.toU64 id)
|
||||
idStr = Num.toStr (TypeId.toU64 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 <https://github.com/roc-lang/roc/issues>"
|
||||
|
||||
alignment : Types, TypeId -> U32
|
||||
alignment = \@Types types, id ->
|
||||
when List.get types.aligns (InternalTypeId.toU64 id) is
|
||||
when List.get types.aligns (TypeId.toU64 id) is
|
||||
Ok answer -> answer
|
||||
Err OutOfBounds ->
|
||||
idStr = Num.toStr (InternalTypeId.toU64 id)
|
||||
idStr = Num.toStr (TypeId.toU64 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 <https://github.com/roc-lang/roc/issues>"
|
||||
|
||||
size : Types, TypeId -> U32
|
||||
size = \@Types types, id ->
|
||||
when List.get types.sizes (InternalTypeId.toU64 id) is
|
||||
when List.get types.sizes (TypeId.toU64 id) is
|
||||
Ok answer -> answer
|
||||
Err OutOfBounds ->
|
||||
idStr = Num.toStr (InternalTypeId.toU64 id)
|
||||
idStr = Num.toStr (TypeId.toU64 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 <https://github.com/roc-lang/roc/issues>"
|
||||
|
|
|
@ -1360,12 +1360,18 @@ generateUnionField = \types ->
|
|||
|
||||
commaSeparated : Str, List a, (a, U64 -> Str) -> Str
|
||||
commaSeparated = \buf, items, step ->
|
||||
length = List.len items
|
||||
List.walk items { buf, count: 0 } \accum, item ->
|
||||
|
||||
length = List.len items |> Num.intCast
|
||||
|
||||
help : { buf : Str, count : U64 }, a -> { buf : Str, count : U64 }
|
||||
help = \accum, item ->
|
||||
if accum.count + 1 == length then
|
||||
{ buf: Str.concat accum.buf (step item accum.count), count: length }
|
||||
else
|
||||
{ buf: Str.concat accum.buf (step item accum.count) |> Str.concat ", ", count: accum.count + 1 }
|
||||
|
||||
items
|
||||
|> List.walk { buf, count: 0 } help
|
||||
|> .buf
|
||||
|
||||
generateNullableUnwrapped : Str, Types, TypeId, Str, Str, Str, TypeId, [FirstTagIsNull, SecondTagIsNull] -> Str
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue