[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*Subject*: Multi-Dimensional Arrays and MCL's FFI*From*: DOYLE@SISU.MGH.HARVARD.EDU*Date*: 20 Jul 1993 15:47:15 -0500 (EST)

There was an article on using the component manager in Develop 12 (December 1992) for a simple math example (there is source and a working component which accompany the article). I think that the component was written in Think C. We've found that components are an excellent way of dynamically linking in code for things that are easier in C (such as handling things at interrupt time) or that talk to hardware (in which case it is like a driver). One of our engineers (Kee Luk) wrote the following code to call the Develop component from MCL: ;;; Math Component Interface ;;; Not copyrighted. But, if you do make millions of $$ from this, ;;; don't spend it all in one place :-) (defvar math-component) (deftrap _ComponentMultiply ((CI (:POINTER :COMPONENTINSTANCERECORD)) (p1 (:INTEGER)) (p2 (:INTEGER)) (result (:POINTER :INTEGER))) (:STACK :SIGNED-LONG) (:STACK-TRAP #xA82A :D0 0 CI p1 p2 result ((+ (ASH 8 16) 2) :SIGNED-LONGINT))) (deftrap _ComponentDivide ((CI (:POINTER :COMPONENTINSTANCERECORD)) (p1 (:INTEGER)) (p2 (:INTEGER)) (result (:POINTER :INTEGER))) (:STACK :SIGNED-LONG) (:STACK-TRAP #xA82A :D0 0 CI p1 p2 result ((+ (ASH 8 16) 1) :SIGNED-LONGINT))) (defun init-math-component () (setf math-component (#_OPENDEFAULTCOMPONENT :|math| 0)) (if (%null-ptr-p math-component) (format t "~&Can not locate math component") math-component)) (defun exit-math-component () (#_CLOSECOMPONENT math-component)) (defun multiply-with-component (p1 p2) (%stack-block ((answer-buffer 2)) (unless (%null-ptr-p math-component) (let ((rc (#_ComponentMultiply math-component p1 p2 answer-buffer))) (if (zerop rc) (format t "~&~a * ~a = ~a" p1 p2 (%get-signed-word answer-buffer)) (format t "~&Error *** return code ~a" rc)))))) (defun divide-with-component (p1 p2) (%stack-block ((answer-buffer 2)) (unless (%null-ptr-p math-component) (let ((rc (#_ComponentDivide math-component p1 p2 answer-buffer))) (if (zerop rc) (format t "~&~a / ~a = ~a" p1 p2 (%get-signed-word answer-buffer)) (format t "~&Error *** return code ~a" rc)))))) #| (init-math-component) (multiply-with-component 3 -4) (divide-with-component 2 -2) (exit-math-component) |#

- Prev by Date:
**Garbage Collection (Again!)** - Next by Date:
**MADACON '94 Call for Papers** - Previous by thread:
**Multi-Dimensional Arrays and MCL's FFI** - Next by thread:
**Several Problems Part II** - Index(es):