Play

Check-in [695ec5f34b]
Login
Overview
Comment:cli.js <-> CLI.elm interop completed, but there seems to be a bug in the parser that needs to be fixed.
Timelines: family | ancestors | descendants | both | cli
Files: files | file ages | folders
SHA3-256: 695ec5f34bcb1406a4117f06bf57d7ccda54420bba2517f98ff7a6eaa4e31690
User & Date: robin.hansen on 2021-04-02 12:37:55
Other Links: branch diff | manifest | tags
Context
2021-04-03
07:29
Fixed bug when parsing words which could result in two words being interpreted as one. check-in: ec17f65074 user: robin.hansen tags: cli
2021-04-02
12:37
cli.js <-> CLI.elm interop completed, but there seems to be a bug in the parser that needs to be fix... check-in: 695ec5f34b user: robin.hansen tags: cli
2021-03-31
14:45
Initial work on cli.js <-> CLI.elm interop. Works fine, just need to implement missing messages. check-in: 4712590b0f user: robin.hansen tags: cli
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified bin/cli.js from [a530aa6713] to [6acf0f0708].

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
42
43
44
45
46
47
48
49
function compileProject() {
    const cwd = process.cwd();
    const compiler = require(__dirname + "/compiler").Elm.CLI.init({
        flags: cwd
    });

    compiler.ports.outgoingPort.subscribe((msg) => {
        console.log(msg);
        switch (msg.type) {
            case 'readFile':
                const filePath = path.join(msg.path, msg.fileName);
                const fileContent = fs.readFileSync(filePath, { encoding: "utf-8" });

                compiler.ports.incomingPort.send({
                    type: "fileContents",
                    path: msg.path,
                    fileName: msg.fileName,
                    content: fileContent
                });
                break;



























            default:
                console.error("Unknown message received from Elm compiler: ", msg);
                break;
        }
    });
}





















function printHelp() {
    console.log(`
Play compiler. Alpha-2.

Possible options are:
* compile: compile the project.
* help: print this help message.
    `);
}







<












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






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










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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function compileProject() {
    const cwd = process.cwd();
    const compiler = require(__dirname + "/compiler").Elm.CLI.init({
        flags: cwd
    });

    compiler.ports.outgoingPort.subscribe((msg) => {

        switch (msg.type) {
            case 'readFile':
                const filePath = path.join(msg.path, msg.fileName);
                const fileContent = fs.readFileSync(filePath, { encoding: "utf-8" });

                compiler.ports.incomingPort.send({
                    type: "fileContents",
                    path: msg.path,
                    fileName: msg.fileName,
                    content: fileContent
                });
                break;
            case "resolvePackageModules":
                const srcPath = path.join(msg.path, "src");
                const childrenFiles = expandDir(msg.path)("src")
                    .filter(name => name.endsWith(".play"))
                    .map(name => name.replace(srcPath + "/", ""));

                compiler.ports.incomingPort.send({
                    type: "resolvedPackageModules",
                    package: msg.package,
                    modules: childrenFiles
                });
                break;
            case "resolveDirectories":
                const subFolders = packageDirs(msg.path);

                compiler.ports.incomingPort.send({
                    type: "resolvedDirectories",
                    parentDir: msg.path,
                    paths: subFolders
                });
                break;
            case "compilationDone":
                console.log("Compiled successfully");
                break;
            case "compilationFailure":
                console.error(msg.error);
                break;
            default:
                console.error("Unknown message received from Elm compiler: ", msg);
                break;
        }
    });
}

function expandDir(basePath) {
    return (dirPath) => {
        const srcPath = path.join(basePath, dirPath);

        if (fs.statSync(srcPath).isFile()) {
            return srcPath;
        }

        const children = fs.readdirSync(srcPath);
        return children.flatMap(expandDir(srcPath));
    };
}

