Skip to content

skeleton for using cffi... kinda like the one for autowrap, just... #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions arrayfire.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
;;;; arrayfire-lisp.asd
;;;;
;;;; Copyright (c) 2016 ArrayFire
;;;; Copyright (c) 2016 Justin Patera <justin.patera@level3inspection.com>

(asdf:defsystem #:arrayfire
:description "ArrayFire Bindings for Common Lisp"
:author "Justin Patera <justin.patera@level3inspection.com>"
:license "BSD 3-Clause License"

:depends-on (#:cffi
#:trivial-garbage)

:serial t
:pathname "src"
:components
((:file "package")
(:file "cffi")
(:file "utils")))
65 changes: 65 additions & 0 deletions src/cffi.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
;;;; cffi.lisp
;;;;
;;;; Copyright (c) 2016 ArrayFire
;;;; Copyright (c) 2016 Justin Patera <justin.patera@level3inspection.com>

(in-package :arrayfire)

(define-foreign-library arrayfire
(t (:default "af")))

(use-foreign-library arrayfire)

; make array
(defctype af-array :pointer)
(defctype dim-t :long-long)

(defcenum af-dtype
:f32
:c32
:f64
:c64
:b8
:s32
:u32
:u8
:s64
:u64
:s16
:u16)


(defcenum af-err
:af-success
:af-err-no-mem
:af-err-driver
:af-err-runtime
:af-err-invalid-array
:af-err-arg
:af-err-size
:af-err-type
:af-err-diff-type
:af-err-batch
:af-err-device
:af-err-not-supported
:af-err-not-configured
:af-err-nonfree
:af-err-no-dbl
:af-err-no-gfx
:af-err-load-lib
:af-err-load-sym
:af-err-arr-bknd-mismatch
:af-err-internal
:af-err-unknown )



(defcfun "af_create_array" af-err
(arr af-array)
(data :pointer)
(ndims :unsigned-int)
(dims dim-t)
(type af-dtype))

;(let ((arr))
; (af-create-array arr 0 1 1 :b8))
39 changes: 39 additions & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;;;; package.lisp
;;;;
;;;; Copyright (c) 2016 ArrayFire
;;;; Copyright (c) 2016 Justin Patera <justin.patera@level3inspection.com>

(in-package :cl)

(defpackage #:arrayfire
(:nicknames #:af)
(:use #:cl #:cffi)
; as these will probably pose a small issue...
(:shadow ; Arithmatic Ops
#:+ #:- #:* #:/
; Complex Ops
#:complex #:real
; Exponential & Logarithmic Fns
#:exp #:log #:sqrt
; Logical Ops
#:and #:eq #:not #:or
; Numeric Fns
#:abs #:floor #:max #:min #:mod #:rem #:round
; Trigonometric & Hyberbolic Fns
#:acos #:asin #:atan #:cos #:sin #:tan
#:acosh #:asinh #:atanh #:cosh #:sinh #:tanh)

(:export ;; lots more than this...
; Arithmatic Ops
#:+ #:- #:* #:/
; Complex Ops
#:complex #:real
; Exponential & Logarithmic Fns
#:exp #:log #:sqrt
; Logical Ops
#:and #:eq #:not #:or
; Numeric Fns
#:abs #:floor #:max #:min #:mod #:rem #:round
; Trigonometric & Hyberbolic Fns
#:acos #:asin #:atan #:cos #:sin #:tan
#:acosh #:asinh #:atanh #:cosh #:sinh #:tanh))
24 changes: 24 additions & 0 deletions src/utils.lisp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
;;;; autowrap.lisp
;;;;
;;;; Copyright (c) 2016 ArrayFire
;;;; Copyright (c) 2016 Justin Patera <justin.patera@level3inspection.com>

(in-package :arrayfire)

; add utils here

; because FizzBuzz is *essential* to our success!!!
(defun fizzbuzz (n)
(if (< 0 n)
(fizzbuzz-helper 1 n)
(error "The Fizzing And The Buzzing And The FizzBuzzing Needs Numbers Greater Than Zero")))

(defun fizzbuzz-helper (n x)
(if (<= n x)
(cons
(case (cl:mod n 15)
(0 "FizzBuzz")
((3 6 9 12) "Fizz")
((5 10) "Buzz")
(otherwise n))
(fizzbuzz-helper (1+ n) x))))