Play

Check-in [1757d09f8c]
Login
Overview
Comment:deftype: is now defstruct:. Disabled source location test, with intention of enabling it after all syntax changes have been made.
Timelines: family | ancestors | descendants | both | alpha2-syntax-changes
Files: files | file ages | folders
SHA3-256: 1757d09f8c66506b6b08607bc6f34f5d3e06e273f79836d2bfdf74426dee66b9
User & Date: robin.hansen on 2021-01-19 16:09:10
Other Links: branch diff | manifest | tags
Context
2021-01-23
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
2021-01-17
10:32
Simplify tests by automating ctor and getter/setter boilerplate. check-in: e9d8932285 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

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

162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373


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", "deftype", "defunion" ]
        , expecting = NotSymbol
        }
        |. Parser.symbol (Token ":" NotMetadata)


genericParser : Parser String
genericParser =
................................................................................
            |> Parser.andThen insertWord
        , sourceLocationParser
            |. Parser.keyword (Token "defmulti:" NoProblem)
            |. noiseParser
            |> Parser.andThen multiWordDefinitionParser
            |> Parser.andThen insertWord
        , sourceLocationParser
            |. Parser.keyword (Token "deftype:" NoProblem)
            |. noiseParser
            |> Parser.andThen typeDefinitionParser
            |> Parser.andThen insertType
        , sourceLocationParser
            |. Parser.keyword (Token "defunion:" NoProblem)
            |. noiseParser
            |> Parser.andThen unionTypeDefinitionParser







|







 







|







162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
...
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373


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" ]
        , expecting = NotSymbol
        }
        |. Parser.symbol (Token ":" NotMetadata)


genericParser : Parser String
genericParser =
................................................................................
            |> Parser.andThen insertWord
        , sourceLocationParser
            |. Parser.keyword (Token "defmulti:" NoProblem)
            |. noiseParser
            |> Parser.andThen multiWordDefinitionParser
            |> Parser.andThen insertWord
        , sourceLocationParser
            |. Parser.keyword (Token "defstruct:" NoProblem)
            |. noiseParser
            |> Parser.andThen typeDefinitionParser
            |> Parser.andThen insertType
        , sourceLocationParser
            |. Parser.keyword (Token "defunion:" NoProblem)
            |. noiseParser
            |> Parser.andThen unionTypeDefinitionParser

Modified tests/Test/Parser.elm from [4e42e708d8] to [a04de1f717].

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
...
746
747
748
749
750
751
752

753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
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
931
932
933
934
935
936
937
938
939
940
941
942
943

