Annotation of gforth/code.fs, revision 1.22

1.1       anton       1: \ ASSEMBLER, CODE etc.
                      2: 
1.17      anton       3: \ Copyright (C) 1995,1996,1997,1999,2003,2007 Free Software Foundation, Inc.
1.2       anton       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
1.16      anton       9: \ as published by the Free Software Foundation, either version 3
1.2       anton      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
1.16      anton      18: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.2       anton      19: 
1.1       anton      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
1.21      anton      25: \g A vocubulary: Replaces the wordlist at the top of the search order
                     26: \g with the assembler wordlist.
1.1       anton      27: 
1.9       crook      28: : init-asm ( -- ) \ gforth
1.21      anton      29: \g Pushes the assembler wordlist on the search order.
1.1       anton      30:     also assembler ;
1.21      anton      31:     
1.7       anton      32: : code ( "name" -- colon-sys ) \ tools-ext
1.21      anton      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.
1.6       anton      39:     header
1.12      anton      40:     here >body cfa,
1.6       anton      41:     defstart init-asm ;
1.1       anton      42: 
1.19      dvdkhlng   43: [ifdef] doabicode:
1.22    ! anton      44: : abi-code ( "name" -- colon-sys )     \ gforth        abi-code
1.20      dvdkhlng   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
1.21      anton      48:    \G Cell *function(Cell *sp, Float **fpp);
1.20      dvdkhlng   49:    \G @end example
1.21      anton      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).
1.18      dvdkhlng   53:     header  
                     54:     doabicode: cfa,
                     55:     defstart init-asm ;
1.19      dvdkhlng   56: [endif]
1.18      dvdkhlng   57: 
1.1       anton      58: : (;code) ( -- ) \ gforth
                     59:     \ execution semantics of @code{;code}
1.15      anton      60:     r> latestxt code-address! ;
1.1       anton      61: 
1.6       anton      62: :noname ( -- colon-sys )
1.15      anton      63:     align here latestxt code-address!
1.6       anton      64:     defstart init-asm ;
1.4       pazsan     65: :noname ( colon-sys1 -- colon-sys2 )   \ tools-ext     semicolon-code
1.1       anton      66:     ( create the [;code] part of a low level defining word )
1.13      anton      67:     ;-hook postpone (;code) basic-block-end finish-code ?struc postpone [
1.3       anton      68:     defstart init-asm ;
1.7       anton      69: interpret/compile: ;code ( compilation. colon-sys1 -- colon-sys2 )     \ tools-ext     semicolon-code
1.21      anton      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
1.22    ! anton      72: \g caveats apply as for @code{code}, so we recommend using
        !            73: \g @code{;abi-code} instead.
1.1       anton      74: 
1.22    ! anton      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:     
1.1       anton      83: : end-code ( colon-sys -- )    \ gforth        end_code
1.21      anton      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.
1.15      anton      88:     latestxt here over - flush-icache
1.1       anton      89:     previous ?struc reveal ;

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