Skip to content

Commit 4bd0ba6

Browse files
committed
Ponder compilation a bit
1 parent 8f5a720 commit 4bd0ba6

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

experiments/idris/src/Playground/OpenType/InductiveRecursive.idr

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,78 @@ namespace FormatOf
9090
simple_glyph = FormatOf.do
9191
flag <- flag
9292
pure (flag.repeat + 1)
93+
94+
95+
-- Thinking about compilation
96+
97+
namespace Rust
98+
99+
data RType : Type where
100+
Var : String -> RType
101+
U8 : RType
102+
U16 : RType
103+
U32 : RType
104+
U64 : RType
105+
I8 : RType
106+
I16 : RType
107+
I32 : RType
108+
I64 : RType
109+
Never : RType
110+
Tuple : List RType -> RType
111+
Vec : RType -> RType
112+
113+
data Item : Type where
114+
Struct : List (String, RType) -> Item
115+
Enum : List (String, RType) -> Item
116+
DecodeFn : () -> Item
117+
EncodeFn : () -> Item
118+
119+
record Module where
120+
constructor MkModule
121+
items : List (String, Item)
122+
123+
124+
namespace Compile
125+
126+
-- TODO: Cache compilations
127+
128+
compileRep : (f : Format) -> Maybe Rust.RType
129+
compileRep End = Just (Rust.Tuple [])
130+
compileRep Fail = Just (Rust.Never)
131+
compileRep (Ignore _ _) = Just (Rust.Tuple [])
132+
compileRep (Repeat _ f) =
133+
Just (Rust.Vec !(compileRep f)) -- TODO: Compile to a contract? Or maybe a
134+
-- fixed size array if the length is known
135+
compileRep (Pure x) =
136+
?todo_compileSingRep -- TODO: interpret an Idris type as a Rust type??
137+
--- hm... maybe need to restrict this?
138+
compileRep (Bind f1 f2) =
139+
Just (Tuple
140+
[ !(compileRep f1)
141+
, !(compileRep (f2 ?todo_compileBind_x)) -- TODO: how to bind the output?
142+
-- enum based on the values of `x : Rep f1`?
143+
-- depends on how `x` is used inside `f2`
144+
])
145+
compileRep (Custom f) =
146+
-- TODO: f.RustRep
147+
Nothing
148+
149+
150+
compileDecode : Format -> (Rust.Module -> Maybe Rust.Module)
151+
compileDecode End = ?todo_compileDecodeEnd
152+
compileDecode Fail = ?todo_compileDecodeFail
153+
compileDecode (Pure x) = ?todo_compileDecodePure
154+
compileDecode (Ignore f _) = ?todo_compileDecodeIgnore
155+
compileDecode (Repeat len f) = ?todo_compileDecodeRepeat
156+
compileDecode (Bind f1 f2) = ?todo_compileDecodeBind
157+
compileDecode (Custom f) = ?todo_compileDecodeCustom
158+
159+
160+
compileEncode : Format -> (Rust.Module -> Maybe Rust.Module)
161+
compileEncode End = ?todo_compileEncodeEnd
162+
compileEncode Fail = ?todo_compileEncodeFail
163+
compileEncode (Pure x) = ?todo_compileEncodePure
164+
compileEncode (Ignore f def) = ?todo_compileEncodeIgnore
165+
compileEncode (Repeat len f) = ?todo_compileEncodeRepeat
166+
compileEncode (Bind f1 f2) = ?todo_compileEncodeBind
167+
compileEncode (Custom f) = ?todo_compileEncodeCustom

0 commit comments

Comments
 (0)