Show
Ignore:
Timestamp:
08/01/08 13:56:05 (5 months ago)
Author:
audreyt
Message:

* Import Pugs 6.2.13.11 from Hackage into our source tree.
* Highlights:

  • Much faster startup time
  • Slightly faster compilation time (mostly due to refactored Pugs.AST.Internals)
  • Portable-to-Win32 readline thanks to Haskeline
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/AST/Internals/Instances.hs

    r20058 r21673  
    3535import DrIFT.Perl6Class 
    3636import Control.Monad 
     37import qualified Data.IntSet as IntSet 
    3738import qualified Data.ByteString as Buf 
    3839 
     
    4243import Pugs.AST.SIO 
    4344import Pugs.Types 
    44 import Pugs.Internals 
     45import Pugs.Internals hiding (get, put) 
    4546import Pugs.Embed.Perl5 
    4647import qualified Data.Set       as Set 
     
    4950 
    5051import qualified Data.HashTable    as H 
     52 
     53import Data.Binary 
     54import GHC.Exts (unsafeCoerce#) 
    5155 
    5256{-# NOINLINE _FakeEnv #-} 
     
    173177    fromYAML x = do 
    174178        buf <- fromYAML x 
    175         bufToID buf 
     179        return $ bufToID buf 
    176180  
    177181instance Perl5 ID where 
     
    908912 
    909913#endif 
     914 
     915instance Binary VThread 
     916    where put (MkThread x1 x2) = return () >> (put x1 >> put x2) 
     917          get = case 0 of 
     918                    0 -> ap (ap (return MkThread) get) get 
     919 
     920instance Binary VSubst 
     921    where put (MkSubst x1 x2) = putWord8 0 >> (put x1 >> put x2) 
     922          put (MkTrans x1 x2) = putWord8 1 >> (put x1 >> put x2) 
     923          get = getWord8 >>= (\tag_ -> case tag_ of 
     924                                           0 -> ap (ap (return MkSubst) get) get 
     925                                           1 -> ap (ap (return MkTrans) get) get) 
     926 
     927instance Binary VThunk 
     928    where put (MkThunk x1 x2) = return () >> (put x1 >> put x2) 
     929          get = case 0 of 
     930                    0 -> ap (ap (return MkThunk) get) get 
     931 
     932instance Binary VProcess 
     933    where put (MkProcess x1) = return () >> put x1 
     934          get = case 0 of 
     935                    0 -> ap (return MkProcess) get 
     936 
     937instance Binary VRule 
     938    where put (MkRulePCRE x1 
     939                          x2 
     940                          x3 
     941                          x4 
     942                          x5 
     943                          x6) = putWord8 0 >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> put x6))))) 
     944          put (MkRulePGE x1 
     945                         x2 
     946                         x3 
     947                         x4) = putWord8 1 >> (put x1 >> (put x2 >> (put x3 >> put x4))) 
     948          get = getWord8 >>= (\tag_ -> case tag_ of 
     949                                           0 -> ap (ap (ap (ap (ap (ap (return MkRulePCRE) get) get) get) get) get) get 
     950                                           1 -> ap (ap (ap (ap (return MkRulePGE) get) get) get) get) 
     951 
     952instance Binary Val 
     953    where put (VUndef) = putWord8 0 
     954          put (VBool x1) = putWord8 1 >> put x1 
     955          put (VInt x1) = putWord8 2 >> put x1 
     956          put (VRat x1) = putWord8 3 >> put x1 
     957          put (VNum x1) = putWord8 4 >> put x1 
     958          put (VComplex x1) = putWord8 5 >> put x1 
     959          put (VStr x1) = putWord8 6 >> put x1 
     960          put (VList x1) = putWord8 7 >> put x1 
     961          put (VType x1) = putWord8 8 >> put x1 
     962          put (VJunc x1) = putWord8 9 >> put x1 
     963          put (VError x1 x2) = putWord8 10 >> (put x1 >> put x2) 
     964          put (VControl x1) = putWord8 11 >> put x1 
     965          put (VRef x1) = putWord8 12 >> put x1 
     966          put (VCode x1) = putWord8 13 >> put x1 
     967          put (VBlock x1) = putWord8 14 >> put x1 
     968          put (VHandle x1) = putWord8 15 >> put x1 
     969          put (VSocket x1) = putWord8 16 >> put x1 
     970          put (VThread x1) = putWord8 17 >> put x1 
     971          put (VProcess x1) = putWord8 18 >> put x1 
     972          put (VRule x1) = putWord8 19 >> put x1 
     973          put (VSubst x1) = putWord8 20 >> put x1 
     974          put (VMatch x1) = putWord8 21 >> put x1 
     975          put (VObject x1) = putWord8 22 >> put x1 
     976          put (VOpaque x1) = putWord8 23 >> put x1 
     977          put (PerlSV x1) = putWord8 24 >> put x1 
     978          put (VV x1) = putWord8 25 >> put x1 
     979          get = getWord8 >>= (\tag_ -> case tag_ of 
     980                                           0 -> return VUndef 
     981                                           1 -> ap (return VBool) get 
     982                                           2 -> ap (return VInt) get 
     983                                           3 -> ap (return VRat) get 
     984                                           4 -> ap (return VNum) get 
     985                                           5 -> ap (return VComplex) get 
     986                                           6 -> ap (return VStr) get 
     987                                           7 -> ap (return VList) get 
     988                                           8 -> ap (return VType) get 
     989                                           9 -> ap (return VJunc) get 
     990                                           10 -> ap (ap (return VError) get) get 
     991                                           11 -> ap (return VControl) get 
     992                                           12 -> ap (return VRef) get 
     993                                           13 -> ap (return VCode) get 
     994                                           14 -> ap (return VBlock) get 
     995                                           15 -> ap (return VHandle) get 
     996                                           16 -> ap (return VSocket) get 
     997                                           17 -> ap (return VThread) get 
     998                                           18 -> ap (return VProcess) get 
     999                                           19 -> ap (return VRule) get 
     1000                                           20 -> ap (return VSubst) get 
     1001                                           21 -> ap (return VMatch) get 
     1002                                           22 -> ap (return VObject) get 
     1003                                           23 -> ap (return VOpaque) get 
     1004                                           24 -> ap (return PerlSV) get 
     1005                                           25 -> ap (return VV) get) 
     1006 
     1007instance Binary ControlLoop 
     1008    where put (LoopNext) = putWord8 0 
     1009          put (LoopRedo) = putWord8 1 
     1010          put (LoopLast) = putWord8 2 
     1011          get = getWord8 >>= (\tag_ -> case tag_ of 
     1012                                           0 -> return LoopNext 
     1013                                           1 -> return LoopRedo 
     1014                                           2 -> return LoopLast) 
     1015 
     1016instance Binary ControlWhen 
     1017    where put (WhenContinue) = putWord8 0 
     1018          put (WhenBreak) = putWord8 1 
     1019          get = getWord8 >>= (\tag_ -> case tag_ of 
     1020                                           0 -> return WhenContinue 
     1021                                           1 -> return WhenBreak) 
     1022 
     1023instance Binary SubType 
     1024    where put (SubMethod) = putWord8 0 
     1025          put (SubCoroutine) = putWord8 1 
     1026          put (SubMacro) = putWord8 2 
     1027          put (SubRoutine) = putWord8 3 
     1028          put (SubBlock) = putWord8 4 
     1029          put (SubPointy) = putWord8 5 
     1030          put (SubPrim) = putWord8 6 
     1031          get = getWord8 >>= (\tag_ -> case tag_ of 
     1032                                           0 -> return SubMethod 
     1033                                           1 -> return SubCoroutine 
     1034                                           2 -> return SubMacro 
     1035                                           3 -> return SubRoutine 
     1036                                           4 -> return SubBlock 
     1037                                           5 -> return SubPointy 
     1038                                           6 -> return SubPrim) 
     1039 
     1040instance Binary Param 
     1041    where put (MkOldParam x1 
     1042                          x2 
     1043                          x3 
     1044                          x4 
     1045                          x5 
     1046                          x6 
     1047                          x7 
     1048                          x8 
     1049                          x9) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> (put x6 >> (put x7 >> (put x8 >> put x9)))))))) 
     1050          get = case 0 of 
     1051                    0 -> ap (ap (ap (ap (ap (ap (ap (ap (ap (return MkOldParam) get) get) get) get) get) get) get) get) get 
     1052 
     1053instance Binary SubAssoc 
     1054    where put (ANil) = putWord8 0 
     1055          put (AIrrelevantToParsing) = putWord8 1 
     1056          put (A_left) = putWord8 2 
     1057          put (A_right) = putWord8 3 
     1058          put (A_non) = putWord8 4 
     1059          put (A_chain) = putWord8 5 
     1060          put (A_list) = putWord8 6 
     1061          get = getWord8 >>= (\tag_ -> case tag_ of 
     1062                                           0 -> return ANil 
     1063                                           1 -> return AIrrelevantToParsing 
     1064                                           2 -> return A_left 
     1065                                           3 -> return A_right 
     1066                                           4 -> return A_non 
     1067                                           5 -> return A_chain 
     1068                                           6 -> return A_list) 
     1069 
     1070instance Binary MPad 
     1071    where put (MkMPad x1 x2) = return () >> (put x1 >> put x2) 
     1072          get = case 0 of 
     1073                    0 -> ap (ap (return MkMPad) get) get 
     1074 
     1075instance Binary VCode 
     1076    where put (MkCode x1 
     1077                      x2 
     1078                      x3 
     1079                      x4 
     1080                      x5 
     1081                      x6 
     1082                      x7 
     1083                      x8 
     1084                      x9 
     1085                      x10 
     1086                      x11 
     1087                      x12 
     1088                      x13 
     1089                      x14 
     1090                      x15 
     1091                      x16) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> (put x6 >> (put x7 >> (put x8 >> (put x9 >> (put x10 >> (put x11 >> (put x12 >> (put x13 >> (put x14 >> (put x15 >> put x16))))))))))))))) 
     1092          get = case 0 of 
     1093                    0 -> ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (return MkCode) get) get) get) get) get) get) get) get) get) get) get) get) get) get) get) get 
     1094 
     1095instance Binary TraitBlocks 
     1096    where put (MkTraitBlocks x1 
     1097                             x2 
     1098                             x3 
     1099                             x4 
     1100                             x5 
     1101                             x6 
     1102                             x7 
     1103                             x8 
     1104                             x9 
     1105                             x10 
     1106                             x11) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> (put x6 >> (put x7 >> (put x8 >> (put x9 >> (put x10 >> put x11)))))))))) 
     1107          get = case 0 of 
     1108                    0 -> ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (return MkTraitBlocks) get) get) get) get) get) get) get) get) get) get) get 
     1109 
     1110instance Binary Ann 
     1111    where put (Cxt x1) = putWord8 0 >> put x1 
     1112          put (Pos x1) = putWord8 1 >> put x1 
     1113          put (Prag x1) = putWord8 2 >> put x1 
     1114          put (Decl x1) = putWord8 3 >> put x1 
     1115          put (Parens) = putWord8 4 
     1116          get = getWord8 >>= (\tag_ -> case tag_ of 
     1117                                           0 -> ap (return Cxt) get 
     1118                                           1 -> ap (return Pos) get 
     1119                                           2 -> ap (return Prag) get 
     1120                                           3 -> ap (return Decl) get 
     1121                                           4 -> return Parens) 
     1122 
     1123instance Binary Exp 
     1124    where put (Noop) = putWord8 0 
     1125          put (App x1 x2 x3) = putWord8 1 >> (put x1 >> (put x2 >> put x3)) 
     1126          put (Syn x1 x2) = putWord8 2 >> (put x1 >> put x2) 
     1127          put (Ann x1 x2) = putWord8 3 >> (put x1 >> put x2) 
     1128          put (Sym x1 
     1129                   x2 
     1130                   x3 
     1131                   x4 
     1132                   x5) = putWord8 4 >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> put x5)))) 
     1133          put (Stmts x1 x2) = putWord8 5 >> (put x1 >> put x2) 
     1134          put (Prim x1) = putWord8 6 >> put x1 
     1135          put (Val x1) = putWord8 7 >> put x1 
     1136          put (Var x1) = putWord8 8 >> put x1 
     1137          put (NonTerm x1) = putWord8 9 >> put x1 
     1138          get = getWord8 >>= (\tag_ -> case tag_ of 
     1139                                           0 -> return Noop 
     1140                                           1 -> ap (ap (ap (return App) get) get) get 
     1141                                           2 -> ap (ap (return Syn) get) get 
     1142                                           3 -> ap (ap (return Ann) get) get 
     1143                                           4 -> ap (ap (ap (ap (ap (return Sym) get) get) get) get) get 
     1144                                           5 -> ap (ap (return Stmts) get) get 
     1145                                           6 -> ap (return Prim) get 
     1146                                           7 -> ap (return Val) get 
     1147                                           8 -> ap (return Var) get 
     1148                                           9 -> ap (return NonTerm) get) 
     1149 
     1150{- 
     1151instance Binary LexPad 
     1152    where put (PRuntime x1) = putWord8 0 >> put x1 
     1153          put (PCompiling x1) = putWord8 1 >> put x1 
     1154          get = getWord8 >>= (\tag_ -> case tag_ of 
     1155                                           0 -> ap (return PRuntime) get 
     1156                                           1 -> ap (return PCompiling) get) 
     1157-} 
     1158 
     1159instance Binary LexPad where 
     1160    put _ = return () 
     1161    get = return (PRuntime emptyPad) 
     1162 
     1163instance Binary Env 
     1164    where put (MkEnv x1 
     1165                     x2 
     1166                     x3 
     1167                     x4 
     1168                     x5 
     1169                     x6 
     1170                     x7 
     1171                     x8 
     1172                     x9 
     1173                     x10 
     1174                     x11 
     1175                     x12 
     1176                     x13 
     1177                     x14 
     1178                     x15 
     1179                     x16 
     1180                     x17) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> (put x6 >> (put x7 >> (put x8 >> (put x9 >> (put x10 >> (put x11 >> (put x12 >> (put x13 >> (put x14 >> (put x15 >> (put x16 >> put x17)))))))))))))))) 
     1181          get = case 0 of 
     1182                    0 -> ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (ap (return MkEnv) get) get) get) get) get) get) get) get) get) get) get) get) get) get) get) get) get 
     1183 
     1184instance Binary Frame 
     1185    where put (FrameLoop) = putWord8 0 
     1186          put (FrameWhen) = putWord8 1 
     1187          put (FrameGather) = putWord8 2 
     1188          put (FrameRoutine) = putWord8 3 
     1189          get = getWord8 >>= (\tag_ -> case tag_ of 
     1190                                           0 -> return FrameLoop 
     1191                                           1 -> return FrameWhen 
     1192                                           2 -> return FrameGather 
     1193                                           3 -> return FrameRoutine) 
     1194 
     1195instance Binary InitDat 
     1196    where put (MkInitDat x1) = return () >> put x1 
     1197          get = case 0 of 
     1198                    0 -> ap (return MkInitDat) get 
     1199 
     1200instance Binary PadEntry 
     1201    where put (PELexical x1 
     1202                         x2 
     1203                         x3 
     1204                         x4) = putWord8 0 >> (put x1 >> (put x2 >> (put x3 >> put x4))) 
     1205          put (PEStatic x1 
     1206                        x2 
     1207                        x3 
     1208                        x4) = putWord8 1 >> (put x1 >> (put x2 >> (put x3 >> put x4))) 
     1209          put (PEConstant x1 
     1210                          x2 
     1211                          x3) = putWord8 2 >> (put x1 >> (put x2 >> put x3)) 
     1212          get = getWord8 >>= (\tag_ -> case tag_ of 
     1213                                           0 -> ap (ap (ap (ap (return PELexical) get) get) get) get 
     1214                                           1 -> ap (ap (ap (ap (return PEStatic) get) get) get) get 
     1215                                           2 -> ap (ap (ap (return PEConstant) get) get) get) 
     1216 
     1217instance Binary Type 
     1218    where put (MkType x1) = putWord8 0 >> put x1 
     1219          put (TypeOr x1 x2) = putWord8 1 >> (put x1 >> put x2) 
     1220          put (TypeAnd x1 x2) = putWord8 2 >> (put x1 >> put x2) 
     1221          get = getWord8 >>= (\tag_ -> case tag_ of 
     1222                                           0 -> ap (return MkType) get 
     1223                                           1 -> ap (ap (return TypeOr) get) get 
     1224                                           2 -> ap (ap (return TypeAnd) get) get) 
     1225 
     1226instance Binary IHashEnv 
     1227    where put (MkHashEnv) = return () 
     1228          get = case 0 of 
     1229                    0 -> return MkHashEnv 
     1230 
     1231instance Binary IScalarCwd 
     1232    where put (MkScalarCwd) = return () 
     1233          get = case 0 of 
     1234                    0 -> return MkScalarCwd 
     1235 
     1236instance Binary ObjectId 
     1237    where put (MkObjectId x1) = return () >> put x1 
     1238          get = case 0 of 
     1239                    0 -> ap (return MkObjectId) get 
     1240 
     1241instance Binary VObject 
     1242    where put (MkObject x1 
     1243                        x2 
     1244                        x3 
     1245                        x4) = return () >> (put x1 >> (put x2 >> (put x3 >> put x4))) 
     1246          get = case 0 of 
     1247                    0 -> ap (ap (ap (ap (return MkObject) get) get) get) get 
     1248 
     1249instance Binary VMatch 
     1250    where put (MkMatch x1 
     1251                       x2 
     1252                       x3 
     1253                       x4 
     1254                       x5 
     1255                       x6) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> (put x5 >> put x6))))) 
     1256          get = case 0 of 
     1257                    0 -> ap (ap (ap (ap (ap (ap (return MkMatch) get) get) get) get) get) get 
     1258 
     1259instance Binary CompUnit 
     1260    where put (MkCompUnit x1 
     1261                          x2 
     1262                          x3 
     1263                          x4) = return () >> (put x1 >> (put x2 >> (put x3 >> put x4))) 
     1264          get = case 0 of 
     1265                    0 -> ap (ap (ap (ap (return MkCompUnit) get) get) get) get 
     1266 
     1267instance Binary IArray 
     1268    where put (MkIArray x1) = return () >> put x1 
     1269          get = case 0 of 
     1270                    0 -> ap (return MkIArray) get 
     1271 
     1272instance Binary VMultiCode 
     1273    where put (MkMultiCode x1 
     1274                           x2 
     1275                           x3 
     1276                           x4 
     1277                           x5) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> put x5)))) 
     1278          get = case 0 of 
     1279                    0 -> ap (ap (ap (ap (ap (return MkMultiCode) get) get) get) get) get 
     1280 
     1281instance Binary VJunc 
     1282    where put (MkJunc x1 
     1283                      x2 
     1284                      x3) = return () >> (put x1 >> (put x2 >> put x3)) 
     1285          get = case 0 of 
     1286                    0 -> ap (ap (ap (return MkJunc) get) get) get 
     1287 
     1288instance Binary a => Binary (IORef a) where 
     1289    put x = put (unsafePerformIO . readIORef $ x) 
     1290    get = fmap (unsafePerformIO . newIORef) get 
     1291 
     1292instance Binary a => Binary (TVar a) where 
     1293    put x = put (unsafePerformIO . atomically . readTVar $ x) 
     1294    get = fmap (unsafePerformIO . newTVarIO) get 
     1295 
     1296instance Binary a => Binary (TMVar a) where 
     1297    put x = put (unsafePerformIO . atomically . readTMVar $ x) 
     1298    get = fmap (unsafePerformIO . newTMVarIO) get 
     1299 
     1300instance Binary (Eval Val) where 
     1301    put = put . unsafePerformIO . fakeEval 
     1302    get = do 
     1303        val <- get 
     1304        return (return val) 
     1305 
     1306instance Binary ThreadId 
     1307instance Binary ClassTree 
     1308instance Binary Dynamic 
     1309instance Binary ProcessHandle 
     1310instance Binary Regex 
     1311instance Binary Unique 
     1312instance Binary VComplex 
     1313instance Binary VHandle 
     1314instance Binary VControl 
     1315instance Binary VOpaque 
     1316instance Binary VSocket 
     1317instance Binary PerlSV 
     1318 
     1319instance Binary Pos 
     1320    where put (MkPos x1 
     1321                     x2 
     1322                     x3 
     1323                     x4 
     1324                     x5) = return () >> (put x1 >> (put x2 >> (put x3 >> (put x4 >> put x5)))) 
     1325          get = case 0 of 
     1326                    0 -> ap (ap (ap (ap (ap (return MkPos) get) get) get) get) get 
     1327 
     1328instance Binary Scope 
     1329    where put (SState) = putWord8 0 
     1330          put (SConstant) = putWord8 1 
     1331          put (SHas) = putWord8 2 
     1332          put (SMy) = putWord8 3 
     1333          put (SOur) = putWord8 4 
     1334          get = getWord8 >>= (\tag_ -> case tag_ of 
     1335                                           0 -> return SState 
     1336                                           1 -> return SConstant 
     1337                                           2 -> return SHas 
     1338                                           3 -> return SMy 
     1339                                           4 -> return SOur) 
     1340 
     1341instance Binary Cxt 
     1342    where put (CxtVoid) = putWord8 0 
     1343          put (CxtItem x1) = putWord8 1 >> put x1 
     1344          put (CxtSlurpy x1) = putWord8 2 >> put x1 
     1345          get = getWord8 >>= (\tag_ -> case tag_ of 
     1346                                           0 -> return CxtVoid 
     1347                                           1 -> ap (return CxtItem) get 
     1348                                           2 -> ap (return CxtSlurpy) get) 
     1349 
     1350instance Binary Pkg where 
     1351    put = put . (cast :: Pkg -> ByteString) 
     1352    get = fmap (cast :: ByteString -> Pkg) get 
     1353 
     1354instance Binary Var where 
     1355    put = put . (cast :: Var -> ByteString) 
     1356    get = fmap (cast :: ByteString -> Var) get 
     1357 
     1358 
     1359instance Binary Pragma 
     1360    where put (MkPrag x1 
     1361                     x2) = return () >> (put x1 >> put x2) 
     1362          get = case 0 of 
     1363                    0 -> ap (ap (return MkPrag) get) get 
     1364 
     1365instance Binary IHash where 
     1366     put x = do 
     1367        let kvs = unsafePerformIO (H.toList x) 
     1368        length kvs `seq` put (kvs :: [(VStr, IVar VScalar)]) 
     1369     get = do 
     1370        (ins :: [(VStr, IVar VScalar)]) <- get 
     1371        length ins `seq` return (unsafePerformIO $ H.fromList H.hashString ins) 
     1372 
     1373instance Binary JuncType 
     1374    where put (JAny) = putWord8 0 
     1375          put (JAll) = putWord8 1 
     1376          put (JNone) = putWord8 2 
     1377          put (JOne) = putWord8 3 
     1378          get = getWord8 >>= (\tag_ -> case tag_ of 
     1379                                           0 -> return JAny 
     1380                                           1 -> return JAll 
     1381                                           2 -> return JNone 
     1382                                           3 -> return JOne) 
     1383 
     1384instance Binary Val.Val 
     1385 
     1386instance Typeable a => Binary (IVar a) where 
     1387    put = put . MkRef 
     1388    get = do 
     1389        MkRef iv <- get 
     1390        return (unsafeCoerce# iv) 
     1391 
     1392instance Binary ([Val] -> Eval Val) where 
     1393    put _ = put () 
     1394    get = return (const $ return VUndef) 
     1395 
     1396instance Binary (Exp -> Eval Val) where 
     1397    put _ = put () 
     1398    get = return (const $ return VUndef) 
     1399 
     1400instance Binary [a] => Binary [:a:] where 
     1401    put = put . fromP 
     1402    get = fmap toP get 
     1403 
     1404instance Binary VRef where 
     1405    put (MkRef (ICode cv)) 
     1406        | Just (mc :: VMultiCode) <- fromTypeable cv = do 
     1407            putWord8 0x30 
     1408            put (mc :: VMultiCode) 
     1409        | otherwise = do 
     1410            putWord8 0x31 
     1411            let VCode vsub = unsafePerformIO (fakeEval $ fmap VCode (code_fetch cv)) 
     1412            put vsub 
     1413    put (MkRef (IScalar sv)) = do 
     1414        putWord8 $ if scalar_iType sv == mkType "Scalar::Const" 
     1415            then 0x32 else 0x33 
     1416        put $ unsafePerformIO (fakeEval $ scalar_fetch sv) 
     1417    put (MkRef (IArray av)) = do 
     1418        putWord8 0x34 
     1419        let VList vals = unsafePerformIO (fakeEval $ fmap VList (array_fetch av)) 
     1420        put vals 
     1421    put (MkRef (IPair pv)) = do 
     1422        putWord8 0x35 
     1423        let VList [k, v] = unsafePerformIO (fakeEval $ fmap (\(k, v) -> VList [k, v]) (pair_fetch pv)) 
     1424        put (k, v) 
     1425    put (MkRef (IHash hv)) 
     1426        | hash_iType hv == mkType "Hash" = do 
     1427            putWord8 0x36 
     1428            let hv' = ((unsafeCoerce# hv) :: IHash) 
     1429            put hv' 
     1430        | hash_iType hv == mkType "Hash::Env" = do 
     1431            putWord8 0x37 
     1432        | hash_iType hv == mkType "Hash::Const" = do 
     1433            putWord8 0xFF 
     1434            let hv' = ((unsafeCoerce# hv) :: VHash) 
     1435            put hv' 
     1436        | otherwise = do 
     1437            putWord8 0xFF 
     1438            -- put (show (typeOf hv))  
     1439            -- let VMatch MkMatch{ matchSubNamed = hv } = unsafePerformIO 
     1440            --         ( fakeEval $ fmap (VMatch . MkMatch False 0 0 "" []) (hash_fetch hv) ) 
     1441            put (Map.empty :: VHash) 
     1442    put ref = fail ("Not implemented: asYAML \"" ++ showType (refType ref) ++ "\"") 
     1443    get = do 
     1444        tag_ <- getWord8 
     1445        case tag_ of 
     1446            0x30 -> fmap codeRef (get :: Get VMultiCode) 
     1447            0x31 -> fmap codeRef (get :: Get VCode) 
     1448            0x32 -> fmap scalarRef (get :: Get VScalar) 
     1449            0x33 -> fmap (MkRef . unsafePerformIO . newScalar') get 
     1450            0x34 -> fmap (MkRef . unsafePerformIO . newArray') get 
     1451            0x35 -> fmap pairRef (get :: Get VPair) 
     1452            0x36 -> do 
     1453                iHash <- get 
     1454                return $ hashRef (iHash :: IHash) 
     1455            0x37 -> return $ hashRef MkHashEnv 
     1456            _    -> fmap hashRef (get :: Get VHash) 
     1457 
     1458newScalar' :: VScalar -> IO (IVar VScalar) 
     1459newScalar' = (fmap IScalar) . newTVarIO 
     1460 
     1461newArray' :: VArray -> IO (IVar VArray) 
     1462newArray' vals = do 
     1463    tvs <- mapM newScalar' vals 
     1464    iv  <- newTVarIO (toP tvs) 
     1465    return $ IArray (MkIArray iv) 
     1466 
     1467instance Binary Pad where 
     1468    put = put . Map.toList . padEntries 
     1469    get = liftM (MkPad . Map.fromList) get 
     1470 
     1471instance Binary EntryFlags where 
     1472    put (MkEntryFlags x) = put x 
     1473    get = fmap MkEntryFlags get 
     1474