on master help sign in
Merge branch 'master' into agda-style-records
commit681d876dfdd0b3360a1e6e1df5037da80c2e3ed8 authorSune Alkærsig <sual@itu.dk> dateMon 2 Mar 2015, 05:46 (12 years ago) parent6f0aff341711c7
80 files changed+1970−826
.gitignore+2 .travis.yml+6 CHANGELOG+11 CITATION.md+29 CONTRIBUTORS+3−2 Setup.hs+1−1 contribs/lib/SQLite3/Makefile+2−3 contribs/lib/SQLite3/Sqlite3.idr+42−48 idris.cabal+10−1 jsrts/Runtime-common.js+11−13 libs/base/Data/Sign.idr+1−1 libs/base/Data/ZZ.idr+1 libs/base/Network/Socket.idr+1−1 libs/base/System/Concurrency/Process.idr+11 libs/base/System/Concurrency/Raw.idr+49−4 libs/effects/Effects.idr+1 libs/prelude/Builtins.idr+10 libs/prelude/Language/Reflection.idr+23−3 libs/prelude/Language/Reflection/Tactical.idr+95 libs/prelude/Prelude/Foldable.idr+1−1 libs/prelude/Prelude/Strings.idr+88−59 libs/prelude/prelude.ipkg+1−1 rts/Makefile+1−1 rts/idris_gc.c+4−2 rts/idris_gmp.c+12−2 rts/idris_rts.c+88−30 rts/idris_rts.h+29−9 rts/windows/idris_stdfgn.c+10−3 rts/windows/win_utils.c+21 src/IRTS/Lang.hs+4−1 src/Idris/AbsSyntax.hs+29−11 src/Idris/AbsSyntaxTree.hs+31−10 src/Idris/CmdOptions.hs+5−3 src/Idris/Core/Elaborate.hs+18−17 src/Idris/Core/Evaluate.hs+29−24 src/Idris/Core/ProofState.hs+34−29 src/Idris/Core/ProofTerm.hs+37−14 src/Idris/Core/TT.hs+3 src/Idris/Core/Unify.hs+3−3 src/Idris/Coverage.hs+10−11 src/Idris/DSL.hs+2 src/Idris/DeepSeq.hs+8−4 src/Idris/Delaborate.hs+2−2 src/Idris/Elab/Clause.hs+43−25 src/Idris/Elab/Data.hs+4−2 src/Idris/Elab/Provider.hs+16−10 src/Idris/Elab/Utils.hs+2−2 src/Idris/ElabQuasiquote.hs+3 src/Idris/ElabTerm.hs+493−174 src/Idris/Erasure.hs+1 src/Idris/Error.hs+3 src/Idris/IBC.hs+169−15 src/Idris/IdeSlave.hs → src/Idris/IdeMode.hs+33−29 src/Idris/IdrisDoc.hs+1 src/Idris/Interactive.hs+3−3 src/Idris/Output.hs+24−22 src/Idris/ParseExpr.hs+20−1 src/Idris/ParseHelpers.hs+16−16 src/Idris/Parser.hs+29−6 src/Idris/Prover.hs+18−18 src/Idris/REPL.hs+190−175 src/Idris/TypeSearch.hs+10−2 src/Pkg/PParser.hs+2−2 src/Util/System.hs+5−1 test/proof008/ClaimAndUnfocus.idr+17 test/proof008/expected test/proof008/run+3 test/quasiquote005/Quasiquote005.idr+22 test/quasiquote005/expected test/quasiquote005/run+3 test/reg050/expected+2−1 test/reg058/expected test/reg058/implicits.idr+14 test/reg058/implicits2.idr+19 test/reg058/run+5 test/totality006/expected+1 test/totality006/run+1 test/totality006/totality006b.idr+14 test/unique001/expected+1−1 test/unique001/unique001c.idr+4−7
.gitignore+2
@@ -14,6 +14,8 @@ cabal.sandbox.config
1414.DS_Store
1515.hpc
1616*.tix
17+.projectile
18+.dir-locals.el
1719custom.mk
1820libs/base/base_doc/
1921libs/effects/effects_doc/
.travis.yml+6
@@ -1,4 +1,10 @@
11language: haskell
2+ghc:
3+ # Idris won't build on 7.4 and earlier due to dependency
4+ # problems. 7.10 isn't yet supported on Travis.
5+ - 7.6
6+ - 7.8
7+
28before_install:
39 - sudo add-apt-repository --yes ppa:h-rayflood/llvm
410 - sudo apt-get update -qq
CHANGELOG+11
@@ -1,3 +1,14 @@
1+New in 0.9.17:
2+--------------
3+* The --ideslave command line option has been replaced with a --ide-mode
4+ command line option with the same semantics.
5+* A new tactic "claim N TY" that introduces a new hole named N with type TY
6+* A new tactic "unfocus" that moves the current hole to the bottom of the
7+ hole stack
8+* Quasiquotation supports the generation of Language.Reflection.Raw terms
9+ in addition to Language.Reflection.TT. Types are used for disambiguation,
10+ defaulting to TT at the REPL.
11+
112New in 0.9.16:
213--------------
314* Inductive-inductive definitions are now supported (i.e. simultaneously
CITATION.mdnew file+29
@@ -0,0 +1,29 @@
1+# Citing `Idris`
2+
3+If you use `Idris` in your work we would prefer it if you would use the following reference in your work.
4+
5+## BibTeX
6+
7+```bibtex
8+@article{JFP:9060502,
9+ author = {BRADY,EDWIN},
10+ title = {Idris, a general-purpose dependently typed programming language: Design and implementation},
11+ journal = {Journal of Functional Programming},
12+ volume = {23},
13+ issue = {05},
14+ month = {9},
15+ year = {2013},
16+ issn = {1469-7653},
17+ pages = {552--593},
18+ numpages = {42},
19+ doi = {10.1017/S095679681300018X},
20+ URL = {http://journals.cambridge.org/article_S095679681300018X},
21+}
22+```
23+
24+## Textual
25+
26+ EDWIN BRADY (2013). Idris, a general-purpose dependently typed
27+ programming language: Design and implementation. Journal of
28+ Functional Programming, 23, pp
29+ 552-593. doi:10.1017/S095679681300018X.
CONTRIBUTORS+3−2
@@ -7,6 +7,8 @@ Jan Bessai
77Michael R. Bernstein
88Nicola Botta
99Edwin Brady
10+Jakob Brünker
11+Alyssa Carter
1012David Raymond Christiansen
1113Carter Charbonneau
1214Jason Dagit
@@ -28,6 +30,7 @@ Philip Rasmussen
2830Reynir Reynisson
2931Seo Sanghyeon
3032Benjamin Saunders
33+Alexander Shabalin
3134startling
3235Chetan T
3336Matúš Tejiščák
@@ -35,5 +38,3 @@ Dirk Ullrich
3538Leif Warner
3639Daniel Waterworth
3740Jonas Westerlund
38−Alyssa Carter
39−Alexander Shabalin
Setup.hs+1−1
@@ -106,7 +106,7 @@ generateVersionModule verbosity dir release = do
106106 "gitHash :: String\n" ++
107107 if release
108108 then "gitHash = \"\"\n"
109− else "gitHash = \"-git:" ++ h ++ "\"\n"
109+ else "gitHash = \"git:" ++ h ++ "\"\n"
110110
111111-- Generate a module that contains the lib path for a freestanding Idris
112112generateTargetModule verbosity dir targetDir = do
contribs/lib/SQLite3/Makefile+2−3
@@ -7,10 +7,9 @@ sqltest : testunit.idr Sqlite3.idr sqlite3api.o
77 idris testunit.idr -o sqltest
88
99sqlite3api.o : sqlite3api.c
10− gcc -c sqlite3api.c
10+ gcc -I . -c sqlite3api.c
1111
1212sqlite3api.so: sqlite3api.c
13− gcc -fPIC -o sqlite3api.so -shared sqlite3api.c
13+ gcc -I . -fPIC -o sqlite3api.so -shared sqlite3api.c
1414
1515all : sqltest sqlite3api.o
16−
contribs/lib/SQLite3/Sqlite3.idr+42−48
@@ -1,8 +1,9 @@
11module Sqlite3
2−import Sqlexpr
3−
2+import public Sqlexpr
43
54%lib C "sqlite3"
5+-- %link C "sqlite3.o"
6+-- %include C "sqlite3.h"
67%link C "sqlite3api.o"
78%include C "sqlite3api.h"
89
@@ -59,7 +60,7 @@ instance Monad DB where
5960 Left err => return (Left err)
6061 Right v => case k v of
6162 MkDB k' => k')
62− return x = MkDB (return (Right x))
63+ --return x = MkDB (return (Right x))
6364
6465fail : String -> DB a
6566fail err = MkDB (return (Left err))
@@ -83,7 +84,7 @@ runDB (MkDB f) = do f' <- f
8384-----------------------------------------------------------------------------
8485
8586open_db : String -> DB DBPointer
86−open_db name = do x <- liftIO (mkForeign (FFun "sqlite3_open_idr" [FString] FPtr) name)
87+open_db name = do x <- liftIO (foreign FFI_C "sqlite3_open_idr" (String -> IO Ptr) name)
8788 return (MkDBPointer x)
8889
8990-----------------------------------------------------------------------------
@@ -91,7 +92,7 @@ open_db name = do x <- liftIO (mkForeign (FFun "sqlite3_open_idr" [FString] FPtr
9192-----------------------------------------------------------------------------
9293
9394close_db : DBPointer -> DB Int
94−close_db (MkDBPointer pointer) = liftIO (mkForeign (FFun "sqlite3_close_idr" [FPtr] FInt) pointer)
95+close_db (MkDBPointer pointer) = liftIO (foreign FFI_C "sqlite3_close_idr" (Ptr -> IO Int) pointer)
9596
9697-----------------------------------------------------------------------------
9798-- | Wrapper around prepare, step and finalize.
@@ -99,7 +100,7 @@ close_db (MkDBPointer pointer) = liftIO (mkForeign (FFun "sqlite3_close_idr" [FP
99100
100101exec_db : DBPointer -> String -> DB Int
101102exec_db (MkDBPointer pointer) stmt = do
102− x <- liftIO (mkForeign (FFun "sqlite3_exec_idr" [FPtr, FString] FInt) pointer stmt)
103+ x <- liftIO (foreign FFI_C "sqlite3_exec_idr" (Ptr -> String -> IO Int) pointer stmt)
103104 if (x == 1)
104105 then fail "Could not execute."
105106 else return x
@@ -110,7 +111,7 @@ exec_db (MkDBPointer pointer) stmt = do
110111
111112exec_db_v2 : StmtPtr -> DB Int
112113exec_db_v2 (MkStmtPtr pointer) = do
113− x <- liftIO (mkForeign (FFun "exec_db" [FPtr] FInt) pointer)
114+ x <- liftIO (foreign FFI_C "exec_db" (Ptr -> IO Int) pointer)
114115 if (x == 21)
115116 then fail "No data returned."
116117 else return x
@@ -122,8 +123,7 @@ exec_db_v2 (MkStmtPtr pointer) = do
122123-----------------------------------------------------------------------------
123124
124125get_error : DBPointer -> IO String
125−get_error (MkDBPointer pointer) = mkForeign (FFun "sqlite3_get_error" [FPtr] FString) pointer
126−
126+get_error (MkDBPointer pointer) = foreign FFI_C "sqlite3_get_error" (Ptr -> IO String) pointer
127127
128128-----------------------------------------------------------------------------
129129-- | Compiles the query inot a byte-code program in order to execute it.
@@ -133,7 +133,7 @@ get_error (MkDBPointer pointer) = mkForeign (FFun "sqlite3_get_error" [FPtr] FSt
133133
134134prepare_db : DBPointer -> String -> DB StmtPtr
135135prepare_db (MkDBPointer pointer) cmd = do
136− result <- liftIO (mkForeign (FFun "sqlite3_prepare_idr" [FPtr, FString] FPtr) pointer cmd)
136+ result <- liftIO (foreign FFI_C "sqlite3_prepare_idr" (Ptr -> String -> IO Ptr) pointer cmd)
137137 flag <- liftIO (nullPtr result)
138138 if flag
139139 then fail "Error occured while preparing"
@@ -147,8 +147,8 @@ prepare_db (MkDBPointer pointer) cmd = do
147147
148148step_db : StmtPtr -> DB Int
149149step_db (MkStmtPtr pointer)= do
150− x <- liftIO (mkForeign (FFun "sqlite3_step_idr" [FPtr] FInt)pointer)
151− if ( x == 101)
150+ x <- liftIO (foreign FFI_C "sqlite3_step_idr" (Ptr -> IO Int) pointer)
151+ if (x == 101)
152152 then fail "SQLITE_DONE"
153153 else return x
154154
@@ -159,7 +159,7 @@ step_db (MkStmtPtr pointer)= do
159159
160160finalize_db : StmtPtr -> DB Int
161161finalize_db (MkStmtPtr pointer) = do
162− x <- liftIO (mkForeign (FFun "sqlite3_finalize_idr" [FPtr] FInt) pointer)
162+ x <- liftIO (foreign FFI_C "sqlite3_finalize_idr" (Ptr -> IO Int) pointer)
163163 if (x /= 0)
164164 then fail "Could not finalize"
165165 else return x
@@ -170,7 +170,7 @@ finalize_db (MkStmtPtr pointer) = do
170170
171171reset_db : StmtPtr -> DB Int
172172reset_db (MkStmtPtr pointer) = do
173− x <- liftIO (mkForeign (FFun "sqlite3_reset_idr" [FPtr] FInt) pointer)
173+ x <- liftIO (foreign FFI_C "sqlite3_reset_idr" (Ptr -> IO Int) pointer)
174174 if (x /= 0)
175175 then fail "Could not reset"
176176 else return x
@@ -181,38 +181,34 @@ reset_db (MkStmtPtr pointer) = do
181181
182182column_count : DBPointer -> IO (Either String Int)
183183column_count (MkDBPointer pointer) = do
184− x <- mkForeign (FFun "sqlite3_column_count_idr" [FPtr] FInt) pointer
185− return $ if (x == 0 )
184+ x <- foreign FFI_C "sqlite3_column_count_idr" (Ptr -> IO Int) pointer
185+ return $ if (x == 0)
186186 then Left "No Data"
187187 else (Right x)
188188
189189column_name : DBPointer -> Int -> IO String
190190column_name (MkDBPointer pointer) iCol =
191− mkForeign (FFun "sqlite3_column_name_idr" [FPtr, FInt] FString) pointer iCol
191+ foreign FFI_C "sqlite3_column_name_idr" (Ptr -> Int -> IO String) pointer iCol
192192
193193column_decltype : DBPointer -> Int -> IO String
194194column_decltype (MkDBPointer pointer) iCol =
195− mkForeign (FFun "sqlite3_column_decltype_idr" [FPtr, FInt] FString) pointer iCol
196−
195+ foreign FFI_C "sqlite3_column_decltype_idr" (Ptr -> Int -> IO String) pointer iCol
197196
198197column_bytes : DBPointer -> Int -> IO Int
199198column_bytes (MkDBPointer pointer) iCol =
200− mkForeign (FFun "sqlite3_column_bytes_idr" [FPtr, FInt] FInt) pointer iCol
201−
199+ foreign FFI_C "sqlite3_column_bytes_idr" (Ptr -> Int -> IO Int) pointer iCol
202200
203201column_blob : DBPointer -> Int -> IO String
204202column_blob (MkDBPointer pointer) iCol =
205− mkForeign (FFun "sqlite3_column_bytes_idr" [FPtr, FInt] FString) pointer iCol
206−
203+ foreign FFI_C "sqlite3_column_bytes_idr" (Ptr -> Int -> IO String) pointer iCol
207204
208205column_text : DBPointer -> Int -> IO String
209206column_text (MkDBPointer pointer) iCol =
210− mkForeign (FFun "sqlite3_column_text_idr" [FPtr, FInt] FString) pointer iCol
211−
207+ foreign FFI_C "sqlite3_column_text_idr" (Ptr -> Int -> IO String) pointer iCol
212208
213209column_Int : DBPointer -> Int -> IO Int
214210column_Int (MkDBPointer pointer) iCol =
215− mkForeign (FFun "sqlite3_column_int_idr" [FPtr, FInt] FInt) pointer iCol
211+ foreign FFI_C "sqlite3_column_int_idr" (Ptr -> Int -> IO Int) pointer iCol
216212
217213-----------------------------------------------------------------------------
218214-- | These routines support some of SQLite backup functions.
@@ -220,22 +216,21 @@ column_Int (MkDBPointer pointer) iCol =
220216
221217backup_init : DBPointer -> String -> DBPointer -> String -> IO DBPointer
222218backup_init (MkDBPointer des_pointer) destName (MkDBPointer src_pointer) srcName =
223− do x <- mkForeign (FFun "sqlite3_backup_init_idr" [FPtr,FString, FPtr, FString] FPtr)
219+ do x <- foreign FFI_C "sqlite3_backup_init_idr" (Ptr -> String -> Ptr -> String -> IO Ptr)
224220 des_pointer destName src_pointer srcName
225221 return (MkDBPointer x)
226222
227223backup_step : DBPointer -> Int -> IO Int
228224backup_step (MkDBPointer pointer) nPage =
229− mkForeign (FFun "sqlite3_backup_step_idr" [FPtr, FInt] FInt) pointer nPage
225+ foreign FFI_C "sqlite3_backup_step_idr" (Ptr -> Int -> IO Int) pointer nPage
230226
231227backup_finish : DBPointer -> IO Int
232228backup_finish (MkDBPointer pointer) =
233− mkForeign (FFun "sqlite3_backup_finish_idr" [FPtr] FInt) pointer
229+ foreign FFI_C "sqlite3_backup_finish_idr" (Ptr -> IO Int) pointer
234230
235231backup_remaining : DBPointer -> IO Int
236232backup_remaining (MkDBPointer pointer) =
237− mkForeign (FFun "sqlite3_backup_remaining_idr" [FPtr] FInt) pointer
238−
233+ foreign FFI_C "sqlite3_backup_remaining_idr" (Ptr -> IO Int) pointer
239234
240235-----------------------------------------------------------------------------
241236-- | Use of this interface is not recommended.
@@ -246,19 +241,18 @@ backup_remaining (MkDBPointer pointer) =
246241
247242get_table : DBPointer -> String -> DB TBPointer
248243get_table (MkDBPointer pointer) name = do
249− x <- liftIO(mkForeign (FFun "sqlite3_get_table_idr" [FPtr, FString] FPtr) pointer name)
244+ x <- liftIO(foreign FFI_C "sqlite3_get_table_idr" (Ptr -> String -> IO Ptr) pointer name)
250245 flag <- liftIO (nullPtr x)
251246 if flag
252247 then do x <- liftIO(get_error_table pointer) ; fail x
253248 else return (MkTBPointer x)
254249 where
255250 get_error_table : Ptr-> IO String
256− get_error_table pointer = do x <- mkForeign (FFun "sqlite3_get_error" [FPtr] FString) pointer
251+ get_error_table pointer = do x <- foreign FFI_C "sqlite3_get_error" (Ptr -> IO String) pointer
257252 return x
258253
259−
260254free_table : TBPointer -> IO ()
261−free_table (MkTBPointer pointer) = do x <- mkForeign (FFun "sqlite3_free_table_idr" [FPtr] FUnit) pointer
255+free_table (MkTBPointer pointer) = do x <- foreign FFI_C "sqlite3_free_table_idr" (Ptr -> IO ()) pointer
262256 return ()
263257
264258-----------------------------------------------------------------------------
@@ -267,11 +261,11 @@ free_table (MkTBPointer pointer) = do x <- mkForeign (FFun "sqlite3_free_table_i
267261-----------------------------------------------------------------------------
268262
269263num_row : TBPointer -> IO Int
270−num_row (MkTBPointer pointer) = do x <- mkForeign (FFun "sqlite3_get_num_row" [FPtr] FInt) pointer
264+num_row (MkTBPointer pointer) = do x <- foreign FFI_C "sqlite3_get_num_row" (Ptr -> IO Int) pointer
271265 return x
272266
273267num_col : TBPointer -> IO Int
274−num_col (MkTBPointer pointer) = do x <- mkForeign (FFun "sqlite3_get_num_col" [FPtr] FInt) pointer
268+num_col (MkTBPointer pointer) = do x <- foreign FFI_C "sqlite3_get_num_col" (Ptr -> IO Int) pointer
275269 return x
276270
277271-----------------------------------------------------------------------------
@@ -280,11 +274,11 @@ num_col (MkTBPointer pointer) = do x <- mkForeign (FFun "sqlite3_get_num_col" [F
280274-----------------------------------------------------------------------------
281275
282276num_row_v2 : DBPointer -> IO Int
283−num_row_v2 (MkDBPointer pointer) = do x <- mkForeign (FFun "sqlite3_get_num_row_v2" [FPtr] FInt) pointer
277+num_row_v2 (MkDBPointer pointer) = do x <- foreign FFI_C "sqlite3_get_num_row_v2" (Ptr -> IO Int) pointer
284278 return x
285279
286280num_col_v2 : DBPointer -> IO Int
287−num_col_v2 (MkDBPointer pointer) = do x <- mkForeign (FFun "sqlite3_get_num_col_v2" [FPtr] FInt) pointer
281+num_col_v2 (MkDBPointer pointer) = do x <- foreign FFI_C "sqlite3_get_num_col_v2" (Ptr -> IO Int) pointer
288282 return x
289283
290284-----------------------------------------------------------------------------
@@ -299,18 +293,18 @@ get_data (MkDBPointer pointer) row col = do
299293 helper ty
300294 where get_data_type : Ptr ->Int -> Int -> IO Int
301295 get_data_type pointer row col =
302− mkForeign (FFun "sqlite3_get_data_type" [FPtr, FInt, FInt] FInt) pointer row col
296+ foreign FFI_C "sqlite3_get_data_type" (Ptr -> Int -> Int -> IO Int) pointer row col
303297 get_data_val_int : Ptr -> Int -> IO Int
304298 get_data_val_int pointer col =
305− mkForeign (FFun "sqlite3_get_val_int" [FPtr,FInt] FInt) pointer col
299+ foreign FFI_C "sqlite3_get_val_int" (Ptr -> Int -> IO Int) pointer col
306300
307301 get_data_val_text : Ptr -> Int -> IO String
308302 get_data_val_text pointer col =
309− mkForeign (FFun "sqlite3_get_val_text" [FPtr, FInt] FString) pointer col
303+ foreign FFI_C "sqlite3_get_val_text" (Ptr -> Int -> IO String) pointer col
310304
311305 get_data_val_float : Ptr -> Int -> IO Float
312306 get_data_val_float pointer col =
313− mkForeign (FFun "sqlite3_get_float" [FPtr, FInt] FFloat) pointer col
307+ foreign FFI_C "sqlite3_get_float" (Ptr -> Int -> IO Float) pointer col
314308
315309 helper : Int -> IO DBVal
316310 helper 1 = do i <- get_data_val_int pointer col ; return (DBInt i)
@@ -360,7 +354,7 @@ strcat str1 str2 = str1 ++ str2
360354
361355bind_int : StmtPtr -> Int -> Int -> DB StmtPtr
362356bind_int (MkStmtPtr pointer) indexval val = do
363− x <- liftIO (mkForeign (FFun "sqlite3_bind_int_idr" [FPtr, FInt, FInt] FPtr) pointer indexval val)
357+ x <- liftIO (foreign FFI_C "sqlite3_bind_int_idr" (Ptr -> Int -> Int -> IO Ptr) pointer indexval val)
364358 flag <- liftIO (nullPtr x)
365359 if flag
366360 then fail "Could not bind int."
@@ -369,7 +363,7 @@ bind_int (MkStmtPtr pointer) indexval val = do
369363
370364bind_float : StmtPtr -> Int -> Float -> DB StmtPtr
371365bind_float (MkStmtPtr pointer) indexval val = do
372− x <- liftIO (mkForeign (FFun "sqlite3_bind_float_idr" [FPtr, FInt, FFloat] FPtr) pointer indexval val)
366+ x <- liftIO (foreign FFI_C "sqlite3_bind_float_idr" (Ptr -> Int -> Float -> IO Ptr) pointer indexval val)
373367 flag <- liftIO (nullPtr x)
374368 if flag
375369 then fail "Could not bind float."
@@ -377,7 +371,7 @@ bind_float (MkStmtPtr pointer) indexval val = do
377371
378372bind_text : StmtPtr -> String -> Int -> Int -> DB StmtPtr
379373bind_text (MkStmtPtr pointer) text indexval lengthval = do
380− x <- liftIO (mkForeign (FFun "sqlite3_bind_text_idr" [FPtr, FString, FInt, FInt] FPtr)
374+ x <- liftIO (foreign FFI_C "sqlite3_bind_text_idr" (Ptr -> String -> Int -> Int -> IO Ptr)
381375 pointer text indexval lengthval)
382376 flag <- liftIO(nullPtr x)
383377 if flag
@@ -386,7 +380,7 @@ bind_text (MkStmtPtr pointer) text indexval lengthval = do
386380
387381bind_null : StmtPtr -> Int -> DB StmtPtr
388382bind_null (MkStmtPtr pointer) indexval = do
389− x <- liftIO (mkForeign (FFun "sqlite3_bind_null_idr" [FPtr, FInt] FPtr) pointer indexval)
383+ x <- liftIO (foreign FFI_C "sqlite3_bind_null_idr" (Ptr -> Int -> IO Ptr) pointer indexval)
390384 flag <- liftIO (nullPtr x)
391385 if flag
392386 then fail "Could not bind null."
@@ -397,7 +391,7 @@ bind_null (MkStmtPtr pointer) indexval = do
397391-----------------------------------------------------------------------------
398392
399393strlen : String -> DB Int
400−strlen str = liftIO (mkForeign (FFun "strLength" [FString] FInt) str)
394+strlen str = liftIO (foreign FFI_C "strLength" (String -> IO Int) str)
401395
402396instance Show DBVal where
403397 show (DBInt i) = "Int val: " ++ show i ++ "\n"
idris.cabal+10−1
@@ -286,6 +286,9 @@ Extra-source-files:
286286 test/reg057/run
287287 test/reg057/*.idr
288288 test/reg057/expected
289+ test/reg058/run
290+ test/reg058/*.idr
291+ test/reg058/expected
289292
290293 test/basic001/run
291294 test/basic001/*.idr
@@ -494,6 +497,9 @@ Extra-source-files:
494497 test/proof004/run
495498 test/proof004/*.idr
496499 test/proof004/expected
500+ test/proof008/run
501+ test/proof008/*.idr
502+ test/proof008/expected
497503
498504 test/quasiquote001/run
499505 test/quasiquote001/*.idr
@@ -507,6 +513,9 @@ Extra-source-files:
507513 test/quasiquote004/run
508514 test/quasiquote004/*.idr
509515 test/quasiquote004/expected
516+ test/quasiquote005/run
517+ test/quasiquote005/*.idr
518+ test/quasiquote005/expected
510519
511520
512521 test/records001/run
@@ -682,7 +691,7 @@ Library
682691 , Idris.ErrReverse
683692 , Idris.Help
684693 , Idris.IBC
685− , Idris.IdeSlave
694+ , Idris.IdeMode
686695 , Idris.IdrisDoc
687696 , Idris.Imports
688697 , Idris.Inliner
jsrts/Runtime-common.js+11−13
@@ -68,20 +68,18 @@ var i$ffiWrap = function(fid,oldbase,myoldbase) {
6868 var res = fid;
6969
7070 for(var i = 0; i < (arguments.length ? arguments.length : 1); ++i) {
71− while (res instanceof i$CON) {
72− i$valstack_top += 1;
73− i$valstack[i$valstack_top] = res;
74− i$valstack[i$valstack_top + 1] = arguments[i];
75− i$SLIDE(2);
76− i$valstack_top = i$valstack_base + 2;
77− i$CALL(_idris__123_APPLY0_125_,[oldbase])
78− while (i$callstack.length) {
79− var func = i$callstack.pop();
80− var args = i$callstack.pop();
81− func.apply(this,args);
82− }
83− res = i$ret;
71+ i$valstack_top += 1;
72+ i$valstack[i$valstack_top] = res;
73+ i$valstack[i$valstack_top + 1] = arguments[i];
74+ i$SLIDE(2);
75+ i$valstack_top = i$valstack_base + 2;
76+ i$CALL(_idris__123_APPLY0_125_,[oldbase])
77+ while (i$callstack.length) {
78+ var func = i$callstack.pop();
79+ var args = i$callstack.pop();
80+ func.apply(this,args);
8481 }
82+ res = i$ret;
8583 }
8684
8785 i$callstack = i$vm.callstack;
libs/base/Data/Sign.idr+1−1
@@ -1,7 +1,7 @@
11module Data.Sign
22
33||| A representation of signs for signed datatypes such as `ZZ`
4−data Sign = Plus | Minus
4+data Sign = Plus | Zero | Minus
55
66||| Discover the sign of some type
77class Signed t where
libs/base/Data/ZZ.idr+1
@@ -15,6 +15,7 @@ import Data.Sign
1515data ZZ = Pos Nat | NegS Nat
1616
1717instance Signed ZZ where
18+ sign (Pos Z) = Zero
1819 sign (Pos _) = Plus
1920 sign (NegS _) = Minus
2021
libs/base/Network/Socket.idr+1−1
@@ -31,7 +31,7 @@ data SocketFamily =
3131instance Show SocketFamily where
3232 show AF_UNSPEC = "AF_UNSPEC"
3333 show AF_INET = "AF_INET"
34− show AF_INET6 = "AF_INET4"
34+ show AF_INET6 = "AF_INET6"
3535
3636instance ToCode SocketFamily where
3737 toCode AF_UNSPEC = 0
libs/base/System/Concurrency/Process.idr+11
@@ -41,6 +41,10 @@ send (MkPID p) m = Lift (sendToThread p (prim__vm, m))
4141msgWaiting : Process msg Bool
4242msgWaiting = Lift checkMsgs
4343
44+||| Return whether a message is waiting in the queue from a specific sender
45+msgWaitingFrom : ProcID msg -> Process msg Bool
46+msgWaitingFrom (MkPID p) = Lift (checkMsgsFrom p)
47+
4448||| Receive a message - blocks if there is no message waiting
4549recv : Process msg msg
4650recv {msg} = do (senderid, m) <- Lift get
@@ -48,6 +52,13 @@ recv {msg} = do (senderid, m) <- Lift get
4852 where get : IO (Ptr, msg)
4953 get = getMsg
5054
55+||| Receive a message from specific sender - blocks if there is no message waiting
56+recvFrom : ProcID msg -> Process msg msg
57+recvFrom (MkPID p) {msg} = do (senderid, m) <- Lift get
58+ return m
59+ where get : IO (Ptr, msg)
60+ get = getMsgFrom p
61+
5162||| receive a message, and return with the sender's process ID.
5263recvWithSender : Process msg (ProcID msg, msg)
5364recvWithSender {msg}
libs/base/System/Concurrency/Raw.idr+49−4
@@ -12,14 +12,59 @@ sendToThread {a} dest val
1212 = foreign FFI_C "idris_sendMessage" (Ptr -> Ptr -> Raw a -> IO ())
1313 prim__vm dest (MkRaw val)
1414
15+||| Check for messages in the process inbox
1516checkMsgs : IO Bool
16−checkMsgs = do msgs <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Int)
17+checkMsgs = do msgs <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Ptr)
1718 prim__vm
18− return (intToBool msgs)
19+ null <- nullPtr msgs
20+ return (not null)
21+
22+||| Check for messages in the process inbox.
23+||| Returns either 'Nothing', if none, or 'Just pid' as pid of sender.
24+listenMsgs : IO (Maybe Ptr)
25+listenMsgs = do sender <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Ptr)
26+ prim__vm
27+ null <- nullPtr sender
28+ return (if null
29+ then Nothing
30+ else Just sender)
31+
32+||| Check for messages from a specific sender in the process inbox
33+checkMsgsFrom : Ptr -> IO Bool
34+checkMsgsFrom sender
35+ = do msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Ptr -> IO Ptr)
36+ prim__vm sender
37+ null <- nullPtr msgs
38+ return (not null)
1939
2040||| Check inbox for messages. If there are none, blocks until a message
2141||| arrives.
42+||| Note that this is not at all type safe! It is intended to be used in
43+||| a type safe wrapper.
2244getMsg : IO a
23−getMsg {a} = do MkRaw x <- foreign FFI_C "idris_recvMessage"
24− (Ptr -> IO (Raw a)) prim__vm
45+getMsg {a} = do m <- foreign FFI_C "idris_recvMessage"
46+ (Ptr -> IO Ptr) prim__vm
47+ MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
2548 return x
49+
50+||| Check inbox for messages. If there are none, blocks until a message
51+||| arrives. Return pair of sender's ID and the message.
52+||| Note that this is not at all type safe! It is intended to be used in
53+||| a type safe wrapper.
54+getMsgWithSender : IO (Ptr, a)
55+getMsgWithSender {a}
56+ = do m <- foreign FFI_C "idris_recvMessage"
57+ (Ptr -> IO Ptr) prim__vm
58+ MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
59+ vm <- foreign FFI_C "idris_getSender" (Ptr -> IO Ptr) m
60+ foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
61+ return (vm, x)
62+
63+getMsgFrom : Ptr -> IO a
64+getMsgFrom {a} sender
65+ = do m <- foreign FFI_C "idris_recvMessageFrom"
66+ (Ptr -> Ptr -> IO Ptr) prim__vm sender
67+ MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
68+ foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
69+ return x
70+
libs/effects/Effects.idr+1
@@ -310,4 +310,5 @@ when : Bool -> Lazy ({xs} Eff ()) -> {xs} Eff ()
310310when True e = Force e
311311when False e = pure ()
312312
313+
313314-- --------------------------------------------------------------------- [ EOF ]
libs/prelude/Builtins.idr+10
@@ -19,6 +19,16 @@ namespace Builtins
1919 ||| @b the right element of the pair
2020 MkPair : {A, B : Type} -> (a : A) -> (b : B) -> Pair A B
2121
22+ ||| The non-dependent pair type, also known as conjunction, usable with
23+ ||| UniqueTypes.
24+ ||| @A the type of the left elements in the pair
25+ ||| @B the type of the left elements in the pair
26+ data UPair : (A : Type*) -> (B : Type*) -> Type where
27+ ||| A pair of elements
28+ ||| @a the left element of the pair
29+ ||| @b the right element of the pair
30+ MkUPair : {A, B : Type*} -> (a : A) -> (b : B) -> UPair A B
31+
2232 ||| Dependent pairs
2333 |||
2434 ||| Dependent pairs represent existential quantification - they consist of a
libs/prelude/Language/Reflection.idr+23−3
@@ -49,7 +49,7 @@ data Const = I Int | BI Integer | Fl Float | Ch Char | Str String
4949 | B32V Bits32x4 | B64V Bits64x2
5050 | AType ArithTy | StrType
5151 | PtrType | ManagedPtrType | BufferType | VoidType | Forgot
52−
52+ | WorldType | TheWorld
5353%name Const c, c'
5454
5555abstract class ReflConst (a : Type) where
@@ -146,6 +146,8 @@ instance Traversable Binder where
146146 traverse f (PVar x) = [| PVar (f x) |]
147147 traverse f (PVTy x) = [| PVTy (f x) |]
148148
149+||| Universes
150+data Universe = NullType | UniqueType | AllTypes
149151
150152||| Reflection of the well typed core language
151153data TT =
@@ -166,7 +168,8 @@ data TT =
166168 ||| Impossible terms
167169 Impossible |
168170 ||| The type of types along (with universe constraints)
169− TType TTUExp
171+ TType TTUExp |
172+ UType Universe
170173%name TT tm, tm'
171174
172175||| Raw terms without types
@@ -179,6 +182,7 @@ data Raw =
179182 RApp Raw Raw |
180183 ||| The type of types
181184 RType |
185+ RUType Universe |
182186 RForce Raw |
183187 ||| Embed a constant
184188 RConstant Const
@@ -213,6 +217,10 @@ data Tactic =
213217 Refine TTName |
214218 ||| Apply both tactics in sequence
215219 Seq Tactic Tactic |
220+ ||| Introduce a new hole with a particular type
221+ Claim TTName TT |
222+ ||| Move the current hole to the end
223+ Unfocus |
216224 ||| Intelligently construct the proof target from the context
217225 Trivial |
218226 ||| Build a proof by applying contructors up to a maximum depth
@@ -395,13 +403,20 @@ instance Quotable Const where
395403 quote BufferType = `(BufferType)
396404 quote VoidType = `(VoidType)
397405 quote Forgot = `(Forgot)
398−
406+ quote WorldType = `(WorldType)
407+ quote TheWorld = `(TheWorld)
399408
400409instance Quotable TTUExp where
401410 quotedTy = `(TTUExp)
402411 quote (UVar x) = `(UVar ~(quote x))
403412 quote (UVal x) = `(UVal ~(quote x))
404413
414+instance Quotable Universe where
415+ quotedTy = `(Universe)
416+ quote Reflection.NullType = `(NullType)
417+ quote Reflection.UniqueType = `(UniqueType)
418+ quote Reflection.AllTypes = `(AllTypes)
419+
405420mutual
406421 instance Quotable TT where
407422 quotedTy = `(TT)
@@ -414,6 +429,7 @@ mutual
414429 quote Erased = `(Erased)
415430 quote Impossible = `(Impossible)
416431 quote (TType uexp) = `(TType ~(quote uexp))
432+ quote (UType u) = `(UType ~(quote u))
417433
418434 instance Quotable (Binder TT) where
419435 quotedTy = `(Binder TT)
@@ -445,6 +461,7 @@ mutual
445461 quoteRaw (RBind n b tm) = `(RBind ~(quote n) ~(assert_total $ quoteRawBinder b) ~(quoteRaw tm))
446462 quoteRaw (RApp tm tm') = `(RApp ~(quoteRaw tm) ~(quoteRaw tm'))
447463 quoteRaw RType = `(RType)
464+ quoteRaw (RUType u) = `(RUType ~(quote u))
448465 quoteRaw (RForce tm) = `(RForce ~(quoteRaw tm))
449466 quoteRaw (RConstant c) = `(RConstant ~(quote c))
450467
@@ -472,6 +489,8 @@ instance Quotable Tactic where
472489 quote (Try tac tac') = `(Try ~(quote tac) ~(quote tac'))
473490 quote (GoalType x tac) = `(GoalType ~(quote x) ~(quote tac))
474491 quote (Refine n) = `(Refine ~(quote n))
492+ quote (Claim n ty) = `(Claim ~(quote n) ~(quote ty))
493+ quote Unfocus = `(Unfocus)
475494 quote (Seq tac tac') = `(Seq ~(quote tac) ~(quote tac'))
476495 quote Trivial = `(Trivial)
477496 quote (Search x) = `(Search ~(quote x))
@@ -494,3 +513,4 @@ instance Quotable Tactic where
494513 quote Skip = `(Skip)
495514 quote (Fail xs) = `(Fail ~(quote xs))
496515 quote SourceFC = `(SourceFC)
516+
libs/prelude/Language/Reflection/Tactical.idrnew file+95
@@ -0,0 +1,95 @@
1+module Language.Reflection.Tactical
2+
3+import Builtins
4+import Prelude.Applicative
5+import Prelude.Functor
6+import Prelude.List
7+import Prelude.Maybe
8+import Prelude.Monad
9+import Language.Reflection
10+
11+abstract
12+data Tactical : Type -> Type where
13+ -- obligatory control stuff
14+ prim__PureTactical : a -> Tactical a
15+ prim__BindTactical : {a, b : Type} -> Tactical a -> (a -> Tactical b) -> Tactical b
16+
17+ prim__Try : {a : Type} -> Tactical a -> Tactical a -> Tactical a
18+ prim__Fail : {a : Type} -> List ErrorReportPart -> Tactical a
19+
20+ prim__Env : Tactical (List (TTName, Binder TT))
21+ prim__Goal : Tactical (TTName, TT)
22+ prim__Holes : Tactical (List TTName)
23+ prim__Guess : Tactical (Maybe TT)
24+
25+ prim__Forget : TT -> Tactical Raw
26+
27+ prim__Gensym : String -> Tactical TTName
28+
29+ prim__Solve : Tactical ()
30+ prim__Fill : Raw -> Tactical ()
31+ prim__Focus : TTName -> Tactical ()
32+ prim__Unfocus : TTName -> Tactical ()
33+ prim__Attack : Tactical ()
34+
35+ prim__Claim : TTName -> Raw -> Tactical ()
36+
37+-------------
38+-- Public API
39+-------------
40+%access public
41+
42+instance Functor Tactical where
43+ map f t = prim__BindTactical t (\x => prim__PureTactical (f x))
44+
45+instance Applicative Tactical where
46+ pure x = prim__PureTactical x
47+ f <$> x = prim__BindTactical f $ \g =>
48+ prim__BindTactical x $ \y =>
49+ prim__PureTactical $ g y
50+
51+instance Alternative Tactical where
52+ empty = prim__Fail [TextPart "empty"]
53+ x <|> y = prim__Try x y
54+
55+instance Monad Tactical where
56+ x >>= f = prim__BindTactical x f
57+
58+fail : List ErrorReportPart -> Tactical a
59+fail err = prim__Fail err
60+
61+getEnv : Tactical (List (TTName, Binder TT))
62+getEnv = prim__Env
63+
64+getGoal : Tactical (TTName, TT)
65+getGoal = prim__Goal
66+
67+getHoles : Tactical (List TTName)
68+getHoles = prim__Holes
69+
70+getGuess : Tactical (Maybe TT)
71+getGuess = prim__Guess
72+
73+forgetTypes : TT -> Tactical Raw
74+forgetTypes tt = prim__Forget tt
75+
76+gensym : (hint : String) -> Tactical TTName
77+gensym hint = prim__Gensym hint
78+
79+solve : Tactical ()
80+solve = prim__Solve
81+
82+fill : Raw -> Tactical ()
83+fill tm = prim__Fill tm
84+
85+focus : (hole : TTName) -> Tactical ()
86+focus hole = prim__Focus hole
87+
88+unfocus : TTName -> Tactical ()
89+unfocus hole = prim__Unfocus hole
90+
91+attack : Tactical ()
92+attack = prim__Attack
93+
94+claim : TTName -> Raw -> Tactical ()
95+claim n ty = prim__Claim n ty
libs/prelude/Prelude/Foldable.idr+1−1
@@ -11,7 +11,7 @@ import Prelude.Algebra
1111
1212class Foldable (t : Type -> Type) where
1313 foldr : (elt -> acc -> acc) -> acc -> t elt -> acc
14− foldl : Foldable t => (acc -> elt -> acc) -> acc -> t elt -> acc
14+ foldl : (acc -> elt -> acc) -> acc -> t elt -> acc
1515 foldl f z t = foldr (flip (.) . flip f) id t z
1616
1717||| Combine each element of a structure into a monoid
libs/prelude/Prelude/Strings.idr+88−59
@@ -17,8 +17,9 @@ import Decidable.Equality
1717
1818||| Appends two strings together.
1919|||
20−||| Idris> "AB" ++ "C"
21−||| "ABC" : String
20+||| ```idris example
21+||| "AB" ++ "C"
22+||| ```
2223(++) : String -> String -> String
2324(++) = prim__concat
2425
@@ -26,8 +27,9 @@ import Decidable.Equality
2627|||
2728||| Doesn't work for empty strings.
2829|||
29−||| Idris> strHead "A"
30−||| 'A' : Char
30+||| ```idris example
31+||| strHead "A"
32+||| ```
3133partial
3234strHead : String -> Char
3335strHead = prim__strHead
@@ -36,20 +38,24 @@ strHead = prim__strHead
3638|||
3739||| Doesn't work for empty strings.
3840|||
39−||| Idris> strTail "AB"
40−||| "B" : String
41−||| Idris> strTail "A"
42−||| "" : String
41+||| ```idris example
42+||| strTail "AB"
43+||| ```
44+||| ```idris example
45+||| strTail "A"
46+||| ```
4347partial
4448strTail : String -> String
4549strTail = prim__strTail
4650
4751||| Adds a character to the front of the specified string.
4852|||
49−||| Idris> strCons 'A' "B"
50−||| "AB" : String
51−||| Idris> strCons 'A' ""
52−||| "A" : String
53+||| ```idris example
54+||| strCons 'A' "B"
55+||| ```
56+||| ```idris example
57+||| strCons 'A' ""
58+||| ```
5359strCons : Char -> String -> String
5460strCons = prim__strCons
5561
@@ -57,18 +63,21 @@ strCons = prim__strCons
5763|||
5864||| Precondition: '0 < i < length s' for 'strIndex s i'.
5965|||
60−||| Idris> strIndex "AB" 1
61−||| 'B' : Char
66+||| ```idris example
67+||| strIndex "AB" 1
68+||| ```
6269partial
6370strIndex : String -> Int -> Char
6471strIndex = prim__strIndex
6572
6673||| Reverses the elements within a String.
6774|||
68−||| Idris> reverse "ABC"
69−||| "CBA" : String
70−||| Idris> reverse ""
71−||| "" : String
75+||| ```idris example
76+||| reverse "ABC"
77+||| ```
78+||| ```idris example
79+||| reverse ""
80+||| ```
7281reverse : String -> String
7382reverse = prim__strRev
7483
@@ -103,8 +112,9 @@ strM x with (decEq (not (x == "")) True)
103112
104113||| Turns a string into a list of characters.
105114|||
106−||| Idris> unpack "ABC"
107−||| ['A', 'B', 'C'] : List Char
115+||| ```idris example
116+||| unpack "ABC"
117+||| ```
108118unpack : String -> List Char
109119unpack s with (strM s)
110120 unpack "" | StrNil = []
@@ -116,8 +126,9 @@ pack = foldr strCons ""
116126
117127||| Creates a string of a single character.
118128|||
119−||| Idris> singleton 'A'
120−||| "A" : String
129+||| ```idris example
130+||| singleton 'A'
131+||| ```
121132singleton : Char -> String
122133singleton c = strCons c ""
123134
@@ -139,10 +150,12 @@ instance Monoid String where
139150||| Splits the string into a part before the predicate
140151||| returns False and the rest of the string.
141152|||
142−||| Idris> span (/= 'C') "ABCD"
143−||| ("AB", "CD") : (String, String)
144−||| Idris> span (/= 'C') "EFGH"
145−||| ("EFGH", "") : (String, String)
153+||| ```idris example
154+||| span (/= 'C') "ABCD"
155+||| ```
156+||| ```idris example
157+||| span (/= 'C') "EFGH"
158+||| ```
146159span : (Char -> Bool) -> String -> (String, String)
147160span p xs with (strM xs)
148161 span p "" | StrNil = ("", "")
@@ -154,28 +167,33 @@ span p xs with (strM xs)
154167||| Splits the string into a part before the predicate
155168||| returns True and the rest of the string.
156169|||
157−||| Idris> break (== 'C') "ABCD"
158−||| ("AB", "CD") : (String, String)
159−||| Idris> break (== 'C') "EFGH"
160−||| ("EFGH", "") : (String, String)
170+||| ```idris example
171+||| break (== 'C') "ABCD"
172+||| ```
173+||| ```idris example
174+||| break (== 'C') "EFGH"
175+||| ```
161176break : (Char -> Bool) -> String -> (String, String)
162177break p = span (not . p)
163178
164179||| Splits the string into parts with the predicate
165180||| indicating separator characters.
166181|||
167−||| Idris> split (== '.') ".AB.C..D"
168−||| ["", "AB", "C", "", "D"] : List String
182+||| ```idris example
183+||| split (== '.') ".AB.C..D"
184+||| ```
169185split : (Char -> Bool) -> String -> List String
170186split p xs = map pack (split p (unpack xs))
171187
172188||| Removes whitespace (determined with 'isSpace') from
173189||| the start of the string.
174190|||
175−||| Idris> ltrim " A\nB"
176−||| "A\nB" : String
177−||| Idris> ltrim " \nAB"
178−||| "AB" : String
191+||| ```idris example
192+||| ltrim " A\nB"
193+||| ```
194+||| ```idris example
195+||| ltrim " \nAB"
196+||| ```
179197ltrim : String -> String
180198ltrim xs with (strM xs)
181199 ltrim "" | StrNil = ""
@@ -185,15 +203,17 @@ ltrim xs with (strM xs)
185203||| Removes whitespace (determined with 'isSpace') from
186204||| the start and end of the string.
187205|||
188−||| Idris> trim " A\nB C "
189−||| "A\nB C" : String
206+||| ```idris example
207+||| trim " A\nB C "
208+||| ```
190209trim : String -> String
191210trim xs = ltrim (reverse (ltrim (reverse xs)))
192211
193212||| Splits a character list into a list of whitespace separated character lists.
194213|||
195−||| Idris> words' (unpack " A B C D E ")
196−||| [['A'], ['B'], ['C'], ['D'], ['E']] : List (List Char)
214+||| ```idris example
215+||| words' (unpack " A B C D E ")
216+||| ```
197217words' : List Char -> List (List Char)
198218words' s = case dropWhile isSpace s of
199219 [] => []
@@ -202,15 +222,17 @@ words' s = case dropWhile isSpace s of
202222
203223||| Splits a string into a list of whitespace separated strings.
204224|||
205−||| Idris> words " A B C D E "
206−||| ["A", "B", "C", "D", "E"] : List String
225+||| ```idris example
226+||| words " A B C D E "
227+||| ```
207228words : String -> List String
208229words s = map pack $ words' $ unpack s
209230
210231||| Splits a character list into a list of newline separated character lists.
211232|||
212−||| Idris> lines' (unpack "\rA BC\nD\r\nE\n")
213−||| [['A', ' ', 'B', 'C'], ['D'], ['E']] : List (List Char)
233+||| ```idris example
234+||| lines' (unpack "\rA BC\nD\r\nE\n")
235+||| ```
214236lines' : List Char -> List (List Char)
215237lines' s = case dropWhile isNL s of
216238 [] => []
@@ -219,8 +241,9 @@ lines' s = case dropWhile isNL s of
219241
220242||| Splits a string into a list of newline separated strings.
221243|||
222−||| Idris> lines "\rA BC\nD\r\nE\n"
223−||| ["A BC", "D", "E"] : List String
244+||| ```idris example
245+||| lines "\rA BC\nD\r\nE\n"
246+||| ```
224247lines : String -> List String
225248lines s = map pack $ lines' $ unpack s
226249
@@ -235,8 +258,9 @@ foldl1 f (x::xs) = foldl f x xs
235258
236259||| Joins the character lists by spaces into a single character list.
237260|||
238−||| Idris> unwords' [['A'], ['B', 'C'], ['D'], ['E']]
239−||| ['A', ' ', 'B', 'C', ' ', 'D', ' ', 'E'] : List Char
261+||| ```idris example
262+||| unwords' [['A'], ['B', 'C'], ['D'], ['E']]
263+||| ```
240264unwords' : List (List Char) -> List Char
241265unwords' [] = []
242266unwords' ws = assert_total (foldr1 addSpace ws)
@@ -246,24 +270,28 @@ unwords' ws = assert_total (foldr1 addSpace ws)
246270
247271||| Joins the strings by spaces into a single string.
248272|||
249−||| Idris> unwords ["A", "BC", "D", "E"]
250−||| "A BC D E" : String
273+||| ```idris example
274+||| unwords ["A", "BC", "D", "E"]
275+||| ```
251276unwords : List String -> String
252277unwords = pack . unwords' . map unpack
253278
254279||| Returns the length of the string.
255280|||
256−||| Idris> length ""
257−||| 0 : Nat
258−||| Idris> length "ABC"
259−||| 3 : Nat
281+||| ```idris example
282+||| length ""
283+||| ```
284+||| ```idris example
285+||| length "ABC"
286+||| ```
260287length : String -> Nat
261288length = fromInteger . prim__zextInt_BigInt . prim_lenString
262289
263290||| Lowercases all characters in the string.
264291|||
265−||| Idris> toLower "aBc12!"
266−||| "abc12!" : String
292+||| ```idris example
293+||| toLower "aBc12!"
294+||| ```
267295toLower : String -> String
268296toLower x with (strM x)
269297 strToLower "" | StrNil = ""
@@ -272,14 +300,15 @@ toLower x with (strM x)
272300
273301||| Uppercases all characters in the string.
274302|||
275−||| Idris> toLower "aBc12!"
276−||| "ABC12!" : String
303+||| ```idris example
304+||| toLower "aBc12!"
305+||| ```
277306toUpper : String -> String
278307toUpper x with (strM x)
279308 strToLower "" | StrNil = ""
280309 strToLower (strCons c cs) | (StrCons c cs) =
281310 strCons (toUpper c) (toUpper (assert_smaller (strCons c cs) cs ))
282−
311+
283312--------------------------------------------------------------------------------
284313-- Predicates
285314--------------------------------------------------------------------------------
libs/prelude/prelude.ipkg+1−1
@@ -10,7 +10,7 @@ modules = Builtins, Prelude, IO,
1010 Prelude.Foldable, Prelude.Traversable, Prelude.Bits, Prelude.Stream,
1111 Prelude.Uninhabited, Prelude.Pairs,
1212
13− Language.Reflection, Language.Reflection.Errors,
13+ Language.Reflection, Language.Reflection.Errors, Language.Reflection.Tactical,
1414
1515 Decidable.Equality
1616
rts/Makefile+1−1
@@ -18,7 +18,7 @@ endif
1818endif
1919
2020ifeq ($(OS), windows)
21− OBJS += windows/idris_stdfgn.o windows/idris_net.o
21+ OBJS += windows/idris_stdfgn.o windows/idris_net.o windows/win_utils.o
2222else
2323 OBJS += idris_stdfgn.o idris_net.o
2424endif
rts/idris_gc.c+4−2
@@ -137,8 +137,10 @@ void idris_gc(VM* vm) {
137137 }
138138
139139#ifdef HAS_PTHREAD
140− for(root = vm->inbox_ptr; root < vm->inbox_write; ++root) {
141− *root = copy(vm, *root);
140+ Msg* msg;
141+
142+ for(msg = vm->inbox; msg < vm->inbox_write; ++msg) {
143+ msg->msg = copy(vm, msg->msg);
142144 }
143145#endif
144146 vm->ret = copy(vm, vm->ret);
rts/idris_gmp.c+12−2
@@ -27,6 +27,7 @@ VAL MKBIGC(VM* vm, char* val) {
2727 mpz_t* bigint;
2828
2929 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
30+ idris_doneAlloc();
3031 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
3132
3233 mpz_init(*bigint);
@@ -43,6 +44,7 @@ VAL MKBIGM(VM* vm, void* big) {
4344
4445 mpz_t* bigint;
4546 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
47+ idris_doneAlloc();
4648 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
4749
4850 mpz_init(*bigint);
@@ -59,6 +61,7 @@ VAL MKBIGMc(VM* vm, void* big) {
5961
6062 mpz_t* bigint;
6163 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
64+ idris_doneAlloc();
6265 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
6366
6467 mpz_init_set(*bigint, *((mpz_t*)big));
@@ -74,6 +77,7 @@ VAL MKBIGUI(VM* vm, unsigned long val) {
7477
7578 mpz_t* bigint;
7679 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
80+ idris_doneAlloc();
7781 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
7882
7983 mpz_init_set_ui(*bigint, val);
@@ -89,6 +93,7 @@ VAL MKBIGSI(VM* vm, signed long val) {
8993
9094 mpz_t* bigint;
9195 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
96+ idris_doneAlloc();
9297 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
9398
9499 mpz_init_set_si(*bigint, val);
@@ -105,6 +110,7 @@ VAL GETBIG(VM * vm, VAL x) {
105110 if (ISINT(x)) {
106111 mpz_t* bigint;
107112 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
113+ idris_doneAlloc();
108114 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
109115
110116 mpz_init(*bigint);
@@ -115,6 +121,7 @@ VAL GETBIG(VM * vm, VAL x) {
115121
116122 return cl;
117123 } else {
124+ idris_doneAlloc();
118125 switch(GETTY(x)) {
119126 case FWD:
120127 return GETBIG(vm, x->info.ptr);
@@ -129,6 +136,7 @@ VAL bigAdd(VM* vm, VAL x, VAL y) {
129136
130137 mpz_t* bigint;
131138 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
139+ idris_doneAlloc();
132140 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
133141 mpz_add(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
134142 SETTY(cl, BIGINT);
@@ -141,6 +149,7 @@ VAL bigSub(VM* vm, VAL x, VAL y) {
141149
142150 mpz_t* bigint;
143151 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
152+ idris_doneAlloc();
144153 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
145154 mpz_sub(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
146155 SETTY(cl, BIGINT);
@@ -153,6 +162,7 @@ VAL bigMul(VM* vm, VAL x, VAL y) {
153162
154163 mpz_t* bigint;
155164 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
165+ idris_doneAlloc();
156166 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
157167 mpz_mul(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
158168 SETTY(cl, BIGINT);
@@ -165,6 +175,7 @@ VAL bigDiv(VM* vm, VAL x, VAL y) {
165175
166176 mpz_t* bigint;
167177 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
178+ idris_doneAlloc();
168179 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
169180 mpz_tdiv_q(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
170181 SETTY(cl, BIGINT);
@@ -177,6 +188,7 @@ VAL bigMod(VM* vm, VAL x, VAL y) {
177188
178189 mpz_t* bigint;
179190 VAL cl = allocate(sizeof(Closure) + sizeof(mpz_t), 0);
191+ idris_doneAlloc();
180192 bigint = (mpz_t*)(((char*)cl) + sizeof(Closure));
181193 mpz_mod(*bigint, GETMPZ(GETBIG(vm,x)), GETMPZ(GETBIG(vm,y)));
182194 SETTY(cl, BIGINT);
@@ -258,8 +270,6 @@ VAL idris_bigMod(VM* vm, VAL x, VAL y) {
258270}
259271
260272int bigEqConst(VAL x, int c) {
261− idris_requireAlloc(IDRIS_MAXGMP);
262−
263273 if (ISINT(x)) { return (GETINT(x) == c); }
264274 else {
265275 int rv = mpz_cmp_si(GETMPZ(x), c);
rts/idris_rts.c+88−30
@@ -1,11 +1,4 @@
1−#include <stdlib.h>
2−#include <stdio.h>
3−#include <string.h>
4−#include <stdarg.h>
51#include <assert.h>
6−#ifdef HAS_PTHREAD
7−#include <pthread.h>
8−#endif
92
103#include "idris_rts.h"
114#include "idris_gc.h"
@@ -44,7 +37,6 @@ VM* init_vm(int stack_size, size_t heap_size,
4437 vm->inbox = malloc(1024*sizeof(VAL));
4538 memset(vm->inbox, 0, 1024*sizeof(VAL));
4639 vm->inbox_end = vm->inbox + 1024;
47− vm->inbox_ptr = vm->inbox;
4840 vm->inbox_write = vm->inbox;
4941
5042 // The allocation lock must be reentrant. The lock exists to ensure that
@@ -72,7 +64,9 @@ VM* init_vm(int stack_size, size_t heap_size,
7264}
7365
7466void init_threadkeys() {
67+#ifdef HAS_PTHREAD
7568 pthread_key_create(&vm_key, (void*)free_key);
69+#endif
7670}
7771
7872void init_threaddata(VM *vm) {
@@ -1005,7 +999,7 @@ void* vmThread(VM* callvm, func f, VAL arg) {
1005999
10061000// VM is assumed to be a different vm from the one x lives on
10071001
1008−VAL copyTo(VM* vm, VAL x) {
1002+VAL doCopyTo(VM* vm, VAL x) {
10091003 int i, ar;
10101004 VAL* argptr;
10111005 Closure* cl;
@@ -1022,7 +1016,7 @@ VAL copyTo(VM* vm, VAL x) {
10221016
10231017 argptr = (VAL*)(cl->info.c.args);
10241018 for(i = 0; i < ar; ++i) {
1025− *argptr = copyTo(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
1019+ *argptr = doCopyTo(vm, *((VAL*)(x->info.c.args)+i)); // recursive version
10261020 argptr++;
10271021 }
10281022 }
@@ -1063,6 +1057,14 @@ VAL copyTo(VM* vm, VAL x) {
10631057 return cl;
10641058}
10651059
1060+VAL copyTo(VM* vm, VAL x) {
1061+ VM* current = pthread_getspecific(vm_key);
1062+ pthread_setspecific(vm_key, vm);
1063+ VAL ret = doCopyTo(vm, x);
1064+ pthread_setspecific(vm_key, current);
1065+ return ret;
1066+}
1067+
10661068// Add a message to another VM's message queue
10671069void idris_sendMessage(VM* sender, VM* dest, VAL msg) {
10681070 // FIXME: If GC kicks in in the middle of the copy, we're in trouble.
@@ -1088,18 +1090,19 @@ void idris_sendMessage(VM* sender, VM* dest, VAL msg) {
10881090 }
10891091
10901092 pthread_mutex_lock(&(dest->inbox_lock));
1091− *(dest->inbox_write) = dmsg;
1092−
1093− dest->inbox_write++;
1093+
10941094 if (dest->inbox_write >= dest->inbox_end) {
1095− dest->inbox_write = dest->inbox;
1096− }
1097−
1098− if (dest->inbox_write == dest->inbox_ptr) {
1099− fprintf(stderr, "Inbox full"); // Maybe grow it instead...
1095+ // FIXME: This is obviously bad in the long run. This should
1096+ // either block, make the inbox bigger, or return an error code,
1097+ // or possibly make it user configurable
1098+ fprintf(stderr, "Inbox full");
11001099 exit(-1);
11011100 }
11021101
1102+ dest->inbox_write->msg = dmsg;
1103+ dest->inbox_write->sender = sender;
1104+ dest->inbox_write++;
1105+
11031106 // Wake up the other thread
11041107 pthread_mutex_lock(&dest->inbox_block);
11051108 pthread_cond_signal(&dest->inbox_waiting);
@@ -1111,19 +1114,47 @@ void idris_sendMessage(VM* sender, VM* dest, VAL msg) {
11111114// printf("Sending [unlock]...\n");
11121115}
11131116
1114−int idris_checkMessages(VM* vm) {
1115− VAL msg = *(vm->inbox_ptr);
1116− return (msg != NULL);
1117+VM* idris_checkMessages(VM* vm) {
1118+ return idris_checkMessagesFrom(vm, NULL);
1119+}
1120+
1121+VM* idris_checkMessagesFrom(VM* vm, VM* sender) {
1122+ Msg* msg;
1123+
1124+ for (msg = vm->inbox; msg < vm->inbox_end && msg->msg != NULL; ++msg) {
1125+ if (sender == NULL || msg->sender == sender) {
1126+ return msg->sender;
1127+ }
1128+ }
1129+ return 0;
1130+}
1131+
1132+Msg* idris_getMessageFrom(VM* vm, VM* sender) {
1133+ Msg* msg;
1134+
1135+ for (msg = vm->inbox; msg < vm->inbox_write; ++msg) {
1136+ if (sender == NULL || msg->sender == sender) {
1137+ return msg;
1138+ }
1139+ }
1140+ return NULL;
11171141}
11181142
11191143// block until there is a message in the queue
1120−VAL idris_recvMessage(VM* vm) {
1121− VAL msg;
1144+Msg* idris_recvMessage(VM* vm) {
1145+ return idris_recvMessageFrom(vm, NULL);
1146+}
1147+
1148+Msg* idris_recvMessageFrom(VM* vm, VM* sender) {
1149+ Msg* msg;
1150+ Msg* ret = malloc(sizeof(Msg));
1151+
11221152 struct timespec timeout;
11231153 int status;
11241154
11251155 pthread_mutex_lock(&vm->inbox_block);
1126− msg = *(vm->inbox_ptr);
1156+ msg = idris_getMessageFrom(vm, sender);
1157+
11271158 while (msg == NULL) {
11281159// printf("No message yet\n");
11291160// printf("Waiting [lock]...\n");
@@ -1133,27 +1164,54 @@ VAL idris_recvMessage(VM* vm) {
11331164 &timeout);
11341165 (void)(status); //don't emit 'unused' warning
11351166// printf("Waiting [unlock]... %d\n", status);
1136− msg = *(vm->inbox_ptr);
1167+ msg = idris_getMessageFrom(vm, sender);
11371168 }
11381169 pthread_mutex_unlock(&vm->inbox_block);
11391170
11401171 if (msg != NULL) {
1172+ ret->msg = msg->msg;
1173+ ret->sender = msg->sender;
1174+
11411175 pthread_mutex_lock(&(vm->inbox_lock));
1142− *(vm->inbox_ptr) = NULL;
1143− vm->inbox_ptr++;
1144− if (vm->inbox_ptr >= vm->inbox_end) {
1145− vm->inbox_ptr = vm->inbox;
1176+
1177+ // Slide everything down after the message in the inbox,
1178+ // Move the inbox_write pointer down, and clear the value at the
1179+ // end - O(n) but it's easier since the message from a specific
1180+ // sender could be anywhere in the inbox
1181+
1182+ for(;msg < vm->inbox_write; ++msg) {
1183+ if (msg+1 != vm->inbox_end) {
1184+ msg->sender = (msg + 1)->sender;
1185+ msg->msg = (msg + 1)->msg;
1186+ }
11461187 }
1188+
1189+ vm->inbox_write->msg = NULL;
1190+ vm->inbox_write->sender = NULL;
1191+ vm->inbox_write--;
1192+
11471193 pthread_mutex_unlock(&(vm->inbox_lock));
11481194 } else {
11491195 fprintf(stderr, "No messages waiting");
11501196 exit(-1);
11511197 }
11521198
1153− return msg;
1199+ return ret;
11541200}
11551201#endif
11561202
1203+VAL idris_getMsg(Msg* msg) {
1204+ return msg->msg;
1205+}
1206+
1207+VM* idris_getSender(Msg* msg) {
1208+ return msg->sender;
1209+}
1210+
1211+void idris_freeMsg(Msg* msg) {
1212+ free(msg);
1213+}
1214+
11571215VAL* nullary_cons;
11581216
11591217void init_nullaries() {
rts/idris_rts.h+29−9
@@ -80,7 +80,16 @@ typedef struct Closure {
8080 } info;
8181} Closure;
8282
83−typedef struct {
83+struct VM_t;
84+
85+struct Msg_t {
86+ struct VM_t* sender;
87+ VAL msg;
88+};
89+
90+typedef struct Msg_t Msg;
91+
92+struct VM_t {
8493 VAL* valstack;
8594 VAL* valstack_top;
8695 VAL* valstack_base;
@@ -93,11 +102,9 @@ typedef struct {
93102 pthread_mutex_t alloc_lock;
94103 pthread_cond_t inbox_waiting;
95104
96− VAL* inbox; // Block of memory for storing messages
97− VAL* inbox_end; // End of block of memory
98−
99− VAL* inbox_ptr; // Next message to read
100− VAL* inbox_write; // Location of next message to write
105+ Msg* inbox; // Block of memory for storing messages
106+ Msg* inbox_end; // End of block of memory
107+ Msg* inbox_write; // Location of next message to write
101108
102109 int processes; // Number of child processes
103110 int max_threads; // maximum number of threads to run in parallel
@@ -106,7 +113,9 @@ typedef struct {
106113
107114 VAL ret;
108115 VAL reg1;
109−} VM;
116+};
117+
118+typedef struct VM_t VM;
110119
111120// Create a new VM
112121VM* init_vm(int stack_size, size_t heap_size,
@@ -277,10 +286,21 @@ VAL copyTo(VM* newVM, VAL x);
277286
278287// Add a message to another VM's message queue
279288void idris_sendMessage(VM* sender, VM* dest, VAL msg);
289+// Check whether there are any messages in the queue and return PID of
290+// sender if so (null if not)
291+VM* idris_checkMessages(VM* vm);
280292// Check whether there are any messages in the queue
281−int idris_checkMessages(VM* vm);
293+VM* idris_checkMessagesFrom(VM* vm, VM* sender);
282294// block until there is a message in the queue
283−VAL idris_recvMessage(VM* vm);
295+Msg* idris_recvMessage(VM* vm);
296+// block until there is a message in the queue
297+Msg* idris_recvMessageFrom(VM* vm, VM* sender);
298+
299+// Query/free structure used to return message data (recvMessage will malloc,
300+// so needs an explicit free)
301+VAL idris_getMsg(Msg* msg);
302+VM* idris_getSender(Msg* msg);
303+void idris_freeMsg(Msg* msg);
284304
285305void dumpVal(VAL r);
286306void dumpStack(VM* vm);
rts/windows/idris_stdfgn.c+10−3
@@ -5,9 +5,12 @@
55#include <fcntl.h>
66#include <stdio.h>
77#include <time.h>
8+#include <io.h>
89
910extern char** environ;
1011
12+int win_fpoll(void* h);
13+
1114void putStr(char* str) {
1215 printf("%s", str);
1316}
@@ -32,14 +35,18 @@ int fileError(void* h) {
3235 return ferror(f);
3336}
3437
35−void fputStr(void* h, char* str) {
38+int idris_writeStr(void* h, char* str) {
3639 FILE* f = (FILE*)h;
37− fputs(str, f);
40+ if (fputs(str, f)) {
41+ return 0;
42+ } else {
43+ return -1;
44+ }
3845}
3946
4047int fpoll(void* h)
4148{
42− return 0;
49+ return win_fpoll(h);
4350}
4451
4552void* do_popen(const char* cmd, const char* mode) {
rts/windows/win_utils.cnew file+21
@@ -0,0 +1,21 @@
1+#include <windows.h>
2+#include <io.h>
3+#include <stdio.h>
4+
5+// THis file exists to avoid clashes between windows.h and idris_rts.h
6+//
7+
8+int win_fpoll(void* h)
9+{
10+ HANDLE wh =(HANDLE) _get_osfhandle(_fileno((FILE*)h));
11+ if (wh == INVALID_HANDLE_VALUE) {
12+ return -1;
13+ }
14+ DWORD ret = WaitForSingleObject(wh, 1000);
15+ // Imitate the return values of select()
16+ if (ret == WAIT_OBJECT_0)
17+ return 1;
18+ if (ret == WAIT_TIMEOUT)
19+ return 0;
20+ return -1;
21+}
src/IRTS/Lang.hs+4−1
@@ -281,7 +281,10 @@ usedIn env (LLazyExp e) = usedIn env e
281281usedIn env (LForce e) = usedIn env e
282282usedIn env (LLet n v e) = usedIn env v ++ usedIn (env \\ [n]) e
283283usedIn env (LLam ns e) = usedIn (env \\ ns) e
284−usedIn env (LCon loc i n args) = concatMap (usedIn env) args
284+usedIn env (LCon v i n args) = let rest = concatMap (usedIn env) args in
285+ case v of
286+ Nothing -> rest
287+ Just (Glob n) -> usedArg env n ++ rest
285288usedIn env (LProj t i) = usedIn env t
286289usedIn env (LCase up e alts) = usedIn env e ++ concatMap (usedInA env) alts
287290 where usedInA env (LConCase i n ns e) = usedIn env e
src/Idris/AbsSyntax.hs+29−11
@@ -10,7 +10,7 @@ import Idris.Core.Typecheck
1010import Idris.AbsSyntaxTree
1111import Idris.Colours
1212import Idris.Docstrings
13−import Idris.IdeSlave hiding (Opt(..))
13+import Idris.IdeMode hiding (Opt(..))
1414import IRTS.CodegenCommon
1515import Util.DynamicLinker
1616
@@ -601,7 +601,7 @@ type1Doc = (annotate (AnnType "Type" "The type of types, one level up") $ text "
601601isetPrompt :: String -> Idris ()
602602isetPrompt p = do i <- getIState
603603 case idris_outputmode i of
604− IdeSlave n h -> runIO . hPutStrLn h $ convSExp "set-prompt" p n
604+ IdeMode n h -> runIO . hPutStrLn h $ convSExp "set-prompt" p n
605605
606606-- | Tell clients how much was parsed and loaded
607607isetLoadedRegion :: Idris ()
@@ -610,7 +610,7 @@ isetLoadedRegion = do i <- getIState
610610 case span of
611611 Just fc ->
612612 case idris_outputmode i of
613− IdeSlave n h ->
613+ IdeMode n h ->
614614 runIO . hPutStrLn h $
615615 convSExp "set-loaded-region" fc n
616616 Nothing -> return ()
@@ -752,10 +752,12 @@ outputTy :: Idris OutputType
752752outputTy = do i <- getIState
753753 return $ opt_outputTy $ idris_options i
754754
755−setIdeSlave :: Bool -> Handle -> Idris ()
756−setIdeSlave True h = do i <- getIState
757− putIState $ i { idris_outputmode = (IdeSlave 0 h), idris_colourRepl = False }
758−setIdeSlave False _ = return ()
755+setIdeMode :: Bool -> Handle -> Idris ()
756+setIdeMode True h = do i <- getIState
757+ putIState $ i { idris_outputmode = IdeMode 0 h
758+ , idris_colourRepl = False
759+ }
760+setIdeMode False _ = return ()
759761
760762setTargetTriple :: String -> Idris ()
761763setTargetTriple t = do i <- getIState
@@ -870,7 +872,7 @@ logLvl l str = do i <- getIState
870872 when (lvl >= l) $
871873 case idris_outputmode i of
872874 RawOutput h -> do runIO $ hPutStrLn h str
873− IdeSlave n h ->
875+ IdeMode n h ->
874876 do let good = SexpList [IntegerAtom (toInteger l), toSExp str]
875877 runIO . hPutStrLn h $ convSExp "log" good n
876878
@@ -972,6 +974,7 @@ expandParams dec ps ns infs tm = en tm
972974 en (PApp fc f as) = PApp fc (en f) (map (fmap en) as)
973975 en (PAppBind fc f as) = PAppBind fc (en f) (map (fmap en) as)
974976 en (PCase fc c os) = PCase fc (en c) (map (pmap en) os)
977+ en (PRunTactics fc tm) = PRunTactics fc (en tm)
975978 en t = t
976979
977980 nselem x [] = False
@@ -1014,7 +1017,7 @@ expandParamsD rhsonly ist dec ps ns (PClauses fc opts n cs)
10141017 (map (expandParams dec ps'' ns' []) ws)
10151018 (expandParams dec ps'' ns' [] rhs)
10161019 (map (expandParamsD True ist dec ps'' ns') ds)
1017− expandParamsC (PWith fc n lhs ws wval ds)
1020+ expandParamsC (PWith fc n lhs ws wval pn ds)
10181021 = let -- ps' = updateps True (namesIn ist wval) (zip ps [0..])
10191022 ps'' = updateps False (namesIn [] ist lhs) (zip ps [0..])
10201023 lhs' = if rhsonly then lhs else (expandParams dec ps'' ns [] lhs)
@@ -1023,6 +1026,7 @@ expandParamsD rhsonly ist dec ps ns (PClauses fc opts n cs)
10231026 PWith fc n' lhs'
10241027 (map (expandParams dec ps'' ns' []) ws)
10251028 (expandParams dec ps'' ns' [] wval)
1029+ pn
10261030 (map (expandParamsD rhsonly ist dec ps'' ns') ds)
10271031 updateps yn nm [] = []
10281032 updateps yn nm (((a, t), i):as)
@@ -1441,6 +1445,7 @@ implicitise syn ignore ist tm = -- trace ("INCOMING " ++ showImp True tm) $
14411445 imps top env (PHidden tm) = imps False env tm
14421446 imps top env (PUnifyLog tm) = imps False env tm
14431447 imps top env (PNoImplicits tm) = imps False env tm
1448+ imps top env (PRunTactics fc tm) = imps False env tm
14441449 imps top env _ = return ()
14451450
14461451 pibind using [] sc = sc
@@ -1562,6 +1567,7 @@ addImpl' inpat env infns ist ptm
15621567 ai qq env ds (PQuasiquote tm g) = PQuasiquote (ai True env ds tm)
15631568 (fmap (ai True env ds) g)
15641569 ai qq env ds (PUnquote tm) = PUnquote (ai False env ds tm)
1570+ ai qq env ds (PRunTactics fc tm) = PRunTactics fc (ai False env ds tm)
15651571 ai qq env ds tm = tm
15661572
15671573 handleErr (Left err) = PElabError err
@@ -1708,6 +1714,10 @@ stripLinear i tm = evalState (sl tm) [] where
17081714 return (a' : as')
17091715 slAlts ns [] = return []
17101716 sl (PPair fc p l r) = do l' <- sl l; r' <- sl r; return (PPair fc p l' r')
1717+ sl (PDPair fc p l t r) = do l' <- sl l
1718+ t' <- sl t
1719+ r' <- sl r
1720+ return (PDPair fc p l' t' r')
17111721 sl (PApp fc fn args) = do -- Just the args, fn isn't matchable as a var
17121722 args' <- mapM slA args
17131723 return $ PApp fc fn args'
@@ -1734,7 +1744,11 @@ stripUnmatchable i (PApp fc fn args) = PApp fc fn (fmap (fmap su) args) where
17341744 | (Bind n (Pi _ t _) sc :_) <- lookupTy f (tt_ctxt i)
17351745 = Placeholder
17361746 su (PApp fc f@(PRef _ fn) args)
1737− | isDConName fn ctxt
1747+ -- here we use canBeDConName because the impossible pattern
1748+ -- check will not necessarily fully resolve constructor names,
1749+ -- and these bare names will otherwise get in the way of
1750+ -- impossbility checking.
1751+ | canBeDConName fn ctxt
17381752 = PApp fc f (fmap (fmap su) args)
17391753 su (PApp fc f args)
17401754 = PHidden (PApp fc f args)
@@ -1968,8 +1982,11 @@ shadow :: Name -> Name -> PTerm -> PTerm
19681982shadow n n' t = sm t where
19691983 sm (PRef fc x) | n == x = PRef fc n'
19701984 sm (PLam fc x t sc) | n /= x = PLam fc x (sm t) (sm sc)
1971− sm (PPi p x t sc) | n /=x = PPi p x (sm t) (sm sc)
1985+ | otherwise = PLam fc x (sm t) sc
1986+ sm (PPi p x t sc) | n /= x = PPi p x (sm t) (sm sc)
1987+ | otherwise = PPi p x (sm t) sc
19721988 sm (PLet fc x t v sc) | n /= x = PLet fc x (sm t) (sm v) (sm sc)
1989+ | otherwise = PLet fc x (sm t) (sm v) sc
19731990 sm (PApp f x as) = PApp f (sm x) (map (fmap sm) as)
19741991 sm (PAppBind f x as) = PAppBind f (sm x) (map (fmap sm) as)
19751992 sm (PCase f x as) = PCase f (sm x) (map (pmap sm) as)
@@ -2082,4 +2099,5 @@ mkUniqueNames env tm = evalState (mkUniq tm) (S.fromList env) where
20822099 mkUniq (PNoImplicits t) = liftM PNoImplicits (mkUniq t)
20832100 mkUniq (PProof ts) = liftM PProof (mapM mkUniqT ts)
20842101 mkUniq (PTactics ts) = liftM PTactics (mapM mkUniqT ts)
2102+ mkUniq (PRunTactics fc ts) = liftM (PRunTactics fc ) (mkUniq ts)
20852103 mkUniq t = return t
src/Idris/AbsSyntaxTree.hs+31−10
@@ -26,6 +26,7 @@ import qualified Control.Monad.Trans.Class as Trans (lift)
2626
2727import Data.Data (Data)
2828import Data.Function (on)
29+import Data.Generics.Uniplate.Data (universe)
2930import Data.List hiding (group)
3031import Data.Char
3132import qualified Data.Map.Strict as M
@@ -143,7 +144,7 @@ data LanguageExt = TypeProviders | ErrorReflection deriving (Show, Eq, Read, Ord
143144
144145-- | The output mode in use
145146data OutputMode = RawOutput Handle -- ^ Print user output directly to the handle
146− | IdeSlave Integer Handle -- ^ Send IDE output for some request ID to the handle
147+ | IdeMode Integer Handle -- ^ Send IDE output for some request ID to the handle
147148 deriving Show
148149
149150-- | How wide is the console?
@@ -404,8 +405,8 @@ data Opt = Filename String
404405 | Quiet
405406 | NoBanner
406407 | ColourREPL Bool
407− | Ideslave
408− | IdeslaveSocket
408+ | Idemode
409+ | IdemodeSocket
409410 | ShowLibs
410411 | ShowLibdir
411412 | ShowIncs
@@ -636,10 +637,10 @@ type ElabD a = Elab' EState a
636637--
637638-- 4. The where block (PDecl' t)
638639
639−data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
640− | PWith FC Name t [t] t [PDecl' t]
641− | PClauseR FC [t] t [PDecl' t]
642− | PWithR FC [t] t [PDecl' t]
640+data PClause' t = PClause FC Name t [t] t [PDecl' t] -- ^ A normal top-level definition.
641+ | PWith FC Name t [t] t (Maybe Name) [PDecl' t]
642+ | PClauseR FC [t] t [PDecl' t]
643+ | PWithR FC [t] t (Maybe Name) [PDecl' t]
643644 deriving Functor
644645{-!
645646deriving instance Binary PClause'
@@ -758,6 +759,7 @@ data PTerm = PQuote Raw -- ^ Inclusion of a core term into the high-level langua
758759 | PLet FC Name PTerm PTerm PTerm -- ^ A let binding
759760 | PTyped PTerm PTerm -- ^ Term with explicit type
760761 | PApp FC PTerm [PArg] -- ^ e.g. IO (), List Char, length x
762+ | PAppImpl PTerm [ImplicitInfo] -- ^ Implicit argument application (introduced during elaboration only)
761763 | PAppBind FC PTerm [PArg] -- ^ implicitly bound application
762764 | PMatchApp FC Name -- ^ Make an application by type matching
763765 | PCase FC PTerm [(PTerm, PTerm)] -- ^ A case expression. Args are source location, scrutinee, and a list of pattern/RHS pairs
@@ -789,7 +791,8 @@ data PTerm = PQuote Raw -- ^ Inclusion of a core term into the high-level langua
789791 | PUnifyLog PTerm -- ^ dump a trace of unifications when building term
790792 | PNoImplicits PTerm -- ^ never run implicit converions on the term
791793 | PQuasiquote PTerm (Maybe PTerm) -- ^ `(Term [: Term])
792− | PUnquote PTerm -- ^ ,Term
794+ | PUnquote PTerm -- ^ ~Term
795+ | PRunTactics FC PTerm -- ^ %runTactics tm - New-style proof script
793796 deriving (Eq, Data, Typeable)
794797
795798
@@ -829,6 +832,8 @@ data PTactic' t = Intro [Name] | Intros | Focus Name
829832 | Induction t
830833 | CaseTac t
831834 | Equiv t
835+ | Claim Name t
836+ | Unfocus
832837 | MatchRefine Name
833838 | LetTac Name t | LetTacTy Name t t
834839 | Exact t | Compute | Trivial | TCInstance
@@ -1243,6 +1248,9 @@ falseTy = sUN "Void"
12431248pairTy = sNS (sUN "Pair") ["Builtins"]
12441249pairCon = sNS (sUN "MkPair") ["Builtins"]
12451250
1251+upairTy = sNS (sUN "UPair") ["Builtins"]
1252+upairCon = sNS (sUN "MkUPair") ["Builtins"]
1253+
12461254eqTy = sUN "="
12471255eqCon = sUN "Refl"
12481256eqDoc = fmap (const (Left $ Msg "")) . parseDocstring . T.pack $
@@ -1376,6 +1384,7 @@ pprintPTerm ppo bnd docArgs infixes = prettySe startPrec bnd
13761384 where
13771385 startPrec = 0
13781386 funcAppPrec = 10
1387+
13791388 prettySe :: Int -> [(Name, Bool)] -> PTerm -> Doc OutputAnnotation
13801389 prettySe p bnd (PQuote r) =
13811390 text "![" <> pretty r <> text "]"
@@ -1641,6 +1650,16 @@ pprintPTerm ppo bnd docArgs infixes = prettySe startPrec bnd
16411650 getFixity :: String -> Maybe Fixity
16421651 getFixity = flip M.lookup fixities
16431652
1653+-- | Determine whether a name was the one inserted for a hole or
1654+-- guess by the delaborator
1655+isHoleName :: Name -> Bool
1656+isHoleName (UN n) = n == T.pack "[__]"
1657+isHoleName _ = False
1658+
1659+-- | Check whether a PTerm has been delaborated from a Term containing a Hole or Guess
1660+containsHole :: PTerm -> Bool
1661+containsHole pterm = or [isHoleName n | PRef _ n <- take 1000 $ universe pterm]
1662+
16441663-- | Pretty-printer helper for the binding site of a name
16451664bindingOf :: Name -- ^^ the bound name
16461665 -> Bool -- ^^ whether the name is implicit
@@ -1656,7 +1675,7 @@ prettyName
16561675 -> Doc OutputAnnotation
16571676prettyName infixParen showNS bnd n
16581677 | (MN _ s) <- n, isPrefixOf "_" $ T.unpack s = text "_"
1659− | (UN n') <- n, isPrefixOf "_" $ T.unpack n' = text "_"
1678+ | (UN n') <- n, T.unpack n' == "_" = text "_"
16601679 | Just imp <- lookup n bnd = annotate (AnnBoundName n imp) fullName
16611680 | otherwise = annotate (AnnName n Nothing Nothing Nothing) fullName
16621681 where fullName = text nameSpace <> parenthesise (text (baseName n))
@@ -1680,7 +1699,7 @@ showCImp ppo (PClause _ n l ws r w)
16801699 where
16811700 showWs [] = empty
16821701 showWs (x : xs) = text "|" <+> prettyImp ppo x <+> showWs xs
1683−showCImp ppo (PWith _ n l ws r w)
1702+showCImp ppo (PWith _ n l ws r pn w)
16841703 = prettyImp ppo l <+> showWs ws <+> text "with" <+> prettyImp ppo r
16851704 <+> braces (text (show w))
16861705 where
@@ -1728,6 +1747,8 @@ getShowArgs :: [PArg] -> [PArg]
17281747getShowArgs [] = []
17291748getShowArgs (e@(PExp _ _ _ tm) : xs) = e : getShowArgs xs
17301749getShowArgs (e : xs) | AlwaysShow `elem` argopts e = e : getShowArgs xs
1750+ | PImp _ _ _ _ tm <- e
1751+ , containsHole tm = e : getShowArgs xs
17311752getShowArgs (_ : xs) = getShowArgs xs
17321753
17331754getConsts :: [PArg] -> [PTerm]
src/Idris/CmdOptions.hs+5−3
@@ -26,7 +26,7 @@ runArgParser = do opts <- execParser $ info parser
2626 idrisProgDesc = PP.vsep [PP.empty,
2727 PP.text "Idris is a general purpose pure functional programming language with dependent",
2828 PP.text "types. Dependent types allow types to be predicated on values, meaning that",
29− PP.text "some aspects of a program’s behaviour can be specified precisely in the type.",
29+ PP.text "some aspects of a program's behaviour can be specified precisely in the type.",
3030 PP.text "It is compiled, with eager evaluation. Its features are influenced by Haskell",
3131 PP.text "and ML.",
3232 PP.empty,
@@ -71,8 +71,10 @@ parseFlags :: Parser [Opt]
7171parseFlags = many $
7272 flag' NoBanner (long "nobanner" <> help "Suppress the banner")
7373 <|> flag' Quiet (short 'q' <> long "quiet" <> help "Quiet verbosity")
74− <|> flag' Ideslave (long "ideslave")
75− <|> flag' IdeslaveSocket (long "ideslave-socket")
74+ <|> flag' Idemode (long "ide-mode" <> help "Run the Idris REPL with machine-readable syntax")
75+ <|> flag' IdemodeSocket (long "ide-mode-socket" <> help "Choose a socket for IDE mode to listen on")
76+ <|> flag' Idemode (long "ideslave" <> help "Deprecated version of --ide-mode") -- TODO: Remove in v0.9.18
77+ <|> flag' IdemodeSocket (long "ideslave-socket" <> help "Deprecated version of --ide-mode-socket") -- TODO: Remove in v0.9.18
7678 <|> (Client <$> strOption (long "client"))
7779 <|> (OLogging <$> option auto (long "log" <> metavar "LEVEL" <> help "Debugging log level"))
7880 <|> flag' NoBasePkgs (long "nobasepkgs" <> help "Do not use the given base package")
src/Idris/Core/Elaborate.hs+18−17
@@ -173,30 +173,30 @@ elaborating_app = do ES (ps, _) _ _ <- get
173173
174174-- Some handy gadgets for pulling out bits of state
175175
176−-- get the global context
176+-- | Get the global context
177177get_context :: Elab' aux Context
178178get_context = do ES p _ _ <- get
179179 return $! (context (fst p))
180180
181−-- update the context
181+-- | Update the context.
182182-- (should only be used for adding temporary definitions or all sorts of
183183-- stuff could go wrong)
184184set_context :: Context -> Elab' aux ()
185185set_context ctxt = do ES (p, a) logs prev <- get
186186 put (ES (p { context = ctxt }, a) logs prev)
187187
188−-- get the proof term
188+-- | get the proof term
189189get_term :: Elab' aux Term
190190get_term = do ES p _ _ <- get
191191 return $! (getProofTerm (pterm (fst p)))
192192
193−-- get the proof term
193+-- | modify the proof term
194194update_term :: (Term -> Term) -> Elab' aux ()
195195update_term f = do ES (p,a) logs prev <- get
196196 let p' = p { pterm = mkProofTerm (f (getProofTerm (pterm p))) }
197197 put (ES (p', a) logs prev)
198198
199−-- get the local context at the currently in focus hole
199+-- | get the local context at the currently in focus hole
200200get_env :: Elab' aux Env
201201get_env = do ES p _ _ <- get
202202 lift $ envAtFocus (fst p)
@@ -213,14 +213,14 @@ get_probs :: Elab' aux Fails
213213get_probs = do ES p _ _ <- get
214214 return $! (problems (fst p))
215215
216−-- Return recently solved names (that is, the names solved since the
216+-- | Return recently solved names (that is, the names solved since the
217217-- last call to get_recents)
218218get_recents :: Elab' aux [Name]
219219get_recents = do ES (p, a) l prev <- get
220220 put (ES (p { recents = [] }, a) l prev)
221221 return (recents p)
222222
223−-- get the current goal type
223+-- | get the current goal type
224224goal :: Elab' aux Type
225225goal = do ES p _ _ <- get
226226 b <- lift $ goalAtFocus (fst p)
@@ -233,15 +233,15 @@ is_guess = do ES p _ _ <- get
233233 Guess _ _ -> return True
234234 _ -> return False
235235
236−-- Get the guess at the current hole, if there is one
237−get_guess :: Elab' aux Type
236+-- | Get the guess at the current hole, if there is one
237+get_guess :: Elab' aux Term
238238get_guess = do ES p _ _ <- get
239239 b <- lift $ goalAtFocus (fst p)
240240 case b of
241241 Guess t v -> return $! v
242242 _ -> fail "Not a guess"
243243
244−-- typecheck locally
244+-- | Typecheck locally
245245get_type :: Raw -> Elab' aux Type
246246get_type tm = do ctxt <- get_context
247247 env <- get_env
@@ -254,7 +254,7 @@ get_type_val tm = do ctxt <- get_context
254254 (val, ty) <- lift $ check ctxt env tm
255255 return $! (finalise val, finalise ty)
256256
257−-- get holes we've deferred for later definition
257+-- | get holes we've deferred for later definition
258258get_deferred :: Elab' aux [Name]
259259get_deferred = do ES p _ _ <- get
260260 return $! (deferred (fst p))
@@ -271,17 +271,18 @@ checkInjective (tm, l, r) = do ctxt <- get_context
271271 isInj ctxt (Bind _ (Pi _ _ _) sc) = True
272272 isInj ctxt _ = False
273273
274−-- get instance argument names
274+-- | get instance argument names
275275get_instances :: Elab' aux [Name]
276276get_instances = do ES p _ _ <- get
277277 return $! (instances (fst p))
278278
279−-- get auto argument names
279+-- | get auto argument names
280280get_autos :: Elab' aux [(Name, [Name])]
281281get_autos = do ES p _ _ <- get
282282 return $! (autos (fst p))
283283
284−-- given a desired hole name, return a unique hole name
284+-- | given a desired hole name, return a unique hole name
285+unique_hole :: Name -> Elab' aux Name
285286unique_hole = unique_hole' False
286287
287288unique_hole' :: Bool -> Name -> Elab' aux Name
@@ -674,7 +675,7 @@ checkPiGoal n
674675 focus f
675676
676677simple_app :: Bool -> Elab' aux () -> Elab' aux () -> String -> Elab' aux ()
677−simple_app infer fun arg app0str =
678+simple_app infer fun arg str =
678679 do a <- getNameFrom (sMN 0 "argTy")
679680 b <- getNameFrom (sMN 0 "retTy")
680681 f <- getNameFrom (sMN 0 "f")
@@ -705,8 +706,8 @@ simple_app infer fun arg app0str =
705706 when (a `elem` hs) $ do movelast a
706707 when (b `elem` hs) $ do movelast b
707708 end_unify
708− where regretWith err = try regret
709− (lift $ tfail err)
709+ where
710+ regretWith err = try regret (lift $ tfail err)
710711
711712-- Abstract over an argument of unknown type, giving a name for the hole
712713-- which we'll fill with the argument type too.
src/Idris/Core/Evaluate.hs+29−24
@@ -11,7 +11,7 @@ module Idris.Core.Evaluate(normalise, normaliseTrace, normaliseC, normaliseAll,
1111 lookupNames, lookupTyName, lookupTyNameExact, lookupTy, lookupTyExact,
1212 lookupP, lookupDef, lookupNameDef, lookupDefExact, lookupDefAcc, lookupDefAccExact, lookupVal,
1313 mapDefCtxt,
14− lookupTotal, lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict, isDConName, isTConName, isConName, isFnName,
14+ lookupTotal, lookupNameTotal, lookupMetaInformation, lookupTyEnv, isTCDict, isDConName, canBeDConName, isTConName, isConName, isFnName,
1515 Value(..), Quote(..), initEval, uniqueNameCtxt, uniqueBindersCtxt, definitions,
1616 isUniverse) where
1717
@@ -971,47 +971,52 @@ isConName n ctxt = isTConName n ctxt || isDConName n ctxt
971971
972972isTConName :: Name -> Context -> Bool
973973isTConName n ctxt
974− = or $ do def <- lookupCtxt n (definitions ctxt)
975− case tfst def of
976− (TyDecl (TCon _ _) _) -> return True
977− _ -> return False
974+ = case lookupDefExact n ctxt of
975+ Just (TyDecl (TCon _ _) _) -> True
976+ _ -> False
978977
978+-- | Check whether a resolved name is certainly a data constructor
979979isDConName :: Name -> Context -> Bool
980980isDConName n ctxt
981+ = case lookupDefExact n ctxt of
982+ Just (TyDecl (DCon _ _ _) _) -> True
983+ _ -> False
984+
985+-- | Check whether any overloading of a name is a data constructor
986+canBeDConName :: Name -> Context -> Bool
987+canBeDConName n ctxt
981988 = or $ do def <- lookupCtxt n (definitions ctxt)
982989 case tfst def of
983− (TyDecl (DCon _ _ _) _) -> return True
984− _ -> return False
990+ (TyDecl (DCon _ _ _) _) -> return True
991+ _ -> return False
985992
986993isFnName :: Name -> Context -> Bool
987994isFnName n ctxt
988− = let def = lookupCtxtExact n (definitions ctxt) in
989− case def of
990− Just (Function _ _, _, _, _) -> True
991− Just (Operator _ _ _, _, _, _) -> True
992− Just (CaseOp _ _ _ _ _ _, _, _, _) -> True
993− _ -> False
995+ = case lookupDefExact n ctxt of
996+ Just (Function _ _) -> True
997+ Just (Operator _ _ _) -> True
998+ Just (CaseOp _ _ _ _ _ _) -> True
999+ _ -> False
9941000
9951001isTCDict :: Name -> Context -> Bool
9961002isTCDict n ctxt
997− = let def = lookupCtxtExact n (definitions ctxt) in
998− case def of
999− Just (Function _ _, _, _, _) -> False
1000− Just (Operator _ _ _, _, _, _) -> False
1001− Just (CaseOp ci _ _ _ _ _, _, _, _) -> tc_dictionary ci
1002− _ -> False
1003+ = case lookupDefExact n ctxt of
1004+ Just (Function _ _) -> False
1005+ Just (Operator _ _ _) -> False
1006+ Just (CaseOp ci _ _ _ _ _) -> tc_dictionary ci
1007+ _ -> False
10031008
10041009lookupP :: Name -> Context -> [Term]
10051010lookupP n ctxt
10061011 = do def <- lookupCtxt n (definitions ctxt)
10071012 p <- case def of
1008− (Function ty tm, a, _, _) -> return (P Ref n ty, a)
1009− (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
1013+ (Function ty tm, a, _, _) -> return (P Ref n ty, a)
1014+ (TyDecl nt ty, a, _, _) -> return (P nt n ty, a)
10101015 (CaseOp _ ty _ _ _ _, a, _, _) -> return (P Ref n ty, a)
1011− (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
1016+ (Operator ty _ _, a, _, _) -> return (P Ref n ty, a)
10121017 case snd p of
1013− Hidden -> []
1014− _ -> return (fst p)
1018+ Hidden -> []
1019+ _ -> return (fst p)
10151020
10161021lookupDefExact :: Name -> Context -> Maybe Def
10171022lookupDefExact n ctxt = tfst <$> lookupCtxtExact n (definitions ctxt)
src/Idris/Core/ProofState.hs+34−29
@@ -23,23 +23,23 @@ import Debug.Trace
2323import Util.Pretty hiding (fill)
2424
2525data ProofState = PS { thname :: Name,
26− holes :: [Name], -- holes still to be solved
27− usedns :: [Name], -- used names, don't use again
28− nextname :: Int, -- name supply
29− pterm :: ProofTerm, -- current proof term
30− ptype :: Type, -- original goal
31− dontunify :: [Name], -- explicitly given by programmer, leave it
26+ holes :: [Name], -- ^ holes still to be solved
27+ usedns :: [Name], -- ^ used names, don't use again
28+ nextname :: Int, -- ^ name supply
29+ pterm :: ProofTerm, -- ^ current proof term
30+ ptype :: Type, -- ^ original goal
31+ dontunify :: [Name], -- ^ explicitly given by programmer, leave it
3232 unified :: (Name, [(Name, Term)]),
3333 notunified :: [(Name, Term)],
34− dotted :: [(Name, [Name])], -- dot pattern holes + environment
35− -- either hole or something in env must turn up in the 'notunified' list during elaboration
34+ dotted :: [(Name, [Name])], -- ^ dot pattern holes + environment
35+ -- either hole or something in env must turn up in the 'notunified' list during elaboration
3636 solved :: Maybe (Name, Term),
3737 problems :: Fails,
3838 injective :: [Name],
39− deferred :: [Name], -- names we'll need to define
40− instances :: [Name], -- instance arguments (for type classes)
41− autos :: [(Name, [Name])], -- unsolved 'auto' implicits with their holes
42− previous :: Maybe ProofState, -- for undo
39+ deferred :: [Name], -- ^ names we'll need to define
40+ instances :: [Name], -- ^ instance arguments (for type classes)
41+ autos :: [(Name, [Name])], -- ^ unsolved 'auto' implicits with their holes
42+ previous :: Maybe ProofState, -- ^ for undo
4343 context :: Context,
4444 plog :: String,
4545 unifylog :: Bool,
@@ -290,12 +290,12 @@ addLog str = action (\ps -> ps { plog = plog ps ++ str ++ "\n" })
290290
291291newProof :: Name -> Context -> Type -> ProofState
292292newProof n ctxt ty = let h = holeName 0
293− ty' = vToP ty in
294− PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
295− (P Bound h ty'))) ty [] (h, []) [] []
296− Nothing [] []
297− [] [] []
298− Nothing ctxt "" False False [] []
293+ ty' = vToP ty
294+ in PS n [h] [] 1 (mkProofTerm (Bind h (Hole ty')
295+ (P Bound h ty'))) ty [] (h, []) [] []
296+ Nothing [] []
297+ [] [] []
298+ Nothing ctxt "" False False [] []
299299
300300type TState = ProofState -- [TacticAction])
301301type RunTactic = RunTactic' TState
@@ -530,6 +530,7 @@ solve ctxt env (Bind x (Guess ty val) sc)
530530 action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping hole " ++ show x) $
531531 holes ps \\ [x],
532532 solved = Just (x, val),
533+ dontunify = filter (/= x) (dontunify ps),
533534 notunified = updateNotunified [(x,val)]
534535 (notunified ps),
535536 recents = x : recents ps,
@@ -602,6 +603,7 @@ patvar n ctxt env (Bind x (Hole t) sc) =
602603 do action (\ps -> ps { holes = traceWhen (unifylog ps) ("Dropping pattern hole " ++ show x) $
603604 holes ps \\ [x],
604605 solved = Just (x, P Bound n t),
606+ dontunify = filter (/=x) (dontunify ps),
605607 notunified = updateNotunified [(x,P Bound n t)]
606608 (notunified ps),
607609 injective = addInj n x (injective ps)
@@ -851,6 +853,7 @@ updateProblems ps updates probs = up updates probs where
851853 hs = holes ps
852854 inj = injective ps
853855 ctxt = context ps
856+ ulog = unifylog ps
854857 usupp = map fst (notunified ps)
855858
856859 up ns [] = (ns, [])
@@ -862,8 +865,8 @@ updateProblems ps updates probs = up updates probs where
862865 if newx || newy || ready ||
863866 any (\n -> n `elem` inj) (refsIn x ++ refsIn y) then
864867 case unify ctxt env' x' y' inj hs usupp while of
865− OK (v, []) -> -- trace ("DID " ++ show (x',y',ready,v)) $
866− up (ns ++ v) ps
868+ OK (v, []) -> traceWhen ulog ("DID " ++ show (x',y',ready,v)) $
869+ up (ns ++ v) ps
867870 e -> -- trace ("FAILED " ++ show (x',y',ready,e)) $
868871 let (ns', ps') = up ns ps in
869872 (ns', (x',y', False, env',err', while, um) : ps')
@@ -911,7 +914,7 @@ processTactic EndUnify ps
911914 ns' = map (\ (n, t) -> (n, updateSolvedTerm ns t)) ns
912915 (ns'', probs') = updateProblems ps ns' (problems ps)
913916 tm' = updateSolved ns'' (pterm ps) in
914− traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
917+ traceWhen (unifylog ps) ("(EndUnify) Dropping holes: " ++ show (map fst ns'')) $
915918 return (ps { pterm = tm',
916919 unified = (h, []),
917920 problems = probs',
@@ -934,7 +937,7 @@ processTactic (ComputeLet n) ps
934937processTactic UnifyProblems ps
935938 = do let (ns', probs') = updateProblems ps [] (problems ps)
936939 pterm' = updateSolved ns' (pterm ps)
937− traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns')) $
940+ traceWhen (unifylog ps) ("(UnifyProblems) Dropping holes: " ++ show (map fst ns')) $
938941 return (ps { pterm = pterm', solved = Nothing, problems = probs',
939942 previous = Just ps, plog = "",
940943 notunified = updateNotunified ns' (notunified ps),
@@ -944,7 +947,7 @@ processTactic (MatchProblems all) ps
944947 = do let (ns', probs') = matchProblems all ps [] (problems ps)
945948 (ns'', probs'') = matchProblems all ps ns' probs'
946949 pterm' = updateSolved ns'' (pterm ps)
947− traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns'')) $
950+ traceWhen (unifylog ps) ("(MatchProblems) Dropping holes: " ++ show (map fst ns'')) $
948951 return (ps { pterm = pterm', solved = Nothing, problems = probs'',
949952 previous = Just ps, plog = "",
950953 notunified = updateNotunified ns'' (notunified ps),
@@ -954,16 +957,19 @@ processTactic t ps
954957 = case holes ps of
955958 [] -> fail "Nothing to fill in."
956959 (h:_) -> do ps' <- execStateT (process t h) ps
957− let (ns', probs')
960+ let (ns_in, probs')
958961 = case solved ps' of
959− Just s -> traceWhen (unifylog ps')
960− ("SOLVED " ++ show s) $
961− updateProblems ps [s] (problems ps')
962+ Just s -> traceWhen (unifylog ps)
963+ ("SOLVED " ++ show s ++ " " ++ show (dontunify ps')) $
964+ updateProblems ps' [s] (problems ps')
962965 _ -> ([], problems ps')
963966 -- rechecking problems may find more solutions, so
964967 -- apply them here
968+ let ns' = dropGiven (dontunify ps') ns_in (holes ps')
965969 let pterm'' = updateSolved ns' (pterm ps')
966− traceWhen (unifylog ps) ("Dropping holes: " ++ show (map fst ns')) $
970+ traceWhen (unifylog ps)
971+ ("Updated problems after solve " ++ qshow probs' ++ "\n" ++
972+ "(Toplevel) Dropping holes: " ++ show (map fst ns')) $
967973 return (ps' { pterm = pterm'',
968974 solved = Nothing,
969975 problems = probs',
@@ -986,7 +992,6 @@ process t h = tactic (Just h) (mktac t)
986992 mktac (MatchFill r) = match_fill r
987993 mktac (PrepFill n ns) = prep_fill n ns
988994 mktac CompleteFill = complete_fill
989− mktac Regret = regret
990995 mktac Solve = solve
991996 mktac (StartUnify n) = start_unify n
992997 mktac Compute = compute
src/Idris/Core/ProofTerm.hs+37−14
@@ -1,8 +1,9 @@
11{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, PatternGuards #-}
22
3−{- Implements a proof state, some primitive tactics for manipulating
4− proofs, and some high level commands for introducing new theorems,
5− evaluation/checking inside the proof system, etc. --}
3+{- | Implements a proof state, some primitive tactics for manipulating
4+proofs, and some high level commands for introducing new theorems,
5+evaluation/checking inside the proof system, etc.
6+-}
67
78module Idris.Core.ProofTerm(ProofTerm, Goal(..), mkProofTerm, getProofTerm,
89 updateSolved, updateSolvedTerm, updateSolvedTerm',
@@ -18,6 +19,7 @@ import Control.Monad.State.Strict
1819import Data.List
1920import Debug.Trace
2021
22+-- | A zipper over terms, in order to efficiently update proof terms.
2123data TermPath = Top
2224 | AppL TermPath Term
2325 | AppR Term TermPath
@@ -25,6 +27,7 @@ data TermPath = Top
2527 | InScope Name (Binder Term) TermPath
2628 deriving Show
2729
30+-- | A zipper over binders, because terms and binders are mutually defined.
2831data BinderPath = Binder (Binder TermPath)
2932 | LetT TermPath Term
3033 | LetV Term TermPath
@@ -32,6 +35,8 @@ data BinderPath = Binder (Binder TermPath)
3235 | GuessV Term TermPath
3336 deriving Show
3437
38+-- | Replace the top of a term path with another term path. In other
39+-- words, "graft" one term path into another.
3540replaceTop :: TermPath -> TermPath -> TermPath
3641replaceTop p Top = p
3742replaceTop p (AppL l t) = AppL (replaceTop p l) t
@@ -45,6 +50,7 @@ replaceTop p (InBind n bp sc) = InBind n (replaceTopB p bp) sc
4550 replaceTopB p (GuessV t v) = GuessV t (replaceTop p v)
4651replaceTop p (InScope n b sc) = InScope n b (replaceTop p sc)
4752
53+-- | Build a term from a zipper, given something to put in the hole.
4854rebuildTerm :: Term -> TermPath -> Term
4955rebuildTerm tm Top = tm
5056rebuildTerm tm (AppL p a) = App (rebuildTerm tm p) a
@@ -52,6 +58,7 @@ rebuildTerm tm (AppR f p) = App f (rebuildTerm tm p)
5258rebuildTerm tm (InScope n b p) = Bind n b (rebuildTerm tm p)
5359rebuildTerm tm (InBind n bp sc) = Bind n (rebuildBinder tm bp) sc
5460
61+-- | Build a binder from a zipper, given something to put in the hole.
5562rebuildBinder :: Term -> BinderPath -> Binder Term
5663rebuildBinder tm (Binder p) = fmap (rebuildTerm tm) p
5764rebuildBinder tm (LetT p t) = Let (rebuildTerm tm p) t
@@ -59,6 +66,9 @@ rebuildBinder tm (LetV v p) = Let v (rebuildTerm tm p)
5966rebuildBinder tm (GuessT p t) = Guess (rebuildTerm tm p) t
6067rebuildBinder tm (GuessV v p) = Guess v (rebuildTerm tm p)
6168
69+-- | Find the binding of a hole in a term. If present, return the path
70+-- to the hole's binding, the environment extended by the binders that
71+-- are crossed, and the actual binding term.
6272findHole :: Name -> Env -> Term -> Maybe (TermPath, Env, Term)
6373findHole n env t = fh' env Top t where
6474 fh' env path tm@(Bind x h sc)
@@ -80,7 +90,7 @@ findHole n env t = fh' env Top t where
8090 fhB env path b
8191 | Just (p, env', tm) <- fh' env path (binderTy b)
8292 = Just (Binder (fmap (\_ -> p) b), env', tm)
83− fhB _ _ _ = Nothing
93+ fhB _ _ _ = Nothing
8494
8595data ProofTerm = PT { -- wholeterm :: Term,
8696 path :: TermPath,
@@ -92,13 +102,17 @@ data ProofTerm = PT { -- wholeterm :: Term,
92102type RunTactic' a = Context -> Env -> Term -> StateT a TC Term
93103type Hole = Maybe Name -- Nothing = default hole, first in list in proof state
94104
105+-- | Refocus the proof term zipper on a particular hole, if it
106+-- exists. If not, return the original proof term.
95107refocus :: Hole -> ProofTerm -> ProofTerm
96108refocus h t = let res = refocus' h t in res
97109-- trace ("OLD: " ++ show t ++ "\n" ++
98110-- "REFOCUSSED " ++ show h ++ ": " ++ show res) res
99111refocus' (Just n) pt@(PT path env tm ups)
112+ -- First look for the hole in the proof term as-is
100113 | Just (p', env', tm') <- findHole n env tm
101114 = PT (replaceTop p' path) env' tm' ups
115+ -- Next apply the updates, and look for the hole in the resulting term
102116 | Just (p', env', tm') <- findHole n [] (rebuildTerm tm (updateSolvedPath ups path))
103117 = PT p' env' tm' []
104118 | otherwise = pt
@@ -118,27 +132,32 @@ same :: Eq a => Maybe a -> a -> Bool
118132same Nothing n = True
119133same (Just x) n = x == n
120134
135+-- | Is a particular binder a hole or a guess?
121136hole :: Binder b -> Bool
122137hole (Hole _) = True
123138hole (Guess _ _) = True
124139hole _ = False
125140
126−updateSolvedTerm :: [(Name, Term)] -> Term -> Term
141+-- | Given a list of solved holes, fill out the solutions in a term
142+updateSolvedTerm :: [(Name, Term)] -> Term -> Term
127143updateSolvedTerm xs x = fst $ updateSolvedTerm' xs x
128144
145+-- | Given a list of solved holes, fill out the solutions in a
146+-- term. Return whether updates were performed, to facilitate sharing
147+-- when there are no updates.
148+updateSolvedTerm' :: [(Name, Term)] -> Term -> (Term, Bool)
129149updateSolvedTerm' [] x = (x, False)
130−updateSolvedTerm' xs x = -- updateSolved' xs x where
131−-- This version below saves allocations, because it doesn't need to reallocate
132−-- the term if there are no updates to do.
133−-- The Bool is ugly, and probably 'Maybe' would be less ugly, but >>= is
134−-- the wrong combinator. Feel free to tidy up as long as it's still as cheap :).
135− updateSolved' xs x where
150+updateSolvedTerm' xs x = updateSolved' xs x where
151+ -- This version below saves allocations, because it doesn't need to reallocate
152+ -- the term if there are no updates to do.
153+ -- The Bool is ugly, and probably 'Maybe' would be less ugly, but >>= is
154+ -- the wrong combinator. Feel free to tidy up as long as it's still as cheap :).
136155 updateSolved' [] x = (x, False)
137156 updateSolved' xs (Bind n (Hole ty) t)
138− | Just v <- lookup n xs
157+ | Just v <- lookup n xs
139158 = case xs of
140159 [_] -> (subst n v t, True) -- some may be Vs! Can't assume
141− -- explicit names
160+ -- explicit names
142161 _ -> let (t', _) = updateSolved' xs t in
143162 (subst n v t', True)
144163 updateSolved' xs tm@(Bind n b t)
@@ -146,7 +165,7 @@ updateSolvedTerm' xs x = -- updateSolved' xs x where
146165 (b', ub) = updateSolvedB' xs b in
147166 if ut || ub then (Bind n b' t', True)
148167 else (tm, False)
149− updateSolved' xs t@(App f a)
168+ updateSolved' xs t@(App f a)
150169 = let (f', uf) = updateSolved' xs f
151170 (a', ua) = updateSolved' xs a in
152171 if uf || ua then (App f' a', True)
@@ -176,10 +195,14 @@ updateSolvedTerm' xs x = -- updateSolved' xs x where
176195 noneOfB ns b = noneOf ns (binderTy b)
177196 noneOf ns _ = True
178197
198+-- | Apply solutions to an environment.
199+updateEnv :: [(Name, Term)] -> Env -> Env
179200updateEnv [] e = e
180201updateEnv ns [] = []
181202updateEnv ns ((n, b) : env) = (n, fmap (updateSolvedTerm ns) b) : updateEnv ns env
182203
204+-- | Fill out solved holes in a term zipper.
205+updateSolvedPath :: [(Name, Term)] -> TermPath -> TermPath
183206updateSolvedPath [] t = t
184207updateSolvedPath ns Top = Top
185208updateSolvedPath ns (AppL p r) = AppL (updateSolvedPath ns p) (updateSolvedTerm ns r)
src/Idris/Core/TT.hs+3
@@ -1345,6 +1345,8 @@ showEnv' env t dbg = se 10 env t where
13451345 = (show $ fst $ env!!i) ++
13461346 if dbg then "{" ++ show i ++ "}" else ""
13471347 | otherwise = "!!V " ++ show i ++ "!!"
1348+ se p env (Bind n b@(Pi (Just _) t k) sc)
1349+ = bracket p 2 $ sb env n b ++ se 10 ((n,b):env) sc
13481350 se p env (Bind n b@(Pi _ t k) sc)
13491351 | noOccurrence n sc && not dbg = bracket p 2 $ se 1 env t ++ arrow k ++ se 10 ((n,b):env) sc
13501352 where arrow (TType _) = " -> "
@@ -1361,6 +1363,7 @@ showEnv' env t dbg = se 10 env t where
13611363 sb env n (Lam t) = showb env "\\ " " => " n t
13621364 sb env n (Hole t) = showb env "? " ". " n t
13631365 sb env n (GHole i t) = showb env "?defer " ". " n t
1366+ sb env n (Pi (Just _) t _) = showb env "{" "} -> " n t
13641367 sb env n (Pi _ t _) = showb env "(" ") -> " n t
13651368 sb env n (PVar t) = showb env "pat " ". " n t
13661369 sb env n (PVTy t) = showb env "pty " ". " n t
src/Idris/Core/Unify.hs+3−3
@@ -153,7 +153,7 @@ match_unify ctxt env topx topy inj holes from =
153153 h2 <- un bnames vx vy
154154 combine bnames h1 h2
155155 uB bnames (Lam tx) (Lam ty) = un bnames tx ty
156− uB bnames (Pi _ tx _) (Pi _ ty _) = un bnames tx ty
156+ uB bnames (Pi i tx _) (Pi i' ty _) = un bnames tx ty
157157 uB bnames x y = do UI s f <- get
158158 let r = recoverable (normalise ctxt env (binderTy x))
159159 (normalise ctxt env (binderTy y))
@@ -461,8 +461,8 @@ unify ctxt env topx topy inj holes usersupp from =
461461 h2 <- un' False (((x,y),binderTy bx):bnames) sx sy
462462 combine bnames h1 h2
463463 where sameBinder (Lam _) (Lam _) = True
464− sameBinder (Pi _ _ _) (Pi _ _ _) = True
465− sameBinder _ _ = False
464+ sameBinder (Pi i _ _) (Pi i' _ _) = True
465+ sameBinder _ _ = False -- never unify holes/guesses/etc
466466 un' fn bnames x y
467467 | OK True <- convEq' ctxt holes x y = do sc 1; return []
468468 | isUniverse x && isUniverse y = do sc 1; return []
src/Idris/Coverage.hs+10−11
@@ -18,18 +18,18 @@ import Debug.Trace
1818
1919import Control.Monad.State.Strict
2020
21−-- Generate a pattern from an 'impossible' LHS. (Need this to eliminate the
22−-- pattern clauses which have been provided explicitly from new clause
23−-- generation.)
24−
21+-- | Generate a pattern from an 'impossible' LHS.
22+--
23+-- We need this to eliminate the pattern clauses which have been
24+-- provided explicitly from new clause generation.
2525mkPatTm :: PTerm -> Idris Term
2626mkPatTm t = do i <- getIState
2727 let timp = addImpl' True [] [] i t
2828 evalStateT (toTT (mapPT deNS timp)) 0
2929 where
3030 toTT (PRef _ n) = do i <- lift getIState
31− case lookupDef n (tt_ctxt i) of
32− [TyDecl nt _] -> return $ P nt n Erased
31+ case lookupNameDef n (tt_ctxt i) of
32+ [(n', TyDecl nt _)] -> return $ P nt n' Erased
3333 _ -> return $ P Ref n Erased
3434 toTT (PApp _ t args) = do t' <- toTT t
3535 args' <- mapM (toTT . getTm) args
@@ -44,13 +44,12 @@ mkPatTm t = do i <- getIState
4444 deNS (PRef f (NS n _)) = PRef f n
4545 deNS t = t
4646
47−-- Given a list of LHSs, generate a extra clauses which cover the remaining
48−-- cases. The ones which haven't been provided are marked 'absurd' so that the
49−-- checker will make sure they can't happen.
50−
47+-- | Given a list of LHSs, generate a extra clauses which cover the remaining
48+-- cases. The ones which haven't been provided are marked 'absurd' so
49+-- that the checker will make sure they can't happen.
50+--
5151-- This will only work after the given clauses have been typechecked and the
5252-- names are fully explicit!
53−
5453genClauses :: FC -> Name -> [Term] -> [PTerm] -> Idris [PTerm]
5554genClauses fc n xs given
5655 = do i <- getIState
src/Idris/DSL.hs+2
@@ -76,6 +76,7 @@ expandDo dsl (PDoBlock ds)
7676 block b _ = PElabError (Msg "Invalid statement in do block")
7777
7878expandDo dsl (PIdiom fc e) = expandDo dsl $ unIdiom (dsl_apply dsl) (dsl_pure dsl) fc e
79+expandDo dsl (PRunTactics fc tm) = PRunTactics fc $ expandDo dsl tm
7980expandDo dsl t = t
8081
8182-- | Replace DSL-bound variable in a term
@@ -162,6 +163,7 @@ debind b tm = let (tm', (bs, _)) = runState (db' tm) ([], 0) in
162163 db' (PDPair fc p l t r) = do l' <- db' l
163164 r' <- db' r
164165 return (PDPair fc p l' t r')
166+ db' (PRunTactics fc t) = fmap (PRunTactics fc) (db' t)
165167 db' t = return t
166168
167169 dbArg a = do t' <- db' (getTm a)
src/Idris/DeepSeq.hs+8−4
@@ -178,13 +178,13 @@ instance (NFData t) => NFData (PClause' t) where
178178 rnf (PClause x1 x2 x3 x4 x5 x6)
179179 = rnf x1 `seq`
180180 rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` ()
181− rnf (PWith x1 x2 x3 x4 x5 x6)
181+ rnf (PWith x1 x2 x3 x4 x5 x6 x7)
182182 = rnf x1 `seq`
183− rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` ()
183+ rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` rnf x6 `seq` rnf x7 `seq` ()
184184 rnf (PClauseR x1 x2 x3 x4)
185185 = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` ()
186− rnf (PWithR x1 x2 x3 x4)
187− = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` ()
186+ rnf (PWithR x1 x2 x3 x4 x5)
187+ = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` rnf x5 `seq` ()
188188
189189instance (NFData t) => NFData (PData' t) where
190190 rnf (PDatadecl x1 x2 x3)
@@ -202,6 +202,7 @@ instance NFData PTerm where
202202 rnf (PLet _ x1 x2 x3 x4)
203203 = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` rnf x4 `seq` ()
204204 rnf (PTyped x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
205+ rnf (PAppImpl x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
205206 rnf (PApp x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
206207 rnf (PAppBind x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
207208 rnf (PMatchApp x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
@@ -238,6 +239,7 @@ instance NFData PTerm where
238239 rnf (PNoImplicits x1) = rnf x1 `seq` ()
239240 rnf (PQuasiquote x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
240241 rnf (PUnquote x1) = rnf x1 `seq` ()
242+ rnf (PRunTactics x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
241243
242244instance (NFData t) => NFData (PTactic' t) where
243245 rnf (Intro x1) = rnf x1 `seq` ()
@@ -249,6 +251,7 @@ instance (NFData t) => NFData (PTactic' t) where
249251 rnf (Induction x1) = rnf x1 `seq` ()
250252 rnf (CaseTac x1) = rnf x1 `seq` ()
251253 rnf (Equiv x1) = rnf x1 `seq` ()
254+ rnf (Claim x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
252255 rnf (MatchRefine x1) = rnf x1 `seq` ()
253256 rnf (LetTac x1 x2) = rnf x1 `seq` rnf x2 `seq` ()
254257 rnf (LetTacTy x1 x2 x3) = rnf x1 `seq` rnf x2 `seq` rnf x3 `seq` ()
@@ -279,6 +282,7 @@ instance (NFData t) => NFData (PTactic' t) where
279282 rnf Skip = ()
280283 rnf (TFail x1) = rnf x1 `seq` ()
281284 rnf SourceFC = ()
285+ rnf Unfocus = ()
282286
283287instance NFData ErrorReportPart where
284288 rnf (TermPart x1) = rnf x1 `seq` ()
src/Idris/Delaborate.hs+2−2
@@ -308,7 +308,7 @@ pprintErr' i (ElaboratingArg f x _ e)
308308 where whatIsName = let ctxt = tt_ctxt i
309309 in if isTConName f ctxt
310310 then text "type constructor" <> space
311− else if isConName f ctxt
311+ else if isDConName f ctxt
312312 then text "constructor" <> space
313313 else if isFnName f ctxt
314314 then text "function" <> space
@@ -488,7 +488,7 @@ fancifyAnnots ist annot@(AnnName n _ _ _) =
488488 _ | isTConName n ctxt -> AnnName n (Just TypeOutput) docs ty
489489 _ | isMetavarName n ist -> AnnName n (Just MetavarOutput) docs ty
490490 _ | isPostulateName n ist -> AnnName n (Just PostulateOutput) docs ty
491− _ | otherwise -> annot
491+ _ | otherwise -> annot
492492 where docOverview :: IState -> Name -> Maybe String -- pretty-print first paragraph of docs
493493 docOverview ist n = do docs <- lookupCtxtExact n (idris_docstrings ist)
494494 let o = overview (fst docs)
src/Idris/Elab/Clause.hs+43−25
@@ -648,9 +648,9 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
648648 -- Now build the RHS, using the type of the LHS as the goal.
649649 i <- getIState -- new implicits from where block
650650 logLvl 5 (showTmImpls (expandParams decorate newargs defs (defs \\ decls) rhs_in))
651− let rhs = addImplBoundInf i (map fst newargs) (defs \\ decls)
651+ let rhs = addImplBoundInf i (map fst newargs_all) (defs \\ decls)
652652 (expandParams decorate newargs defs (defs \\ decls) rhs_in)
653− logLvl 2 $ "RHS: " ++ showTmImpls rhs
653+ logLvl 2 $ "RHS: " ++ show (map fst newargs_all) ++ " " ++ showTmImpls rhs
654654 ctxt <- getContext -- new context with where block added
655655 logLvl 5 "STARTING CHECK"
656656 ((rhs', defer, is, probs), _) <-
@@ -673,7 +673,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
673673 when inf $ addTyInfConstraints fc (map (\(x,y,_,_,_,_,_) -> (x,y)) probs)
674674
675675 logLvl 5 "DONE CHECK"
676− logLvl 2 $ "---> " ++ show rhs'
676+ logLvl 4 $ "---> " ++ show rhs'
677677 when (not (null defer)) $ iLOG $ "DEFERRED " ++
678678 show (map (\ (n, (_,_,t)) -> (n, t)) defer)
679679 def' <- checkDef fc defer
@@ -796,7 +796,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
796796 isArg' _ = False
797797 isArg _ _ = False
798798
799−elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
799+elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
800800 = do let tcgen = Dictionary `elem` opts
801801 ctxt <- getContext
802802 -- Build the LHS as an "Infer", and pull out its type and
@@ -859,6 +859,11 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
859859 -- rather than a de Bruijn index.
860860 let pdeps = usedNamesIn pvars i (delab i cwvalty)
861861 let (bargs_pre, bargs_post) = split pdeps bargs []
862+
863+ let mpn = case pn_in of
864+ Nothing -> Nothing
865+ Just n -> Just (uniqueName n (map fst bargs))
866+
862867 logLvl 10 ("With type " ++ show (getRetTy cwvaltyN) ++
863868 " depends on " ++ show pdeps ++ " from " ++ show pvars)
864869 logLvl 10 ("Pre " ++ show bargs_pre ++ "\nPost " ++ show bargs_post)
@@ -867,12 +872,19 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
867872 -- (ps : Xs) -> (withval : cwvalty) -> (ps' : Xs') -> ret_ty
868873 let wargval = getRetTy cwvalN
869874 let wargtype = getRetTy cwvaltyN
875+ let wargname = sMN windex "warg"
876+
870877 logLvl 5 ("Abstract over " ++ show wargval ++ " in " ++ show wargtype)
871878 let wtype = bindTyArgs (flip (Pi Nothing) (TType (UVar 0))) (bargs_pre ++
872− (sMN 0 "warg", wargtype) :
873− map (abstract (sMN 0 "warg") wargval wargtype) bargs_post)
874− (substTerm wargval (P Bound (sMN 0 "warg") wargtype) ret_ty)
875− logLvl 5 ("New function type " ++ show wtype)
879+ (wargname, wargtype) :
880+ map (abstract wargname wargval wargtype) bargs_post ++
881+ case mpn of
882+ Just pn -> [(pn, mkApp (P Ref eqTy Erased)
883+ [wargtype, wargtype,
884+ P Bound wargname Erased, wargval])]
885+ Nothing -> [])
886+ (substTerm wargval (P Bound wargname wargtype) ret_ty)
887+ logLvl 3 ("New function type " ++ show wtype)
876888 let wname = SN (WithN windex fname)
877889
878890 let imps = getImps wtype -- add to implicits context
@@ -893,18 +905,21 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
893905 -- in the subdecls, lhs becomes:
894906 -- fname pats | wpat [rest]
895907 -- ==> fname' ps wpat [rest], match pats against toplevel for ps
896− wb <- mapM (mkAuxC wname lhs (map fst bargs_pre) (map fst bargs_post))
908+ wb <- mapM (mkAuxC mpn wname lhs (map fst bargs_pre) (map fst bargs_post))
897909 withblock
898910 logLvl 3 ("with block " ++ show wb)
899911 -- propagate totality assertion to the new definitions
900912 when (AssertTotal `elem` opts) $ setFlags wname [AssertTotal]
901913 mapM_ (rec_elabDecl info EAll info) wb
902914
903− -- rhs becomes: fname' ps wval
915+ -- rhs becomes: fname' ps_pre wval ps_post Refl
904916 let rhs = PApp fc (PRef fc wname)
905917 (map (pexp . (PRef fc) . fst) bargs_pre ++
906918 pexp wval :
907− (map (pexp . (PRef fc) . fst) bargs_post))
919+ (map (pexp . (PRef fc) . fst) bargs_post) ++
920+ case mpn of
921+ Nothing -> []
922+ Just _ -> [pexp (PRefl fc Placeholder)])
908923 logLvl 5 ("New RHS " ++ showTmImpls rhs)
909924 ctxt <- getContext -- New context with block added
910925 i <- getIState
@@ -927,13 +942,13 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
927942 getImps (Bind n (Pi _ _ _) t) = pexp Placeholder : getImps t
928943 getImps _ = []
929944
930− mkAuxC wname lhs ns ns' (PClauses fc o n cs)
931− | True = do cs' <- mapM (mkAux wname lhs ns ns') cs
945+ mkAuxC pn wname lhs ns ns' (PClauses fc o n cs)
946+ | True = do cs' <- mapM (mkAux pn wname lhs ns ns') cs
932947 return $ PClauses fc o wname cs'
933948 | otherwise = ifail $ show fc ++ "with clause uses wrong function name " ++ show n
934− mkAuxC wname lhs ns ns' d = return $ d
949+ mkAuxC pn wname lhs ns ns' d = return $ d
935950
936− mkAux wname toplhs ns ns' (PClause fc n tm_in (w:ws) rhs wheres)
951+ mkAux pn wname toplhs ns ns' (PClause fc n tm_in (w:ws) rhs wheres)
937952 = do i <- getIState
938953 let tm = addImplPat i tm_in
939954 logLvl 2 ("Matching " ++ showTmImpls tm ++ " against " ++
@@ -942,33 +957,36 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in withblock)
942957 Left (a,b) -> ifail $ show fc ++ ":with clause does not match top level"
943958 Right mvars ->
944959 do logLvl 3 ("Match vars : " ++ show mvars)
945− lhs <- updateLHS n wname mvars ns ns' (fullApp tm) w
960+ lhs <- updateLHS n pn wname mvars ns ns' (fullApp tm) w
946961 return $ PClause fc wname lhs ws rhs wheres
947− mkAux wname toplhs ns ns' (PWith fc n tm_in (w:ws) wval withs)
962+ mkAux pn wname toplhs ns ns' (PWith fc n tm_in (w:ws) wval pn' withs)
948963 = do i <- getIState
949964 let tm = addImplPat i tm_in
950965 logLvl 2 ("Matching " ++ showTmImpls tm ++ " against " ++
951966 showTmImpls toplhs)
952− withs' <- mapM (mkAuxC wname toplhs ns ns') withs
967+ withs' <- mapM (mkAuxC pn wname toplhs ns ns') withs
953968 case matchClause i toplhs tm of
954969 Left (a,b) -> trace ("matchClause: " ++ show a ++ " =/= " ++ show b) (ifail $ show fc ++ "with clause does not match top level")
955970 Right mvars ->
956− do lhs <- updateLHS n wname mvars ns ns' (fullApp tm) w
957− return $ PWith fc wname lhs ws wval withs'
958− mkAux wname toplhs ns ns' c
971+ do lhs <- updateLHS n pn wname mvars ns ns' (fullApp tm) w
972+ return $ PWith fc wname lhs ws wval pn' withs'
973+ mkAux pn wname toplhs ns ns' c
959974 = ifail $ show fc ++ ":badly formed with clause"
960975
961976 addArg (PApp fc f args) w = PApp fc f (args ++ [pexp w])
962977 addArg (PRef fc f) w = PApp fc (PRef fc f) [pexp w]
963978
964− updateLHS n wname mvars ns_in ns_in' (PApp fc (PRef fc' n') args) w
979+ updateLHS n pn wname mvars ns_in ns_in' (PApp fc (PRef fc' n') args) w
965980 = let ns = map (keepMvar (map fst mvars) fc') ns_in
966981 ns' = map (keepMvar (map fst mvars) fc') ns_in' in
967982 return $ substMatches mvars $
968983 PApp fc (PRef fc' wname)
969− (map pexp ns ++ pexp w : (map pexp ns'))
970− updateLHS n wname mvars ns_in ns_in' tm w
971− = updateLHS n wname mvars ns_in ns_in' (PApp fc tm []) w
984+ (map pexp ns ++ pexp w : (map pexp ns') ++
985+ case pn of
986+ Nothing -> []
987+ Just pnm -> [pexp (PRef fc pnm)])
988+ updateLHS n pn wname mvars ns_in ns_in' tm w
989+ = updateLHS n pn wname mvars ns_in ns_in' (PApp fc tm []) w
972990
973991 keepMvar mvs fc v | v `elem` mvs = PRef fc v
974992 | otherwise = Placeholder
src/Idris/Elab/Data.hs+4−2
@@ -316,11 +316,13 @@ elabCaseFun ind paramPos n ty cons info = do
316316 eliminatorClauses <- mapM (\(cns, cnsElim) -> generateEliminatorClauses cns cnsElim clauseGeneralArgs generalParams) (zip cons clauseConsElimArgs)
317317 let eliminatorDef = PClauses emptyFC [TotalFn] elimDeclName eliminatorClauses
318318 elimLog $ "-- case function definition: " ++ (show . showDeclImp verbosePPOption) eliminatorDef
319− State.lift $ idrisCatch (rec_elabDecl info EAll info eliminatorTyDecl) (\err -> return ())
319+ State.lift $ idrisCatch (rec_elabDecl info EAll info eliminatorTyDecl)
320+ (ierror . Elaborating "type declaration of " elimDeclName)
320321 -- Do not elaborate clauses if there aren't any
321322 case eliminatorClauses of
322323 [] -> State.lift $ solveDeferred elimDeclName -- Remove meta-variable for type
323− _ -> State.lift $ idrisCatch (rec_elabDecl info EAll info eliminatorDef) (\err -> return ())
324+ _ -> State.lift $ idrisCatch (rec_elabDecl info EAll info eliminatorDef)
325+ (ierror . Elaborating "clauses of " elimDeclName)
324326 where elimLog :: String -> EliminatorState ()
325327 elimLog s = State.lift (logLvl 2 s)
326328
src/Idris/Elab/Provider.hs+16−10
@@ -74,9 +74,9 @@ elabProvider info syn fc what n
7474 (e, et) <- case what of
7575 ProvTerm _ tm -> elabVal info ERHS tm
7676 ProvPostulate tm -> elabVal info ERHS tm
77− unless (isProviderOf (normalise ctxt [] ty') et) $
78− ifail $ "Expected provider type IO (Provider (" ++
79− show ty' ++ "))" ++ ", got " ++ show et ++ " instead."
77+ unless (isProviderOf ctxt ty' et) $
78+ ifail $ "Expected provider type " ++ show (providerOf ty') ++
79+ ", got " ++ show et ++ " instead."
8080
8181 -- Execute the type provider and normalise the result
8282 -- use 'run__provider' to convert to a primitive IO action
@@ -107,11 +107,17 @@ elabProvider info syn fc what n
107107 isTType (TType _) = True
108108 isTType _ = False
109109
110− isProviderOf :: TT Name -> TT Name -> Bool
111− isProviderOf tp prov
112− | (P _ (UN io) _, [prov']) <- unApply prov
113− , (P _ (NS (UN prov) [provs]) _, [tp']) <- unApply prov'
114− , tp == tp', io == txt "IO"
115− , prov == txt "Provider" && provs == txt "Providers" = True
116− isProviderOf _ _ = False
110+ -- Note: IO (Providers.Provider ty) is used instead of IO'
111+ -- (MkFFI C_FFI) (Providers.Provider ty) in hopes of better
112+ -- error messages with less normalisation
113+ providerOf :: Type -> Type
114+ providerOf ty = App (P Ref (sUN "IO") Erased) $
115+ App (P Ref (sNS (sUN "Provider") ["Providers"]) Erased)
116+ ty
117+
118+ isProviderOf :: Context -> TT Name -> TT Name -> Bool
119+ isProviderOf ctxt tp prov =
120+ case converts ctxt [] (providerOf tp) prov of
121+ OK _ -> True
122+ _ -> False
117123
src/Idris/Elab/Utils.hs+2−2
@@ -120,8 +120,8 @@ decorateid decorate (PTy doc argdocs s f o n t) = PTy doc argdocs s f o (decorat
120120decorateid decorate (PClauses f o n cs)
121121 = PClauses f o (decorate n) (map dc cs)
122122 where dc (PClause fc n t as w ds) = PClause fc (decorate n) (dappname t) as w ds
123− dc (PWith fc n t as w ds)
124− = PWith fc (decorate n) (dappname t) as w
123+ dc (PWith fc n t as w pn ds)
124+ = PWith fc (decorate n) (dappname t) as w pn
125125 (map (decorateid decorate) ds)
126126 dappname (PApp fc (PRef fc' n) as) = PApp fc (PRef fc' (decorate n)) as
127127 dappname t = t
src/Idris/ElabQuasiquote.hs+3
@@ -36,6 +36,7 @@ extractTUnquotes n (GoalType s tac)
3636 return (GoalType s tac', ex)
3737extractTUnquotes n (TCheck t) = extract1 n TCheck t
3838extractTUnquotes n (TEval t) = extract1 n TEval t
39+extractTUnquotes n (Claim name t) = extract1 n (Claim name) t
3940extractTUnquotes n tac = return (tac, []) -- the rest don't contain PTerms
4041
4142extractPArgUnquotes :: Int -> PArg -> Elab' aux (PArg, [(Name, PTerm)])
@@ -169,6 +170,8 @@ extractUnquotes n (PUnquote tm)
169170 return (PRef (fileFC "(unquote)") n, [(n, tm)])
170171 | otherwise = fmap (\(tm', ex) -> (PUnquote tm', ex)) $
171172 extractUnquotes (n-1) tm
173+extractUnquotes n (PRunTactics fc tm)
174+ = fmap (\(tm', ex) -> (PRunTactics fc tm', ex)) $ extractUnquotes n tm
172175extractUnquotes n x = return (x, []) -- no subterms!
173176
174177
src/Idris/ElabTerm.hs+493−174
@@ -1,5 +1,5 @@
1−{-# LANGUAGE PatternGuards #-}
2−
1+{-# LANGUAGE PatternGuards, ViewPatterns #-}
2+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
33module Idris.ElabTerm where
44
55import Idris.AbsSyntax
@@ -164,13 +164,14 @@ getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
164164getUnmatchable ctxt n = []
165165
166166data ElabCtxt = ElabCtxt { e_inarg :: Bool,
167+ e_isfn :: Bool, -- ^ Function part of application
167168 e_guarded :: Bool,
168169 e_intype :: Bool,
169170 e_qq :: Bool,
170171 e_nomatching :: Bool -- ^ can't pattern match
171172 }
172173
173−initElabCtxt = ElabCtxt False False False False False
174+initElabCtxt = ElabCtxt False False False False False False
174175
175176goal_polymorphic :: ElabD Bool
176177goal_polymorphic =
@@ -244,7 +245,7 @@ elab ist info emode opts fn tm
244245 then solveAuto ist fn False a
245246 else return ()) as
246247
247− itm <- if not pattern then insertImpLam t else return t
248+ itm <- if not pattern then insertImpLam ina t else return t
248249 ct <- insertCoerce ina itm
249250 t' <- insertLazy ct
250251 g <- goal
@@ -308,7 +309,7 @@ elab ist info emode opts fn tm
308309 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
309310 && isTypeConst c
310311 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
311− | pattern && not reflection && e_nomatching ina
312+ | pattern && not reflection && not (e_qq ina) && e_nomatching ina
312313 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
313314 | otherwise = do apply (RConstant c) []; solve
314315 elab' ina fc (PQuote r) = do fill r; solve
@@ -317,6 +318,7 @@ elab ist info emode opts fn tm
317318 g <- goal
318319 case g of
319320 TType _ -> elab' ina (Just fc) (PRef fc unitTy)
321+ UType _ -> elab' ina (Just fc) (PRef fc unitTy)
320322 _ -> elab' ina (Just fc) (PRef fc unitCon)
321323 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
322324 = do g <- goal; resolveTC False 5 g fn ist
@@ -352,13 +354,32 @@ elab ist info emode opts fn tm
352354 elab' ina _ (PPair fc _ l r)
353355 = do hnf_compute
354356 g <- goal
357+ let (tc, _) = unApply g
355358 case g of
356359 TType _ -> elab' ina (Just fc) (PApp fc (PRef fc pairTy)
357360 [pexp l,pexp r])
358− _ -> elab' ina (Just fc) (PApp fc (PRef fc pairCon)
361+ UType _ -> elab' ina (Just fc) (PApp fc (PRef fc upairTy)
362+ [pexp l,pexp r])
363+ _ -> case tc of
364+ P _ n _ | n == upairTy
365+ -> elab' ina (Just fc) (PApp fc (PRef fc upairCon)
366+ [pimp (sUN "A") Placeholder False,
367+ pimp (sUN "B") Placeholder False,
368+ pexp l, pexp r])
369+ _ -> elab' ina (Just fc) (PApp fc (PRef fc pairCon)
359370 [pimp (sUN "A") Placeholder False,
360371 pimp (sUN "B") Placeholder False,
361372 pexp l, pexp r])
373+-- _ -> try' (elab' ina (Just fc) (PApp fc (PRef fc pairCon)
374+-- [pimp (sUN "A") Placeholder False,
375+-- pimp (sUN "B") Placeholder False,
376+-- pexp l, pexp r]))
377+-- (elab' ina (Just fc) (PApp fc (PRef fc upairCon)
378+-- [pimp (sUN "A") Placeholder False,
379+-- pimp (sUN "B") Placeholder False,
380+-- pexp l, pexp r]))
381+-- True
382+
362383 elab' ina _ (PDPair fc p l@(PRef _ n) t r)
363384 = case t of
364385 Placeholder ->
@@ -399,6 +420,7 @@ elab ist info emode opts fn tm
399420 where -- if none work, take the error from the first
400421 trySeq (x : xs) = let e1 = elab' ina fc x in
401422 try' e1 (trySeq' e1 xs) True
423+ trySeq [] = fail "Nothing to try in sequence"
402424 trySeq' deferr [] = proofFail deferr
403425 trySeq' deferr (x : xs)
404426 = try' (do elab' ina fc x
@@ -411,7 +433,7 @@ elab ist info emode opts fn tm
411433 | pattern && not reflection && not (e_qq ec) && not (e_intype ec)
412434 && isTConName n (tt_ctxt ist)
413435 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
414− | pattern && not reflection && e_nomatching ec
436+ | pattern && not reflection && not (e_qq ec) && e_nomatching ec
415437 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
416438 | (pattern || (bindfree && bindable n)) && not (inparamBlock n) && not (e_qq ec)
417439 = do let ina = e_inarg ec
@@ -439,7 +461,7 @@ elab ist info emode opts fn tm
439461 | pattern && not reflection && not (e_qq ina) && not (e_intype ina)
440462 && isTConName n (tt_ctxt ist)
441463 = lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
442− | pattern && not reflection && e_nomatching ina
464+ | pattern && not reflection && not (e_qq ina) && e_nomatching ina
443465 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
444466 | otherwise =
445467 do fty <- get_type (Var n) -- check for implicits
@@ -525,7 +547,8 @@ elab ist info emode opts fn tm
525547 -- HACK: If the name leaks into its type, it may leak out of
526548 -- scope outside, so substitute in the outer scope.
527549 expandLet n (case lookup n env of
528− Just (Let t v) -> v)
550+ Just (Let t v) -> v
551+ other -> error ("Value not a let binding: " ++ show other))
529552 solve
530553 elab' ina _ (PGoal fc r n sc) = do
531554 rty <- goal
@@ -596,17 +619,13 @@ elab ist info emode opts fn tm
596619 _ -> lift $ tfail (NoSuchVariable fn)
597620 ns <- match_apply (Var fn') (map (\x -> (x,0)) imps)
598621 solve
599− -- This isn't a sound way of checking for Typecase - we need a
600− -- better way!
601−-- elab' (_, _, inty, qq) (PApp fc (PRef _ f) args')
602−-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty && not qq
603−-- = lift $ tfail (Msg "Typecase is not allowed")
604622 -- if f is local, just do a simple_app
605− elab' ina _ tm@(PApp fc (PRef _ f) args_in)
606− | pattern && not reflection && e_nomatching ina
623+ -- FIXME: Anyone feel like refactoring this mess? - EB
624+ elab' ina topfc tm@(PApp fc (PRef _ f) args_in)
625+ | pattern && not reflection && not (e_qq ina) && e_nomatching ina
607626 = lift $ tfail $ Msg ("Attempting concrete match on polymorphic argument: " ++ show tm)
608− | otherwise
609− = do env <- get_env
627+ | otherwise = implicitApp $
628+ do env <- get_env
610629 ty <- goal
611630 fty <- get_type (Var f)
612631 ctxt <- get_context
@@ -614,18 +633,18 @@ elab ist info emode opts fn tm
614633 let unmatchableArgs = if pattern
615634 then getUnmatchable (tt_ctxt ist) f
616635 else []
617− -- Dot it if we're in a pattern and it isn't a constructor
618−-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
619−
636+-- trace ("BEFORE " ++ show f ++ ": " ++ show ty) $
620637 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
621638 && isTConName f (tt_ctxt ist)) $
622639 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
623640 if (f `elem` map fst env && length args == 1 && length args_in == 1)
624641 then -- simple app, as below
625− do simple_app False (elabE ina (Just fc) (PRef fc f))
642+ do simple_app False
643+ (elabE (ina { e_isfn = True }) (Just fc) (PRef fc f))
626644 (elabE (ina { e_inarg = True }) (Just fc) (getTm (head args)))
627645 (show tm)
628646 solve
647+ return []
629648 else
630649 do ivs <- get_instances
631650 ps <- get_probs
@@ -656,22 +675,58 @@ elab ist info emode opts fn tm
656675 (zip ns' (unmatchableArgs ++ repeat False))
657676 (f == sUN "Force")
658677 (map (\x -> getTm x) eargs) -- TODO: remove this False arg
659− solve
660− ivs' <- get_instances
661− -- Attempt to resolve any type classes which have 'complete' types,
662− -- i.e. no holes in them
663− when (not pattern || (e_inarg ina && not tcgen &&
664− not (e_guarded ina))) $
665− mapM_ (\n -> do focus n
666− g <- goal
667− env <- get_env
668− hs <- get_holes
669− if all (\n -> not (n `elem` hs)) (freeNames g)
670− then try (resolveTC False 7 g fn ist)
671− (movelast n)
672− else movelast n)
673− (ivs' \\ ivs)
674− where -- normal < alternatives < lambdas < rewrites < tactic < default tactic
678+ imp <- if (e_isfn ina) then
679+ do guess <- get_guess
680+ gty <- get_type (forget guess)
681+ env <- get_env
682+ let ty_n = normalise ctxt env gty
683+ return $ getReqImps ty_n
684+ else return []
685+ -- Now we find out how many implicits we needed at the
686+ -- end of the application by looking at the goal again
687+ -- - Have another go, but this time add the
688+ -- implicits (can't think of a better way than this...)
689+ case imp of
690+ rs@(_:_) | not pattern -> return rs -- quit, try again
691+ _ -> do solve
692+ hs <- get_holes
693+ ivs' <- get_instances
694+ -- Attempt to resolve any type classes which have 'complete' types,
695+ -- i.e. no holes in them
696+ when (not pattern || (e_inarg ina && not tcgen &&
697+ not (e_guarded ina))) $
698+ mapM_ (\n -> do focus n
699+ g <- goal
700+ env <- get_env
701+ hs <- get_holes
702+ if all (\n -> not (n `elem` hs)) (freeNames g)
703+ then try (resolveTC False 7 g fn ist)
704+ (movelast n)
705+ else movelast n)
706+ (ivs' \\ ivs)
707+ return []
708+ where
709+ -- Run the elaborator, which returns how many implicit
710+ -- args were needed, then run it again with those args. We need
711+ -- this because we have to elaborate the whole application to
712+ -- find out whether any computations have caused more implicits
713+ -- to be needed.
714+ implicitApp :: ElabD [ImplicitInfo] -> ElabD ()
715+ implicitApp elab
716+ | pattern = do elab; return ()
717+ | otherwise
718+ = do s <- get
719+ imps <- elab
720+ case imps of
721+ [] -> return ()
722+ es -> do put s
723+ elab' ina topfc (PAppImpl tm es)
724+
725+ getReqImps (Bind x (Pi (Just i) ty _) sc)
726+ = i : getReqImps sc
727+ getReqImps _ = []
728+
729+ -- normal < alternatives < lambdas < rewrites < tactic < default tactic
675730 -- reason for lambdas after alternatives is that having
676731 -- the alternative resolved can help with typechecking the lambda
677732 -- or the rewrite. Rewrites/tactics need as much information
@@ -744,15 +799,24 @@ elab ist info emode opts fn tm
744799 setInjective (PApp _ (PRef _ n) _) = setinj n
745800 setInjective _ = return ()
746801
747− elab' ina _ tm@(PApp fc f [arg])
748− = erun fc $
802+ elab' ina _ tm@(PApp fc f [arg]) =
803+ erun fc $
749804 do simple_app (not $ headRef f)
750− (elabE ina (Just fc) f) (elabE (ina { e_inarg = True }) (Just fc) (getTm arg))
805+ (elabE (ina { e_isfn = True }) (Just fc) f)
806+ (elabE (ina { e_inarg = True }) (Just fc) (getTm arg))
751807 (show tm)
752808 solve
753809 where headRef (PRef _ _) = True
754810 headRef (PApp _ f _) = headRef f
755811 headRef _ = False
812+
813+ elab' ina fc (PAppImpl f es) = do appImpl (reverse es) -- not that we look...
814+ solve
815+ where appImpl [] = elab' (ina { e_isfn = False }) fc f -- e_isfn not set, so no recursive expansion of implicits
816+ appImpl (e : es) = simple_app False
817+ (appImpl es)
818+ (elab' ina fc Placeholder)
819+ (show f)
756820 elab' ina fc Placeholder
757821 = do (h : hs) <- get_holes
758822 movelast h
@@ -826,9 +890,21 @@ elab ist info emode opts fn tm
826890 envU <- mapM (getKind args) args
827891 let namesUsedInRHS = nub $ scvn : concatMap (\(_,rhs) -> allNamesIn rhs) opts
828892
829− -- Drop the unique arguments used in the scrutinee (since it's
830− -- not valid to use them again anyway)
831− let argsDropped = filter (isUnique envU) (nub $ allNamesIn scr)
893+ -- Drop the unique arguments used in the term already
894+ -- and in the scrutinee (since it's
895+ -- not valid to use them again anyway)
896+ --
897+ -- Also drop unique arguments which don't appear explicitly
898+ -- in either case branch so they don't count as used
899+ -- unnecessarily (can only do this for unique things, since we
900+ -- assume they don't appear implicitly in types)
901+ ptm <- get_term
902+ let inOpts = (filter (/= scvn) (map fst args)) \\ (concatMap (\x -> allNamesIn (snd x)) opts)
903+
904+ let argsDropped = filter (isUnique envU)
905+ (nub $ allNamesIn scr ++ inApp ptm ++
906+ inOpts)
907+
832908 let args' = filter (\(n, _) -> n `notElem` argsDropped) args
833909
834910 cname <- unique_hole' True (mkCaseName fn)
@@ -855,6 +931,13 @@ elab ist info emode opts fn tm
855931 Just xs@(_:_) -> sNS n xs
856932 _ -> n
857933
934+ inApp (P _ n _) = [n]
935+ inApp (App f a) = inApp f ++ inApp a
936+ inApp (Bind n (Let _ v) sc) = inApp v ++ inApp sc
937+ inApp (Bind n (Guess _ v) sc) = inApp v ++ inApp sc
938+ inApp (Bind n b sc) = inApp sc
939+ inApp _ = []
940+
858941 isUnique envk n = case lookup n envk of
859942 Just u -> u
860943 _ -> False
@@ -882,13 +965,16 @@ elab ist info emode opts fn tm
882965 elab' ina fc (PUnifyLog t) = do unifyLog True
883966 elab' ina fc t
884967 unifyLog False
885− elab' ina fc (PQuasiquote t goal) -- TODO: goal type
968+ elab' ina fc (PQuasiquote t goal)
886969 = do -- First extract the unquoted subterms, replacing them with fresh
887970 -- names in the quasiquoted term. Claim their reflections to be
888− -- of type TT.
971+ -- an inferred type (to support polytypic quasiquotes).
889972 (t, unq) <- extractUnquotes 0 t
890973 let unquoteNames = map fst unq
891− mapM_ (flip claim (Var tt)) unquoteNames
974+ mapM_ (\uqn -> do uqh <- getNameFrom (sMN 0 "uqh")
975+ claim uqh RType
976+ movelast uqh
977+ claim uqn (Var uqh)) unquoteNames
892978
893979
894980 -- Save the old state - we need a fresh proof state to avoid
@@ -897,7 +983,7 @@ elab ist info emode opts fn tm
897983 saveState
898984 updatePS (const .
899985 newProof (sMN 0 "q") ctxt $
900− P Ref tt Erased)
986+ P Ref (reflm "TT") Erased)
901987
902988 -- Re-add the unquotes, letting Idris infer the (fictional)
903989 -- types. Here, they represent the real type rather than the type
@@ -944,18 +1030,22 @@ elab ist info emode opts fn tm
9441030 Just q -> do ctxt <- get_context
9451031 (q', _, _) <- lift $ recheck ctxt [(uq, Lam Erased) | uq <- unquoteNames] (forget q) q
9461032 if pattern
947− then reflectQuotePattern unquoteNames q'
948− else do fill $ reflectQuote unquoteNames q'
1033+ then do try' (reflectTTQuotePattern unquoteNames q')
1034+ (reflectRawQuotePattern unquoteNames (forget q'))
1035+ True
1036+ else do try' (fill $ reflectTTQuote unquoteNames q')
1037+ -- we forget q' instead of using q to ensure rechecking
1038+ (fill $ reflectRawQuote unquoteNames (forget q'))
1039+ True -- ignore errors like proof search does
9491040 solve
1041+
9501042 Nothing -> lift . tfail . Msg $ "Broken elaboration of quasiquote"
9511043
9521044 -- Finally fill in the terms or patterns from the unquotes. This
9531045 -- happens last so that their holes still exist while elaborating
9541046 -- the main quotation.
9551047 mapM_ elabUnquote unq
956− where tt = sNS (sUN "TT") ["Reflection", "Language"]
957−
958− elabUnquote (n, tm)
1048+ where elabUnquote (n, tm)
9591049 = do focus n
9601050 elabE (ina { e_qq = False }) fc tm
9611051
@@ -976,6 +1066,20 @@ elab ist info emode opts fn tm
9761066 delayElab $ do focus h
9771067 dotterm
9781068 elab' ina fc t
1069+ elab' ina _ (PRunTactics fc tm) =
1070+ do attack
1071+ n <- getNameFrom (sMN 0 "tacticScript")
1072+ n' <- getNameFrom (sMN 0 "tacticExpr")
1073+ let scriptTy = RApp (Var (sNS (sUN "Tactical") ["Tactical", "Reflection", "Language"])) (Var unitTy)
1074+ claim n scriptTy
1075+ movelast n
1076+ letbind n' scriptTy (Var n)
1077+ focus n
1078+ elab' ina (Just fc) tm
1079+ env <- get_env
1080+ ctxt <- get_context
1081+ runTactical fc ctxt env (P Bound n' Erased)
1082+ solve
9791083 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
9801084
9811085 delayElab t = updateAux (\e -> e { delayed_elab = delayed_elab e ++ [t] })
@@ -999,6 +1103,7 @@ elab ist info emode opts fn tm
9991103 findScr [(n, (_, t))] = [(n, (True, t))]
10001104 findScr (x : xs) = x : findScr xs
10011105 -- [] can't happen since scrutinee is in the environment!
1106+ findScr [] = error "The impossible happened - the scrutinee was not in the environment"
10021107
10031108 -- To make sure top level pattern name remains in scope, put
10041109 -- it at the end of the environment
@@ -1072,16 +1177,20 @@ elab ist info emode opts fn tm
10721177 = x : insertScopedImps fc sc xs
10731178 insertScopedImps _ _ xs = xs
10741179
1075− insertImpLam t =
1180+ insertImpLam ina t =
10761181 do ty <- goal
10771182 env <- get_env
10781183 let ty' = normalise (tt_ctxt ist) env ty
10791184 addLam ty' t
10801185 where
10811186 -- just one level at a time
1082− addLam (Bind n (Pi (Just _) _ _) sc) t
1083− = do impn <- unique_hole (sMN 0 "imp")
1084− return (PLam emptyFC impn Placeholder t)
1187+ addLam (Bind n (Pi (Just _) _ _) sc) t =
1188+ do impn <- unique_hole (sMN 0 "imp")
1189+ if e_isfn ina -- apply to an implicit immediately
1190+ then return (PApp emptyFC
1191+ (PLam emptyFC impn Placeholder t)
1192+ [pexp Placeholder])
1193+ else return (PLam emptyFC impn Placeholder t)
10851194 addLam _ t = return t
10861195
10871196 insertCoerce ina t@(PCase _ _ _) = return t
@@ -1156,7 +1265,8 @@ elab ist info emode opts fn tm
11561265 lift (tfail (elaboratingArgErr while' e))
11571266 put newState
11581267 return result
1159−
1268+ elabArgs _ _ _ _ _ _ (((arg, hole), _) : _) _ [] =
1269+ fail $ "Can't elaborate these args: " ++ show arg ++ " " ++ show hole
11601270
11611271-- For every alternative, look at the function at the head. Automatically resolve
11621272-- any nested alternatives where that function is also at the head
@@ -1334,6 +1444,7 @@ resTC' tcs defaultOn depth topg fn ist
13341444 let imps = case lookupCtxtName n (idris_implicits ist) of
13351445 [] -> []
13361446 [args] -> map isImp (snd args) -- won't be overloaded!
1447+ xs -> error "The impossible happened - overloading is not expected here!"
13371448 ps <- get_probs
13381449 tm <- get_term
13391450 args <- map snd <$> try' (apply (Var n) imps)
@@ -1394,6 +1505,86 @@ case_ ind autoSolve ist fn tm = do
13941505 else casetac (forget val)
13951506 when autoSolve solveAll
13961507
1508+runTactical :: FC -> Context -> Env -> Term -> ElabD ()
1509+runTactical fc ctxt env tm = runTacTm (eval tm) >> return ()
1510+ where
1511+ eval = normaliseAll ctxt env
1512+ tacN str = sNS (sUN str) ["Tactical", "Reflection", "Language"]
1513+ returnUnit = fmap fst $ get_type_val (Var unitCon)
1514+
1515+ -- | Do a step in the reflected elaborator monad. The input is the
1516+ -- step, the output is the (reflected) term returned.
1517+ runTacTm :: Term -> ElabD Term
1518+ runTacTm (unApply -> tac@(P _ n _, args))
1519+ | n == tacN "prim__Solve", [] <- args
1520+ = do solve
1521+ returnUnit
1522+ | n == tacN "prim__Goal", [] <- args
1523+ = do (h:_) <- get_holes
1524+ t <- goal
1525+ fmap fst . get_type_val $
1526+ rawPair (Var (reflm "TTName"), Var (reflm "TT"))
1527+ (reflectName h, reflect t)
1528+ | n == tacN "prim__Holes", [] <- args
1529+ = do hs <- get_holes
1530+ fmap fst . get_type_val $
1531+ mkList (Var $ reflm "TTName") (map reflectName hs)
1532+ | n == tacN "prim__Guess", [] <- args
1533+ = do ok <- is_guess
1534+ if ok
1535+ then do guess <- fmap forget get_guess
1536+ fmap fst . get_type_val $
1537+ RApp (RApp (Var (sNS (sUN "Just") ["Maybe", "Prelude"]))
1538+ (Var (reflm "TT")))
1539+ guess
1540+ else fmap fst . get_type_val $
1541+ RApp (Var (sNS (sUN "Nothing") ["Maybe", "Prelude"]))
1542+ (Var (reflm "TT"))
1543+ | n == tacN "prim__Env", [] <- args
1544+ = do env <- get_env
1545+ fmap fst . get_type_val $ reflectEnv env
1546+ | n == tacN "prim__Fail", [_a, errs] <- args
1547+ = do parts <- reifyReportParts (eval errs)
1548+ lift . tfail $ ReflectionError [parts] (Msg "")
1549+ | n == tacN "prim__PureTactical", [_a, tm] <- args
1550+ = return tm
1551+ | n == tacN "prim__BindTactical", [_a, _b, first, andThen] <- args
1552+ = do let first' = eval first
1553+ res <- runTacTm first'
1554+ let next = eval (App andThen res)
1555+ runTacTm next
1556+ | n == tacN "prim__Try", [_a, first, alt] <- args
1557+ = do let first' = eval first
1558+ let alt' = eval alt
1559+ try' (runTacTm first') (runTacTm alt') True
1560+ | n == tacN "prim__Fill", [raw] <- args
1561+ = do raw' <- reifyRaw raw
1562+ apply raw' []
1563+ returnUnit
1564+ | n == tacN "prim__Gensym", [eval -> Constant (Str hint)] <- args
1565+ = do n <- getNameFrom (sMN 0 hint)
1566+ fmap fst $ get_type_val (reflectName n)
1567+ | n == tacN "prim__Claim", [n, ty] <- args
1568+ = do n' <- reifyTTName n
1569+ ty' <- reifyRaw ty
1570+ claim n' ty'
1571+ returnUnit
1572+ | n == tacN "prim__Forget", [tt] <- args
1573+ = do tt' <- reifyTT tt
1574+ fmap fst . get_type_val $ reflect tt'
1575+ | n == tacN "prim__Attack", [] <- args
1576+ = do attack
1577+ returnUnit
1578+ | n == tacN "prim__Focus", [what] <- args
1579+ = do n' <- reifyTTName what
1580+ focus n'
1581+ returnUnit
1582+ | n == tacN "prim__Unfocus", [what] <- args
1583+ = do n' <- reifyTTName what
1584+ movelast n'
1585+ returnUnit
1586+ runTacTm x = lift . tfail . InternalMsg $ "tactical is not implemented for " ++ show x
1587+
13971588-- Running tactics directly
13981589-- if a tactic adds unification problems, return an error
13991590
@@ -1460,6 +1651,12 @@ runTac autoSolve ist perhapsFC fn tac
14601651 when autoSolve solveAll
14611652 runT DoUnify = do unify_all
14621653 when autoSolve solveAll
1654+ runT (Claim n tm) = do tmHole <- getNameFrom (sMN 0 "newGoal")
1655+ claim tmHole RType
1656+ claim n (Var tmHole)
1657+ focus tmHole
1658+ elab ist toplevel ERHS [] (sMN 0 "tac") tm
1659+ focus n
14631660 runT (Equiv tm) -- let bind tm, then
14641661 = do attack
14651662 tyn <- getNameFrom (sMN 0 "ety")
@@ -1520,6 +1717,10 @@ runTac autoSolve ist perhapsFC fn tac
15201717 = do proofSearch' ist rec False depth prover top fn hints
15211718 when autoSolve solveAll
15221719 runT (Focus n) = focus n
1720+ runT Unfocus = do hs <- get_holes
1721+ case hs of
1722+ [] -> return ()
1723+ (h : _) -> movelast h
15231724 runT Solve = solve
15241725 runT (Try l r) = do try' (runT l) (runT r) True
15251726 runT (TSeq l r) = do runT l; runT r
@@ -1664,6 +1865,7 @@ reify _ (P _ n _) | n == reflm "Solve" = return Solve
16641865reify _ (P _ n _) | n == reflm "Compute" = return Compute
16651866reify _ (P _ n _) | n == reflm "Skip" = return Skip
16661867reify _ (P _ n _) | n == reflm "SourceFC" = return SourceFC
1868+reify _ (P _ n _) | n == reflm "Unfocus" = return Unfocus
16671869reify ist t@(App _ _)
16681870 | (P _ f _, args) <- unApply t = reifyApp ist f args
16691871reify _ t = fail ("Unknown tactic " ++ show t)
@@ -1675,6 +1877,9 @@ reifyApp _ t [Constant (I i)]
16751877reifyApp _ t [x]
16761878 | t == reflm "Refine" = do n <- reifyTTName x
16771879 return $ Refine n []
1880+reifyApp ist t [n, ty] | t == reflm "Claim" = do n' <- reifyTTName n
1881+ goal <- reifyTT ty
1882+ return $ Claim n' (delab ist goal)
16781883reifyApp ist t [l, r] | t == reflm "Seq" = liftM2 TSeq (reify ist l) (reify ist r)
16791884reifyApp ist t [Constant (Str n), x]
16801885 | t == reflm "GoalType" = liftM (GoalType n) (reify ist x)
@@ -1705,16 +1910,20 @@ reifyApp ist t [n, tt', t']
17051910 t'' <- reifyTT t'
17061911 return $ LetTacTy n' (delab ist tt'') (delab ist t'')
17071912reifyApp ist t [errs]
1708− | t == reflm "Fail" = case unList errs of
1709− Nothing -> fail "Failed to reify errors"
1710− Just errs' ->
1711− let parts = mapM reifyReportPart errs' in
1712− case parts of
1713− Left err -> fail $ "Couldn't reify \"Fail\" tactic - " ++ show err
1714− Right errs'' ->
1715− return $ TFail errs''
1913+ | t == reflm "Fail" = fmap TFail (reifyReportParts errs)
17161914reifyApp _ f args = fail ("Unknown tactic " ++ show (f, args)) -- shouldn't happen
17171915
1916+reifyReportParts :: Term -> ElabD [ErrorReportPart]
1917+reifyReportParts errs =
1918+ case unList errs of
1919+ Nothing -> fail "Failed to reify errors"
1920+ Just errs' ->
1921+ let parts = mapM reifyReportPart errs' in
1922+ case parts of
1923+ Left err -> fail $ "Couldn't reify \"Fail\" tactic - " ++ show err
1924+ Right errs'' ->
1925+ return errs''
1926+
17181927-- | Reify terms from their reflected representation
17191928reifyTT :: Term -> ElabD Term
17201929reifyTT t@(App _ _)
@@ -1894,6 +2103,7 @@ reifyIntTy (P _ n _) | n == reflm "ITBig" = return ITBig
18942103reifyIntTy (P _ n _) | n == reflm "ITChar" = return ITChar
18952104reifyIntTy (App (App (P _ n _) nt) (Constant (I i))) | n == reflm "ITVec" = fmap (flip ITVec i)
18962105 (reifyNativeTy nt)
2106+reifyIntTy tm = fail $ "The term " ++ show tm ++ " is not a reflected IntTy"
18972107
18982108reifyTTUExp :: Term -> ElabD UExp
18992109reifyTTUExp t@(App _ _)
@@ -1910,7 +2120,11 @@ reflCall funName args
19102120
19112121-- | Lift a term into its Language.Reflection.TT representation
19122122reflect :: Term -> Raw
1913−reflect = reflectQuote []
2123+reflect = reflectTTQuote []
2124+
2125+-- | Lift a term into its Language.Reflection.Raw representation
2126+reflectRaw :: Raw -> Raw
2127+reflectRaw = reflectRawQuote []
19142128
19152129claimTT :: Name -> ElabD Name
19162130claimTT n = do n' <- getNameFrom n
@@ -1921,8 +2135,8 @@ claimTT n = do n' <- getNameFrom n
19212135-- In particular, the less-interesting bits are elaborated to _ patterns. This
19222136-- happens to NameTypes, universe levels, names that are bound but not used,
19232137-- and the type annotation field of the P constructor.
1924−reflectQuotePattern :: [Name] -> Term -> ElabD ()
1925−reflectQuotePattern unq (P _ n _)
2138+reflectTTQuotePattern :: [Name] -> Term -> ElabD ()
2139+reflectTTQuotePattern unq (P _ n _)
19262140 | n `elem` unq = -- the unquoted names have been claimed as TT already - just use them
19272141 do fill (Var n) ; solve
19282142 | otherwise =
@@ -1936,10 +2150,10 @@ reflectQuotePattern unq (P _ n _)
19362150 fill $ reflCall "P" [Var nt, Var n', Var tyannot]
19372151 solve
19382152 focus n'; reflectNameQuotePattern n
1939−reflectQuotePattern unq (V n)
2153+reflectTTQuotePattern unq (V n)
19402154 = do fill $ reflCall "V" [RConstant (I n)]
19412155 solve
1942−reflectQuotePattern unq (Bind n b x)
2156+reflectTTQuotePattern unq (Bind n b x)
19432157 = do x' <- claimTT (sMN 0 "sc")
19442158 movelast x'
19452159 b' <- getNameFrom (sMN 0 "binder")
@@ -1959,111 +2173,215 @@ reflectQuotePattern unq (Bind n b x)
19592173 Var b',
19602174 Var x']
19612175 solve
1962− focus x'; reflectQuotePattern unq x
1963− focus b'; reflectBinderQuotePattern unq b
1964−
1965− where
1966− reflectBinderQuotePattern :: [Name] -> Binder Term -> ElabD ()
1967− reflectBinderQuotePattern unq (Lam t)
1968− = do t' <- claimTT (sMN 0 "ty"); movelast t'
1969− fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
1970− solve
1971− focus t'; reflectQuotePattern unq t
1972− reflectBinderQuotePattern unq (Pi _ t k)
1973− = do t' <- claimTT (sMN 0 "ty") ; movelast t'
1974− k' <- claimTT (sMN 0 "k"); movelast k';
1975− fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
1976− solve
1977− focus t'; reflectQuotePattern unq t
1978− reflectBinderQuotePattern unq (Let x y)
1979− = do x' <- claimTT (sMN 0 "ty"); movelast x';
1980− y' <- claimTT (sMN 0 "v"); movelast y';
1981− fill $ reflCall "Let" [Var (reflm "TT"), Var x', Var y']
1982− solve
1983− focus x'; reflectQuotePattern unq x
1984− focus y'; reflectQuotePattern unq y
1985− reflectBinderQuotePattern unq (NLet x y)
1986− = do x' <- claimTT (sMN 0 "ty"); movelast x'
1987− y' <- claimTT (sMN 0 "v"); movelast y'
1988− fill $ reflCall "NLet" [Var (reflm "TT"), Var x', Var y']
1989− solve
1990− focus x'; reflectQuotePattern unq x
1991− focus y'; reflectQuotePattern unq y
1992− reflectBinderQuotePattern unq (Hole t)
1993− = do t' <- claimTT (sMN 0 "ty"); movelast t'
1994− fill $ reflCall "Hole" [Var (reflm "TT"), Var t']
1995− solve
1996− focus t'; reflectQuotePattern unq t
1997− reflectBinderQuotePattern unq (GHole _ t)
1998− = do t' <- claimTT (sMN 0 "ty"); movelast t'
1999− fill $ reflCall "GHole" [Var (reflm "TT"), Var t']
2000− solve
2001− focus t'; reflectQuotePattern unq t
2002− reflectBinderQuotePattern unq (Guess x y)
2003− = do x' <- claimTT (sMN 0 "ty"); movelast x'
2004− y' <- claimTT (sMN 0 "v"); movelast y'
2005− fill $ reflCall "Guess" [Var (reflm "TT"), Var x', Var y']
2006− solve
2007− focus x'; reflectQuotePattern unq x
2008− focus y'; reflectQuotePattern unq y
2009− reflectBinderQuotePattern unq (PVar t)
2010− = do t' <- claimTT (sMN 0 "ty"); movelast t'
2011− fill $ reflCall "PVar" [Var (reflm "TT"), Var t']
2012− solve
2013− focus t'; reflectQuotePattern unq t
2014− reflectBinderQuotePattern unq (PVTy t)
2015− = do t' <- claimTT (sMN 0 "ty"); movelast t'
2016− fill $ reflCall "PVTy" [Var (reflm "TT"), Var t']
2017− solve
2018− focus t'; reflectQuotePattern unq t
2019−reflectQuotePattern unq (App f x)
2176+ focus x'; reflectTTQuotePattern unq x
2177+ focus b'; reflectBinderQuotePattern reflectTTQuotePattern unq b
2178+reflectTTQuotePattern unq (App f x)
20202179 = do f' <- claimTT (sMN 0 "f"); movelast f'
20212180 x' <- claimTT (sMN 0 "x"); movelast x'
20222181 fill $ reflCall "App" [Var f', Var x']
20232182 solve
2024− focus f'; reflectQuotePattern unq f
2025− focus x'; reflectQuotePattern unq x
2026−reflectQuotePattern unq (Constant c)
2183+ focus f'; reflectTTQuotePattern unq f
2184+ focus x'; reflectTTQuotePattern unq x
2185+reflectTTQuotePattern unq (Constant c)
20272186 = do fill $ reflCall "TConst" [reflectConstant c]
20282187 solve
2029−reflectQuotePattern unq (Proj t i)
2188+reflectTTQuotePattern unq (Proj t i)
20302189 = do t' <- claimTT (sMN 0 "t"); movelast t'
20312190 fill $ reflCall "Proj" [Var t', RConstant (I i)]
20322191 solve
2033− focus t'; reflectQuotePattern unq t
2034−reflectQuotePattern unq (Erased)
2192+ focus t'; reflectTTQuotePattern unq t
2193+reflectTTQuotePattern unq (Erased)
20352194 = do erased <- claimTT (sMN 0 "erased")
20362195 movelast erased
20372196 fill $ (Var erased)
20382197 solve
2039−reflectQuotePattern unq (Impossible)
2198+reflectTTQuotePattern unq (Impossible)
20402199 = do fill $ Var (reflm "Impossible")
20412200 solve
2042−reflectQuotePattern unq (TType exp)
2201+reflectTTQuotePattern unq (TType exp)
20432202 = do ue <- getNameFrom (sMN 0 "uexp")
20442203 claim ue (Var (sNS (sUN "TTUExp") ["Reflection", "Language"]))
20452204 movelast ue
20462205 fill $ reflCall "TType" [Var ue]
20472206 solve
2207+reflectTTQuotePattern unq (UType u)
2208+ = do uH <- getNameFrom (sMN 0 "someUniv")
2209+ claim uH (Var (reflm "Universe"))
2210+ movelast uH
2211+ fill $ reflCall "UType" [Var uH]
2212+ solve
2213+ focus uH
2214+ fill (Var (reflm (case u of
2215+ NullType -> "NullType"
2216+ UniqueType -> "UniqueType"
2217+ AllTypes -> "AllTypes")))
2218+ solve
20482219
2049−-- | Create a reflected term, but leave refs to the provided name intact
2050−reflectQuote :: [Name] -> Term -> Raw
2051−reflectQuote unq (P nt n t)
2220+reflectRawQuotePattern :: [Name] -> Raw -> ElabD ()
2221+reflectRawQuotePattern unq (Var n)
2222+ -- the unquoted names already have types, just use them
2223+ | n `elem` unq = do fill (Var n); solve
2224+ | otherwise = do fill (reflCall "Var" [reflectName n]); solve
2225+reflectRawQuotePattern unq (RBind n b sc) =
2226+ do scH <- getNameFrom (sMN 0 "sc")
2227+ claim scH (Var (reflm "Raw"))
2228+ movelast scH
2229+ bH <- getNameFrom (sMN 0 "binder")
2230+ claim bH (RApp (Var (reflm "Binder"))
2231+ (Var (reflm "Raw")))
2232+ if n `elem` freeNamesR sc
2233+ then do fill $ reflCall "RBind" [reflectName n,
2234+ Var bH,
2235+ Var scH]
2236+ solve
2237+ else do any <- getNameFrom (sMN 0 "anyName")
2238+ claim any (Var (reflm "TTName"))
2239+ movelast any
2240+ fill $ reflCall "RBind" [Var any, Var bH, Var scH]
2241+ solve
2242+ focus scH; reflectRawQuotePattern unq sc
2243+ focus bH; reflectBinderQuotePattern reflectRawQuotePattern unq b
2244+ where freeNamesR (Var n) = [n]
2245+ freeNamesR (RBind n (Let t v) body) = concat [freeNamesR v,
2246+ freeNamesR body \\ [n],
2247+ freeNamesR t]
2248+ freeNamesR (RBind n b body) = freeNamesR (binderTy b) ++
2249+ (freeNamesR body \\ [n])
2250+ freeNamesR (RApp f x) = freeNamesR f ++ freeNamesR x
2251+ freeNamesR RType = []
2252+ freeNamesR (RUType _) = []
2253+ freeNamesR (RForce r) = freeNamesR r
2254+ freeNamesR (RConstant _) = []
2255+reflectRawQuotePattern unq (RApp f x) =
2256+ do fH <- getNameFrom (sMN 0 "f")
2257+ claim fH (Var (reflm "Raw"))
2258+ movelast fH
2259+ xH <- getNameFrom (sMN 0 "x")
2260+ claim xH (Var (reflm "Raw"))
2261+ movelast xH
2262+ fill $ reflCall "RApp" [Var fH, Var xH]
2263+ solve
2264+ focus fH; reflectRawQuotePattern unq f
2265+ focus xH; reflectRawQuotePattern unq x
2266+reflectRawQuotePattern unq RType =
2267+ do fill (Var (reflm "RType"))
2268+ solve
2269+reflectRawQuotePattern unq (RUType univ) =
2270+ do uH <- getNameFrom (sMN 0 "universe")
2271+ claim uH (Var (reflm "Universe"))
2272+ movelast uH
2273+ fill $ reflCall "RUType" [Var uH]
2274+ solve
2275+ focus uH; fill (reflectUniverse univ); solve
2276+reflectRawQuotePattern unq (RForce r) =
2277+ do rH <- getNameFrom (sMN 0 "raw")
2278+ claim rH (Var (reflm "Raw"))
2279+ movelast rH
2280+ fill $ reflCall "RForce" [Var rH]
2281+ solve
2282+ focus rH; reflectRawQuotePattern unq r
2283+reflectRawQuotePattern unq (RConstant c) =
2284+ do cH <- getNameFrom (sMN 0 "const")
2285+ claim cH (Var (reflm "Constant"))
2286+ movelast cH
2287+ fill (reflCall "RConstant" [Var cH]); solve
2288+ focus cH
2289+ fill (reflectConstant c); solve
2290+
2291+reflectBinderQuotePattern :: ([Name] -> a -> ElabD ()) -> [Name] -> Binder a -> ElabD ()
2292+reflectBinderQuotePattern q unq (Lam t)
2293+ = do t' <- claimTT (sMN 0 "ty"); movelast t'
2294+ fill $ reflCall "Lam" [Var (reflm "TT"), Var t']
2295+ solve
2296+ focus t'; q unq t
2297+reflectBinderQuotePattern q unq (Pi _ t k)
2298+ = do t' <- claimTT (sMN 0 "ty") ; movelast t'
2299+ k' <- claimTT (sMN 0 "k"); movelast k';
2300+ fill $ reflCall "Pi" [Var (reflm "TT"), Var t', Var k']
2301+ solve
2302+ focus t'; q unq t
2303+reflectBinderQuotePattern q unq (Let x y)
2304+ = do x' <- claimTT (sMN 0 "ty"); movelast x';
2305+ y' <- claimTT (sMN 0 "v"); movelast y';
2306+ fill $ reflCall "Let" [Var (reflm "TT"), Var x', Var y']
2307+ solve
2308+ focus x'; q unq x
2309+ focus y'; q unq y
2310+reflectBinderQuotePattern q unq (NLet x y)
2311+ = do x' <- claimTT (sMN 0 "ty"); movelast x'
2312+ y' <- claimTT (sMN 0 "v"); movelast y'
2313+ fill $ reflCall "NLet" [Var (reflm "TT"), Var x', Var y']
2314+ solve
2315+ focus x'; q unq x
2316+ focus y'; q unq y
2317+reflectBinderQuotePattern q unq (Hole t)
2318+ = do t' <- claimTT (sMN 0 "ty"); movelast t'
2319+ fill $ reflCall "Hole" [Var (reflm "TT"), Var t']
2320+ solve
2321+ focus t'; q unq t
2322+reflectBinderQuotePattern q unq (GHole _ t)
2323+ = do t' <- claimTT (sMN 0 "ty"); movelast t'
2324+ fill $ reflCall "GHole" [Var (reflm "TT"), Var t']
2325+ solve
2326+ focus t'; q unq t
2327+reflectBinderQuotePattern q unq (Guess x y)
2328+ = do x' <- claimTT (sMN 0 "ty"); movelast x'
2329+ y' <- claimTT (sMN 0 "v"); movelast y'
2330+ fill $ reflCall "Guess" [Var (reflm "TT"), Var x', Var y']
2331+ solve
2332+ focus x'; q unq x
2333+ focus y'; q unq y
2334+reflectBinderQuotePattern q unq (PVar t)
2335+ = do t' <- claimTT (sMN 0 "ty"); movelast t'
2336+ fill $ reflCall "PVar" [Var (reflm "TT"), Var t']
2337+ solve
2338+ focus t'; q unq t
2339+reflectBinderQuotePattern q unq (PVTy t)
2340+ = do t' <- claimTT (sMN 0 "ty"); movelast t'
2341+ fill $ reflCall "PVTy" [Var (reflm "TT"), Var t']
2342+ solve
2343+ focus t'; q unq t
2344+
2345+reflectUniverse :: Universe -> Raw
2346+reflectUniverse u =
2347+ (Var (reflm (case u of
2348+ NullType -> "NullType"
2349+ UniqueType -> "UniqueType"
2350+ AllTypes -> "AllTypes")))
2351+
2352+-- | Create a reflected TT term, but leave refs to the provided name intact
2353+reflectTTQuote :: [Name] -> Term -> Raw
2354+reflectTTQuote unq (P nt n t)
20522355 | n `elem` unq = Var n
2053− | otherwise = reflCall "P" [reflectNameType nt, reflectName n, reflectQuote unq t]
2054−reflectQuote unq (V n)
2356+ | otherwise = reflCall "P" [reflectNameType nt, reflectName n, reflectTTQuote unq t]
2357+reflectTTQuote unq (V n)
20552358 = reflCall "V" [RConstant (I n)]
2056−reflectQuote unq (Bind n b x)
2057− = reflCall "Bind" [reflectName n, reflectBinderQuote unq b, reflectQuote unq x]
2058−reflectQuote unq (App f x)
2059− = reflCall "App" [reflectQuote unq f, reflectQuote unq x]
2060−reflectQuote unq (Constant c)
2359+reflectTTQuote unq (Bind n b x)
2360+ = reflCall "Bind" [reflectName n, reflectBinderQuote reflectTTQuote unq b, reflectTTQuote unq x]
2361+reflectTTQuote unq (App f x)
2362+ = reflCall "App" [reflectTTQuote unq f, reflectTTQuote unq x]
2363+reflectTTQuote unq (Constant c)
20612364 = reflCall "TConst" [reflectConstant c]
2062−reflectQuote unq (Proj t i)
2063− = reflCall "Proj" [reflectQuote unq t, RConstant (I i)]
2064−reflectQuote unq (Erased) = Var (reflm "Erased")
2065−reflectQuote unq (Impossible) = Var (reflm "Impossible")
2066−reflectQuote unq (TType exp) = reflCall "TType" [reflectUExp exp]
2365+reflectTTQuote unq (Proj t i)
2366+ = reflCall "Proj" [reflectTTQuote unq t, RConstant (I i)]
2367+reflectTTQuote unq (Erased) = Var (reflm "Erased")
2368+reflectTTQuote unq (Impossible) = Var (reflm "Impossible")
2369+reflectTTQuote unq (TType exp) = reflCall "TType" [reflectUExp exp]
2370+reflectTTQuote unq (UType u) = reflCall "UType" [reflectUniverse u]
2371+
2372+reflectRawQuote :: [Name] -> Raw -> Raw
2373+reflectRawQuote unq (Var n)
2374+ | n `elem` unq = Var n
2375+ | otherwise = reflCall "Var" [reflectName n]
2376+reflectRawQuote unq (RBind n b r) =
2377+ reflCall "RBind" [reflectName n, reflectBinderQuote reflectRawQuote unq b, reflectRawQuote unq r]
2378+reflectRawQuote unq (RApp f x) =
2379+ reflCall "RApp" [reflectRawQuote unq f, reflectRawQuote unq x]
2380+reflectRawQuote unq RType = Var (reflm "RType")
2381+reflectRawQuote unq (RUType u) =
2382+ reflCall "RUType" [reflectUniverse u]
2383+reflectRawQuote unq (RForce r) = reflCall "RForce" [reflectRawQuote unq r]
2384+reflectRawQuote unq (RConstant cst) = reflCall "RConstant" [reflectConstant cst]
20672385
20682386reflectNameType :: NameType -> Raw
20692387reflectNameType (Bound) = Var (reflm "Bound")
@@ -2114,27 +2432,27 @@ reflectNameQuotePattern _ -- for all other names, match any
21142432 solve
21152433
21162434reflectBinder :: Binder Term -> Raw
2117−reflectBinder = reflectBinderQuote []
2118−
2119−reflectBinderQuote :: [Name] -> Binder Term -> Raw
2120−reflectBinderQuote unq (Lam t)
2121− = reflCall "Lam" [Var (reflm "TT"), reflectQuote unq t]
2122−reflectBinderQuote unq (Pi _ t k)
2123− = reflCall "Pi" [Var (reflm "TT"), reflectQuote unq t, reflectQuote unq k]
2124−reflectBinderQuote unq (Let x y)
2125− = reflCall "Let" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2126−reflectBinderQuote unq (NLet x y)
2127− = reflCall "NLet" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2128−reflectBinderQuote unq (Hole t)
2129− = reflCall "Hole" [Var (reflm "TT"), reflectQuote unq t]
2130−reflectBinderQuote unq (GHole _ t)
2131− = reflCall "GHole" [Var (reflm "TT"), reflectQuote unq t]
2132−reflectBinderQuote unq (Guess x y)
2133− = reflCall "Guess" [Var (reflm "TT"), reflectQuote unq x, reflectQuote unq y]
2134−reflectBinderQuote unq (PVar t)
2135− = reflCall "PVar" [Var (reflm "TT"), reflectQuote unq t]
2136−reflectBinderQuote unq (PVTy t)
2137− = reflCall "PVTy" [Var (reflm "TT"), reflectQuote unq t]
2435+reflectBinder = reflectBinderQuote reflectTTQuote []
2436+
2437+reflectBinderQuote :: ([Name] -> a -> Raw) -> [Name] -> Binder a -> Raw
2438+reflectBinderQuote q unq (Lam t)
2439+ = reflCall "Lam" [Var (reflm "TT"), q unq t]
2440+reflectBinderQuote q unq (Pi _ t k)
2441+ = reflCall "Pi" [Var (reflm "TT"), q unq t, q unq k]
2442+reflectBinderQuote q unq (Let x y)
2443+ = reflCall "Let" [Var (reflm "TT"), q unq x, q unq y]
2444+reflectBinderQuote q unq (NLet x y)
2445+ = reflCall "NLet" [Var (reflm "TT"), q unq x, q unq y]
2446+reflectBinderQuote q unq (Hole t)
2447+ = reflCall "Hole" [Var (reflm "TT"), q unq t]
2448+reflectBinderQuote q unq (GHole _ t)
2449+ = reflCall "GHole" [Var (reflm "TT"), q unq t]
2450+reflectBinderQuote q unq (Guess x y)
2451+ = reflCall "Guess" [Var (reflm "TT"), q unq x, q unq y]
2452+reflectBinderQuote q unq (PVar t)
2453+ = reflCall "PVar" [Var (reflm "TT"), q unq t]
2454+reflectBinderQuote q unq (PVTy t)
2455+ = reflCall "PVTy" [Var (reflm "TT"), q unq t]
21382456
21392457mkList :: Raw -> [Raw] -> Raw
21402458mkList ty [] = RApp (Var (sNS (sUN "Nil") ["List", "Prelude"])) ty
@@ -2174,7 +2492,8 @@ reflectConstant ManagedPtrType = Var (reflm "ManagedPtrType")
21742492reflectConstant BufferType = Var (reflm "BufferType")
21752493reflectConstant VoidType = Var (reflm "VoidType")
21762494reflectConstant Forgot = Var (reflm "Forgot")
2177−
2495+reflectConstant WorldType = Var (reflm "WorldType")
2496+reflectConstant TheWorld = Var (reflm "TheWorld")
21782497
21792498reflectUExp :: UExp -> Raw
21802499reflectUExp (UVar i) = reflCall "UVar" [RConstant (I i)]
src/Idris/Erasure.hs+1
@@ -468,6 +468,7 @@ buildDepMap ci used ctx mainName = addPostulates used $
468468 -- the easy cases
469469 getDepsTerm vs bs cd (Constant _) = M.empty
470470 getDepsTerm vs bs cd (TType _) = M.empty
471+ getDepsTerm vs bs cd (UType _) = M.empty
471472 getDepsTerm vs bs cd Erased = M.empty
472473 getDepsTerm vs bs cd Impossible = M.empty
473474
src/Idris/Error.hs+3
@@ -1,4 +1,5 @@
11{-# LANGUAGE DeriveDataTypeable #-}
2+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
23
34module Idris.Error where
45
@@ -146,3 +147,5 @@ warnDisamb ist (PQuasiquote tm goal) = warnDisamb ist tm >>
146147 Foldable.mapM_ (warnDisamb ist) goal
147148warnDisamb ist (PUnquote tm) = warnDisamb ist tm
148149warnDisamb ist (PAs _ _ tm) = warnDisamb ist tm
150+warnDisamb ist (PAppImpl tm _) = warnDisamb ist tm
151+warnDisamb ist (PRunTactics _ tm) = warnDisamb ist tm
src/Idris/IBC.hs+169−15
@@ -1,4 +1,5 @@
11{-# LANGUAGE TypeSynonymInstances #-}
2+{-# OPTIONS_GHC -fwarn-incomplete-patterns #-}
23
34module Idris.IBC where
45
@@ -36,7 +37,7 @@ import Codec.Compression.Zlib (compress)
3637import Util.Zlib (decompressEither)
3738
3839ibcVersion :: Word8
39−ibcVersion = 95
40+ibcVersion = 98
4041
4142data IBCFile = IBCFile { ver :: Word8,
4243 sourcefile :: FilePath,
@@ -610,6 +611,7 @@ instance Binary a => Binary (D.Block a) where
610611 4 -> liftM3 D.CodeBlock get get get
611612 5 -> liftM D.HtmlBlock get
612613 6 -> return D.HRule
614+ _ -> error "Corrupted binary data for Block"
613615
614616instance Binary a => Binary (D.Inline a) where
615617 put (D.Str txt) = do putWord8 0 ; put txt
@@ -636,6 +638,7 @@ instance Binary a => Binary (D.Inline a) where
636638 8 -> liftM3 D.Image get get get
637639 9 -> liftM D.Entity get
638640 10 -> liftM D.RawHtml get
641+ _ -> error "Corrupted binary data for Inline"
639642
640643instance Binary CT.ListType where
641644 put (CT.Bullet c) = putWord8 0 >> put c
@@ -644,6 +647,7 @@ instance Binary CT.ListType where
644647 case i of
645648 0 -> liftM CT.Bullet get
646649 1 -> liftM2 CT.Numbered get get
650+ _ -> error "Corrupted binary data for ListType"
647651
648652instance Binary CT.CodeAttr where
649653 put (CT.CodeAttr a b) = put a >> put b
@@ -656,6 +660,7 @@ instance Binary CT.NumWrapper where
656660 case i of
657661 0 -> return CT.PeriodFollowing
658662 1 -> return CT.ParenFollowing
663+ _ -> error "Corrupted binary data for NumWrapper"
659664
660665----- Generated by 'derive'
661666
@@ -868,6 +873,9 @@ instance Binary PReason where
868873 put x1
869874 NotProductive -> putWord8 5
870875 BelieveMe -> putWord8 6
876+ UseUndef x1 -> do putWord8 7
877+ put x1
878+ ExternalIO -> putWord8 8
871879 get
872880 = do i <- getWord8
873881 case i of
@@ -880,6 +888,9 @@ instance Binary PReason where
880888 return (Mutual x1)
881889 5 -> return NotProductive
882890 6 -> return BelieveMe
891+ 7 -> do x1 <- get
892+ return (UseUndef x1)
893+ 8 -> return ExternalIO
883894 _ -> error "Corrupted binary data for PReason"
884895
885896instance Binary Totality where
@@ -913,6 +924,7 @@ instance Binary MetaInformation where
913924 0 -> return EmptyMI
914925 1 -> do x1 <- get
915926 return (DataMI x1)
927+ _ -> error "Corrupted binary data for MetaInformation"
916928
917929instance Binary IBCFile where
918930 put x@(IBCFile x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 x21 x22 x23 x24 x25 x26 x27 x28 x29 x30 x31 x32 x33 x34 x35 x36 x37 x38 x39 x40 x41 x42)
@@ -1019,6 +1031,7 @@ instance Binary DataOpt where
10191031 1 -> return DefaultEliminator
10201032 2 -> return DataErrRev
10211033 3 -> return DefaultCaseFun
1034+ _ -> error "Corrupted binary data for DataOpt"
10221035
10231036instance Binary FnOpt where
10241037 put x
@@ -1038,6 +1051,8 @@ instance Binary FnOpt where
10381051 CoveringFn -> putWord8 11
10391052 NoImplicit -> putWord8 12
10401053 Constructor -> putWord8 13
1054+ CExport x1 -> do putWord8 14
1055+ put x1
10411056 get
10421057 = do i <- getWord8
10431058 case i of
@@ -1056,6 +1071,8 @@ instance Binary FnOpt where
10561071 11 -> return CoveringFn
10571072 12 -> return NoImplicit
10581073 13 -> return Constructor
1074+ 14 -> do x1 <- get
1075+ return $ CExport x1
10591076 _ -> error "Corrupted binary data for FnOpt"
10601077
10611078instance Binary Fixity where
@@ -1250,6 +1267,20 @@ instance (Binary t) => Binary (PDecl' t) where
12501267 put x4
12511268 put x5
12521269 put x6
1270+ PSyntax x1 x2 -> do putWord8 13
1271+ put x1
1272+ put x2
1273+ PDirective x1 -> error "Cannot serialize PDirective"
1274+ PProvider x1 x2 x3 x4 -> do putWord8 15
1275+ put x1
1276+ put x2
1277+ put x3
1278+ put x4
1279+ PTransform x1 x2 x3 x4 -> do putWord8 16
1280+ put x1
1281+ put x2
1282+ put x3
1283+ put x4
12531284 get
12541285 = do i <- getWord8
12551286 case i of
@@ -1330,8 +1361,37 @@ instance (Binary t) => Binary (PDecl' t) where
13301361 x5 <- get
13311362 x6 <- get
13321363 return (PPostulate x1 x2 x3 x4 x5 x6)
1364+ 13 -> do x1 <- get
1365+ x2 <- get
1366+ return (PSyntax x1 x2)
1367+ 14 -> do error "Cannot deserialize PDirective"
1368+ 15 -> do x1 <- get
1369+ x2 <- get
1370+ x3 <- get
1371+ x4 <- get
1372+ return (PProvider x1 x2 x3 x4)
1373+ 16 -> do x1 <- get
1374+ x2 <- get
1375+ x3 <- get
1376+ x4 <- get
1377+ return (PTransform x1 x2 x3 x4)
13331378 _ -> error "Corrupted binary data for PDecl'"
13341379
1380+instance Binary t => Binary (ProvideWhat' t) where
1381+ put (ProvTerm x1 x2) = do putWord8 0
1382+ put x1
1383+ put x2
1384+ put (ProvPostulate x1) = do putWord8 1
1385+ put x1
1386+ get = do y <- getWord8
1387+ case y of
1388+ 0 -> do x1 <- get
1389+ x2 <- get
1390+ return (ProvTerm x1 x2)
1391+ 1 -> do x1 <- get
1392+ return (ProvPostulate x1)
1393+ _ -> error "Corrupted binary data for ProvideWhat"
1394+
13351395instance Binary Using where
13361396 put (UImplicit x1 x2) = do putWord8 0; put x1; put x2
13371397 put (UConstraint x1 x2) = do putWord8 1; put x1; put x2
@@ -1340,6 +1400,7 @@ instance Binary Using where
13401400 case i of
13411401 0 -> do x1 <- get; x2 <- get; return (UImplicit x1 x2)
13421402 1 -> do x1 <- get; x2 <- get; return (UConstraint x1 x2)
1403+ _ -> error "Corrupted binary data for Using"
13431404
13441405instance Binary SyntaxInfo where
13451406 put (Syn x1 x2 x3 x4 _ x5 x6 _ _ x7 _)
@@ -1370,23 +1431,25 @@ instance (Binary t) => Binary (PClause' t) where
13701431 put x4
13711432 put x5
13721433 put x6
1373− PWith x1 x2 x3 x4 x5 x6 -> do putWord8 1
1374− put x1
1375− put x2
1376− put x3
1377− put x4
1378− put x5
1379− put x6
1434+ PWith x1 x2 x3 x4 x5 x6 x7 -> do putWord8 1
1435+ put x1
1436+ put x2
1437+ put x3
1438+ put x4
1439+ put x5
1440+ put x6
1441+ put x7
13801442 PClauseR x1 x2 x3 x4 -> do putWord8 2
13811443 put x1
13821444 put x2
13831445 put x3
13841446 put x4
1385− PWithR x1 x2 x3 x4 -> do putWord8 3
1386− put x1
1387− put x2
1388− put x3
1389− put x4
1447+ PWithR x1 x2 x3 x4 x5 -> do putWord8 3
1448+ put x1
1449+ put x2
1450+ put x3
1451+ put x4
1452+ put x5
13901453 get
13911454 = do i <- getWord8
13921455 case i of
@@ -1403,7 +1466,8 @@ instance (Binary t) => Binary (PClause' t) where
14031466 x4 <- get
14041467 x5 <- get
14051468 x6 <- get
1406− return (PWith x1 x2 x3 x4 x5 x6)
1469+ x7 <- get
1470+ return (PWith x1 x2 x3 x4 x5 x6 x7)
14071471 2 -> do x1 <- get
14081472 x2 <- get
14091473 x3 <- get
@@ -1413,7 +1477,8 @@ instance (Binary t) => Binary (PClause' t) where
14131477 x2 <- get
14141478 x3 <- get
14151479 x4 <- get
1416− return (PWithR x1 x2 x3 x4)
1480+ x5 <- get
1481+ return (PWithR x1 x2 x3 x4 x5)
14171482 _ -> error "Corrupted binary data for PClause'"
14181483
14191484instance (Binary t) => Binary (PData' t) where
@@ -1450,6 +1515,7 @@ instance Binary PunInfo where
14501515 0 -> return TypeOrTerm
14511516 1 -> return IsType
14521517 2 -> return IsTerm
1518+ _ -> error "Corrupted binary data for PunInfo"
14531519
14541520instance Binary PTerm where
14551521 put x
@@ -1484,6 +1550,7 @@ instance Binary PTerm where
14841550 PTyped x1 x2 -> do putWord8 7
14851551 put x1
14861552 put x2
1553+ PAppImpl x1 x2 -> error "PAppImpl in final term"
14871554 PApp x1 x2 x3 -> do putWord8 8
14881555 put x1
14891556 put x2
@@ -1568,6 +1635,21 @@ instance Binary PTerm where
15681635 put x2
15691636 PUniverse x1 -> do putWord8 38
15701637 put x1
1638+ PRunTactics x1 x2 -> do putWord8 39
1639+ put x1
1640+ put x2
1641+ PAs x1 x2 x3 -> do putWord8 40
1642+ put x1
1643+ put x2
1644+ put x3
1645+ PElabError x1 -> do putWord8 41
1646+ put x1
1647+ PQuasiquote x1 x2 -> do putWord8 42
1648+ put x1
1649+ put x2
1650+ PUnquote x1 -> do putWord8 43
1651+ put x1
1652+
15711653
15721654 get
15731655 = do i <- getWord8
@@ -1686,6 +1768,20 @@ instance Binary PTerm where
16861768 return (PDisamb x1 x2)
16871769 38 -> do x1 <- get
16881770 return (PUniverse x1)
1771+ 39 -> do x1 <- get
1772+ x2 <- get
1773+ return (PRunTactics x1 x2)
1774+ 40 -> do x1 <- get
1775+ x2 <- get
1776+ x3 <- get
1777+ return (PAs x1 x2 x3)
1778+ 41 -> do x1 <- get
1779+ return (PElabError x1)
1780+ 42 -> do x1 <- get
1781+ x2 <- get
1782+ return (PQuasiquote x1 x2)
1783+ 43 -> do x1 <- get
1784+ return (PUnquote x1)
16891785 _ -> error "Corrupted binary data for PTerm"
16901786
16911787instance (Binary t) => Binary (PTactic' t) where
@@ -1739,6 +1835,35 @@ instance (Binary t) => Binary (PTactic' t) where
17391835 CaseTac x1 -> do putWord8 23
17401836 put x1
17411837 SourceFC -> putWord8 24
1838+ Intros -> putWord8 25
1839+ Equiv x1 -> do putWord8 26
1840+ put x1
1841+ Claim x1 x2 -> do putWord8 27
1842+ put x1
1843+ put x2
1844+ Unfocus -> putWord8 28
1845+ MatchRefine x1 -> do putWord8 29
1846+ put x1
1847+ LetTacTy x1 x2 x3 -> do putWord8 30
1848+ put x1
1849+ put x2
1850+ put x3
1851+ TCInstance -> putWord8 31
1852+ GoalType x1 x2 -> do putWord8 32
1853+ put x1
1854+ put x2
1855+ TCheck x1 -> do putWord8 33
1856+ put x1
1857+ TEval x1 -> do putWord8 34
1858+ put x1
1859+ TDocStr x1 -> do putWord8 35
1860+ put x1
1861+ TSearch x1 -> do putWord8 36
1862+ put x1
1863+ Skip -> putWord8 37
1864+ TFail x1 -> do putWord8 38
1865+ put x1
1866+ Abandon -> putWord8 39
17421867 get
17431868 = do i <- getWord8
17441869 case i of
@@ -1790,6 +1915,35 @@ instance (Binary t) => Binary (PTactic' t) where
17901915 23 -> do x1 <- get
17911916 return (CaseTac x1)
17921917 24 -> return SourceFC
1918+ 25 -> return Intros
1919+ 26 -> do x1 <- get
1920+ return (Equiv x1)
1921+ 27 -> do x1 <- get
1922+ x2 <- get
1923+ return (Claim x1 x2)
1924+ 28 -> return Unfocus
1925+ 29 -> do x1 <- get
1926+ return (MatchRefine x1)
1927+ 30 -> do x1 <- get
1928+ x2 <- get
1929+ x3 <- get
1930+ return (LetTacTy x1 x2 x3)
1931+ 31 -> return TCInstance
1932+ 32 -> do x1 <- get
1933+ x2 <- get
1934+ return (GoalType x1 x2)
1935+ 33 -> do x1 <- get
1936+ return (TCheck x1)
1937+ 34 -> do x1 <- get
1938+ return (TEval x1)
1939+ 35 -> do x1 <- get
1940+ return (TDocStr x1)
1941+ 36 -> do x1 <- get
1942+ return (TSearch x1)
1943+ 37 -> return Skip
1944+ 38 -> do x1 <- get
1945+ return (TFail x1)
1946+ 39 -> return Abandon
17931947 _ -> error "Corrupted binary data for PTactic'"
17941948
17951949
src/Idris/IdeSlave.hs → src/Idris/IdeMode.hsrenamed+33−29
@@ -2,7 +2,7 @@
22
33{-# LANGUAGE FlexibleInstances, IncoherentInstances, PatternGuards #-}
44
5−module Idris.IdeSlave(parseMessage, convSExp, IdeSlaveCommand(..), sexpToCommand, toSExp, SExp(..), SExpable, Opt(..), ideSlaveEpoch, getLen, getNChar) where
5+module Idris.IdeMode(parseMessage, convSExp, IdeModeCommand(..), sexpToCommand, toSExp, SExp(..), SExpable, Opt(..), ideModeEpoch, getLen, getNChar) where
66
77import Text.Printf
88import Numeric
@@ -206,32 +206,33 @@ parseSExp = parseString pSExp (Directed (UTF8.fromString "(unknown)") 0 0 0 0)
206206
207207data Opt = ShowImpl | ErrContext deriving Show
208208
209−data IdeSlaveCommand = REPLCompletions String
210− | Interpret String
211− | TypeOf String
212− | CaseSplit Int String
213− | AddClause Int String
214− | AddProofClause Int String
215− | AddMissing Int String
216− | MakeWithBlock Int String
217− | ProofSearch Bool Int String [String] (Maybe Int) -- ^^ Recursive?, line, name, hints, depth
218− | MakeLemma Int String
219− | LoadFile String (Maybe Int)
220− | DocsFor String
221− | Apropos String
222− | GetOpts
223− | SetOpt Opt Bool
224− | Metavariables Int -- ^^ the Int is the column count for pretty-printing
225− | WhoCalls String
226− | CallsWho String
227− | TermNormalise [(Name, Bool)] Term
228− | TermShowImplicits [(Name, Bool)] Term
229− | TermNoImplicits [(Name, Bool)] Term
230− | PrintDef String
231− | ErrString Err
232− | ErrPPrint Err
233−
234−sexpToCommand :: SExp -> Maybe IdeSlaveCommand
209+data IdeModeCommand = REPLCompletions String
210+ | Interpret String
211+ | TypeOf String
212+ | CaseSplit Int String
213+ | AddClause Int String
214+ | AddProofClause Int String
215+ | AddMissing Int String
216+ | MakeWithBlock Int String
217+ | ProofSearch Bool Int String [String] (Maybe Int) -- ^^ Recursive?, line, name, hints, depth
218+ | MakeLemma Int String
219+ | LoadFile String (Maybe Int)
220+ | DocsFor String
221+ | Apropos String
222+ | GetOpts
223+ | SetOpt Opt Bool
224+ | Metavariables Int -- ^^ the Int is the column count for pretty-printing
225+ | WhoCalls String
226+ | CallsWho String
227+ | TermNormalise [(Name, Bool)] Term
228+ | TermShowImplicits [(Name, Bool)] Term
229+ | TermNoImplicits [(Name, Bool)] Term
230+ | PrintDef String
231+ | ErrString Err
232+ | ErrPPrint Err
233+ | GetIdrisVersion
234+
235+sexpToCommand :: SExp -> Maybe IdeModeCommand
235236sexpToCommand (SexpList (x:[])) = sexpToCommand x
236237sexpToCommand (SexpList [SymbolAtom "interpret", StringAtom cmd]) = Just (Interpret cmd)
237238sexpToCommand (SexpList [SymbolAtom "repl-completions", StringAtom prefix]) = Just (REPLCompletions prefix)
@@ -275,6 +276,7 @@ sexpToCommand (SexpList [SymbolAtom "hide-term-implicits", StringAtom encoded])
275276sexpToCommand (SexpList [SymbolAtom "print-definition", StringAtom name]) = Just (PrintDef name)
276277sexpToCommand (SexpList [SymbolAtom "error-string", StringAtom encoded]) = Just . ErrString . decodeErr $ encoded
277278sexpToCommand (SexpList [SymbolAtom "error-pprint", StringAtom encoded]) = Just . ErrPPrint . decodeErr $ encoded
279+sexpToCommand (SymbolAtom "version") = Just GetIdrisVersion
278280sexpToCommand _ = Nothing
279281
280282parseMessage :: String -> Either Err (SExp, Integer)
@@ -298,5 +300,7 @@ convSExp pre s id =
298300getHexLength :: String -> String
299301getHexLength s = printf "%06x" (1 + (length s))
300302
301−ideSlaveEpoch :: Int
302−ideSlaveEpoch = 1
303+-- | The version of the IDE mode command set. Increment this when you
304+-- change it so clients can adapt.
305+ideModeEpoch :: Int
306+ideModeEpoch = 1
src/Idris/IdrisDoc.hs+1
@@ -318,6 +318,7 @@ extractPTermNames (PCoerced p) = extract p
318318extractPTermNames (PDisamb _ p) = extract p
319319extractPTermNames (PUnifyLog p) = extract p
320320extractPTermNames (PNoImplicits p) = extract p
321+extractPTermNames (PRunTactics _ p) = extract p
321322extractPTermNames _ = []
322323
323324-- | Shorter name for extractPTermNames
src/Idris/Interactive.hs+3−3
@@ -16,7 +16,7 @@ import Idris.ElabTerm
1616import Idris.Error
1717import Idris.Delaborate
1818import Idris.Output
19−import Idris.IdeSlave hiding (IdeSlaveCommand(..))
19+import Idris.IdeMode hiding (IdeModeCommand(..))
2020
2121import Idris.Elab.Value
2222
@@ -271,7 +271,7 @@ makeLemma fn updatefile l n
271271 runIO $ copyFile fb fn
272272 else case idris_outputmode i of
273273 RawOutput _ -> iPrintResult $ lem ++ "\n" ++ lem_app
274− IdeSlave n h ->
274+ IdeMode n h ->
275275 let good = SexpList [SymbolAtom "ok",
276276 SexpList [SymbolAtom "metavariable-lemma",
277277 SexpList [SymbolAtom "replace-metavariable",
@@ -289,7 +289,7 @@ makeLemma fn updatefile l n
289289 runIO $ copyFile fb fn
290290 else case idris_outputmode i of
291291 RawOutput _ -> iPrintResult $ lem_app
292− IdeSlave n h ->
292+ IdeMode n h ->
293293 let good = SexpList [SymbolAtom "ok",
294294 SexpList [SymbolAtom "provisional-definition-lemma",
295295 SexpList [SymbolAtom "definition-clause",
src/Idris/Output.hs+24−22
@@ -8,7 +8,7 @@ import Idris.Core.Evaluate (isDConName, isTConName, isFnName, normaliseAll)
88import Idris.AbsSyntax
99import Idris.Delaborate
1010import Idris.Docstrings
11−import Idris.IdeSlave
11+import Idris.IdeMode
1212
1313import Util.Pretty
1414import Util.ScreenSize (getScreenWidth)
@@ -43,7 +43,7 @@ iWarn fc err =
4343 then text (show fc) <> colon <//> err
4444 else err
4545 runIO . hPutStrLn h $ displayDecorated (consoleDecorate i) err'
46− IdeSlave n h ->
46+ IdeMode n h ->
4747 do err' <- iRender . fmap (fancifyAnnots i) $ err
4848 let (str, spans) = displaySpans err'
4949 runIO . hPutStrLn h $
@@ -52,8 +52,8 @@ iWarn fc err =
5252iRender :: Doc a -> Idris (SimpleDoc a)
5353iRender d = do w <- getWidth
5454 ist <- getIState
55− let ideSlave = case idris_outputmode ist of
56− IdeSlave _ _ -> True
55+ let ideMode = case idris_outputmode ist of
56+ IdeMode _ _ -> True
5757 _ -> False
5858 case w of
5959 InfinitelyWide -> return $ renderPretty 1.0 1000000000 d
@@ -61,7 +61,7 @@ iRender d = do w <- getWidth
6161 if n < 1
6262 then renderPretty 1.0 1000000000 d
6363 else renderPretty 0.8 n d
64− AutomaticWidth | ideSlave -> return $ renderPretty 1.0 1000000000 d
64+ AutomaticWidth | ideMode -> return $ renderPretty 1.0 1000000000 d
6565 | otherwise -> do width <- runIO getScreenWidth
6666 return $ renderPretty 0.8 width d
6767
@@ -76,7 +76,7 @@ consoleDisplayAnnotated h output = do ist <- getIState
7676iPrintTermWithType :: Doc OutputAnnotation -> Doc OutputAnnotation -> Idris ()
7777iPrintTermWithType tm ty = iRenderResult (tm <+> colon <+> align ty)
7878
79−-- | Pretty-print a collection of overloadings to REPL or IDESlave - corresponds to :t name
79+-- | Pretty-print a collection of overloadings to REPL or IDEMode - corresponds to :t name
8080iPrintFunTypes :: [(Name, Bool)] -> Name -> [(Name, Doc OutputAnnotation)] -> Idris ()
8181iPrintFunTypes bnd n [] = iPrintError $ "No such variable " ++ show n
8282iPrintFunTypes bnd n overloads = do ist <- getIState
@@ -94,7 +94,7 @@ iRenderOutput doc =
9494 case idris_outputmode i of
9595 RawOutput h -> do out <- iRender doc
9696 runIO $ putStrLn (displayDecorated (consoleDecorate i) out)
97− IdeSlave n h ->
97+ IdeMode n h ->
9898 do (str, spans) <- fmap displaySpans . iRender . fmap (fancifyAnnots i) $ doc
9999 let out = [toSExp str, toSExp spans]
100100 runIO . hPutStrLn h $ convSExp "write-decorated" out n
@@ -103,10 +103,10 @@ iRenderResult :: Doc OutputAnnotation -> Idris ()
103103iRenderResult d = do ist <- getIState
104104 case idris_outputmode ist of
105105 RawOutput h -> consoleDisplayAnnotated h d
106− IdeSlave n h -> ideSlaveReturnAnnotated n h d
106+ IdeMode n h -> ideModeReturnAnnotated n h d
107107
108−ideSlaveReturnWithStatus :: String -> Integer -> Handle -> Doc OutputAnnotation -> Idris ()
109−ideSlaveReturnWithStatus status n h out = do
108+ideModeReturnWithStatus :: String -> Integer -> Handle -> Doc OutputAnnotation -> Idris ()
109+ideModeReturnWithStatus status n h out = do
110110 ist <- getIState
111111 (str, spans) <- fmap displaySpans .
112112 iRender .
@@ -116,16 +116,16 @@ ideSlaveReturnWithStatus status n h out = do
116116 runIO . hPutStrLn h $ convSExp "return" good n
117117
118118
119−-- | Write pretty-printed output to IDESlave with semantic annotations
120−ideSlaveReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
121−ideSlaveReturnAnnotated = ideSlaveReturnWithStatus "ok"
119+-- | Write pretty-printed output to IDEMode with semantic annotations
120+ideModeReturnAnnotated :: Integer -> Handle -> Doc OutputAnnotation -> Idris ()
121+ideModeReturnAnnotated = ideModeReturnWithStatus "ok"
122122
123123-- | Show an error with semantic highlighting
124124iRenderError :: Doc OutputAnnotation -> Idris ()
125125iRenderError e = do ist <- getIState
126126 case idris_outputmode ist of
127127 RawOutput h -> consoleDisplayAnnotated h e
128− IdeSlave n h -> ideSlaveReturnWithStatus "error" n h e
128+ IdeMode n h -> ideModeReturnWithStatus "error" n h e
129129
130130iPrintWithStatus :: String -> String -> Idris ()
131131iPrintWithStatus status s = do
@@ -134,7 +134,7 @@ iPrintWithStatus status s = do
134134 RawOutput h -> case s of
135135 "" -> return ()
136136 s -> runIO $ hPutStrLn h s
137− IdeSlave n h ->
137+ IdeMode n h ->
138138 let good = SexpList [SymbolAtom status, toSExp s] in
139139 runIO $ hPutStrLn h $ convSExp "return" good n
140140
@@ -149,21 +149,23 @@ iputStrLn :: String -> Idris ()
149149iputStrLn s = do i <- getIState
150150 case idris_outputmode i of
151151 RawOutput h -> runIO $ hPutStrLn h s
152− IdeSlave n h -> runIO . hPutStrLn h $ convSExp "write-string" s n
152+ IdeMode n h -> runIO . hPutStrLn h $ convSExp "write-string" s n
153153
154154
155−ideslavePutSExp :: SExpable a => String -> a -> Idris ()
156−ideslavePutSExp cmd info = do i <- getIState
157− case idris_outputmode i of
158− IdeSlave n h -> runIO . hPutStrLn h $ convSExp cmd info n
159− _ -> return ()
155+idemodePutSExp :: SExpable a => String -> a -> Idris ()
156+idemodePutSExp cmd info = do i <- getIState
157+ case idris_outputmode i of
158+ IdeMode n h ->
159+ runIO . hPutStrLn h $
160+ convSExp cmd info n
161+ _ -> return ()
160162
161163-- TODO: send structured output similar to the metavariable list
162164iputGoal :: SimpleDoc OutputAnnotation -> Idris ()
163165iputGoal g = do i <- getIState
164166 case idris_outputmode i of
165167 RawOutput h -> runIO $ hPutStrLn h (displayDecorated (consoleDecorate i) g)
166− IdeSlave n h ->
168+ IdeMode n h ->
167169 let (str, spans) = displaySpans . fmap (fancifyAnnots i) $ g
168170 goal = [toSExp str, toSExp spans]
169171 in runIO . hPutStrLn h $ convSExp "write-goal" goal n
src/Idris/ParseExpr.hs+20−1
@@ -221,6 +221,7 @@ InternalExpr ::=
221221internalExpr :: SyntaxInfo -> IdrisParser PTerm
222222internalExpr syn =
223223 unifyLog syn
224+ <|> runTactics syn
224225 <|> disamb syn
225226 <|> noImplicits syn
226227 <|> recordType syn
@@ -487,6 +488,19 @@ unifyLog syn = do try (lchar '%' *> reserved "unifyLog")
487488 return (PUnifyLog tm)
488489 <?> "unification log expression"
489490
491+{- | Parses a new-style tactics expression
492+RunTactics ::=
493+ '%' 'runTactics' SimpleExpr
494+ ;
495+-}
496+runTactics :: SyntaxInfo -> IdrisParser PTerm
497+runTactics syn = do try (lchar '%' *> reserved "runTactics")
498+ fc <- getFC
499+ tm <- simpleExpr syn
500+ i <- get
501+ return $ PRunTactics fc tm
502+ <?> "new-style tactics expression"
503+
490504{- | Parses a disambiguation expression
491505Disamb ::=
492506 '%' 'disamb' NameList Expr
@@ -1251,10 +1265,15 @@ tactics =
12511265 [ (["intro"], Nothing, const $ -- FIXME syntax for intro (fresh name)
12521266 do ns <- sepBy (spaced name) (lchar ','); return $ Intro ns)
12531267 , noArgs ["intros"] Intros
1268+ , noArgs ["unfocus"] Unfocus
12541269 , (["refine"], Just ExprTArg, const $
12551270 do n <- spaced fnName
12561271 imps <- many imp
12571272 return $ Refine n imps)
1273+ , (["claim"], Nothing, \syn ->
1274+ do n <- indentPropHolds gtProp *> name
1275+ goal <- indentPropHolds gtProp *> expr syn
1276+ return $ Claim n goal)
12581277 , (["mrefine"], Just ExprTArg, const $
12591278 do n <- spaced fnName
12601279 return $ MatchRefine n)
@@ -1329,7 +1348,7 @@ tactics =
13291348
13301349
13311350tactic :: SyntaxInfo -> IdrisParser PTactic
1332−tactic syn = choice [ do choice (map reserved names); parser syn
1351+tactic syn = choice [ do choice (map reserved names); parser syn
13331352 | (names, _, parser) <- tactics ]
13341353 <|> do lchar '{'
13351354 t <- tactic syn;
src/Idris/ParseHelpers.hs+16−16
@@ -105,30 +105,28 @@ isEol :: Char -> Bool
105105isEol '\n' = True
106106isEol _ = False
107107
108+-- | A parser that succeeds at the end of the line
108109eol :: MonadicParsing m => m ()
109110eol = (satisfy isEol *> pure ()) <|> lookAhead eof <?> "end of line"
110111
111112{- | Consumes a single-line comment
112113
113114@
114− SingleLineComment_t ::= '--' EOL_t
115− | '--' ~DocCommentMarker_t ~EOL_t* EOL_t
116− ;
115+ SingleLineComment_t ::= '--' ~EOL_t* EOL_t ;
117116@
118117 -}
119118singleLineComment :: MonadicParsing m => m ()
120−singleLineComment = try (string "--" *> eol *> pure ())
121− <|> try (string "--" *> many simpleWhiteSpace *>
122− many (satisfy (not . isEol)) *>
123− eol *> pure ())
124− <?> ""
119+singleLineComment = (string "--" *>
120+ many (satisfy (not . isEol)) *>
121+ eol *> pure ())
122+ <?> "single-line comment"
125123
126124{- | Consumes a multi-line comment
127125
128126@
129127 MultiLineComment_t ::=
130128 '{ -- }'
131− | '{ -' ~DocCommentMarker_t InCommentChars_t
129+ | '{ -' InCommentChars_t
132130 ;
133131@
134132
@@ -154,7 +152,7 @@ multiLineComment = try (string "{-" *> (string "-}") *> pure ())
154152 startEnd :: String
155153 startEnd = "{}-"
156154
157−{-| Parses a documentation comment (similar to haddock) given a marker character
155+{-| Parses a documentation comment
158156
159157@
160158 DocComment_t ::= '|||' ~EOL_t* EOL_t
@@ -224,7 +222,7 @@ float = Tok.double
224222idrisStyle :: MonadicParsing m => IdentifierStyle m
225223idrisStyle = IdentifierStyle _styleName _styleStart _styleLetter _styleReserved Hi.Identifier Hi.ReservedIdentifier
226224 where _styleName = "Idris"
227− _styleStart = satisfy isAlpha
225+ _styleStart = satisfy isAlpha <|> oneOf "_"
228226 _styleLetter = satisfy isAlphaNum <|> oneOf "_'."
229227 _styleReserved = HS.fromList ["let", "in", "data", "codata", "record", "corecord", "Type",
230228 "do", "dsl", "import", "impossible",
@@ -262,7 +260,9 @@ reservedOp name = token $ try $
262260
263261-- | Parses an identifier as a token
264262identifier :: MonadicParsing m => m String
265−identifier = token $ Tok.ident idrisStyle
263+identifier = try(do i <- token $ Tok.ident idrisStyle
264+ when (i == "_") $ unexpected "wildcard"
265+ return i)
266266
267267-- | Parses an identifier with possible namespace as a name
268268iName :: MonadicParsing m => [String] -> m Name
@@ -562,17 +562,17 @@ collect (c@(PClauses _ o _ _) : ds)
562562 where clauses :: Maybe Name -> [PClause] -> [PDecl] -> [PDecl]
563563 clauses j@(Just n) acc (PClauses fc _ _ [PClause fc' n' l ws r w] : ds)
564564 | n == n' = clauses j (PClause fc' n' l ws r (collect w) : acc) ds
565− clauses j@(Just n) acc (PClauses fc _ _ [PWith fc' n' l ws r w] : ds)
566− | n == n' = clauses j (PWith fc' n' l ws r (collect w) : acc) ds
565+ clauses j@(Just n) acc (PClauses fc _ _ [PWith fc' n' l ws r pn w] : ds)
566+ | n == n' = clauses j (PWith fc' n' l ws r pn (collect w) : acc) ds
567567 clauses (Just n) acc xs = PClauses (fcOf c) o n (reverse acc) : collect xs
568568 clauses Nothing acc (x:xs) = collect xs
569569 clauses Nothing acc [] = []
570570
571571 cname :: PDecl -> Maybe Name
572572 cname (PClauses fc _ _ [PClause _ n _ _ _ _]) = Just n
573− cname (PClauses fc _ _ [PWith _ n _ _ _ _]) = Just n
573+ cname (PClauses fc _ _ [PWith _ n _ _ _ _ _]) = Just n
574574 cname (PClauses fc _ _ [PClauseR _ _ _ _]) = Nothing
575− cname (PClauses fc _ _ [PWithR _ _ _ _]) = Nothing
575+ cname (PClauses fc _ _ [PWithR _ _ _ _ _]) = Nothing
576576 fcOf :: PDecl -> FC
577577 fcOf (PClauses fc _ _ _) = fc
578578collect (PParams f ns ps : ds) = PParams f ns (collect ps) : collect ds
src/Idris/Parser.hs+29−6
@@ -826,11 +826,12 @@ clause syn
826826 popIndent
827827 reserved "with"
828828 wval <- simpleExpr syn
829+ pn <- optProof
829830 openBlock
830831 ds <- some $ fnDecl syn
831832 let withs = concat ds
832833 closeBlock
833− return $ PWithR fc wargs wval withs)
834+ return $ PWithR fc wargs wval pn withs)
834835 <|> do ty <- try (do pushIndent
835836 ty <- simpleExpr syn
836837 symbol "<=="
@@ -878,6 +879,7 @@ clause syn
878879 popIndent
879880 reserved "with"
880881 wval <- bracketed syn
882+ pn <- optProof
881883 openBlock
882884 ds <- some $ fnDecl syn
883885 closeBlock
@@ -885,7 +887,7 @@ clause syn
885887 let capp = PApp fc (PRef fc n) [pexp l, pexp r]
886888 let withs = map (fillLHSD n capp wargs) $ concat ds
887889 put (ist { lastParse = Just n })
888− return $ PWith fc n capp wargs wval withs)
890+ return $ PWith fc n capp wargs wval pn withs)
889891 <|> do pushIndent
890892 n_in <- fnName; let n = expandNS syn n_in
891893 cargs <- many (constraintArg syn)
@@ -911,19 +913,24 @@ clause syn
911913 ist <- get
912914 put (ist { lastParse = Just n })
913915 wval <- bracketed syn
916+ pn <- optProof
914917 openBlock
915918 ds <- some $ fnDecl syn
916919 let withs = map (fillLHSD n capp wargs) $ concat ds
917920 closeBlock
918921 popIndent
919− return $ PWith fc n capp wargs wval withs)
922+ return $ PWith fc n capp wargs wval pn withs)
920923 <?> "function clause"
921924 where
925+ optProof = option Nothing (do reserved "proof"
926+ n <- fnName
927+ return (Just n))
928+
922929 fillLHS :: Name -> PTerm -> [PTerm] -> PClause -> PClause
923930 fillLHS n capp owargs (PClauseR fc wargs v ws)
924931 = PClause fc n capp (owargs ++ wargs) v ws
925− fillLHS n capp owargs (PWithR fc wargs v ws)
926− = PWith fc n capp (owargs ++ wargs) v
932+ fillLHS n capp owargs (PWithR fc wargs v pn ws)
933+ = PWith fc n capp (owargs ++ wargs) v pn
927934 (map (fillLHSD n capp (owargs ++ wargs)) ws)
928935 fillLHS _ _ _ c = c
929936
@@ -1192,7 +1199,7 @@ parseProg syn fname input mrk
11921199 i <- getIState
11931200 case idris_outputmode i of
11941201 RawOutput h -> iputStrLn (show $ fixColour (idris_colourRepl i) doc)
1195− IdeSlave n h -> iWarn fc (P.text msg)
1202+ IdeMode n h -> iWarn fc (P.text msg)
11961203 putIState (i { errSpan = Just fc })
11971204 return []
11981205 Success (x, i) -> do putIState i
@@ -1304,8 +1311,24 @@ loadSource lidr f toline
13041311 mapM_ (addIBC . IBCImport) [(reexport, realName) | (reexport, realName, alias, fc) <- imports]
13051312 let syntax = defaultSyntax{ syn_namespace = reverse mname,
13061313 maxline = toline }
1314+ ist <- getIState
1315+ -- Save the span from parsing the module header, because
1316+ -- an empty program parse might obliterate it.
1317+ let oldSpan = idris_parsedSpan ist
13071318 ds' <- parseProg syntax f file pos
13081319
1320+ case (ds', oldSpan) of
1321+ ([], Just fc) ->
1322+ -- If no program elements were parsed, we dind't
1323+ -- get a loaded region in the IBC file. That
1324+ -- means we need to add it back.
1325+ do ist <- getIState
1326+ putIState ist { idris_parsedSpan = oldSpan
1327+ , ibc_write = IBCParsedRegion fc :
1328+ ibc_write ist
1329+ }
1330+ _ -> return ()
1331+
13091332 -- Parsing done, now process declarations
13101333
13111334 let ds = namespaces mname ds'
src/Idris/Prover.hs+18−18
@@ -20,7 +20,7 @@ import Idris.Parser hiding (params)
2020import Idris.Error
2121import Idris.DataOpts
2222import Idris.Completion
23−import qualified Idris.IdeSlave as IdeSlave
23+import qualified Idris.IdeMode as IdeMode
2424import Idris.Output
2525import Idris.TypeSearch (searchByType)
2626
@@ -67,12 +67,12 @@ assumptionNames e
6767prove :: Ctxt OptInfo -> Context -> Bool -> Name -> Type -> Idris ()
6868prove opt ctxt lit n ty
6969 = do let ps = initElaborator n ctxt ty
70− ideslavePutSExp "start-proof-mode" n
70+ idemodePutSExp "start-proof-mode" n
7171 (tm, prf) <- ploop n True ("-" ++ show n) [] (ES (ps, initEState) "" Nothing) Nothing
7272 iLOG $ "Adding " ++ show tm
7373 i <- getIState
7474 case idris_outputmode i of
75− IdeSlave _ _ -> ideslavePutSExp "end-proof-mode" (n, showProof lit n prf)
75+ IdeMode _ _ -> idemodePutSExp "end-proof-mode" (n, showProof lit n prf)
7676 _ -> iputStrLn $ showProof lit n prf
7777 let proofs = proof_list i
7878 putIState (i { proof_list = (n, prf) : proofs })
@@ -95,8 +95,8 @@ prove opt ctxt lit n ty
9595 [([], P Ref n ty, ptm')] ty)
9696 solveDeferred n
9797 case idris_outputmode i of
98− IdeSlave n h ->
99− runIO . hPutStrLn h $ IdeSlave.convSExp "return" (IdeSlave.SymbolAtom "ok", "") n
98+ IdeMode n h ->
99+ runIO . hPutStrLn h $ IdeMode.convSExp "return" (IdeMode.SymbolAtom "ok", "") n
100100 _ -> return ()
101101
102102elabStep :: ElabState EState -> ElabD a -> Idris (a, ElabState EState)
@@ -185,24 +185,24 @@ receiveInput :: Handle -> ElabState EState -> Idris (Maybe String)
185185receiveInput h e =
186186 do i <- getIState
187187 let inh = if h == stdout then stdin else h
188− len' <- runIO $ IdeSlave.getLen inh
188+ len' <- runIO $ IdeMode.getLen inh
189189 len <- case len' of
190190 Left err -> ierror err
191191 Right n -> return n
192− l <- runIO $ IdeSlave.getNChar inh len ""
193− (sexp, id) <- case IdeSlave.parseMessage l of
192+ l <- runIO $ IdeMode.getNChar inh len ""
193+ (sexp, id) <- case IdeMode.parseMessage l of
194194 Left err -> ierror err
195195 Right (sexp, id) -> return (sexp, id)
196− putIState $ i { idris_outputmode = (IdeSlave id h) }
197− case IdeSlave.sexpToCommand sexp of
198− Just (IdeSlave.REPLCompletions prefix) ->
196+ putIState $ i { idris_outputmode = (IdeMode id h) }
197+ case IdeMode.sexpToCommand sexp of
198+ Just (IdeMode.REPLCompletions prefix) ->
199199 do (unused, compls) <- proverCompletion (assumptionNames e) (reverse prefix, "")
200− let good = IdeSlave.SexpList [IdeSlave.SymbolAtom "ok", IdeSlave.toSExp (map replacement compls, reverse unused)]
201− ideslavePutSExp "return" good
200+ let good = IdeMode.SexpList [IdeMode.SymbolAtom "ok", IdeMode.toSExp (map replacement compls, reverse unused)]
201+ idemodePutSExp "return" good
202202 receiveInput h e
203− Just (IdeSlave.Interpret cmd) -> return (Just cmd)
204− Just (IdeSlave.TypeOf str) -> return (Just (":t " ++ str))
205− Just (IdeSlave.DocsFor str) -> return (Just (":doc " ++ str))
203+ Just (IdeMode.Interpret cmd) -> return (Just cmd)
204+ Just (IdeMode.TypeOf str) -> return (Just (":t " ++ str))
205+ Just (IdeMode.DocsFor str) -> return (Just (":doc " ++ str))
206206 _ -> return Nothing
207207
208208ploop :: Name -> Bool -> String -> [String] -> ElabState EState -> Maybe History -> Idris (Term, [String])
@@ -221,7 +221,7 @@ ploop fn d prompt prf e h
221221 l <- getInputLine (prompt ++ "> ")
222222 h' <- getHistory
223223 return (l, Just h')
224− IdeSlave _ handle ->
224+ IdeMode _ handle ->
225225 do isetPrompt prompt
226226 i <- receiveInput handle e
227227 return (i, h)
@@ -254,7 +254,7 @@ ploop fn d prompt prf e h
254254 (_, st) <- elabStep e (runTac autoSolve i (Just proverFC) fn tac)
255255 return (True, st, False, prf ++ [step], Right $ iPrintResult ""))
256256 (\err -> return (False, e, False, prf, Left err))
257− ideslavePutSExp "write-proof-state" (prf', length prf')
257+ idemodePutSExp "write-proof-state" (prf', length prf')
258258 case res of
259259 Left err -> do ist <- getIState
260260 iRenderError $ pprintErr ist err
src/Idris/REPL.hs+190−175
@@ -22,7 +22,7 @@ import Idris.Primitives
2222import Idris.Coverage
2323import Idris.Docs hiding (Doc)
2424import Idris.Completion
25−import qualified Idris.IdeSlave as IdeSlave
25+import qualified Idris.IdeMode as IdeMode
2626import Idris.Chaser
2727import Idris.Imports
2828import Idris.Colours hiding (colourise)
@@ -165,7 +165,7 @@ startServer port orig fn_in = do tid <- runIO $ forkOS (serverLoop port)
165165 cmd <- hGetLine h
166166 let isth = case idris_outputmode ist of
167167 RawOutput _ -> ist {idris_outputmode = RawOutput h}
168− IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
168+ IdeMode n _ -> ist {idris_outputmode = IdeMode n h}
169169 (ist', fn) <- processNetCmd orig isth h fn cmd
170170 hClose h
171171 loop fn ist' sock
@@ -204,7 +204,7 @@ processNetCmd orig i h fn cmd
204204 do ist <- getIState
205205 putIState $ case idris_outputmode ist of
206206 RawOutput _ -> ist {idris_outputmode = RawOutput h}
207− IdeSlave n _ -> ist {idris_outputmode = IdeSlave n h}
207+ IdeMode n _ -> ist {idris_outputmode = IdeMode n h}
208208
209209-- | Run a command on the server on localhost
210210runClient :: PortID -> String -> IO ()
@@ -232,62 +232,62 @@ runClient port str = withSocketsDo $ do
232232 putStrLn "Unable to connect to a running Idris repl"
233233
234234
235−initIdeslaveSocket :: IO Handle
236−initIdeslaveSocket = do
235+initIdemodeSocket :: IO Handle
236+initIdemodeSocket = do
237237 (sock, port) <- listenOnLocalhostAnyPort
238238 putStrLn $ show port
239239 (h, _, _) <- accept sock
240240 hSetEncoding h utf8
241241 return h
242242
243−-- | Run the IdeSlave
244−ideslaveStart :: Bool -> IState -> [FilePath] -> Idris ()
245−ideslaveStart s orig mods
246− = do h <- runIO $ if s then initIdeslaveSocket else return stdout
247− setIdeSlave True h
243+-- | Run the IdeMode
244+idemodeStart :: Bool -> IState -> [FilePath] -> Idris ()
245+idemodeStart s orig mods
246+ = do h <- runIO $ if s then initIdemodeSocket else return stdout
247+ setIdeMode True h
248248 i <- getIState
249249 case idris_outputmode i of
250− IdeSlave n h ->
251− do runIO $ hPutStrLn h $ IdeSlave.convSExp "protocol-version" IdeSlave.ideSlaveEpoch n
250+ IdeMode n h ->
251+ do runIO $ hPutStrLn h $ IdeMode.convSExp "protocol-version" IdeMode.ideModeEpoch n
252252 case mods of
253− a:_ -> runIdeSlaveCommand h n i "" [] (IdeSlave.LoadFile a Nothing)
253+ a:_ -> runIdeModeCommand h n i "" [] (IdeMode.LoadFile a Nothing)
254254 _ -> return ()
255− ideslave h orig mods
255+ idemode h orig mods
256256
257−ideslave :: Handle -> IState -> [FilePath] -> Idris ()
258−ideslave h orig mods
257+idemode :: Handle -> IState -> [FilePath] -> Idris ()
258+idemode h orig mods
259259 = do idrisCatch
260260 (do let inh = if h == stdout then stdin else h
261− len' <- runIO $ IdeSlave.getLen inh
261+ len' <- runIO $ IdeMode.getLen inh
262262 len <- case len' of
263263 Left err -> ierror err
264264 Right n -> return n
265− l <- runIO $ IdeSlave.getNChar inh len ""
266− (sexp, id) <- case IdeSlave.parseMessage l of
265+ l <- runIO $ IdeMode.getNChar inh len ""
266+ (sexp, id) <- case IdeMode.parseMessage l of
267267 Left err -> ierror err
268268 Right (sexp, id) -> return (sexp, id)
269269 i <- getIState
270− putIState $ i { idris_outputmode = (IdeSlave id h) }
270+ putIState $ i { idris_outputmode = (IdeMode id h) }
271271 idrisCatch -- to report correct id back!
272272 (do let fn = case mods of
273273 (f:_) -> f
274274 _ -> ""
275− case IdeSlave.sexpToCommand sexp of
276− Just cmd -> runIdeSlaveCommand h id orig fn mods cmd
275+ case IdeMode.sexpToCommand sexp of
276+ Just cmd -> runIdeModeCommand h id orig fn mods cmd
277277 Nothing -> iPrintError "did not understand" )
278278 (\e -> do iPrintError $ show e))
279279 (\e -> do iPrintError $ show e)
280− ideslave h orig mods
280+ idemode h orig mods
281281
282−-- | Run IDESlave commands
283−runIdeSlaveCommand :: Handle -- ^^ The handle for communication
282+-- | Run IDEMode commands
283+runIdeModeCommand :: Handle -- ^^ The handle for communication
284284 -> Integer -- ^^ The continuation ID for the client
285285 -> IState -- ^^ The original IState
286286 -> FilePath -- ^^ The current open file
287287 -> [FilePath] -- ^^ The currently loaded modules
288− -> IdeSlave.IdeSlaveCommand -- ^^ The command to process
288+ -> IdeMode.IdeModeCommand -- ^^ The command to process
289289 -> Idris ()
290−runIdeSlaveCommand h id orig fn mods (IdeSlave.Interpret cmd) =
290+runIdeModeCommand h id orig fn mods (IdeMode.Interpret cmd) =
291291 do c <- colourise
292292 i <- getIState
293293 case parseCmd i "(input)" cmd of
@@ -297,96 +297,96 @@ runIdeSlaveCommand h id orig fn mods (IdeSlave.Interpret cmd) =
297297 (do process fn (Prove n')
298298 isetPrompt (mkPrompt mods)
299299 case idris_outputmode i of
300− IdeSlave n h -> -- signal completion of proof to ide
300+ IdeMode n h -> -- signal completion of proof to ide
301301 runIO . hPutStrLn h $
302− IdeSlave.convSExp "return"
303− (IdeSlave.SymbolAtom "ok", "")
302+ IdeMode.convSExp "return"
303+ (IdeMode.SymbolAtom "ok", "")
304304 n
305305 _ -> return ())
306306 (\e -> do ist <- getIState
307307 isetPrompt (mkPrompt mods)
308308 case idris_outputmode i of
309− IdeSlave n h ->
309+ IdeMode n h ->
310310 runIO . hPutStrLn h $
311− IdeSlave.convSExp "abandon-proof" "Abandoned" n
311+ IdeMode.convSExp "abandon-proof" "Abandoned" n
312312 _ -> return ()
313313 iRenderError $ pprintErr ist e)
314314 Success (Right cmd) -> idrisCatch
315− (ideslaveProcess fn cmd)
315+ (idemodeProcess fn cmd)
316316 (\e -> getIState >>= iRenderError . flip pprintErr e)
317317 Success (Left err) -> iPrintError err
318−runIdeSlaveCommand h id orig fn mods (IdeSlave.REPLCompletions str) =
318+runIdeModeCommand h id orig fn mods (IdeMode.REPLCompletions str) =
319319 do (unused, compls) <- replCompletion (reverse str, "")
320− let good = IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
321− IdeSlave.toSExp (map replacement compls,
320+ let good = IdeMode.SexpList [IdeMode.SymbolAtom "ok",
321+ IdeMode.toSExp (map replacement compls,
322322 reverse unused)]
323− runIO . hPutStrLn h $ IdeSlave.convSExp "return" good id
324−runIdeSlaveCommand h id orig fn mods (IdeSlave.LoadFile filename toline) =
323+ runIO . hPutStrLn h $ IdeMode.convSExp "return" good id
324+runIdeModeCommand h id orig fn mods (IdeMode.LoadFile filename toline) =
325325 do i <- getIState
326326 clearErr
327327 putIState (orig { idris_options = idris_options i,
328− idris_outputmode = (IdeSlave id h) })
328+ idris_outputmode = (IdeMode id h) })
329329 mods <- loadInputs [filename] toline
330330 isetPrompt (mkPrompt mods)
331331 -- Report either success or failure
332332 i <- getIState
333333 case (errSpan i) of
334− Nothing -> let msg = maybe (IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
335− IdeSlave.SexpList []])
336− (\fc -> IdeSlave.SexpList [IdeSlave.SymbolAtom "ok",
337− IdeSlave.toSExp fc])
334+ Nothing -> let msg = maybe (IdeMode.SexpList [IdeMode.SymbolAtom "ok",
335+ IdeMode.SexpList []])
336+ (\fc -> IdeMode.SexpList [IdeMode.SymbolAtom "ok",
337+ IdeMode.toSExp fc])
338338 (idris_parsedSpan i)
339− in runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
339+ in runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
340340 Just x -> iPrintError $ "didn't load " ++ filename
341− ideslave h orig mods
342−runIdeSlaveCommand h id orig fn mods (IdeSlave.TypeOf name) =
341+ idemode h orig mods
342+runIdeModeCommand h id orig fn mods (IdeMode.TypeOf name) =
343343 case splitName name of
344344 Left err -> iPrintError err
345− Right n -> process "(ideslave)"
346− (Check (PRef (FC "(ideslave)" (0,0) (0,0)) n))
347−runIdeSlaveCommand h id orig fn mods (IdeSlave.DocsFor name) =
345+ Right n -> process "(idemode)"
346+ (Check (PRef (FC "(idemode)" (0,0) (0,0)) n))
347+runIdeModeCommand h id orig fn mods (IdeMode.DocsFor name) =
348348 case parseConst orig name of
349− Success c -> process "(ideslave)" (DocStr (Right c))
349+ Success c -> process "(idemode)" (DocStr (Right c))
350350 Failure _ ->
351351 case splitName name of
352352 Left err -> iPrintError err
353− Right n -> process "(ideslave)" (DocStr (Left n))
354−runIdeSlaveCommand h id orig fn mods (IdeSlave.CaseSplit line name) =
353+ Right n -> process "(idemode)" (DocStr (Left n))
354+runIdeModeCommand h id orig fn mods (IdeMode.CaseSplit line name) =
355355 process fn (CaseSplitAt False line (sUN name))
356−runIdeSlaveCommand h id orig fn mods (IdeSlave.AddClause line name) =
356+runIdeModeCommand h id orig fn mods (IdeMode.AddClause line name) =
357357 process fn (AddClauseFrom False line (sUN name))
358−runIdeSlaveCommand h id orig fn mods (IdeSlave.AddProofClause line name) =
358+runIdeModeCommand h id orig fn mods (IdeMode.AddProofClause line name) =
359359 process fn (AddProofClauseFrom False line (sUN name))
360−runIdeSlaveCommand h id orig fn mods (IdeSlave.AddMissing line name) =
360+runIdeModeCommand h id orig fn mods (IdeMode.AddMissing line name) =
361361 process fn (AddMissing False line (sUN name))
362−runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeWithBlock line name) =
362+runIdeModeCommand h id orig fn mods (IdeMode.MakeWithBlock line name) =
363363 process fn (MakeWith False line (sUN name))
364−runIdeSlaveCommand h id orig fn mods (IdeSlave.ProofSearch r line name hints depth) =
364+runIdeModeCommand h id orig fn mods (IdeMode.ProofSearch r line name hints depth) =
365365 doProofSearch fn False r line (sUN name) (map sUN hints) depth
366−runIdeSlaveCommand h id orig fn mods (IdeSlave.MakeLemma line name) =
366+runIdeModeCommand h id orig fn mods (IdeMode.MakeLemma line name) =
367367 case splitName name of
368368 Left err -> iPrintError err
369369 Right n -> process fn (MakeLemma False line n)
370−runIdeSlaveCommand h id orig fn mods (IdeSlave.Apropos a) =
370+runIdeModeCommand h id orig fn mods (IdeMode.Apropos a) =
371371 process fn (Apropos [] a)
372−runIdeSlaveCommand h id orig fn mods (IdeSlave.GetOpts) =
372+runIdeModeCommand h id orig fn mods (IdeMode.GetOpts) =
373373 do ist <- getIState
374374 let opts = idris_options ist
375375 let impshow = opt_showimp opts
376376 let errCtxt = opt_errContext opts
377− let options = (IdeSlave.SymbolAtom "ok",
378− [(IdeSlave.SymbolAtom "show-implicits", impshow),
379− (IdeSlave.SymbolAtom "error-context", errCtxt)])
380− runIO . hPutStrLn h $ IdeSlave.convSExp "return" options id
381−runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ShowImpl b) =
377+ let options = (IdeMode.SymbolAtom "ok",
378+ [(IdeMode.SymbolAtom "show-implicits", impshow),
379+ (IdeMode.SymbolAtom "error-context", errCtxt)])
380+ runIO . hPutStrLn h $ IdeMode.convSExp "return" options id
381+runIdeModeCommand h id orig fn mods (IdeMode.SetOpt IdeMode.ShowImpl b) =
382382 do setImpShow b
383− let msg = (IdeSlave.SymbolAtom "ok", b)
384− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
385−runIdeSlaveCommand h id orig fn mods (IdeSlave.SetOpt IdeSlave.ErrContext b) =
383+ let msg = (IdeMode.SymbolAtom "ok", b)
384+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
385+runIdeModeCommand h id orig fn mods (IdeMode.SetOpt IdeMode.ErrContext b) =
386386 do setErrContext b
387− let msg = (IdeSlave.SymbolAtom "ok", b)
388− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
389−runIdeSlaveCommand h id orig fn mods (IdeSlave.Metavariables cols) =
387+ let msg = (IdeMode.SymbolAtom "ok", b)
388+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
389+runIdeModeCommand h id orig fn mods (IdeMode.Metavariables cols) =
390390 do ist <- getIState
391391 let mvs = reverse $ map fst (idris_metavars ist) \\ primDefs
392392 let ppo = ppOptionIst ist
@@ -403,7 +403,7 @@ runIdeSlaveCommand h id orig fn mods (IdeSlave.Metavariables cols) =
403403 render ist bnd c pc))
404404 splitMvs
405405 runIO . hPutStrLn h $
406− IdeSlave.convSExp "return" (IdeSlave.SymbolAtom "ok", mvOutput) id
406+ IdeMode.convSExp "return" (IdeMode.SymbolAtom "ok", mvOutput) id
407407 where mapPair f g xs = zip (map (f . fst) xs) (map (g . snd) xs)
408408 mapSnd f xs = zip (map fst xs) (map (f . snd) xs)
409409
@@ -447,32 +447,32 @@ runIdeSlaveCommand h id orig fn mods (IdeSlave.Metavariables cols) =
447447 let (out, spans) = render ist bnd t pt in
448448 (show n , out, spans)
449449
450−runIdeSlaveCommand h id orig fn mods (IdeSlave.WhoCalls n) =
450+runIdeModeCommand h id orig fn mods (IdeMode.WhoCalls n) =
451451 case splitName n of
452452 Left err -> iPrintError err
453453 Right n -> do calls <- whoCalls n
454454 ist <- getIState
455− let msg = (IdeSlave.SymbolAtom "ok",
455+ let msg = (IdeMode.SymbolAtom "ok",
456456 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
457− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
457+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
458458 where pn ist = displaySpans .
459459 renderPretty 0.9 1000 .
460460 fmap (fancifyAnnots ist) .
461461 prettyName True True []
462−runIdeSlaveCommand h id orig fn mods (IdeSlave.CallsWho n) =
462+runIdeModeCommand h id orig fn mods (IdeMode.CallsWho n) =
463463 case splitName n of
464464 Left err -> iPrintError err
465465 Right n -> do calls <- callsWho n
466466 ist <- getIState
467− let msg = (IdeSlave.SymbolAtom "ok",
467+ let msg = (IdeMode.SymbolAtom "ok",
468468 map (\ (n,ns) -> (pn ist n, map (pn ist) ns)) calls)
469− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
469+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
470470 where pn ist = displaySpans .
471471 renderPretty 0.9 1000 .
472472 fmap (fancifyAnnots ist) .
473473 prettyName True True []
474474
475−runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNormalise bnd tm) =
475+runIdeModeCommand h id orig fn modes (IdeMode.TermNormalise bnd tm) =
476476 do ctxt <- getContext
477477 ist <- getIState
478478 let tm' = force (normaliseAll ctxt [] tm)
@@ -482,46 +482,54 @@ runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNormalise bnd tm) =
482482 []
483483 (idris_infixes ist)
484484 (delab ist tm'))
485− msg = (IdeSlave.SymbolAtom "ok",
485+ msg = (IdeMode.SymbolAtom "ok",
486486 displaySpans .
487487 renderPretty 0.9 80 .
488488 fmap (fancifyAnnots ist) $ ptm)
489− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
490−runIdeSlaveCommand h id orig fn modes (IdeSlave.TermShowImplicits bnd tm) =
491− ideSlaveForceTermImplicits h id bnd True tm
492−runIdeSlaveCommand h id orig fn modes (IdeSlave.TermNoImplicits bnd tm) =
493− ideSlaveForceTermImplicits h id bnd False tm
494−runIdeSlaveCommand h id orig fn mods (IdeSlave.PrintDef name) =
489+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
490+runIdeModeCommand h id orig fn modes (IdeMode.TermShowImplicits bnd tm) =
491+ ideModeForceTermImplicits h id bnd True tm
492+runIdeModeCommand h id orig fn modes (IdeMode.TermNoImplicits bnd tm) =
493+ ideModeForceTermImplicits h id bnd False tm
494+runIdeModeCommand h id orig fn mods (IdeMode.PrintDef name) =
495495 case splitName name of
496496 Left err -> iPrintError err
497− Right n -> process "(ideslave)" (PrintDef n)
498−runIdeSlaveCommand h id orig fn modes (IdeSlave.ErrString e) =
497+ Right n -> process "(idemode)" (PrintDef n)
498+runIdeModeCommand h id orig fn modes (IdeMode.ErrString e) =
499499 do ist <- getIState
500500 let out = displayS . renderPretty 1.0 60 $ pprintErr ist e
501− msg = (IdeSlave.SymbolAtom "ok", IdeSlave.StringAtom $ out "")
502− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
503−runIdeSlaveCommand h id orig fn modes (IdeSlave.ErrPPrint e) =
501+ msg = (IdeMode.SymbolAtom "ok", IdeMode.StringAtom $ out "")
502+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
503+runIdeModeCommand h id orig fn modes (IdeMode.ErrPPrint e) =
504504 do ist <- getIState
505505 let (out, spans) =
506506 displaySpans .
507507 renderPretty 0.9 80 .
508508 fmap (fancifyAnnots ist) $ pprintErr ist e
509− msg = (IdeSlave.SymbolAtom "ok", out, spans)
510− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
511−
512−-- | Show a term for IDESlave with the specified implicitness
513−ideSlaveForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
514−ideSlaveForceTermImplicits h id bnd impl tm =
509+ msg = (IdeMode.SymbolAtom "ok", out, spans)
510+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
511+runIdeModeCommand h id orig fn modes IdeMode.GetIdrisVersion =
512+ let idrisVersion = (versionBranch version,
513+ if not (null gitHash)
514+ then [gitHash]
515+ else [])
516+ msg = (IdeMode.SymbolAtom "ok", idrisVersion)
517+ in runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
518+
519+
520+-- | Show a term for IDEMode with the specified implicitness
521+ideModeForceTermImplicits :: Handle -> Integer -> [(Name, Bool)] -> Bool -> Term -> Idris ()
522+ideModeForceTermImplicits h id bnd impl tm =
515523 do ist <- getIState
516524 let expl = annotate (AnnTerm bnd tm)
517525 (pprintPTerm ((ppOptionIst ist) { ppopt_impl = impl })
518526 bnd [] (idris_infixes ist)
519527 (delab ist tm))
520− msg = (IdeSlave.SymbolAtom "ok",
528+ msg = (IdeMode.SymbolAtom "ok",
521529 displaySpans .
522530 renderPretty 0.9 80 .
523531 fmap (fancifyAnnots ist) $ expl)
524− runIO . hPutStrLn h $ IdeSlave.convSExp "return" msg id
532+ runIO . hPutStrLn h $ IdeMode.convSExp "return" msg id
525533
526534splitName :: String -> Either String Name
527535splitName s = case reverse $ splitOn "." s of
@@ -532,75 +540,76 @@ splitName s = case reverse $ splitOn "." s of
532540 unparen ('(':x:xs) | last xs == ')' = init (x:xs)
533541 unparen str = str
534542
535−ideslaveProcess :: FilePath -> Command -> Idris ()
536−ideslaveProcess fn Warranty = process fn Warranty
537−ideslaveProcess fn Help = process fn Help
538−ideslaveProcess fn (ChangeDirectory f) = do process fn (ChangeDirectory f)
539− iPrintResult "changed directory to"
540−ideslaveProcess fn (Eval t) = process fn (Eval t)
541−ideslaveProcess fn (NewDefn decls) = do process fn (NewDefn decls)
542− iPrintResult "defined"
543−ideslaveProcess fn (Undefine n) = process fn (Undefine n)
544−ideslaveProcess fn (ExecVal t) = process fn (ExecVal t)
545−ideslaveProcess fn (Check (PRef x n)) = process fn (Check (PRef x n))
546−ideslaveProcess fn (Check t) = process fn (Check t)
547−ideslaveProcess fn (DocStr n) = process fn (DocStr n)
548−ideslaveProcess fn Universes = process fn Universes
549−ideslaveProcess fn (Defn n) = do process fn (Defn n)
550− iPrintResult ""
551−ideslaveProcess fn (TotCheck n) = process fn (TotCheck n)
552−ideslaveProcess fn (DebugInfo n) = do process fn (DebugInfo n)
553− iPrintResult ""
554−ideslaveProcess fn (Search ps t) = process fn (Search ps t)
555−ideslaveProcess fn (Spec t) = process fn (Spec t)
556−-- RmProof and AddProof not supported!
557−ideslaveProcess fn (ShowProof n') = process fn (ShowProof n')
558−ideslaveProcess fn (HNF t) = process fn (HNF t)
559−--ideslaveProcess fn TTShell = process fn TTShell -- need some prove mode!
560−ideslaveProcess fn (TestInline t) = process fn (TestInline t)
561−
562−ideslaveProcess fn Execute = do process fn Execute
543+idemodeProcess :: FilePath -> Command -> Idris ()
544+idemodeProcess fn Warranty = process fn Warranty
545+idemodeProcess fn Help = process fn Help
546+idemodeProcess fn (ChangeDirectory f) = do process fn (ChangeDirectory f)
547+ iPrintResult "changed directory to"
548+idemodeProcess fn (ModImport f) = process fn (ModImport f)
549+idemodeProcess fn (Eval t) = process fn (Eval t)
550+idemodeProcess fn (NewDefn decls) = do process fn (NewDefn decls)
551+ iPrintResult "defined"
552+idemodeProcess fn (Undefine n) = process fn (Undefine n)
553+idemodeProcess fn (ExecVal t) = process fn (ExecVal t)
554+idemodeProcess fn (Check (PRef x n)) = process fn (Check (PRef x n))
555+idemodeProcess fn (Check t) = process fn (Check t)
556+idemodeProcess fn (DocStr n) = process fn (DocStr n)
557+idemodeProcess fn Universes = process fn Universes
558+idemodeProcess fn (Defn n) = do process fn (Defn n)
563559 iPrintResult ""
564−ideslaveProcess fn (Compile codegen f) = do process fn (Compile codegen f)
565− iPrintResult ""
566−ideslaveProcess fn (LogLvl i) = do process fn (LogLvl i)
560+idemodeProcess fn (TotCheck n) = process fn (TotCheck n)
561+idemodeProcess fn (DebugInfo n) = do process fn (DebugInfo n)
562+ iPrintResult ""
563+idemodeProcess fn (Search ps t) = process fn (Search ps t)
564+idemodeProcess fn (Spec t) = process fn (Spec t)
565+-- RmProof and AddProof not supported!
566+idemodeProcess fn (ShowProof n') = process fn (ShowProof n')
567+idemodeProcess fn (HNF t) = process fn (HNF t)
568+--idemodeProcess fn TTShell = process fn TTShell -- need some prove mode!
569+idemodeProcess fn (TestInline t) = process fn (TestInline t)
570+
571+idemodeProcess fn Execute = do process fn Execute
572+ iPrintResult ""
573+idemodeProcess fn (Compile codegen f) = do process fn (Compile codegen f)
574+ iPrintResult ""
575+idemodeProcess fn (LogLvl i) = do process fn (LogLvl i)
576+ iPrintResult ""
577+idemodeProcess fn (Pattelab t) = process fn (Pattelab t)
578+idemodeProcess fn (Missing n) = process fn (Missing n)
579+idemodeProcess fn (DynamicLink l) = do process fn (DynamicLink l)
580+ iPrintResult ""
581+idemodeProcess fn ListDynamic = do process fn ListDynamic
567582 iPrintResult ""
568−ideslaveProcess fn (Pattelab t) = process fn (Pattelab t)
569−ideslaveProcess fn (Missing n) = process fn (Missing n)
570−ideslaveProcess fn (DynamicLink l) = do process fn (DynamicLink l)
571− iPrintResult ""
572−ideslaveProcess fn ListDynamic = do process fn ListDynamic
573− iPrintResult ""
574−ideslaveProcess fn Metavars = process fn Metavars
575−ideslaveProcess fn (SetOpt ErrContext) = do process fn (SetOpt ErrContext)
576− iPrintResult ""
577−ideslaveProcess fn (UnsetOpt ErrContext) = do process fn (UnsetOpt ErrContext)
578− iPrintResult ""
579−ideslaveProcess fn (SetOpt ShowImpl) = do process fn (SetOpt ShowImpl)
580− iPrintResult ""
581−ideslaveProcess fn (UnsetOpt ShowImpl) = do process fn (UnsetOpt ShowImpl)
582− iPrintResult ""
583−ideslaveProcess fn (SetOpt ShowOrigErr) = do process fn (SetOpt ShowOrigErr)
583+idemodeProcess fn Metavars = process fn Metavars
584+idemodeProcess fn (SetOpt ErrContext) = do process fn (SetOpt ErrContext)
585+ iPrintResult ""
586+idemodeProcess fn (UnsetOpt ErrContext) = do process fn (UnsetOpt ErrContext)
584587 iPrintResult ""
585−ideslaveProcess fn (UnsetOpt ShowOrigErr) = do process fn (UnsetOpt ShowOrigErr)
586− iPrintResult ""
587−ideslaveProcess fn (SetOpt x) = process fn (SetOpt x)
588−ideslaveProcess fn (UnsetOpt x) = process fn (UnsetOpt x)
589−ideslaveProcess fn (CaseSplitAt False pos str) = process fn (CaseSplitAt False pos str)
590−ideslaveProcess fn (AddProofClauseFrom False pos str) = process fn (AddProofClauseFrom False pos str)
591−ideslaveProcess fn (AddClauseFrom False pos str) = process fn (AddClauseFrom False pos str)
592−ideslaveProcess fn (AddMissing False pos str) = process fn (AddMissing False pos str)
593−ideslaveProcess fn (MakeWith False pos str) = process fn (MakeWith False pos str)
594−ideslaveProcess fn (DoProofSearch False r pos str xs) = process fn (DoProofSearch False r pos str xs)
595−ideslaveProcess fn (SetConsoleWidth w) = do process fn (SetConsoleWidth w)
588+idemodeProcess fn (SetOpt ShowImpl) = do process fn (SetOpt ShowImpl)
589+ iPrintResult ""
590+idemodeProcess fn (UnsetOpt ShowImpl) = do process fn (UnsetOpt ShowImpl)
591+ iPrintResult ""
592+idemodeProcess fn (SetOpt ShowOrigErr) = do process fn (SetOpt ShowOrigErr)
596593 iPrintResult ""
597−ideslaveProcess fn (Apropos pkg a) = do process fn (Apropos pkg a)
598− iPrintResult ""
599−ideslaveProcess fn (WhoCalls n) = process fn (WhoCalls n)
600−ideslaveProcess fn (CallsWho n) = process fn (CallsWho n)
601−ideslaveProcess fn (PrintDef n) = process fn (PrintDef n)
602−ideslaveProcess fn (PPrint fmt n tm) = process fn (PPrint fmt n tm)
603−ideslaveProcess fn _ = iPrintError "command not recognized or not supported"
594+idemodeProcess fn (UnsetOpt ShowOrigErr) = do process fn (UnsetOpt ShowOrigErr)
595+ iPrintResult ""
596+idemodeProcess fn (SetOpt x) = process fn (SetOpt x)
597+idemodeProcess fn (UnsetOpt x) = process fn (UnsetOpt x)
598+idemodeProcess fn (CaseSplitAt False pos str) = process fn (CaseSplitAt False pos str)
599+idemodeProcess fn (AddProofClauseFrom False pos str) = process fn (AddProofClauseFrom False pos str)
600+idemodeProcess fn (AddClauseFrom False pos str) = process fn (AddClauseFrom False pos str)
601+idemodeProcess fn (AddMissing False pos str) = process fn (AddMissing False pos str)
602+idemodeProcess fn (MakeWith False pos str) = process fn (MakeWith False pos str)
603+idemodeProcess fn (DoProofSearch False r pos str xs) = process fn (DoProofSearch False r pos str xs)
604+idemodeProcess fn (SetConsoleWidth w) = do process fn (SetConsoleWidth w)
605+ iPrintResult ""
606+idemodeProcess fn (Apropos pkg a) = do process fn (Apropos pkg a)
607+ iPrintResult ""
608+idemodeProcess fn (WhoCalls n) = process fn (WhoCalls n)
609+idemodeProcess fn (CallsWho n) = process fn (CallsWho n)
610+idemodeProcess fn (PrintDef n) = process fn (PrintDef n)
611+idemodeProcess fn (PPrint fmt n tm) = process fn (PPrint fmt n tm)
612+idemodeProcess fn _ = iPrintError "command not recognized or not supported"
604613
605614
606615-- | The prompt consists of the currently loaded modules, or "Idris" if there are none
@@ -722,6 +731,10 @@ process fn Warranty = iPrintResult warranty
722731process fn (ChangeDirectory f)
723732 = do runIO $ setCurrentDirectory f
724733 return ()
734+process fn (ModImport f) = do fmod <- loadModule f
735+ case fmod of
736+ Just pr -> isetPrompt pr
737+ Nothing -> iPrintError $ "Can't find import " ++ f
725738process fn (Eval t)
726739 = withErrorReflection $ do logLvl 5 $ show t
727740 getIState >>= flip warnDisamb t
@@ -751,7 +764,7 @@ process fn (NewDefn decls) = do
751764 getName _ = Nothing
752765 -- getClauseName is partial and I am not sure it's used safely! -- trillioneyes
753766 getClauseName (PClause fc name whole with rhs whereBlock) = name
754− getClauseName (PWith fc name whole with rhs whereBlock) = name
767+ getClauseName (PWith fc name whole with rhs pn whereBlock) = name
755768 defineName :: [PDecl] -> Idris ()
756769 defineName (tyDecl@(PTy docs argdocs syn fc opts name ty) : decls) = do
757770 elabDecl EAll recinfo tyDecl
@@ -780,9 +793,9 @@ process fn (NewDefn decls) = do
780793 getClauses _ = []
781794 getRHS :: PClause -> PTerm
782795 getRHS (PClause fc name whole with rhs whereBlock) = rhs
783− getRHS (PWith fc name whole with rhs whereBlock) = rhs
796+ getRHS (PWith fc name whole with rhs pn whereBlock) = rhs
784797 getRHS (PClauseR fc with rhs whereBlock) = rhs
785− getRHS (PWithR fc with rhs whereBlock) = rhs
798+ getRHS (PWithR fc with rhs pn whereBlock) = rhs
786799 setReplDefined :: Maybe Name -> Idris ()
787800 setReplDefined Nothing = return ()
788801 setReplDefined (Just n) = do
@@ -808,7 +821,7 @@ process fn (Undefine names) = undefine names
808821 -- Keep track of which names you've removed so you can
809822 -- print them out to the user afterward
810823 undefine names = undefine' names []
811− undefine' [] list = do iRenderOutput $ printUndefinedNames list
824+ undefine' [] list = do iRenderResult $ printUndefinedNames list
812825 return ()
813826 undefine' (n:names) already = do
814827 allDefined <- idris_repl_defs `fmap` get
@@ -1091,13 +1104,15 @@ process fn Execute
10911104 (tmpn, tmph) <- runIO tempfile
10921105 runIO $ hClose tmph
10931106 t <- codegen
1107+ -- gcc adds .exe when it builds windows programs
1108+ progName <- return $ if isWindows then tmpn ++ ".exe" else tmpn
10941109 ir <- compile t tmpn m
10951110 runIO $ generate t (fst (head (idris_imported ist))) ir
10961111 case idris_outputmode ist of
1097− RawOutput h -> do runIO $ rawSystem tmpn []
1112+ RawOutput h -> do runIO $ rawSystem progName []
10981113 return ()
1099− IdeSlave n h -> runIO . hPutStrLn h $
1100− IdeSlave.convSExp "run-program" tmpn n)
1114+ IdeMode n h -> runIO . hPutStrLn h $
1115+ IdeMode.convSExp "run-program" tmpn n)
11011116 (\e -> getIState >>= iRenderError . flip pprintErr e)
11021117 where fc = fileFC "main"
11031118process fn (Compile codegen f)
@@ -1482,7 +1497,7 @@ idrisMain opts =
14821497 do let inputs = opt getFile opts
14831498 let quiet = Quiet `elem` opts
14841499 let nobanner = NoBanner `elem` opts
1485− let idesl = Ideslave `elem` opts || IdeslaveSocket `elem` opts
1500+ let idesl = Idemode `elem` opts || IdemodeSocket `elem` opts
14861501 let runrepl = not (NoREPL `elem` opts)
14871502 let verbose = runrepl || Verbose `elem` opts
14881503 let output = opt getOutput opts
@@ -1607,8 +1622,8 @@ idrisMain opts =
16071622-- clearOrigPats
16081623 startServer port orig mods
16091624 runInputT (replSettings (Just historyFile)) $ repl orig mods efile
1610− let idesock = IdeslaveSocket `elem` opts
1611− when (idesl) $ ideslaveStart idesock orig inputs
1625+ let idesock = IdemodeSocket `elem` opts
1626+ when (idesl) $ idemodeStart idesock orig inputs
16121627 ok <- noErrors
16131628 when (not ok) $ runIO (exitWith (ExitFailure 1))
16141629 where
@@ -1793,7 +1808,7 @@ getPort (_:xs) = getPort xs
17931808opt :: (Opt -> Maybe a) -> [Opt] -> [a]
17941809opt = mapMaybe
17951810
1796−ver = showVersion version ++ gitHash
1811+ver = showVersion version ++ "-" ++ gitHash
17971812
17981813defaultPort :: PortID
17991814defaultPort = PortNumber (fromIntegral 4294)
src/Idris/TypeSearch.hs+10−2
@@ -57,7 +57,7 @@ searchByType pkgs pterm = do
5757 case idris_outputmode i of
5858 RawOutput _ -> do mapM_ iRenderOutput docs
5959 iPrintResult ""
60− IdeSlave _ _ -> iRenderResult (vsep docs)
60+ IdeMode _ _ -> iRenderResult (vsep docs)
6161 putIState i -- don't actually make any changes
6262 where
6363 numLimit = 50
@@ -99,6 +99,14 @@ typeFromDef (def, _, _, _) = get def where
9999 get (CaseOp _ ty _ _ _ _) = Just ty
100100 get _ = Nothing
101101
102+-- Replace all occurences of `Lazy' s t` with `t` in a type
103+unLazy :: Type -> Type
104+unLazy typ = case typ of
105+ App (App (P _ lazy _) _) ty | lazy == sUN "Lazy'" -> unLazy ty
106+ Bind name binder ty -> Bind name (fmap unLazy binder) (unLazy ty)
107+ App t1 t2 -> App (unLazy t1) (unLazy t2)
108+ Proj ty i -> Proj (unLazy ty) i
109+ _ -> typ
102110
103111-- | reverse the edges for a directed acyclic graph
104112reverseDag :: Ord k => [((k, a), Set k)] -> [((k, a), Set k)]
@@ -362,7 +370,7 @@ matchTypesBulk istate maxScore type1 types = getAllResults startQueueOfQueues wh
362370 argNames1 = map fst dag1
363371 makeDag :: Type -> (ArgsDAG, Classes, Type)
364372 makeDag = first3 (zipWith (\i (ty, deps) -> (ty, (i, deps))) [0..] . reverseDag) .
365− computeDagP (isTypeClassArg classInfo) . vToP
373+ computeDagP (isTypeClassArg classInfo) . vToP . unLazy
366374 first3 f (a,b,c) = (f a, b, c)
367375
368376 -- update our state with the unification resolutions
src/Pkg/PParser.hs+2−2
@@ -16,7 +16,7 @@ import Idris.CmdOptions
1616import Control.Monad.State.Strict
1717import Control.Applicative
1818
19−import System.Info (os)
19+import Util.System
2020
2121
2222type PParser = StateT PkgDesc IdrisInnerParser
@@ -63,7 +63,7 @@ pClause :: PParser ()
6363pClause = do reserved "executable"; lchar '=';
6464 exec <- iName []
6565 st <- get
66− put (st { execout = Just (if os `elem` ["win32", "mingw32", "cygwin32"]
66+ put (st { execout = Just (if isWindows
6767 then ((show exec) ++ ".exe")
6868 else ( show exec )
6969 ) })
src/Util/System.hs+5−1
@@ -1,4 +1,4 @@
1−module Util.System(tempfile,withTempdir,rmFile,catchIO) where
1+module Util.System(tempfile,withTempdir,rmFile,catchIO, isWindows) where
22
33-- System helper functions.
44import Control.Monad (when)
@@ -9,6 +9,7 @@ import System.Directory (getTemporaryDirectory
99 )
1010import System.FilePath ((</>), normalise)
1111import System.IO
12+import System.Info
1213import System.IO.Error
1314import Control.Exception as CE
1415
@@ -18,6 +19,9 @@ catchIO = CE.catch
1819throwIO :: IOError -> IO a
1920throwIO = CE.throw
2021
22+isWindows :: Bool
23+isWindows = os `elem` ["win32", "mingw32", "cygwin32"]
24+
2125tempfile :: IO (FilePath, Handle)
2226tempfile = do dir <- getTemporaryDirectory
2327 openTempFile (normalise dir) "idris"
test/proof008/ClaimAndUnfocus.idrnew file+17
@@ -0,0 +1,17 @@
1+module ClaimAndUnfocus
2+
3+foo : Nat -> Nat
4+foo = ?foo_rhs
5+
6+---------- Proofs ----------
7+
8+ClaimAndUnfocus.foo_rhs = proof
9+ claim bar Nat -> Nat -> Nat
10+ unfocus
11+ intro x
12+ exact bar x x
13+ intro x,y
14+ refine plus
15+ refine x
16+ refine y
17+
test/proof008/expectednew file

No changes to the content.

test/proof008/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris --check $@ ClaimAndUnfocus.idr
3+rm -f *.ibc
test/quasiquote005/Quasiquote005.idrnew file+22
@@ -0,0 +1,22 @@
1+module Quasiquote005
2+
3+-- Test Raw quasiquotes
4+
5+test : the Language.Reflection.Raw `(plus (S Z) (S Z)) =
6+ RApp (RApp (Var (NS (UN "plus") ["Nat", "Prelude"]))
7+ (RApp (Var (NS (UN "S") ["Nat", "Prelude"]))
8+ (Var (NS (UN "Z") ["Nat", "Prelude"]))))
9+ (RApp (Var (NS (UN "S") ["Nat", "Prelude"]))
10+ (Var (NS (UN "Z") ["Nat", "Prelude"])))
11+test = Refl
12+
13+firstAddend : Raw -> Maybe Raw
14+firstAddend `(plus ~first ~_) = Just first
15+firstAddend _ = Nothing
16+
17+firstAddendOk : firstAddend (RApp (RApp (Var (NS (UN "plus") ["Nat", "Prelude"]))
18+ (RApp (Var (NS (UN "S") ["Nat", "Prelude"]))
19+ (Var (NS (UN "Z") ["Nat", "Prelude"]))))
20+ (Var (NS (UN "Z") ["Nat", "Prelude"]))) =
21+ the (Maybe Raw) (Just `(S Z))
22+firstAddendOk = Refl
test/quasiquote005/expectednew file

No changes to the content.

test/quasiquote005/runnew file+3
@@ -0,0 +1,3 @@
1+#!/usr/bin/env bash
2+idris $@ --check --nocolour Quasiquote005.idr
3+rm -f *.ibc
test/reg050/expected+2−1
@@ -23,6 +23,7 @@ When elaborating an application of function Prelude.Monad.>>=:
2323 ambiguous use of a non-associative operator,
2424 ambiguous use of a right-associative operator,
2525 end of input, function argument,
26− matching application expression
26+ matching application expression,
27+ single-line comment
2728doubleBang mmn = do pure !!mmn
2829 ^
test/reg058/expectednew file

No changes to the content.

test/reg058/implicits.idrnew file+14
@@ -0,0 +1,14 @@
1+%default total
2+
3+InterpBool : () -> Type
4+InterpBool () = {x : Type} -> x -> Nat
5+
6+class IdrisBug (u : ()) where
7+ idrisBug : InterpBool u
8+
9+instance IdrisBug () where
10+ idrisBug _ = Z
11+
12+f : Nat
13+f = idrisBug {u = ()} 'a'
14+
test/reg058/implicits2.idrnew file+19
@@ -0,0 +1,19 @@
1+import Data.Vect
2+
3+impTy : Bool -> Type
4+impTy True = Int
5+impTy False = {n : Nat} -> Vect n Int -> Vect n Int
6+
7+wibble : impTy False
8+wibble [] = []
9+wibble (x :: xs) = x * 2 :: wibble xs
10+
11+wobble : (b : Bool) -> impTy b
12+wobble True = 42
13+wobble False = wibble
14+
15+foo : Vect 4 Int
16+foo = wobble False [1,2,3,4]
17+
18+bar : Int
19+bar = wobble True
test/reg058/runnew file+5
@@ -0,0 +1,5 @@
1+#!/usr/bin/env bash
2+idris $@ implicits.idr --check
3+idris $@ implicits2.idr --check
4+
5+rm -f *.ibc
test/totality006/expected+1
@@ -1,2 +1,3 @@
11totality006.idr:8:1:Main.prf is not total as there are missing cases
22totality006a.idr:11:6:prf' (S _) (S _) Oh is a valid case
3+totality006b.idr:10:1:totality006b.blargh is not total as there are missing cases
test/totality006/run+1
@@ -1,4 +1,5 @@
11#!/usr/bin/env bash
22idris $@ totality006.idr --check
33idris $@ totality006a.idr --check
4+idris $@ totality006b.idr --check
45rm -f *.ibc
test/totality006/totality006b.idrnew file+14
@@ -0,0 +1,14 @@
1+module totality006b
2+
3+import Data.So
4+
5+
6+-- There are approaches to impossibility checking that break on this
7+-- case but not on test006.idr, due to the extra computation.
8+total
9+blargh : (xs, ys : List a) -> So (length xs > length ys) -> GT (length xs) (length ys)
10+blargh [] [] Oh impossible
11+blargh [] (y :: xs) so = absurd so
12+blargh (y :: xs) [] Oh = LTESucc LTEZero
13+
14+-- Missing: blargh (y :: xs) (z :: ys) x = ?blargh_rhs_3
test/unique001/expected+1−1
@@ -15,6 +15,6 @@ unique001a.idr:55:12:Can't convert
1515with
1616 Int -> String
1717unique001b.idr:16:7:Borrowed name xs must not be used on RHS
18−unique001c.idr:49:6:Unique name f is used more than once
18+unique001c.idr:46:6:Unique name f is used more than once
1919unique001d.idr:3:7:Borrowed name x must not be used on RHS
2020unique001e.idr:4:11:Constructor Main.:: has a UniqueType, but the data type does not
test/unique001/unique001c.idr+4−7
@@ -11,14 +11,11 @@ data UTree : UniqueType where
1111 ULeaf : UTree
1212 UNode : UTree -> Int -> UTree -> UTree
1313
14−data UPair : UniqueType -> UniqueType -> UniqueType where
15− MkUPair : {a,b:UniqueType} -> a -> b -> UPair a b
16−
1714dup : UTree -> UPair UTree UTree
18−dup ULeaf = MkUPair ULeaf ULeaf
19−dup (UNode l y r) = let MkUPair l1 l2 = dup l
20− MkUPair r1 r2 = dup r in
21− MkUPair (UNode l1 y r1) (UNode l2 y r2)
15+dup ULeaf = (ULeaf, ULeaf)
16+dup (UNode l y r) = let (l1, l2) = dup l
17+ (r1, r2) = dup r in
18+ (UNode l1 y r1, UNode l2 y r2)
2219
2320data Tree : Type where
2421 Leaf : Tree