Stabel

Check-in [fc3b105833]
Login
Overview
Comment:String literals. [3fac68d49a].
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: fc3b10583377da1c220936801591b329bf0089190ad4cb8a2ace78df76b6dcdb
User & Date: robin.hansen on 2021-09-06 20:39:00
Other Links: manifest | tags
Context
2021-09-09
10:46
It is now possible to write Stabel programs that return a string. check-in: 2f5dcec13a user: robin.hansen tags: trunk
2021-09-06
20:39
String literals. [3fac68d49a]. check-in: fc3b105833 user: robin.hansen tags: trunk
20:37
Strings now work. Closed-Leaf check-in: b730446f95 user: robin.hansen tags: strings
2021-09-01
05:19
Fix issues found with elm-review. check-in: f7ed530f30 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified elm.json from [696f8df2ff] to [6ed21b8cff].

7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
    "dependencies": {
        "direct": {
            "elm/core": "1.0.5",
            "elm/json": "1.1.3",
            "elm/parser": "1.1.0",
            "elm-community/dict-extra": "2.4.0",
            "elm-community/list-extra": "8.3.0",
            "elm-community/result-extra": "2.4.0"

        },
        "indirect": {}
    },
    "test-dependencies": {
        "direct": {
            "elm-community/string-extra": "4.0.1",
            "elm-explorations/test": "1.2.2"







|
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    "dependencies": {
        "direct": {
            "elm/core": "1.0.5",
            "elm/json": "1.1.3",
            "elm/parser": "1.1.0",
            "elm-community/dict-extra": "2.4.0",
            "elm-community/list-extra": "8.3.0",
            "elm-community/result-extra": "2.4.0",
            "zwilias/elm-utf-tools": "2.0.1"
        },
        "indirect": {}
    },
    "test-dependencies": {
        "direct": {
            "elm-community/string-extra": "4.0.1",
            "elm-explorations/test": "1.2.2"

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

786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
            let
                indexOfId =
                    indexOf name context.inlineFunctionNames
                        |> Maybe.withDefault 0
            in
            Wasm.Batch
                [ Wasm.Commented
                    (name ++ "ref")
                    (Wasm.I32_Const indexOfId)
                , BaseModule.callStackPushFn
                ]

        ConstructType typeId members ->
            let
                typeSize =







|







786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
            let
                indexOfId =
                    indexOf name context.inlineFunctionNames
                        |> Maybe.withDefault 0
            in
            Wasm.Batch
                [ Wasm.Commented
                    ("ref: " ++ name)
                    (Wasm.I32_Const indexOfId)
                , BaseModule.callStackPushFn
                ]

        ConstructType typeId members ->
            let
                typeSize =

Modified src/Stabel/Parser.elm from [040268e985] to [acca630c3a].

37
38
39
40
41
42
43

44
45
46
47
48
49
50
..
51
52
53
54
55
56
57

58
59
60
61
62
63
64
..
82
83
84
85
86
87
88

89
90
91
92
93
94
95
...
116
117
118
119
120
121
122


123
124
125
126
127
128
129
...
262
263
264
265
266
267
268




























































































































269
270
271
272
273
274
275
...
499
500
501
502
503
504
505





506
507
508
509
510
511
512
...
595
596
597
598
599
600
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
635
...
651
652
653
654
655
656
657

658
659
660
661
662
663
664
...
677
678
679
680
681
682
683






684
685
686
687
688
689
690
...
722
723
724
725
726
727
728

729
730
731
732
733
734
735
...
773
774
775
776
777
778
779






780
781
782
783
784
785
786
...
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
...
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
947
948
949
950
951
....
1053
1054
1055
1056
1057
1058
1059






1060
1061
1062
1063
1064
1065
1066
    , functions : Dict String FunctionDefinition
    }


type alias TypeDefinition =
    { name : String
    , sourceLocation : SourceLocationRange

    , generics : List String
    , members : TypeDefinitionMembers
    }


type TypeDefinitionMembers
    = StructMembers (List ( String, PossiblyQualifiedType ))
................................................................................
    | UnionMembers (List PossiblyQualifiedType)


type alias FunctionDefinition =
    { name : String
    , typeSignature : AssociatedFunctionSignature
    , sourceLocationRange : Maybe SourceLocationRange

    , aliases : Dict String String
    , imports : Dict String (List String)
    , implementation : FunctionImplementation
    }


type FunctionImplementation
................................................................................
    | PackageFunction SourceLocationRange (List String) String
    | ExternalFunction SourceLocationRange (List String) String
    | InlineFunction SourceLocationRange (List AstNode)
    | ConstructType String
    | GetMember String String
    | SetMember String String
    | ArrayLiteral SourceLocationRange (List AstNode)



run : String -> String -> Result (List (Parser.DeadEnd Context Problem)) AST
run ref sourceCode =
    Parser.run (parser ref) sourceCode


................................................................................
        , '['
        , ']'
        , '('
        , ')'
        , '.'
        , '#'
        , '/'


        ]


whitespaceChars : Set Char
whitespaceChars =
    Set.fromList
        [ ' '
................................................................................


textParser : Parser String
textParser =
    Parser.chompWhile (\c -> not <| Set.member c whitespaceChars)
        |> Parser.getChompedString






























































































































genericParser : Parser String
genericParser =
    Parser.oneOf
        [ Parser.succeed identity
            |. Parser.symbol (Token "-" UnknownError)
            |> Parser.andThen (\_ -> Parser.problem ExpectedGeneric)
................................................................................
        , Parser.inContext ExposingKeyword
            (Parser.succeed (\exposings -> Parser.Loop { def | exposes = exposings })
                |. Parser.keyword (Token "exposing:" UnknownError)
                |. noiseParser
                |= (Parser.loop [] symbolImplListParser |> Parser.map Set.fromList)
                |. noiseParser
            )





        , Parser.succeed UnknownMetadata
            |= metadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done def)
            |. Parser.keyword (Token ":" UnknownError)
            |. noiseParser
        ]
................................................................................
                    , typeSignature =
                        AssociatedFunctionSignature.Verified
                            { input =
                                List.map (NotStackRange << Tuple.second) typeMembers
                            , output = [ typeOfType ]
                            }
                    , sourceLocationRange = Nothing

                    , aliases = Dict.empty
                    , imports = Dict.empty
                    , implementation =
                        SoloImpl [ ConstructType typeDef.name ]
                    }

                setterGetterPair ( memberName, memberType ) =
................................................................................
                    [ { name = ">" ++ memberName
                      , typeSignature =
                            AssociatedFunctionSignature.Verified
                                { input = [ typeOfType, NotStackRange memberType ]
                                , output = [ typeOfType ]
                                }
                      , sourceLocationRange = Nothing

                      , aliases = Dict.empty
                      , imports = Dict.empty
                      , implementation =
                            SoloImpl
                                [ SetMember typeDef.name memberName ]
                      }
                    , { name = memberName ++ ">"
                      , typeSignature =
                            AssociatedFunctionSignature.Verified
                                { input = [ typeOfType ]
                                , output = [ NotStackRange memberType ]
                                }
                      , sourceLocationRange = Nothing

                      , aliases = Dict.empty
                      , imports = Dict.empty
                      , implementation =
                            SoloImpl
                                [ GetMember typeDef.name memberName ]
                      }
                    ]
................................................................................
                        }
            }

        emptyDef =
            { name = name
            , typeSignature = AssociatedFunctionSignature.NotProvided
            , sourceLocationRange = Nothing

            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = SoloImpl []
            }
    in
    Parser.inContext (Problem.FunctionDefinition startLocation name) <|
        case Dict.get name definedFunctions of
................................................................................
functionMetadataParser def =
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser






        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
................................................................................
                , implementation = reverseWhens def.implementation
            }

        emptyDef =
            { name = name
            , typeSignature = AssociatedFunctionSignature.NotProvided
            , sourceLocationRange = Nothing

            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = SoloImpl []
            }

        reverseWhens implementation =
            case implementation of
................................................................................
    in
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser






        , Parser.inContext ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
................................................................................
typeDefinitionParser :
    Dict String TypeDefinition
    -> Dict String FunctionDefinition
    -> ( SourceLocation, String )
    -> Parser TypeDefinition
typeDefinitionParser definedTypes definedFunctions ( startLocation, typeName ) =
    let
        ctor generics members endLocation =
            { name = typeName
            , sourceLocation = SourceLocationRange startLocation endLocation

            , generics = generics
            , members = StructMembers members
            }
    in
    Parser.inContext (Problem.StructDefinition startLocation typeName) <|
        case Dict.get typeName definedTypes of
            Just previousDefinition ->
                Parser.problem <|
                    TypeAlreadyDefined
................................................................................
                        typeName
                        previousDefinition.sourceLocation

            Nothing ->
                Parser.succeed ctor
                    |. noiseParser
                    |= Parser.loop [] typeGenericParser




                    |= Parser.loop [] (typeMemberParser definedFunctions)
                    |= sourceLocationParser


typeGenericParser : List String -> Parser (Parser.Step (List String) (List String))
typeGenericParser generics =
    Parser.oneOf
        [ Parser.succeed (\name -> Parser.Loop (name :: generics))
            |= genericParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse generics))
        ]








