Play

Check-in [25fd54d4db]
Login
Overview
Comment:Structs with no members now doesn't have a leading > in their constructor name. Only the compiler can create function names that begin with a capital letter.
Timelines: family | ancestors | descendants | both | alpha2-syntax-changes
Files: files | file ages | folders
SHA3-256: 25fd54d4db72408f3d1612b25984c014c95e795bd3e01f31eecf43d461775d48
User & Date: robin.hansen on 2021-01-23 15:11:00
Other Links: branch diff | manifest | tags
Context
2021-01-23
17:41
Re-enable and correct source location test. check-in: a897d19fce user: robin.hansen tags: alpha2-syntax-changes
15:11
Structs with no members now doesn't have a leading > in their constructor name. Only the compiler ca... check-in: 25fd54d4db user: robin.hansen tags: alpha2-syntax-changes
2021-01-19
16:09
deftype: is now defstruct:. Disabled source location test, with intention of enabling it after all s... check-in: 1757d09f8c user: robin.hansen tags: alpha2-syntax-changes
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Play/Parser.elm from [9cc4869edf] to [cc94b41119].

156
157
158
159
160
161
162


















163
164
165
166
167
168
169
...
389
390
391
392
393
394
395





396
397
398
399
400
401
402
403
...
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
                |. Parser.symbol (Token ":" NotMetadata)
                |> Parser.andThen (\_ -> Parser.problem FoundMetadata)
            , Parser.succeed identity
            ]
        |. noiseParser
        |> Parser.backtrackable




















definitionMetadataParser : Parser String
definitionMetadataParser =
    Parser.variable
        { start = \c -> not (Char.isDigit c || Char.isUpper c || Set.member c invalidSymbolChars)
        , inner = validSymbolChar
        , reserved = Set.fromList [ "def", "defmulti", "defstruct", "defunion" ]
................................................................................
                        [] ->
                            Type.Custom typeName

                        _ ->
                            Type.CustomGeneric typeName (List.map Type.Generic binds)

                ctorDef =





                    { name = ">" ++ typeName
                    , metadata =
                        Metadata.default
                            |> Metadata.withVerifiedType (List.map Tuple.second typeMembers) [ typeOfType ]
                    , implementation =
                        SoloImpl [ ConstructType typeName ]
                    }

................................................................................
    Parser.oneOf
        [ Parser.succeed (\startLoc value endLoc -> Integer (SourceLocationRange startLoc endLoc) value)
            |= sourceLocationParser
            |= intParser
            |= sourceLocationParser
        , Parser.succeed (\startLoc value endLoc -> Word (SourceLocationRange startLoc endLoc) value)
            |= sourceLocationParser
            |= symbolParser
            |= sourceLocationParser
        ]


typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of







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







 







>
>
>
>
>
|







 







|







156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
...
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
                |. Parser.symbol (Token ":" NotMetadata)
                |> Parser.andThen (\_ -> Parser.problem FoundMetadata)
            , Parser.succeed identity
            ]
        |. noiseParser
        |> Parser.backtrackable


symbolImplParser : Parser String
symbolImplParser =
    Parser.variable
        { start = \c -> not (Char.isDigit c || Set.member c invalidSymbolChars)
        , inner = validSymbolChar
        , reserved = Set.empty
        , expecting = NotSymbol
        }
        |. Parser.oneOf
            [ Parser.succeed identity
                |. Parser.symbol (Token ":" NotMetadata)
                |> Parser.andThen (\_ -> Parser.problem FoundMetadata)
            , Parser.succeed identity
            ]
        |. noiseParser
        |> Parser.backtrackable


