File:  [gforth] / gforth / lib.fs
Revision 1.29: download - view: text, annotated - select for diffs
Tue Jul 29 15:55:26 2008 UTC (15 years, 7 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Prefer libffi over ffcall

    1: \ lib.fs	shared library support package 		11may97py
    2: 
    3: \ Copyright (C) 1995,1996,1997,1998,2000,2003,2005,2006,2007,2008 Free Software Foundation, Inc.
    4: 
    5: \ This file is part of Gforth.
    6: 
    7: \ Gforth is free software; you can redistribute it and/or
    8: \ modify it under the terms of the GNU General Public License
    9: \ as published by the Free Software Foundation, either version 3
   10: \ of the License, or (at your option) any later version.
   11: 
   12: \ This program is distributed in the hope that it will be useful,
   13: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
   14: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15: \ GNU General Public License for more details.
   16: 
   17: \ You should have received a copy of the GNU General Public License
   18: \ along with this program. If not, see http://www.gnu.org/licenses/.
   19: 
   20: s" libffi.so" open-lib [if]
   21:     .( including libffi.fs )
   22:     include libffi.fs
   23: [ELSE]
   24:     s" libavcall.so"     open-lib 0<>
   25:     s" libcallback.so"   open-lib 0<> and [if]
   26: 	.( including fflib.fs [ffcall] )
   27: 	include fflib.fs
   28:     [ELSE]
   29: 	.( Neither libffi nor ffcall are available ) cr
   30: 	abort
   31:         .( Using oldlib.fs; incompatible with fflib.fs and libffi.fs) cr
   32: 	include oldlib.fs
   33:     [THEN]
   34: [THEN]
   35: 
   36: \ testing stuff
   37: 
   38: [IFUNDEF] libc
   39:     s" os-type" environment? [IF]
   40: 	2dup s" linux-gnu" str= [IF]  2drop
   41: 	    cell 8 = [IF]
   42: 		library libc /lib64/libc.so.6
   43: 	    [ELSE]
   44: 		library libc /lib/libc.so.6
   45: 	    [THEN]
   46: 	[ELSE] 2dup s" cygwin" str= [IF]  2drop
   47: 		library libc cygwin1.dll
   48: 	    [ELSE]  2dup s" bsd" search nip nip [IF]  2drop
   49: 		    library libc libc.so
   50: 		[ELSE]  2dup s" darwin" string-prefix? [IF]  2drop
   51: 			library libc libc.dylib
   52: 		    [ELSE]  2drop \ or add your stuff here
   53: 		    [THEN]
   54: 		[THEN]
   55: 	    [THEN]
   56: 	[THEN]
   57:     [THEN]
   58: [THEN]
   59: 
   60: [ifdef] testing
   61: 
   62: library libc libc.so.6
   63:                 
   64: libc sleep int (int) sleep
   65: libc open  ptr int int (int) open
   66: libc lseek int llong int (llong) lseek64
   67: libc read  int ptr int (int) read
   68: libc close int (int) close
   69: 
   70: library libm libm.so.6
   71: 
   72: libm fmodf sf sf (sf) fmodf
   73: libm fmod  df df (fp) fmod
   74: 
   75: \ example for a windows callback
   76:     
   77: callback wincall (int) int int int int callback;
   78: 
   79: :noname ( a b c d -- e )  2drop 2drop 0 ; wincall do_timer
   80: 
   81: \ test a callback
   82: 
   83: callback 2:1 (int) int int callback;
   84: 
   85: : cb-test ( a b -- c )
   86:     cr ." Testing callback"
   87:     cr ." arguments: " .s
   88:     cr ." result " + .s cr ;
   89: ' cb-test 2:1 c_plus
   90: 
   91: fptr 2:1call int int (int)
   92: 
   93: : test  c_plus 2:1call ;
   94: 
   95: \ 3 4 test
   96: 
   97: \ bigFORTH legacy library test
   98: 
   99: library libX11 libX11.so.6
  100: 
  101: legacy on
  102: 
  103: 1 libX11 XOpenDisplay XOpenDisplay    ( name -- dpy )
  104: 5 libX11 XInternAtoms XInternAtoms    ( atoms flag count names dpy -- status )
  105: 
  106: legacy off
  107: 
  108: [then]    

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>