@@ -12,13 +12,15 @@ module Unison.Runtime.Decompile
12
12
)
13
13
where
14
14
15
+ import Data.Map qualified as Map
15
16
import Data.Set (singleton )
16
17
import Unison.ABT (substs )
17
18
import Unison.Codebase.Runtime (Error )
18
19
import Unison.ConstructorReference (GConstructorReference (.. ))
19
20
import Unison.Prelude
20
21
import Unison.Reference (Reference , pattern Builtin )
21
22
import Unison.Referent (pattern Ref )
23
+ import Unison.Referent qualified as Referent
22
24
import Unison.Runtime.ANF (maskTags )
23
25
import Unison.Runtime.Array
24
26
( Array ,
@@ -38,7 +40,6 @@ import Unison.Runtime.Stack
38
40
USeq ,
39
41
UnboxedTypeTag (.. ),
40
42
Val (.. ),
41
- inflateMap ,
42
43
pattern DataC ,
43
44
pattern PApV ,
44
45
)
@@ -77,6 +78,7 @@ import Unison.Util.Bytes qualified as By
77
78
import Unison.Util.Pretty (indentN , lines , lit , shown , syntaxToColor , wrap )
78
79
import Unison.Util.Text qualified as Text
79
80
import Unison.Var (Var )
81
+ import Unison.Builtin.Decls qualified as DD
80
82
import Prelude hiding (lines )
81
83
82
84
con :: (Var v ) => Reference -> Word64 -> Term v ()
@@ -230,15 +232,29 @@ decompileForeign backref topTerms f
230
232
(decompileBytes . By. fromWord8s $ byteArrayToList a)
231
233
| Just s <- unwrapSeq f =
232
234
list' () <$> traverse (decompile backref topTerms) s
233
- | Just m <- maybeUnwrapForeign hmapRef f =
234
- decompile backref topTerms . BoxedVal $ inflateMap m
235
+ | Just m <- maybeUnwrapForeign hmapRef f = do
236
+ let decompileEntry k v = pair <$> decompile backref topTerms k <*> decompile backref topTerms v
237
+ kvs <- traverse (uncurry decompileEntry) (Map. toList m)
238
+ pure $ app () map_fromList (list () kvs)
235
239
decompileForeign _ _ (Wrap r _) =
236
240
err (BadForeign r) $ bug text
237
241
where
238
242
text
239
243
| Builtin name <- r = " <" <> name <> " >"
240
244
| otherwise = " <Foreign>"
241
245
246
+ map_fromList :: (Var v ) => Term v ()
247
+ map_fromList =
248
+ case Referent. fromText " #apmvhl40hl48q1s7383g5ev3sh7td8qo374t87bchpnu24sccmnvm13e2a1q0f2p1prm2uk9prfpg598dc9jo23iagact6gmi18vta8" of
249
+ Just r -> Term. fromReferent () r
250
+ Nothing -> error " Map_fromList"
251
+
252
+ pair :: (Var v ) => Term v () -> Term v () -> Term v ()
253
+ pair a b =
254
+ Term. apps' (Term. fromReferent () DD. pairCtorRef) [
255
+ a, Term. apps' (Term. fromReferent () DD. pairCtorRef) [b, Term. fromReferent () DD. unitCtorRef]
256
+ ]
257
+
242
258
decompileBytes :: (Var v ) => By. Bytes -> Term v ()
243
259
decompileBytes =
244
260
app () (builtin () $ fromString " Bytes.fromList" )
0 commit comments