definitionMetadataParser : Parser String
definitionMetadataParser =
    Parser.variable
        { start = \c -> not (Char.isDigit c || Char.isUpper c || Set.member c invalidSymbolChars)
        , inner = validSymbolChar
        , reserved = Set.fromList [ "def", "defmulti", "defstruct", "defunion" ]
................................................................................
                        [] ->
                            Type.Custom typeName

                        _ ->
                            Type.CustomGeneric typeName (List.map Type.Generic binds)

                ctorDef =
                    { name =
                        if List.isEmpty typeMembers then
                            typeName

                        else
                            ">" ++ typeName
                    , metadata =
                        Metadata.default
                            |> Metadata.withVerifiedType (List.map Tuple.second typeMembers) [ typeOfType ]
                    , implementation =
                        SoloImpl [ ConstructType typeName ]
                    }

................................................................................
    Parser.oneOf
        [ Parser.succeed (\startLoc value endLoc -> Integer (SourceLocationRange startLoc endLoc) value)
            |= sourceLocationParser
            |= intParser
            |= sourceLocationParser
        , Parser.succeed (\startLoc value endLoc -> Word (SourceLocationRange startLoc endLoc) value)
            |= sourceLocationParser
            |= symbolImplParser
            |= sourceLocationParser
        ]


typeDefinitionName : TypeDefinition -> String
typeDefinitionName typeDef =
    case typeDef of

Modified tests/Test/Parser.elm from [a04de1f717] to [8e99ba724c].

601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
...
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
            [ test "Single match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: zero?
                            when: Int( value 0 )
                              >True
                            : >False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
................................................................................
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        Type.Int
                                                        [ ( "value", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"
................................................................................
            , test "Recursive match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: pair?
                            when: List( tail List( tail Nil ) )
                              >True
                            : >False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
................................................................................
                                                                (TypeMatch emptyRange
                                                                    (Type.Custom "List")
                                                                    [ ( "tail", AST.LiteralType (Type.Custom "Nil") )
                                                                    ]
                                                                )
                                                          )
                                                        ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"
................................................................................
            , test "Multiple match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: origo?
                            when: Pair( first 0 second 0 )
                              >True
                            : >False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
................................................................................
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (Type.Custom "Pair")
                                                        [ ( "first", AST.LiteralInt 0 )
                                                        , ( "second", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"







|
|







 







|


|







 







|
|







 







|


|







 







|
|







 







|


|







601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
...
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
...
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
            [ test "Single match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: zero?
                            when: Int( value 0 )
                              True
                            : False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
................................................................................
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        Type.Int
                                                        [ ( "value", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Word emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"
................................................................................
            , test "Recursive match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: pair?
                            when: List( tail List( tail Nil ) )
                              True
                            : False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
................................................................................
                                                                (TypeMatch emptyRange
                                                                    (Type.Custom "List")
                                                                    [ ( "tail", AST.LiteralType (Type.Custom "Nil") )
                                                                    ]
                                                                )
                                                          )
                                                        ]
                                                  , [ AST.Word emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"
................................................................................
            , test "Multiple match" <|
                \_ ->
                    let
                        source =
                            """
                            defmulti: origo?
                            when: Pair( first 0 second 0 )
                              True
                            : False
                            """

                        expectedAst =
                            { types = Dict.empty
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
................................................................................
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (Type.Custom "Pair")
                                                        [ ( "first", AST.LiteralInt 0 )
                                                        , ( "second", AST.LiteralInt 0 )
                                                        ]
                                                  , [ AST.Word emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "False" ]
                                      }
                                    ]
                            }
                    in
                    case compile source of
                        Err _ ->
                            Expect.fail "Did not expect parsing to fail"

Modified tests/Test/Parser/Error.elm from [0045370d97] to [948634a5ee].

106
107
108
109
110
111
112







113
114
115
116
117
118
119
                    checkForError (expectedError "member") <|
                        """
                        defunion: Gender
                        member: Male
                        member: Female
                        """
            ]







        ]


checkForError : (Problem -> Bool) -> String -> Expectation
checkForError fn source =
    case compile source of
        Err errors ->







>
>
>
>
>
>
>







106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                    checkForError (expectedError "member") <|
                        """
                        defunion: Gender
                        member: Male
                        member: Female
                        """
            ]
        , test "Only compiler can create functions which names begins with an upper case letter" <|
            \_ ->
                checkForError ((==) NotSymbol) <|
                    """
                    def: Person
                    : 1
                    """
        ]


checkForError : (Problem -> Bool) -> String -> Expectation
checkForError fn source =
    case compile source of
        Err errors ->

Modified tests/Test/Parser/Util.elm from [240dab60e8] to [a86a98ba7a].

123
124
125
126
127
128
129





130
131
132
133
134
135
136
137
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =





            { name = ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =







>
>
>
>
>
|







123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =
            { name =
                if List.isEmpty members then
                    name

                else
                    ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =

Modified tests/Test/Qualifier.elm from [fe9a3dfa3e] to [f2374a327b].

481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Custom "Box") [ ( "value", AST.LiteralInt 0 ) ]
                                                  , [ AST.Word emptyRange ">True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
................................................................................
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "Box") [ ( "value", LiteralInt 0 ) ], [ Word emptyRange ">True" ] )
                                                ]
                                                [ Word emptyRange ">False" ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run unqualifiedAst of
                        Err _ ->
................................................................................
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ Type.Custom "Bool" ]
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange
                                                    (Type.Custom "Box")
                                                    [ ( "value", AST.LiteralType (Type.Custom "True") ) ]
                                              , [ AST.Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ AST.Word emptyRange ">False" ]
                                  }
                                ]
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
................................................................................
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ boolUnion ]
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange
                                                    (Type.Custom "Box")
                                                    [ ( "value", LiteralType (Type.Custom "True") ) ]
                                              , [ Word emptyRange ">True" ]
                                              )
                                            ]
                                            [ Word emptyRange ">False" ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
        ]







