| \ compiler definitions 14sep97jaw |
\ compiler definitions 14sep97jaw |
| |
|
| \ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006 Free Software Foundation, Inc. |
\ Copyright (C) 1995,1996,1997,1998,2000,2003,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc. |
| |
|
| \ This file is part of Gforth. |
\ This file is part of Gforth. |
| |
|
| \ Gforth is free software; you can redistribute it and/or |
\ Gforth is free software; you can redistribute it and/or |
| \ modify it under the terms of the GNU General Public License |
\ modify it under the terms of the GNU General Public License |
| \ as published by the Free Software Foundation; either version 2 |
\ as published by the Free Software Foundation, either version 3 |
| \ of the License, or (at your option) any later version. |
\ of the License, or (at your option) any later version. |
| |
|
| \ This program is distributed in the hope that it will be useful, |
\ This program is distributed in the hope that it will be useful, |
| \ GNU General Public License for more details. |
\ GNU General Public License for more details. |
| |
|
| \ You should have received a copy of the GNU General Public License |
\ You should have received a copy of the GNU General Public License |
| \ along with this program; if not, write to the Free Software |
\ along with this program. If not, see http://www.gnu.org/licenses/. |
| \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
|
| |
|
| \ \ Revisions-Log |
\ \ Revisions-Log |
| |
|
| \G puts down string as longcstring |
\G puts down string as longcstring |
| dup , here swap chars dup allot move ; |
dup , here swap chars dup allot move ; |
| |
|
| |
[IFDEF] prelude-mask |
| |
variable next-prelude |
| |
|
| |
: prelude, ( -- ) |
| |
next-prelude @ if |
| |
align next-prelude @ , |
| |
then ; |
| |
[THEN] |
| |
|
| : header, ( c-addr u -- ) \ gforth |
: header, ( c-addr u -- ) \ gforth |
| name-too-long? |
name-too-long? |
| dup max-name-length @ max max-name-length ! |
dup max-name-length @ max max-name-length ! |
| |
[ [IFDEF] prelude-mask ] prelude, [ [THEN] ] |
| align here last ! |
align here last ! |
| [ has? flash [IF] ] |
[ has? ec [IF] ] |
| -1 A, |
-1 A, |
| [ [ELSE] ] |
[ [ELSE] ] |
| current @ 1 or A, \ link field; before revealing, it contains the |
current @ 1 or A, \ link field; before revealing, it contains the |
| string, |
string, |
| [ [ELSE] ] |
[ [ELSE] ] |
| longstring, alias-mask lastflags cset |
longstring, alias-mask lastflags cset |
| |
next-prelude @ 0<> prelude-mask and lastflags cset |
| |
next-prelude off |
| [ [THEN] ] |
[ [THEN] ] |
| cfalign ; |
cfalign ; |
| |
|
| is basic-block-end |
is basic-block-end |
| [THEN] |
[THEN] |
| |
|
| |
has? primcentric [IF] |
| has? peephole [IF] |
has? peephole [IF] |
| |
|
| \ dynamic only |
\ dynamic only |
| : peephole-compile, ( xt -- ) |
: peephole-compile, ( xt -- ) |
| \ compile xt, appending its code to the current dynamic superinstruction |
\ compile xt, appending its code to the current dynamic superinstruction |
| here swap , compile-prim1 ; |
here swap , compile-prim1 ; |
| |
[ELSE] |
| |
: peephole-compile, ( xt -- addr ) @ , ; |
| |
[THEN] |
| |
|
| : compile-to-prims, ( xt -- ) |
: compile-to-prims, ( xt -- ) |
| \G compile xt to use primitives (and their peephole optimization) |
\G compile xt to use primitives (and their peephole optimization) |
| douser: OF >body @ ['] useraddr peephole-compile, , EXIT ENDOF |
douser: OF >body @ ['] useraddr peephole-compile, , EXIT ENDOF |
| dodefer: OF >body ['] lit-perform peephole-compile, , EXIT ENDOF |
dodefer: OF >body ['] lit-perform peephole-compile, , EXIT ENDOF |
| dofield: OF >body @ ['] lit+ peephole-compile, , EXIT ENDOF |
dofield: OF >body @ ['] lit+ peephole-compile, , EXIT ENDOF |
| |
doabicode: OF >body ['] abi-call peephole-compile, , EXIT ENDOF |
| \ dofield: OF >body @ POSTPONE literal ['] + peephole-compile, EXIT ENDOF |
\ dofield: OF >body @ POSTPONE literal ['] + peephole-compile, EXIT ENDOF |
| \ code words and ;code-defined words (code words could be optimized): |
\ code words and ;code-defined words (code words could be optimized): |
| dup in-dictionary? IF drop POSTPONE literal ['] execute peephole-compile, EXIT THEN |
dup in-dictionary? IF drop POSTPONE literal ['] execute peephole-compile, EXIT THEN |
| \ \ compiler loop |
\ \ compiler loop |
| |
|
| : compiler1 ( c-addr u -- ... xt ) |
: compiler1 ( c-addr u -- ... xt ) |
| 2dup find-name dup |
2dup find-name [ [IFDEF] prelude-mask ] run-prelude [ [THEN] ] dup |
| if ( c-addr u nt ) |
if ( c-addr u nt ) |
| nip nip name>comp |
nip nip name>comp |
| else |
else |