@@ -267,108 +267,193 @@ data Tactic =
267%name Tactic tac, tac'
267%name Tactic tac, tac'
270−||| Things with a canonical representation in the TT datatype.
270+||| Things with a canonical representation as a reflected term.
272||| This type class is intended to be used during proof automation and the
272||| This type class is intended to be used during proof automation and the
273||| construction of custom tactics.
273||| construction of custom tactics.
275||| @ a the type to be quoted
275||| @ a the type to be quoted
276+||| @ t the type to quote it to (typically `TT` or `Raw`)
276−class Quotable a where
277+class Quotable a t where
277 ||| A representation of the type `a`.
278 ||| A representation of the type `a`.
279 ||| This is to enable quoting polymorphic datatypes
280 ||| This is to enable quoting polymorphic datatypes
280− quotedTy : TT
281+ quotedTy : t
282 ||| Quote a particular element of `a`.
283 ||| Quote a particular element of `a`.
284 ||| Each equation should look something like ```quote (Foo x y) = `(Foo ~(quote x) ~(quote y))```
285 ||| Each equation should look something like ```quote (Foo x y) = `(Foo ~(quote x) ~(quote y))```
285− quote : a -> TT
286+ quote : a -> t
287−instance Quotable Nat where
288+instance Quotable Nat TT where
288 quotedTy = `(Nat)
289 quotedTy = `(Nat)
290 quote Z = `(Z)
291 quote Z = `(Z)
291 quote (S k) = `(S ~(quote k))
292 quote (S k) = `(S ~(quote k))
293−instance Quotable Int where
294+instance Quotable Nat Raw where
298+ quote (S k) = `(S ~(quote k))
300+instance Quotable Int TT where
294 quotedTy = `(Int)
301 quotedTy = `(Int)
295 quote x = TConst (I x)
302 quote x = TConst (I x)
297−instance Quotable Float where
304+instance Quotable Int Raw where
306+ quote x = RConstant (I x)
308+instance Quotable Float TT where
298 quotedTy = `(Float)
309 quotedTy = `(Float)
299 quote x = TConst (Fl x)
310 quote x = TConst (Fl x)
301−instance Quotable Char where
312+instance Quotable Float Raw where
314+ quote x = RConstant (Fl x)
316+instance Quotable Char TT where
302 quotedTy = `(Char)
317 quotedTy = `(Char)
303 quote x = TConst (Ch x)
318 quote x = TConst (Ch x)
305−instance Quotable Bits8 where
320+instance Quotable Char Raw where
322+ quote x = RConstant (Ch x)
324+instance Quotable Bits8 TT where
306 quotedTy = `(Bits8)
325 quotedTy = `(Bits8)
307 quote x = TConst (B8 x)
326 quote x = TConst (B8 x)
309−instance Quotable Bits16 where
328+instance Quotable Bits8 Raw where
330+ quote x = RConstant (B8 x)
332+instance Quotable Bits16 TT where
310 quotedTy = `(Bits16)
333 quotedTy = `(Bits16)
311 quote x = TConst (B16 x)
334 quote x = TConst (B16 x)
313−instance Quotable Bits32 where
336+instance Quotable Bits16 Raw where
337+ quotedTy = `(Bits16)
338+ quote x = RConstant (B16 x)
340+instance Quotable Bits32 TT where
314 quotedTy = `(Bits32)
341 quotedTy = `(Bits32)
315 quote x = TConst (B32 x)
342 quote x = TConst (B32 x)
317−instance Quotable Bits64 where
344+instance Quotable Bits32 Raw where
345+ quotedTy = `(Bits32)
346+ quote x = RConstant (B32 x)
348+instance Quotable Bits64 TT where
318 quotedTy = `(Bits64)
349 quotedTy = `(Bits64)
319 quote x = TConst (B64 x)
350 quote x = TConst (B64 x)
321−instance Quotable Integer where
352+instance Quotable Bits64 Raw where
353+ quotedTy = `(Bits64)
354+ quote x = RConstant (B64 x)
356+instance Quotable Integer TT where
322 quotedTy = `(Integer)
357 quotedTy = `(Integer)
323 quote x = TConst (BI x)
358 quote x = TConst (BI x)
325−instance Quotable Bits8x16 where
360+instance Quotable Integer Raw where
361+ quotedTy = `(Integer)
362+ quote x = RConstant (BI x)
364+instance Quotable Bits8x16 TT where
326 quotedTy = `(Bits8x16)
365 quotedTy = `(Bits8x16)
327 quote x = TConst (B8V x)
366 quote x = TConst (B8V x)
329−instance Quotable Bits16x8 where
368+instance Quotable Bits8x16 Raw where
369+ quotedTy = `(Bits8x16)
370+ quote x = RConstant (B8V x)
372+instance Quotable Bits16x8 TT where
330 quotedTy = `(Bits16x8)
373 quotedTy = `(Bits16x8)
331 quote x = TConst (B16V x)
374 quote x = TConst (B16V x)
333−instance Quotable Bits32x4 where
376+instance Quotable Bits16x8 Raw where
377+ quotedTy = `(Bits16x8)
378+ quote x = RConstant (B16V x)
380+instance Quotable Bits32x4 TT where
334 quotedTy = `(Bits32x4)
381 quotedTy = `(Bits32x4)
335 quote x = TConst (B32V x)
382 quote x = TConst (B32V x)
337−instance Quotable Bits64x2 where
384+instance Quotable Bits32x4 Raw where
385+ quotedTy = `(Bits32x4)
386+ quote x = RConstant (B32V x)
388+instance Quotable Bits64x2 TT where
338 quotedTy = `(Bits64x2)
389 quotedTy = `(Bits64x2)
339 quote x = TConst (B64V x)
390 quote x = TConst (B64V x)
341−instance Quotable String where
392+instance Quotable Bits64x2 Raw where
393+ quotedTy = `(Bits64x2)
394+ quote x = RConstant (B64V x)
396+instance Quotable String TT where
342 quotedTy = `(String)
397 quotedTy = `(String)
343 quote x = TConst (Str x)
398 quote x = TConst (Str x)
345−instance Quotable NameType where
400+instance Quotable String Raw where
401+ quotedTy = `(String)
402+ quote x = RConstant (Str x)
404+instance Quotable NameType TT where
346 quotedTy = `(NameType)
405 quotedTy = `(NameType)
347 quote Bound = `(Bound)
406 quote Bound = `(Bound)
348 quote Ref = `(Ref)
407 quote Ref = `(Ref)
349 quote (DCon x y) = `(DCon ~(quote x) ~(quote y))
408 quote (DCon x y) = `(DCon ~(quote x) ~(quote y))
350 quote (TCon x y) = `(TCon ~(quote x) ~(quote y))
409 quote (TCon x y) = `(TCon ~(quote x) ~(quote y))
411+instance Quotable NameType Raw where
412+ quotedTy = `(NameType)
413+ quote Bound = `(Bound)
415+ quote (DCon x y) = `(DCon ~(quote {t=Raw} x) ~(quote {t=Raw} y))
416+ quote (TCon x y) = `(TCon ~(quote {t=Raw} x) ~(quote {t=Raw} y))
352−instance Quotable a => Quotable (List a) where
418+instance Quotable a TT => Quotable (List a) TT where
353 quotedTy = `(List ~(quotedTy {a=a}))
419 quotedTy = `(List ~(quotedTy {a=a}))
354 quote [] = `(List.Nil {a=~quotedTy})
420 quote [] = `(List.Nil {a=~quotedTy})
355 quote (x :: xs) = `(List.(::) {a=~quotedTy} ~(quote x) ~(quote xs))
421 quote (x :: xs) = `(List.(::) {a=~quotedTy} ~(quote x) ~(quote xs))
357−instance Quotable TTName where
423+instance Quotable a Raw => Quotable (List a) Raw where
424+ quotedTy = `(List ~(quotedTy {a=a}))
425+ quote [] = `(List.Nil {a=~quotedTy})
426+ quote (x :: xs) = `(List.(::) {a=~quotedTy} ~(quote x) ~(quote xs))
428+instance Quotable TTName TT where
358 quotedTy = `(TTName)
429 quotedTy = `(TTName)
359 quote (UN x) = `(UN ~(quote x))
430 quote (UN x) = `(UN ~(quote x))
360 quote (NS n xs) = `(NS ~(quote n) ~(quote xs))
431 quote (NS n xs) = `(NS ~(quote n) ~(quote xs))
361 quote (MN x y) = `(MN ~(quote x) ~(quote y))
432 quote (MN x y) = `(MN ~(quote x) ~(quote y))
362 quote NErased = `(NErased)
433 quote NErased = `(NErased)
364−instance Quotable NativeTy where
435+instance Quotable TTName Raw where
436+ quotedTy = `(TTName)
437+ quote (UN x) = `(UN ~(quote {t=Raw} x))
438+ quote (NS n xs) = `(NS ~(quote {t=Raw} n) ~(quote {t=Raw} xs))
439+ quote (MN x y) = `(MN ~(quote {t=Raw} x) ~(quote {t=Raw} y))
440+ quote NErased = `(NErased)
442+instance Quotable NativeTy TT where
443+ quotedTy = `(NativeTy)
444+ quote IT8 = `(Reflection.IT8)
445+ quote IT16 = `(Reflection.IT16)
446+ quote IT32 = `(Reflection.IT32)
447+ quote IT64 = `(Reflection.IT64)
449+instance Quotable NativeTy Raw where
365 quotedTy = `(NativeTy)
450 quotedTy = `(NativeTy)
366 quote IT8 = `(Reflection.IT8)
451 quote IT8 = `(Reflection.IT8)
367 quote IT16 = `(Reflection.IT16)
452 quote IT16 = `(Reflection.IT16)
368 quote IT32 = `(Reflection.IT32)
453 quote IT32 = `(Reflection.IT32)
369 quote IT64 = `(Reflection.IT64)
454 quote IT64 = `(Reflection.IT64)
371−instance Quotable Reflection.IntTy where
456+instance Quotable Reflection.IntTy TT where
372 quotedTy = `(Reflection.IntTy)
457 quotedTy = `(Reflection.IntTy)
373 quote (ITFixed x) = `(ITFixed ~(quote x))
458 quote (ITFixed x) = `(ITFixed ~(quote x))
374 quote ITNative = `(Reflection.ITNative)
459 quote ITNative = `(Reflection.ITNative)
@@ -376,12 +461,25 @@ instance Quotable Reflection.IntTy where
376 quote ITChar = `(Reflection.ITChar)
461 quote ITChar = `(Reflection.ITChar)
377 quote (ITVec x y) = `(ITVec ~(quote x) ~(quote y))
462 quote (ITVec x y) = `(ITVec ~(quote x) ~(quote y))
379−instance Quotable ArithTy where
464+instance Quotable Reflection.IntTy Raw where
465+ quotedTy = `(Reflection.IntTy)
466+ quote (ITFixed x) = `(ITFixed ~(quote {t=Raw} x))
467+ quote ITNative = `(Reflection.ITNative)
468+ quote ITBig = `(ITBig)
469+ quote ITChar = `(Reflection.ITChar)
470+ quote (ITVec x y) = `(ITVec ~(quote {t=Raw} x) ~(quote {t=Raw} y))
472+instance Quotable ArithTy TT where
380 quotedTy = `(ArithTy)
473 quotedTy = `(ArithTy)
381 quote (ATInt x) = `(ATInt ~(quote x))
474 quote (ATInt x) = `(ATInt ~(quote x))
382 quote ATFloat = `(ATFloat)
475 quote ATFloat = `(ATFloat)
384−instance Quotable Const where
477+instance Quotable ArithTy Raw where
478+ quotedTy = `(ArithTy)
479+ quote (ATInt x) = `(ATInt ~(quote {t=Raw} x))
480+ quote ATFloat = `(ATFloat)
482+instance Quotable Const TT where
385 quotedTy = `(Const)
483 quotedTy = `(Const)
386 quote (I x) = `(I ~(quote x))
484 quote (I x) = `(I ~(quote x))
387 quote (BI x) = `(BI ~(quote x))
485 quote (BI x) = `(BI ~(quote x))
@@ -406,19 +504,55 @@ instance Quotable Const where
406 quote WorldType = `(WorldType)
504 quote WorldType = `(WorldType)
407 quote TheWorld = `(TheWorld)
505 quote TheWorld = `(TheWorld)
409−instance Quotable TTUExp where
507+instance Quotable Const Raw where
509+ quote (I x) = `(I ~(quote {t=Raw} x))
510+ quote (BI x) = `(BI ~(quote {t=Raw} x))
511+ quote (Fl x) = `(Fl ~(quote {t=Raw} x))
512+ quote (Ch x) = `(Ch ~(quote {t=Raw} x))
513+ quote (Str x) = `(Str ~(quote {t=Raw} x))
514+ quote (B8 x) = `(B8 ~(quote {t=Raw} x))
515+ quote (B16 x) = `(B16 ~(quote {t=Raw} x))
516+ quote (B32 x) = `(B32 ~(quote {t=Raw} x))
517+ quote (B64 x) = `(B64 ~(quote {t=Raw} x))
518+ quote (B8V xs) = `(B8V ~(quote {t=Raw} xs))
519+ quote (B16V xs) = `(B16V ~(quote {t=Raw} xs))
520+ quote (B32V xs) = `(B32V ~(quote {t=Raw} xs))
521+ quote (B64V xs) = `(B64V ~(quote {t=Raw} xs))
522+ quote (AType x) = `(AType ~(quote {t=Raw} x))
523+ quote StrType = `(StrType)
524+ quote PtrType = `(PtrType)
525+ quote ManagedPtrType = `(ManagedPtrType)
526+ quote BufferType = `(BufferType)
527+ quote VoidType = `(VoidType)
528+ quote Forgot = `(Forgot)
529+ quote WorldType = `(WorldType)
530+ quote TheWorld = `(TheWorld)
532+instance Quotable TTUExp TT where
410 quotedTy = `(TTUExp)
533 quotedTy = `(TTUExp)
411 quote (UVar x) = `(UVar ~(quote x))
534 quote (UVar x) = `(UVar ~(quote x))
412 quote (UVal x) = `(UVal ~(quote x))
535 quote (UVal x) = `(UVal ~(quote x))
414−instance Quotable Universe where
537+instance Quotable TTUExp Raw where
538+ quotedTy = `(TTUExp)
539+ quote (UVar x) = `(UVar ~(quote {t=Raw} x))
540+ quote (UVal x) = `(UVal ~(quote {t=Raw} x))
542+instance Quotable Universe TT where
543+ quotedTy = `(Universe)
544+ quote Reflection.NullType = `(NullType)
545+ quote Reflection.UniqueType = `(UniqueType)
546+ quote Reflection.AllTypes = `(AllTypes)
548+instance Quotable Universe Raw where
415 quotedTy = `(Universe)
549 quotedTy = `(Universe)
416 quote Reflection.NullType = `(NullType)
550 quote Reflection.NullType = `(NullType)
417 quote Reflection.UniqueType = `(UniqueType)
551 quote Reflection.UniqueType = `(UniqueType)
418 quote Reflection.AllTypes = `(AllTypes)
552 quote Reflection.AllTypes = `(AllTypes)
421− instance Quotable TT where
555+ instance Quotable TT TT where
422 quotedTy = `(TT)
556 quotedTy = `(TT)
423 quote (P nt n tm) = `(P ~(quote nt) ~(quote n) ~(quote tm))
557 quote (P nt n tm) = `(P ~(quote nt) ~(quote n) ~(quote tm))
424 quote (V x) = `(V ~(quote x))
558 quote (V x) = `(V ~(quote x))
@@ -431,7 +565,7 @@ mutual
431 quote (TType uexp) = `(TType ~(quote uexp))
565 quote (TType uexp) = `(TType ~(quote uexp))
432 quote (UType u) = `(UType ~(quote u))
566 quote (UType u) = `(UType ~(quote u))
434− instance Quotable (Binder TT) where
568+ instance Quotable (Binder TT) TT where
435 quotedTy = `(Binder TT)
569 quotedTy = `(Binder TT)
436 quote (Lam x) = `(Lam {a=TT} ~(assert_total (quote x)))
570 quote (Lam x) = `(Lam {a=TT} ~(assert_total (quote x)))
437 quote (Pi x k) = `(Pi {a=TT} ~(assert_total (quote x))
571 quote (Pi x k) = `(Pi {a=TT} ~(assert_total (quote x))
@@ -448,7 +582,7 @@ mutual
448 quote (PVTy x) = `(PVTy {a=TT} ~(assert_total (quote x)))
582 quote (PVTy x) = `(PVTy {a=TT} ~(assert_total (quote x)))
451−instance Quotable ErrorReportPart where
585+instance Quotable ErrorReportPart TT where
452 quotedTy = `(ErrorReportPart)
586 quotedTy = `(ErrorReportPart)
453 quote (TextPart x) = `(TextPart ~(quote x))
587 quote (TextPart x) = `(TextPart ~(quote x))
454 quote (NamePart n) = `(NamePart ~(quote n))
588 quote (NamePart n) = `(NamePart ~(quote n))
@@ -476,15 +610,15 @@ mutual
476 quoteRawBinder (PVar x) = `(PVar {a=Raw} ~(quoteRaw x))
610 quoteRawBinder (PVar x) = `(PVar {a=Raw} ~(quoteRaw x))
477 quoteRawBinder (PVTy x) = `(PVTy {a=Raw} ~(quoteRaw x))
611 quoteRawBinder (PVTy x) = `(PVTy {a=Raw} ~(quoteRaw x))
479−instance Quotable Raw where
613+instance Quotable Raw TT where
480 quotedTy = `(Raw)
614 quotedTy = `(Raw)
481 quote = quoteRaw
615 quote = quoteRaw
483−instance Quotable (Binder Raw) where
617+instance Quotable (Binder Raw) TT where
484 quotedTy = `(Binder Raw)
618 quotedTy = `(Binder Raw)
485 quote = quoteRawBinder
619 quote = quoteRawBinder
487−instance Quotable Tactic where
621+instance Quotable Tactic TT where
488 quotedTy = `(Tactic)
622 quotedTy = `(Tactic)
489 quote (Try tac tac') = `(Try ~(quote tac) ~(quote tac'))
623 quote (Try tac tac') = `(Try ~(quote tac) ~(quote tac'))
490 quote (GoalType x tac) = `(GoalType ~(quote x) ~(quote tac))
624 quote (GoalType x tac) = `(GoalType ~(quote x) ~(quote tac))
@@ -514,3 +648,17 @@ instance Quotable Tactic where
514 quote (Fail xs) = `(Fail ~(quote xs))
648 quote (Fail xs) = `(Fail ~(quote xs))
515 quote SourceFC = `(SourceFC)
649 quote SourceFC = `(SourceFC)
652+instance Quotable SourceLocation TT where
653+ quotedTy = `(SourceLocation)
654+ quote (FileLoc fn (sl, sc) (el, ec)) =
655+ `(FileLoc ~(quote fn)
656+ (~(quote sl), ~(quote sc))
657+ (~(quote el), ~(quote ec)))
659+instance Quotable SourceLocation Raw where
660+ quotedTy = `(SourceLocation)
661+ quote (FileLoc fn (sl, sc) (el, ec)) =
662+ `(FileLoc ~(quote {t=Raw} fn)
663+ (~(quote {t=Raw} sl), ~(quote {t=Raw} sc))
664+ (~(quote {t=Raw} el), ~(quote {t=Raw} ec)))