typeMemberParser :
    Dict String FunctionDefinition
    -> List ( String, PossiblyQualifiedType )
    ->
        Parser
            (Parser.Step
                (List ( String, PossiblyQualifiedType ))
                (List ( String, PossiblyQualifiedType ))
            )
typeMemberParser functions types =
    let
        alreadyDefinedCheck name =
            let
                getterName =
                    name ++ ">"

                setterName =
................................................................................
                            setter.sourceLocationRange

                ( Nothing, Nothing ) ->
                    Parser.succeed name
    in
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\name type_ -> Parser.Loop (( name, type_ ) :: types))
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= Parser.andThen alreadyDefinedCheck symbolParser
                |. noiseParser
                |= typeRefParser






        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done (List.reverse types))
        ]


unionTypeDefinitionParser : Dict String TypeDefinition -> ( SourceLocation, String ) -> Parser TypeDefinition
unionTypeDefinitionParser definedTypes ( startLocation, typeName ) =
    let
        ctor generics members endLocation =
            { name = typeName
            , sourceLocation = SourceLocationRange startLocation endLocation

            , generics = generics
            , members = UnionMembers members
            }
    in
    Parser.inContext (Problem.UnionDefinition startLocation typeName) <|
        case Dict.get typeName definedTypes of
            Just previousDefinition ->
                Parser.problem <|
                    TypeAlreadyDefined
................................................................................
                        typeName
                        previousDefinition.sourceLocation

            Nothing ->
                Parser.succeed ctor
                    |. noiseParser
                    |= Parser.loop [] typeGenericParser




                    |= Parser.loop [] unionTypeMemberParser
                    |= sourceLocationParser








unionTypeMemberParser :
    List PossiblyQualifiedType
    -> Parser (Parser.Step (List PossiblyQualifiedType) (List PossiblyQualifiedType))


unionTypeMemberParser types =
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\type_ -> Parser.Loop (type_ :: types))
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= typeRefParser






        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done (List.reverse types))
        ]


typeSignatureParser : Parser FunctionSignature
typeSignatureParser =
    Parser.succeed (\input output -> { input = input, output = output })
        |= Parser.loop [] typeLoopParser
................................................................................
        , Parser.succeed (\startLoc arrContent endLoc -> Parser.Loop (ArrayLiteral (SourceLocationRange startLoc endLoc) arrContent :: nodes))
            |= sourceLocationParser
            |. Parser.symbol (Token "{" ExpectedLeftCurly)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "}" ExpectedRightCurly)
            |= sourceLocationParser






            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


nodeParser : Parser AstNode
nodeParser =







>







 







>







 







>







 







>
>







 







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







 







>
>
>
>
>







 







>







 







>













>







 







>







 







>
>
>
>
>
>







 







>







 







>
>
>
>
>
>







 







|


>

|







 







>
>
>
>
|












>
>
>
>
>
>



|



|
|

|







 







|





>
>
>
>
>
>



|






|


>

|







 







>
>
>
>
|



>
>
>
>
>
>

<
<
>
>
|


|



>
>
>
>
>
>



|







 







>
>
>
>
>
>







37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
..
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
...
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
...
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
...
744
745
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
...
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
...
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
...
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
...
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
...
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
....
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
....
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110


1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
....
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
    , functions : Dict String FunctionDefinition
    }


type alias TypeDefinition =
    { name : String
    , sourceLocation : SourceLocationRange
    , documentation : String
    , generics : List String
    , members : TypeDefinitionMembers
    }


type TypeDefinitionMembers
    = StructMembers (List ( String, PossiblyQualifiedType ))
................................................................................
    | UnionMembers (List PossiblyQualifiedType)


type alias FunctionDefinition =
    { name : String
    , typeSignature : AssociatedFunctionSignature
    , sourceLocationRange : Maybe SourceLocationRange
    , documentation : String
    , aliases : Dict String String
    , imports : Dict String (List String)
    , implementation : FunctionImplementation
    }


type FunctionImplementation
................................................................................
    | PackageFunction SourceLocationRange (List String) String
    | ExternalFunction SourceLocationRange (List String) String
    | InlineFunction SourceLocationRange (List AstNode)
    | ConstructType String
    | GetMember String String
    | SetMember String String
    | ArrayLiteral SourceLocationRange (List AstNode)
    | StringLiteral SourceLocationRange String


run : String -> String -> Result (List (Parser.DeadEnd Context Problem)) AST
run ref sourceCode =
    Parser.run (parser ref) sourceCode


................................................................................
        , '['
        , ']'
        , '('
        , ')'
        , '.'
        , '#'
        , '/'
        , '\''
        , '"'
        ]


whitespaceChars : Set Char
whitespaceChars =
    Set.fromList
        [ ' '
................................................................................


textParser : Parser String
textParser =
    Parser.chompWhile (\c -> not <| Set.member c whitespaceChars)
        |> Parser.getChompedString


stringParser : Parser String
stringParser =
    Parser.oneOf
        [ Parser.succeed stripMultilineStringWhitespace
            |. Parser.symbol (Token "\"\"\"" UnknownError)
            |= Parser.loop (Just "") multilineStringParserLoop
        , Parser.succeed identity
            |. Parser.symbol (Token "\"" UnknownError)
            |= Parser.loop (Just "") stringParserLoop
        ]


stringParserLoop : Maybe String -> Parser (Parser.Step (Maybe String) String)
stringParserLoop maybeStr =
    case maybeStr of
        Nothing ->
            -- Work around bug in elm/parser
            Parser.problem StringNotTerminated

        Just str ->
            Parser.oneOf
                [ Parser.succeed (Parser.Done str)
                    |. Parser.symbol (Token "\"" UnknownError)
                , Parser.succeed (\char -> Parser.Loop <| Just <| str ++ String.fromChar char)
                    |. Parser.symbol (Token "\\" UnknownError)
                    |= Parser.oneOf
                        [ Parser.succeed '\n'
                            |. Parser.symbol (Token "n" UnknownError)
                        , Parser.succeed '\t'
                            |. Parser.symbol (Token "t" UnknownError)
                        , Parser.succeed '"'
                            |. Parser.symbol (Token "\"" UnknownError)
                        , Parser.succeed '\\'
                            |. Parser.symbol (Token "\\" UnknownError)
                        , Parser.succeed ()
                            |. Parser.chompIf (always True) UnknownError
                            |> Parser.getChompedString
                            |> Parser.andThen (\seq -> Parser.problem (UnknownEscapeSequence <| "\\" ++ seq))
                        ]

                -- Couldn't get the below to work in any other way :(
                , Parser.succeed (Parser.Loop Nothing)
                    |. Parser.end StringNotTerminated
                , Parser.succeed (Parser.Done str)
                    |. Parser.symbol (Token "\n" UnknownError)
                    |> Parser.andThen (\_ -> Parser.problem StringNotTerminated)
                , Parser.succeed ()
                    |. Parser.chompWhile (\c -> c /= '\n' && c /= '"' && c /= '\\')
                    |> Parser.getChompedString
                    |> Parser.map (\chompedStr -> Parser.Loop <| Just <| str ++ chompedStr)
                ]


multilineStringParserLoop : Maybe String -> Parser (Parser.Step (Maybe String) String)
multilineStringParserLoop maybeStr =
    case maybeStr of
        Nothing ->
            -- Work around bug in elm/parser
            Parser.problem StringNotTerminated

        Just str ->
            Parser.oneOf
                [ Parser.succeed (Parser.Done str)
                    |. Parser.symbol (Token "\"\"\"" UnknownError)

                -- Couldn't get the below to work in any other way :(
                , Parser.succeed (Parser.Loop Nothing)
                    |. Parser.end StringNotTerminated
                , Parser.succeed ()
                    |. Parser.chompWhile (\c -> c /= '"')
                    |> Parser.getChompedString
                    |> Parser.map (\chompedStr -> Parser.Loop <| Just <| str ++ chompedStr)
                ]


stripMultilineStringWhitespace : String -> String
stripMultilineStringWhitespace str =
    let
        noLeadingNewline =
            if String.startsWith "\n" str then
                String.dropLeft 1 str

            else
                str

        noEndingNewline =
            if String.endsWith "\n" noLeadingNewline then
                String.dropRight 1 noLeadingNewline

            else
                noLeadingNewline

        linesWithLeadingWhitespace =
            String.lines noEndingNewline
                |> List.map (\line -> ( countLeadingWhitespace line, line ))

        linesWithStrippedWhitespace =
            case linesWithLeadingWhitespace of
                [] ->
                    []

                ( maxWhitespace, _ ) :: _ ->
                    List.map
                        (stripMaxWhitespace maxWhitespace)
                        linesWithLeadingWhitespace
    in
    String.join "\n" linesWithStrippedWhitespace


countLeadingWhitespace : String -> Int
countLeadingWhitespace str =
    case String.uncons str of
        Just ( ' ', rest ) ->
            1 + countLeadingWhitespace rest

        _ ->
            0


stripMaxWhitespace : Int -> ( Int, String ) -> String
stripMaxWhitespace max ( whitespaceCount, line ) =
    String.dropLeft (min max whitespaceCount) line


genericParser : Parser String
genericParser =
    Parser.oneOf
        [ Parser.succeed identity
            |. Parser.symbol (Token "-" UnknownError)
            |> Parser.andThen (\_ -> Parser.problem ExpectedGeneric)
................................................................................
        , Parser.inContext ExposingKeyword
            (Parser.succeed (\exposings -> Parser.Loop { def | exposes = exposings })
                |. Parser.keyword (Token "exposing:" UnknownError)
                |. noiseParser
                |= (Parser.loop [] symbolImplListParser |> Parser.map Set.fromList)
                |. noiseParser
            )
        , Parser.succeed (\str -> Parser.Loop { def | documentation = str })
            |. Parser.keyword (Token "doc:" UnknownError)
            |. noiseParser
            |= stringParser
            |. noiseParser
        , Parser.succeed UnknownMetadata
            |= metadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done def)
            |. Parser.keyword (Token ":" UnknownError)
            |. noiseParser
        ]
