Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / fm / lib / chains.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: chains.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)chains.fth 1.3 01/08/07
43purpose:
44copyright: Copyright 2001 Sun Microsystems, Inc All rights reserved
45
46\ Provide 4 new compile methods:
47\
48\ chain: \ name
49\ create a new headerless chain.
50\ Add a call to 'name' before dropping into the new definition if it
51\ exists. stand-init is an example of one such chain.
52\ terminate with ';' as for a normal colon definition.
53\ Note: a chained word will always be available in the forth vocabulary
54\ at compile time regardless of what vocabulary it was defined under.
55\
56\ tail-chain: \ name
57\ create a new headerless chain.
58\ terminate with 'tail;' which will compile in a call to the previous
59\ definition of 'name' before returning.
60\ execute-buffer is an example of a tail-chain: where the routine
61\ decides to call the previous routine *after* executing some internal
62\ code.
63\
64\ tail;
65\ Part of 'tail-chain:' complete a tail-chain call.
66\ It is an error to break a tail-chain by terminating without a 'tail;'
67\ Detection will only happen upon the next tail-chain call.
68\
69\ overload: \ name
70\ create a new routine, supressing warnings for the creation.
71\ It is an error to declare a routine as 'overload'ed if it does not
72\ already exist.
73\ The new routine is headered or headerless depending upon the current
74\ header state.
75\
76\
77\ Usage examples:
78\
79\ 1 chain: foo ." hello " ; \ foo1
80\ chain: foo ." world" ; \ foo2
81\
82\ Executing foo will print 'hello world' because foo2 calls foo1 before
83\ executing any internal code.
84\
85\ 2 tail-chain: bar ." world" tail; \ bar1
86\ tail-chain: bar ." hello " tail; \ bar2
87\
88\ Executing bar will also print 'hello world' this time bar2 prints
89\ " hello" and then when finished (tail;) calls bar1 which prints "world"
90\
91\ Useage of tail-chain: should be deprecated. Its easy to make mistakes
92\ execute-buffer is a good use, others probably are not.
93\
94\ 3 : xxx ." xxx" ;
95\ : yyy xxx ." yyy" ;
96\ overload: xxx ['] xxx catch drop ;
97\
98\ yyy wants to call the raw routine xxx, but the official interface to
99\ xxx is supposed to be catch protected, so xxx is intentionally
100\ overloaded to pretect its callers from 'throw'.
101\
102\ However for this specific case renaming the first xxx to (xxx) would
103\ have been a better choice and then no overload: is required.
104\
105\ Everything else is private DONT call it.
106\
107headers transient
108
109variable chain-acf
110h# 20 alloc-mem value chain-name
111h# 200 alloc-mem value tail-chain-info
112
113[ifnexist] headerless?
1140 value headerless?
115warning @ warning off
116: headers 0 is headerless? headers ;
117: headerless true is headerless? headerless ;
118warning !
119[then]
120
121: (make-chain) ( -- ) chain-acf @ ?dup if token, then chain-acf off ;
122
123: (chain-header) ( -- ) chain-name count $header acf-align ;
124
125: (chain:) ( str,len -- )
126 chain-name pack count $find 0= if 2drop false then chain-acf !
127[ifndef] show-duplicates? warning @ >r warning off [then]
128 ['] header behavior >r ['] (chain-header) is header : r> is header
129[ifndef] show-duplicates? r> warning ! [then]
130;
131
132: (headerless-chain:) ( str,len -- )
133 get-current >r ['] forth set-current ( str, len) ( r: c-voc )
134 headerless? >r headerless (chain:) r> 0= if headers then ( ) ( r: c-voc )
135 r> set-current ( ) ( r: )
136;
137
138: chain: ( -- ) \ Name
139 safe-parse-word (headerless-chain:) (make-chain)
140; immediate
141
142: overload: ( -- ) \ Name
143 safe-parse-word 2dup $find if ( str,len acf )
144 drop (chain:) ( )
145 else ( str,len )
146 where ." Error: overload of " type ." not neccessary" cr
147 abort ( )
148 then
149; immediate
150
151[ifexist] file-name
152: tail-chain: ( -- ) \ Name
153 safe-parse-word ( str,len )
154 tail-chain-info c@ if ( str,len )
155 tail-chain-info count type
156 0 tail-chain-info c! abort
157 then
158 source-id ?dup 0<> if ( str,len )
159 dup file-name tail-chain-info pack >r ( str,len id )
160 " :" r@ $cat file-line ( str,len id )
161 base @ >r decimal (.) r> base ! r@ $cat ( str,len )
162 " : Error: Broken tail call for " r> $cat ( str,len )
163 then ( str,len )
164 2dup tail-chain-info $cat ( str,len )
165 (headerless-chain:) ( )
166; immediate
167
168: tail; ( -- ) (make-chain) postpone ; 0 tail-chain-info c! ; immediate
169[then]
170
171resident headerless
172
173