Stabel

Check-in [b5450e1656]
Login
Overview
Comment:I think type checking of arrays work now :)
Timelines: family | ancestors | descendants | both | arrays
Files: files | file ages | folders
SHA3-256: b5450e1656672dad0ec3e2c16efe8df9b04ab7e6686a490641b932e27b306f76
User & Date: robin.hansen on 2021-08-22 10:39:20
Other Links: branch diff | manifest | tags
Context
2021-08-22
14:58
Wire up the first array builtins. We still require some changes in codegen and typechecker before we... check-in: 60f3575980 user: robin.hansen tags: arrays
10:39
I think type checking of arrays work now :) check-in: b5450e1656 user: robin.hansen tags: arrays
09:59
Implement code that type check array literals, now we need to add an array type. check-in: 8e523926b1 user: robin.hansen tags: arrays
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Data/Type.elm from [69ab1cb9cc] to [ad62e63d60].

19
20
21
22
23
24
25

26
27
28
29
30
31
32
...
136
137
138
139
140
141
142



143
144
145
146
147
148
149
...
176
177
178
179
180
181
182



183
184
185
186
187
188
189
    = Int
    | Generic String
    | Custom String
    | CustomGeneric String (List Type)
    | Union (Maybe String) (List Type)
    | FunctionSignature FunctionType
    | StackRange String



type alias FunctionType =
    { input : List Type
    , output : List Type
    }

................................................................................

        FunctionSignature _ ->
            "Function"

        StackRange name ->
            name ++ "..."





toDisplayString : Type -> String
toDisplayString t =
    case t of
        Int ->
            "Int"

................................................................................

        FunctionSignature quotType ->
            "[ " ++ functionTypeToString quotType ++ " ]"

        StackRange name ->
            name ++ "..."





functionTypeToString : FunctionType -> String
functionTypeToString functionType =
    let
        inputTypeStrings =
            List.map toDisplayString functionType.input








>







 







>
>
>







 







>
>
>







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    = Int
    | Generic String
    | Custom String
    | CustomGeneric String (List Type)
    | Union (Maybe String) (List Type)
    | FunctionSignature FunctionType
    | StackRange String
    | Array Type


type alias FunctionType =
    { input : List Type
    , output : List Type
    }

................................................................................

        FunctionSignature _ ->
            "Function"

        StackRange name ->
            name ++ "..."

        Array _ ->
            "Array"


toDisplayString : Type -> String
toDisplayString t =
    case t of
        Int ->
            "Int"

................................................................................

        FunctionSignature quotType ->
            "[ " ++ functionTypeToString quotType ++ " ]"

        StackRange name ->
            name ++ "..."

        Array t_ ->
            "Array(" ++ toDisplayString t_ ++ ")"


functionTypeToString : FunctionType -> String
functionTypeToString functionType =
    let
        inputTypeStrings =
            List.map toDisplayString functionType.input

Modified src/Stabel/TypeChecker.elm from [05819b475d] to [1893c3764f].

1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1431
1432
1433
1434
1435
1436
1437



1438
1439
1440
1441
1442
1443
1444
....
1664
1665
1666
1667
1668
1669
1670



1671
1672
1673
1674
1675
1676
1677
                            if List.member t acc then
                                unionizeTypesHelper rest acc

                            else
                                unionizeTypesHelper rest (t :: acc)
            in
            case res of
                Ok ( _, newContext ) ->
                    -- TODO: Push array type
                    Ok ( newContext, [] )

                Err err ->
                    Err err

        Qualifier.Function _ untypedDef ->
            let
                ( def, contextWithTypedDef ) =
................................................................................

        Type.FunctionSignature wt ->
            Type.FunctionSignature
                { input = List.map (tagGeneric idx) wt.input
                , output = List.map (tagGeneric idx) wt.output
                }




        _ ->
            type_


functionTypeToStackEffects : FunctionType -> List StackEffect
functionTypeToStackEffects functionType =
    List.map Pop (List.reverse functionType.input)
................................................................................

                                else
                                    compatibleTypes currCtx lType rType
                        in
                        ( contextAfterOutputCheck
                        , inputsCompatible && outputsCompatible
                        )




                    _ ->
                        ( context, False )


getGenericBinding : Context -> Type -> Maybe Type
getGenericBinding context type_ =







|
<
|







 







>
>
>







 







>
>
>







1272
1273
1274
1275
1276
1277
1278
1279

1280
1281
1282
1283
1284
1285
1286
1287
....
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
....
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
                            if List.member t acc then
                                unionizeTypesHelper rest acc

                            else
                                unionizeTypesHelper rest (t :: acc)
            in
            case res of
                Ok ( inferredType, newContext ) ->

                    Ok ( newContext, [ Push <| Type.Array inferredType ] )

                Err err ->
                    Err err

        Qualifier.Function _ untypedDef ->
            let
                ( def, contextWithTypedDef ) =
................................................................................

        Type.FunctionSignature wt ->
            Type.FunctionSignature
                { input = List.map (tagGeneric idx) wt.input
                , output = List.map (tagGeneric idx) wt.output
                }

        Type.Array t ->
            Type.Array <| tagGeneric idx t

        _ ->
            type_


functionTypeToStackEffects : FunctionType -> List StackEffect
functionTypeToStackEffects functionType =
    List.map Pop (List.reverse functionType.input)
................................................................................

                                else
                                    compatibleTypes currCtx lType rType
                        in
                        ( contextAfterOutputCheck
                        , inputsCompatible && outputsCompatible
                        )

                    ( Type.Array lt, Type.Array rt ) ->
                        compatibleTypes context lt rt

                    _ ->
                        ( context, False )


getGenericBinding : Context -> Type -> Maybe Type
getGenericBinding context type_ =