................................................................................
                    , typeSignature =
                        AssociatedFunctionSignature.Verified
                            { input =
                                List.map (NotStackRange << Tuple.second) typeMembers
                            , output = [ typeOfType ]
                            }
                    , sourceLocationRange = Nothing
                    , documentation = ""
                    , aliases = Dict.empty
                    , imports = Dict.empty
                    , implementation =
                        SoloImpl [ ConstructType typeDef.name ]
                    }

                setterGetterPair ( memberName, memberType ) =
................................................................................
                    [ { name = ">" ++ memberName
                      , typeSignature =
                            AssociatedFunctionSignature.Verified
                                { input = [ typeOfType, NotStackRange memberType ]
                                , output = [ typeOfType ]
                                }
                      , sourceLocationRange = Nothing
                      , documentation = ""
                      , aliases = Dict.empty
                      , imports = Dict.empty
                      , implementation =
                            SoloImpl
                                [ SetMember typeDef.name memberName ]
                      }
                    , { name = memberName ++ ">"
                      , typeSignature =
                            AssociatedFunctionSignature.Verified
                                { input = [ typeOfType ]
                                , output = [ NotStackRange memberType ]
                                }
                      , sourceLocationRange = Nothing
                      , documentation = ""
                      , aliases = Dict.empty
                      , imports = Dict.empty
                      , implementation =
                            SoloImpl
                                [ GetMember typeDef.name memberName ]
                      }
                    ]
................................................................................
                        }
            }

        emptyDef =
            { name = name
            , typeSignature = AssociatedFunctionSignature.NotProvided
            , sourceLocationRange = Nothing
            , documentation = ""
            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = SoloImpl []
            }
    in
    Parser.inContext (Problem.FunctionDefinition startLocation name) <|
        case Dict.get name definedFunctions of
................................................................................
functionMetadataParser def =
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
                |. Parser.keyword (Token "alias:" UnknownError)
                |. noiseParser
                |= symbolParser
                |. noiseParser
                |= modulePathStringParser
................................................................................
                , implementation = reverseWhens def.implementation
            }

        emptyDef =
            { name = name
            , typeSignature = AssociatedFunctionSignature.NotProvided
            , sourceLocationRange = Nothing
            , documentation = ""
            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = SoloImpl []
            }

        reverseWhens implementation =
            case implementation of
................................................................................
    in
    Parser.oneOf
        [ Parser.inContext TypeKeyword <|
            Parser.succeed (\typeSign -> Parser.Loop { def | typeSignature = AssociatedFunctionSignature.UserProvided typeSign })
                |. Parser.keyword (Token "type:" UnknownError)
                |. noiseParser
                |= typeSignatureParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { def | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.inContext ElseKeyword <|
            Parser.succeed (\impl -> Parser.Loop { def | implementation = setDefaultImpl impl })
                |. Parser.keyword (Token "else:" UnknownError)
                |. noiseParser
                |= implementationParser
        , Parser.inContext AliasKeyword <|
            Parser.succeed (\alias value -> Parser.Loop { def | aliases = Dict.insert alias value def.aliases })
................................................................................
typeDefinitionParser :
    Dict String TypeDefinition
    -> Dict String FunctionDefinition
    -> ( SourceLocation, String )
    -> Parser TypeDefinition
typeDefinitionParser definedTypes definedFunctions ( startLocation, typeName ) =
    let
        ctor generics result endLocation =
            { name = typeName
            , sourceLocation = SourceLocationRange startLocation endLocation
            , documentation = result.documentation
            , generics = generics
            , members = StructMembers result.members
            }
    in
    Parser.inContext (Problem.StructDefinition startLocation typeName) <|
        case Dict.get typeName definedTypes of
            Just previousDefinition ->
                Parser.problem <|
                    TypeAlreadyDefined
................................................................................
                        typeName
                        previousDefinition.sourceLocation

            Nothing ->
                Parser.succeed ctor
                    |. noiseParser
                    |= Parser.loop [] typeGenericParser
                    |= Parser.loop
                        { documentation = ""
                        , members = []
                        }
                        (typeMemberParser definedFunctions)
                    |= sourceLocationParser


typeGenericParser : List String -> Parser (Parser.Step (List String) (List String))
typeGenericParser generics =
    Parser.oneOf
        [ Parser.succeed (\name -> Parser.Loop (name :: generics))
            |= genericParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse generics))
        ]


type alias StructMembersParserResult =
    { documentation : String
    , members : List ( String, PossiblyQualifiedType )
    }


typeMemberParser :
    Dict String FunctionDefinition
    -> StructMembersParserResult
    ->
        Parser
            (Parser.Step
                StructMembersParserResult
                StructMembersParserResult
            )
typeMemberParser functions result =
    let
        alreadyDefinedCheck name =
            let
                getterName =
                    name ++ ">"

                setterName =
................................................................................
                            setter.sourceLocationRange

                ( Nothing, Nothing ) ->
                    Parser.succeed name
    in
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\name type_ -> Parser.Loop { result | members = ( name, type_ ) :: result.members })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= Parser.andThen alreadyDefinedCheck symbolParser
                |. noiseParser
                |= typeRefParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done { result | members = List.reverse result.members })
        ]


unionTypeDefinitionParser : Dict String TypeDefinition -> ( SourceLocation, String ) -> Parser TypeDefinition
unionTypeDefinitionParser definedTypes ( startLocation, typeName ) =
    let
        ctor generics result endLocation =
            { name = typeName
            , sourceLocation = SourceLocationRange startLocation endLocation
            , documentation = result.documentation
            , generics = generics
            , members = UnionMembers result.types
            }
    in
    Parser.inContext (Problem.UnionDefinition startLocation typeName) <|
        case Dict.get typeName definedTypes of
            Just previousDefinition ->
                Parser.problem <|
                    TypeAlreadyDefined
................................................................................
                        typeName
                        previousDefinition.sourceLocation

            Nothing ->
                Parser.succeed ctor
                    |. noiseParser
                    |= Parser.loop [] typeGenericParser
                    |= Parser.loop
                        { documentation = ""
                        , types = []
                        }
                        unionTypeMemberParser
                    |= sourceLocationParser


type alias UnionMembersParserResult =
    { documentation : String
    , types : List PossiblyQualifiedType
    }


unionTypeMemberParser :


    UnionMembersParserResult
    -> Parser (Parser.Step UnionMembersParserResult UnionMembersParserResult)
unionTypeMemberParser result =
    Parser.oneOf
        [ Parser.inContext MemberKeyword <|
            Parser.succeed (\type_ -> Parser.Loop { result | types = type_ :: result.types })
                |. Parser.symbol (Token ":" UnknownError)
                |. noiseParser
                |= typeRefParser
        , Parser.inContext DocKeyword <|
            Parser.succeed (\str -> Parser.Loop { result | documentation = str })
                |. Parser.keyword (Token "doc:" UnknownError)
                |. noiseParser
                |= stringParser
                |. noiseParser
        , Parser.succeed UnknownMetadata
            |= definitionMetadataParser
            |> Parser.andThen Parser.problem
        , Parser.succeed (Parser.Done { result | types = List.reverse result.types })
        ]


typeSignatureParser : Parser FunctionSignature
typeSignatureParser =
    Parser.succeed (\input output -> { input = input, output = output })
        |= Parser.loop [] typeLoopParser
................................................................................
        , Parser.succeed (\startLoc arrContent endLoc -> Parser.Loop (ArrayLiteral (SourceLocationRange startLoc endLoc) arrContent :: nodes))
            |= sourceLocationParser
            |. Parser.symbol (Token "{" ExpectedLeftCurly)
            |. noiseParser
            |= implementationParser
            |. Parser.symbol (Token "}" ExpectedRightCurly)
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (\startLoc strContent endLoc -> Parser.Loop (StringLiteral (SourceLocationRange startLoc endLoc) strContent :: nodes))
            |= sourceLocationParser
            |= stringParser
            -- stringParser chomps the final "
            |= sourceLocationParser
            |. noiseParser
        , Parser.succeed (Parser.Done (List.reverse nodes))
        ]


