on master help sign in
Merge branch 'master' into cabal_stuff
5c6c22fNiklas Larsson
CHANGELOG.md+4−1
@@ -1,7 +1,10 @@
1−# New in 1.0.1
1+# New in 1.1.0
2
2
3## Library Updates
3## Library Updates
4
4
5++ Added `Text.PrettyPrint.WL` an implementation of the Wadler-Leijen
6+ Pretty-Print algorithm. Useful for those wishing to pretty print
7+ things.
5+ Added `Text.Lexer` and `Text.Parser` to `contrib`. These are small libraries
8+ Added `Text.Lexer` and `Text.Parser` to `contrib`. These are small libraries
6 for implementing total lexical analysers and parsers.
9 for implementing total lexical analysers and parsers.
7+ New instances:
10+ New instances:
idris.cabal+8−10
@@ -1,5 +1,5 @@
1Name: idris
1Name: idris
2−Version: 1.0
2+Version: 1.1.0
3License: BSD3
3License: BSD3
4License-file: LICENSE
4License-file: LICENSE
5Author: Edwin Brady
5Author: Edwin Brady
@@ -40,7 +40,7 @@ Description: Idris is a general purpose language with full dependent types.
40 .
40 .
41 * Hugs style interactive environment
41 * Hugs style interactive environment
42
42
43−Cabal-Version: >= 1.8.1
43+Cabal-Version: >= 1.18
44
44
45Build-type: Custom
45Build-type: Custom
46
46
@@ -302,14 +302,6 @@ Library
302 , fsnotify >= 0.2 && < 2.2
302 , fsnotify >= 0.2 && < 2.2
303 , async < 2.2
303 , async < 2.2
304
304
305− Extensions: MultiParamTypeClasses
306− , DeriveFoldable
307− , DeriveTraversable
308− , FunctionalDependencies
309− , FlexibleContexts
310− , FlexibleInstances
311− , TemplateHaskell
312−
313 ghc-prof-options: -auto-all -caf-all
305 ghc-prof-options: -auto-all -caf-all
314
306
315 if os(linux)
307 if os(linux)
@@ -347,6 +339,7 @@ Executable idris
347 , haskeline >= 0.7
339 , haskeline >= 0.7
348 , transformers
340 , transformers
349
341
342+ Default-Language: Haskell2010
350 ghc-prof-options: -auto-all -caf-all
343 ghc-prof-options: -auto-all -caf-all
351 ghc-options: -threaded -rtsopts -funbox-strict-fields -with-rtsopts=-I0
344 ghc-options: -threaded -rtsopts -funbox-strict-fields -with-rtsopts=-I0
352
345
@@ -372,6 +365,8 @@ Test-suite regression-and-feature-tests
372 , bytestring
365 , bytestring
373 , transformers
366 , transformers
374
367
368+
369+ Default-Language: Haskell2010
375 ghc-prof-options: -auto-all -caf-all
370 ghc-prof-options: -auto-all -caf-all
376 ghc-options: -threaded -rtsopts -with-rtsopts=-N -funbox-strict-fields
371 ghc-options: -threaded -rtsopts -with-rtsopts=-N -funbox-strict-fields
377
372
@@ -385,6 +380,7 @@ Executable idris-codegen-c
385 , haskeline >= 0.7
380 , haskeline >= 0.7
386 , transformers
381 , transformers
387
382
383+ Default-Language: Haskell2010
388 ghc-prof-options: -auto-all -caf-all
384 ghc-prof-options: -auto-all -caf-all
389 ghc-options: -threaded -rtsopts -funbox-strict-fields
385 ghc-options: -threaded -rtsopts -funbox-strict-fields
390
386
@@ -398,6 +394,7 @@ Executable idris-codegen-javascript
398 , haskeline >= 0.7
394 , haskeline >= 0.7
399 , transformers
395 , transformers
400
396
397+ Default-Language: Haskell2010
401 ghc-prof-options: -auto-all -caf-all
398 ghc-prof-options: -auto-all -caf-all
402 ghc-options: -threaded -rtsopts -funbox-strict-fields
399 ghc-options: -threaded -rtsopts -funbox-strict-fields
403
400
@@ -411,5 +408,6 @@ Executable idris-codegen-node
411 , haskeline >= 0.7
408 , haskeline >= 0.7
412 , transformers
409 , transformers
413
410
411+ Default-Language: Haskell2010
414 ghc-prof-options: -auto-all -caf-all
412 ghc-prof-options: -auto-all -caf-all
415 ghc-options: -threaded -rtsopts -funbox-strict-fields
413 ghc-options: -threaded -rtsopts -funbox-strict-fields
libs/contrib/Text/PrettyPrint/WL.idrnew file+18
@@ -0,0 +1,18 @@
1+||| A revised Idris port of the Wadler-Leijen pretty-printer.
2+|||
3+||| This port of the Wadler-Leijen Pretty-Printer is based upon the
4+||| port originally created by Shayan Najd [1]. We have changed the
5+||| render function to be total using a technique based on
6+||| continuations proposed by gallais [2], and fix minor errors in the
7+||| original Idris port.
8+|||
9+||| [1] https://github.com/shayan-najd/wl-pprint
10+||| [2] https://gallais.github.io/blog/termination-tricks.html
11+module Text.PrettyPrint.WL
12+
13+import public Text.PrettyPrint.WL.Core
14+import public Text.PrettyPrint.WL.Characters
15+import public Text.PrettyPrint.WL.Combinators
16+
17+%default total
18+%access export
libs/contrib/Text/PrettyPrint/WL/Characters.idrnew file+103
@@ -0,0 +1,103 @@
1+||| Commonly used characters
2+module Text.PrettyPrint.WL.Characters
3+
4+import Text.PrettyPrint.WL.Core
5+
6+%default total
7+%access export
8+
9+lparen : Doc
10+lparen = char '('
11+
12+rparen : Doc
13+rparen = char ')'
14+
15+langle : Doc
16+langle = char '<'
17+
18+rangle : Doc
19+rangle = char '>'
20+
21+lbrace : Doc
22+lbrace = char '{'
23+
24+rbrace : Doc
25+rbrace = char '}'
26+
27+lbracket : Doc
28+lbracket = char '['
29+
30+rbracket : Doc
31+rbracket = char ']'
32+
33+squote : Doc
34+squote = char '\''
35+
36+dquote : Doc
37+dquote = char '"'
38+
39+semi : Doc
40+semi = char ';'
41+
42+colon : Doc
43+colon = char ':'
44+
45+comma : Doc
46+comma = char ','
47+
48+space : Doc
49+space = char ' '
50+
51+dot : Doc
52+dot = char '.'
53+
54+backslash : Doc
55+backslash = char '\\'
56+
57+forwardslash : Doc
58+forwardslash = char '/'
59+
60+equals : Doc
61+equals = char '='
62+
63+pipe : Doc
64+pipe = char '|'
65+
66+bang : Doc
67+bang = char '!'
68+
69+tick : Doc
70+tick = char '`'
71+
72+tilda : Doc
73+tilda = char '~'
74+
75+hash : Doc
76+hash = char '#'
77+
78+asterix : Doc
79+asterix = char '*'
80+
81+ampersand : Doc
82+ampersand = char '&'
83+
84+dash : Doc
85+dash = char '-'
86+
87+question : Doc
88+question = char '?'
89+
90+dollar : Doc
91+dollar = char '$'
92+
93+pound : Doc
94+pound = char '£'
95+
96+euro : Doc
97+euro = char '€'
98+
99+caret : Doc
100+caret = char '^'
101+
102+percent : Doc
103+percent = char '%'
libs/contrib/Text/PrettyPrint/WL/Combinators.idrnew file+259
@@ -0,0 +1,259 @@
1+||| Common combinators.
2+module Text.PrettyPrint.WL.Combinators
3+
4+import Text.PrettyPrint.WL.Core
5+import Text.PrettyPrint.WL.Characters
6+
7+%default total
8+%access export
9+
10+-- --------------------------------------------------- [ Alignment Combinators ]
11+
12+||| The document `(align x)` renders document `x` with the nesting
13+||| level set to the current column. It is used for example to
14+||| implement 'hang'.
15+align : Doc -> Doc
16+align d = column (\k => nesting (\i => nest (k - i) d))
17+
18+||| The hang combinator implements hanging indentation. The document
19+||| `(hang i x)` renders document `x` with a nesting level set to the
20+||| current column plus `i`.
21+hang : Int -> Doc -> Doc
22+hang i d = align (nest i d)
23+
24+||| The document `(indent i x)` indents document `x` with `i` spaces.
25+indent : Int -> Doc -> Doc
26+indent i d = hang i (text (spaces i) <+> d)
27+
28+-- -------------------------------------------------- [ High-Level Combinators ]
29+
30+||| The document `softLine` behaves like `space` if the resulting
31+||| output fits the page, otherwise it behaves like `line`.
32+softLine : Doc
33+softLine = group line
34+
35+||| The document `softbreak` behaves like `empty` if the resulting
36+||| output fits the page, otherwise it behaves like 'line'.
37+softBreak : Doc
38+softBreak = group breakLine
39+
40+infixr 5 |/|, |//|, |$|, |$$|
41+infixr 6 |+|, |++|
42+
43+private
44+concatDoc : Doc -> Doc -> Doc -> Doc
45+concatDoc sep x y = x `beside` (sep `beside` y)
46+
47+||| The document `(x |+| y)` concatenates document `x` and document
48+||| `y`. It is an associative operation having 'empty' as a left and
49+||| right unit.
50+(|+|) : Doc -> Doc -> Doc
51+(|+|) = (<+>)
52+
53+||| The document `(x |++| y)` concatenates document `x` and `y` with a
54+||| `space` in between.
55+(|++|) : Doc -> Doc -> Doc
56+(|++|) = concatDoc space
57+
58+||| The document `(x |/| y)` concatenates document `x` and `y` with a
59+||| 'softline' in between. This effectively puts `x` and `y` either
60+||| next to each other (with a `space` in between) or underneath each
61+||| other.
62+(|/|) : Doc -> Doc -> Doc
63+(|/|) = concatDoc softLine
64+
65+||| The document `(x |//| y)` concatenates document `x` and `y` with
66+||| a 'softbreak' in between. This effectively puts `x` and `y` either
67+||| right next to each other or underneath each other.
68+(|//|) : Doc -> Doc -> Doc
69+(|//|) = concatDoc softBreak
70+
71+||| The document `(x |$| y)` concatenates document `x` and `y` with a
72+||| `line` in between.
73+(|$|) : Doc -> Doc -> Doc
74+(|$|) = concatDoc line
75+
76+||| The document `(x |$$| y)` concatenates document `x` and `y` with
77+||| a `linebreak` in between.
78+(|$$|) : Doc -> Doc -> Doc
79+(|$$|) = concatDoc breakLine
80+
81+||| The document `(vsep xs)` concatenates all documents `xs`
82+||| vertically with `(|$|)`. If a 'group' undoes the line breaks
83+||| inserted by `vsep`, all documents are separated with a space.
84+vsep : List Doc -> Doc
85+vsep = fold (|$|)
86+
87+||| The document `(sep xs)` concatenates all documents `xs` either
88+||| horizontally with `(|++|)`, if it fits the page, or vertically with
89+||| `(|$|)`.
90+sep : List Doc -> Doc
91+sep = group . vsep
92+
93+
94+||| The document `(fillSep xs)` concatenates documents `xs`
95+||| horizontally with `(|++|)` as long as its fits the page, than
96+||| inserts a `line` and continues doing that for all documents in
97+||| `xs`.
98+fillSep : List Doc -> Doc
99+fillSep = fold (|/|)
100+
101+||| The document `(hsep xs)` concatenates all documents `xs`
102+||| horizontally with `(|++|)`.
103+hsep : List Doc -> Doc
104+hsep = fold (|++|)
105+
106+||| The document `(hcat xs)` concatenates all documents `xs`
107+||| horizontally with `(|+|)`.
108+hcat : List Doc -> Doc
109+hcat = fold (<+>)
110+
111+||| The document `(vcat xs)` concatenates all documents `xs`
112+||| vertically with `(|$$|)`. If a `group` undoes the line breaks
113+||| inserted by `vcat`, all documents are directly concatenated.
114+vcat : List Doc -> Doc
115+vcat = fold (|$$|)
116+
117+||| The document `(cat xs)` concatenates all documents `xs` either
118+||| horizontally with `(|+|)`, if it fits the page, or vertically with
119+||| `(|$$|)`.
120+cat : List Doc -> Doc
121+cat = group . vcat
122+
123+||| The document `(fillCat xs)` concatenates documents `xs`
124+||| horizontally with `(|+|)` as long as its fits the page, than inserts
125+||| a `linebreak` and continues doing that for all documents in `xs`.
126+fillCat : List Doc -> Doc
127+fillCat = fold (|//|)
128+
129+||| The document `(enclose l r x)` encloses document `x` between
130+||| documents `l` and `r` using `(|+|)`.
131+enclose : Doc -> Doc -> Doc -> Doc
132+enclose l r x = concatDoc x l r
133+
134+squotes : Doc -> Doc
135+squotes = enclose squote squote
136+
137+dquotes : Doc -> Doc
138+dquotes = enclose dquote dquote
139+
140+braces : Doc -> Doc
141+braces = enclose lbrace rbrace
142+
143+parens : Doc -> Doc
144+parens = enclose lparen rparen
145+
146+angles : Doc -> Doc
147+angles = enclose langle rangle
148+
149+brackets : Doc -> Doc
150+brackets = enclose lbracket rbracket
151+
152+-- ----------------------------------------------------- [ Lists, Sets, Tuples ]
153+
154+||| The document `(encloseSep l r sep xs)` concatenates the documents
155+||| `xs` separated by `sep` and encloses the resulting document by `l`
156+||| and `r`. The documents are rendered horizontally if that fits the
157+||| page. Otherwise they are aligned vertically. All separators are put
158+||| in front of the elements.
159+encloseSep : (l : Doc)
160+ -> (r : Doc)
161+ -> (sep : Doc)
162+ -> (xs : List Doc)
163+ -> Doc
164+encloseSep l r s [] = l <+> r
165+encloseSep l r s [x] = l <+> x <+> r
166+encloseSep l r s xs = align (cat (zipWith (<+>) (l :: replicate (length xs) s) xs) <+> r)
167+
168+||| The document `(list xs)` comma separates the documents `xs` and
169+||| encloses them in square brackets. The documents are rendered
170+||| horizontally if that fits the page. Otherwise they are aligned
171+||| vertically. All comma separators are put in front of the
172+||| elements.
173+list : List Doc -> Doc
174+list = encloseSep lbracket rbracket comma
175+
176+||| The document `(tupled xs)` comma separates the documents `xs`
177+||| and encloses them in parenthesis. The documents are rendered
178+||| horizontally if that fits the page. Otherwise they are aligned
179+||| vertically. All comma separators are put in front of the
180+||| elements.
181+tupled : List Doc -> Doc
182+tupled = encloseSep lparen rparen comma
183+
184+||| The document `(set xs)` separates the documents `xs` with
185+||| commas and encloses them in braces. The documents are
186+||| rendered horizontally if that fits the page. Otherwise they are
187+||| aligned vertically. All comma's are put in front of the
188+||| elements.
189+set : List Doc -> Doc
190+set = encloseSep lbrace rbrace comma
191+
192+||| The document `(semiBraces xs)` separates the documents `xs` with
193+||| semi-colon and encloses them in braces. The documents are
194+||| rendered horizontally if that fits the page. Otherwise they are
195+||| aligned vertically. All semi-colons's are put in front of the
196+||| elements.
197+semiBrace : List Doc -> Doc
198+semiBrace = encloseSep lbrace rbrace semi
199+
200+||| `(punctuate p xs)` concatenates all documents in `xs` with
201+||| document `p` except for the last document.
202+punctuate : Doc -> List Doc -> List Doc
203+punctuate p [] = []
204+punctuate p [x] = [x]
205+punctuate p (x :: xs) = (x <+> p) :: punctuate p xs
206+
207+-- ------------------------------------------------------------------- [ Fills ]
208+
209+width : Doc -> (Int -> Doc) -> Doc
210+width doc f = column (\k => doc <+> column (\k' => f (k' - k)))
211+
212+||| The document `(fillBreak i x)` first renders document `x`. It
213+||| than appends `space`s until the width is equal to `i`. If the
214+||| width of `x` is already larger than `i`, the nesting level is
215+||| increased by `i` and a `line` is appended.
216+fillBreak : (i : Int) -> (x : Doc) -> Doc
217+fillBreak f x =
218+ width x (\w => if (w > f)
219+ then nest f breakLine
220+ else text (spaces (f - w)))
221+
222+||| The document `(fill i x)` renders document `x`. It than appends
223+||| `space`s until the width is equal to `i`. If the width of `x` is
224+||| already larger, nothing is appended. This combinator is quite
225+||| useful in practice to output a list of bindings.
226+fill : (i : Int) -> (x : Doc) -> Doc
227+fill f d =
228+ width d (\w => if (w >= f)
229+ then empty
230+ else text (spaces (f - w)))
231+
232+-- -------------------------------------------------------------- [ Primatives ]
233+
234+||| The document `(literal s)` concatenates all characters in `s`
235+||| using `line` for newline characters and `char` for all other
236+||| characters. It is used instead of 'text' whenever the text contains
237+||| newline characters.
238+literal : (str : String) -> Doc
239+literal str = mkLiteral (unpack str)
240+ where
241+ mkLiteral : List Char -> Doc
242+ mkLiteral Nil = empty
243+ mkLiteral ('\n':: ss) = line <+> mkLiteral ss
244+ mkLiteral (c :: ss) = char c <+> mkLiteral ss
245+
246+bool : Bool -> Doc
247+bool b = text (show b)
248+
249+nat : Nat -> Doc
250+nat n = text (show n)
251+
252+int : Int -> Doc
253+int i = text (show i)
254+
255+integer : Integer -> Doc
256+integer i = text (show i)
257+
258+double : Double -> Doc
259+double d = text (show d)
libs/contrib/Text/PrettyPrint/WL/Core.idrnew file+225
@@ -0,0 +1,225 @@
1+||| Core definitions and primitives.
2+module Text.PrettyPrint.WL.Core
3+
4+%default total
5+%access export
6+
7+-- -------------------------------------------------------------------- [ Core ]
8+
9+||| The abstract data type `Doc` represents pretty documents.
10+|||
11+data Doc : Type where
12+ Empty : Doc
13+ Chara : (c : Char) -> Doc
14+ Text : (len : Int) -> (str : String) -> Doc
15+ Line : (undone : Bool) -> Doc
16+
17+ Cat : (x : Doc) -> (y : Doc) -> Doc
18+ Nest : (lvl : Int) -> (x : Doc) -> Doc
19+ Union : (x : Doc) -> (y : Doc) -> Doc
20+
21+ Column : (f : Int -> Doc) -> Doc
22+ Nesting : (f : Int -> Doc) -> Doc
23+
24+-- -------------------------------------------------------------- [ Primitives ]
25+
26+||| The empty document is, indeed, empty.
27+empty : Doc
28+empty = Empty
29+
30+||| The `line` document advances to the next line and indents to the
31+||| current nesting level. Document `line` behaves like `(text " ")`
32+||| if the line break is undone by 'group'.
33+line : Doc
34+line = Line False
35+
36+||| The document `(char c)` contains the literal character `c`. If the
37+||| character is a newline (`'\n'`) the function returns a line
38+||| document. Ideally, the function 'line' should be used for line
39+||| breaks.
40+char : (c : Char) -> Doc
41+char '\n' = line
42+char c = Chara c
43+
44+||| The document `(text s)` contains the literal string `s`. The
45+||| string shouldn't contain any newline (`'\n'`) characters. If the
46+||| string contains newline characters, the function 'literal' should be
47+||| used.
48+text : (str : String) -> Doc
49+text "" = empty
50+text str = Text (cast $ length str) str
51+
52+||| The `breakLine` document advances to the next line and indents to
53+||| the current nesting level. Document `breakLine` behaves like
54+||| 'empty' if the line break is undone by 'group'.
55+breakLine : Doc
56+breakLine = Line True
57+
58+||| Horizontal concatenation of documents
59+beside : Doc -> Doc -> Doc
60+beside = Cat
61+
62+||| The document `(nest lvl x)` renders document `x` with the current
63+||| indentation level increased by lvl.
64+nest : (lvl : Int)
65+ -> (x : Doc)
66+ -> Doc
67+nest = Nest
68+
69+column : (f : Int -> Doc) -> Doc
70+column = Column
71+
72+nesting : (f : Int -> Doc) -> Doc
73+nesting = Nesting
74+
75+private %inline
76+flatten : Doc -> Doc
77+flatten (Line break) = if break then Empty else Text 1 " "
78+
79+flatten (Cat x y) = Cat (flatten x) (flatten y)
80+flatten (Nest lvl x) = Nest lvl (flatten x)
81+flatten (Union x _) = flatten x
82+flatten (Column f) = Column (\i => flatten $ f i)
83+flatten (Nesting f) = Nesting (\i => flatten $ f i)
84+
85+flatten other = other
86+
87+||| The `group` combinator is used to specify alternative
88+||| layouts. The document `(group x)` undoes all line breaks in
89+||| document `x`. The resulting line is added to the current line if
90+||| that fits the page. Otherwise, the document `x` is rendered without
91+||| any changes.
92+group : Doc -> Doc
93+group x = Union (flatten x) x
94+
95+Semigroup Doc where
96+ (<+>) x y = beside x y
97+
98+Monoid Doc where
99+ neutral = empty
100+
101+fold : (f : Doc -> Doc -> Doc) -> (ds : List Doc) -> Doc
102+fold _ Nil = empty
103+fold f (x::xs) = foldl f x xs
104+
105+-- --------------------------------------------------------------- [ Renderers ]
106+
107+namespace PrettyDoc
108+
109+ ||| The data type `PrettyDoc` represents rendered documents and is
110+ ||| used by the display functions.
111+ data PrettyDoc : Type where
112+ Empty : PrettyDoc
113+ Chara : (c : Char) -> (rest : PrettyDoc) -> PrettyDoc
114+ Text : (len : Int) -> (str : String) -> (rest : PrettyDoc) -> PrettyDoc
115+ Line : (lvl : Int) -> (rest : PrettyDoc) -> PrettyDoc
116+
117+||| Helper function to construct spaces.
118+spaces : (n : Int) -> String
119+spaces n = if n <= 0 then "" else pack $ replicate (cast n) ' '
120+
121+private
122+indentation : Int -> String
123+indentation n = spaces n
124+
125+||| `(showPrettyDoc doc)` takes the output `PrettyDoc` from a
126+||| rendering function and transforms it to a String for printing.
127+showPrettyDoc : (doc : PrettyDoc) -> String
128+showPrettyDoc doc = showPrettyDocS doc ""
129+ where
130+ showPrettyDocS : (doc : PrettyDoc) -> (acc : String) -> String
131+ showPrettyDocS Empty = id
132+ showPrettyDocS (Chara c rest) = strCons c . showPrettyDocS rest
133+ showPrettyDocS (Text len str rest) = (str ++) . showPrettyDocS rest
134+ showPrettyDocS (Line lvl rest) = (('\n' `strCons` indentation lvl) ++) . showPrettyDocS rest
135+
136+private
137+fits : (w : Int) -> (x : PrettyDoc) -> Bool
138+fits w Empty = if w < 0 then False else True
139+fits w (Chara c rest) = if w < 0 then False else fits (w - 1) rest
140+
141+fits w (Text len str rest) = if w < 0 then False else fits (w - len) rest
142+
143+fits w (Line _ _) = if w < 0 then False else True
144+
145+
146+||| Use the Wadler-Leijen algorithm to pretty print the `doc`.
147+||| The algorithm uses a page width of `width` and a ribbon
148+||| width of `(ribbonfrac * width)` characters. The ribbon width is
149+||| the maximal amount of non-indentation characters on a line. The
150+||| parameter `ribbonfrac` should be between `0.0` and `1.0`. If it is
151+||| lower or higher, the ribbon width will be 0 or `width`
152+||| respectively.
153+render : (rfrac : Double)
154+ -> (width : Int)
155+ -> (doc : Doc)
156+ -> PrettyDoc
157+render rfrac w doc = best w 0 0 doc (const Empty)
158+ where
159+ rwidth : Int
160+ rwidth = max 0 $ min w (cast (cast w * rfrac))
161+
162+ nicest : (lvl : Int)
163+ -> (col : Int)
164+ -> (x : PrettyDoc)
165+ -> (y : PrettyDoc)
166+ -> PrettyDoc
167+ nicest n k x y =
168+ let width = min (w - k) (rwidth - k + n)
169+ in if fits width x then x else y
170+
171+ best : (lvl : Int)
172+ -> (col : Int)
173+ -> (curr : Int)
174+ -> (doc : Doc)
175+ -> (k : Int -> PrettyDoc)
176+ -> PrettyDoc
177+ best lvl col curr Empty k = k col
178+ best lvl col curr (Chara c) k = Chara c $ k (col + 1)
179+ best lvl col curr (Text len str) k = Text len str $ k (col + len)
180+ best lvl col curr (Line undone) k = Line curr $ k curr
181+
182+ best lvl col curr (Cat x y) k =
183+ best lvl col curr x (\curr' => best lvl curr' curr y k)
184+
185+ best lvl col curr (Nest x y) k = best lvl col (curr+x) y k
186+
187+ best lvl col curr (Union x y) k =
188+ nicest lvl col (best lvl col curr x k)
189+ (best lvl col curr y k)
190+
191+ best lvl col curr (Column f) k = best lvl col curr (f col) k
192+ best lvl col curr (Nesting f) k = best lvl col curr (f curr) k
193+
194+||| Print the document to a string using the given ribbon fraction
195+||| and page width.
196+toString : (rfrac : Double)
197+ -> (width : Int)
198+ -> (doc : Doc)
199+ -> String
200+toString rfrac width doc = showPrettyDoc (render rfrac width doc)
201+
202+writeDoc : (fname : String)
203+ -> (rfrac : Double)
204+ -> (width : Int)
205+ -> (doc : Doc)
206+ -> IO (Either FileError ())
207+writeDoc fname rfrac width doc = writeFile fname $ toString rfrac width doc
208+
209+namespace Default
210+
211+ ||| Render the document with a default ribbon fraction of 0.4 and page width of 120 characters.
212+ render : (doc : Doc) -> PrettyDoc
213+ render = render 0.4 120
214+
215+ ||| Print the document to a string using a default ribbon fraction
216+ ||| of 0.4 and page width of 120 characters.
217+ toString : (doc : Doc) -> String
218+ toString = toString 0.4 120
219+
220+ ||| Write the doc to `fname` using a default ribbon fraction of 0.4
221+ ||| and page width of 120 characters.
222+ writeDoc : (fname : String)
223+ -> (doc : Doc)
224+ -> IO (Either FileError ())
225+ writeDoc fname doc = writeFile fname $ Default.toString doc
libs/contrib/contrib.ipkg+5
@@ -32,4 +32,9 @@ modules = CFFI, CFFI.Types, CFFI.Memory,
32
32
33 Text.Lexer, Text.Parser,
33 Text.Lexer, Text.Parser,
34
34
35+ Text.PrettyPrint.WL,
36+ Text.PrettyPrint.WL.Core,
37+ Text.PrettyPrint.WL.Characters,
38+ Text.PrettyPrint.WL.Combinators,
39+
35 Data.Fin.Extra
40 Data.Fin.Extra
scripts/runidrisnew file+18
@@ -0,0 +1,18 @@
1+#!/bin/sh
2+
3+# This is a script that runs an idris program, suitable for use
4+# in a shebang line. We cache the executables by naming them after
5+# the SHA hash of the idris source and looking for it before
6+# compiling
7+RUNIDRIS_DIR="${TEMP:-/tmp}/runidris"
8+if [ ! -d $RUNIDRIS_DIR ]; then
9+ mkdir $RUNIDRIS_DIR
10+ chmod 700 $RUNIDRIS_DIR
11+fi
12+TEMP_NAME="runidris-`sha1sum $1 | cut -c1-40`"
13+FP="$RUNIDRIS_DIR/$TEMP_NAME"
14+if [ ! -e $FP ]; then
15+ "${IDRIS:-idris}" $1 --ibcsubdir "$RUNIDRIS_DIR" -i "." -o $FP
16+fi
17+shift
18+"$FP" "$@"
scripts/runidris-nodenew file+18
@@ -0,0 +1,18 @@
1+#!/bin/sh
2+
3+# This is a script that runs an idris program, suitable for use
4+# in a shebang line. We cache the executables by naming them after
5+# the SHA hash of the idris source and looking for it before
6+# compiling. This is the node version.
7+RUNIDRIS_DIR="${TEMP:-/tmp}/runidris-node"
8+if [ ! -d $RUNIDRIS_DIR ]; then
9+ mkdir $RUNIDRIS_DIR
10+ chmod 700 $RUNIDRIS_DIR
11+fi
12+TEMP_NAME="runidris-`sha1sum $1 | cut -c1-40`.js"
13+FP="$RUNIDRIS_DIR/$TEMP_NAME"
14+if [ ! -e $FP ]; then
15+ "${IDRIS:-idris}" --codegen node --ibcsubdir "$RUNIDRIS_DIR" -i "." $1 -o $FP
16+fi
17+shift
18+node "$FP" "$@"
src/IRTS/CodegenC.hs+234−115
@@ -5,9 +5,11 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE FlexibleContexts #-}
9+
8module IRTS.CodegenC (codegenC) where
10module IRTS.CodegenC (codegenC) where
9
11
10−import Idris.AbsSyntax
12+import Idris.AbsSyntax hiding (getBC)
11import Idris.Core.TT
13import Idris.Core.TT
12import IRTS.Bytecode
14import IRTS.Bytecode
13import IRTS.CodegenCommon
15import IRTS.CodegenCommon
@@ -19,10 +21,12 @@ import IRTS.System
19import Util.System
21import Util.System
20
22
21import Control.Monad
23import Control.Monad
24+import Control.Monad
25+import Control.Monad.RWS
22import Data.Bits
26import Data.Bits
23import Data.Char
27import Data.Char
24−import Data.List (intercalate, nubBy)
28+import Data.List (find, intercalate, nubBy, partition)
25−import Debug.Trace
29+import qualified Data.Text as T
26import Numeric
30import Numeric
27import System.Directory
31import System.Directory
28import System.Exit
32import System.Exit
@@ -30,6 +34,8 @@ import System.FilePath ((<.>), (</>))
30import System.IO
34import System.IO
31import System.Process
35import System.Process
32
36
37+import Debug.Trace
38+
33codegenC :: CodeGenerator
39codegenC :: CodeGenerator
34codegenC ci = do codegenC' (simpleDecls ci)
40codegenC ci = do codegenC' (simpleDecls ci)
35 (outputFile ci)
41 (outputFile ci)
@@ -64,7 +70,9 @@ codegenC' defs out exec incs objs libs flags exports iface dbg
64 let bc = map toBC defs
70 let bc = map toBC defs
65 let wrappers = genWrappers bc
71 let wrappers = genWrappers bc
66 let h = concatMap toDecl (map fst bc)
72 let h = concatMap toDecl (map fst bc)
67− let cc = concatMap (uncurry toC) bc
73+ let (state, cc) = execRWS (generateSrc bc) 0
74+ (CS { fnName = Nothing,
75+ level = 1 })
68 let hi = concatMap ifaceC (concatMap getExp exports)
76 let hi = concatMap ifaceC (concatMap getExp exports)
69 d <- getIdrisCRTSDir
77 d <- getIdrisCRTSDir
70 mprog <- readFile (d </> "idris_main" <.> "c")
78 mprog <- readFile (d </> "idris_main" <.> "c")
@@ -134,12 +142,17 @@ creg Tmp = "REG1"
134toDecl :: Name -> String
142toDecl :: Name -> String
135toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n"
143toDecl f = "void " ++ cname f ++ "(VM*, VAL*);\n"
136
144
137−toC :: Name -> [BC] -> String
145+generateSrc :: [(Name, [BC])] -> RWS Int String CState ()
146+generateSrc bc = mapM_ toC bc
147+
148+toC :: (Name, [BC]) -> RWS Int String CState ()
138−toC f code
149+toC (f, code) = do
139− = -- "/* " ++ show code ++ "*/\n\n" ++
150+ modify (\s -> s { fnName = Just f })
151+ s <- get
140− "void " ++ cname f ++ "(VM* vm, VAL* oldbase) {\n" ++
152+ tell $ "void " ++ cname f ++ "(VM* vm, VAL* oldbase) {\n"
141− indent 1 ++ "INITFRAME;\n" ++
153+ tell $ indent (level s) ++ "INITFRAME;\n"
142− concatMap (bcc 1) code ++ "}\n\n"
154+ bcc code
155+ tell $ "}\n\n"
143
156
144showCStr :: String -> String
157showCStr :: String -> String
145showCStr s = '"' : foldr ((++) . showChar) "\"" s
158showCStr s = '"' : foldr ((++) . showChar) "\"" s
@@ -175,10 +188,22 @@ showCStr s = '"' : foldr ((++) . showChar) "\"" s
175 2 -> s
188 2 -> s
176 _ -> error $ "Can't happen: String of invalid length " ++ show s
189 _ -> error $ "Can't happen: String of invalid length " ++ show s
177
190
191+data CState = CS {
192+ fnName :: Maybe Name,
193+ level :: Int
194+}
195+
196+
178−bcc :: Int -> BC -> String
197+bcc :: [BC] -> RWS Int String CState ()
198+bcc [] = return ()
199+bcc ((ASSIGN l r):xs) = do
200+ i <- get
179−bcc i (ASSIGN l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
201+ tell $ indent (level i) ++ creg l ++ " = " ++ creg r ++ ";\n"
202+ bcc xs
180−bcc i (ASSIGNCONST l c)
203+bcc ((ASSIGNCONST l c):xs) = do
204+ i <- get
181− = indent i ++ creg l ++ " = " ++ mkConst c ++ ";\n"
205+ tell $ indent (level i) ++ creg l ++ " = " ++ mkConst c ++ ";\n"
206+ bcc xs
182 where
207 where
183 mkConst (I i) = "MKINT(" ++ show i ++ ")"
208 mkConst (I i) = "MKINT(" ++ show i ++ ")"
184 mkConst (BI i) | i < (2^30) = "MKINT(" ++ show i ++ ")"
209 mkConst (BI i) | i < (2^30) = "MKINT(" ++ show i ++ ")"
@@ -196,16 +221,21 @@ bcc i (ASSIGNCONST l c)
196 mkConst c | isTypeConst c = "MKINT(42424242)"
221 mkConst c | isTypeConst c = "MKINT(42424242)"
197 mkConst c = error $ "mkConst of (" ++ show c ++ ") not implemented"
222 mkConst c = error $ "mkConst of (" ++ show c ++ ") not implemented"
198
223
224+bcc ((UPDATE l r):xs) = do
225+ i <- get
199−bcc i (UPDATE l r) = indent i ++ creg l ++ " = " ++ creg r ++ ";\n"
226+ tell $ indent (level i) ++ creg l ++ " = " ++ creg r ++ ";\n"
227+ bcc xs
200−bcc i (MKCON l loc tag []) | tag < 256
228+bcc ((MKCON l loc tag []):xs) | tag < 256 = do
229+ i <- get
201− = indent i ++ creg l ++ " = NULL_CON(" ++ show tag ++ ");\n"
230+ tell $ indent (level i) ++ creg l ++ " = NULL_CON(" ++ show tag ++ ");\n"
231+ bcc xs
202−bcc i (MKCON l loc tag args)
232+bcc ((MKCON l loc tag args):xs) = do
233+ i <- get
234+ let tab = indent (level i)
203− = indent i ++ alloc loc tag ++
235+ tell $ tab ++ alloc loc tag ++
204− indent i ++ setArgs 0 args ++ "\n" ++
236+ tab ++ setArgs 0 args ++ "\n" ++
205− indent i ++ creg l ++ " = " ++ creg Tmp ++ ";\n"
237+ tab ++ creg l ++ " = " ++ creg Tmp ++ ";\n"
206−
238+ bcc xs
207−-- "MKCON(vm, " ++ creg l ++ ", " ++ show tag ++ ", " ++
208−-- show (length args) ++ concatMap showArg args ++ ");\n"
209 where showArg r = ", " ++ creg r
239 where showArg r = ", " ++ creg r
210 setArgs i [] = ""
240 setArgs i [] = ""
211 setArgs i (x : xs) = "SETARG(" ++ creg Tmp ++ ", " ++ show i ++ ", " ++ creg x ++
241 setArgs i (x : xs) = "SETARG(" ++ creg Tmp ++ ", " ++ show i ++ ", " ++ creg x ++
@@ -217,52 +247,94 @@ bcc i (MKCON l loc tag args)
217 = "updateCon(" ++ creg Tmp ++ ", " ++ creg old ++ ", " ++ show tag ++ ", " ++
247 = "updateCon(" ++ creg Tmp ++ ", " ++ creg old ++ ", " ++ show tag ++ ", " ++
218 show (length args) ++ ");\n"
248 show (length args) ++ ");\n"
219
249
250+bcc ((PROJECT l loc a):xs) = do
251+ i <- get
220−bcc i (PROJECT l loc a) = indent i ++ "PROJECT(vm, " ++ creg l ++ ", " ++ show loc ++
252+ tell $ indent (level i) ++ "PROJECT(vm, " ++ creg l ++ ", "
221− ", " ++ show a ++ ");\n"
253+ ++ show loc ++ ", " ++ show a ++ ");\n"
254+ bcc xs
222−bcc i (PROJECTINTO r t idx)
255+bcc ((PROJECTINTO r t idx):xs) = do
256+ i <- get
223− = indent i ++ creg r ++ " = GETARG(" ++ creg t ++ ", " ++ show idx ++ ");\n"
257+ tell $ indent (level i) ++ creg r ++ " = GETARG(" ++ creg t
258+ ++ ", " ++ show idx ++ ");\n"
259+ bcc xs
224−bcc i (CASE True r code def)
260+bcc ((CASE True r code def):xs)
225− | length code < 4 = showCase i def code
261+ | length code < 4 = do
262+ showCases def code
263+ bcc xs
226 where
264 where
227− showCode :: Int -> [BC] -> String
265+ showCode bc = do
228− showCode i bc = "{\n" ++ concatMap (bcc (i + 1)) bc ++
266+ w <- getBC bc xs
267+ i <- get
229− indent i ++ "}\n"
268+ tell $ "{\n" ++ w ++ indent (level i) ++ "}\n"
230−
269+
231− showCase :: Int -> Maybe [BC] -> [(Int, [BC])] -> String
270+ showCases Nothing [(t, c)] = do
232− showCase i Nothing [(t, c)] = indent i ++ showCode i c
271+ i <- get
233− showCase i (Just def) [] = indent i ++ showCode i def
272+ tell $ indent (level i)
273+ showCode c
274+ showCases (Just def) [] = do
275+ i <- get
276+ tell $ indent (level i)
277+ showCode def
234− showCase i def ((t, c) : cs)
278+ showCases def ((t, c) : cs) = do
279+ i <- get
235− = indent i ++ "if (CTAG(" ++ creg r ++ ") == " ++ show t ++ ") " ++ showCode i c
280+ tell $ indent (level i) ++ "if (CTAG(" ++ creg r ++ ") == "
281+ ++ show t ++ ") "
282+ showCode c
236− ++ indent i ++ "else\n" ++ showCase i def cs
283+ tell $ indent (level i) ++ "else\n"
237−
284+ showCases def cs
285+
238−bcc i (CASE safe r code def)
286+bcc ((CASE safe r code def):xs) = do
287+ i <- get
239− = indent i ++ "switch(" ++ ctag safe ++ "(" ++ creg r ++ ")) {\n" ++
288+ tell $ indent (level i) ++ "switch(" ++ ctag safe ++ "(" ++ creg r ++ ")) {\n"
240− concatMap (showCase i) code ++
289+ mapM showCase code
241− showDef i def ++
290+ showDef def
242− indent i ++ "}\n"
291+ tell $ indent (level i) ++ "}\n"
292+ bcc xs
243 where
293 where
244 ctag True = "CTAG"
294 ctag True = "CTAG"
245 ctag False = "TAG"
295 ctag False = "TAG"
246
296
297+ showCase (t, bc) = do
298+ w <- getBC bc xs
299+ is <- get
300+ let i = level is
247− showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
301+ tell $ indent i ++ "case " ++ show t ++ ":\n"
248− ++ concatMap (bcc (i+1)) bc ++ indent (i + 1) ++ "break;\n"
302+ ++ w ++ indent (i + 1) ++ "break;\n"
249− showDef i Nothing = ""
303+ showDef Nothing = return $ ()
250− showDef i (Just c) = indent i ++ "default:\n"
304+ showDef (Just c) = do
305+ w <- getBC c xs
306+ is <- get
307+ let i = level is
251− ++ concatMap (bcc (i+1)) c ++ indent (i + 1) ++ "break;\n"
308+ tell $ indent i ++ "default:\n" ++ w ++ indent (i + 1) ++ "break;\n"
309+
252−bcc i (CONSTCASE r code def)
310+bcc ((CONSTCASE r code def):xs)
253 | intConsts code
311 | intConsts code
254−-- = indent i ++ "switch(GETINT(" ++ creg r ++ ")) {\n" ++
312+ = do
255−-- concatMap (showCase i) code ++
313+ is <- get
256−-- showDef i def ++
314+ let i = level is
257−-- indent i ++ "}\n"
315+ codes <- mapM getCode code
258− = concatMap (iCase (creg r)) code ++
316+ defs <- showDefS def
259− indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
317+ tell $ concatMap (iCase i (creg r)) codes
318+ tell $ indent i ++ "{\n" ++ defs ++ indent i ++ "}\n"
319+ bcc xs
260 | strConsts code
320 | strConsts code
321+ = do
322+ is <- get
323+ let i = level is
324+ codes <- mapM getCode code
325+ defs <- showDefS def
261− = concatMap (strCase ("GETSTR(" ++ creg r ++ ")")) code ++
326+ tell $ concatMap (strCase i ("GETSTR(" ++ creg r ++ ")")) codes
262− indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
327+ ++ indent i ++ "{\n" ++ defs ++ indent i ++ "}\n"
328+ bcc xs
263 | bigintConsts code
329 | bigintConsts code
330+ = do
331+ is <- get
332+ let i = level is
333+ codes <- mapM getCode code
334+ defs <- showDefS def
264− = concatMap (biCase (creg r)) code ++
335+ tell $ concatMap (biCase i (creg r)) codes ++
265− indent i ++ "{\n" ++ showDefS i def ++ indent i ++ "}\n"
336+ indent i ++ "{\n" ++ defs ++ indent i ++ "}\n"
337+ bcc xs
266 | otherwise = error $ "Can't happen: Can't compile const case " ++ show code
338 | otherwise = error $ "Can't happen: Can't compile const case " ++ show code
267 where
339 where
268 intConsts ((I _, _ ) : _) = True
340 intConsts ((I _, _ ) : _) = True
@@ -279,72 +351,119 @@ bcc i (CONSTCASE r code def)
279 strConsts ((Str _, _ ) : _) = True
351 strConsts ((Str _, _ ) : _) = True
280 strConsts _ = False
352 strConsts _ = False
281
353
354+ getCode (x, code) = do
355+ c <- getBC code xs
356+ return (x, c)
357+
282− strCase sv (s, bc) =
358+ strCase i sv (s, bc) =
283 indent i ++ "if (strcmp(" ++ sv ++ ", " ++ show s ++ ") == 0) {\n" ++
359 indent i ++ "if (strcmp(" ++ sv ++ ", " ++ show s ++ ") == 0) {\n" ++
284− concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
360+ bc ++ indent i ++ "} else\n"
285− biCase bv (BI b, bc) =
361+ biCase i bv (BI b, bc) =
286 indent i ++ "if (bigEqConst(" ++ bv ++ ", " ++ show b ++ ")) {\n"
362 indent i ++ "if (bigEqConst(" ++ bv ++ ", " ++ show b ++ ")) {\n"
287− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
363+ ++ bc ++ indent i ++ "} else\n"
288− iCase v (I b, bc) =
364+ iCase i v (I b, bc) =
289 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
365 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
290− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
366+ ++ bc ++ indent i ++ "} else\n"
291− iCase v (Ch b, bc) =
367+ iCase i v (Ch b, bc) =
292 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show (fromEnum b) ++ ") {\n"
368 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show (fromEnum b) ++ ") {\n"
293− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
369+ ++ bc ++ indent i ++ "} else\n"
294− iCase v (B8 w, bc) =
370+ iCase i v (B8 w, bc) =
295 indent i ++ "if (GETBITS8(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
371 indent i ++ "if (GETBITS8(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
296− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
372+ ++ bc ++ indent i ++ "} else\n"
297− iCase v (B16 w, bc) =
373+ iCase i v (B16 w, bc) =
298 indent i ++ "if (GETBITS16(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
374 indent i ++ "if (GETBITS16(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
299− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
375+ ++ bc ++ indent i ++ "} else\n"
300− iCase v (B32 w, bc) =
376+ iCase i v (B32 w, bc) =
301 indent i ++ "if (GETBITS32(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
377 indent i ++ "if (GETBITS32(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
302− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
378+ ++ bc ++ indent i ++ "} else\n"
303− iCase v (B64 w, bc) =
379+ iCase i v (B64 w, bc) =
304 indent i ++ "if (GETBITS64(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
380 indent i ++ "if (GETBITS64(" ++ v ++ ") == " ++ show (fromEnum w) ++ ") {\n"
305− ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
381+ ++ bc ++ indent i ++ "} else\n"
306− showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
382+
307− ++ concatMap (bcc (i+1)) bc ++
383+ showDefS Nothing = return ""
308− indent (i + 1) ++ "break;\n"
384+ showDefS (Just c) = getBC c xs
309− showDef i Nothing = ""
385+
310− showDef i (Just c) = indent i ++ "default:\n"
386+bcc (CALL n:xs) = do
311− ++ concatMap (bcc (i+1)) c ++
387+ i <- get
312− indent (i + 1) ++ "break;\n"
313− showDefS i Nothing = ""
314− showDefS i (Just c) = concatMap (bcc (i+1)) c
315−
316−bcc i (CALL n) = indent i ++ "CALL(" ++ cname n ++ ");\n"
388+ tell $ indent (level i) ++ "CALL(" ++ cname n ++ ");\n"
389+ bcc xs
390+bcc (TAILCALL n:xs) = do
391+ i <- get
317−bcc i (TAILCALL n) = indent i ++ "TAILCALL(" ++ cname n ++ ");\n"
392+ tell $ indent (level i) ++ "TAILCALL(" ++ cname n ++ ");\n"
393+ bcc xs
394+bcc ((SLIDE n):xs) = do
395+ i <- get
318−bcc i (SLIDE n) = indent i ++ "SLIDE(vm, " ++ show n ++ ");\n"
396+ tell $ indent (level i) ++ "SLIDE(vm, " ++ show n ++ ");\n"
397+ bcc xs
398+bcc (REBASE:xs) = do
399+ i <- get
319−bcc i REBASE = indent i ++ "REBASE;\n"
400+ tell $ indent (level i)++ "REBASE;\n"
401+ bcc xs
320−bcc i (RESERVE 0) = ""
402+bcc ((RESERVE 0):xs) = bcc xs
403+bcc ((RESERVE n):xs) = do
404+ i <- get
321−bcc i (RESERVE n) = indent i ++ "RESERVE(" ++ show n ++ ");\n"
405+ tell $ indent (level i) ++ "RESERVE(" ++ show n ++ ");\n"
406+ bcc xs
322−bcc i (ADDTOP 0) = ""
407+bcc ((ADDTOP 0):xs) = bcc xs
408+bcc ((ADDTOP n):xs) = do
409+ i <- get
323−bcc i (ADDTOP n) = indent i ++ "ADDTOP(" ++ show n ++ ");\n"
410+ tell $ indent (level i) ++ "ADDTOP(" ++ show n ++ ");\n"
411+ bcc xs
412+bcc ((TOPBASE n):xs) = do
413+ i <- get
324−bcc i (TOPBASE n) = indent i ++ "TOPBASE(" ++ show n ++ ");\n"
414+ tell $ indent (level i) ++ "TOPBASE(" ++ show n ++ ");\n"
415+ bcc xs
416+bcc ((BASETOP n):xs) = do
417+ i <- get
325−bcc i (BASETOP n) = indent i ++ "BASETOP(" ++ show n ++ ");\n"
418+ tell $ indent (level i) ++ "BASETOP(" ++ show n ++ ");\n"
419+ bcc xs
420+bcc (STOREOLD:xs) = do
421+ i <- get
326−bcc i STOREOLD = indent i ++ "STOREOLD;\n"
422+ tell $ indent (level i) ++ "STOREOLD;\n"
423+ bcc xs
424+bcc ((OP l fn args):xs) = do
425+ i <- get
327−bcc i (OP l fn args) = indent i ++ doOp (creg l ++ " = ") fn args ++ ";\n"
426+ tell $ indent (level i) ++ doOp (creg l ++ " = ") fn args ++ ";\n"
427+ bcc xs
328−bcc i (FOREIGNCALL l rty (FStr fn@('&':name)) [])
428+bcc ((FOREIGNCALL l rty (FStr fn@('&':name)) []):xs) = do
329− = indent i ++
429+ i <- get
330− c_irts (toFType rty) (creg l ++ " = ") fn ++ ";\n"
430+ tell $ indent (level i) ++ c_irts (toFType rty) (creg l ++ " = ") fn ++ ";\n"
431+ bcc xs
331−bcc i (FOREIGNCALL l rty (FStr fn) (x:xs)) | fn == "%wrapper"
432+bcc ((FOREIGNCALL l rty (FStr fn) (x:xs)):zs) | fn == "%wrapper"
332− = indent i ++
433+ = do
434+ i <- get
333− c_irts (toFType rty) (creg l ++ " = ")
435+ tell $ indent (level i) ++ c_irts (toFType rty) (creg l ++ " = ")
334 ("_idris_get_wrapper(" ++ creg (snd x) ++ ")") ++ ";\n"
436 ("_idris_get_wrapper(" ++ creg (snd x) ++ ")") ++ ";\n"
437+ bcc zs
335−bcc i (FOREIGNCALL l rty (FStr fn) (x:xs)) | fn == "%dynamic"
438+bcc ((FOREIGNCALL l rty (FStr fn) (x:xs)):zs) | fn == "%dynamic"
439+ = do
440+ i <- get
336− = indent i ++ c_irts (toFType rty) (creg l ++ " = ")
441+ tell $ indent (level i) ++ c_irts (toFType rty) (creg l ++ " = ")
337 ("(*(" ++ cFnSig "" rty xs ++ ") GETPTR(" ++ creg (snd x) ++ "))" ++
442 ("(*(" ++ cFnSig "" rty xs ++ ") GETPTR(" ++ creg (snd x) ++ "))" ++
338 "(" ++ showSep "," (map fcall xs) ++ ")") ++ ";\n"
443 "(" ++ showSep "," (map fcall xs) ++ ")") ++ ";\n"
444+ bcc zs
339−bcc i (FOREIGNCALL l rty (FStr fn) args)
445+bcc ((FOREIGNCALL l rty (FStr fn) args):xs) = do
340− = indent i ++
446+ i <- get
341− c_irts (toFType rty) (creg l ++ " = ")
447+ tell $ indent (level i) ++ c_irts (toFType rty) (creg l ++ " = ")
342− (fn ++ "(" ++ showSep "," (map fcall args) ++ ")") ++ ";\n"
448+ (fn ++ "(" ++ showSep "," (map fcall args) ++ ")") ++ ";\n"
449+ bcc xs
343−bcc i (FOREIGNCALL l rty _ args) = error "Foreign Function calls cannot be partially applied, without being inlined."
450+bcc ((FOREIGNCALL l rty _ args):_) = error "Foreign Function calls cannot be partially applied, without being inlined."
451+bcc ((NULL r):xs) = do
452+ i <- get
344−bcc i (NULL r) = indent i ++ creg r ++ " = NULL;\n" -- clear, so it'll be GCed
453+ tell $ indent (level i) ++ creg r ++ " = NULL;\n" -- clear, so it'll be GCed
454+ bcc xs
455+bcc ((ERROR str):xs) = do
456+ i <- get
457+ tell $ indent (level i) ++ "fprintf(stderr, "
345−bcc i (ERROR str) = indent i ++ "fprintf(stderr, " ++ show str ++ "); fprintf(stderr, \"\\n\"); exit(-1);\n"
458+ ++ show str ++ "); fprintf(stderr, \"\\n\"); exit(-1);\n"
459+ bcc xs
346-- bcc i c = error (show c) -- indent i ++ "// not done yet\n"
460-- bcc i c = error (show c) -- indent i ++ "// not done yet\n"
347
461
462+getBC code xs = do
463+ i <- get
464+ let (a, s, w) = runRWS (bcc code) 0 (i { level = level i + 1 })
465+ return w
466+
348fcall (t, arg) = irts_c (toFType t) (creg arg)
467fcall (t, arg) = irts_c (toFType t) (creg arg)
349-- Deconstruct the Foreign type in the defunctionalised expression and build
468-- Deconstruct the Foreign type in the defunctionalised expression and build
350-- a foreign type description for c_irts and irts_c
469-- a foreign type description for c_irts and irts_c
src/IRTS/Compiler.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE CPP, PatternGuards, TypeSynonymInstances #-}
8+{-# LANGUAGE CPP, FlexibleContexts, PatternGuards, TypeSynonymInstances #-}
9
9
10module IRTS.Compiler(compile, generate) where
10module IRTS.Compiler(compile, generate) where
11
11
src/IRTS/Defunctionalise.hs+1−1
@@ -19,7 +19,7 @@ To defunctionalise:
198. Add explicit EVAL to case, primitives, and foreign calls
198. Add explicit EVAL to case, primitives, and foreign calls
20
20
21-}
21-}
22−{-# LANGUAGE PatternGuards #-}
22+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
23module IRTS.Defunctionalise(module IRTS.Defunctionalise
23module IRTS.Defunctionalise(module IRTS.Defunctionalise
24 , module IRTS.Lang
24 , module IRTS.Lang
25 ) where
25 ) where
src/IRTS/Lang.hs+2−1
@@ -5,7 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, PatternGuards #-}
8+{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, FlexibleContexts,
9+ PatternGuards #-}
9
10
10module IRTS.Lang where
11module IRTS.Lang where
11
12
src/IRTS/Portable.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE OverloadedStrings #-}
8+{-# LANGUAGE FlexibleInstances, OverloadedStrings, TypeSynonymInstances #-}
9module IRTS.Portable (writePortable) where
9module IRTS.Portable (writePortable) where
10
10
11import Idris.Core.CaseTree
11import Idris.Core.CaseTree
src/IRTS/Simplified.hs+1
@@ -5,6 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE FlexibleContexts #-}
8module IRTS.Simplified(simplifyDefs, SDecl(..), SExp(..), SAlt(..)) where
9module IRTS.Simplified(simplifyDefs, SDecl(..), SExp(..), SAlt(..)) where
9
10
10import Idris.Core.CaseTree
11import Idris.Core.CaseTree
src/Idris/AbsSyntax.hs+1−1
@@ -6,7 +6,7 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9−{-# LANGUAGE DeriveFunctor, PatternGuards #-}
9+{-# LANGUAGE DeriveFunctor, FlexibleContexts, PatternGuards #-}
10
10
11module Idris.AbsSyntax(
11module Idris.AbsSyntax(
12 module Idris.AbsSyntax
12 module Idris.AbsSyntax
src/Idris/AbsSyntaxTree.hs+10−1
@@ -6,7 +6,9 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9−{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, PatternGuards #-}
9+{-# LANGUAGE DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric,
10+ DeriveTraversable, FlexibleContexts, FlexibleInstances,
11+ MultiParamTypeClasses, PatternGuards, TypeSynonymInstances #-}
10
12
11module Idris.AbsSyntaxTree where
13module Idris.AbsSyntaxTree where
12
14
@@ -1047,6 +1049,7 @@ mapPTermFC f g (PDoBlock dos) = PDoBlock (map mapPDoFC dos)
1047 DoBindP (f fc) (mapPTermFC f g t1) (mapPTermFC f g t2) (map (\(l,r)-> (mapPTermFC f g l, mapPTermFC f g r)) alts)
1049 DoBindP (f fc) (mapPTermFC f g t1) (mapPTermFC f g t2) (map (\(l,r)-> (mapPTermFC f g l, mapPTermFC f g r)) alts)
1048 mapPDoFC (DoLet fc n nfc t1 t2) = DoLet (f fc) n (g nfc) (mapPTermFC f g t1) (mapPTermFC f g t2)
1050 mapPDoFC (DoLet fc n nfc t1 t2) = DoLet (f fc) n (g nfc) (mapPTermFC f g t1) (mapPTermFC f g t2)
1049 mapPDoFC (DoLetP fc t1 t2) = DoLetP (f fc) (mapPTermFC f g t1) (mapPTermFC f g t2)
1051 mapPDoFC (DoLetP fc t1 t2) = DoLetP (f fc) (mapPTermFC f g t1) (mapPTermFC f g t2)
1052+ mapPDoFC (DoRewrite fc h) = DoRewrite (f fc) (mapPTermFC f g h)
1050mapPTermFC f g (PIdiom fc t) = PIdiom (f fc) (mapPTermFC f g t)
1053mapPTermFC f g (PIdiom fc t) = PIdiom (f fc) (mapPTermFC f g t)
1051mapPTermFC f g (PMetavar fc n) = PMetavar (g fc) n
1054mapPTermFC f g (PMetavar fc n) = PMetavar (g fc) n
1052mapPTermFC f g (PProof tacs) = PProof (map (fmap (mapPTermFC f g)) tacs)
1055mapPTermFC f g (PProof tacs) = PProof (map (fmap (mapPTermFC f g)) tacs)
@@ -1171,6 +1174,7 @@ data PDo' t = DoExp FC t
1171 | DoBindP FC t t [(t,t)]
1174 | DoBindP FC t t [(t,t)]
1172 | DoLet FC Name FC t t -- ^ second FC is precise name location
1175 | DoLet FC Name FC t t -- ^ second FC is precise name location
1173 | DoLetP FC t t
1176 | DoLetP FC t t
1177+ | DoRewrite FC t -- rewrite in do block
1174 deriving (Eq, Ord, Functor, Data, Generic, Typeable)
1178 deriving (Eq, Ord, Functor, Data, Generic, Typeable)
1175{-!
1179{-!
1176deriving instance Binary PDo'
1180deriving instance Binary PDo'
@@ -1182,6 +1186,7 @@ instance Sized a => Sized (PDo' a) where
1182 size (DoBindP fc l r alts) = 1 + size fc + size l + size r + size alts
1186 size (DoBindP fc l r alts) = 1 + size fc + size l + size r + size alts
1183 size (DoLet fc nm nfc l r) = 1 + size fc + size nm + size l + size r
1187 size (DoLet fc nm nfc l r) = 1 + size fc + size nm + size l + size r
1184 size (DoLetP fc l r) = 1 + size fc + size l + size r
1188 size (DoLetP fc l r) = 1 + size fc + size l + size r
1189+ size (DoRewrite fc h) = 1 + size fc + size h
1185
1190
1186type PDo = PDo' PTerm
1191type PDo = PDo' PTerm
1187
1192
@@ -1277,6 +1282,7 @@ highestFC (PDoBlock lines) =
1277 getDoFC (DoBindP fc l r alts) = fc
1282 getDoFC (DoBindP fc l r alts) = fc
1278 getDoFC (DoLet fc nm nfc l r) = fc
1283 getDoFC (DoLet fc nm nfc l r) = fc
1279 getDoFC (DoLetP fc l r) = fc
1284 getDoFC (DoLetP fc l r) = fc
1285+ getDoFC (DoRewrite fc h) = fc
1280
1286
1281highestFC (PIdiom fc _) = Just fc
1287highestFC (PIdiom fc _) = Just fc
1282highestFC (PMetavar fc _) = Just fc
1288highestFC (PMetavar fc _) = Just fc
@@ -1951,6 +1957,9 @@ pprintPTerm ppo bnd docArgs infixes = prettySe (ppopt_depth ppo) startPrec bnd
1951 ppdo bnd (DoLetP _ _ _ : dos) = -- ok because never made by delab
1957 ppdo bnd (DoLetP _ _ _ : dos) = -- ok because never made by delab
1952 text "no pretty printer for pattern-matching do binding" :
1958 text "no pretty printer for pattern-matching do binding" :
1953 ppdo bnd dos
1959 ppdo bnd dos
1960+ ppdo bnd (DoRewrite _ _ : dos) = -- ok because never made by delab
1961+ text "no pretty printer for pattern-matching do binding" :
1962+ ppdo bnd dos
1954 ppdo _ [] = []
1963 ppdo _ [] = []
1955 prettySe d p bnd (PCoerced t) = prettySe d p bnd t
1964 prettySe d p bnd (PCoerced t) = prettySe d p bnd t
1956 prettySe d p bnd (PElabError s) = pretty s
1965 prettySe d p bnd (PElabError s) = pretty s
src/Idris/Apropos.hs+1
@@ -5,6 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE FlexibleInstances #-}
8module Idris.Apropos (apropos, aproposModules) where
9module Idris.Apropos (apropos, aproposModules) where
9
10
10import Idris.AbsSyntax
11import Idris.AbsSyntax
src/Idris/CaseSplit.hs+1−1
@@ -17,7 +17,7 @@ Always take the "more specific" argument when there is a discrepancy, i.e.
17names over '_', patterns over names, etc.
17names over '_', patterns over names, etc.
18-}
18-}
19
19
20−{-# LANGUAGE PatternGuards #-}
20+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
21
21
22module Idris.CaseSplit(
22module Idris.CaseSplit(
23 splitOnLine, replaceSplits
23 splitOnLine, replaceSplits
src/Idris/Chaser.hs+2
@@ -5,6 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE FlexibleContexts #-}
9+
8module Idris.Chaser(
10module Idris.Chaser(
9 buildTree, getImports
11 buildTree, getImports
10 , getModuleFiles
12 , getModuleFiles
src/Idris/Core/Binary.hs+2
@@ -5,6 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE FlexibleInstances #-}
9+
8{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
9module Idris.Core.Binary where
11module Idris.Core.Binary where
10
12
src/Idris/Core/CaseTree.hs+2−2
@@ -18,8 +18,8 @@ allows casing on arbitrary terms, here we choose to maintain the distinction
18in order to allow for better optimisation opportunities.
18in order to allow for better optimisation opportunities.
19
19
20-}
20-}
21+{-# LANGUAGE DeriveFunctor, DeriveGeneric, FlexibleContexts, FlexibleInstances,
21−{-# LANGUAGE DeriveFunctor, DeriveGeneric, PatternGuards, TypeSynonymInstances
22+ PatternGuards, TypeSynonymInstances #-}
22− #-}
23
23
24module Idris.Core.CaseTree (
24module Idris.Core.CaseTree (
25 CaseDef(..), SC, SC'(..), CaseAlt, CaseAlt'(..), ErasureInfo
25 CaseDef(..), SC, SC'(..), CaseAlt, CaseAlt'(..), ErasureInfo
src/Idris/Core/DeepSeq.hs+2−1
@@ -5,7 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE BangPatterns, CPP, FlexibleInstances, TypeSynonymInstances,
8−{-# LANGUAGE BangPatterns, CPP, ViewPatterns #-}
9+ ViewPatterns #-}
9{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10
11
11module Idris.Core.DeepSeq where
12module Idris.Core.DeepSeq where
src/Idris/Core/ProofState.hs+2−1
@@ -10,7 +10,8 @@ proofs, and some high level commands for introducing new theorems,
10evaluation/checking inside the proof system, etc.
10evaluation/checking inside the proof system, etc.
11-}
11-}
12
12
13−{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, PatternGuards #-}
13+{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses,
14+ PatternGuards #-}
14module Idris.Core.ProofState(
15module Idris.Core.ProofState(
15 ProofState(..), newProof, envAtFocus, goalAtFocus
16 ProofState(..), newProof, envAtFocus, goalAtFocus
16 , Tactic(..), Goal(..), processTactic, nowElaboratingPS
17 , Tactic(..), Goal(..), processTactic, nowElaboratingPS
src/Idris/Core/TT.hs+4−2
@@ -22,8 +22,10 @@ TT is the core language of Idris. The language has:
22 * We have a simple collection of tactics which we use to elaborate source
22 * We have a simple collection of tactics which we use to elaborate source
23 programs with implicit syntax into fully explicit terms.
23 programs with implicit syntax into fully explicit terms.
24-}
24-}
25−{-# LANGUAGE DeriveDataTypeable, DeriveFunctor, DeriveGeneric, FlexibleContexts,
25+{-# LANGUAGE DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric,
26+ DeriveTraversable, FlexibleContexts, FlexibleInstances,
26− FunctionalDependencies, MultiParamTypeClasses, PatternGuards #-}
27+ FunctionalDependencies, MultiParamTypeClasses, PatternGuards,
28+ TypeSynonymInstances #-}
27{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
29{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
28module Idris.Core.TT(
30module Idris.Core.TT(
29 AppStatus(..), ArithTy(..), Binder(..), Const(..), Ctxt(..)
31 AppStatus(..), ArithTy(..), Binder(..), Const(..), Ctxt(..)
src/Idris/Core/Typecheck.hs+2−2
@@ -6,8 +6,8 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9−{-# LANGUAGE DeriveFunctor, FlexibleInstances, MultiParamTypeClasses,
9+{-# LANGUAGE DeriveFunctor, FlexibleContexts, FlexibleInstances,
10− PatternGuards #-}
10+ MultiParamTypeClasses, PatternGuards #-}
11
11
12module Idris.Core.Typecheck where
12module Idris.Core.Typecheck where
13
13
src/Idris/Core/Unify.hs+1−1
@@ -11,7 +11,7 @@ Returns a list of hole names paired with the term which solves them, and
11a list of things which need to be injective.
11a list of things which need to be injective.
12
12
13-}
13-}
14−{-# LANGUAGE PatternGuards #-}
14+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
15
15
16module Idris.Core.Unify(
16module Idris.Core.Unify(
17 match_unify, unify
17 match_unify, unify
src/Idris/Core/WHNF.hs+1−1
@@ -6,7 +6,7 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9−{-# LANGUAGE PatternGuards #-}
9+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
11module Idris.Core.WHNF(whnf, whnfArgs, WEnv) where
11module Idris.Core.WHNF(whnf, whnfArgs, WEnv) where
12
12
src/Idris/Coverage.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE PatternGuards #-}
8+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
9module Idris.Coverage(genClauses, validCoverageCase, recoverableCoverage,
9module Idris.Coverage(genClauses, validCoverageCase, recoverableCoverage,
10 mkPatTm) where
10 mkPatTm) where
11
11
src/Idris/DSL.hs+2
@@ -109,6 +109,8 @@ expandSugar dsl (PDoBlock ds)
109 = PLet fc n nfc ty tm (block b rest)
109 = PLet fc n nfc ty tm (block b rest)
110 block b (DoLetP fc p tm : rest)
110 block b (DoLetP fc p tm : rest)
111 = PCase fc tm [(p, block b rest)]
111 = PCase fc tm [(p, block b rest)]
112+ block b (DoRewrite fc h : rest)
113+ = PRewrite fc Nothing h (block b rest) Nothing
112 block b (DoExp fc tm : rest)
114 block b (DoExp fc tm : rest)
113 = PApp fc b
115 = PApp fc b
114 [pexp tm,
116 [pexp tm,
src/Idris/DataOpts.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE PatternGuards #-}
8+{-# LANGUAGE FlexibleInstances, PatternGuards #-}
9
9
10module Idris.DataOpts(applyOpts) where
10module Idris.DataOpts(applyOpts) where
11
11
src/Idris/Docstrings.hs+2−1
@@ -6,7 +6,8 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9−{-# LANGUAGE DeriveFunctor, DeriveGeneric, ScopedTypeVariables #-}
9+{-# LANGUAGE DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable,
10+ ScopedTypeVariables #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
11{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
11module Idris.Docstrings (
12module Idris.Docstrings (
12 Docstring(..), Block(..), Inline(..), parseDocstring, renderDocstring
13 Docstring(..), Block(..), Inline(..), parseDocstring, renderDocstring
src/Idris/Elab/Quasiquote.hs+1
@@ -75,6 +75,7 @@ extractDoUnquotes d (DoLet fc n nfc v b)
75 (b', ex2) <- extractUnquotes d b
75 (b', ex2) <- extractUnquotes d b
76 return (DoLet fc n nfc v' b', ex1 ++ ex2)
76 return (DoLet fc n nfc v' b', ex1 ++ ex2)
77extractDoUnquotes d (DoLetP fc t t') = fail "Pattern-matching lets cannot be quasiquoted"
77extractDoUnquotes d (DoLetP fc t t') = fail "Pattern-matching lets cannot be quasiquoted"
78+extractDoUnquotes d (DoRewrite fc h) = fail "Rewrites in Do block cannot be quasiquoted"
78
79
79
80
80extractUnquotes :: Int -> PTerm -> Elab' aux (PTerm, [(Name, PTerm)])
81extractUnquotes :: Int -> PTerm -> Elab' aux (PTerm, [(Name, PTerm)])
src/Idris/Elab/Utils.hs+7−6
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE PatternGuards #-}
8+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
9module Idris.Elab.Utils where
9module Idris.Elab.Utils where
10
10
11import Idris.AbsSyntax
11import Idris.AbsSyntax
@@ -449,9 +449,12 @@ displayWarnings est
449 = mapM_ displayImpWarning (implicit_warnings est)
449 = mapM_ displayImpWarning (implicit_warnings est)
450 where
450 where
451 displayImpWarning :: (FC, Name) -> Idris ()
451 displayImpWarning :: (FC, Name) -> Idris ()
452− displayImpWarning (fc, n) =
452+ displayImpWarning (fc, n) = do
453+ ist <- getIState
454+ let msg = show (nsroot n)
453− iputStrLn $ show fc ++ ":WARNING: " ++ show (nsroot n) ++ " is bound as an implicit\n"
455+ ++ " is bound as an implicit\n"
454− ++ "\tDid you mean to refer to " ++ show n ++ "?"
456+ ++ "\tDid you mean to refer to " ++ show n ++ "?"
457+ iWarn fc (pprintErr ist (Msg msg))
455
458
456propagateParams :: IState -> [Name] -> Type -> [Name] -> PTerm -> PTerm
459propagateParams :: IState -> [Name] -> Type -> [Name] -> PTerm -> PTerm
457propagateParams i ps t bound tm@(PApp _ (PRef fc hls n) args)
460propagateParams i ps t bound tm@(PApp _ (PRef fc hls n) args)
@@ -767,5 +770,3 @@ isPlausible ist var env n ty
767 collectConstraints env tcs t
770 collectConstraints env tcs t
768 | (V i, _) <- unApply t = (Just (env !! i), tcs)
771 | (V i, _) <- unApply t = (Just (env !! i), tcs)
769 | otherwise = (Nothing, tcs)
772 | otherwise = (Nothing, tcs)
770−
771−
src/Idris/Error.hs+1
@@ -138,6 +138,7 @@ warnDisamb ist (PDoBlock steps) = mapM_ wStep steps
138 mapM_ (\(x,y) -> warnDisamb ist x >> warnDisamb ist y) cs
138 mapM_ (\(x,y) -> warnDisamb ist x >> warnDisamb ist y) cs
139 wStep (DoLet _ _ _ x y) = warnDisamb ist x >> warnDisamb ist y
139 wStep (DoLet _ _ _ x y) = warnDisamb ist x >> warnDisamb ist y
140 wStep (DoLetP _ x y) = warnDisamb ist x >> warnDisamb ist y
140 wStep (DoLetP _ x y) = warnDisamb ist x >> warnDisamb ist y
141+ wStep (DoRewrite _ h) = warnDisamb ist h
141warnDisamb ist (PIdiom _ x) = warnDisamb ist x
142warnDisamb ist (PIdiom _ x) = warnDisamb ist x
142warnDisamb ist (PMetavar _ _) = return ()
143warnDisamb ist (PMetavar _ _) = return ()
143warnDisamb ist (PProof tacs) = mapM_ (Foldable.mapM_ (warnDisamb ist)) tacs
144warnDisamb ist (PProof tacs) = mapM_ (Foldable.mapM_ (warnDisamb ist)) tacs
src/Idris/IBC.hs+9−2
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE TypeSynonymInstances #-}
8+{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
9{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
9{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10
10
11module Idris.IBC (loadIBC, loadPkgIndex,
11module Idris.IBC (loadIBC, loadPkgIndex,
@@ -48,7 +48,7 @@ import System.Directory
48import System.FilePath
48import System.FilePath
49
49
50ibcVersion :: Word16
50ibcVersion :: Word16
51−ibcVersion = 160
51+ibcVersion = 161
52
52
53-- | When IBC is being loaded - we'll load different things (and omit
53-- | When IBC is being loaded - we'll load different things (and omit
54-- different structures/definitions) depending on which phase we're in.
54-- different structures/definitions) depending on which phase we're in.
@@ -2293,6 +2293,9 @@ instance (Binary t) => Binary (PDo' t) where
2293 put x1
2293 put x1
2294 put x2
2294 put x2
2295 put x3
2295 put x3
2296+ DoRewrite x1 x2 -> do putWord8 5
2297+ put x1
2298+ put x2
2296 get
2299 get
2297 = do i <- getWord8
2300 = do i <- getWord8
2298 case i of
2301 case i of
@@ -2319,6 +2322,10 @@ instance (Binary t) => Binary (PDo' t) where
2319 x2 <- get
2322 x2 <- get
2320 x3 <- get
2323 x3 <- get
2321 return (DoLetP x1 x2 x3)
2324 return (DoLetP x1 x2 x3)
2325+ 5 -> do
2326+ x1 <- get
2327+ x2 <- get
2328+ return (DoRewrite x1 x2)
2322 _ -> error "Corrupted binary data for PDo'"
2329 _ -> error "Corrupted binary data for PDo'"
2323
2330
2324
2331
src/Idris/IdrisDoc.hs+1
@@ -344,6 +344,7 @@ extractPDo (DoBindP _ p1 p2 ps) = let (ps1, ps2) = unzip ps
344 in concatMap extract (p1 : p2 : ps')
344 in concatMap extract (p1 : p2 : ps')
345extractPDo (DoLet _ n _ p1 p2) = n : concatMap extract [p1, p2]
345extractPDo (DoLet _ n _ p1 p2) = n : concatMap extract [p1, p2]
346extractPDo (DoLetP _ p1 p2) = concatMap extract [p1, p2]
346extractPDo (DoLetP _ p1 p2) = concatMap extract [p1, p2]
347+extractPDo (DoRewrite _ p) = extract p
347
348
348-- | Helper function for extractPTermNames
349-- | Helper function for extractPTermNames
349extractPTactic :: PTactic -> [Name]
350extractPTactic :: PTactic -> [Name]
src/Idris/Output.hs+1
@@ -6,6 +6,7 @@ License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8
8
9+{-# LANGUAGE FlexibleInstances #-}
9{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
10
11
11module Idris.Output where
12module Idris.Output where
src/Idris/Package/Parser.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE CPP, ConstraintKinds #-}
8+{-# LANGUAGE CPP, ConstraintKinds, FlexibleInstances, TypeSynonymInstances #-}
9module Idris.Package.Parser where
9module Idris.Package.Parser where
10
10
11import Idris.AbsSyntaxTree
11import Idris.AbsSyntaxTree
src/Idris/Parser.hs+7−2
@@ -5,7 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE ConstraintKinds, GeneralizedNewtypeDeriving, PatternGuards #-}
8+{-# LANGUAGE ConstraintKinds, FlexibleContexts, GeneralizedNewtypeDeriving,
9+ PatternGuards #-}
9{-# OPTIONS_GHC -O0 #-}
10{-# OPTIONS_GHC -O0 #-}
10module Idris.Parser(module Idris.Parser,
11module Idris.Parser(module Idris.Parser,
11 module Idris.Parser.Expr,
12 module Idris.Parser.Expr,
@@ -1569,7 +1570,8 @@ parseImports fname input
1569 [ImportInfo],
1570 [ImportInfo],
1570 Maybe Delta),
1571 Maybe Delta),
1571 [(FC, OutputAnnotation)], IState)
1572 [(FC, OutputAnnotation)], IState)
1573+ imports = do optional shebang
1572− imports = do whiteSpace
1574+ whiteSpace
1573 (mdoc, mname, annots) <- moduleHeader
1575 (mdoc, mname, annots) <- moduleHeader
1574 ps_exp <- many import_
1576 ps_exp <- many import_
1575 mrk <- mark
1577 mrk <- mark
@@ -1594,6 +1596,9 @@ parseImports fname input
1594 (fc, AnnNamespace ns (Just path)) : addPath annots path
1596 (fc, AnnNamespace ns (Just path)) : addPath annots path
1595 addPath (annot:annots) path = annot : addPath annots path
1597 addPath (annot:annots) path = annot : addPath annots path
1596
1598
1599+ shebang :: IdrisParser ()
1600+ shebang = string "#!" *> many (satisfy $ not . isEol) *> eol *> pure ()
1601+
1597-- | There should be a better way of doing this...
1602-- | There should be a better way of doing this...
1598findFC :: Doc -> (FC, String)
1603findFC :: Doc -> (FC, String)
1599findFC x = let s = show (plain x) in findFC' s
1604findFC x = let s = show (plain x) in findFC' s
src/Idris/Parser/Expr.hs+7
@@ -234,6 +234,7 @@ updateSynMatch = update
234 = DoBindP fc (update ns i) (update ns t)
234 = DoBindP fc (update ns i) (update ns t)
235 (map (\(l,r) -> (update ns l, update ns r)) ts)
235 (map (\(l,r) -> (update ns l, update ns r)) ts)
236 upd ns (DoLetP fc i t) = DoLetP fc (update ns i) (update ns t)
236 upd ns (DoLetP fc i t) = DoLetP fc (update ns i) (update ns t)
237+ upd ns (DoRewrite fc h) = DoRewrite fc (update ns h)
237 update ns (PIdiom fc t) = PIdiom fc $ update ns t
238 update ns (PIdiom fc t) = PIdiom fc $ update ns t
238 update ns (PMetavar fc n) = uncurry (flip PMetavar) $ updateB ns (n, fc)
239 update ns (PMetavar fc n) = uncurry (flip PMetavar) $ updateB ns (n, fc)
239 update ns (PProof tacs) = PProof $ map (updTactic ns) tacs
240 update ns (PProof tacs) = PProof $ map (updTactic ns) tacs
@@ -1343,6 +1344,7 @@ doBlock syn
1343Do ::=
1344Do ::=
1344 'let' Name TypeSig'? '=' Expr
1345 'let' Name TypeSig'? '=' Expr
1345 | 'let' Expr' '=' Expr
1346 | 'let' Expr' '=' Expr
1347+ | 'rewrite Expr
1346 | Name '<-' Expr
1348 | Name '<-' Expr
1347 | Expr' '<-' Expr
1349 | Expr' '<-' Expr
1348 | Expr
1350 | Expr
@@ -1367,6 +1369,11 @@ do_ syn
1367 sc <- expr syn
1369 sc <- expr syn
1368 highlightP kw AnnKeyword
1370 highlightP kw AnnKeyword
1369 return (DoLetP fc i sc))
1371 return (DoLetP fc i sc))
1372+ <|> try (do kw <- reservedFC "rewrite"
1373+ fc <- getFC
1374+ sc <- expr syn
1375+ highlightP kw AnnKeyword
1376+ return (DoRewrite fc sc))
1370 <|> try (do (i, ifc) <- name
1377 <|> try (do (i, ifc) <- name
1371 symbol "<-"
1378 symbol "<-"
1372 fc <- getFC
1379 fc <- getFC
src/Idris/Parser/Helpers.hs+3−2
@@ -5,8 +5,9 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+{-# LANGUAGE CPP, ConstraintKinds, FlexibleInstances,
8−{-# LANGUAGE CPP, ConstraintKinds, GeneralizedNewtypeDeriving, PatternGuards,
9+ GeneralizedNewtypeDeriving, PatternGuards, StandaloneDeriving,
9− StandaloneDeriving #-}
10+ TypeSynonymInstances #-}
10module Idris.Parser.Helpers where
11module Idris.Parser.Helpers where
11
12
12import Idris.AbsSyntax
13import Idris.AbsSyntax
src/Idris/Parser/Ops.hs+2−1
@@ -5,7 +5,8 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE ConstraintKinds, GeneralizedNewtypeDeriving, PatternGuards #-}
8+{-# LANGUAGE ConstraintKinds, FlexibleContexts, GeneralizedNewtypeDeriving,
9+ PatternGuards #-}
9module Idris.Parser.Ops where
10module Idris.Parser.Ops where
10
11
11import Idris.AbsSyntax
12import Idris.AbsSyntax
src/Idris/PartialEval.hs+1−1
@@ -5,7 +5,7 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8−{-# LANGUAGE PatternGuards #-}
8+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
9
9
10module Idris.PartialEval(
10module Idris.PartialEval(
11 partial_eval, getSpecApps, specType
11 partial_eval, getSpecApps, specType
src/Idris/Prover.hs+1
@@ -350,6 +350,7 @@ elabloop info fn d prompt prf e prev h env
350 Success (Right cmd') ->
350 Success (Right cmd') ->
351 case cmd' of
351 case cmd' of
352 DoLetP {} -> ifail "Pattern-matching let not supported here"
352 DoLetP {} -> ifail "Pattern-matching let not supported here"
353+ DoRewrite {} -> ifail "Pattern-matching do-rewrite not supported here"
353 DoBindP {} -> ifail "Pattern-matching <- not supported here"
354 DoBindP {} -> ifail "Pattern-matching <- not supported here"
354 DoLet fc i ifc Placeholder expr ->
355 DoLet fc i ifc Placeholder expr ->
355 do (tm, ty) <- elabVal (recinfo proverfc) ERHS (inLets ist env expr)
356 do (tm, ty) <- elabVal (recinfo proverfc) ERHS (inLets ist env expr)
src/Idris/REPL.hs+1−1
@@ -5,7 +5,7 @@ License : BSD3
5Maintainer : The Idris Community.
5Maintainer : The Idris Community.
6-}
6-}
7
7
8−{-# LANGUAGE PatternGuards #-}
8+{-# LANGUAGE FlexibleContexts, PatternGuards #-}
9
9
10module Idris.REPL
10module Idris.REPL
11 ( idemodeStart
11 ( idemodeStart
src/Util/Pretty.hs+3
@@ -5,6 +5,9 @@ Copyright :
5License : BSD3
5License : BSD3
6Maintainer : The Idris Community.
6Maintainer : The Idris Community.
7-}
7-}
8+
9+{-# LANGUAGE MultiParamTypeClasses #-}
10+
8module Util.Pretty (
11module Util.Pretty (
9 module Text.PrettyPrint.Annotated.Leijen
12 module Text.PrettyPrint.Annotated.Leijen
10 , Sized(..)
13 , Sized(..)
stack-shell.nix+1−1
@@ -2,7 +2,7 @@ with (import <nixpkgs> {});
2
2
3let
3let
4 # MUST match resolver in stack.yaml
4 # MUST match resolver in stack.yaml
5− resolver = haskell.packages.lts-8_18.ghc;
5+ resolver = haskell.packages.lts-9_0.ghc;
6
6
7 native_libs = [
7 native_libs = [
8 libffi
8 libffi
stack.yaml+1−1
@@ -1,4 +1,4 @@
1−resolver: lts-8.18
1+resolver: lts-9.0
2
2
3packages:
3packages:
4 - location: .
4 - location: .
test/basic009/expected+1−1
@@ -1,5 +1,5 @@
1MAIN-PASS
1MAIN-PASS
2−Faulty.idr:6:9-12:WARNING: num is bound as an implicit
2+Faulty.idr:6:9-12:num is bound as an implicit
3 Did you mean to refer to A.num?
3 Did you mean to refer to A.num?
4Faulty.idr:7:7:When checking right hand side of fault with expected type
4Faulty.idr:7:7:When checking right hand side of fault with expected type
5 num = 0
5 num = 0
test/basic018/expected+4−2
@@ -1,6 +1,8 @@
1+basic018.idr:7:12-17:
1−basic018.idr:7:12-17:WARNING: thing is bound as an implicit
2+thing is bound as an implicit
2 Did you mean to refer to Main.thing?
3 Did you mean to refer to Main.thing?
4+basic018.idr:12:8-13:
3−basic018.idr:12:8-13:WARNING: thing is bound as an implicit
5+thing is bound as an implicit
4 Did you mean to refer to Main.thing?
6 Did you mean to refer to Main.thing?
5basic018.idr:13:6:When checking right hand side of test with expected type
7basic018.idr:13:6:When checking right hand side of test with expected type
6 thing = S 41
8 thing = S 41
test/interactive017/TestMod.idrnew file+5
@@ -0,0 +1,5 @@
1+module TestMod
2+
3+export
4+test : IO ()
5+test = putStrLn "Hello from a module"
test/interactive017/expectednew file+7
@@ -0,0 +1,7 @@
1+hello from C
2+hello from C
3+hello from node
4+hello from node
5+Hello ["aaa"]
6+Hello ["bbb", "aaa"]
7+Hello from a module
test/interactive017/runnew file+9
@@ -0,0 +1,9 @@
1+#!/bin/sh
2+PATH="../../scripts:$PATH"
3+./shebang.idr
4+./shebang.idr
5+./shebang-node.idr
6+./shebang-node.idr
7+./shebang-args.idr aaa
8+./shebang-args.idr bbb aaa
9+./shebang-import.idr
test/interactive017/shebang-args.idrnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env runidris
2+
3+main : IO ()
4+main = do
5+ args <- getArgs
6+ putStrLn $ "Hello " ++ (show $ drop 1 args)
test/interactive017/shebang-import.idrnew file+6
@@ -0,0 +1,6 @@
1+#!/usr/bin/env runidris
2+
3+import TestMod
4+
5+main : IO ()
6+main = TestMod.test
test/interactive017/shebang-node.idrnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env runidris-node
2+
3+main : IO ()
4+main = putStrLn "hello from node"
test/interactive017/shebang.idrnew file+4
@@ -0,0 +1,4 @@
1+#!/usr/bin/env runidris
2+
3+main : IO ()
4+main = putStrLn "hello from C"
test/regression002/expected+2−1
@@ -110,7 +110,8 @@ reg068.idr:1:6:Main.nat has a name which may be implicitly bound.
110This is likely to lead to problems!
110This is likely to lead to problems!
111reg068.idr:2:6:Main.ze has a name which may be implicitly bound.
111reg068.idr:2:6:Main.ze has a name which may be implicitly bound.
112This is likely to lead to problems!
112This is likely to lead to problems!
113+reg068.idr:2:8-11:
113−reg068.idr:2:8-11:WARNING: nat is bound as an implicit
114+nat is bound as an implicit
114 Did you mean to refer to Main.nat?
115 Did you mean to refer to Main.nat?
115reg068.idr:2:6:When checking constructor Main.ze:
116reg068.idr:2:6:When checking constructor Main.ze:
116Type level variable nat is not Main.nat
117Type level variable nat is not Main.nat