This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
generated from dannypsnl-fork/racket-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
readback.rkt
48 lines (43 loc) · 1.62 KB
/
readback.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#lang typed/racket
(provide (all-defined-out))
(require "ast.rkt"
"eval.rkt")
(: readback-value : Value -> NormalExpr)
(define (readback-value v)
(match v
[(V:Lambda f) (NE:Lambda (readback-value (Inst f (genV))))]
[(V:Pair u v) (NE:Pair (readback-value u) (readback-value v))]
[(V:Constructor c v) (NE:Constructor c (readback-value v))]
[(V:Unit) (NE:Unit)]
[(V:One) (NE:One)]
[(V:Type level) (NE:Type level)]
[(V:Pi t g) (NE:Pi (readback-value t) (readback-value (Inst g (genV))))]
[(V:Sigma t g) (NE:Sigma (readback-value t) (readback-value (Inst g (genV))))]
[(V:Sum c) (NE:Sum (readback-casetree c))]
[(V:Neu l) (NE:Neu (readback-neu l))]
[else (error 'unreachable)]))
(: readback-neu : Neutral -> NormalNeutral)
(define (readback-neu n)
(match n))
(: readback-casetree : CaseTree -> NormalCaseTree)
(define (readback-casetree tele)
(for/hash : NormalCaseTree ([(name case) (in-hash tele)])
(values name
(readback-case case))))
(: readback-case : Case -> NormalCase)
(define (readback-case case)
(GCase (if (Value? (GCase-expr case))
(readback-value (GCase-expr case))
(GCase-expr case))
(readback-telescope (GCase-context case))))
(: readback-telescope : (GTelescope Value) -> (GTelescope NormalExpr))
(define (readback-telescope tele)
(match tele
[(Tele:Nil) (Tele:Nil)]
[(Tele:UpDec ctx decl)
(Tele:UpDec (readback-telescope ctx) decl)]
[(Tele:UpVar ctx pat val)
(Tele:UpVar (readback-telescope ctx)
pat
(readback-value (cast val Value)))]
[else (error 'unreachable)]))