nodeParser : Parser AstNode
nodeParser =

Modified src/Stabel/Parser/ModuleDefinition.elm from [7265ca2262] to [6d4b48c8bb].

14
15
16
17
18
19
20

21
22
23
24
25
26
27
28

29
30
31
32
33
34
35
36
37
38
39
    | Defined Definition


type alias Definition =
    { aliases : Dict String String
    , imports : Dict String (List String)
    , exposes : Set String

    }


emptyDefinition : Definition
emptyDefinition =
    { aliases = Dict.empty
    , imports = Dict.empty
    , exposes = Set.empty

    }


definition : ModuleDefinition -> Definition
definition mod =
    case mod of
        Undefined ->
            emptyDefinition

        Defined def ->
            def







>








>











14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    | Defined Definition


type alias Definition =
    { aliases : Dict String String
    , imports : Dict String (List String)
    , exposes : Set String
    , documentation : String
    }


emptyDefinition : Definition
emptyDefinition =
    { aliases = Dict.empty
    , imports = Dict.empty
    , exposes = Set.empty
    , documentation = ""
    }


definition : ModuleDefinition -> Definition
definition mod =
    case mod of
        Undefined ->
            emptyDefinition

        Defined def ->
            def

Modified src/Stabel/Parser/Problem.elm from [11e01b8df9] to [c2792cae36].

19
20
21
22
23
24
25

26
27
28
29
30
31
32
..
48
49
50
51
52
53
54


55
56
57
58
59
60
61
...
136
137
138
139
140
141
142



143
144
145
146
147
148
149
...
262
263
264
265
266
267
268








    | MultifunctionDefinition SourceLocation String
    | StructDefinition SourceLocation String
    | UnionDefinition SourceLocation String
    | AliasKeyword
    | ImportKeyword
    | ExposingKeyword
    | TypeKeyword

    | MemberKeyword
    | ImplementationKeyword
    | ElseKeyword


type Problem
    = ExpectedInt
................................................................................
    | ExpectedRightCurly
    | FunctionAlreadyDefined String (Maybe SourceLocationRange)
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String




toString : String -> String -> DeadEnd Context Problem -> String
toString sourceRef source deadEnd =
    let
        contextExplination =
            contextStackExplination deadEnd
................................................................................

        ExposingKeyword ->
            "exposing keyword"

        TypeKeyword ->
            "type keyword"




        MemberKeyword ->
            "member"

        ImplementationKeyword ->
            "implementation"

        ElseKeyword ->
................................................................................
        ModuleIsEmpty ->
            "A module is required to contain at least one definition."

        BadDefinition name ->
            "'"
                ++ name
                ++ "' is not a valid definition. Expected either defmodule:, def:, defmulti:, defstruct: or defunion:"















>







 







>
>







 







>
>
>







 







>
>
>
>
>
>
>
>
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
..
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
...
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
    | MultifunctionDefinition SourceLocation String
    | StructDefinition SourceLocation String
    | UnionDefinition SourceLocation String
    | AliasKeyword
    | ImportKeyword
    | ExposingKeyword
    | TypeKeyword
    | DocKeyword
    | MemberKeyword
    | ImplementationKeyword
    | ElseKeyword


type Problem
    = ExpectedInt
................................................................................
    | ExpectedRightCurly
    | FunctionAlreadyDefined String (Maybe SourceLocationRange)
    | TypeAlreadyDefined String SourceLocationRange
    | UnknownMetadata String
    | InvalidModulePath String
    | ModuleIsEmpty
    | BadDefinition String
    | UnknownEscapeSequence String
    | StringNotTerminated


toString : String -> String -> DeadEnd Context Problem -> String
toString sourceRef source deadEnd =
    let
        contextExplination =
            contextStackExplination deadEnd
................................................................................

        ExposingKeyword ->
            "exposing keyword"

        TypeKeyword ->
            "type keyword"

        DocKeyword ->
            "doc keyword"

        MemberKeyword ->
            "member"

        ImplementationKeyword ->
            "implementation"

        ElseKeyword ->
................................................................................
        ModuleIsEmpty ->
            "A module is required to contain at least one definition."

        BadDefinition name ->
            "'"
                ++ name
                ++ "' is not a valid definition. Expected either defmodule:, def:, defmulti:, defstruct: or defunion:"

        UnknownEscapeSequence seq ->
            "'"
                ++ seq
                ++ "' is not a valid escape sequence. Expected either \\n, \\t, \\\\ or \\\"."

        StringNotTerminated ->
            "This string never terminates. Expected to find a closing \"."

Modified src/Stabel/Qualifier.elm from [39463bf45b] to [546a2fca9e].

23
24
25
26
27
28
29

30
31
32
33
34
35
36
...
213
214
215
216
217
218
219

220
221
222
223
224
225
226
....
1465
1466
1467
1468
1469
1470
1471

















1472
1473
1474
1475
1476
1477
1478
import Stabel.Data.Type as Type exposing (FunctionType, Type)
import Stabel.Data.TypeSignature as TypeSignature exposing (TypeSignature)
import Stabel.Parser as Parser
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature
import Stabel.Parser.ModuleDefinition as ModuleDefinition
import Stabel.Parser.Type as Parser
import Stabel.Qualifier.Problem exposing (Problem(..))



type alias AST =
    { types : Dict String TypeDefinition
    , functions : Dict String FunctionDefinition
    , referenceableFunctions : Set String
    }
................................................................................

        def =
            ModuleDefinition.definition config.ast.moduleDefinition
    in
    { imports = Dict.union def.imports defaultImports
    , aliases = def.aliases
    , exposes = def.exposes

    }


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition
resolveUnionInTypeDefs qt td =
    { td
        | members =
................................................................................
                            Ok (ArrayLiteral (mapLoc loc) qualifiedNodes)
                                :: acc.qualifiedNodes
                    }

                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }



















isMultiFunction : Parser.FunctionDefinition -> Bool
isMultiFunction def =
    case def.implementation of
        Parser.SoloImpl _ ->
            False








>







 







>







 







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







23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
...
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
....
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
import Stabel.Data.Type as Type exposing (FunctionType, Type)
import Stabel.Data.TypeSignature as TypeSignature exposing (TypeSignature)
import Stabel.Parser as Parser
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature
import Stabel.Parser.ModuleDefinition as ModuleDefinition
import Stabel.Parser.Type as Parser
import Stabel.Qualifier.Problem exposing (Problem(..))
import String.UTF8 as UTF8


type alias AST =
    { types : Dict String TypeDefinition
    , functions : Dict String FunctionDefinition
    , referenceableFunctions : Set String
    }
................................................................................

        def =
            ModuleDefinition.definition config.ast.moduleDefinition
    in
    { imports = Dict.union def.imports defaultImports
    , aliases = def.aliases
    , exposes = def.exposes
    , documentation = def.documentation
    }


resolveUnionInTypeDefs : Dict String TypeDefinition -> TypeDefinition -> TypeDefinition
resolveUnionInTypeDefs qt td =
    { td
        | members =
................................................................................
                            Ok (ArrayLiteral (mapLoc loc) qualifiedNodes)
                                :: acc.qualifiedNodes
                    }

                Err err ->
                    { acc | qualifiedNodes = Err err :: acc.qualifiedNodes }

        Parser.StringLiteral loc value ->
            let
                stringBytes =
                    UTF8.toBytes value

                stringNode =
                    -- locations are all wrong, but should always be correct
                    -- therefore it should never be visible to the user
                    Parser.InlineFunction loc
                        [ Parser.ArrayLiteral loc <|
                            List.map (Parser.Integer loc) stringBytes
                        , Parser.ExternalFunction loc [ "string" ] "from-bytes"
                        ]
            in
            qualifyNode config currentDefName (Parser.Function loc "!") acc
                |> qualifyNode config currentDefName stringNode


isMultiFunction : Parser.FunctionDefinition -> Bool
isMultiFunction def =
    case def.implementation of
        Parser.SoloImpl _ ->
            False

Modified src/Stabel/Wasm.elm from [00f148bec4] to [5257e9c1dc].

416
417
418
419
420
421
422
423
424
425
426
427
428
429
430

        Unreachable ->
            Str "unreachable"

        Commented comment inst ->
            case formatInstruction inst of
                Str val ->
                    Str <| val ++ ";; " ++ comment

                BatchFormat batch ->
                    BatchFormat <| (Str <| ";; " ++ comment) :: batch

                Indent batch ->
                    Indent <| (Str <| ";; " ++ comment) :: batch








|







416
417
418
419
420
421
422
423
424
425
426
427
428
429
430

        Unreachable ->
            Str "unreachable"

        Commented comment inst ->
            case formatInstruction inst of
                Str val ->
                    Str <| val ++ " ;; " ++ comment

                BatchFormat batch ->
                    BatchFormat <| (Str <| ";; " ++ comment) :: batch

                Indent batch ->
                    Indent <| (Str <| ";; " ++ comment) :: batch

