2 | import Core.Binary.Prims
3 | import Core.Case.CaseTree
4 | import Core.CompileExpr
12 | import Libraries.Data.NameMap
13 | import Libraries.Data.NatSet
14 | import Libraries.Data.SparseMatrix
15 | import Libraries.Data.WithDefault
17 | import Libraries.Utils.Binary
18 | import Libraries.Utils.Scheme
24 | toBuf = toBuf . (YesInline ==)
25 | fromBuf = Core.map (\ b => ifThenElse b YesInline NotInline) $
fromBuf
29 | toBuf = toBuf . unsafeUnfoldNamespace
30 | fromBuf = Core.map unsafeFoldNamespace $
fromBuf
33 | TTC ModuleIdent where
34 | toBuf = toBuf . unsafeUnfoldModuleIdent
35 | fromBuf = Core.map unsafeFoldModuleIdent $
fromBuf
38 | TTC VirtualIdent where
39 | toBuf Interactive = tag 0
42 | 0 => pure Interactive
43 | _ => corrupt "VirtualIdent"
46 | TTC OriginDesc where
47 | toBuf (PhysicalIdrSrc ident) = do tag 0;
toBuf ident
48 | toBuf (PhysicalPkgSrc fname) = do tag 1;
toBuf fname
49 | toBuf (Virtual ident) = do tag 2;
toBuf ident
53 | 0 => [| PhysicalIdrSrc (fromBuf) |]
54 | 1 => [| PhysicalPkgSrc (fromBuf) |]
55 | 2 => [| Virtual (fromBuf) |]
56 | _ => corrupt "OriginDesc"
60 | toBuf (MkFC file startPos endPos)
61 | = do tag 0;
toBuf file;
toBuf startPos;
toBuf endPos
62 | toBuf (MkVirtualFC file startPos endPos)
63 | = do tag 2;
toBuf file;
toBuf startPos;
toBuf endPos
64 | toBuf EmptyFC = tag 1
68 | 0 => do f <- fromBuf;
69 | s <- fromBuf;
e <- fromBuf
72 | 2 => do f <- fromBuf;
73 | s <- fromBuf;
e <- fromBuf
74 | pure (MkVirtualFC f s e)
81 | toBuf (NS xs x) = do tag 0;
toBuf xs;
toBuf x
82 | toBuf (UN (Basic x)) = do tag 1;
toBuf x
83 | toBuf (MN x y) = do tag 2;
toBuf x;
toBuf y
84 | toBuf (PV x y) = do tag 3;
toBuf x;
toBuf y
85 | toBuf (DN x y) = do tag 4;
toBuf x;
toBuf y
86 | toBuf (UN (Field x)) = do tag 5;
toBuf x
87 | toBuf (Nested x y) = do tag 6;
toBuf x;
toBuf y
88 | toBuf (CaseBlock x y) = do tag 7;
toBuf x;
toBuf y
89 | toBuf (WithBlock x y) = do tag 8;
toBuf x;
toBuf y
91 | = throw (InternalError ("Can't write resolved name " ++ show x))
92 | toBuf (UN Underscore) = tag 9
96 | 0 => do xs <- fromBuf
99 | 1 => do x <- fromBuf
100 | pure (UN $
Basic x)
101 | 2 => do x <- fromBuf
104 | 3 => do x <- fromBuf
107 | 4 => do x <- fromBuf
110 | 5 => do x <- fromBuf
111 | pure (UN $
Field x)
112 | 6 => do x <- fromBuf
115 | 7 => do x <- fromBuf
117 | pure (CaseBlock x y)
118 | 8 => do x <- fromBuf
120 | pure (WithBlock x y)
121 | 9 => pure (UN Underscore)
122 | _ => corrupt "Name"
136 | _ => corrupt "RigCount"
139 | TTC t => TTC (PiInfo t) where
140 | toBuf Implicit = tag 0
141 | toBuf Explicit = tag 1
142 | toBuf AutoImplicit = tag 2
143 | toBuf (DefImplicit r) = do tag 3;
toBuf r
149 | 2 => pure AutoImplicit
150 | 3 => do t <- fromBuf;
pure (DefImplicit t)
151 | _ => corrupt "PiInfo"
154 | TTC t => TTC (PiBindData t) where
155 | toBuf (MkPiBindData info ty)
159 | = do info <- fromBuf
161 | pure (MkPiBindData info ty)
164 | {fs : _} -> (ev : All (TTC . KeyVal.type) fs) => TTC (Record fs) where
166 | toBuf {ev = _ :: _} ((lbl :- v) :: y)
168 | ;
toBuf v ;
toBuf y
173 | _ => corrupt "Record"
174 | fromBuf {fs = (str :-: v :: xs)} {ev = ba :: bs}
176 | 1 => do val <- fromBuf @{ba}
177 | tail <- the (Core (Record xs)) fromBuf
178 | pure ((str :- val) :: tail)
179 | _ => corrupt "Record"
182 | {fs : _} -> All (TTC . KeyVal.type) fs => TTC a => TTC (WithData fs a) where
183 | toBuf (MkWithData extra val)
189 | pure $
MkWithData nm val
194 | toBuf IntType = tag 0
195 | toBuf Int8Type = tag 1
196 | toBuf Int16Type = tag 2
197 | toBuf Int32Type = tag 3
198 | toBuf Int64Type = tag 4
199 | toBuf IntegerType = tag 5
200 | toBuf Bits8Type = tag 6
201 | toBuf Bits16Type = tag 7
202 | toBuf Bits32Type = tag 8
203 | toBuf Bits64Type = tag 9
204 | toBuf StringType = tag 10
205 | toBuf CharType = tag 11
206 | toBuf DoubleType = tag 12
207 | toBuf WorldType = tag 13
209 | fromBuf = case !getTag of
212 | 2 => pure Int16Type
213 | 3 => pure Int32Type
214 | 4 => pure Int64Type
215 | 5 => pure IntegerType
216 | 6 => pure Bits8Type
217 | 7 => pure Bits16Type
218 | 8 => pure Bits32Type
219 | 9 => pure Bits64Type
220 | 10 => pure StringType
221 | 11 => pure CharType
222 | 12 => pure DoubleType
223 | 13 => pure WorldType
224 | _ => corrupt "PrimType"
228 | toBuf (I x) = do tag 0;
toBuf x
229 | toBuf (I8 x) = do tag 1;
toBuf x
230 | toBuf (I16 x) = do tag 2;
toBuf x
231 | toBuf (I32 x) = do tag 3;
toBuf x
232 | toBuf (I64 x) = do tag 4;
toBuf x
233 | toBuf (BI x) = do tag 5;
toBuf x
234 | toBuf (B8 x) = do tag 6;
toBuf x
235 | toBuf (B16 x) = do tag 7;
toBuf x
236 | toBuf (B32 x) = do tag 8;
toBuf x
237 | toBuf (B64 x) = do tag 9;
toBuf x
238 | toBuf (Str x) = do tag 10;
toBuf x
239 | toBuf (Ch x) = do tag 11;
toBuf x
240 | toBuf (Db x) = do tag 12;
toBuf x
241 | toBuf (PrT x) = do tag 13;
toBuf x
242 | toBuf WorldVal = tag 14
246 | 0 => do x <- fromBuf;
pure (I x)
247 | 1 => do x <- fromBuf;
pure (I8 x)
248 | 2 => do x <- fromBuf;
pure (I16 x)
249 | 3 => do x <- fromBuf;
pure (I32 x)
250 | 4 => do x <- fromBuf;
pure (I64 x)
251 | 5 => do x <- fromBuf;
pure (BI x)
252 | 6 => do x <- fromBuf;
pure (B8 x)
253 | 7 => do x <- fromBuf;
pure (B16 x)
254 | 8 => do x <- fromBuf;
pure (B32 x)
255 | 9 => do x <- fromBuf;
pure (B64 x)
256 | 10 => do x <- fromBuf;
pure (Str x)
257 | 11 => do x <- fromBuf;
pure (Ch x)
258 | 12 => do x <- fromBuf;
pure (Db x)
259 | 13 => do x <- fromBuf;
pure (PrT x)
260 | 14 => pure WorldVal
261 | _ => corrupt "Constant"
264 | TTC LazyReason where
266 | toBuf LLazy = tag 1
267 | toBuf LUnknown = tag 2
274 | _ => corrupt "LazyReason"
278 | toBuf Bound = tag 0
280 | toBuf (DataCon t arity) = do tag 2;
toBuf t;
toBuf arity
281 | toBuf (TyCon arity) = do tag 3;
toBuf arity
287 | 2 => do x <- fromBuf;
y <- fromBuf;
pure (DataCon x y)
288 | 3 => do y <- fromBuf;
pure (TyCon y)
289 | _ => corrupt "NameType"
297 | mkPrf : (idx : Nat) -> IsVar n idx ns
298 | mkPrf {n} {ns} Z = believe_me (First {n} {ns = n :: ns})
299 | mkPrf {n} {ns} (S k) = believe_me (Later {m=n} (mkPrf {n} {ns} k))
303 | {vars : _} -> TTC (Binder (Term vars)) where
304 | toBuf (Lam _ c x ty) = do tag 0;
toBuf c;
toBuf x;
toBuf ty
305 | toBuf (Let _ c val ty) = do tag 1;
toBuf c;
toBuf val
306 | toBuf (Pi _ c x ty) = do tag 2;
toBuf c;
toBuf x;
toBuf ty
307 | toBuf (PVar _ c p ty) = do tag 3;
toBuf c;
toBuf p;
toBuf ty
308 | toBuf (PLet _ c val ty) = do tag 4;
toBuf c;
toBuf val
309 | toBuf (PVTy _ c ty) = do tag 5;
toBuf c
313 | 0 => do c <- fromBuf;
x <- fromBuf;
ty <- fromBuf;
pure (Lam emptyFC c x ty)
314 | 1 => do c <- fromBuf;
x <- fromBuf;
pure (Let emptyFC c x (Erased emptyFC Placeholder))
315 | 2 => do c <- fromBuf;
x <- fromBuf;
y <- fromBuf;
pure (Pi emptyFC c x y)
316 | 3 => do c <- fromBuf;
p <- fromBuf;
ty <- fromBuf;
pure (PVar emptyFC c p ty)
317 | 4 => do c <- fromBuf;
x <- fromBuf;
pure (PLet emptyFC c x (Erased emptyFC Placeholder))
318 | 5 => do c <- fromBuf;
pure (PVTy emptyFC c (Erased emptyFC Placeholder))
319 | _ => corrupt "Binder"
323 | toBuf UseLeft = tag 0
324 | toBuf UseRight = tag 1
330 | _ => corrupt "UseSide"
334 | {vars : _} -> TTC (Term vars) where
335 | toBuf (Local {name} fc c idx y)
337 | then do tag (13 + cast idx)
342 | toBuf (Ref fc nt name)
344 | toBuf nt;
toBuf name
345 | toBuf (Meta fc n i xs)
348 | toBuf (Bind fc x bnd scope)
351 | toBuf bnd;
toBuf scope
352 | toBuf (App fc fn arg)
353 | = do let (fn, args) = getFnArgs (App fc fn arg)
361 | toBuf (As fc s as tm)
363 | toBuf as;
toBuf s;
toBuf tm
364 | toBuf (TDelayed fc r tm)
367 | toBuf (TDelay fc r ty tm)
369 | toBuf r;
toBuf ty;
toBuf tm
370 | toBuf (TForce fc r tm)
373 | toBuf (PrimVal fc c)
376 | toBuf (Erased fc _)
379 | = do tag 11;
toBuf u
383 | 0 => do c <- fromBuf
385 | name <- maybe (corrupt "Term") pure
387 | pure (Local {name} emptyFC c idx (mkPrf idx))
388 | 1 => do nt <- fromBuf;
name <- fromBuf
389 | pure (Ref emptyFC nt name)
390 | 2 => do n <- fromBuf
392 | pure (Meta emptyFC n 0 xs)
393 | 3 => do x <- fromBuf
394 | bnd <- fromBuf;
scope <- fromBuf
395 | pure (Bind emptyFC x bnd scope)
396 | 4 => do fn <- fromBuf
398 | pure (App emptyFC fn arg)
399 | 5 => do as <- fromBuf;
s <- fromBuf;
tm <- fromBuf
400 | pure (As emptyFC s as tm)
401 | 6 => do lr <- fromBuf;
tm <- fromBuf
402 | pure (TDelayed emptyFC lr tm)
403 | 7 => do lr <- fromBuf;
404 | ty <- fromBuf;
tm <- fromBuf
405 | pure (TDelay emptyFC lr ty tm)
406 | 8 => do lr <- fromBuf;
tm <- fromBuf
407 | pure (TForce emptyFC lr tm)
408 | 9 => do c <- fromBuf
409 | pure (PrimVal emptyFC c)
410 | 10 => pure (Erased emptyFC Placeholder)
411 | 11 => do u <- fromBuf;
pure (TType emptyFC u)
412 | 12 => do fn <- fromBuf
414 | pure (apply emptyFC fn args)
415 | idxp => do c <- fromBuf
416 | let idx : Nat = fromInteger (cast (idxp - 13))
417 | let Just name = getAt idx vars
418 | | Nothing => corrupt "Term"
419 | pure (Local {name} emptyFC c idx (mkPrf idx))
424 | = do tag 0;
toBuf fc;
toBuf x;
toBuf y
425 | toBuf (PCon fc x t arity xs)
426 | = do tag 1;
toBuf fc;
toBuf x;
toBuf t;
toBuf arity;
toBuf xs
427 | toBuf (PTyCon fc x arity xs)
428 | = do tag 2;
toBuf fc;
toBuf x;
toBuf arity;
toBuf xs
429 | toBuf (PConst fc c)
430 | = do tag 3;
toBuf fc;
toBuf c
431 | toBuf (PArrow fc x s t)
432 | = do tag 4;
toBuf fc;
toBuf x;
toBuf s;
toBuf t
433 | toBuf (PDelay fc x t y)
434 | = do tag 5;
toBuf fc;
toBuf x;
toBuf t;
toBuf y
436 | = do tag 6;
toBuf fc;
toBuf x
437 | toBuf (PUnmatchable fc x)
438 | = do tag 7;
toBuf fc;
toBuf x
442 | 0 => do fc <- fromBuf;
x <- fromBuf;
445 | 1 => do fc <- fromBuf;
x <- fromBuf
446 | t <- fromBuf;
arity <- fromBuf
448 | pure (PCon fc x t arity xs)
449 | 2 => do fc <- fromBuf;
x <- fromBuf
452 | pure (PTyCon fc x arity xs)
453 | 3 => do fc <- fromBuf;
c <- fromBuf
455 | 4 => do fc <- fromBuf;
x <- fromBuf
456 | s <- fromBuf;
t <- fromBuf
457 | pure (PArrow fc x s t)
458 | 5 => do fc <- fromBuf;
x <- fromBuf;
459 | t <- fromBuf;
y <- fromBuf
460 | pure (PDelay fc x t y)
461 | 6 => do fc <- fromBuf;
x <- fromBuf
463 | 7 => do fc <- fromBuf;
x <- fromBuf
464 | pure (PUnmatchable fc x)
469 | {vars : _} -> TTC (CaseTree vars) where
470 | toBuf (Case {name} idx x scTy xs)
471 | = do tag 0;
toBuf name;
toBuf idx;
toBuf xs
473 | = do tag 1;
toBuf x
474 | toBuf (Unmatched msg)
475 | = do tag 2;
toBuf msg
476 | toBuf Impossible = tag 3
480 | 0 => do name <- fromBuf;
idx <- fromBuf
482 | pure (Case {name} idx (mkPrf idx) (Erased emptyFC Placeholder) xs)
483 | 1 => do x <- fromBuf
485 | 2 => do msg <- fromBuf
486 | pure (Unmatched msg)
487 | 3 => pure Impossible
488 | _ => corrupt "CaseTree"
491 | {vars : _} -> TTC (CaseAlt vars) where
492 | toBuf (ConCase x t args y)
493 | = do tag 0;
toBuf x;
toBuf t;
toBuf args;
toBuf y
494 | toBuf (DelayCase ty arg y)
495 | = do tag 1;
toBuf ty;
toBuf arg;
toBuf y
496 | toBuf (ConstCase x y)
497 | = do tag 2;
toBuf x;
toBuf y
498 | toBuf (DefaultCase x)
499 | = do tag 3;
toBuf x
503 | 0 => do x <- fromBuf;
t <- fromBuf
504 | args <- fromBuf;
y <- fromBuf
505 | pure (ConCase x t args y)
506 | 1 => do ty <- fromBuf;
arg <- fromBuf;
y <- fromBuf
507 | pure (DelayCase ty arg y)
508 | 2 => do x <- fromBuf;
y <- fromBuf
509 | pure (ConstCase x y)
510 | 3 => do x <- fromBuf
511 | pure (DefaultCase x)
512 | _ => corrupt "CaseAlt"
515 | {vars : _} -> TTC (Env Term vars) where
517 | toBuf ((::) bnd env)
518 | = do toBuf bnd;
toBuf env
521 | fromBuf {vars = []} = pure []
522 | fromBuf {vars = x :: xs}
523 | = do bnd <- fromBuf
528 | TTC Visibility where
529 | toBuf Private = tag 0
530 | toBuf Export = tag 1
531 | toBuf Public = tag 2
538 | _ => corrupt "Visibility"
541 | TTC PartialReason where
542 | toBuf NotStrictlyPositive = tag 0
543 | toBuf (BadCall xs) = do tag 1;
toBuf xs
544 | toBuf (BadPath xs n) = do tag 2;
toBuf xs;
toBuf n
545 | toBuf (RecPath xs) = do tag 3;
toBuf xs
549 | 0 => pure NotStrictlyPositive
550 | 1 => do xs <- fromBuf
552 | 2 => do xs <- fromBuf
554 | pure (BadPath xs n)
555 | 3 => do xs <- fromBuf
557 | _ => corrupt "PartialReason"
560 | TTC Terminating where
561 | toBuf Unchecked = tag 0
562 | toBuf IsTerminating = tag 1
563 | toBuf (NotTerminating p) = do tag 2;
toBuf p
567 | 0 => pure Unchecked
568 | 1 => pure IsTerminating
569 | 2 => do p <- fromBuf
570 | pure (NotTerminating p)
571 | _ => corrupt "Terminating"
575 | toBuf IsCovering = tag 0
576 | toBuf (MissingCases ms)
579 | toBuf (NonCoveringCall ns)
585 | 0 => pure IsCovering
586 | 1 => do ms <- fromBuf
587 | pure (MissingCases ms)
588 | 2 => do ns <- fromBuf
589 | pure (NonCoveringCall ns)
590 | _ => corrupt "Covering"
594 | toBuf (MkTotality term cov) = do toBuf term;
toBuf cov
597 | = do term <- fromBuf
599 | pure (MkTotality term cov)
602 | {n : _} -> TTC (PrimFn n) where
603 | toBuf (Add ty) = do tag 0;
toBuf ty
604 | toBuf (Sub ty) = do tag 1;
toBuf ty
605 | toBuf (Mul ty) = do tag 2;
toBuf ty
606 | toBuf (Div ty) = do tag 3;
toBuf ty
607 | toBuf (Mod ty) = do tag 4;
toBuf ty
608 | toBuf (Neg ty) = do tag 5;
toBuf ty
609 | toBuf (ShiftL ty) = do tag 35;
toBuf ty
610 | toBuf (ShiftR ty) = do tag 36;
toBuf ty
611 | toBuf (BAnd ty) = do tag 37;
toBuf ty
612 | toBuf (BOr ty) = do tag 38;
toBuf ty
613 | toBuf (BXOr ty) = do tag 39;
toBuf ty
614 | toBuf (LT ty) = do tag 6;
toBuf ty
615 | toBuf (LTE ty) = do tag 7;
toBuf ty
616 | toBuf (EQ ty) = do tag 8;
toBuf ty
617 | toBuf (GTE ty) = do tag 9;
toBuf ty
618 | toBuf (GT ty) = do tag 10;
toBuf ty
619 | toBuf StrLength = tag 11
620 | toBuf StrHead = tag 12
621 | toBuf StrTail = tag 13
622 | toBuf StrIndex = tag 14
623 | toBuf StrCons = tag 15
624 | toBuf StrAppend = tag 16
625 | toBuf StrReverse = tag 17
626 | toBuf StrSubstr = tag 18
628 | toBuf DoubleExp = tag 19
629 | toBuf DoubleLog = tag 20
630 | toBuf DoublePow = tag 21
631 | toBuf DoubleSin = tag 22
632 | toBuf DoubleCos = tag 23
633 | toBuf DoubleTan = tag 24
634 | toBuf DoubleASin = tag 25
635 | toBuf DoubleACos = tag 26
636 | toBuf DoubleATan = tag 27
637 | toBuf DoubleSqrt = tag 32
638 | toBuf DoubleFloor = tag 33
639 | toBuf DoubleCeiling = tag 34
641 | toBuf (Cast x y) = do tag 99;
toBuf x;
toBuf y
642 | toBuf BelieveMe = tag 100
643 | toBuf Crash = tag 101
648 | S (S Z) => fromBuf2
649 | S (S (S Z)) => fromBuf3
650 | _ => corrupt "PrimFn"
652 | fromBuf1 : Core (PrimFn 1)
655 | 5 => do ty <- fromBuf;
pure (Neg ty)
656 | 11 => pure StrLength
659 | 17 => pure StrReverse
660 | 19 => pure DoubleExp
661 | 20 => pure DoubleLog
662 | 22 => pure DoubleSin
663 | 23 => pure DoubleCos
664 | 24 => pure DoubleTan
665 | 25 => pure DoubleASin
666 | 26 => pure DoubleACos
667 | 27 => pure DoubleATan
668 | 32 => pure DoubleSqrt
669 | 33 => pure DoubleFloor
670 | 34 => pure DoubleCeiling
672 | 99 => do x <- fromBuf;
y <- fromBuf;
pure (Cast x y)
673 | _ => corrupt "PrimFn 1"
675 | fromBuf2 : Core (PrimFn 2)
678 | 0 => do ty <- fromBuf;
pure (Add ty)
679 | 1 => do ty <- fromBuf;
pure (Sub ty)
680 | 2 => do ty <- fromBuf;
pure (Mul ty)
681 | 3 => do ty <- fromBuf;
pure (Div ty)
682 | 4 => do ty <- fromBuf;
pure (Mod ty)
683 | 6 => do ty <- fromBuf;
pure (LT ty)
684 | 7 => do ty <- fromBuf;
pure (LTE ty)
685 | 8 => do ty <- fromBuf;
pure (EQ ty)
686 | 9 => do ty <- fromBuf;
pure (GTE ty)
687 | 10 => do ty <- fromBuf;
pure (GT ty)
688 | 14 => pure StrIndex
690 | 16 => pure StrAppend
691 | 21 => pure DoublePow
692 | 35 => do ty <- fromBuf;
pure (ShiftL ty)
693 | 36 => do ty <- fromBuf;
pure (ShiftR ty)
694 | 37 => do ty <- fromBuf;
pure (BAnd ty)
695 | 38 => do ty <- fromBuf;
pure (BOr ty)
696 | 39 => do ty <- fromBuf;
pure (BXOr ty)
698 | _ => corrupt "PrimFn 2"
700 | fromBuf3 : Core (PrimFn 3)
703 | 18 => pure StrSubstr
704 | 100 => pure BelieveMe
705 | _ => corrupt "PrimFn 3"
709 | toBuf DATACON = tag 0
710 | toBuf TYCON = tag 1
713 | toBuf (ENUM n) = do tag 4;
toBuf n
714 | toBuf NOTHING = tag 5
716 | toBuf RECORD = tag 7
719 | toBuf UNIT = tag 10
727 | 4 => do n <- fromBuf;
pure (ENUM n)
734 | _ => corrupt "ConInfo"
738 | {vars : _} -> TTC (CExp vars) where
739 | toBuf (CLocal fc {x} {idx} h) = do tag 0;
toBuf fc;
toBuf idx
740 | toBuf (CRef fc n) = do tag 1;
toBuf fc;
toBuf n
741 | toBuf (CLam fc x sc) = do tag 2;
toBuf fc;
toBuf x;
toBuf sc
742 | toBuf (CLet fc x inl val sc) = do tag 3;
toBuf fc;
toBuf x;
toBuf inl;
toBuf val;
toBuf sc
743 | toBuf (CApp fc f as) = assert_total $
do tag 4;
toBuf fc;
toBuf f;
toBuf as
744 | toBuf (CCon fc t n ci as) = assert_total $
do tag 5;
toBuf fc;
toBuf t;
toBuf n;
toBuf ci;
toBuf as
745 | toBuf (COp {arity} fc op as) = assert_total $
do tag 6;
toBuf fc;
toBuf arity;
toBuf op;
toBuf as
746 | toBuf (CExtPrim fc f as) = assert_total $
do tag 7;
toBuf fc;
toBuf f;
toBuf as
747 | toBuf (CForce fc lr x) = assert_total $
do tag 8;
toBuf fc;
toBuf lr;
toBuf x
748 | toBuf (CDelay fc lr x) = assert_total $
do tag 9;
toBuf fc;
toBuf lr;
toBuf x
749 | toBuf (CConCase fc sc alts def) = assert_total $
do tag 10;
toBuf fc;
toBuf sc;
toBuf alts;
toBuf def
750 | toBuf (CConstCase fc sc alts def) = assert_total $
do tag 11;
toBuf fc;
toBuf sc;
toBuf alts;
toBuf def
751 | toBuf (CPrimVal fc c) = do tag 12;
toBuf fc;
toBuf c
752 | toBuf (CErased fc) = do tag 13;
toBuf fc
753 | toBuf (CCrash fc msg) = do tag 14;
toBuf fc;
toBuf msg
756 | = assert_total $
case !getTag of
757 | 0 => do fc <- fromBuf
759 | let Just x = getAt idx vars
760 | | Nothing => corrupt "CExp"
761 | pure (CLocal {x} fc (mkPrf idx))
762 | 1 => do fc <- fromBuf
765 | 2 => do fc <- fromBuf
766 | x <- fromBuf;
sc <- fromBuf
767 | pure (CLam fc x sc)
768 | 3 => do fc <- fromBuf
769 | x <- fromBuf;
inl <- fromBuf;
val <- fromBuf;
sc <- fromBuf
770 | pure (CLet fc x inl val sc)
771 | 4 => do fc <- fromBuf
772 | f <- fromBuf;
as <- fromBuf
773 | pure (CApp fc f as)
774 | 5 => do fc <- fromBuf
775 | t <- fromBuf;
n <- fromBuf;
ci <- fromBuf;
as <- fromBuf
776 | pure (CCon fc t n ci as)
777 | 6 => do fc <- fromBuf
778 | arity <- fromBuf;
op <- fromBuf;
args <- fromBuf
779 | pure (COp {arity} fc op args)
780 | 7 => do fc <- fromBuf
781 | p <- fromBuf;
as <- fromBuf
782 | pure (CExtPrim fc p as)
783 | 8 => do fc <- fromBuf
786 | pure (CForce fc lr x)
787 | 9 => do fc <- fromBuf
790 | pure (CDelay fc lr x)
791 | 10 => do fc <- fromBuf
792 | sc <- fromBuf;
alts <- fromBuf;
def <- fromBuf
793 | pure (CConCase fc sc alts def)
794 | 11 => do fc <- fromBuf
795 | sc <- fromBuf;
alts <- fromBuf;
def <- fromBuf
796 | pure (CConstCase fc sc alts def)
797 | 12 => do fc <- fromBuf
799 | pure (CPrimVal fc c)
800 | 13 => do fc <- fromBuf
802 | 14 => do fc <- fromBuf
804 | pure (CCrash fc msg)
805 | _ => corrupt "CExp"
808 | {vars : _} -> TTC (CConAlt vars) where
809 | toBuf (MkConAlt n ci t as sc) = do toBuf n;
toBuf ci;
toBuf t;
toBuf as;
toBuf sc
812 | = do n <- fromBuf;
ci <- fromBuf;
t <- fromBuf
813 | as <- fromBuf;
sc <- fromBuf
814 | pure (MkConAlt n ci t as sc)
817 | {vars : _} -> TTC (CConstAlt vars) where
818 | toBuf (MkConstAlt c sc) = do toBuf c;
toBuf sc
821 | = do c <- fromBuf;
sc <- fromBuf
822 | pure (MkConstAlt c sc)
826 | toBuf CFUnit = tag 0
827 | toBuf CFInt = tag 1
828 | toBuf CFUnsigned8 = tag 2
829 | toBuf CFUnsigned16 = tag 3
830 | toBuf CFUnsigned32 = tag 4
831 | toBuf CFUnsigned64 = tag 5
832 | toBuf CFString = tag 6
833 | toBuf CFDouble = tag 7
834 | toBuf CFChar = tag 8
835 | toBuf CFPtr = tag 9
836 | toBuf CFWorld = tag 10
837 | toBuf (CFFun s t) = do tag 11;
toBuf s;
toBuf t
838 | toBuf (CFIORes t) = do tag 12;
toBuf t
839 | toBuf (CFStruct n a) = do tag 13;
toBuf n;
toBuf a
840 | toBuf (CFUser n a) = do tag 14;
toBuf n;
toBuf a
841 | toBuf CFGCPtr = tag 15
842 | toBuf CFBuffer = tag 16
843 | toBuf CFInt8 = tag 17
844 | toBuf CFInt16 = tag 18
845 | toBuf CFInt32 = tag 19
846 | toBuf CFInt64 = tag 20
847 | toBuf CFForeignObj = tag 21
848 | toBuf CFInteger = tag 22
854 | 2 => pure CFUnsigned8
855 | 3 => pure CFUnsigned16
856 | 4 => pure CFUnsigned32
857 | 5 => pure CFUnsigned64
863 | 11 => do s <- fromBuf;
t <- fromBuf;
pure (CFFun s t)
864 | 12 => do t <- fromBuf;
pure (CFIORes t)
865 | 13 => do n <- fromBuf;
a <- fromBuf;
pure (CFStruct n a)
866 | 14 => do n <- fromBuf;
a <- fromBuf;
pure (CFUser n a)
868 | 16 => pure CFBuffer
873 | 21 => pure CFForeignObj
874 | 22 => pure CFInteger
875 | _ => corrupt "CFType"
879 | toBuf (MkFun args cexpr) = do tag 0;
toBuf args;
toBuf cexpr
880 | toBuf (MkCon t arity pos) = do tag 1;
toBuf t;
toBuf arity;
toBuf pos
881 | toBuf (MkForeign cs args ret) = do tag 2;
toBuf cs;
toBuf args;
toBuf ret
882 | toBuf (MkError cexpr) = do tag 3;
toBuf cexpr
886 | 0 => do args <- fromBuf;
cexpr <- fromBuf
887 | pure (MkFun args cexpr)
888 | 1 => do t <- fromBuf;
arity <- fromBuf;
pos <- fromBuf
889 | pure (MkCon t arity pos)
890 | 2 => do cs <- fromBuf;
args <- fromBuf;
ret <- fromBuf
891 | pure (MkForeign cs args ret)
892 | 3 => do cexpr <- fromBuf
893 | pure (MkError cexpr)
894 | _ => corrupt "CDef"
899 | toBuf ChezSep = tag 1
900 | toBuf Racket = tag 2
901 | toBuf Gambit = tag 3
902 | toBuf (Other s) = do tag 4;
toBuf s
904 | toBuf Javascript = tag 6
906 | toBuf VMCodeInterp = tag 8
914 | 4 => do s <- fromBuf
917 | 6 => pure Javascript
919 | 8 => pure VMCodeInterp
923 | TTC PairNames where
925 | = do toBuf (pairType l)
932 | pure (MkPairNs ty d f)
935 | TTC RewriteNames where
937 | = do toBuf (equalType l)
938 | toBuf (rewriteName l)
942 | pure (MkRewriteNs ty l)
945 | TTC PrimNames where
947 | = do toBuf (fromIntegerName l)
948 | toBuf (fromStringName l)
949 | toBuf (fromCharName l)
950 | toBuf (fromDoubleName l)
951 | toBuf (fromTTImpName l)
952 | toBuf (fromNameName l)
953 | toBuf (fromDeclsName l)
962 | pure (MkPrimNs i str c d t n dl)
966 | toBuf NotHole = tag 0
967 | toBuf (SolvedHole n) = do tag 1;
toBuf n
972 | 1 => do n <- fromBuf;
pure (SolvedHole n)
973 | _ => corrupt "HoleInfo"
976 | TTC PMDefInfo where
978 | = do toBuf (holeInfo l)
979 | toBuf (alwaysReduce l)
980 | toBuf (externalDecl l)
985 | pure (MkPMDefInfo h r e)
988 | TTC TypeFlags where
990 | = do toBuf (uniqueAuto l)
995 | pure (MkTypeFlags u e)
1000 | toBuf (PMDef pi args ct rt pats)
1001 | = do tag 1;
toBuf pi;
toBuf args;
toBuf ct;
toBuf pats
1004 | toBuf (ForeignDef a cs)
1005 | = do tag 3;
toBuf a;
toBuf cs
1007 | = throw (InternalError "Trying to serialise a Builtin")
1008 | toBuf (DCon t arity nt) = do tag 4;
toBuf t;
toBuf arity;
toBuf nt
1009 | toBuf (TCon arity parampos detpos u ms datacons dets)
1010 | = do tag 5;
toBuf arity;
toBuf parampos
1011 | toBuf detpos;
toBuf u;
toBuf ms;
toBuf datacons
1014 | = do tag 6;
toBuf locs;
toBuf (implbind p)
1015 | toBuf (BySearch c depth def)
1016 | = do tag 7;
toBuf c;
toBuf depth;
toBuf def
1017 | toBuf (Guess guess envb constraints)
1018 | = do tag 8;
toBuf guess;
toBuf envb;
toBuf constraints
1021 | toBuf (UniverseLevel i) = do tag 11;
toBuf i
1030 | pure (PMDef pi args ct (Unmatched "") pats)
1036 | 4 => do t <- fromBuf;
a <- fromBuf;
nt <- fromBuf
1039 | ps <- fromBuf;
dets <- fromBuf;
1041 | ms <- fromBuf;
cs <- fromBuf
1043 | pure (TCon a ps dets u ms cs detags)
1046 | pure (Hole l (holeInit p))
1047 | 7 => do c <- fromBuf;
depth <- fromBuf
1049 | pure (BySearch c depth def)
1050 | 8 => do g <- fromBuf;
envb <- fromBuf;
cs <- fromBuf
1053 | 10 => pure Context.Delayed
1061 | toBuf CoveringOnly = tag 1
1062 | toBuf PartialOK = tag 2
1069 | _ => corrupt "TotalReq"
1073 | toBuf NoInline = tag 13
1074 | toBuf Deprecate = tag 15
1075 | toBuf Invertible = tag 3
1076 | toBuf Overloadable = tag 4
1078 | toBuf (SetTotal x) = do tag 6;
toBuf x
1079 | toBuf BlockedHint = tag 7
1081 | toBuf (PartialEval x) = tag 9
1082 | toBuf AllGuarded = tag 10
1083 | toBuf (ConType ci) = do tag 11;
toBuf ci
1084 | toBuf (Identity x) = do tag 12;
toBuf x
1092 | 6 => do x <- fromBuf;
pure (SetTotal x)
1095 | 9 => pure (PartialEval [])
1097 | 11 => do ci <- fromBuf;
pure (ConType ci)
1098 | 12 => do x <- fromBuf;
pure (Identity x)
1114 | _ => corrupt "SizeChange"
1118 | toBuf c = do toBuf (fnCall c);
toBuf (fnArgs c);
toBuf (fnLoc c)
1123 | pure (MkSCCall fn args loc)
1130 | do toBuf (compexpr gdef)
1131 | toBuf (map NameMap.toList (refersToRuntimeM gdef))
1136 | toBuf (multiplicity gdef)
1138 | toBuf (map NameMap.toList (refersToM gdef))
1139 | toBuf (definition gdef)
1140 | when (isUserName (fullname gdef)) $
1145 | toBuf (inferrable gdef)
1147 | toBuf (visibility gdef)
1149 | toBuf (isEscapeHatch gdef)
1151 | toBuf (invertible gdef)
1153 | toBuf (sizeChange gdef)
1158 | let refsR = map fromList refsRList
1163 | let refs = map fromList refsList
1168 | seargs <- fromBuf;
specargs <- fromBuf
1171 | vis <- fromBuf;
tot <- fromBuf;
hatch <- fromBuf
1176 | pure (MkGlobalDef loc name ty eargs seargs specargs iargs
1178 | tot hatch fl refs refsR inv c True def cdef Nothing sc Nothing)
1179 | else pure (MkGlobalDef loc name (Erased loc Placeholder) NatSet.empty NatSet.empty NatSet.empty NatSet.empty
1180 | mul Scope.empty (specified Public) unchecked False [] refs refsR
1181 | False False True def cdef Nothing [] Nothing)
1185 | toBuf (MkTransform {vars} n env lhs rhs)
1198 | pure (MkTransform {vars} n env lhs rhs)
1201 | Core.Context.decode gam idx update (Coded ns bin)
1202 | = do b <- newRef Bin bin
1206 | def' <- resolved gam (restoreNS ns def)
1207 | when update $
coreLift_ $
writeArray arr idx (Decoded def')
1209 | Core.Context.decode gam idx update (Decoded def) = pure def