Stabel

Check-in [1a424e8e29]
Login
Overview
Comment:Solve remaining issue by sorting the list of types before creating a boxMap.
Timelines: family | ancestors | descendants | both | arrays
Files: files | file ages | folders
SHA3-256: 1a424e8e2995c7d34eb04c6141379e377b194cf5c76cf76b4f461153e83ae0d3
User & Date: robin.hansen on 2021-09-01 04:26:38
Other Links: branch diff | manifest | tags
Context
2021-09-01
04:29
Add array literals and a few builtins. [ccf0c23cc5] [839b5c7d9a] check-in: 7aabb3c813 user: robin.hansen tags: trunk
04:26
Solve remaining issue by sorting the list of types before creating a boxMap. Closed-Leaf check-in: 1a424e8e29 user: robin.hansen tags: arrays
2021-08-31
19:10
Box elements of array when array contains a union of types. check-in: 775ec8d96b user: robin.hansen tags: arrays
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Codegen.elm from [d3be6650e8] to [a26ff5ae8f].

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447


448
449
450
451
452
453
454
455
            List.length members

        UnionMembers members ->
            List.length members


unionBoxMap : List Type -> List ( Type, Int )
unionBoxMap union =
    let
        helper t ( nextId, mapping ) =
            if requiresBoxingInPatternMatch t then
                ( nextId - 1
                , ( t, nextId ) :: mapping
                )

            else
                ( nextId, mapping )
    in


    List.foldl helper ( -1, [] ) union
        |> Tuple.second


requiresBoxingInPatternMatch : Type -> Bool
requiresBoxingInPatternMatch type_ =
    case type_ of
        Type.Int ->







|










>
>
|







430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
            List.length members

        UnionMembers members ->
            List.length members


unionBoxMap : List Type -> List ( Type, Int )
unionBoxMap unionMembers =
    let
        helper t ( nextId, mapping ) =
            if requiresBoxingInPatternMatch t then
                ( nextId - 1
                , ( t, nextId ) :: mapping
                )

            else
                ( nextId, mapping )
    in
    unionMembers
        |> List.sortWith Type.compareBaseType
        |> List.foldl helper ( -1, [] )
        |> Tuple.second


requiresBoxingInPatternMatch : Type -> Bool
requiresBoxingInPatternMatch type_ =
    case type_ of
        Type.Int ->

Modified src/Stabel/Data/Type.elm from [50cc86fb14] to [c48106c77e].

1
2
3

4
5
6
7
8
9
10
..
11
12
13
14
15
16
17




18
19
20
21
22
23
24
...
119
120
121
122
123
124
125































126
127
128
129
130
131
132
module Stabel.Data.Type exposing
    ( FunctionType
    , Type(..)

    , compatibleFunctions
    , emptyFunctionType
    , equalBaseType
    , functionTypeToString
    , genericName
    , genericlyCompatible
    , isGeneric
................................................................................
    , referencedGenerics
    , toDisplayString
    )

import Dict exposing (Dict)
import Set exposing (Set)






type Type
    = Int
    | Generic String
    | Custom String
    | CustomGeneric String (List Type)
    | Union (Maybe String) (List Type)
................................................................................

        ( CustomGeneric lName _, CustomGeneric rName _ ) ->
            lName == rName

        _ ->
            lhs == rhs

































sameCategory : Type -> Type -> Bool
sameCategory lhs rhs =
    case ( lhs, rhs ) of
        ( FunctionSignature _, FunctionSignature _ ) ->
            True




>







 







>
>
>
>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
..
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
module Stabel.Data.Type exposing
    ( FunctionType
    , Type(..)
    , compareBaseType
    , compatibleFunctions
    , emptyFunctionType
    , equalBaseType
    , functionTypeToString
    , genericName
    , genericlyCompatible
    , isGeneric
................................................................................
    , referencedGenerics
    , toDisplayString
    )

import Dict exposing (Dict)
import Set exposing (Set)



-- TODO: Are all these functions still needed?


type Type
    = Int
    | Generic String
    | Custom String
    | CustomGeneric String (List Type)
    | Union (Maybe String) (List Type)
................................................................................

        ( CustomGeneric lName _, CustomGeneric rName _ ) ->
            lName == rName

        _ ->
            lhs == rhs


compareBaseType : Type -> Type -> Order
compareBaseType lhs rhs =
    compare
        (baseTypeToComparable lhs)
        (baseTypeToComparable rhs)


baseTypeToComparable : Type -> String
baseTypeToComparable t =
    case t of
        Int ->
            "int"

        Array _ ->
            "array"

        Generic val ->
            "gen_" ++ val

        Custom name ->
            "custom_" ++ name

        CustomGeneric name _ ->
            "custom_" ++ name

        _ ->
            -- the remaining types cannot be used ina  union,
            -- so the need for them to be sorted is 0
            ""


sameCategory : Type -> Type -> Bool
sameCategory lhs rhs =
    case ( lhs, rhs ) of
        ( FunctionSignature _, FunctionSignature _ ) ->
            True