Modified src/TestCompiler.elm from [e04edc62d9] to [8b48cbd435].

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =
            let
                fullPath =
                    mod.package ++ mod.modulePath
            in
            case Parser.run fullPath mod.source of
                Err errs ->
                    Err ( fullPath, mod.source, errs )

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )







|







187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =
            let
                fullPath =
                    "/" ++ mod.package ++ "/" ++ mod.modulePath
            in
            case Parser.run fullPath mod.source of
                Err errs ->
                    Err ( fullPath, mod.source, errs )

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )

Modified tests/Test/Parser.elm from [7f783df7cb] to [0383b8f873].

47
48
49
50
51
52
53

54
55
56
57
58
59
60
..
62
63
64
65
66
67
68

69
70
71
72
73
74
75
76
77
78
79

80
81
82
83
84
85
86
...
112
113
114
115
116
117
118








































119
120
121
122
123
124
125
...
151
152
153
154
155
156
157

158
159
160
161
162
163
164
...
165
166
167
168
169
170
171

172
173
174
175
176
177
178
...
197
198
199
200
201
202
203

204
205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223
...
243
244
245
246
247
248
249

250
251
252
253
254
255
256
...
260
261
262
263
264
265
266

267
268
269
270
271
272
273
...
288
289
290
291
292
293
294

295
296
297
298
299
300
301
...
304
305
306
307
308
309
310

311
312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334

335
336
337
338
339
340
341
342
































343
344
345
346
347
348
349
...
361
362
363
364
365
366
367

368
369
370
371
372
373
374
...
400
401
402
403
404
405
406

407
408
409
410
411
412
413
414
415














































































416
417
418
419
420

421
422
423
424
425
426
427
428
429

430
431
432
433
434
435
436
...
466
467
468
469
470
471
472

473
474
475
476
477
478
479
480
481

482
483
484
485
486
487
488
489
490

491
492
493
494
495
496
497
...
530
531
532
533
534
535
536

537
538
539
540
541
542
543
544
545

546
547
548
549
550
551
552

553
554
555
556
557
558
559
560
561

562
563
564
565
566
567
568
...
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
635
636
637

638
639
640
641
642
643
644
...
683
684
685
686
687
688
689

690
691
692
693
694
695
696
697
698
699

700
701
702
703
704
705
706
...
743
744
745
746
747
748
749

750
751
752
753
754
755
756
757
758
759

760
761
762
763
764
765
766
...
790
791
792
793
794
795
796

797
798
799
800
801
802
803
...
828
829
830
831
832
833
834

835
836
837
838
839
840
841
...
872
873
874
875
876
877
878

879
880
881
882
883
884
885
...
909
910
911
912
913
914
915

916
917
918
919
920
921
922
....
1001
1002
1003
1004
1005
1006
1007

1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019

1020
1021
1022
1023
1024
1025
1026
1027

1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040

1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051

1052
1053
1054
1055
1056
1057
1058
....
1061
1062
1063
1064
1065
1066
1067

1068
1069
1070
1071
1072
1073
1074
....
1106
1107
1108
1109
1110
1111
1112

1113
1114
1115
1116
1117
1118
1119
....
1138
1139
1140
1141
1142
1143
1144

1145
1146
1147
1148
1149
1150
1151
....
1175
1176
1177
1178
1179
1180
1181








1182



















































































































                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
................................................................................
                                , { name = "dec"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "-"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "inc"
                                            , AST.Function emptyRange "inc"
................................................................................
                                [ { name = "int="
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [], NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Bool" [] ]
                                            }
                                  , sourceLocationRange = Nothing








































                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "-"
                                            , AST.Function emptyRange "zero?"
                                            ]
................................................................................
                                [ { name = ","
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [], NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "+"
                                            ]
                                  }
................................................................................
                                , { name = "add2"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 2
                                            , AST.Function emptyRange ","
                                            ]
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "True"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "as-int"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "True" [] ]
                                                , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.Integer emptyRange 1
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Person"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members =
                                            AST.StructMembers
                                                [ ( "age", LocalRef "Int" [] )
                                                , ( "jobs", LocalRef "Int" [] )
                                                ]
                                      }
................................................................................
                                    [ { name = "get-age"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "Person" [] ]
                                                , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.Function emptyRange "age>"
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Box"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" )
                                                ]
                                      }
                                    ]
................................................................................
                                    [ { name = ">Box"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.ConstructType "Box" ]
                                      }
                                    , { name = ">element"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| LocalRef "Box" [ Generic "a" ], NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.SetMember "Box" "element" ]
                                      }
                                    , { name = "element>"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                , output = [ NotStackRange <| Generic "a" ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.GetMember "Box" "element" ]
                                      }
                                    ]
                            }
                    in
































                    expectAst source expectedAst
            ]
        , test "Parser understands generic types" <|
            \_ ->
                let
                    source =
                        """
................................................................................
                                [ { name = "over"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| Generic "a", NotStackRange <| Generic "b" ]
                                            , output = [ NotStackRange <| Generic "a", NotStackRange <| Generic "b", NotStackRange <| Generic "a" ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "dup"
                                            , AST.Function emptyRange "rotate"
                                            ]
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Bool"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "True" []
                                                , LocalRef "False" []
                                                ]
                                      }
                                    , { name = "True"
                                      , sourceLocation = emptyRange














































































                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    , { name = "False"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "to-int"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Maybe"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ Generic "a"
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Generic "a") []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "MaybeBox"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "Box" [ Generic "a" ]
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Box"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" ) ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "MaybeBox"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "Box" [ Generic "a" ]
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Box"
                                      , sourceLocation = emptyRange

                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" ) ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange

                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "MaybeBox" [ Generic "a" ], NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| Generic "a" ]
                                                }
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                                                        { input = [ NotStackRange <| LocalRef "Int" [] ]
                                                        , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                        }
                                                ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "!"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.InlineFunction
                                                emptyRange
................................................................................
                                                        { input = [ StackRange "a" ]
                                                        , output = [ StackRange "b" ]
                                                        }
                                                ]
                                            , output = [ StackRange "b" ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "!"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.InlineFunction emptyRange
                                                [ AST.Integer emptyRange 1
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch
                                                        emptyRange
                                                        (LocalRef "Int" [])
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "List" [])
                                                        [ ( "tail"
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing

                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "Pair" [])
                                                        [ ( "first", AST.LiteralInt 0 )
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "some-array"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ArrayLiteral emptyRange
                                                [ AST.Integer emptyRange 1
                                                , AST.Integer emptyRange 2
................................................................................
                        , types =
                            Dict.fromListBy .name
                                [ { name = "Bool"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 2 1)
                                            (SourceLocation 6 1)

                                  , generics = []
                                  , members =
                                        AST.UnionMembers
                                            [ LocalRef "True" []
                                            , LocalRef "False" []
                                            ]
                                  }
                                , { name = "True"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 6 1)
                                            (SourceLocation 7 1)

                                  , generics = []
                                  , members = AST.StructMembers []
                                  }
                                , { name = "False"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 7 1)
                                            (SourceLocation 9 1)

                                  , generics = []
                                  , members = AST.StructMembers []
                                  }
                                ]
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "True"
                                  , typeSignature =
                                        AssociatedFunctionSignature.Verified
                                            { input = []
                                            , output = [ NotStackRange <| LocalRef "True" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation = SoloImpl [ ConstructType "True" ]
                                  }
                                , { name = "False"
                                  , typeSignature =
                                        AssociatedFunctionSignature.Verified
                                            { input = []
                                            , output = [ NotStackRange <| LocalRef "False" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation = SoloImpl [ ConstructType "False" ]
                                  }
                                , { name = "from-int"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
................................................................................
                                            }
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 9 1)
                                                (SourceLocation 16 1)
                                            )

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 11 3)
................................................................................
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 16 1)
                                                (SourceLocation 19 1)
                                            )

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ Function
                                                (SourceLocationRange
                                                    (SourceLocation 17 3)
................................................................................
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 19 1)
                                                (SourceLocation 23 1)
                                            )

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 20 3)
................................................................................
                in
                case compileRetainLocations source of
                    Err _ ->
                        Expect.fail "Did not expect compilation to fail."

                    Ok ast ->
                        Expect.equal expectedAst ast








        ]


























































































































>







 







>











>







 







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







 







>







 







>







 







>













>







 







>







 







>







 







>







 







>












>












>








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







 







>







 







>









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





>









>







 







>









>









>







 







>









>







>









>







 







>









>







>













>







 







>










>







 







>










>







 







>







 







>







 







>







 







>







 







>












>








>













>











>







 







>







 







>







 







>







 







>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
..
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
...
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
...
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
...
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
...
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
...
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
...
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
...
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
...
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
...
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
...
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
...
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
....
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
....
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
....
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
....
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
....
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
....
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
....
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
....
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
................................................................................
                                , { name = "dec"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "-"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "inc"
                                            , AST.Function emptyRange "inc"
................................................................................
                                [ { name = "int="
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [], NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Bool" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "-"
                                            , AST.Function emptyRange "zero?"
                                            ]
                                  }
                                ]
                        }
                in
                expectAst source expectedAst
        , test "Functions can have documentation strings" <|
            \_ ->
                let
                    source =
                        """
                        def: int=
                        type: Int Int -- Bool
                        doc: \"\"\"
                        A function that checks if two ints are the same
                        \"\"\"
                        : - zero?
                        """

                    expectedAst =
                        { sourceReference = ""
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "int="
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [], NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Bool" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = "A function that checks if two ints are the same"
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "-"
                                            , AST.Function emptyRange "zero?"
                                            ]
................................................................................
                                [ { name = ","
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [], NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "+"
                                            ]
                                  }
................................................................................
                                , { name = "add2"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            , output = [ NotStackRange <| AST.LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 2
                                            , AST.Function emptyRange ","
                                            ]
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "True"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "as-int"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "True" [] ]
                                                , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.Integer emptyRange 1
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Person"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members =
                                            AST.StructMembers
                                                [ ( "age", LocalRef "Int" [] )
                                                , ( "jobs", LocalRef "Int" [] )
                                                ]
                                      }
................................................................................
                                    [ { name = "get-age"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "Person" [] ]
                                                , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.Function emptyRange "age>"
                                                ]
                                      }
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Box"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" )
                                                ]
                                      }
                                    ]
................................................................................
                                    [ { name = ">Box"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.ConstructType "Box" ]
                                      }
                                    , { name = ">element"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| LocalRef "Box" [ Generic "a" ], NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.SetMember "Box" "element" ]
                                      }
                                    , { name = "element>"
                                      , typeSignature =
                                            AssociatedFunctionSignature.Verified
                                                { input = [ NotStackRange <| LocalRef "Box" [ Generic "a" ] ]
                                                , output = [ NotStackRange <| Generic "a" ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl [ AST.GetMember "Box" "element" ]
                                      }
                                    ]
                            }
                    in
                    expectAst source expectedAst
            , test "Documentation" <|
                \_ ->
                    let
                        source =
                            """
                            defstruct: Box a
                            doc: \"\"\"
                            Boxes a value
                            \"\"\"
                            : element a
                            """

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Box"
                                      , sourceLocation = emptyRange
                                      , documentation = "Boxes a value"
                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" )
                                                ]
                                      }
                                    ]
                            , functions = Dict.empty
                            }
                                |> addFunctionsForStructs
                    in
                    expectAst source expectedAst
            ]
        , test "Parser understands generic types" <|
            \_ ->
                let
                    source =
                        """
