Annotation of gforth/vmgen-ex2/mini-inst.vmg, revision 1.6
1.1 anton 1: \ mini.inst is generated automatically from mini-inst.vmg and mini-super.vmg
2: \ example .vmg file
3:
1.6 ! anton 4: \ Copyright (C) 2001,2002,2003,2007 Free Software Foundation, Inc.
1.1 anton 5:
6: \ This file is part of Gforth.
7:
8: \ Gforth is free software; you can redistribute it and/or
9: \ modify it under the terms of the GNU General Public License
1.5 anton 10: \ as published by the Free Software Foundation, either version 3
1.1 anton 11: \ of the License, or (at your option) any later version.
12:
13: \ This program is distributed in the hope that it will be useful,
14: \ but WITHOUT ANY WARRANTY; without even the implied warranty of
15: \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: \ GNU General Public License for more details.
17:
18: \ You should have received a copy of the GNU General Public License
1.5 anton 19: \ along with this program. If not, see http://www.gnu.org/licenses/.
1.1 anton 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" long" 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:
1.2 anton 40: add ( i1 i2 -- i )
1.1 anton 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);
1.2 anton 80: INST_TAIL;
1.1 anton 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: \ The following VM instructions also explicitly reference sp and
101: \ therefore may have to do something about spTOS caching.
102:
103: call ( #target #iadjust -- targetret aoldfp )
104: /* IF_spTOS(sp[2] = spTOS);*/ /* unnecessary; vmgen inserts a flush anyway */
105: targetret = IP;
106: SET_IP(target);
107: aoldfp = fp;
108: sp = (Cell *)(((char *)sp)+iadjust);
109: fp = (char *)sp;
110: /* IF_spTOS(spTOS = sp[0]); */ /* dead, thus unnecessary; vmgen copies aoldfp there */
111:
112: return ( #iadjust target afp i1 -- i2 )
113: /* IF_spTOS(sp[-2] = spTOS); */ /* unnecessary; that stack item is dead */
114: SET_IP(target);
115: sp = (Cell *)(((char *)sp)+iadjust);
116: fp = afp;
117: i2=i1;
118: /* IF_spTOS(spTOS = sp[0]); */ /* dead, thus unnecessary; vmgen copies i2 there */
119:
120: \ loadlocal and storelocal access stack items below spTOS, so we can
121: \ ignore spTOS caching.
122:
123: loadlocal ( #ioffset -- i )
124: vm_Cell2i(*(Cell *)(fp+ioffset),i);
125:
126: storelocal ( #ioffset i -- )
127: vm_i2Cell(i,*(Cell *)(fp+ioffset));
128:
129: end ( i -- )
130: /* SUPER_END would increment the next BB count (because IP points there);
131: this would be a problem if there is no following BB.
132: Instead, we do the following to add an end point for the current BB: */
133: #ifdef VM_PROFILING
134: block_insert(IP); /* we also do this at compile time, so this is unnecessary */
135: #endif
136: return i;
137:
138: include(mini-super.vmg)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>