File:  [gforth] / gforth / libcc.fs
Revision 1.38: download - view: text, annotated - select for diffs
Tue Jun 17 21:27:54 2008 UTC (15 years, 10 months ago) by anton
Branches: MAIN
CVS tags: HEAD
documented LIB-ERROR C-LIBRARY-NAME C-LIBRARY END-C-LIBRARY

    1: \ libcc.fs	foreign function interface implemented using a C compiler
    2: 
    3: \ Copyright (C) 2006,2007 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: 
   21: \ What this implementation does is this: if it sees a declaration like
   22: 
   23: \ \ something that tells it that the current library is libc
   24: \ \c #include <unistd.h>
   25: \ c-function dlseek lseek n d n -- d
   26: 
   27: \ it genererates C code similar to the following:
   28: 
   29: \ #include <gforth.h>
   30: \ #include <unistd.h>
   31: \ 
   32: \ void gforth_c_lseek_ndn_d(void)
   33: \ {
   34: \   Cell *sp = gforth_SP;
   35: \   Float *fp = gforth_FP;
   36: \   long long result;  /* longest type in C */
   37: \   gforth_ll2d(lseek(sp[3],gforth_d2ll(sp[2],sp[1]),sp[0]),sp[3],sp[2]);
   38: \   gforth_SP = sp+2;
   39: \ }
   40: 
   41: \ Then it compiles this code and dynamically links it into the Gforth
   42: \ system (batching and caching are future work).  It also dynamically
   43: \ links lseek.  Performing DLSEEK then puts the function pointer of
   44: \ the function pointer of gforth_c_lseek_ndn_d on the stack and
   45: \ calls CALL-C.
   46: 
   47: \ ToDo:
   48: 
   49: \ Batching, caching and lazy evaluation:
   50: 
   51: \ Batching:
   52: 
   53: \ New words are deferred, and the corresponding C functions are
   54: \ collected in one file, until the first word is EXECUTEd; then the
   55: \ file is compiled and linked into the system, and the word is
   56: \ resolved.
   57: 
   58: \ Caching:
   59: 
   60: \ Instead of compiling all this stuff anew for every execution, we
   61: \ keep the files around and have an index file containing the function
   62: \ names and their corresponding .so files.  If the needed wrapper name
   63: \ is already present, it is just linked instead of generating the
   64: \ wrapper again.  This is all done by loading the index file(s?),
   65: \ which define words for the wrappers in a separate wordlist.
   66: 
   67: \ The files are built in .../lib/gforth/$VERSION/libcc/ or
   68: \ ~/.gforth/libcc/$HOST/.
   69: 
   70: \ other things to do:
   71: 
   72: \ c-variable forth-name c-name
   73: \ c-constant forth-name c-name
   74: 
   75: \ Todo: conversion between function pointers and xts (both directions)
   76: 
   77: \ taking an xt and turning it into a function pointer:
   78: 
   79: \ e.g., assume we have the xt of + and want to create a C function int
   80: \ gforth_callback_plus(int, int), and then pass the pointer to that
   81: \ function:
   82: 
   83: \ There should be Forth code like this:
   84: \   ] + 0 (bye)
   85: \ Assume that the start of this code is START
   86:         
   87: \ Now, there should be a C function:
   88: 
   89: \ int gforth_callback_plus(int p1, int p2)
   90: \ {
   91: \   Cell   *sp = gforth_SP;
   92: \   Float  *fp = gforth_FP;
   93: \   Float  *fp = gforth_FP;
   94: \   Address lp = gforth_LP;
   95: \   sp -= 2;
   96: \   sp[0] = p1;
   97: \   sp[1] = p2;
   98: \   gforth_engine(START, sp, rp, fp, lp);
   99: \   sp += 1;
  100: \   gforth_RP = rp;
  101: \   gforth_SP = sp;
  102: \   gforth_FP = fp;
  103: \   gforth_LP = lp;
  104: \   return sp[0];
  105: \ }
  106: 
  107: \ and the pointer to that function is the C function pointer for the XT of +.
  108: 
  109: \ Future problems:
  110: \   how to combine the Forth code generation with inlining
  111: \   START is not a constant across executions (when caching the C files)
  112: \      Solution: make START a variable, and store into it on startup with dlsym
  113: 
  114: \ Syntax:
  115: \  callback <rettype> <params> <paramtypes> -- <rettype>
  116: 
  117: 
  118: \ data structures
  119: 
  120: \ For every c-function, we have three words: two anonymous words
  121: \ created by c-function-ft (first time) and c-function-rt (run-time),
  122: \ and a named deferred word.  The deferred word first points to the
  123: \ first-time word, then to the run-time word; the run-time word calls
  124: \ the c function.
  125: 
  126: [ifundef] parse-name
  127:     ' parse-word alias parse-name
  128: [then]
  129: [ifundef] defer!
  130: : defer! ( xt xt-deferred -- ) \ gforth  defer-store
  131: \G Changes the @code{defer}red word @var{xt-deferred} to execute @var{xt}.
  132:     >body [ has? rom [IF] ] @ [ [THEN] ] ! ;
  133: [then]
  134: 
  135: \ : delete-file 2drop 0 ;
  136: 
  137: require struct.fs
  138: 
  139:     \ counted-string
  140:     
  141: \ c-function-ft word body:
  142: struct
  143:     cell% field cff-cfr \ xt of c-function-rt word
  144:     cell% field cff-deferred \ xt of c-function deferred word
  145:     cell% field cff-lha \ address of the lib-handle for the lib that
  146:                         \ contains the wrapper function of the word
  147:     char% field cff-rtype  \ return type
  148:     char% field cff-np     \ number of parameters
  149:     1 0   field cff-ptypes \ #npar parameter types
  150:     \  counted string: c-name
  151: end-struct cff%
  152: 
  153: variable c-source-file-id \ contains the source file id of the current batch
  154: 0 c-source-file-id !
  155: variable lib-handle-addr \ points to the library handle of the current batch.
  156:                          \ the library handle is 0 if the current
  157:                          \ batch is not yet compiled.
  158: 2variable lib-filename   \ filename without extension
  159: 2variable lib-modulename \ basename of the file without extension
  160: 
  161: : delete-file 2drop 0 ;
  162: 
  163: : .nb ( n -- )
  164:     0 .r ;
  165: 
  166: : const+ ( n1 "name" -- n2 )
  167:     dup constant 1+ ;
  168: 
  169: : front-string { c-addr1 u1 c-addr2 u2 -- c-addr3 u3 }
  170:     \ insert string c-addr2 u2 in buffer c-addr1 u1; c-addr3 u3 is the
  171:     \ remainder of the buffer.
  172:     assert( u1 u2 u>= )
  173:     c-addr2 c-addr1 u2 move
  174:     c-addr1 u1 u2 /string ;
  175: 
  176: : front-char { c-addr1 u1 c -- c-addr3 u2 }
  177:     \ insert c in buffer c-addr1 u1; c-addr3 u3 is the remainder of
  178:     \ the buffer.
  179:     assert( u1 0 u> )
  180:     c c-addr1 c!
  181:     c-addr1 u1 1 /string ;
  182: 
  183: : s+ { addr1 u1 addr2 u2 -- addr u }
  184:     u1 u2 + allocate throw { addr }
  185:     addr1 addr u1 move
  186:     addr2 addr u1 + u2 move
  187:     addr u1 u2 +
  188: ;
  189: 
  190: : append { addr1 u1 addr2 u2 -- addr u }
  191:     addr1 u1 u2 + dup { u } resize throw { addr }
  192:     addr2 addr u1 + u2 move
  193:     addr u ;
  194: 
  195: \ linked list stuff (should go elsewhere)
  196: 
  197: struct
  198:     cell% field list-next
  199:     1 0   field list-payload
  200: end-struct list%
  201: 
  202: : list-insert { node list -- }
  203:     list list-next @ node list-next !
  204:     node list list-next ! ;
  205: 
  206: : list-append { node endlistp -- }
  207:     \ insert node at place pointed to by endlistp
  208:     node endlistp @ list-insert
  209:     node list-next endlistp ! ;
  210: 
  211: : list-map ( ... list xt -- ... )
  212:     \ xt ( ... node -- ... )
  213:     { xt } begin { node }
  214: 	node while
  215: 	    node xt execute
  216: 	    node list-next @
  217:     repeat ;
  218: 
  219: \ linked libraries
  220: 
  221: list%
  222:     cell% 2* field c-lib-string
  223: end-struct c-lib%
  224: 
  225: variable c-libs \ linked list of library names (without "lib")
  226: 
  227: : add-lib ( c-addr u -- )
  228: \G Add library lib@i{string} to the list of libraries, where
  229: \G @i{string} is represented by @i{c-addr u}.
  230:     c-lib% %size allocate throw dup >r
  231:     c-lib-string 2!
  232:     r> c-libs list-insert ;
  233: 
  234: : append-l ( c-addr1 u1 node -- c-addr2 u2 )
  235:     \ append " -l<nodelib>" to string1
  236:     >r s"  -l" append r> c-lib-string 2@ append ;
  237: 
  238: \ C prefix lines
  239: 
  240: \ linked list of longcstrings: [ link | count-cell | characters ]
  241: 
  242: list%
  243:     cell% field c-prefix-count
  244:     1 0   field c-prefix-chars
  245: end-struct c-prefix%
  246: 
  247: variable c-prefix-lines 0 c-prefix-lines !
  248: variable c-prefix-lines-end c-prefix-lines c-prefix-lines-end !
  249: 
  250: : print-c-prefix-line ( node -- )
  251:     dup c-prefix-chars swap c-prefix-count @ type cr ;
  252: 
  253: : print-c-prefix-lines ( -- )
  254:     c-prefix-lines @ ['] print-c-prefix-line list-map ;
  255: 
  256: : save-c-prefix-line ( c-addr u -- )
  257:     c-source-file-id @ ?dup-if
  258: 	>r 2dup r> write-line throw
  259:     then
  260:     align here 0 , c-prefix-lines-end list-append ( c-addr u )
  261:     longstring, ;
  262: 
  263: : \c ( "rest-of-line" -- ) \ gforth backslash-c
  264:     \G One line of C declarations for the C interface
  265:     -1 parse save-c-prefix-line ;
  266: 
  267: s" #include <gforth/" version-string s+ s" /libcc.h>" append ( c-addr u )
  268:   2dup save-c-prefix-line drop free throw
  269: 
  270: \ Types (for parsing)
  271: 
  272: wordlist constant libcc-types
  273: 
  274: get-current libcc-types set-current
  275: 
  276: \ index values
  277: -1
  278: const+ -- \ end of arguments
  279: const+ n \ integer cell
  280: const+ a \ address cell
  281: const+ d \ double
  282: const+ r \ float
  283: const+ func \ C function pointer
  284: const+ void
  285: drop
  286: 
  287: set-current
  288: 
  289: : parse-libcc-type ( "libcc-type" -- u )
  290:     parse-name libcc-types search-wordlist 0= -13 and throw execute ;
  291: 
  292: : parse-function-types ( "{libcc-type}" "--" "libcc-type" -- )
  293:     here 2 chars allot here begin
  294: 	parse-libcc-type dup 0>= while
  295: 	    c,
  296:     repeat
  297:     drop here swap - over char+ c!
  298:     parse-libcc-type dup 0< -32 and throw swap c! ;
  299: 
  300: : type-letter ( n -- c )
  301:     chars s" nadrfv" drop + c@ ;
  302: 
  303: \ count-stacks
  304: 
  305: : count-stacks-n ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  306:     1+ ;
  307: 
  308: : count-stacks-a ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  309:     1+ ;
  310: 
  311: : count-stacks-d ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  312:     2 + ;
  313: 
  314: : count-stacks-r ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  315:     swap 1+ swap ;
  316: 
  317: : count-stacks-func ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  318:     1+ ;
  319: 
  320: : count-stacks-void ( fp-change1 sp-change1 -- fp-change2 sp-change2 )
  321: ;
  322: 
  323: create count-stacks-types
  324: ' count-stacks-n ,
  325: ' count-stacks-a ,
  326: ' count-stacks-d ,
  327: ' count-stacks-r ,
  328: ' count-stacks-func ,
  329: ' count-stacks-void ,
  330: 
  331: : count-stacks ( pars -- fp-change sp-change )
  332:     \ pars is an addr u pair
  333:     0 0 2swap over + swap u+do
  334: 	i c@ cells count-stacks-types + @ execute
  335:     loop ;
  336: 
  337: \ gen-pars
  338: 
  339: : gen-par-n ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  340:     ." sp[" 1- dup .nb ." ]" ;
  341: 
  342: : gen-par-a ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  343:     ." (void *)(" gen-par-n ." )" ;
  344: 
  345: : gen-par-d ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  346:     ." gforth_d2ll(" gen-par-n ." ," gen-par-n ." )" ;
  347: 
  348: : gen-par-r ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  349:     swap 1- tuck ." fp[" .nb ." ]" ;
  350: 
  351: : gen-par-func ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  352:     gen-par-a ;
  353: 
  354: : gen-par-void ( fp-depth1 sp-depth1 -- fp-depth2 sp-depth2 )
  355:     -32 throw ;
  356: 
  357: create gen-par-types
  358: ' gen-par-n ,
  359: ' gen-par-a ,
  360: ' gen-par-d ,
  361: ' gen-par-r ,
  362: ' gen-par-func ,
  363: ' gen-par-void ,
  364: 
  365: : gen-par ( fp-depth1 sp-depth1 partype -- fp-depth2 sp-depth2 )
  366:     cells gen-par-types + @ execute ;
  367: 
  368: \ the call itself
  369: 
  370: : gen-wrapped-call { d: pars d: c-name fp-change1 sp-change1 -- }
  371:     c-name type ." ("
  372:     fp-change1 sp-change1 pars over + swap u+do 
  373: 	i c@ gen-par
  374: 	i 1+ i' < if
  375: 	    ." ,"
  376: 	endif
  377:     loop
  378:     2drop ." )" ;
  379: 
  380: \ calls for various kinds of return values
  381: 
  382: : gen-wrapped-void ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  383:     2dup 2>r gen-wrapped-call 2r> ;
  384: 
  385: : gen-wrapped-n ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  386:     2dup gen-par-n 2>r ." =" gen-wrapped-call 2r> ;
  387: 
  388: : gen-wrapped-a ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  389:     2dup gen-par-n 2>r ." =(Cell)" gen-wrapped-call 2r> ;
  390: 
  391: : gen-wrapped-d ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  392:     ." gforth_ll2d(" gen-wrapped-void
  393:     ." ," gen-par-n ." ," gen-par-n ." )" ;
  394: 
  395: : gen-wrapped-r ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  396:     2dup gen-par-r 2>r ." =" gen-wrapped-call 2r> ;
  397: 
  398: : gen-wrapped-func ( pars c-name fp-change1 sp-change1 -- fp-change sp-change )
  399:     gen-wrapped-a ;
  400: 
  401: create gen-wrapped-types
  402: ' gen-wrapped-n ,
  403: ' gen-wrapped-a ,
  404: ' gen-wrapped-d ,
  405: ' gen-wrapped-r ,
  406: ' gen-wrapped-func ,
  407: ' gen-wrapped-void ,
  408: 
  409: : gen-wrapped-stmt ( pars c-name fp-change1 sp-change1 ret -- fp-change sp-change )
  410:     cells gen-wrapped-types + @ execute ;
  411: 
  412: : wrapper-function-name ( addr -- c-addr u )
  413:     \ addr points to the return type index of a c-function descriptor
  414:     count { r-type } count { d: pars }
  415:     pars + count { d: c-name }
  416:     s" gforth_c_" { d: prefix }
  417:     prefix nip c-name nip + pars nip + 3 + { u }
  418:     u allocate throw { c-addr }
  419:     c-addr u
  420:     prefix front-string c-name front-string '_ front-char
  421:     pars bounds u+do
  422: 	i c@ type-letter front-char
  423:     loop
  424:     '_ front-char r-type type-letter front-char assert( dup 0= )
  425:     2drop c-addr u ;
  426: 
  427: : gen-wrapper-function ( addr -- )
  428:     \ addr points to the return type index of a c-function descriptor
  429:     dup { descriptor }
  430:     count { ret } count 2dup { d: pars } chars + count { d: c-name }
  431:     ." void " lib-modulename 2@ type ." _LTX_" descriptor wrapper-function-name 2dup type drop free throw
  432:     .\" (void)\n"
  433:     .\" {\n  Cell MAYBE_UNUSED *sp = gforth_SP;\n  Float MAYBE_UNUSED *fp = gforth_FP;\n  "
  434:     pars c-name 2over count-stacks ret gen-wrapped-stmt .\" ;\n"
  435:     ?dup-if
  436: 	."   gforth_SP = sp+" .nb .\" ;\n"
  437:     endif
  438:     ?dup-if
  439: 	."   gforth_FP = fp+" .nb .\" ;\n"
  440:     endif
  441:     .\" }\n" ;
  442: 
  443: : open-wrappers ( -- addr )
  444:     lib-filename 2@ s" .la" s+
  445:     2dup open-lib >r
  446:     drop free throw r> ;
  447: 
  448: : tempdir ( -- c-addr u )
  449:     s" TMPDIR" getenv dup 0= if
  450:         2drop s" /tmp"
  451:     then ;
  452: 
  453: : gen-filename ( x -- c-addr u )
  454:     \ generates a file basename for lib-handle-addr X
  455:     0 <<# ['] #s $10 base-execute #> 
  456:     s" gforth_c_" 2swap s+ #>> ;
  457: 
  458: : prepend-dirname ( c-addr1 u1 -- c-addr2 u2 )
  459:     tempdir s" /" s+ 2over append
  460:     2swap drop free throw ;
  461: 
  462: : c-library-name1 ( c-addr u -- )
  463:     \ set up filenames for a new library; c-addr u is the basename of
  464:     \ the library
  465:     assert( c-source-file-id @ 0= )
  466:     prepend-dirname { d: filename }
  467:     here 0 , lib-handle-addr ! filename lib-filename 2!
  468:     filename tempdir nip 1+ /string lib-modulename 2!
  469:     open-wrappers dup if
  470: 	lib-handle-addr @ !
  471: 	( 0 c-source-file-id ! ) \ already set
  472:     else
  473: 	drop
  474: 	filename s" .c" s+ 2dup w/o create-file throw dup c-source-file-id !
  475: 	['] print-c-prefix-lines swap outfile-execute
  476: 	drop free throw
  477:     endif ;
  478: 
  479: : lib-handle ( -- addr )
  480:     lib-handle-addr @ @ ;
  481: 
  482: : init-c-source-file ( -- )
  483:     lib-handle 0= if
  484: 	c-source-file-id @ 0= if
  485: 	    here gen-filename c-library-name1
  486: 	endif
  487:     endif ;
  488: 
  489: : c-source-file ( -- file-id )
  490:     c-source-file-id @ assert( dup ) ;
  491: 
  492: : notype-execute ( ... xt -- ... )
  493:     what's type { oldtype } try
  494: 	['] 2drop is type execute 0
  495:     restore
  496: 	oldtype is type
  497:     endtry
  498:     throw ;
  499: 
  500: : c-source-file-execute ( ... xt -- ... )
  501:     \ direct the output of xt to c-source-file, or nothing
  502:     lib-handle if
  503: 	notype-execute
  504:     else
  505: 	c-source-file outfile-execute
  506:     endif ;
  507: 
  508: : .lib-error ( -- )
  509:     [ifdef] lib-error
  510:         ['] cr stderr outfile-execute
  511:         lib-error ['] type stderr outfile-execute
  512:     [then] ;
  513: 
  514: DEFER compile-wrapper-function ( -- )
  515: : compile-wrapper-function1 ( -- )
  516:     lib-handle 0= if
  517: 	c-source-file close-file throw
  518: 	0 c-source-file-id !
  519: 	[ libtool-command s"  --silent --mode=compile gcc -I " s+
  520: 	s" includedir" getenv append ] sliteral
  521: 	s"  -O -c " s+ lib-filename 2@ append s" .c -o " append
  522: 	lib-filename 2@ append s" .lo" append ( c-addr u )
  523: 	\    cr 2dup type
  524: 	2dup system drop free throw $? abort" libtool compile failed"
  525: 	[ libtool-command s"  --silent --mode=link gcc -module -rpath " s+ ] sliteral
  526: 	tempdir s+ s"  " append
  527: 	lib-filename 2@ append s" .lo -o " append
  528: 	lib-filename 2@ append s" .la" append ( c-addr u )
  529: 	c-libs @ ['] append-l list-map
  530: 	\    2dup type cr
  531: 	2dup system drop free throw $? abort" libtool link failed"
  532: 	open-wrappers dup 0= if
  533: 	    .lib-error true abort" open-lib failed"
  534: 	endif
  535: 	( lib-handle ) lib-handle-addr @ !
  536:     endif
  537:     lib-filename 2@ drop free throw 0 0 lib-filename 2! ;
  538: ' compile-wrapper-function1 IS compile-wrapper-function
  539: \    s" ar rcs xxx.a xxx.o" system
  540: \    $? abort" ar generated error" ;
  541: 
  542: : link-wrapper-function { cff -- sym }
  543:     cff cff-rtype wrapper-function-name { d: wrapper-name }
  544:     wrapper-name cff cff-lha @ @ assert( dup ) lib-sym dup 0= if
  545:         .lib-error -&32 throw
  546:     endif
  547:     wrapper-name drop free throw ;
  548: 
  549: : c-function-ft ( xt-defr xt-cfr "c-name" "{libcc-type}" "--" "libcc-type" -- )
  550:     \ build time/first time action for c-function
  551:     init-c-source-file
  552:     noname create 2, lib-handle-addr @ ,
  553:     parse-name { d: c-name }
  554:     here parse-function-types c-name string,
  555:     ['] gen-wrapper-function c-source-file-execute
  556:   does> ( ... -- ... )
  557:     dup 2@ { xt-defer xt-cfr }
  558:     dup cff-lha @ @ 0= if
  559: 	compile-wrapper-function
  560:     endif
  561:     link-wrapper-function xt-cfr >body !
  562:     xt-cfr xt-defer defer!
  563:     xt-cfr execute ;
  564: 
  565: : c-function-rt ( -- )
  566:     \ run-time definition for c function; addr is the address where
  567:     \ the sym should be stored
  568:     noname create 0 ,
  569:   does> ( ... -- ... )
  570:     @ call-c ;
  571: 
  572: : c-function ( "forth-name" "c-name" "@{type@}" "--" "type" -- ) \ gforth
  573:     \G Define a Forth word @i{forth-name}.  @i{Forth-name} has the
  574:     \G specified stack effect and calls the C function @code{c-name}.
  575:     defer lastxt dup c-function-rt lastxt c-function-ft
  576:     lastxt swap defer! ;
  577: 
  578: : clear-libs ( -- )
  579: \G Clear the list of libs
  580:     c-source-file-id @ if
  581: 	compile-wrapper-function
  582:     endif
  583:     0 c-libs ! ;
  584: clear-libs
  585: 
  586: : c-library-incomplete ( -- )
  587:     true abort" Called function of unfinished named C library" ;
  588: 
  589: : c-library-name ( c-addr u -- ) \ gforth
  590: \G Start a C library interface with name @i{c-addr u}.
  591:     clear-libs
  592:     ['] c-library-incomplete is compile-wrapper-function
  593:     c-library-name1 ;
  594: 
  595: : c-library ( "name" -- ) \ gforth
  596: \G Parsing version of @code{c-library-name}
  597:     name save-mem c-library-name ;
  598: 
  599: : end-c-library ( -- ) \ gforth
  600: \G Finish and (if necessary) build the latest C library interface.
  601:     ['] compile-wrapper-function1 is compile-wrapper-function
  602:     compile-wrapper-function1 ;

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