................................................................................
                                [ { name = "over"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| Generic "a", NotStackRange <| Generic "b" ]
                                            , output = [ NotStackRange <| Generic "a", NotStackRange <| Generic "b", NotStackRange <| Generic "a" ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "dup"
                                            , AST.Function emptyRange "rotate"
                                            ]
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Bool"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "True" []
                                                , LocalRef "False" []
                                                ]
                                      }
                                    , { name = "True"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    , { name = "False"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "to-int"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
                                                , ( TypeMatch emptyRange (LocalRef "False" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 0 ]
                                                  )
                                                ]
                                                []
                                      }
                                    ]
                            }
                                |> addFunctionsForStructs
                    in
                    expectAst source expectedAst
            , test "Can have documentation strings" <|
                \_ ->
                    let
                        source =
                            """
                            defunion: Bool
                            doc: \"\"\"
                            Short for boolean
                            \"\"\"
                            : True 
                            : False 

                            defstruct: True
                            defstruct: False

                            defmulti: to-int
                            doc: \"\"\"
                            Converts a boolean into an int
                            \"\"\"
                            : True
                              drop 1
                            : False
                              drop 0
                            """

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Bool"
                                      , sourceLocation = emptyRange
                                      , documentation = "Short for boolean"
                                      , generics = []
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "True" []
                                                , LocalRef "False" []
                                                ]
                                      }
                                    , { name = "True"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    , { name = "False"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "to-int"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = "Converts a boolean into an int"
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "True" []) []
                                                  , [ AST.Function emptyRange "drop", AST.Integer emptyRange 1 ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "Maybe"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ Generic "a"
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (Generic "a") []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "MaybeBox"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "Box" [ Generic "a" ]
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Box"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" ) ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types =
                                Dict.fromListBy .name
                                    [ { name = "MaybeBox"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.UnionMembers
                                                [ LocalRef "Box" [ Generic "a" ]
                                                , LocalRef "Nil" []
                                                ]
                                      }
                                    , { name = "Box"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = [ "a" ]
                                      , members =
                                            AST.StructMembers
                                                [ ( "element", Generic "a" ) ]
                                      }
                                    , { name = "Nil"
                                      , sourceLocation = emptyRange
                                      , documentation = ""
                                      , generics = []
                                      , members = AST.StructMembers []
                                      }
                                    ]
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "if-present"
                                      , typeSignature =
                                            AssociatedFunctionSignature.UserProvided
                                                { input = [ NotStackRange <| LocalRef "MaybeBox" [ Generic "a" ], NotStackRange <| Generic "a" ]
                                                , output = [ NotStackRange <| Generic "a" ]
                                                }
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange (LocalRef "Box" [ Generic "a" ]) []
                                                  , [ AST.Function emptyRange "!" ]
                                                  )
................................................................................
                                                        { input = [ NotStackRange <| LocalRef "Int" [] ]
                                                        , output = [ NotStackRange <| LocalRef "Int" [] ]
                                                        }
                                                ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "!"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.InlineFunction
                                                emptyRange
