[gforth] / gforth / code.fs  

gforth: gforth/code.fs


1 : anton 1.1 \ ASSEMBLER, CODE etc.
2 :    
3 : anton 1.17 \ Copyright (C) 1995,1996,1997,1999,2003,2007 Free Software Foundation, Inc.
4 : anton 1.2
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 : anton 1.16 \ as published by the Free Software Foundation, either version 3
10 : anton 1.2 \ 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 : anton 1.16 \ along with this program. If not, see http://www.gnu.org/licenses/.
19 : anton 1.2
20 : anton 1.1 \ 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 : anton 1.21 \g A vocubulary: Replaces the wordlist at the top of the search order
26 :     \g with the assembler wordlist.
27 : anton 1.1
28 : crook 1.9 : init-asm ( -- ) \ gforth
29 : anton 1.21 \g Pushes the assembler wordlist on the search order.
30 : anton 1.1 also assembler ;
31 : anton 1.21
32 : anton 1.7 : code ( "name" -- colon-sys ) \ tools-ext
33 : anton 1.21 \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 : anton 1.6 header
40 : anton 1.12 here >body cfa,
41 : anton 1.6 defstart init-asm ;
42 : anton 1.1
43 : dvdkhlng 1.19 [ifdef] doabicode:
44 : dvdkhlng 1.20 : 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 : anton 1.21 \G Cell *function(Cell *sp, Float **fpp);
49 : dvdkhlng 1.20 \G @end example
50 : anton 1.21 \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 : dvdkhlng 1.18 header
54 :     doabicode: cfa,
55 :     defstart init-asm ;
56 : dvdkhlng 1.19 [endif]
57 : dvdkhlng 1.18
58 : anton 1.1 : (;code) ( -- ) \ gforth
59 :     \ execution semantics of @code{;code}
60 : anton 1.15 r> latestxt code-address! ;
61 : anton 1.1
62 : anton 1.6 :noname ( -- colon-sys )
63 : anton 1.15 align here latestxt code-address!
64 : anton 1.6 defstart init-asm ;
65 : pazsan 1.4 :noname ( colon-sys1 -- colon-sys2 ) \ tools-ext semicolon-code
66 : anton 1.1 ( create the [;code] part of a low level defining word )
67 : anton 1.13 ;-hook postpone (;code) basic-block-end finish-code ?struc postpone [
68 : anton 1.3 defstart init-asm ;
69 : anton 1.7 interpret/compile: ;code ( compilation. colon-sys1 -- colon-sys2 ) \ tools-ext semicolon-code
70 : anton 1.21 \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}, but Gforth does not have a
73 :     \g @code{;abi-code} yet. As a workaround, you can use @code{does> foo
74 :     \g ;} instead, where @code{foo} is defined with @code{abi-code}.
75 : anton 1.1
76 :     : end-code ( colon-sys -- ) \ gforth end_code
77 : anton 1.21 \G End a code definition. Note that you have to assemble the
78 :     \G return from the ABI call (for @code{abi-code}) or the dispatch
79 :     \G to the next VM instruction (for @code{code} and @code{;code})
80 :     \G yourself.
81 : anton 1.15 latestxt here over - flush-icache
82 : anton 1.1 previous ?struc reveal ;
83 : crook 1.9

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help