Stabel

Check-in [6fd8ec29cf]
Login
Overview
Comment:Fixed bug where reliance on string module was not inferred when encountering a string literal.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 6fd8ec29cfd5989c75c4227c1c3bf41a0878529564bf29192d3cc123af2c0b7c
User & Date: robin.hansen on 2021-09-09 10:58:18
Other Links: manifest | tags
Context
2021-09-09
11:08
A default function to be executed with 'stabel run' can now be specified in the stabel.json file. check-in: f465c04492 user: robin.hansen tags: trunk
10:58
Fixed bug where reliance on string module was not inferred when encountering a string literal. check-in: 6fd8ec29cf user: robin.hansen tags: trunk
10:46
It is now possible to write Stabel programs that return a string. check-in: 2f5dcec13a user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/CLI.elm from [9ea3e5c648] to [5956d7ecf1].

142
143
144
145
146
147
148
149
150
151



152

153


154
155
156
157
158
159
160
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
legalIntEntryPointType : Type.FunctionType
legalIntEntryPointType =
    { input = []
    , output = [ Type.Int ]
    }


legalStringEntryPointType : Type.FunctionType
legalStringEntryPointType =
    { input = []



    , output = [ Type.Custom "/stabel/standard_library/string/String" ]

    }




typeCheckAndRun :
    Maybe String
    -> Qualifier.AST
    -> Result ( List String, List TypeCheckerProblem.Problem ) ( String, Bool )
typeCheckAndRun entryPoint qualifiedAst =
................................................................................
                Just fn ->
                    if fn.type_ == legalIntEntryPointType then
                        typedAst
                            |> Codegen.run exportedFunctions
                            |> Wasm.toString
                            |> (\wat -> Ok ( wat, False ))

                    else if fn.type_ == legalStringEntryPointType then
                        typedAst
                            |> Codegen.run exportedFunctions
                            |> Wasm.toString
                            |> (\wat -> Ok ( wat, True ))

                    else
                        let







|
|
|
>
>
>
|
>
|
>
>







 







|







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
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
legalIntEntryPointType : Type.FunctionType
legalIntEntryPointType =
    { input = []
    , output = [ Type.Int ]
    }


legalStringEntryPointType : Type.FunctionType -> Bool
legalStringEntryPointType fnType =
    case ( fnType.input, fnType.output ) of
        ( [ Type.StackRange _ ], [ Type.Custom "/stabel/standard_library/string/String" ] ) ->
            True

        ( [], [ Type.Custom "/stabel/standard_library/string/String" ] ) ->
            True

        _ ->
            False


typeCheckAndRun :
    Maybe String
    -> Qualifier.AST
    -> Result ( List String, List TypeCheckerProblem.Problem ) ( String, Bool )
typeCheckAndRun entryPoint qualifiedAst =
................................................................................
                Just fn ->
                    if fn.type_ == legalIntEntryPointType then
                        typedAst
                            |> Codegen.run exportedFunctions
                            |> Wasm.toString
                            |> (\wat -> Ok ( wat, False ))

                    else if legalStringEntryPointType fn.type_ then
                        typedAst
                            |> Codegen.run exportedFunctions
                            |> Wasm.toString
                            |> (\wat -> Ok ( wat, True ))

                    else
                        let

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

1796
1797
1798
1799
1800
1801
1802



1803
1804
1805
                    Just potentialAlias

        Parser.PackageFunction _ path _ ->
            Just (String.join "/" path)

        Parser.ExternalFunction _ path _ ->
            Just ("/" ++ String.join "/" path)




        _ ->
            Nothing







>
>
>



1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
                    Just potentialAlias

        Parser.PackageFunction _ path _ ->
            Just (String.join "/" path)

        Parser.ExternalFunction _ path _ ->
            Just ("/" ++ String.join "/" path)

        Parser.StringLiteral _ _ ->
            Just "/string"

        _ ->
            Nothing

Modified tests/Test/Qualifier.elm from [517b02c243] to [9aef3f3120].

446
447
448
449
450
451
452



453
454
455
456
457
458
459
...
461
462
463
464
465
466
467

468
469
470
471
472
473
474
...
482
483
484
485
486
487
488

489
490
491
492
493
494
495
                        def: main
                        alias: ali internal/alias
                        import: /list/of/names one
                        : html/div
                          call-external
                          /some/ext/word
                          ali/word1



                        """

                    expectedRequiredModules =
                        Set.fromList
                            [ "/robheghan/dummy/list/of/names"
                            , "/robheghan/dummy/some/ext"
                            , "/robheghan/html/external/html"
................................................................................
                            , "/robheghan/html/external/types"
                            , "/robheghan/html/external/double"
                            , "/package/test/internal/alias"
                            , "/package/test/internal/types"
                            , "/package/test/internal/match"
                            , "/package/test/package/module"
                            , "/stabel/standard_library/core"

                            ]
                in
                case Parser.run "test" source of
                    Err errors ->
                        Expect.fail <| "Parser error: " ++ Debug.toString errors

                    Ok parserAst ->
................................................................................
                                            [ ( "/list/of/names", "robheghan/dummy" )
                                            , ( "/some/ext", "robheghan/dummy" )
                                            , ( "/external/html", "robheghan/html" )
                                            , ( "/external/module", "robheghan/html" )
                                            , ( "/external/types", "robheghan/html" )
                                            , ( "/external/double", "robheghan/html" )
                                            , ( "/core", "stabel/standard_library" )

                                            ]
                                    }
                        in
                        Expect.equal expectedRequiredModules actualRequiredModules
        , test "Reliance on standard_library/core only when standard_library is specified as externalModule" <|
            \_ ->
                let







>
>
>







 







>







 







>







446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
...
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
...
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
                        def: main
                        alias: ali internal/alias
                        import: /list/of/names one
                        : html/div
                          call-external
                          /some/ext/word
                          ali/word1

                        def: string-hello
                        : "hello"
                        """

                    expectedRequiredModules =
                        Set.fromList
                            [ "/robheghan/dummy/list/of/names"
                            , "/robheghan/dummy/some/ext"
                            , "/robheghan/html/external/html"
................................................................................
                            , "/robheghan/html/external/types"
                            , "/robheghan/html/external/double"
                            , "/package/test/internal/alias"
                            , "/package/test/internal/types"
                            , "/package/test/internal/match"
                            , "/package/test/package/module"
                            , "/stabel/standard_library/core"
                            , "/stabel/standard_library/string"
                            ]
                in
                case Parser.run "test" source of
                    Err errors ->
                        Expect.fail <| "Parser error: " ++ Debug.toString errors

                    Ok parserAst ->
................................................................................
                                            [ ( "/list/of/names", "robheghan/dummy" )
                                            , ( "/some/ext", "robheghan/dummy" )
                                            , ( "/external/html", "robheghan/html" )
                                            , ( "/external/module", "robheghan/html" )
                                            , ( "/external/types", "robheghan/html" )
                                            , ( "/external/double", "robheghan/html" )
                                            , ( "/core", "stabel/standard_library" )
                                            , ( "/string", "stabel/standard_library" )
                                            ]
                                    }
                        in
                        Expect.equal expectedRequiredModules actualRequiredModules
        , test "Reliance on standard_library/core only when standard_library is specified as externalModule" <|
            \_ ->
                let