function packageDirs(parentDir) {
    return fs.readdirSync(parentDir)
        .map(dir => path.join(parentDir, dir))
        .filter(dir => fs.statSync(dir).isDirectory())
        .filter(dir => fs.readdirSync(dir).indexOf('play.json') >= 0);
}

function printHelp() {
    console.log(`
Play compiler. Alpha-2.

Possible options are:
* compile: compile the project.
* help: print this help message.
    `);
}

Modified src/CLI.elm from [6db0dd20b5] to [11905a4a5e].

1
2
3
4
5
6

7
8
9
10
11
12
13
14
15
16
17
18
..
55
56
57
58
59
60
61
62
63

























64
65
66
67
68
69
70
71
72
73
...
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
port module CLI exposing (main)

import Json.Decode as Json
import Json.Encode as Encode
import Platform exposing (Program)
import Play.Codegen as Codegen

import Play.PackageLoader as PackageLoader
import Play.Parser as Parser
import Play.Parser.Problem as ParserProblem
import Play.Qualifier as Qualifier
import Play.Qualifier.Problem as QualifierProblem
import Play.TypeChecker as TypeChecker
import Play.TypeChecker.Problem as TypeCheckerProblem
import Wasm


type alias Model =
    PackageLoader.Model
................................................................................
    case msg of
        Incomming packageLoaderMsgJson ->
            case Json.decodeValue decodePackageLoaderMsg packageLoaderMsgJson of
                Ok packageLoaderMsg ->
                    let
                        updatedModel =
                            PackageLoader.update packageLoaderMsg model
                                |> Debug.log "new model"
                    in

























                    ( updatedModel
                    , sendSideEffectFromModel updatedModel
                    )

                Err decodeError ->
                    let
                        _ =
                            Debug.log "error" decodeError
                    in
                    ( model
................................................................................
                [ ( "type", Encode.string "resolveDirectories" )
                , ( "path", Encode.string path )
                ]

        PackageLoader.ResolvePackageModules moduleName path ->
            Encode.object
                [ ( "type", Encode.string "resolvePackageModules" )
                , ( "module", Encode.string moduleName )
                , ( "path", Encode.string path )
                ]


















decodePackageLoaderMsg : Json.Decoder PackageLoader.Msg
decodePackageLoaderMsg =
    let
        helper typeStr =
            case typeStr of
                "fileContents" ->
                    Json.map3 PackageLoader.FileContents
                        (Json.field "path" Json.string)
                        (Json.field "fileName" Json.string)
                        (Json.field "content" Json.string)











                _ ->
                    Json.fail <| "Unknown msg type: " ++ typeStr



    in
    Json.field "type" Json.string
        |> Json.andThen helper



-- PORTS






>

<
<
<
<







 







<

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







 







|



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












>
>
>
>
>
>
>
>
>
>


>
>
>







1
2
3
4
5
6
7
8




9
10
11
12
13
14
15
..
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
93
94
...
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
port module CLI exposing (main)

import Json.Decode as Json
import Json.Encode as Encode
import Platform exposing (Program)
import Play.Codegen as Codegen
import Play.Data.PackagePath as PackagePath
import Play.PackageLoader as PackageLoader




import Play.TypeChecker as TypeChecker
import Play.TypeChecker.Problem as TypeCheckerProblem
import Wasm


type alias Model =
    PackageLoader.Model
................................................................................
    case msg of
        Incomming packageLoaderMsgJson ->
            case Json.decodeValue decodePackageLoaderMsg packageLoaderMsgJson of
                Ok packageLoaderMsg ->
                    let
                        updatedModel =
                            PackageLoader.update packageLoaderMsg model

                    in
                    case updatedModel of
                        PackageLoader.Done qualifiedAst ->
                            let
                                compilationResult =
                                    case TypeChecker.run (Debug.log "ast" qualifiedAst) of
                                        Err typeErrors ->
                                            formatErrors (TypeCheckerProblem.toString "") typeErrors

                                        Ok typedAst ->
                                            Codegen.codegen typedAst
                                                |> Result.mapError (always "compfail")
                                                |> Result.map Wasm.toString
                            in
                            case compilationResult of
                                Ok wast ->
                                    ( model
                                    , outgoingPort <| encodeCompilationDone wast
                                    )

                                Err error ->
                                    ( model
                                    , outgoingPort <| encodeCompilationFailure error
                                    )

                        _ ->
                            ( updatedModel
                            , sendSideEffectFromModel updatedModel
                            )

                Err decodeError ->
                    let
                        _ =
                            Debug.log "error" decodeError
                    in
                    ( model
................................................................................
                [ ( "type", Encode.string "resolveDirectories" )
                , ( "path", Encode.string path )
                ]

        PackageLoader.ResolvePackageModules moduleName path ->
            Encode.object
                [ ( "type", Encode.string "resolvePackageModules" )
                , ( "package", Encode.string moduleName )
                , ( "path", Encode.string path )
                ]


encodeCompilationDone : String -> Json.Value
encodeCompilationDone wast =
    Encode.object
        [ ( "type", Encode.string "compilationDone" )
        , ( "wast", Encode.string wast )
        ]


encodeCompilationFailure : String -> Json.Value
encodeCompilationFailure errorMsg =
    Encode.object
        [ ( "type", Encode.string "compilationFailure" )
        , ( "error", Encode.string errorMsg )
        ]


decodePackageLoaderMsg : Json.Decoder PackageLoader.Msg
decodePackageLoaderMsg =
    let
        helper typeStr =
            case typeStr of
                "fileContents" ->
                    Json.map3 PackageLoader.FileContents
                        (Json.field "path" Json.string)
                        (Json.field "fileName" Json.string)
                        (Json.field "content" Json.string)

                "resolvedPackageModules" ->
                    Json.map2 PackageLoader.ResolvedPackageModules
                        (Json.field "package" Json.string)
                        (Json.field "modules" (Json.list Json.string))

                "resolvedDirectories" ->
                    Json.map2 PackageLoader.ResolvedDirectories
                        (Json.field "parentDir" Json.string)
                        (Json.field "paths" (Json.list packagePathDecoder))

                _ ->
                    Json.fail <| "Unknown msg type: " ++ typeStr

        packagePathDecoder =
            Json.map PackagePath.fromString Json.string
    in
    Json.field "type" Json.string
        |> Json.andThen helper



-- PORTS

Added stdlib/lib/useless/junk version [a7ffc6f8bf].

Added stdlib/lib/version/play.json version [73b800a441].

























>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
{
    "name": "play/version",
    "version": "1.0.0",
    "language-version": "0.2.0",
    "exposed-modules": [
        "version/data"
    ],
    "dependencies": {
    },
    "package-paths": [
    ]
}

Added stdlib/lib/version/src/version/data.play version [f4d9804625].





>
>
1
2
def: minor
: 1

Modified stdlib/play.json from [1664c7c068] to [163a77ae7d].

2
3
4
5
6
7
8

9
10

11
12
    "name": "play/standard_library",
    "version": "0.2.0",
    "language-version": "0.2.0",
    "exposed-modules": [
        "basic"
    ],
    "dependencies": {

    },
    "package-paths": [

    ]
}







>


>


2
3
4
5
6
7
8
9
10
11
12
13
14
    "name": "play/standard_library",
    "version": "0.2.0",
    "language-version": "0.2.0",
    "exposed-modules": [
        "basic"
    ],
    "dependencies": {
        "play/version": "1.0.0"
    },
    "package-paths": [
        "lib/*"
    ]
}

Modified stdlib/src/basic.play from [e3769efe5c] to [0ef79cb1cb].

1
2
def: one
: 1
|
|
1
2
def: version
: tmp/mod/major /version/data/minor + 

Added stdlib/src/tmp/mod.play version [2e69dc67e4].





>
>
1
2
def: major
: 2