File:  [gforth] / gforth / lib.fs
Revision 1.30: download - view: text, annotated - select for diffs
Thu Jul 31 12:46:03 2008 UTC (15 years, 7 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Changed search for libffi

    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" os-type" environment? [IF]
   21:     2dup s" linux-gnu" str= [IF] 2drop s" libffi.so"
   22:     [ELSE] 2dup s" bsd" search nip nip [IF] 2drop s" libffi.so"
   23: 	[ELSE] 2dup s" cygwin" str= [IF] 2drop s" libffi.dll"
   24: 	    [ELSE] 2dup s" darwin" str= [IF] 2drop s" libffi.dylib"
   25: 		[ELSE] 2drop [THEN] [THEN] [THEN] [THEN] [THEN]
   26: open-lib [if]
   27:     .( including libffi.fs )
   28:     include libffi.fs
   29: [ELSE]
   30:     s" libavcall.so"     open-lib 0<>
   31:     s" libcallback.so"   open-lib 0<> and [if]
   32: 	.( including fflib.fs [ffcall] )
   33: 	include fflib.fs
   34:     [ELSE]
   35: 	.( Neither libffi nor ffcall are available ) cr
   36: 	abort
   37:         .( Using oldlib.fs; incompatible with fflib.fs and libffi.fs) cr
   38: 	include oldlib.fs
   39:     [THEN]
   40: [THEN]
   41: 
   42: \ testing stuff
   43: 
   44: [IFUNDEF] libc
   45:     s" os-type" environment? [IF]
   46: 	2dup s" linux-gnu" str= [IF]  2drop
   47: 	    cell 8 = [IF]
   48: 		library libc /lib64/libc.so.6
   49: 	    [ELSE]
   50: 		library libc /lib/libc.so.6
   51: 	    [THEN]
   52: 	[ELSE] 2dup s" cygwin" str= [IF]  2drop
   53: 		library libc cygwin1.dll
   54: 	    [ELSE]  2dup s" bsd" search nip nip [IF]  2drop
   55: 		    library libc libc.so
   56: 		[ELSE]  2dup s" darwin" string-prefix? [IF]  2drop
   57: 			library libc libc.dylib
   58: 		    [ELSE]  2drop \ or add your stuff here
   59: 		    [THEN]
   60: 		[THEN]
   61: 	    [THEN]
   62: 	[THEN]
   63:     [THEN]
   64: [THEN]
   65: 
   66: [ifdef] testing
   67: 
   68: library libc libc.so.6
   69:                 
   70: libc sleep int (int) sleep
   71: libc open  ptr int int (int) open
   72: libc lseek int llong int (llong) lseek64
   73: libc read  int ptr int (int) read
   74: libc close int (int) close
   75: 
   76: library libm libm.so.6
   77: 
   78: libm fmodf sf sf (sf) fmodf
   79: libm fmod  df df (fp) fmod
   80: 
   81: \ example for a windows callback
   82:     
   83: callback wincall (int) int int int int callback;
   84: 
   85: :noname ( a b c d -- e )  2drop 2drop 0 ; wincall do_timer
   86: 
   87: \ test a callback
   88: 
   89: callback 2:1 (int) int int callback;
   90: 
   91: : cb-test ( a b -- c )
   92:     cr ." Testing callback"
   93:     cr ." arguments: " .s
   94:     cr ." result " + .s cr ;
   95: ' cb-test 2:1 c_plus
   96: 
   97: fptr 2:1call int int (int)
   98: 
   99: : test  c_plus 2:1call ;
  100: 
  101: \ 3 4 test
  102: 
  103: \ bigFORTH legacy library test
  104: 
  105: library libX11 libX11.so.6
  106: 
  107: legacy on
  108: 
  109: 1 libX11 XOpenDisplay XOpenDisplay    ( name -- dpy )
  110: 5 libX11 XInternAtoms XInternAtoms    ( atoms flag count names dpy -- status )
  111: 
  112: legacy off
  113: 
  114: [then]    

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