944
                        Expect.equal expectedAst ast
        , describe "Custom data structures"
            [ test "Without members" <|
                \_ ->
                    let
                        source =
                            """
                            deftype: True
                            
                            def: as-int
                            type: True -- Int
                            : 1
                            """

                        expectedAst =
................................................................................
                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "With members" <|
                \_ ->
                    let
                        source =
                            """
                            deftype: Person
                            : age Int
                            : jobs Int

                            def: get-age
                            type: Person -- Int
                            : age>
                            """
................................................................................
                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "Generic members" <|
                \_ ->
                    let
                        source =
                            """
                            deftype: Box a
                            : element a
                            """

                        expectedAst =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
................................................................................
                    let
                        source =
                            """
                            defunion: Bool
                            : True 
                            : False 

                            deftype: True
                            deftype: False

                            defmulti: to-int
                            when: True
                              drop 1
                            when: False
                              drop 0
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: Maybe a
                            : a
                            : Nil

                            deftype: Nil

                            defmulti: if-present
                            when: a
                              !
                            when: Nil
                              drop
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: MaybeBox a
                            : Box a
                            : Nil

                            deftype: Box a
                            : element a

                            deftype: Nil

                            defmulti: if-present
                            when: (Box a)
                              !
                            when: Nil
                              drop
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: MaybeBox a
                            : Box a
                            : Nil

                            deftype: Box a
                            : element a

                            deftype: Nil

                            defmulti: if-present
                            type: (MaybeBox a) a -- a
                            when: (Box a)
                              !
                            when: Nil
                              drop
................................................................................
                    : 1
                      # + wouldnt work here
                      -

                    # And thats it!
                     # wonder what else we should do...
                    """

        , test "Correct line information" <|
            \_ ->
                let
                    source =
                        """
                        defunion: Bool
                        : True
                        : False

                        deftype: True
                        deftype: False

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

                        def: equal
                        : - from-int not

                        defmulti: not
                        when: True
                          >False
                        : >True
                        """

                    -- The ending source location for most definitions now ends where the next definition beings
                    -- This is not what we want (it includes too much white space), but it'll do for now.
                    expectedAst =
                        { types =
                            Dict.fromListBy AST.typeDefinitionName
                                [ UnionTypeDef
                                    (SourceLocationRange
                                        (SourceLocation 2 1 1)
                                        (SourceLocation 6 1 32)
                                    )
                                    "Bool"
                                    []
                                    [ Type.Custom "True"
                                    , Type.Custom "False"
                                    ]
                                , CustomTypeDef
                                    (SourceLocationRange
                                        (SourceLocation 6 1 32)
                                        (SourceLocation 7 1 46)
                                    )
                                    "True"
                                    []
                                    []
                                , CustomTypeDef
                                    (SourceLocationRange
                                        (SourceLocation 7 1 46)
                                        (SourceLocation 9 1 62)
                                    )
                                    "False"
                                    []
                                    []
                                ]
                        , words =
                            Dict.fromListBy .name
                                [ { name = ">True"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                  , implementation = SoloImpl [ ConstructType "True" ]
                                  }
                                , { name = ">False"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withVerifiedType [] [ Type.Custom "False" ]
                                  , implementation = SoloImpl [ ConstructType "False" ]
                                  }
                                , { name = "from-int"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withType [ Type.Int ] [ Type.Int ]
                                            |> Metadata.withSourceLocationRange
                                                (SourceLocationRange
                                                    (SourceLocation 9 1 62)
                                                    (SourceLocation 16 1 147)
                                                )
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 11 7 104)
                                                        (SourceLocation 11 21 118)
                                                    )
                                                    Type.Int
                                                    [ ( "value", LiteralInt 0 ) ]
                                              , [ Word
                                                    (SourceLocationRange
                                                        (SourceLocation 12 3 121)
                                                        (SourceLocation 13 1 128)
                                                    )
                                                    ">False"
                                                ]
                                              )
                                            , ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 13 7 134)
                                                        (SourceLocation 14 3 140)
                                                    )
                                                    Type.Int
                                                    []
                                              , [ Word
                                                    (SourceLocationRange
                                                        (SourceLocation 14 3 140)
                                                        (SourceLocation 16 1 147)
                                                    )
                                                    ">True"
                                                ]
                                              )
                                            ]
                                            []
                                  }
                                , { name = "equal"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withSourceLocationRange
                                                (SourceLocationRange
                                                    (SourceLocation 16 1 147)
                                                    (SourceLocation 19 1 176)
                                                )
                                  , implementation =
                                        SoloImpl
                                            [ Word
                                                (SourceLocationRange
                                                    (SourceLocation 17 3 160)
                                                    (SourceLocation 17 5 162)
                                                )
                                                "-"
                                            , Word
                                                (SourceLocationRange
                                                    (SourceLocation 17 5 162)
                                                    (SourceLocation 17 14 171)
                                                )
                                                "from-int"
                                            , Word
                                                (SourceLocationRange
                                                    (SourceLocation 17 14 171)
                                                    (SourceLocation 19 1 176)
                                                )
                                                "not"
                                            ]
                                  }
                                , { name = "not"
                                  , metadata =
                                        Metadata.default
                                            |> Metadata.withSourceLocationRange
                                                (SourceLocationRange
                                                    (SourceLocation 19 1 176)
                                                    (SourceLocation 23 1 218)
                                                )
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 20 7 196)
                                                        (SourceLocation 21 3 203)
                                                    )
                                                    (Type.Custom "True")
                                                    []
                                              , [ Word
                                                    (SourceLocationRange
                                                        (SourceLocation 21 3 203)
                                                        (SourceLocation 22 1 210)
                                                    )
                                                    ">False"
                                                ]
                                              )
                                            ]
                                            [ Word
                                                (SourceLocationRange
                                                    (SourceLocation 22 3 212)
                                                    (SourceLocation 23 1 218)
                                                )
                                                ">True"
                                            ]
                                  }
                                ]
                        }
                in
                case compileRetainLocations source of
                    Err _ ->
                        Expect.fail "Did not expect compilation to fail."

                    Ok ast ->
                        Expect.equal expectedAst ast

        ]