................................................................................
                                                        { input = [ StackRange "a" ]
                                                        , output = [ StackRange "b" ]
                                                        }
                                                ]
                                            , output = [ StackRange "b" ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "!"
                                            ]
                                  }
                                , { name = "main"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.InlineFunction emptyRange
                                                [ AST.Integer emptyRange 1
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "zero?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch
                                                        emptyRange
                                                        (LocalRef "Int" [])
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "pair?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "List" [])
                                                        [ ( "tail"
................................................................................
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "origo?"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            MultiImpl
                                                [ ( TypeMatch emptyRange
                                                        (LocalRef "Pair" [])
                                                        [ ( "first", AST.LiteralInt 0 )
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "some-array"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ArrayLiteral emptyRange
                                                [ AST.Integer emptyRange 1
                                                , AST.Integer emptyRange 2
................................................................................
                        , types =
                            Dict.fromListBy .name
                                [ { name = "Bool"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 2 1)
                                            (SourceLocation 6 1)
                                  , documentation = ""
                                  , generics = []
                                  , members =
                                        AST.UnionMembers
                                            [ LocalRef "True" []
                                            , LocalRef "False" []
                                            ]
                                  }
                                , { name = "True"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 6 1)
                                            (SourceLocation 7 1)
                                  , documentation = ""
                                  , generics = []
                                  , members = AST.StructMembers []
                                  }
                                , { name = "False"
                                  , sourceLocation =
                                        SourceLocationRange
                                            (SourceLocation 7 1)
                                            (SourceLocation 9 1)
                                  , documentation = ""
                                  , generics = []
                                  , members = AST.StructMembers []
                                  }
                                ]
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "True"
                                  , typeSignature =
                                        AssociatedFunctionSignature.Verified
                                            { input = []
                                            , output = [ NotStackRange <| LocalRef "True" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation = SoloImpl [ ConstructType "True" ]
                                  }
                                , { name = "False"
                                  , typeSignature =
                                        AssociatedFunctionSignature.Verified
                                            { input = []
                                            , output = [ NotStackRange <| LocalRef "False" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation = SoloImpl [ ConstructType "False" ]
                                  }
                                , { name = "from-int"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
................................................................................
                                            }
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 9 1)
                                                (SourceLocation 16 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 11 3)
................................................................................
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 16 1)
                                                (SourceLocation 19 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ Function
                                                (SourceLocationRange
                                                    (SourceLocation 17 3)
................................................................................
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange =
                                        Just
                                            (SourceLocationRange
                                                (SourceLocation 19 1)
                                                (SourceLocation 23 1)
                                            )
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch
                                                    (SourceLocationRange
                                                        (SourceLocation 20 3)
................................................................................
                in
                case compileRetainLocations source of
                    Err _ ->
                        Expect.fail "Did not expect compilation to fail."

                    Ok ast ->
                        Expect.equal expectedAst ast
        , describe "Strings" <|
            let
                expectParseString input output =
                    let
                        source =
                            """
                            def: str
                            : """ ++ "\"" ++ input ++ "\""

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "str"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.StringLiteral emptyRange output
                                                ]
                                      }
                                    ]
                            }
                    in
                    expectAst source expectedAst
            in
            [ test "Simple case" <|
                \_ ->
                    expectParseString
                        "This is a test"
                        "This is a test"
            , test "Empty string" <|
                \_ ->
                    expectParseString
                        ""
                        ""
            , test "Newline escape sequence" <|
                \_ ->
                    expectParseString
                        "This is a test with\\n a newline"
                        "This is a test with\n a newline"
            , test "Tab escape sequence" <|
                \_ ->
                    expectParseString
                        "This is a test with\\t a tab"
                        "This is a test with\t a tab"
            , test "Backslash escape sequence" <|
                \_ ->
                    expectParseString
                        "This is a test with\\\\ a backslash"
                        "This is a test with\\ a backslash"
            , test "Double-quote escape sequence" <|
                \_ ->
                    expectParseString
                        "This is a \\\"test\\\" with a double quote"
                        "This is a \"test\" with a double quote"
            ]
        , describe "Multiline strings" <|
            let
                expectParseString input output =
                    let
                        source =
                            """
                            def: str
                            : """ ++ "\"\"\"" ++ input ++ "\"\"\""

                        expectedAst =
                            { sourceReference = ""
                            , moduleDefinition = ModuleDefinition.Undefined
                            , types = Dict.empty
                            , functions =
                                Dict.fromListBy .name
                                    [ { name = "str"
                                      , typeSignature = AssociatedFunctionSignature.NotProvided
                                      , sourceLocationRange = Nothing
                                      , documentation = ""
                                      , aliases = Dict.empty
                                      , imports = Dict.empty
                                      , implementation =
                                            SoloImpl
                                                [ AST.StringLiteral emptyRange output
                                                ]
                                      }
                                    ]
                            }
                    in
                    expectAst source expectedAst
            in
            [ test "Simple case" <|
                \_ ->
                    expectParseString
                        "This is a test"
                        "This is a test"
            , test "Empty multiline string" <|
                \_ ->
                    expectParseString
                        ""
                        ""
            , test "There are no escape sequences" <|
                \_ ->
                    expectParseString
                        "This is a test with\\n a newline escape sequence"
                        "This is a test with\\n a newline escape sequence"
            , test "Actual multiline" <|
                \_ ->
                    expectParseString
                        "\n    This is a test\n      with some indentation\n    Let's see how it turns out\n"
                        "This is a test\n  with some indentation\nLet's see how it turns out"
            , test "Above test using Elm's multiline" <|
                \_ ->
                    expectParseString
                        """
                        This is a test
                          with some indentation
                        Let's see how it turns out
                        """
                        "This is a test\n  with some indentation\nLet's see how it turns out"
            ]
        ]

Modified tests/Test/Parser/Errors.elm from [02d836c7d4] to [a51137eb07].

263
264
265
266
267
268
269





















































270
271
272
273
274
275
276
                        source =
                            """
                            test
                            """
                    in
                    checkForError (badDefinition "test") source
            ]





















































        ]


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







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







263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
                        source =
                            """
                            test
                            """
                    in
                    checkForError (badDefinition "test") source
            ]
        , describe "Strings" <|
            let
                unknownEscapeSequence expected problem =
                    case problem of
                        UnknownEscapeSequence actual ->
                            actual == expected

                        _ ->
                            False

                stringNotTerminated problem =
                    problem == StringNotTerminated
            in
            [ test "Unknown escape sequence" <|
                \_ ->
                    let
                        source =
                            """
                            def: src
                            : "bad \\u"
                            """
                    in
                    checkForError (unknownEscapeSequence "\\u") source
            , test "Newline before terminating string" <|
                \_ ->
                    let
                        source =
                            """
                            def: src
                            : "bad 
                              string"
                            """
                    in
                    checkForError stringNotTerminated source
            , test "String never terminates" <|
                \_ ->
                    let
                        source =
                            """
                           def: src
                           : "bad string"""
                    in
                    checkForError stringNotTerminated source
            , test "Multiline string never terminates" <|
                \_ ->
                    let
                        source =
                            """
                           def: src
                           : \"\"\"bad string"""
                    in
                    checkForError stringNotTerminated source
            ]
        ]


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

Modified tests/Test/Parser/ModuleDefinition.elm from [8a3ead45b0] to [74c103f02d].

1
2
3
4
5
6
7
8
..
53
54
55
56
57
58
59

60
61
62
63
64

65
66
67
68
69
70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
85
86
87
88















































89
90
91
92
93
94
95
...
107
108
109
110
111
112
113

114
115
116
117
118
119
120
...
155
156
157
158
159
160
161

162
163
164
165
166
167
168
...
199
200
201
202
203
204
205

206
207
208
209
210
211
212
213
214
215
216
module Test.Parser.ModuleDefinition exposing (..)

import Dict
import Dict.Extra as Dict
import Set
import Stabel.Parser as AST exposing (..)
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature
import Stabel.Parser.ModuleDefinition as ModuleDefinition
................................................................................
                                , imports =
                                    Dict.fromList
                                        [ ( "/some/other/mod", [ "test1", "word2" ] )
                                        , ( "internals", [ "foo" ] )
                                        , ( "internal/mod", [] )
                                        ]
                                , exposes = Set.fromList [ "inc" ]

                                }
                        , types =
                            Dict.fromListBy .name
                                [ { name = "Pair"
                                  , sourceLocation = emptyRange

                                  , generics = [ "a", "b" ]
                                  , members =
                                        AST.StructMembers
                                            [ ( "first", Generic "a" )
                                            , ( "second", Generic "b" )
                                            ]
                                  }
                                ]
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
                                  }
                                ]
                        }
                            |> addFunctionsForStructs















































                in
                expectAst source expectedAst
        , test "Functions can have its own aliases and imports" <|
            \_ ->
                let
                    source =
                        """
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases =
                                        Dict.fromList
                                            [ ( "other", "/some/mod" )
                                            , ( "moar", "local/mod" )
                                            ]
                                  , imports =
                                        Dict.fromList
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "with-default"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases =
                                        Dict.fromList
                                            [ ( "other", "/some/mod" )
                                            , ( "moar", "local/mod" )
                                            ]
                                  , imports =
                                        Dict.fromList
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ExternalFunction emptyRange [ "ext" ] "fn1" ]
                                  }
                                ]
                        }
                in
                expectAst source expectedAst
        ]
|







 







>





>













>











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







 







>







 







>







 







>











1
2
3
4
5
6
7
8
..
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
...
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
module Test.Parser.ModuleDefinition exposing (suite)

import Dict
import Dict.Extra as Dict
import Set
import Stabel.Parser as AST exposing (..)
import Stabel.Parser.AssociatedFunctionSignature as AssociatedFunctionSignature
import Stabel.Parser.ModuleDefinition as ModuleDefinition
................................................................................
                                , imports =
                                    Dict.fromList
                                        [ ( "/some/other/mod", [ "test1", "word2" ] )
                                        , ( "internals", [ "foo" ] )
                                        , ( "internal/mod", [] )
                                        ]
                                , exposes = Set.fromList [ "inc" ]
                                , documentation = ""
                                }
                        , types =
                            Dict.fromListBy .name
                                [ { name = "Pair"
                                  , sourceLocation = emptyRange
                                  , documentation = ""
                                  , generics = [ "a", "b" ]
                                  , members =
                                        AST.StructMembers
                                            [ ( "first", Generic "a" )
                                            , ( "second", Generic "b" )
                                            ]
                                  }
                                ]
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
                                  }
                                ]
                        }
                            |> addFunctionsForStructs
                in
                expectAst source expectedAst
        , test "Documentation string" <|
            \_ ->
                let
                    source =
                        """
                        defmodule:
                        doc: \"\"\"
                        A module for dealing with numbers
                        \"\"\"
                        exposing: inc
                        :

                        def: inc
                        : 1 +
                        """

                    expectedAst =
                        { sourceReference = ""
                        , moduleDefinition =
                            ModuleDefinition.Defined
                                { aliases =
                                    Dict.fromList []
                                , imports =
                                    Dict.fromList
                                        []
                                , exposes = Set.fromList [ "inc" ]
                                , documentation = "A module for dealing with numbers"
                                }
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Integer emptyRange 1
                                            , AST.Function emptyRange "+"
                                            ]
                                  }
                                ]
                        }
                in
                expectAst source expectedAst
        , test "Functions can have its own aliases and imports" <|
            \_ ->
                let
                    source =
                        """
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "inc"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases =
                                        Dict.fromList
                                            [ ( "other", "/some/mod" )
                                            , ( "moar", "local/mod" )
                                            ]
                                  , imports =
                                        Dict.fromList
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "with-default"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases =
                                        Dict.fromList
                                            [ ( "other", "/some/mod" )
                                            , ( "moar", "local/mod" )
                                            ]
                                  , imports =
                                        Dict.fromList
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ExternalFunction emptyRange [ "ext" ] "fn1" ]
                                  }
                                ]
                        }
                in
                expectAst source expectedAst
        ]

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

28
29
30
31
32
33
34

35
36
37
38
39
40
41
..
56
57
58
59
60
61
62

63
64
65
66
67
68
69
..
84
85
86
87
88
89
90

91
92
93
94
95
96
97
...
119
120
121
122
123
124
125

126
127
128
129
130
131
132
...
154
155
156
157
158
159
160

161
162
163
164
165
166
167
...
192
193
194
195
196
197
198

199
200
201
202
203
204
205
...
236
237
238
239
240
241
242

