Last active
February 24, 2020 15:09
-
-
Save sdiehl/0491596cd7faaf95503e4b7066cffe62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cabal-version: 3.0 | |
name: example | |
build-type: Simple | |
version: 1.0.0 | |
executable example | |
main-is: Main.hs | |
build-depends: base, ghc-prim | |
default-language: Haskell2010 | |
ghc-options: -ddump-cmm | |
c-sources: example.cmm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Cmm.h" | |
example (W_ n) { | |
entry: | |
return (n+1); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE ForeignFunctionInterface #-} | |
{-# LANGUAGE GHCForeignImportPrim #-} | |
{-# LANGUAGE MagicHash #-} | |
{-# LANGUAGE UnliftedFFITypes #-} | |
module Main where | |
import GHC.Prim | |
import GHC.Word | |
foreign import prim "example" example_cmm :: Word# -> Word# | |
example :: Word64 -> Word64 | |
example (W64# n) = W64# (example_cmm n) | |
main :: IO () | |
main = print (example 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment