File:  [gforth] / gforth / code.fs
Revision 1.22: download - view: text, annotated - select for diffs
Sun Apr 25 18:27:09 2010 UTC (13 years, 11 months ago) by anton
Branches: MAIN
CVS tags: HEAD
added ;ABI-CODE (not yet documented, not interactively usable yet)
deleted does-handler and doesjump stuff (unused)
moved abi-call to a new group
Extended AMD64 calling convention documentation

    1: \ ASSEMBLER, CODE etc.
    2: 
    3: \ Copyright (C) 1995,1996,1997,1999,2003,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: \ does not include the actual assembler (which is machine-dependent),
   21: \ only words like CODE that are implementation-dependent, but can be
   22: \ defined for all machines.
   23: 
   24: vocabulary assembler ( -- ) \ tools-ext
   25: \g A vocubulary: Replaces the wordlist at the top of the search order
   26: \g with the assembler wordlist.
   27: 
   28: : init-asm ( -- ) \ gforth
   29: \g Pushes the assembler wordlist on the search order.
   30:     also assembler ;
   31:     
   32: : code ( "name" -- colon-sys )	\ tools-ext
   33:     \G Start a native code definition that runs in the context of the
   34:     \G Gforth virtual machine (engine).  Such a definition is not
   35:     \G portable between Gforth installations, so we recommend using
   36:     \G @code{abi-code} instead of @code{code}.  You have to end a
   37:     \G @code{code} definition with a dispatch to the next virtual
   38:     \G machine instruction.
   39:     header
   40:     here >body cfa,
   41:     defstart init-asm ;
   42: 
   43: [ifdef] doabicode:
   44: : abi-code ( "name" -- colon-sys )	\ gforth	abi-code
   45:    \G Start a native code definition that is called using the platform's
   46:    \G ABI conventions corresponding to the C-prototype:
   47:    \G @example
   48:    \G Cell *function(Cell *sp, Float **fpp);
   49:    \G @end example
   50:    \G The FP stack pointer is passed in by providing a reference to a
   51:    \G memory location containing the FP stack pointer and is passed
   52:    \G out by storing the changed FP stack pointer there (if necessary).
   53:     header  
   54:     doabicode: cfa,
   55:     defstart init-asm ;
   56: [endif]
   57: 
   58: : (;code) ( -- ) \ gforth
   59:     \ execution semantics of @code{;code}
   60:     r> latestxt code-address! ;
   61: 
   62: :noname ( -- colon-sys )
   63:     align here latestxt code-address!
   64:     defstart init-asm ;
   65: :noname ( colon-sys1 -- colon-sys2 )	\ tools-ext	semicolon-code
   66:     ( create the [;code] part of a low level defining word )
   67:     ;-hook postpone (;code) basic-block-end finish-code ?struc postpone [
   68:     defstart init-asm ;
   69: interpret/compile: ;code ( compilation. colon-sys1 -- colon-sys2 )	\ tools-ext	semicolon-code
   70: \g The code after @code{;code} becomes the behaviour of the last
   71: \g defined word (which must be a @code{create}d word).  The same
   72: \g caveats apply as for @code{code}, so we recommend using
   73: \g @code{;abi-code} instead.
   74: 
   75: [ifdef] do;abicode: 
   76: : !;abi-code ( addr -- )
   77:     latestxt do;abicode: any-code! ;
   78: 
   79: : ;abi-code ( -- ) \ gforth semicolon-abi-code
   80:     ['] !;abi-code does>-like postpone [ init-asm ; immediate
   81: [then]
   82:     
   83: : end-code ( colon-sys -- )	\ gforth	end_code
   84:     \G End a code definition.  Note that you have to assemble the
   85:     \G return from the ABI call (for @code{abi-code}) or the dispatch
   86:     \G to the next VM instruction (for @code{code} and @code{;code})
   87:     \G yourself.
   88:     latestxt here over - flush-icache
   89:     previous ?struc reveal ;

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