help needed for adding isWHNF primop to 5.00.2

Sigbjorn Finne sof@galconn.com
Sun, 29 Jul 2001 11:39:18 -0700


Bernard James POPE bjpop@cs.mu.OZ.AU writes:
>
> I would like to add a primitive to GHC 5.00.2 of the form:
>
>    isWHNF :: a -> Bool
>
  ... list of steps followed deleted...
>
> If anyone could point me in the right direction to solving my problem
> I would be very grateful.

Hi,

the panic you're getting is due to the fact that you didn't add native
code generator support for your primitive (compile your example with
-fvia-C to sidestep it). Appended is an NCG implementation for it,
which you might find helpful (the impl is based on dataToTagOp's).

Whether your primop is precise enough to test WHNFness or
not, I'll let others be the judge of..

hth
--sigbjorn

-- #define isHNFzh(r,a) r=(! closure_HNF((StgClosure *)a))
primCode [res] IsHNFOp [arg]
   = let res'        = amodeToStix res
         arg'        = amodeToStix arg
         arg_info    = StInd PtrRep arg'
         word_32     = StInd WordRep (StIndex PtrRep arg_info (StInt (-1)))
         masked_le32 = StPrim SrlOp [word_32, StInt 16]
         masked_be32 = StPrim AndOp [word_32, StInt 65535]
#ifdef WORDS_BIGENDIAN
         ty_info     = masked_le32
#else
         ty_info     = masked_be32
#endif
         not_a_thunk = StPrim IntEqOp [ StPrim AndOp [ty_info, StInt 0x10]
                                      , StInt 0x0
                                      ]
                        -- ToDo: don't hardwire the value of _THUNK from
InfoTables.h
         assign      = StAssign IntRep res' not_a_thunk
     in
     returnUs (\ xs -> assign : xs)