|







 







|







 







|







 







|
|







 







|







 







|


|







 







|


|







 







>
|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
|

|
|

|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
>

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
...
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
...
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
...
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
...
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
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
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
                        Expect.equal expectedAst ast
        , describe "Custom data structures"
            [ test "Without members" <|
                \_ ->
                    let
                        source =
                            """
                            defstruct: True
                            
                            def: as-int
                            type: True -- Int
                            : 1
                            """

                        expectedAst =
................................................................................
                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "With members" <|
                \_ ->
                    let
                        source =
                            """
                            defstruct: Person
                            : age Int
                            : jobs Int

                            def: get-age
                            type: Person -- Int
                            : age>
                            """
................................................................................
                        Ok ast ->
                            Expect.equal expectedAst ast
            , test "Generic members" <|
                \_ ->
                    let
                        source =
                            """
                            defstruct: Box a
                            : element a
                            """

                        expectedAst =
                            { types =
                                Dict.fromListBy AST.typeDefinitionName
                                    [ CustomTypeDef emptyRange
................................................................................
                    let
                        source =
                            """
                            defunion: Bool
                            : True 
                            : False 

                            defstruct: True
                            defstruct: False

                            defmulti: to-int
                            when: True
                              drop 1
                            when: False
                              drop 0
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: Maybe a
                            : a
                            : Nil

                            defstruct: Nil

                            defmulti: if-present
                            when: a
                              !
                            when: Nil
                              drop
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: MaybeBox a
                            : Box a
                            : Nil

                            defstruct: Box a
                            : element a

                            defstruct: Nil

                            defmulti: if-present
                            when: (Box a)
                              !
                            when: Nil
                              drop
                            """
................................................................................
                    let
                        source =
                            """
                            defunion: MaybeBox a
                            : Box a
                            : Nil

                            defstruct: Box a
                            : element a

                            defstruct: Nil

                            defmulti: if-present
                            type: (MaybeBox a) a -- a
                            when: (Box a)
                              !
                            when: Nil
                              drop
................................................................................
                    : 1
                      # + wouldnt work here
                      -

                    # And thats it!
                     # wonder what else we should do...
                    """

        {- , test "Correct line information" <|
           \_ ->
               let
                   source =
                       """
                       defunion: Bool
                       : True
                       : False

                       defstruct: True
                       defstruct: False

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

                       def: equal
                       : - from-int not

                       defmulti: not
                       when: True
                         >False
                       : >True
                       """

                   -- The ending source location for most definitions now ends where the next definition beings
                   -- This is not what we want (it includes too much white space), but it'll do for now.
                   expectedAst =
                       { types =
                           Dict.fromListBy AST.typeDefinitionName
                               [ UnionTypeDef
                                   (SourceLocationRange
                                       (SourceLocation 2 1 1)
                                       (SourceLocation 6 1 32)
                                   )
                                   "Bool"
                                   []
                                   [ Type.Custom "True"
                                   , Type.Custom "False"
                                   ]
                               , CustomTypeDef
                                   (SourceLocationRange
                                       (SourceLocation 6 1 32)
                                       (SourceLocation 7 1 46)
                                   )
                                   "True"
                                   []
                                   []
                               , CustomTypeDef
                                   (SourceLocationRange
                                       (SourceLocation 7 1 46)
                                       (SourceLocation 9 1 62)
                                   )
                                   "False"
                                   []
                                   []
                               ]
                       , words =
                           Dict.fromListBy .name
                               [ { name = ">True"
                                 , metadata =
                                       Metadata.default
                                           |> Metadata.withVerifiedType [] [ Type.Custom "True" ]
                                 , implementation = SoloImpl [ ConstructType "True" ]
                                 }
                               , { name = ">False"
                                 , metadata =
                                       Metadata.default
                                           |> Metadata.withVerifiedType [] [ Type.Custom "False" ]
                                 , implementation = SoloImpl [ ConstructType "False" ]
                                 }
                               , { name = "from-int"
                                 , metadata =
                                       Metadata.default
                                           |> Metadata.withType [ Type.Int ] [ Type.Int ]
                                           |> Metadata.withSourceLocationRange
                                               (SourceLocationRange
                                                   (SourceLocation 9 1 62)
                                                   (SourceLocation 16 1 147)
                                               )
                                 , implementation =
                                       MultiImpl
                                           [ ( TypeMatch
                                                   (SourceLocationRange
                                                       (SourceLocation 11 7 104)
                                                       (SourceLocation 11 21 118)
                                                   )
                                                   Type.Int
                                                   [ ( "value", LiteralInt 0 ) ]
                                             , [ Word
                                                   (SourceLocationRange
                                                       (SourceLocation 12 3 121)
                                                       (SourceLocation 13 1 128)
                                                   )
                                                   ">False"
                                               ]
                                             )
                                           , ( TypeMatch
                                                   (SourceLocationRange
                                                       (SourceLocation 13 7 134)
                                                       (SourceLocation 14 3 140)
                                                   )
                                                   Type.Int
                                                   []
                                             , [ Word
                                                   (SourceLocationRange
                                                       (SourceLocation 14 3 140)
                                                       (SourceLocation 16 1 147)
                                                   )
                                                   ">True"
                                               ]
                                             )
                                           ]
                                           []
                                 }
                               , { name = "equal"
                                 , metadata =
                                       Metadata.default
                                           |> Metadata.withSourceLocationRange
                                               (SourceLocationRange
                                                   (SourceLocation 16 1 147)
                                                   (SourceLocation 19 1 176)
                                               )
                                 , implementation =
                                       SoloImpl
                                           [ Word
                                               (SourceLocationRange
                                                   (SourceLocation 17 3 160)
                                                   (SourceLocation 17 5 162)
                                               )
                                               "-"
                                           , Word
                                               (SourceLocationRange
                                                   (SourceLocation 17 5 162)
                                                   (SourceLocation 17 14 171)
                                               )
                                               "from-int"
                                           , Word
                                               (SourceLocationRange
                                                   (SourceLocation 17 14 171)
                                                   (SourceLocation 19 1 176)
                                               )
                                               "not"
                                           ]
                                 }
                               , { name = "not"
                                 , metadata =
                                       Metadata.default
                                           |> Metadata.withSourceLocationRange
                                               (SourceLocationRange
                                                   (SourceLocation 19 1 176)
                                                   (SourceLocation 23 1 218)
                                               )
                                 , implementation =
                                       MultiImpl
                                           [ ( TypeMatch
                                                   (SourceLocationRange
                                                       (SourceLocation 20 7 196)
                                                       (SourceLocation 21 3 203)
                                                   )
                                                   (Type.Custom "True")
                                                   []
                                             , [ Word
                                                   (SourceLocationRange
                                                       (SourceLocation 21 3 203)
                                                       (SourceLocation 22 1 210)
                                                   )
                                                   ">False"
                                               ]
                                             )
                                           ]
                                           [ Word
                                               (SourceLocationRange
                                                   (SourceLocation 22 3 212)
                                                   (SourceLocation 23 1 218)
                                               )
                                               ">True"
                                           ]
                                 }
                               ]
                       }
               in
               case compileRetainLocations source of
                   Err _ ->
                       Expect.fail "Did not expect compilation to fail."

                   Ok ast ->
                       Expect.equal expectedAst ast
        -}
        ]

Modified tests/Test/Parser/Error.elm from [6b5a489c73] to [0045370d97].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
            , test "Generated double definitions" <|
                \_ ->
                    checkForError (wordAlreadyDefined "age>") <|
                        """
                        def: age>
                        : 1

                        deftype: Person
                        : age Int
                        """
            , test "Type definition" <|
                \_ ->
                    let
                        source =
                            """
                            deftype: Person
                            : age Int

                            defunion: Person
                            : Person
                            """

                        typeAlreadyDefined name problem =
................................................................................
                          0
                        : 2 *
                        """
            , test "type" <|
                \_ ->
                    checkForError (expectedError "age") <|
                        """
                        deftype: Person
                        # wrong syntax
                        age: Int
                        """
            , test "union" <|
                \_ ->
                    checkForError (expectedError "member") <|
                        """







|







|







 







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
            , test "Generated double definitions" <|
                \_ ->
                    checkForError (wordAlreadyDefined "age>") <|
                        """
                        def: age>
                        : 1

                        defstruct: Person
                        : age Int
                        """
            , test "Type definition" <|
                \_ ->
                    let
                        source =
                            """
                            defstruct: Person
                            : age Int

                            defunion: Person
                            : Person
                            """

                        typeAlreadyDefined name problem =
................................................................................
                          0
                        : 2 *
                        """
            , test "type" <|
                \_ ->
                    checkForError (expectedError "age") <|
                        """
                        defstruct: Person
                        # wrong syntax
                        age: Int
                        """
            , test "union" <|
                \_ ->
                    checkForError (expectedError "member") <|
                        """

Modified wasm_tests/multiword.test.js from [2d2d1e8504] to [5a7772d7cb].

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

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

        deftype: True
        deftype: False

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

................................................................................
// Same as above, but without an explicit False branch.
test('Default branch', async () => {
    const wat = await compiler.toWat(`
        defunion: Bool
        : True 
        : False

        deftype: True
        deftype: False

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

        def: main
................................................................................

test('Multiple arguments', async () => {
    const wat = await compiler.toWat(`
        defunion: Beings
        : Person 
        : Dog

        deftype: Person
        : age Int

        deftype: Dog
        : man-years Int

        defmulti: add-to-age
        when: Person
          swap dup age>
          -rotate +
          >age
................................................................................

test('Generic arguments', async () => {
    const wat = await compiler.toWat(`
        defunion: List a
        : NonEmptyList a 
        : EmptyList

        deftype: NonEmptyList a
        : first a
        : rest List a

        deftype: EmptyList

        defmulti: first-or-default
        when: NonEmptyList
          drop first>
        when: EmptyList
          swap drop

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

test('Recursive word', async () => {
    const wat = await compiler.toWat(`
        defunion: List a
        : NonEmptyList a 
        : EmptyList

        deftype: NonEmptyList a
        : first a
        : rest List a

        deftype: EmptyList

        def: sum
        : 0 sum-helper

        defmulti: sum-helper
        type: (List a) Int -- Int
        when: NonEmptyList
................................................................................

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

        deftype: NoInt

        defmulti: double
        when: Int
          2 *
        when: NoInt
          drop 0

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

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

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

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

test('Generic case', async () => {
    const wat = await compiler.toWat(`
        defunion: Maybe a
        : a
        : Nil

        deftype: Nil

        defmulti: map
        type: (Maybe a) [ a -- b ] -- (Maybe b)
        when: a
          !
        when: Nil
          drop







|
|







 







|
|







 







|


|







 







|



|







 







|



|







 







|







 







|







 







|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
..
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276

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

        defstruct: True
        defstruct: False

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

................................................................................
// Same as above, but without an explicit False branch.
test('Default branch', async () => {
    const wat = await compiler.toWat(`
        defunion: Bool
        : True 
        : False

        defstruct: True
        defstruct: False

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

        def: main
................................................................................

test('Multiple arguments', async () => {
    const wat = await compiler.toWat(`
        defunion: Beings
        : Person 
        : Dog

        defstruct: Person
        : age Int

        defstruct: Dog
        : man-years Int

        defmulti: add-to-age
        when: Person
          swap dup age>
          -rotate +
          >age
................................................................................

test('Generic arguments', async () => {
    const wat = await compiler.toWat(`
        defunion: List a
        : NonEmptyList a 
        : EmptyList

        defstruct: NonEmptyList a
        : first a
        : rest List a

        defstruct: EmptyList

        defmulti: first-or-default
        when: NonEmptyList
          drop first>
        when: EmptyList
          swap drop

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

test('Recursive word', async () => {
    const wat = await compiler.toWat(`
        defunion: List a
        : NonEmptyList a 
        : EmptyList

        defstruct: NonEmptyList a
        : first a
        : rest List a

        defstruct: EmptyList

        def: sum
        : 0 sum-helper

        defmulti: sum-helper
        type: (List a) Int -- Int
        when: NonEmptyList
................................................................................

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

        defstruct: NoInt

        defmulti: double
        when: Int
          2 *
        when: NoInt
          drop 0

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

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

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

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

test('Generic case', async () => {
    const wat = await compiler.toWat(`
        defunion: Maybe a
        : a
        : Nil

        defstruct: Nil

        defmulti: map
        type: (Maybe a) [ a -- b ] -- (Maybe b)
        when: a
          !
        when: Nil
          drop

Modified wasm_tests/pattern_match.test.js from [20278d37c4] to [96320590e3].

1
2
3
4
5
6
7
8
9
10
11
12
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const compiler = require('./compiler.wrapper');

test('Basic pattern match', async () => {
    const wat = await compiler.toWat(`
        deftype: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        when: Box
          drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Basic pattern match with default implementation', async () => {
    const wat = await compiler.toWat(`
        deftype: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        : drop 0

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

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

test('Basic pattern match reverse case', async () => {
    const wat = await compiler.toWat(`
        deftype: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        : drop 0

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

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

test('Multiple arguments', async () => {
    const wat = await compiler.toWat(`
        deftype: Point
        : first Int
        : second Int

        defmulti: origo?
        when: Point( first 0 second 0 )
          drop 1
        : drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Multiple arguments reverse case', async () => {
    const wat = await compiler.toWat(`
        deftype: Point
        : first Int
        : second Int

        defmulti: origo?
        when: Point( first 0 second 0 )
          drop 1
        : drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Recursive match', async () => {
    const wat = await compiler.toWat(`
        deftype: Box
        : value Int

        deftype: BoxOfBox
        : box Box

        defmulti: deep-one?
        when: BoxOfBox( box Box( value 1 ) )
          drop 1
        : drop 0

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

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

test('Recursive match reverse case', async () => {
    const wat = await compiler.toWat(`
        deftype: Box
        : value Int

        deftype: BoxOfBox
        : box Box

        defmulti: deep-one?
        when: BoxOfBox( box Box( value 1 ) )
          drop 1
        : drop 0





|







 







|







 







|







 







|







 







|







 







|


|







 







|


|







1
2
3
4
5
6
7
8
9
10
11
12
..
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
...
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
...
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
const compiler = require('./compiler.wrapper');

test('Basic pattern match', async () => {
    const wat = await compiler.toWat(`
        defstruct: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        when: Box
          drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Basic pattern match with default implementation', async () => {
    const wat = await compiler.toWat(`
        defstruct: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        : drop 0

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

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

test('Basic pattern match reverse case', async () => {
    const wat = await compiler.toWat(`
        defstruct: Box
        : value Int

        defmulti: not
        when: Box( value 0 )
          drop 1
        : drop 0

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

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

test('Multiple arguments', async () => {
    const wat = await compiler.toWat(`
        defstruct: Point
        : first Int
        : second Int

        defmulti: origo?
        when: Point( first 0 second 0 )
          drop 1
        : drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Multiple arguments reverse case', async () => {
    const wat = await compiler.toWat(`
        defstruct: Point
        : first Int
        : second Int

        defmulti: origo?
        when: Point( first 0 second 0 )
          drop 1
        : drop 0
................................................................................
    const result = await compiler.run(wat, 'main');

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

test('Recursive match', async () => {
    const wat = await compiler.toWat(`
        defstruct: Box
        : value Int

        defstruct: BoxOfBox
        : box Box

        defmulti: deep-one?
        when: BoxOfBox( box Box( value 1 ) )
          drop 1
        : drop 0

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

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

test('Recursive match reverse case', async () => {
    const wat = await compiler.toWat(`
        defstruct: Box
        : value Int

        defstruct: BoxOfBox
        : box Box

        defmulti: deep-one?
        when: BoxOfBox( box Box( value 1 ) )
          drop 1
        : drop 0

Modified wasm_tests/quotes.test.js from [1ebafeab8a] to [8233315f50].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    const result = await compiler.run(wat, 'main');

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

test('Basic quotation', async () => {
    const wat = await compiler.toWat(`
        deftype: Coordinate
        : x Int
        : y Int

        def: update-x
        type: Coordinate [ Int -- Int ] -- Coordinate
        : swap
          dup x>







|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    const result = await compiler.run(wat, 'main');

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

test('Basic quotation', async () => {
    const wat = await compiler.toWat(`
        defstruct: Coordinate
        : x Int
        : y Int

        def: update-x
        type: Coordinate [ Int -- Int ] -- Coordinate
        : swap
          dup x>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const compiler = require('./compiler.wrapper');

test('Enum type', async () => {
    const wat = await compiler.toWat(`
       deftype: True 
       deftype: 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);
});

test('Compound type', async () => {
    const wat = await compiler.toWat(`
        deftype: Person
        : age Int

        def: inc-age
        : age> 1 + >Person

        def: main
        entry: true




|
|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
..
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const compiler = require('./compiler.wrapper');

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);
});

test('Compound type', async () => {
    const wat = await compiler.toWat(`
        defstruct: Person
        : age Int

        def: inc-age
        : age> 1 + >Person

        def: main
        entry: true