|


|







 







|

|







 







|


|







 







|


|












481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
...
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
...
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
...
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            AST.MultiImpl
                                                [ ( AST.TypeMatch emptyRange (Type.Custom "Box") [ ( "value", AST.LiteralInt 0 ) ]
                                                  , [ AST.Word emptyRange "True" ]
                                                  )
                                                ]
                                                [ AST.Word emptyRange "False" ]
                                      }
                                    ]
                            }
                                |> ParserUtil.addFunctionsForStructs

                        expectedAst =
                            { types =
................................................................................
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , metadata = Metadata.default
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Type.Custom "Box") [ ( "value", LiteralInt 0 ) ], [ Word emptyRange "True" ] )
                                                ]
                                                [ Word emptyRange "False" ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
                    in
                    case run unqualifiedAst of
                        Err _ ->
................................................................................
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ Type.Custom "Bool" ]
                                  , implementation =
                                        AST.MultiImpl
                                            [ ( AST.TypeMatch emptyRange
                                                    (Type.Custom "Box")
                                                    [ ( "value", AST.LiteralType (Type.Custom "True") ) ]
                                              , [ AST.Word emptyRange "True" ]
                                              )
                                            ]
                                            [ AST.Word emptyRange "False" ]
                                  }
                                ]
                        }
                            |> ParserUtil.addFunctionsForStructs

                    expectedAst =
                        { types =
................................................................................
                                        Metadata.default
                                            |> Metadata.withType [ Type.Custom "Box" ] [ boolUnion ]
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange
                                                    (Type.Custom "Box")
                                                    [ ( "value", LiteralType (Type.Custom "True") ) ]
                                              , [ Word emptyRange "True" ]
                                              )
                                            ]
                                            [ Word emptyRange "False" ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
                case run unqualifiedAst of
                    Err _ ->
                        Expect.fail "Did not expect qualification to fail"

                    Ok qualifiedAst ->
                        Expect.equal expectedAst qualifiedAst
        ]

Modified tests/Test/Qualifier/Util.elm from [e107564c2e] to [2822ce177a].

28
29
30
31
32
33
34





35
36
37
38
39
40
41
42
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =





            { name = ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =







>
>
>
>
>
|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
            if List.isEmpty generics then
                Type.Custom name

            else
                Type.CustomGeneric name (List.map Type.Generic generics)

        ctor =
            { name =
                if List.isEmpty members then
                    name

                else
                    ">" ++ name
            , metadata =
                Metadata.default
                    |> Metadata.withVerifiedType (List.map Tuple.second members) [ selfType ]
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =

Modified tests/Test/TypeChecker.elm from [ccb93b6437] to [7ab0558be9].

151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
...
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
...
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
...
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
...
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
....
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
....
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
                                  }
                                , { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.asEntryPoint
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange ">True"
                                            , QAST.Word emptyRange "as-int"
                                            ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
................................................................................
                            [ multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.asEntryPoint
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.Word emptyRange ">True"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Word emptyRange ">False"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Builtin emptyRange Builtin.Equal
                                        ]
                              }
                            ]
                    }
                        |> QualifierUtil.addFunctionsForStructs
