- (state_and_prim_datacon, state_and_prim_ty) = getStatePairingConInfo the_prim_result_ty
-\end{code}
-
-This grimy bit of code is for digging out the IOok constructor from an
-application of the the IO type. The constructor is needed for
-wrapping the result of a _ccall_. The alternative is to wire-in IO,
-which brings a whole heap of junk with it.
-
-If the representation of IO changes, this will probably have to be
-brought in line with the new definition.
-
-newtype IO a = IO (State# RealWorld -> IOResult a)
-
-the constructor IO has type (State# RealWorld -> IOResult a) -> IO a
+-- wrap up an unboxed value.
+wrapUnboxedValue :: Type -> DsM (Type, Id, CoreExpr)
+wrapUnboxedValue ty
+ | null data_cons
+ -- oops! can't see the data constructors
+ = can'tSeeDataConsPanic "result" ty
+ -- Data types with a single constructor, which has a single, primitive-typed arg
+ | (maybeToBool maybe_data_type) && -- Data type
+ (null other_data_cons) && -- Just one constr
+ not (null data_con_arg_tys) && null other_args_tys && -- Just one arg
+ isUnLiftedType the_prim_result_ty -- of primitive type
+ =
+ newSysLocalDs the_prim_result_ty `thenDs` \ prim_result_id ->
+ let
+ the_result = mkConApp the_data_con (map Type tycon_arg_tys ++ [Var prim_result_id])
+ in
+ returnDs (ccall_res_type, prim_result_id, the_result)