Stabel

Check-in [8bbd6d2ddc]
Login
Overview
Comment:Attempted syntax sugar approach for supporting int literals as pattern match, but it causes codegen and type checking bugs. Seems we need to go all the way here, which is better anyway.
Timelines: family | ancestors | descendants | both | int-literals-in-pattern-match
Files: files | file ages | folders
SHA3-256: 8bbd6d2ddcac0e63552b8c33c867b7b49e9c66c5abb92244f73e69c48c57a8fd
User & Date: robin.hansen on 2021-09-21 17:37:51
Other Links: branch diff | manifest | tags
Context
2021-09-22
09:12
Parser and Qualifier updated with new type match structure. check-in: f6408f42e9 user: robin.hansen tags: int-literals-in-pattern-match
2021-09-21
17:37
Attempted syntax sugar approach for supporting int literals as pattern match, but it causes codegen ... check-in: 8bbd6d2ddc user: robin.hansen tags: int-literals-in-pattern-match
2021-09-20
16:33
Aliases can now be implicit [c2996a5e70] check-in: 7c8e530718 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Parser.elm from [6bb3a2d289] to [c836706185].

68
69
70
71
72
73
74

75
76
77
78
79
80
81
82
83
84
85
86
87
....
1338
1339
1340
1341
1342
1343
1344





1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356

1357
1358
1359
1360
1361
1362
1363
....
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394

type FunctionImplementation
    = SoloImpl (List AstNode)
    | MultiImpl (List ( TypeMatch, List AstNode )) (List AstNode)


type TypeMatch

    = TypeMatch SourceLocationRange PossiblyQualifiedType (List ( String, TypeMatchValue ))


type TypeMatchValue
    = LiteralInt Int
    | LiteralType PossiblyQualifiedType
    | RecursiveMatch TypeMatch


type AstNode
    = Integer SourceLocationRange Int
    | Function SourceLocationRange String
    | PackageFunction SourceLocationRange (List String) String
................................................................................
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))
        ]


typeMatchParser : Parser TypeMatch
typeMatchParser =





    Parser.succeed (\startLoc type_ conds endLoc -> TypeMatch (SourceLocationRange startLoc endLoc) type_ conds)
        |= sourceLocationParser
        |= typeMatchTypeParser
        |= Parser.oneOf
            [ Parser.succeed identity
                |. Parser.symbol (Token "(" ExpectedLeftParen)
                |. noiseParser
                |= Parser.loop [] typeMatchConditionParser
                |. Parser.symbol (Token ")" ExpectedRightParen)
            , Parser.succeed []
            ]
        |= sourceLocationParser



typeMatchConditionParser : List ( String, TypeMatchValue ) -> Parser (Parser.Step (List ( String, TypeMatchValue )) (List ( String, TypeMatchValue )))
typeMatchConditionParser nodes =
    Parser.oneOf
        [ Parser.succeed (\name value -> Parser.Loop (( name, value ) :: nodes))
            |= symbolParser
................................................................................
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


typeMatchValueParser : Parser TypeMatchValue
typeMatchValueParser =
    let
        handleNewType ((TypeMatch _ type_ conditions) as match) =
            case conditions of
                [] ->
                    LiteralType type_

                _ ->
                    RecursiveMatch match
    in
    Parser.oneOf
        [ Parser.succeed LiteralInt
            |= intParser
        , Parser.succeed handleNewType
            |= typeMatchParser
        ]


implementationParser : Parser (List AstNode)
implementationParser =
    Parser.loop [] implementationParserHelp









>
|



<
|







 







>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
|
>







 







|
|
|





<
<
<
|
|
<







68
69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
87
....
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
....
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387



1388
1389

1390
1391
1392
1393
1394
1395
1396

type FunctionImplementation
    = SoloImpl (List AstNode)
    | MultiImpl (List ( TypeMatch, List AstNode )) (List AstNode)


type TypeMatch
    = TypeMatchInt SourceLocationRange Int
    | TypeMatchType SourceLocationRange PossiblyQualifiedType (List ( String, TypeMatchValue ))


type TypeMatchValue

    = LiteralType PossiblyQualifiedType
    | RecursiveMatch TypeMatch


type AstNode
    = Integer SourceLocationRange Int
    | Function SourceLocationRange String
    | PackageFunction SourceLocationRange (List String) String
................................................................................
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse reverseTypes))
        ]


