[EMAIL PROTECTED] (Jorge Acereda Maci�) writes:
> If nobody is working on it tell me and I will send patches in one or
> two weeks (I will be some time away from computers).

Ok, here you have a preliminary patch, no autoconf libavcall detection
or fancy stuff (like comments ;-). It needs some polishing, it is only
a proof of concept. It is for gforth 0.5.0, sorry (I patched it on a
NetBSD system and they are lagging, should be easy to adapt to 0.6.1).

You can download ffcall from:

ftp://ftp.santafe.edu/pub/gnu/ffcall-1.8.tar.gz
ftp://ftp.ilog.fr/pub/Users/haible/gnu/ffcall-1.8.tar.gz

Oops! I didn't patch the makefiles, compile with:

make LDLIBS="-lm -lavcall"


> libc sleep sleep int --int
> libm fmodf fmodf float float --float

Ok, I changed this format to meet Chuck's requirements: 

libc sleep foreign: sleep int --int

Chuck: "foreign:" takes the address to call from the stack, so it
should be possible to do what you want.

It is also possible to use directly the stuff defined in prim instead
of this interface. The above definition could be expressed as:

: sleep  libc sleep aliteral av-start-int av-int av-call-int ; 

I think it should be easy to implement callbacks with these libraries,
will take a look in a couple of weeks.

Greetings,
  Jorge

----->8----->8----->8----->8----->8----->8----->8----->8----->8----->8
diff -Nur gforth-0.5.0/prim /home/jacereda/gforth-0.5.0/prim
--- gforth-0.5.0/prim   Sat Sep 23 18:22:02 2000
+++ /home/jacereda/gforth-0.5.0/prim    Thu Jul 24 22:41:42 2003
@@ -1593,6 +1593,67 @@
 IF_TOS(TOS=sp[0]);
 IF_FTOS(FTOS=fp[0]);
 
+
+av-start-void   ( c_addr -- )    gforth  av_start_void
+av_start_void(alist, c_addr);
+
+av-start-int    ( c_addr -- )    gforth  av_start_int
+av_start_int(alist, c_addr, &irv);
+
+av-start-float    ( c_addr -- )    gforth  av_start_float
+av_start_float(alist, c_addr, &frv);
+
+av-start-double    ( c_addr -- )    gforth  av_start_double
+av_start_double(alist, c_addr, &drv);
+
+av-start-longlong    ( c_addr -- )    gforth  av_start_longlong
+av_start_longlong(alist, c_addr, &llrv);
+
+av-start-ptr    ( c_addr -- )    gforth  av_start_ptr
+av_start_ptr(alist, c_addr, void*, &prv);
+
+
+av-int  ( w -- )  gforth  av_int
+av_int(alist, w);
+
+av-float        ( r -- )        gforth  av_float
+av_float(alist, r);
+
+av-double        ( r -- )        gforth  av_double
+av_double(alist, r);
+
+av-longlong        ( d -- )        gforth  av_longlong
+av_longlong(alist, d);
+
+av-ptr        ( c_addr -- )        gforth  av_ptr
+av_ptr(alist, void*, c_addr);
+
+
+av-call-void    ( -- )          gforth  av_call_void
+av_call(alist);
+
+av-call-int    ( -- w )        gforth  av_call_int
+av_call(alist);
+w = irv;
+
+av-call-float   ( -- r )        gforth  av_call_float
+av_call(alist);
+r = frv;
+
+av-call-double   ( -- r )        gforth  av_call_double
+av_call(alist);
+r = drv;
+
+av-call-longlong   ( -- d )        gforth  av_call_longlong
+av_call(alist);
+d = llrv;
+
+av-call-ptr   ( -- c_addr )        gforth  av_call_ptr
+av_call(alist);
+c_addr = prv;
+
+
+
 \+
 \+file
 
diff -Nur gforth-0.5.0/engine/engine.c /home/jacereda/gforth-0.5.0/engine/engine.c
--- gforth-0.5.0/engine/engine.c        Sat Sep 23 18:22:09 2000
+++ /home/jacereda/gforth-0.5.0/engine/engine.c Thu Jul 24 22:26:36 2003
@@ -59,6 +59,8 @@
 #include <dl.h>
 #endif
 
+#include <avcall.h>
+
 #ifndef SEEK_SET
 /* should be defined in stdio.h, but some systems don't have it */
 #define SEEK_SET 0
@@ -259,6 +261,12 @@
    returns array of machine code labels (for use in a loader), if ip==NULL
 */
 {
+    av_alist alist;
+    float frv;
+    int irv;
+    double drv;
+    long long llrv;
+    void * prv;
 #ifndef GFORTH_DEBUGGING
   register Xt *ip IPREG;
   register Cell *rp RPREG;
diff -Nur gforth-0.5.0/ffcall.fs /home/jacereda/gforth-0.5.0/ffcall.fs
--- gforth-0.5.0/ffcall.fs      Thu Jan  1 00:00:00 1970
+++ /home/jacereda/gforth-0.5.0/ffcall.fs       Fri Jul 25 15:42:05 2003
@@ -0,0 +1,48 @@
+true value testing?
+
+: library:
+    create immediate
+    bl parse open-lib
+    dup 0= abort" unable to open lib"   ,
+does>
+    @ >r bl parse r> lib-sym
+    dup 0= abort" unable to find symbol" ;
+
+: foreign: >r : r> postpone aliteral false ;
+
+: rettype ( endxt startxt "name" -- )
+    create immediate 2,
+does>
+    2@ compile, >r
+    begin dup while compile, repeat drop
+    r> compile,  postpone ; ;
+
+' av-call-void ' av-start-void rettype --
+' av-call-int ' av-start-int rettype --int
+' av-call-float ' av-start-float rettype --flt
+' av-call-double ' av-start-double rettype --dbl
+' av-call-longlong ' av-start-longlong rettype --llong
+' av-call-ptr ' av-start-ptr rettype --ptr
+
+: int ['] av-int ; immediate
+: flt ['] av-float ; immediate
+: dbl ['] av-double ; immediate
+: llong ['] av-longlong ; immediate
+: ptr ['] av-ptr ; immediate
+
+testing? [if]
+
+library: libc /usr/lib/libc.so
+                
+libc sleep foreign: sleep   int --int
+libc open  foreign: open    int int ptr --int
+libc lseek foreign: lseek   int llong int --llong
+libc read  foreign: read    int ptr int --int
+libc close foreign: close   int --int
+
+library: libm /usr/lib/libm.so
+
+libm fmodf foreign: fmodf   flt flt --flt
+libm fmod  foreign: fmod    dbl dbl --dbl
+
+[then]    

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to