If the size of the argument list is unknown "before runtime", you will need to convert the function into something that works in the list anyway. Note that the type (IORef [Word32]) means that when the program is executed, the IO action will read / write the (modifiable) Word32 list. Haskell programs should only say how to mutate / read / write a list - hence the IO () monad.
The LLVM git file you are referring to has examples /List.hs. It creates the LLVM build procedure "arrayLoop",
arrayLoop :: (Phi a, IsType b, Num i, IsConst i, IsInteger i, IsFirstClass i, CmpRet i Bool) => Value i -> Value (Ptr b) -> a -> (Value (Ptr b) -> a -> CodeGenFunction ra) -> CodeGenFunction ra arrayLoop len ptr start loopBody = do
which increases the pointer to the list ints, p and reduces the remaining length i in each call to the body block. This block repeatedly calls "loopBody" and stores the result in "vars", which ultimately returns (untouched to zero) to "s" inside the mList function:
mList :: CodeGenModule (Function (StablePtr (IORef [Word32]) -> Word32 -> Ptr Word32 -> IO Int32)) mList = createFunction ExternalLinkage $ \ ref size ptr -> do next <- staticFunction nelem let _ = next :: Function (StablePtr (IORef [Word32]) -> IO Word32) s <- arrayLoop size ptr (valueOf 0) $ \ ptri y -> do flip store ptri =<< call next ref return y ret (s :: Value Int32)
All the additional information about nelem / NextListElement is used in their example for "loopBody", which moves the list once to the left. This repo also mentions a mailing list: haskell-llvm@projects.haskellorg.
GHC7 can compile using LLVM, but I think that would not help with a Haskell program that interprets the language if GHC also does not compile JIT - does anyone know if this is so?
David M. Rogers Dec 21 2018-12-12T00: 00Z
source share