Skip to content
This repository has been archived by the owner on Apr 16, 2020. It is now read-only.

Latest commit

 

History

History
52 lines (43 loc) · 1.5 KB

TODO.org

File metadata and controls

52 lines (43 loc) · 1.5 KB

Write a simple C runtime linker and function call

  • State “DONE” from “TODO” [2019-11-09 Sat 17:28]
import System.Posix.DynamicLinker
import Foreign.Ptr
import Foreign.LibFFI
main = do
    malloc <- dlsym Default "malloc"
    memset <- dlsym Default "memset"
    p <- callFFI malloc (retPtr retVoid) [argCSize (2^30)]
    callFFI memset (retPtr retVoid) [argPtr p, argCInt 0, argCSize (2^30)]
    callFFI memset (retPtr retVoid) [argPtr nullPtr, argCInt 0, argCSize 1]

From http://hackage.haskell.org/package/libffi-0.1/docs/Foreign-LibFFI.html

Add foreign calls to the index

Add ForeignOp constructor to Op (ref’ing CCallSpec)

  • State “DONE” from “TODO” [2019-10-27 Sun 11:38]
 data Op
   = PrimOp PrimOp
+  | ForeignOp CCallSpec

Deal with this issue:

prana-interpreter> [1 of 1] Recompiling Atan2 [prana]
prana-interpreter> [1 of 1] Converting Atan2 [prana]
prana-interpreter> prana-interpreter-test: panic! (the 'impossible' happened)
prana-interpreter>   (GHC version 8.4.3 for x86_64-unknown-linux):
prana-interpreter> 	Unexpected function for data alt case scrutinee.
{-# LANGUAGE NoImplicitPrelude #-}

-- | Demonstrate various use of the FFI.

module Atan2 where

import Foreign.C

foreign import ccall "math.h atan2"
   atan2 :: CDouble -> CDouble -> CDouble

it :: CDouble
it = atan2 (-10) (10) * 180 / 3.14159265