Annotation of gforth/vmgen-ex/mini.vmg, revision 1.1
1.1 ! anton 1: \ example .vmg file
! 2:
! 3: \ Copyright (C) 2001 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 2
! 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, write to the Free Software
! 19: \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
! 20:
! 21:
! 22: \ WARNING: This file is processed by m4. Make sure your identifiers
! 23: \ don't collide with m4's (e.g. by undefining them).
! 24:
! 25:
! 26: \ comments start with "\ "
! 27:
! 28: \ stack definitions:
! 29: \E stack data-stack sp Cell
! 30:
! 31: \ stack prefix definitions
! 32: \E inst-stream stack-prefix #
! 33:
! 34: \ type prefix definitions:
! 35: \E s" Cell" single data-stack type-prefix i
! 36: \E s" char *" single data-stack type-prefix a
! 37: \E s" Inst *" single data-stack type-prefix target
! 38:
! 39: \ simple VM instructions:
! 40: add ( i1 i2 -- i )
! 41: i = i1+i2;
! 42:
! 43: sub ( i1 i2 -- i )
! 44: i = i1-i2;
! 45:
! 46: mul ( i1 i2 -- i )
! 47: i = i1*i2;
! 48:
! 49: and ( i1 i2 -- i )
! 50: i = i1 & i2;
! 51:
! 52: or ( i1 i2 -- i )
! 53: i = i1 | i2;
! 54:
! 55: lessthan ( i1 i2 -- i )
! 56: i = i1<i2;
! 57:
! 58: equals ( i1 i2 -- i )
! 59: i = i1==i2;
! 60:
! 61: not ( i1 -- i2 )
! 62: i2 = !i1;
! 63:
! 64: negate ( i1 -- i2 )
! 65: i2 = -i1;
! 66:
! 67: lit ( #i -- i )
! 68:
! 69: drop ( i -- )
! 70:
! 71: print ( i -- )
! 72: printf("%ld\n", i);
! 73:
! 74: branch ( #target -- )
! 75: SET_IP(target);
! 76:
! 77: zbranch ( #target i -- )
! 78: if (i==0) {
! 79: SET_IP(target);
! 80: TAIL;
! 81: }
! 82:
! 83: \ The stack is organized as follows:
! 84: \ The stack grows downwards; a stack usually looks like this:
! 85:
! 86: \ higher addresses
! 87: \ --------------------- bottom of stack
! 88: \ locals of main
! 89: \ return address (points to VM code after call)
! 90: \ +->oldfp (NULL)
! 91: \ | intermediate results (e.g., 1 for a call like 1+foo(...))
! 92: \ | arguments passed to the called function
! 93: \ | locals of the called function
! 94: \ | return address (points to VM code after call)
! 95: \ +--oldfp <-- fp
! 96: \ intermediate results <-- sp
! 97: \ ---------------------- top of stack
! 98: \ lower addresses
! 99:
! 100: call ( #target #iadjust -- targetret aoldfp )
! 101: targetret = IP;
! 102: SET_IP(target);
! 103: aoldfp = fp;
! 104: sp = (Cell *)(((char *)sp)+iadjust);
! 105: fp = (char *)sp;
! 106:
! 107: return ( #iadjust target afp i1 -- i2 )
! 108: SET_IP(target);
! 109: sp = (Cell *)(((char *)sp)+iadjust);
! 110: fp = afp;
! 111: i2=i1;
! 112:
! 113: loadlocal ( #ioffset -- i )
! 114: i = *(Cell *)(fp+ioffset);
! 115:
! 116: storelocal ( #ioffset i -- )
! 117: *(Cell *)(fp+ioffset) = i;
! 118:
! 119: end ( i -- )
! 120: /* SUPER_END would increment the next BB count (because IP points there);
! 121: this would be a problem if there is no following BB.
! 122: Instead, we do the following to add an end point for the current BB: */
! 123: #ifdef VM_PROFILING
! 124: block_insert(IP); /* we also do this at compile time;
! 125: only one of them is necessary */
! 126: #endif
! 127: return i;
! 128:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>