@@ -2737,63 +2737,106 @@ unpackDataCon dcon_var freeVarToVarEnv lenv ddfs fundefs denv1 tenv1 senv isPack
27372737 -- An indirection or redirection pointer.
27382738 -- ASSUMPTION: We can always bind it, since it occurs immediately after the tag.
27392739 CursorTy -> do
2740- tmp <- dbgTrace (minChatLvl) " Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) " End FieldCur\n " gensym " readcursor_indir"
2741- tmp_flds <- mapM (\ ((dcon, idx), _) -> gensym " readcursor_indir_flds" ) _field_cur
2742- loc_var <- lookupVariable loc fenv
2743- var_dcon_next <- gensym " dcon_next"
2744- vars_next_fields <- mapM (\ ((dcon, idx), _) -> gensym " field_nxt" ) _field_cur
2745- redirection_var_dcon <- gensym " dcon_redir"
2746- redirection_var_flds <- mapM (\ ((dcon, idx), _) -> gensym " fld_redir" ) _field_cur
2747- -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1
2748- -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur
2749- let tenv' = M. union (M. fromList [(tmp , MkTy2 (ProdTy [CursorTy , CursorTy , IntTy ])),
2740+ if isRedirectionTag dcon
2741+ then do
2742+ tmp <- dbgTrace (minChatLvl) " Print field_cur: " dbgTrace (minChatLvl) (sdoc (dcur, _field_cur)) dbgTrace (minChatLvl) " End FieldCur\n " gensym " readcursor_indir"
2743+ tmp_flds <- mapM (\ ((dcon, idx), _) -> gensym " readcursor_indir_flds" ) _field_cur
2744+ loc_var <- lookupVariable loc fenv
2745+ var_dcon_next <- gensym " dcon_next"
2746+ vars_next_fields <- mapM (\ ((dcon, idx), _) -> gensym " field_nxt" ) _field_cur
2747+ redirection_var_dcon <- gensym " dcon_redir"
2748+ redirection_var_flds <- mapM (\ ((dcon, idx), _) -> gensym " fld_redir" ) _field_cur
2749+ -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1
2750+ -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur
2751+ let tenv' = M. union (M. fromList [(tmp , MkTy2 (ProdTy [CursorTy , CursorTy , IntTy ])),
27502752 -- ((loc_var) , MkTy2 CursorTy),
27512753 (redirection_var_dcon , MkTy2 CursorTy ),
27522754 (toEndV redirection_var_dcon, MkTy2 CursorTy ),
27532755 (toTagV redirection_var_dcon, MkTy2 IntTy ),
27542756 (toEndFromTaggedV redirection_var_dcon, MkTy2 CursorTy )])
2755- tenv
2756- read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon
2757- then Ext (ReadTaggedCursor var_dcon_next)
2758- else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
2759- -- v is the variable i want to send to the call.
2760- -- In this case v is the soa variable where all redirections are unpacked.
2761- binds = [(var_dcon_next, [] , CursorTy , Ext (AddCursor dcur (LitE 1 ))),
2762- (tmp , [] , ProdTy [CursorTy , CursorTy , IntTy ], read_cursor),
2763- ((loc_var) , [] , CursorTy , VarE dcur),
2764- (redirection_var_dcon , [] , CursorTy , ProjE 0 (VarE tmp)),
2765- (toEndV redirection_var_dcon, [] , CursorTy , ProjE 1 (VarE tmp)),
2766- (toTagV redirection_var_dcon, [] , IntTy , ProjE 2 (VarE tmp)),
2767- (toEndFromTaggedV redirection_var_dcon, [] , CursorTy , Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))]
2768-
2769- -- generate binds for all fields.
2770- binds_flields = L. foldl (\ (index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon
2771- then Ext (ReadTaggedCursor (vars_next_fields !! index))
2772- else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
2773- tmpf = tmp_flds !! index
2774- ty_of_field = (lookupDataCon ddfs dcon') !! idx
2775- in case ty_of_field of
2776- (MkTy2 PackedTy {}) -> let new_binds = [(redirection_var_flds !! index, [] , CursorTy , Ext (AddCursor var (LitE 0 )))]
2777- in (index + 1 , res ++ new_binds)
2778- (MkTy2 CursorArrayTy {}) -> let new_binds = [(redirection_var_flds !! index, [] , CursorTy , Ext (AddCursor var (LitE 0 )))]
2757+ tenv
2758+ read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon
2759+ then Ext (ReadTaggedCursor var_dcon_next)
2760+ else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
2761+ -- v is the variable i want to send to the call.
2762+ -- In this case v is the soa variable where all redirections are unpacked.
2763+ binds = [(var_dcon_next, [] , CursorTy , Ext (AddCursor dcur (LitE 1 ))),
2764+ (tmp , [] , ProdTy [CursorTy , CursorTy , IntTy ], read_cursor),
2765+ ((loc_var) , [] , CursorTy , VarE dcur),
2766+ (redirection_var_dcon , [] , CursorTy , ProjE 0 (VarE tmp)),
2767+ (toEndV redirection_var_dcon, [] , CursorTy , ProjE 1 (VarE tmp)),
2768+ (toTagV redirection_var_dcon, [] , IntTy , ProjE 2 (VarE tmp)),
2769+ (toEndFromTaggedV redirection_var_dcon, [] , CursorTy , Ext $ AddCursor redirection_var_dcon (VarE (toTagV redirection_var_dcon)))]
2770+
2771+ -- generate binds for all fields.
2772+ binds_flields = L. foldl (\ (index, res) ((dcon', idx), var) -> let read_cursor_f = if isIndirectionTag dcon || isRedirectionTag dcon
2773+ then Ext (ReadTaggedCursor (vars_next_fields !! index))
2774+ else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
2775+ tmpf = tmp_flds !! index
2776+ ty_of_field = (lookupDataCon ddfs dcon') !! idx
2777+ in case ty_of_field of
2778+ (MkTy2 PackedTy {}) -> let new_binds = [(redirection_var_flds !! index, [] , CursorTy , Ext (AddCursor var (LitE 0 )))]
2779+ in (index + 1 , res ++ new_binds)
2780+ (MkTy2 CursorArrayTy {}) -> let new_binds = [(redirection_var_flds !! index, [] , CursorTy , Ext (AddCursor var (LitE 0 )))]
2781+ in (index + 1 , res ++ new_binds)
2782+ _ -> let new_binds = [(vars_next_fields !! index, [] , CursorTy , Ext (AddCursor var (LitE 1 ))),
2783+ (tmpf , [] , ProdTy [CursorTy , CursorTy , IntTy ], read_cursor_f),
2784+ -- ((loc_var) , [], CursorTy, VarE dcur),
2785+ ((redirection_var_flds !! index) , [] , CursorTy , ProjE 0 (VarE tmpf)),
2786+ (toEndV (redirection_var_flds !! index), [] , CursorTy , ProjE 1 (VarE tmpf)),
2787+ (toTagV (redirection_var_flds !! index), [] , IntTy , ProjE 2 (VarE tmpf)),
2788+ (toEndFromTaggedV (redirection_var_flds !! index), [] , CursorTy , Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))]
27792789 in (index + 1 , res ++ new_binds)
2780- _ -> let new_binds = [(vars_next_fields !! index, [] , CursorTy , Ext (AddCursor var (LitE 1 ))),
2781- (tmpf , [] , ProdTy [CursorTy , CursorTy , IntTy ], read_cursor_f),
2782- -- ((loc_var) , [], CursorTy, VarE dcur),
2783- ((redirection_var_flds !! index) , [] , CursorTy , ProjE 0 (VarE tmpf)),
2784- (toEndV (redirection_var_flds !! index), [] , CursorTy , ProjE 1 (VarE tmpf)),
2785- (toTagV (redirection_var_flds !! index), [] , IntTy , ProjE 2 (VarE tmpf)),
2786- (toEndFromTaggedV (redirection_var_flds !! index), [] , CursorTy , Ext $ AddCursor (redirection_var_flds !! index) (VarE (toTagV (redirection_var_flds !! index))))]
2787- in (index + 1 , res ++ new_binds)
2788-
2789- ) (0 , [] ) _field_cur
2790- soa_redir_bind = [(v, [] , CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))]
2791- tenv'' = M. union (M. fromList [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds)))
2792- ] )
2793- tenv
2794- bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v)
2795- return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod
27962790
2791+ ) (0 , [] ) _field_cur
2792+ soa_redir_bind = [(v, [] , CursorArrayTy (1 + length (redirection_var_flds)), Ext (MakeCursorArray (1 + length (redirection_var_flds)) ([redirection_var_dcon] ++ redirection_var_flds)))]
2793+ tenv'' = M. union (M. fromList [ (v, MkTy2 $ CursorArrayTy (1 + length (redirection_var_flds)))
2794+ ] )
2795+ tenv
2796+ bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv'' -- (toEndV v)
2797+ return $ mkLets (binds ++ (snd binds_flields) ++ soa_redir_bind) bod
2798+ else if isIndirectionTag dcon
2799+ then
2800+ do
2801+ tmp <- gensym " readcursor_indir"
2802+ loc_var <- lookupVariable loc fenv
2803+ let locs_ty = case (loc) of
2804+ FL (Single _) -> CursorTy
2805+ FL (SoA _ flds) -> CursorArrayTy (1 + length (flds))
2806+ _ -> error " Expected location!"
2807+
2808+ let locs_ty3 :: Ty3 = case (loc) of
2809+ FL (Single _) -> CursorTy
2810+ FL (SoA _ flds) -> CursorArrayTy (1 + length (flds))
2811+ _ -> error " Expected location!"
2812+
2813+ -- let field_idx = fromJust $ L.elemIndex (v, locarg) vlocs1
2814+ -- let cur = fromJust $ L.lookup (dcon, field_idx) _field_cur
2815+ var_dcon_next <- gensym " dcon_next"
2816+
2817+ let tenv' = M. union (M. fromList [(tmp , MkTy2 (ProdTy [CursorTy , CursorTy , IntTy ])),
2818+ ((loc_var) , MkTy2 locs_ty),
2819+ (v , MkTy2 locs_ty)
2820+ -- (toEndV v, MkTy2 CursorTy),
2821+ -- (toTagV v, MkTy2 IntTy),
2822+ -- (toEndFromTaggedV v, MkTy2 CursorTy)
2823+ ])
2824+ tenv
2825+ read_cursor = if isIndirectionTag dcon || isRedirectionTag dcon
2826+ then Ext (ReadTaggedCursor var_dcon_next)
2827+ else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
2828+ binds = [ (var_dcon_next, [] , CursorTy , Ext (AddCursor dcur (LitE 1 ))),
2829+ (tmp , [] , ProdTy [CursorTy , CursorTy , IntTy ], read_cursor),
2830+ (v , [] , CursorTy , ProjE 0 (VarE tmp)),
2831+ -- (toEndV v, [], CursorTy, ProjE 1 (VarE tmp)),
2832+ -- (toTagV v, [], IntTy , ProjE 2 (VarE tmp)),
2833+ -- End of region needs to be calculated differently
2834+ -- (toEndFromTaggedV v, [], CursorTy, Ext $ AddCursor v (VarE (toTagV v))),
2835+ ((loc_var) , [] , locs_ty3, VarE v)
2836+ ]
2837+ bod <- go curw fenv rst_vlocs rst_tys canBind denv tenv' -- (toEndV v)
2838+ return $ mkLets binds bod
2839+ else error $ " unpackRegularDataCon: cursorty without indirection/redirection."
27972840
27982841 VectorTy el_ty -> do
27992842 tmp <- gensym " read_vec_tuple"
0 commit comments