243
244
245
246
247
248
249
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.PackageFunction emptyRange [ "some", "module" ] "sample" ]
                                  }
                                ]
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ExternalFunction emptyRange [ "some", "module" ] "sample" ]
                                  }
                                ]
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.PackageFunction emptyRange [ "internal" ] "sample"
                                            , AST.ExternalFunction emptyRange [ "some", "module" ] "sample"
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| InternalRef [ "internal" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 1
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| ExternalRef [ "external" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 1
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| ExternalRef [ "external" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (ExternalRef [ "external" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| InternalRef [ "internal" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing

                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (InternalRef [ "internal" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1







>







 







>







 







>







 







>







 







>







 







>







 







>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.PackageFunction emptyRange [ "some", "module" ] "sample" ]
                                  }
                                ]
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.ExternalFunction emptyRange [ "some", "module" ] "sample" ]
                                  }
                                ]
................................................................................
                        , moduleDefinition = ModuleDefinition.Undefined
                        , types = Dict.empty
                        , functions =
                            Dict.fromListBy .name
                                [ { name = "test"
                                  , typeSignature = AssociatedFunctionSignature.NotProvided
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.PackageFunction emptyRange [ "internal" ] "sample"
                                            , AST.ExternalFunction emptyRange [ "some", "module" ] "sample"
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| InternalRef [ "internal" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 1
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| ExternalRef [ "external" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        SoloImpl
                                            [ AST.Function emptyRange "drop"
                                            , AST.Integer emptyRange 1
                                            ]
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| ExternalRef [ "external" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (ExternalRef [ "external" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1
................................................................................
                                [ { name = "test"
                                  , typeSignature =
                                        AssociatedFunctionSignature.UserProvided
                                            { input = [ NotStackRange <| InternalRef [ "internal" ] "Tipe" [] ]
                                            , output = [ NotStackRange <| LocalRef "Int" [] ]
                                            }
                                  , sourceLocationRange = Nothing
                                  , documentation = ""
                                  , aliases = Dict.empty
                                  , imports = Dict.empty
                                  , implementation =
                                        MultiImpl
                                            [ ( TypeMatch emptyRange (InternalRef [ "internal" ] "Tipe" []) [ ( "value", LiteralInt 1 ) ]
                                              , [ AST.Function emptyRange "drop"
                                                , AST.Integer emptyRange 1

Modified tests/Test/Parser/Util.elm from [38c3a75d10] to [c45a582fc9].

81
82
83
84
85
86
87



88
89
90
91
92
93
94
...
144
145
146
147
148
149
150

151
152
153
154
155
156
157
...
160
161
162
163
164
165
166

167
168
169
170
171
172
173
...
177
178
179
180
181
182
183

184
185
186
187
188
189
190

        AST.InlineFunction _ val ->
            AST.InlineFunction emptyRange (List.map stripNodeLocation val)

        AST.ArrayLiteral _ val ->
            AST.ArrayLiteral emptyRange (List.map stripNodeLocation val)




        _ ->
            node


stripMultiWordBranchLocation : ( TypeMatch, List AstNode ) -> ( TypeMatch, List AstNode )
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch
................................................................................
                    ">" ++ name
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = List.map (NotStackRange << Tuple.second) members
                    , output = [ selfType ]
                    }
            , sourceLocationRange = Nothing

            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =
            List.map settersHelper members
................................................................................
            { name = ">" ++ memberName
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = [ selfType, NotStackRange type_ ]
                    , output = [ selfType ]
                    }
            , sourceLocationRange = Nothing

            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation =
                AST.SoloImpl [ AST.SetMember name memberName ]
            }

        getters =
................................................................................
            { name = memberName ++ ">"
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = [ selfType ]
                    , output = [ NotStackRange type_ ]
                    }
            , sourceLocationRange = Nothing

            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation =
                AST.SoloImpl [ AST.GetMember name memberName ]
            }

        allFuncs =







>
>
>







 







>







 







>







 







>







81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
...
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196

        AST.InlineFunction _ val ->
            AST.InlineFunction emptyRange (List.map stripNodeLocation val)

        AST.ArrayLiteral _ val ->
            AST.ArrayLiteral emptyRange (List.map stripNodeLocation val)

        AST.StringLiteral _ val ->
            AST.StringLiteral emptyRange val

        _ ->
            node


stripMultiWordBranchLocation : ( TypeMatch, List AstNode ) -> ( TypeMatch, List AstNode )
stripMultiWordBranchLocation ( typeMatch, nodes ) =
    ( stripTypeMatchLocation typeMatch
................................................................................
                    ">" ++ name
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = List.map (NotStackRange << Tuple.second) members
                    , output = [ selfType ]
                    }
            , sourceLocationRange = Nothing
            , documentation = ""
            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation = AST.SoloImpl [ AST.ConstructType name ]
            }

        setters =
            List.map settersHelper members
................................................................................
            { name = ">" ++ memberName
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = [ selfType, NotStackRange type_ ]
                    , output = [ selfType ]
                    }
            , sourceLocationRange = Nothing
            , documentation = ""
            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation =
                AST.SoloImpl [ AST.SetMember name memberName ]
            }

        getters =
................................................................................
            { name = memberName ++ ">"
            , typeSignature =
                AssociatedFunctionSignature.Verified
                    { input = [ selfType ]
                    , output = [ NotStackRange type_ ]
                    }
            , sourceLocationRange = Nothing
            , documentation = ""
            , aliases = Dict.empty
            , imports = Dict.empty
            , implementation =
                AST.SoloImpl [ AST.GetMember name memberName ]
            }

        allFuncs =

Modified wasm_tests/compiler.wrapper.js from [897ec18e2b] to [86e63f9b44].

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
48
49
50
51
52
53
54































55
56
57
58
59
60
61
..
81
82
83
84
85
86
87





















88
89
90
91
92
93
94
            } else {
                reject(output);
            }
        });
    });
}

exports.toProjectWat = function toWat(payload) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileProject',
                entryPoint: payload.entryPoint,
                modules: payload.modules.map((mod) => {
                    mod.source = stripIndent(mod.source)
................................................................................
                resolve(output);
            } else {
                reject(output);
            }
        });
    });
}
































exports.run = async function run(wat, functionName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat, {
        bulk_memory: true
    }).toBinary({}).buffer;

................................................................................
    }

    stackElement(index) {
        // The first three I32 positions are used for stack and heap information
        // The fourth position is the first element of the stack
        return this.memoryView[3 + (index || 0)];
    }






















    typeIdForPointer(index) {
        const pointer = this.stackElement(index || 0);
        const wordPointer = pointer / 4;
        return this.memoryView[wordPointer];
    }
}







|







 







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







 







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







22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
            } else {
                reject(output);
            }
        });
    });
}

function toProjectWat(payload) {
    return new Promise((resolve, reject) => {
        const compiler = Compiler.Elm.TestCompiler.init({
            flags: {
                __type: 'CompileProject',
                entryPoint: payload.entryPoint,
                modules: payload.modules.map((mod) => {
                    mod.source = stripIndent(mod.source)
................................................................................
                resolve(output);
            } else {
                reject(output);
            }
        });
    });
}

exports.toProjectWat = toProjectWat;

exports.toStringWat = function toStringWat(entry, sourceCode) {
    return toProjectWat({
        entryPoint: `/author/sample/core/${entry}`,
        modules: [
            {
                package: 'stabel/standard_library',
                module: 'string',
                source: `
                    defmodule:
                    exposing: String from-bytes
                    :

                    defstruct: String
                    : content Array Int

                    def: from-bytes
                    type: (Array Int) -- String
                    : >String
                `
            },
            {
                package: 'author/sample',
                module: 'core',
                source: stripIndent(sourceCode)
            }
        ]
    });
}

exports.run = async function run(wat, functionName) {
    const wabt = await wabtInit();
    const wasmModule = wabt.parseWat('tmp', wat, {
        bulk_memory: true
    }).toBinary({}).buffer;

................................................................................
    }

    stackElement(index) {
        // The first three I32 positions are used for stack and heap information
        // The fourth position is the first element of the stack
        return this.memoryView[3 + (index || 0)];
    }

    stringElement(index) {
        // String structure => typeId | array 
        const strPointer = this.stackElement(index || 0);
        const strOffset = strPointer / 4;

        const arrayPointer = this.memoryView[strOffset + 1];
        const arrayOffset = arrayPointer / 4;

        const strLen = this.memoryView[arrayOffset];

        const content = [];
        const strValueOffset = arrayOffset + 1;
        for (let i = 0; i < strLen; i++) {
            content.push(this.memoryView[strValueOffset + i]);
        }

        const decoder = new TextDecoder();
        const strAsUtf8 = new Uint8Array(content);
        return decoder.decode(strAsUtf8);
    }

    typeIdForPointer(index) {
        const pointer = this.stackElement(index || 0);
        const wordPointer = pointer / 4;
        return this.memoryView[wordPointer];
    }
}

Added wasm_tests/string.test.js version [5d3dbc07b2].











































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const compiler = require('./compiler.wrapper');

test('Empty', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : ""
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("");
});

test('Sample', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : "This is a test"
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("This is a test");
});

test('Emoji', async () => {
    const wat = await compiler.toStringWat('main', `
        def: main
        type: -- /string/String
        : "💩"
    `);

    const result = await compiler.run(wat, '/author/sample/core/main');

    expect(result.stringElement()).toBe("💩");
});