0 | module Core.SchemeEval.ToScheme
3 | import Libraries.Utils.Scheme
6 | Scheme Namespace where
7 | toScheme x = toScheme (unsafeUnfoldNamespace x)
8 | fromScheme x = Just $
unsafeFoldNamespace !(fromScheme x)
11 | Scheme UserName where
12 | toScheme (Basic str) = toScheme str
13 | toScheme (Field str) = Vector 5 [toScheme str]
14 | toScheme Underscore = Vector 9 []
16 | fromScheme (Vector 5 [x]) = pure $
Field !(fromScheme x)
17 | fromScheme (Vector 9 []) = pure Underscore
18 | fromScheme (StringVal x) = pure (Basic x)
19 | fromScheme _ = Nothing
23 | toScheme (NS x y) = Vector 0 [toScheme x, toScheme y]
24 | toScheme (UN x) = toScheme x
25 | toScheme (MN x y) = Vector 2 [toScheme x, toScheme y]
26 | toScheme (PV x y) = Vector 3 [toScheme x, toScheme y]
27 | toScheme (DN x y) = Vector 4 [toScheme x, toScheme y]
28 | toScheme (Nested x y) = Vector 6 [toScheme x, toScheme y]
29 | toScheme (CaseBlock x y) = Vector 7 [toScheme x, toScheme y]
30 | toScheme (WithBlock x y) = Vector 8 [toScheme x, toScheme y]
31 | toScheme (Resolved x) = toScheme x
33 | fromScheme (Vector 0 [x, y])
34 | = pure $
NS !(fromScheme x) !(fromScheme y)
35 | fromScheme (Vector 2 [x, y])
36 | = pure $
MN !(fromScheme x) !(fromScheme y)
37 | fromScheme (Vector 3 [x, y])
38 | = pure $
PV !(fromScheme x) !(fromScheme y)
39 | fromScheme (Vector 4 [x, y])
40 | = pure $
DN !(fromScheme x) !(fromScheme y)
41 | fromScheme (Vector 5 [x, y])
42 | = pure $
UN (Field !(fromScheme x))
43 | fromScheme (Vector 6 [x, y])
44 | = pure $
Nested !(fromScheme x) !(fromScheme y)
45 | fromScheme (Vector 7 [x, y])
46 | = pure $
CaseBlock !(fromScheme x) !(fromScheme y)
47 | fromScheme (Vector 8 [x, y])
48 | = pure $
WithBlock !(fromScheme x) !(fromScheme y)
49 | fromScheme (Vector 9 [])
50 | = pure $
UN Underscore
51 | fromScheme (IntegerVal x)
52 | = pure $
Resolved (cast x)
53 | fromScheme (StringVal x)
54 | = pure $
UN (Basic x)
55 | fromScheme _ = Nothing
58 | Scheme ModuleIdent where
59 | toScheme ns = toScheme (miAsNamespace ns)
60 | fromScheme s = Just $
nsAsModuleIdent !(fromScheme s)
63 | Scheme OriginDesc where
64 | toScheme (PhysicalIdrSrc ident) = Vector 0 [toScheme ident]
65 | toScheme (PhysicalPkgSrc fname) = Vector 1 [toScheme fname]
66 | toScheme (Virtual ident) = Null
68 | fromScheme (Vector 0 [i]) = Just (PhysicalIdrSrc !(fromScheme i))
69 | fromScheme (Vector 1 [i]) = Just (PhysicalPkgSrc !(fromScheme i))
70 | fromScheme (Vector {}) = Nothing
71 | fromScheme _ = Just (Virtual Interactive)
75 | toScheme (MkFC d s e) = Vector 0 [toScheme d, toScheme s, toScheme e]
76 | toScheme (MkVirtualFC d s e) = Vector 1 [toScheme d, toScheme s, toScheme e]
77 | toScheme EmptyFC = Null
79 | fromScheme _ = Just EmptyFC
82 | Scheme LazyReason where
83 | toScheme LInf = IntegerVal 0
84 | toScheme LLazy = IntegerVal 1
85 | toScheme LUnknown = IntegerVal 2
87 | fromScheme (IntegerVal 0) = Just LInf
88 | fromScheme (IntegerVal 1) = Just LLazy
89 | fromScheme _ = Just LUnknown
92 | Scheme RigCount where
94 | = if isErased x then IntegerVal 0
95 | else if isLinear x then IntegerVal 1
98 | fromScheme (IntegerVal 0) = Just erased
99 | fromScheme (IntegerVal 1) = Just linear
100 | fromScheme _ = Just top
103 | toSchemePi : PiInfo (SchemeObj Write) -> SchemeObj Write
104 | toSchemePi Implicit = IntegerVal 0
105 | toSchemePi Explicit = IntegerVal 1
106 | toSchemePi AutoImplicit = IntegerVal 2
107 | toSchemePi (DefImplicit s) = Box s
110 | toSchemeWhy : WhyErased (SchemeObj Write) -> SchemeObj Write
111 | toSchemeWhy Impossible = IntegerVal 0
112 | toSchemeWhy Placeholder = IntegerVal 1
113 | toSchemeWhy (Dotted s) = Box s