................................................................................
                                Dict.fromListBy .name
                                    [ { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange ">False"
                                                    ]
                                                  )
                                                , ( QAST.TypeMatch emptyRange (Type.Custom "False") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange ">True"
                                                    ]
                                                  )
                                                ]
                                                []
                                      }
                                    , { name = "true-to-int"
                                      , metadata =
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange ">True"
                                                , QAST.Word emptyRange "not"
                                                , QAST.Word emptyRange "true-to-int"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
................................................................................
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange ">EmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Integer emptyRange 0
                                                , QAST.Word emptyRange "first-or-default"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Equal
                                                ]
                                      }
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange ">Nil"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange "with-default"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = ">Nil"
                                      , type_ = { input = [], output = [ Type.Custom "Nil" ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Nil"
................................................................................
                                      , type_ = { input = [], output = [ Type.Int ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            SoloImpl
                                                [ Word emptyRange
                                                    ">Nil"
                                                    { input = []
                                                    , output = [ Type.Custom "Nil" ]
                                                    }
                                                , IntLiteral emptyRange 1
                                                , Word emptyRange
                                                    "with-default"
                                                    { input = [ Type.Union [ Type.Int, Type.Custom "Nil" ], Type.Int ]
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange ">Nil"
                                                , QAST.WordRef emptyRange "main__quot1"
                                                , QAST.Word emptyRange "map"
                                                ]
                                      }
                                    , { name = "main__quot1"
                                      , metadata =
                                            Metadata.default
................................................................................
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Integer emptyRange 2
                                                , QAST.Integer emptyRange 3
                                                , QAST.Word emptyRange ">EmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange "sum"
                                                ]
                                      }
                                    ]







|







 







|

|







 







|




|







 







|







 







|







 







|







 







|







 







|







 







|







 







|







151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
...
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
...
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
...
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
...
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
...
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
...
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
...
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
....
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
....
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
                                  }
                                , { name = "main"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.asEntryPoint
                                  , implementation =
                                        QAST.SoloImpl
                                            [ QAST.Word emptyRange "True"
                                            , QAST.Word emptyRange "as-int"
                                            ]
                                  }
                                ]
                        }
                            |> QualifierUtil.addFunctionsForStructs
                in
................................................................................
                            [ multiFn
                            , { name = "main"
                              , metadata =
                                    Metadata.default
                                        |> Metadata.asEntryPoint
                              , implementation =
                                    QAST.SoloImpl
                                        [ QAST.Word emptyRange "True"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Word emptyRange "False"
                                        , QAST.Word emptyRange "to-int"
                                        , QAST.Builtin emptyRange Builtin.Equal
                                        ]
                              }
                            ]
                    }
                        |> QualifierUtil.addFunctionsForStructs
................................................................................
                                Dict.fromListBy .name
                                    [ { name = "not"
                                      , metadata = Metadata.default
                                      , implementation =
                                            QAST.MultiImpl
                                                [ ( QAST.TypeMatch emptyRange (Type.Custom "True") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange "False"
                                                    ]
                                                  )
                                                , ( QAST.TypeMatch emptyRange (Type.Custom "False") []
                                                  , [ QAST.Builtin emptyRange Builtin.StackDrop
                                                    , QAST.Word emptyRange "True"
                                                    ]
                                                  )
                                                ]
                                                []
                                      }
                                    , { name = "true-to-int"
                                      , metadata =
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange "True"
                                                , QAST.Word emptyRange "not"
                                                , QAST.Word emptyRange "true-to-int"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
................................................................................
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange "EmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Integer emptyRange 0
                                                , QAST.Word emptyRange "first-or-default"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Builtin emptyRange Builtin.Equal
                                                ]
                                      }
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange "Nil"
                                                , QAST.Integer emptyRange 1
                                                , QAST.Word emptyRange "with-default"
                                                ]
                                      }
                                    ]
                            }
                                |> QualifierUtil.addFunctionsForStructs
