Skip to content
This repository was archived by the owner on Oct 5, 2024. It is now read-only.

Commit 3163b05

Browse files
authored
Merge branch 'master' into char-escapes
2 parents b7a3cf4 + 07382a6 commit 3163b05

File tree

21 files changed

+532
-249
lines changed

21 files changed

+532
-249
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ node_js:
44
lts/*
55

66
before_install:
7-
8-
9-
script: make && make test
7+
108

9+
script: make && make test && make lint

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,12 @@ build:
1212
test:
1313
elm make src/library/Todo.elm --output /dev/null # build the library just to test it compiles
1414
elm-test
15+
16+
.PHONY: format
17+
format:
18+
elm-format . --yes
19+
20+
21+
.PHONY: lint
22+
lint:
23+
elm-format . --validate

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Oh God please yes! :heart: Feel free to look around the [<kbd>help wanted</kbd>]
7070

7171
| | parser tests | parse | desugar | infer types | optimize | emit | emit tests |
7272
| ----------------- | -------------------- | -------------------- | ------------------ | ------------------ | -------------------- | ------------------ | ------------------ |
73-
| integers | :heavy_check_mark: | :warning: [[1]](#f1) | :heavy_check_mark: | :heavy_check_mark: | :warning: [[2]](#f2) | :heavy_check_mark: | :heavy_check_mark: |
73+
| integers | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :warning: [[2]](#f2) | :heavy_check_mark: | :heavy_check_mark: |
7474
| floats | :x: [[3]](#f3) | :x: [[4]](#f4) | :x: [[3]](#f3) | :x: [[3]](#f3) | :x: [[5]](#f5) | :x: [[3]](#f3) | :x: [[3]](#f3) |
7575
| characters | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
7676
| strings | :warning: [[6]](#f6) | :warning: [[7]](#f7) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
@@ -94,7 +94,6 @@ Oh God please yes! :heart: Feel free to look around the [<kbd>help wanted</kbd>]
9494
| custom operators | :x: | :x: | :x: | :x: | :x: | :x: | :x: |
9595
| shaders (?) | :x: | :x: | :x: | :x: | :x: | :x: | :x: |
9696

97-
1. <span id="f1"></span> Hex integers not implemented; will be fixed in [#19](https://github.com/elm-in-elm/compiler/pull/19)
9897
2. <span id="f2"></span> To be optimized with multiplication, subtraction, division, modulo, exponentiation... maybe more?; not tracked yet
9998
3. <span id="f3"></span> Not implemented; tracked in [#17](https://github.com/elm-in-elm/compiler/issues/17)
10099
4. <span id="f4"></span> Not implemented; not tracked yet
@@ -108,7 +107,8 @@ The tooling around this project requires:
108107

109108
* **`make`** for the [Makefile](Makefile)
110109
* **NodeJS 10+** for the [CLI tool](src/index.js)
111-
* **`elm`** and **`elm-test`**
110+
* **`elm`**, **`elm-test`** and **`elm-format`**
111+
112112

113113
or alternatively a good amount of ingenuity to do stuff in a different-than-planned way.
114114

@@ -126,6 +126,14 @@ $ make test
126126
```
127127
Runs `elm-test` on the test suite (gasp!)
128128

129+
## Formatting code
130+
131+
```
132+
$ make format
133+
```
134+
Runs elm-format.
135+
Make sure to format code before submitting a pull request!
136+
129137
## Small TODOs
130138

131139
> This is a brain-dump of some low-level stuff. (High-level stuff should be in the roadmap.) My apologies if it's hard to make sense of this! ~janiczek
@@ -143,7 +151,6 @@ Runs `elm-test` on the test suite (gasp!)
143151

144152
#### General
145153

146-
- [ ] Nix expression for the dependencies and building this project? Would that be helpful?
147154
- [ ] Compare our `Main.compile` with official compiler's `Compile.compile` - is that a better API?
148155
- [ ] Types module: remove, refactor into "module per datastructure" style?
149156
- [ ] Deal with kernel modules
@@ -165,7 +172,6 @@ Runs `elm-test` on the test suite (gasp!)
165172
- [ ] Annotate type errors with position in source code (for better error messages)
166173
- [ ] Try to find a better name for "occurs check" and make the error message easier to understand
167174
- [ ] Document the typechecking stages better (ie. at all)
168-
- [ ] Find a (probably monadic) abstraction for `assignIds` so we don't have to thread the state in such a way. (This might not be possible because of lack of do notation. Ie. callback hell would always have to happen... Dunno!) For example see `Stage.InferTypes.assignIdsHelp`, the `Canonical.Plus` case.
169175
- [ ] Rename types to be able to show nice type variables (ie. the classic `a` instead of `type #0` or something). `Stage.InferTypes.getType`
170176

171177
#### Optimizations

elm.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"elm-community/graph": "6.0.0",
1919
"elm-community/maybe-extra": "5.0.0",
2020
"elm-community/result-extra": "2.2.1",
21+
"rtfeldman/elm-hex": "1.0.0",
2122
"turboMaCk/any-dict": "1.0.1",
2223
"turboMaCk/any-set": "1.0.0"
2324
},
@@ -38,9 +39,8 @@
3839
"elm/virtual-dom": "1.0.2",
3940
"elm-community/json-extra": "4.0.0",
4041
"elm-community/list-extra": "8.2.0",
41-
"rtfeldman/elm-hex": "1.0.0",
4242
"rtfeldman/elm-iso8601-date-strings": "1.1.2",
4343
"stil4m/structured-writer": "1.0.2"
4444
}
4545
}
46-
}
46+
}

example-project/src/Main.elm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module Main exposing (main)
22

33

44
main =
5-
let
6-
x =
7-
1
8-
in
9-
x
5+
if 1 + 2 then
6+
()
7+
8+
else
9+
True

shell.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
let
2+
nixpkgs = (import <nixpkgs> {}).fetchFromGitHub {
3+
owner = "nixOS";
4+
repo = "nixpkgs-channels";
5+
rev = "73392e79aa62e406683d6a732eb4f4101f4732be";
6+
sha256 = "049fq37sxdn5iis7ni407j2jsfrxbb41pgv5zawi02qj47f74az9";
7+
};
8+
in with import nixpkgs {};
9+
mkShell {
10+
buildInputs = with elmPackages; [
11+
nodejs-10_x
12+
elm elm-test elm-format elm-analyse
13+
];
14+
}

src/compiler/AST/Typed.elm

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module AST.Typed exposing
33
, Expr_(..)
44
, ProjectFields
55
, lambda
6+
, let_
67
, transformAll
78
, transformOnce
89
)
@@ -63,6 +64,14 @@ lambda argument body argumentId =
6364
}
6465

6566

67+
let_ : AnyDict String VarName (Binding Expr) -> Expr -> Expr_
68+
let_ bindings body =
69+
Let
70+
{ bindings = bindings
71+
, body = body
72+
}
73+
74+
6675
{-| A helper for the Transform library.
6776
-}
6877
recurse : (Expr -> Expr) -> Expr -> Expr

src/compiler/Common.elm

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ module Common exposing
66
, filePathToString
77
, mapBinding
88
, moduleNameToString
9-
, moduleNames
109
, topLevelDeclarationToString
1110
, unalias
1211
, varNameToString
@@ -20,15 +19,12 @@ import Common.Types
2019
, FilePath(..)
2120
, Module
2221
, ModuleName(..)
23-
, Modules
24-
, Set_
2522
, TopLevelDeclaration
2623
, VarName(..)
2724
)
2825
import Dict.Any
2926
import Error exposing (Error(..), GeneralError(..))
3027
import Extra.Dict.Any
31-
import Set.Any
3228

3329

3430
filePathToString : FilePath -> String
@@ -41,18 +37,6 @@ moduleNameToString (ModuleName moduleName) =
4137
moduleName
4238

4339

44-
moduleNames : Modules expr -> Set_ ModuleName
45-
moduleNames program =
46-
let
47-
toSet : Modules expr -> Set_ ModuleName
48-
toSet dict =
49-
dict
50-
|> Dict.Any.keys
51-
|> Set.Any.fromList moduleNameToString
52-
in
53-
toSet program
54-
55-
5640
{-| Expects the source directory filepaths to be normalized so that there's no `/` at the end.
5741
-}
5842
expectedFilePath : FilePath -> ModuleName -> FilePath

src/compiler/Error.elm

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type GeneralError
3939

4040
type ParseError
4141
= ModuleNameDoesntMatchFilePath ModuleName FilePath
42-
| FileNotFound FilePath
4342
| EmptySourceDirectories
4443
| InvalidElmJson JD.Error
4544
| ParseProblem (List (P.DeadEnd ParseContext ParseProblem))
@@ -48,6 +47,7 @@ type ParseError
4847
type ParseContext
4948
= InLiteral
5049
| InLiteralInt
50+
| InHexInt
5151
| InExpr
5252
| InIf
5353
| InLet
@@ -78,7 +78,6 @@ type ParseProblem
7878
| ExpectingEqualsSign -- `x >=< 1`
7979
| ExpectingMinusSign -- `>-<42`
8080
| ExpectingInt
81-
| ExpectingHexadecimals
8281
| ExpectingSingleQuote
8382
| ExpectingChar
8483
| ExpectingEscapeBackslash
@@ -101,10 +100,10 @@ type ParseProblem
101100
| ExpectingFalse
102101
| ExpectingLet
103102
| ExpectingIn
104-
| ExpectingAtLeastOne
105-
| ExpectingNewline
106103
| ExpectingUnit
104+
| ExpectingHexPrefix
107105
| InvalidInt
106+
| InvalidHexInt
108107
| CompilerBug String
109108

110109

@@ -113,10 +112,6 @@ type DesugarError
113112
{ var : ( Maybe ModuleName, VarName )
114113
, module_ : ModuleName
115114
}
116-
| AmbiguousVar
117-
{ var : ( Maybe ModuleName, VarName )
118-
, module_ : ModuleName
119-
}
120115

121116

122117
type TypeError
@@ -156,11 +151,6 @@ toString error =
156151
++ filePath
157152
++ "`."
158153

159-
FileNotFound (FilePath filePath) ->
160-
"File `"
161-
++ filePath
162-
++ "` not found."
163-
164154
EmptySourceDirectories ->
165155
"Empty `sourceDirectories`!"
166156

@@ -190,20 +180,6 @@ toString error =
190180
++ moduleName
191181
++ "`. Have you imported it?"
192182

193-
AmbiguousVar { var, module_ } ->
194-
let
195-
( maybeModuleName, varName ) =
196-
var
197-
198-
(ModuleName moduleName) =
199-
module_
200-
in
201-
"There are multiple definitions for variable `"
202-
++ fullVarName maybeModuleName varName
203-
++ "` in the module `"
204-
++ moduleName
205-
++ "`. Keep only one in the code! Maybe alias some imports to fix the collision?"
206-
207183
TypeError typeError ->
208184
case typeError of
209185
UnknownName (VarName varName) ->

src/compiler/Extra/Tuple.elm

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)