typeMatchParser : Parser TypeMatch
typeMatchParser =
    Parser.oneOf
        [ Parser.succeed (\startLoc int endLoc -> TypeMatchInt (SourceLocationRange startLoc endLoc) int)
            |= sourceLocationParser
            |= intParser
            |= sourceLocationParser
        , Parser.succeed (\startLoc type_ conds endLoc -> TypeMatchType (SourceLocationRange startLoc endLoc) type_ conds)
            |= sourceLocationParser
            |= typeMatchTypeParser
            |= Parser.oneOf
                [ Parser.succeed identity
                    |. Parser.symbol (Token "(" ExpectedLeftParen)
                    |. noiseParser
                    |= Parser.loop [] typeMatchConditionParser
                    |. Parser.symbol (Token ")" ExpectedRightParen)
                , Parser.succeed []
                ]
            |= sourceLocationParser
        ]


typeMatchConditionParser : List ( String, TypeMatchValue ) -> Parser (Parser.Step (List ( String, TypeMatchValue )) (List ( String, TypeMatchValue )))
typeMatchConditionParser nodes =
    Parser.oneOf
        [ Parser.succeed (\name value -> Parser.Loop (( name, value ) :: nodes))
            |= symbolParser
................................................................................
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


typeMatchValueParser : Parser TypeMatchValue
typeMatchValueParser =
    let
        handleNewType match =
            case match of
                TypeMatchType _ type_ [] ->
                    LiteralType type_

                _ ->
                    RecursiveMatch match
    in



    Parser.succeed handleNewType
        |= typeMatchParser



implementationParser : Parser (List AstNode)
implementationParser =
    Parser.loop [] implementationParserHelp


Modified src/Stabel/Qualifier.elm from [ff52ef351a] to [851ada32fd].

896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912



913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
...
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
...
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
....
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
....
1726
1727
1728
1729
1730
1731
1732
1733





1734
1735
1736
1737
1738
1739
1740
1741
                                else
                                    Err <| UnionTypeMatchWithPatterns range

                Nothing ->
                    Err <| UnknownTypeRef range name
    in
    case typeMatch of
        Parser.TypeMatch range (Parser.LocalRef "Int" []) [] ->
            Ok <| TypeMatch (qualifiedRange range) Type.Int []

        Parser.TypeMatch range (Parser.LocalRef "Int" []) [ ( "value", Parser.LiteralInt val ) ] ->
            Ok <|
                TypeMatch
                    (qualifiedRange range)
                    Type.Int
                    [ TypeMatchCond "value" Type.Int (LiteralInt val) ]




        Parser.TypeMatch range (Parser.LocalRef "Array" []) [] ->
            Ok <|
                TypeMatch
                    (qualifiedRange range)
                    (Type.Array (Type.Generic "*a"))
                    []

        Parser.TypeMatch range (Parser.Generic sym) [] ->
            Ok <| TypeMatch (qualifiedRange range) (Type.Generic sym) []

        Parser.TypeMatch range (Parser.LocalRef name []) patterns ->
            case qualifiedNameToMatch (qualifiedRange range) (qualifyName config name) patterns of
                (Err (UnknownTypeRef _ _)) as errMsg ->
                    case resolveImportedType config modRefs name of
                        Just importedModule ->
                            qualifiedNameToMatch
                                (qualifiedRange range)
                                (importedModule ++ "/" ++ name)
................................................................................

                        Nothing ->
                            errMsg

                result ->
                    result

        Parser.TypeMatch range (Parser.InternalRef [ possibleAlias ] name _) patterns ->
            case Dict.get possibleAlias modRefs.aliases of
                Just actualPath ->
                    if representsExternalModule actualPath then
                        let
                            extPath =
                                splitExternalPackagePath actualPath
                        in
                        qualifyMatch config qualifiedTypes modRefs <|
                            Parser.TypeMatch range (Parser.ExternalRef extPath name []) patterns

                    else
                        let
                            qualifiedName =
                                actualPath
                                    ++ "/"
                                    ++ name
................................................................................
                            possibleAlias
                                ++ "/"
                                ++ name
                                |> qualifyPackageModule config.packageName
                    in
                    qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatch range (Parser.InternalRef path name _) patterns ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
                        |> qualifyPackageModule config.packageName
            in
            qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatch range (Parser.ExternalRef path name _) patterns ->
            let
                pathString =
                    "/" ++ String.join "/" path

                qualifiedName =
                    Dict.get pathString config.externalModules
                        |> Maybe.map (\prefix -> "/" ++ prefix ++ pathString ++ "/" ++ name)
                        |> Maybe.withDefault ""
            in
            qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatch range _ _ ->
            Err <| InvalidTypeMatch (qualifiedRange range)


qualifyMatchValue :
    RunConfig
    -> Dict String TypeDefinition
    -> ModuleReferences
................................................................................
    -> List ( String, Type )
    -> ( String, Parser.TypeMatchValue )
    -> Result Problem TypeMatchCond
qualifyMatchValue config qualifiedTypes modRefs range typeName members ( fieldName, matchValue ) =
    case List.find ((==) fieldName << Tuple.first) members of
        Just ( _, fieldType ) ->
            case matchValue of
                Parser.LiteralInt val ->
                    Ok <| TypeMatchCond fieldName fieldType (LiteralInt val)

                Parser.LiteralType type_ ->
                    type_
                        |> qualifyMemberType config modRefs range
                        |> Result.map
                            (\qualifiedType ->
                                TypeMatchCond
                                    fieldName
................................................................................
                Parser.MultiImpl branches _ ->
                    branches
                        |> List.map Tuple.first
                        |> List.map extractMatchType
                        |> List.filterMap extractModuleReferenceFromType
                        |> Set.fromList

        extractMatchType (Parser.TypeMatch _ tipe _) =





            tipe

        impls =
            case function.implementation of
                Parser.SoloImpl impl ->
                    [ impl ]

                Parser.MultiImpl branches impl ->







|
<
<
<






>
>
>
|






|


|







 







|








|







 







|









|











|







 







<
<
<







 







|
>
>
>
>
>
|







896
897
898
899
900
901
902
903



904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
...
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
...
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
....
1002
1003
1004
1005
1006
1007
1008



1009
1010
1011
1012
1013
1014
1015
....
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
                                else
                                    Err <| UnionTypeMatchWithPatterns range

                Nothing ->
                    Err <| UnknownTypeRef range name
    in
    case typeMatch of
        Parser.TypeMatchInt range val ->



            Ok <|
                TypeMatch
                    (qualifiedRange range)
                    Type.Int
                    [ TypeMatchCond "value" Type.Int (LiteralInt val) ]

        Parser.TypeMatchType range (Parser.LocalRef "Int" []) [] ->
            Ok <| TypeMatch (qualifiedRange range) Type.Int []

        Parser.TypeMatchType range (Parser.LocalRef "Array" []) [] ->
            Ok <|
                TypeMatch
                    (qualifiedRange range)
                    (Type.Array (Type.Generic "*a"))
                    []

        Parser.TypeMatchType range (Parser.Generic sym) [] ->
            Ok <| TypeMatch (qualifiedRange range) (Type.Generic sym) []

        Parser.TypeMatchType range (Parser.LocalRef name []) patterns ->
            case qualifiedNameToMatch (qualifiedRange range) (qualifyName config name) patterns of
                (Err (UnknownTypeRef _ _)) as errMsg ->
                    case resolveImportedType config modRefs name of
                        Just importedModule ->
                            qualifiedNameToMatch
                                (qualifiedRange range)
                                (importedModule ++ "/" ++ name)
................................................................................

                        Nothing ->
                            errMsg

                result ->
                    result

        Parser.TypeMatchType range (Parser.InternalRef [ possibleAlias ] name _) patterns ->
            case Dict.get possibleAlias modRefs.aliases of
                Just actualPath ->
                    if representsExternalModule actualPath then
                        let
                            extPath =
                                splitExternalPackagePath actualPath
                        in
                        qualifyMatch config qualifiedTypes modRefs <|
                            Parser.TypeMatchType range (Parser.ExternalRef extPath name []) patterns

                    else
                        let
                            qualifiedName =
                                actualPath
                                    ++ "/"
                                    ++ name
................................................................................
                            possibleAlias
                                ++ "/"
                                ++ name
                                |> qualifyPackageModule config.packageName
                    in
                    qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatchType range (Parser.InternalRef path name _) patterns ->
            let
                qualifiedName =
                    path
                        ++ [ name ]
                        |> String.join "/"
                        |> qualifyPackageModule config.packageName
            in
            qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatchType range (Parser.ExternalRef path name _) patterns ->
            let
                pathString =
                    "/" ++ String.join "/" path

                qualifiedName =
                    Dict.get pathString config.externalModules
                        |> Maybe.map (\prefix -> "/" ++ prefix ++ pathString ++ "/" ++ name)
                        |> Maybe.withDefault ""
            in
            qualifiedNameToMatch (qualifiedRange range) qualifiedName patterns

        Parser.TypeMatchType range _ _ ->
            Err <| InvalidTypeMatch (qualifiedRange range)


qualifyMatchValue :
    RunConfig
    -> Dict String TypeDefinition
    -> ModuleReferences
................................................................................
    -> List ( String, Type )
    -> ( String, Parser.TypeMatchValue )
    -> Result Problem TypeMatchCond
qualifyMatchValue config qualifiedTypes modRefs range typeName members ( fieldName, matchValue ) =
    case List.find ((==) fieldName << Tuple.first) members of
        Just ( _, fieldType ) ->
            case matchValue of



                Parser.LiteralType type_ ->
                    type_
                        |> qualifyMemberType config modRefs range
                        |> Result.map
                            (\qualifiedType ->
                                TypeMatchCond
                                    fieldName
................................................................................
                Parser.MultiImpl branches _ ->
                    branches
                        |> List.map Tuple.first
                        |> List.map extractMatchType
                        |> List.filterMap extractModuleReferenceFromType
                        |> Set.fromList

        extractMatchType match =
            case match of
                Parser.TypeMatchInt _ _ ->
                    Parser.LocalRef "Int" []

                Parser.TypeMatchType _ tipe _ ->
                    tipe

        impls =
            case function.implementation of
                Parser.SoloImpl impl ->
                    [ impl ]

                Parser.MultiImpl branches impl ->

Modified tests/Test/Parser.elm from [b630228d82] to [46f7896150].

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
...
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
...
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
...
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
....
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
....
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
....
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
....
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272

1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
....
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "False" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = "Converts a boolean into an int"
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "False" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Generic "a") []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
        , describe "Pattern matching"
            [ test "Single match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: zero?
                            : Int( value 0 )
                              True
                            else: False
                            """

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch
                                                        emptyRange
                                                        (LocalRef "Int" [])
                                                        [ ( "value", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Function emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "List" [])
                                                        [ ( "tail"
                                                          , AST.RecursiveMatch
                                                                (TypeMatch emptyRange
                                                                    (LocalRef "List" [])
                                                                    [ ( "tail", AST.LiteralType (LocalRef "Nil" []) )
                                                                    ]
                                                                )
                                                          )
                                                        ]
                                                  , [ AST.Function emptyRange "True" ]
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "Pair" [])
                                                        [ ( "first", AST.LiteralInt 0 )
                                                        , ( "second", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Function emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
................................................................................
                        : False

                        defstruct: True
                        defstruct: False

                        defmulti: from-int
                        type: Int -- Int
                        : Int( value 0 )
                          False>
                        : Int
                          True>

                        def: equal
                        : - from-int not

................................................................................
                                                (SourceLocation 16 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 11 3)
                                                        (SourceLocation 11 17)
                                                    )
                                                    (LocalRef "Int" [])
                                                    [ ( "value", LiteralInt 0 ) ]

                                              , [ Function
                                                    (SourceLocationRange
                                                        (SourceLocation 12 3)
                                                        (SourceLocation 12 9)
                                                    )
                                                    "False>"
                                                ]
                                              )
                                            , ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 13 3)
                                                        (SourceLocation 13 6)
                                                    )
                                                    (LocalRef "Int" [])
                                                    []
                                              , [ Function
................................................................................
                                                (SourceLocation 23 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 20 3)
                                                        (SourceLocation 20 7)
                                                    )
                                                    (LocalRef "True" [])
                                                    []
                                              , [ Function







|


|







 







|


|







 







|


|







 







|


|







 







|


|







 







|







 







|
<
<
<
<







 







|



|







 







|

|
|







 







|







 







|


|

<
<
>








|







 







|







519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
...
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
...
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
...
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
...
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
...
979
980
981
982
983
984
985
986




987
988
989
990
991
992
993
....
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
....
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
....
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
....
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266


1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
....
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatchType emptyRange (LocalRef "False" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = "Converts a boolean into an int"
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatchType emptyRange (LocalRef "False" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange (Generic "a") []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatchType emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatchType emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
                                                , ( TypeMatchType emptyRange (LocalRef "Nil" []) []
                                                  , [ AST.Function emptyRange "drop" ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
................................................................................
        , describe "Pattern matching"
            [ test "Single match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: zero?
                            : 0
                              True
                            else: False
                            """

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchInt emptyRange 0




                                                  , [ AST.Function emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
                            }
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange
                                                        (LocalRef "List" [])
                                                        [ ( "tail"
                                                          , AST.RecursiveMatch
                                                                (TypeMatchType emptyRange
                                                                    (LocalRef "List" [])
                                                                    [ ( "tail", AST.LiteralType (LocalRef "Nil" []) )
                                                                    ]
                                                                )
                                                          )
                                                        ]
                                                  , [ AST.Function emptyRange "True" ]
................................................................................
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatchType emptyRange
                                                        (LocalRef "Pair" [])
                                                        [ ( "first", RecursiveMatch <| TypeMatchInt emptyRange 0 )
                                                        , ( "second", RecursiveMatch <| TypeMatchInt emptyRange 0 )
                                                        ]
                                                  , [ AST.Function emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Function emptyRange "False" ]
                                      }
                                    ]
................................................................................
                        : False

                        defstruct: True
                        defstruct: False

                        defmulti: from-int
                        type: Int -- Int
                        : 0
                          False>
                        : Int
                          True>

                        def: equal
                        : - from-int not

................................................................................
                                                (SourceLocation 16 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatchInt
                                                    (SourceLocationRange
                                                        (SourceLocation 11 3)
                                                        (SourceLocation 12 1)
                                                    )


                                                    0
                                              , [ Function
                                                    (SourceLocationRange
                                                        (SourceLocation 12 3)
                                                        (SourceLocation 12 9)
                                                    )
                                                    "False>"
                                                ]
                                              )
                                            , ( TypeMatchType
                                                    (SourceLocationRange
                                                        (SourceLocation 13 3)
                                                        (SourceLocation 13 6)
                                                    )
                                                    (LocalRef "Int" [])
                                                    []
                                              , [ Function
................................................................................
                                                (SourceLocation 23 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatchType
                                                    (SourceLocationRange
                                                        (SourceLocation 20 3)
                                                        (SourceLocation 20 7)
                                                    )
                                                    (LocalRef "True" [])
                                                    []
                                              , [ Function

Modified tests/Test/Parser/ModuleDefinition.elm from [598f9224a4] to [df351f0b8c].

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
                                        Dict.fromList
                                            [ ( "/some/other/mod", [ "test1", "word2" ] )
                                            , ( "internals", [ "foo" ] )
                                            , ( "internal/mod", [] )
                                            ]
                                  , implementation =
                                        MultiImpl
                                            [ ( AST.TypeMatch emptyRange (Generic "a") []
                                              , [ AST.Function emptyRange "drop" ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "swap"
                                            , AST.Function emptyRange "drop"
                                            ]
                                  }







|







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
                                        Dict.fromList
                                            [ ( "/some/other/mod", [ "test1", "word2" ] )
                                            , ( "internals", [ "foo" ] )
                                            , ( "internal/mod", [] )
                                            ]
                                  , implementation =
                                        MultiImpl
                                            [ ( AST.TypeMatchType emptyRange (Generic "a") []
                                              , [ AST.Function emptyRange "drop" ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "swap"
                                            , AST.Function emptyRange "drop"
                                            ]
                                  }

Modified tests/Test/Parser/QualifiedRefs.elm from [6b5fcdd2e5] to [cf2cf9f2d4].

202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (ExternalRef [ "external" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 0
................................................................................
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (InternalRef [ "internal" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 0







|







 







|







202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatchType emptyRange (ExternalRef [ "external" ] "Tipe" []) [ ( "value", RecursiveMatch <| TypeMatchInt emptyRange 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 0
................................................................................
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatchType emptyRange (InternalRef [ "internal" ] "Tipe" []) [ ( "value", RecursiveMatch <| TypeMatchInt emptyRange 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
                                                ]
                                              )
                                            ]
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 0

Modified tests/Test/Parser/Util.elm from [0c312f5c79] to [d2a2df77af].

96
97
98
99
100
101
102
103





104
105
106
107
108
109
110
111
112
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch
    , List.map stripNodeLocation nodes
    )


stripTypeMatchLocation : TypeMatch -> TypeMatch
stripTypeMatchLocation (TypeMatch _ type_ otherConds) =





    TypeMatch emptyRange type_ <|
        List.map (Tuple.mapSecond stripRecursiveTypeMatchLocation) otherConds


stripRecursiveTypeMatchLocation : TypeMatchValue -> TypeMatchValue
stripRecursiveTypeMatchLocation typeMatchValue =
    case typeMatchValue of
        RecursiveMatch typeMatch ->
            RecursiveMatch (stripTypeMatchLocation typeMatch)







|
>
>
>
>
>
|
|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch
    , List.map stripNodeLocation nodes
    )


stripTypeMatchLocation : TypeMatch -> TypeMatch
stripTypeMatchLocation match =
    case match of
        TypeMatchInt _ int ->
            TypeMatchInt emptyRange int

        TypeMatchType _ type_ otherConds ->
            TypeMatchType emptyRange type_ <|
                List.map (Tuple.mapSecond stripRecursiveTypeMatchLocation) otherConds


stripRecursiveTypeMatchLocation : TypeMatchValue -> TypeMatchValue
stripRecursiveTypeMatchLocation typeMatchValue =
    case typeMatchValue of
        RecursiveMatch typeMatch ->
            RecursiveMatch (stripTypeMatchLocation typeMatch)

Modified tests/Test/Qualifier.elm from [5a6565cefb] to [a654cc777a].

19
20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40

41
42
43
44
45
46
47
..
48
49
50
51
52
53
54
55
56

57
58
59
60
61
62
63
..
64
65
66
67
68
69
70
71
72

73
74
75
76
77
78
79
    describe "Qualifier"
        [ test "Recursive function" <|
            \_ ->
                let
                    source =
                        """
                        defmulti: count-down
                        : Int( value 0 )
                          0

                        : Int
                          1 - count-down
                        """
                in
                QualifierUtil.expectQualification source
        , test "Recursive function through inline function" <|
            \_ ->
                let
                    source =
                        """
                        defmulti: count-down
                        : Int( value 0 )
                          0

                        : Int
                          [ count-down ] !
                        """
                in
                QualifierUtil.expectQualification source
        , test "Function cycle" <|
            \_ ->
................................................................................
                let
                    source =
                        """
                        def: dec-down
                        : 1 - count-down 

                        defmulti: count-down
                        : Int( value 0 )
                          0

                        : Int
                          dec-down
                        """
                in
                QualifierUtil.expectQualification source
        , test "Function cycle with inline function" <|
            \_ ->
................................................................................
                let
                    source =
                        """
                        def: dec-down
                        : 1 - count-down 

                        defmulti: count-down
                        : Int( value 0 )
                          0

                        : Int
                          [ dec-down ] !
                        """
                in
                QualifierUtil.expectQualification source
        , test "Name mangling" <|
            \_ ->







|
<
>











|
<
>







 







|
<
>







 







|
<
>







19
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
47
..
48
49
50
51
52
53
54
55

56
57
58
59
60
61
62
63
..
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
    describe "Qualifier"
        [ test "Recursive function" <|
            \_ ->
                let
                    source =
                        """
                        defmulti: count-down
                        : 0

                          drop 0
                        : Int
                          1 - count-down
                        """
                in
                QualifierUtil.expectQualification source
        , test "Recursive function through inline function" <|
            \_ ->
                let
                    source =
                        """
                        defmulti: count-down
                        : 0

                          drop 0
                        : Int
                          [ count-down ] !
                        """
                in
                QualifierUtil.expectQualification source
        , test "Function cycle" <|
            \_ ->
................................................................................
                let
                    source =
                        """
                        def: dec-down
                        : 1 - count-down 

                        defmulti: count-down
                        : 0

                          drop 0
                        : Int
                          dec-down
                        """
                in
                QualifierUtil.expectQualification source
        , test "Function cycle with inline function" <|
            \_ ->
................................................................................
                let
                    source =
                        """
                        def: dec-down
                        : 1 - count-down 

                        defmulti: count-down
                        : 0

                          drop 0
                        : Int
                          [ dec-down ] !
                        """
                in
                QualifierUtil.expectQualification source
        , test "Name mangling" <|
            \_ ->

Modified tests/Test/TypeChecker/Errors.elm from [46be466d12] to [9bf4cbb6a5].

211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

                        def: main
                        type: -- out
                        : 0 true-or-false

                        defmulti: true-or-false
                        type: Int -- (Tmp a b)
                        : Int( value 0 )
                          drop False>
                        : Int
                          drop True>
                        """
                in
                Expect.equalLists
                    [ Problem.TypeError emptyRange
................................................................................

                        defstruct: True
                        defstruct: False

                        defmulti: true-or-false
                        # should be Int -- Int (Maybe a)
                        type: Int -- Int
                        : Int( value 0 )
                          False>
                        : Int
                          True>
                        """
                in
                Expect.equalLists
                    [ Problem.TypeError emptyRange
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : Int( value 1 )
                              1 +
                            """

                        inexhaustiveError problem =
                            case problem of
                                Problem.InexhaustiveMultiFunction _ [ [ Type.Int ] ] ->
                                    True
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : Int( value 1 )
                              1 +
                            else: 
                              0 +
                            """
                    in
                    Util.expectTypeCheck input
            , test "Nested" <|
................................................................................
                            : value Int

                            def: main
                            type: -- Int
                            : 1 >IntBox mword value>

                            defmulti: mword
                            : IntBox( value Int( value 1 ) )
                              value> 1 + >IntBox
                            """

                        inexhaustiveError problem =
                            case problem of
                                Problem.InexhaustiveMultiFunction _ [ [ Type.Custom "IntBox", Type.Int ] ] ->
                                    True
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : Int( value 1 )
                              1 +
                            : Int
                              dup +
                            """
                    in
                    Util.expectTypeCheck input
            , test "A total branch should prevent addition of later partial branch" <|
................................................................................
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : Int
                              dup +
                            : Int( value 1 )
                              1 +
                            """
                    in
                    Util.expectTypeCheck input
            , test "Test with non-int type as pattern" <|
                \_ ->
                    let
................................................................................
                            defstruct: IntBox
                            : value Int

                            defstruct: Nil

                            defmulti: with-default
                            type: (Maybe IntBox) Int -- Int
                            : IntBox( value Int( value 0 ) )
                              drop value>
                            : Nil
                              swap drop

                            def: main
                            : Nil> 1 with-default
                            """







|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
...
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

                        def: main
                        type: -- out
                        : 0 true-or-false

                        defmulti: true-or-false
                        type: Int -- (Tmp a b)
                        : 0
                          drop False>
                        : Int
                          drop True>
                        """
                in
                Expect.equalLists
                    [ Problem.TypeError emptyRange
................................................................................

                        defstruct: True
                        defstruct: False

                        defmulti: true-or-false
                        # should be Int -- Int (Maybe a)
                        type: Int -- Int
                        : 0
                          False>
                        : Int
                          True>
                        """
                in
                Expect.equalLists
                    [ Problem.TypeError emptyRange
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : 1
                              1 +
                            """

                        inexhaustiveError problem =
                            case problem of
                                Problem.InexhaustiveMultiFunction _ [ [ Type.Int ] ] ->
                                    True
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : 1
                              1 +
                            else: 
                              0 +
                            """
                    in
                    Util.expectTypeCheck input
            , test "Nested" <|
................................................................................
                            : value Int

                            def: main
                            type: -- Int
                            : 1 >IntBox mword value>

                            defmulti: mword
                            : IntBox( value 1 )
                              value> 1 + >IntBox
                            """

                        inexhaustiveError problem =
                            case problem of
                                Problem.InexhaustiveMultiFunction _ [ [ Type.Custom "IntBox", Type.Int ] ] ->
                                    True
................................................................................
                    let
                        input =
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : 1
                              1 +
                            : Int
                              dup +
                            """
                    in
                    Util.expectTypeCheck input
            , test "A total branch should prevent addition of later partial branch" <|
................................................................................
                            """
                            def: main
                            : 2 mword

                            defmulti: mword
                            : Int
                              dup +
                            : 1
                              1 +
                            """
                    in
                    Util.expectTypeCheck input
            , test "Test with non-int type as pattern" <|
                \_ ->
                    let
................................................................................
                            defstruct: IntBox
                            : value Int

                            defstruct: Nil

                            defmulti: with-default
                            type: (Maybe IntBox) Int -- Int
                            : IntBox( value 0 )
                              drop value>
                            : Nil
                              swap drop

                            def: main
                            : Nil> 1 with-default
                            """

Modified wasm_tests/module_resolution.test.js from [327530c16f] to [b4cd6fda72].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                module: 'internal',
                source: `
                    def: inc
                    : 1 +

                    defmulti: flip
                    type: Int -- Int
                    : Int( value 1 )
                      drop 0
                    else: drop 1
                `
            },
            {
                package: 'author/sample',
                module: 'core',
................................................................................
                module: 'external',
                source: `
                    def: inc
                    : 1 +

                    defmulti: flip
                    type: Int -- Int
                    : Int( value 1 )
                      drop 0
                    else: drop 1
                `
            },
            {
                package: 'author/sample',
                module: 'core',







|







 







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                module: 'internal',
                source: `
                    def: inc
                    : 1 +

                    defmulti: flip
                    type: Int -- Int
                    : 1
                      drop 0
                    else: drop 1
                `
            },
            {
                package: 'author/sample',
                module: 'core',
................................................................................
                module: 'external',
                source: `
                    def: inc
                    : 1 +

                    defmulti: flip
                    type: Int -- Int
                    : 1
                      drop 0
                    else: drop 1
                `
            },
            {
                package: 'author/sample',
                module: 'core',

Modified wasm_tests/multifunctions.test.js from [b56d183212] to [e8bb9fea35].

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

    expect(result.stackElement()).toBe(8);
});

test('Int match', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: double
        : Int( value 0 )
          drop 2
        : Int
          2 *

        def: main
        : 0 double
    `);
................................................................................

    expect(result.stackElement()).toBe(2);
});

test('Int match (reverse)', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: double
        : Int( value 0 )
          drop 2
        : Int
          2 *

        def: main
        : 6 double
    `);
................................................................................

    expect(result.stackElement()).toBe(12);
});

test('Correct Int boxing behaviour', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: add
        : Int( value 0 )
          swap 
          drop 2
          swap
          +
        : Int
          +

................................................................................
});

test('Correct Int boxing behaviour when mismatch between word input size and stack size', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Nil

        defmulti: inc-zero
        : Int( value 0 )
          swap 
          drop 1
          swap
        : Int

        def: main
        : 0 Nil> inc-zero
................................................................................
test('Cyclic case', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : 10 count-down

        defmulti: count-down
        type: Int -- Int
        : Int( value 0 )
          drop 0
        : Int
          dec-count-down

        def: dec-count-down
        : 1 - count-down
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(0);
});







|







 







|







 







|







 







|







 







|












176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
...
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307

    expect(result.stackElement()).toBe(8);
});

test('Int match', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: double
        : 0
          drop 2
        : Int
          2 *

        def: main
        : 0 double
    `);
................................................................................

    expect(result.stackElement()).toBe(2);
});

test('Int match (reverse)', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: double
        : 0
          drop 2
        : Int
          2 *

        def: main
        : 6 double
    `);
................................................................................

    expect(result.stackElement()).toBe(12);
});

test('Correct Int boxing behaviour', async () => {
    const wat = await compiler.toWat('main', `
        defmulti: add
        : 0
          swap 
          drop 2
          swap
          +
        : Int
          +

................................................................................
});

test('Correct Int boxing behaviour when mismatch between word input size and stack size', async () => {
    const wat = await compiler.toWat('main', `
        defstruct: Nil

        defmulti: inc-zero
        : 0
          swap 
          drop 1
          swap
        : Int

        def: main
        : 0 Nil> inc-zero
................................................................................
test('Cyclic case', async () => {
    const wat = await compiler.toWat('main', `
        def: main
        : 10 count-down

        defmulti: count-down
        type: Int -- Int
        : 0
          drop 0
        : Int
          dec-count-down

        def: dec-count-down
        : 1 - count-down
    `);

    const result = await compiler.run(wat, 'main');

    expect(result.stackElement()).toBe(0);
});