................................................................................
                                        [ Type.Generic "a"
                                        , Type.Custom "Nil"
                                        ]
                                    , CustomTypeDef "Nil" emptyRange [] []
                                    ]
                            , words =
                                Dict.fromListBy .name
                                    [ { name = "Nil"
                                      , type_ = { input = [], output = [ Type.Custom "Nil" ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.withVerifiedType [] [ Type.Custom "Nil" ]
                                      , implementation =
                                            SoloImpl
                                                [ ConstructType "Nil"
................................................................................
                                      , type_ = { input = [], output = [ Type.Int ] }
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            SoloImpl
                                                [ Word emptyRange
                                                    "Nil"
                                                    { input = []
                                                    , output = [ Type.Custom "Nil" ]
                                                    }
                                                , IntLiteral emptyRange 1
                                                , Word emptyRange
                                                    "with-default"
                                                    { input = [ Type.Union [ Type.Int, Type.Custom "Nil" ], Type.Int ]
................................................................................
                                      }
                                    , { name = "main"
                                      , metadata =
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Word emptyRange "Nil"
                                                , QAST.WordRef emptyRange "main__quot1"
                                                , QAST.Word emptyRange "map"
                                                ]
                                      }
                                    , { name = "main__quot1"
                                      , metadata =
                                            Metadata.default
................................................................................
                                            Metadata.default
                                                |> Metadata.asEntryPoint
                                      , implementation =
                                            QAST.SoloImpl
                                                [ QAST.Integer emptyRange 1
                                                , QAST.Integer emptyRange 2
                                                , QAST.Integer emptyRange 3
                                                , QAST.Word emptyRange "EmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange ">NonEmptyList"
                                                , QAST.Word emptyRange "sum"
                                                ]
                                      }
                                    ]

Modified wasm_tests/multiword.test.js from [5a7772d7cb] to [08aaade640].

13
14
15
16
17
18
19

20

21
22
23
24
25
26
27
..
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
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
169
...
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
        when: True
          drop 100
        when: False
          drop 75

        def: main
        entry: true

        : >True to-int >False to-int -

    `);

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

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

................................................................................
        defmulti: to-int
        when: True
          drop 100
        : drop 75

        def: main
        entry: true
        : >True to-int 
          >False to-int 
          -
    `);

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

    expect(result.stackElement()).toBe(25);
});
................................................................................
        when: NonEmptyList
          drop first>
        when: EmptyList
          swap drop

        def: main
        entry: true
        : 1 >EmptyList >NonEmptyList
          0 first-or-default
    `);

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

    expect(result.stackElement()).toBe(1);
});
................................................................................
        when: NonEmptyList
          swap dup first> rotate rest> rotate + sum-helper
        when: EmptyList
          swap drop

        def: main
        entry: true
        : 1 2 3 >EmptyList >NonEmptyList >NonEmptyList >NonEmptyList
          sum
    `);

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

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

test('Int case', async () => {
    const wat = await compiler.toWat(`
        defunion: Bool
        : Int
        : NoInt

        defstruct: NoInt

        defmulti: double
        when: Int
................................................................................
          swap 
          drop 1
          swap
        when: Int

        def: main
        entry: true
        : 0 >Nil inc-zero
          drop 
    `);

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

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







>
|
>







 







|
|







 







|







 







|










|







 







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
        when: True
          drop 100
        when: False
          drop 75

        def: main
        entry: true
        : True to-int 
          False to-int 
          -
    `);

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

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

................................................................................
        defmulti: to-int
        when: True
          drop 100
        : drop 75

        def: main
        entry: true
        : True to-int 
          False to-int 
          -
    `);

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

    expect(result.stackElement()).toBe(25);
});
................................................................................
        when: NonEmptyList
          drop first>
        when: EmptyList
          swap drop

        def: main
        entry: true
        : 1 EmptyList >NonEmptyList
          0 first-or-default
    `);

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

    expect(result.stackElement()).toBe(1);
});
................................................................................
        when: NonEmptyList
          swap dup first> rotate rest> rotate + sum-helper
        when: EmptyList
          swap drop

        def: main
        entry: true
        : 1 2 3 EmptyList >NonEmptyList >NonEmptyList >NonEmptyList
          sum
    `);

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

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

test('Int case', async () => {
    const wat = await compiler.toWat(`
        defunion: IntParseResult
        : Int
        : NoInt

        defstruct: NoInt

        defmulti: double
        when: Int
................................................................................
          swap 
          drop 1
          swap
        when: Int

        def: main
        entry: true
        : 0 Nil inc-zero
          drop 
    `);

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

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

Modified wasm_tests/record.test.js from [9f647c936c] to [203aebee22].

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
test('Enum type', async () => {
    const wat = await compiler.toWat(`
       defstruct: True 
       defstruct: False

       def: main
       entry: true
       : >True
    `);

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

    // types are sorted alphabetically, so False will get id 0, and True gets id 1.
    expect(result.typeIdForPointer()).toBe(1);
});







|







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
test('Enum type', async () => {
    const wat = await compiler.toWat(`
       defstruct: True 
       defstruct: False

       def: main
       entry: true
       : True
    `);

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

    // types are sorted alphabetically, so False will get id 0, and True gets id 1.
    expect(result.typeIdForPointer()).toBe(1);
});