1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate * All rights reserved.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*7c478bd9Sstevel@tonic-gate
29*7c478bd9Sstevel@tonic-gate #include <stdio.h>
30*7c478bd9Sstevel@tonic-gate #include <string.h>
31*7c478bd9Sstevel@tonic-gate
32*7c478bd9Sstevel@tonic-gate #include <fcode/private.h>
33*7c478bd9Sstevel@tonic-gate #include <fcode/log.h>
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gate #define NUM_DEFAULT_ACTIONS 7
36*7c478bd9Sstevel@tonic-gate
37*7c478bd9Sstevel@tonic-gate /*
38*7c478bd9Sstevel@tonic-gate * value_fetch and value_store are the same as "fetch" and "store", but
39*7c478bd9Sstevel@tonic-gate * we'll leave them implemented here for now.
40*7c478bd9Sstevel@tonic-gate */
41*7c478bd9Sstevel@tonic-gate static void
value_fetch(fcode_env_t * env)42*7c478bd9Sstevel@tonic-gate value_fetch(fcode_env_t *env)
43*7c478bd9Sstevel@tonic-gate {
44*7c478bd9Sstevel@tonic-gate variable_t *addr;
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "value_fetch");
47*7c478bd9Sstevel@tonic-gate addr = (variable_t *)POP(DS);
48*7c478bd9Sstevel@tonic-gate PUSH(DS, (variable_t)*addr);
49*7c478bd9Sstevel@tonic-gate }
50*7c478bd9Sstevel@tonic-gate
51*7c478bd9Sstevel@tonic-gate static void
value_store(fcode_env_t * env)52*7c478bd9Sstevel@tonic-gate value_store(fcode_env_t *env)
53*7c478bd9Sstevel@tonic-gate {
54*7c478bd9Sstevel@tonic-gate variable_t *addr;
55*7c478bd9Sstevel@tonic-gate
56*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "value_store");
57*7c478bd9Sstevel@tonic-gate addr = (variable_t *)POP(DS);
58*7c478bd9Sstevel@tonic-gate *addr = (variable_t)POP(DS);
59*7c478bd9Sstevel@tonic-gate }
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate void *
get_internal_address(fcode_env_t * env)62*7c478bd9Sstevel@tonic-gate get_internal_address(fcode_env_t *env)
63*7c478bd9Sstevel@tonic-gate {
64*7c478bd9Sstevel@tonic-gate int *ptr;
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "get_internal_address");
67*7c478bd9Sstevel@tonic-gate ptr = (int *)POP(DS);
68*7c478bd9Sstevel@tonic-gate if (*ptr > 0)
69*7c478bd9Sstevel@tonic-gate return ((uchar_t *)env + *ptr);
70*7c478bd9Sstevel@tonic-gate return ((uchar_t *)MYSELF - *ptr);
71*7c478bd9Sstevel@tonic-gate }
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate void
internal_env_fetch(fcode_env_t * env)74*7c478bd9Sstevel@tonic-gate internal_env_fetch(fcode_env_t *env)
75*7c478bd9Sstevel@tonic-gate {
76*7c478bd9Sstevel@tonic-gate instance_t **iptr;
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "internal_env_fetch");
79*7c478bd9Sstevel@tonic-gate iptr = (instance_t **)get_internal_address(env);
80*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)(*iptr));
81*7c478bd9Sstevel@tonic-gate }
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate void
internal_env_store(fcode_env_t * env)84*7c478bd9Sstevel@tonic-gate internal_env_store(fcode_env_t *env)
85*7c478bd9Sstevel@tonic-gate {
86*7c478bd9Sstevel@tonic-gate instance_t **iptr;
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "internal_env_store");
89*7c478bd9Sstevel@tonic-gate iptr = (instance_t **)get_internal_address(env);
90*7c478bd9Sstevel@tonic-gate *iptr = (instance_t *)POP(DS);
91*7c478bd9Sstevel@tonic-gate }
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gate void
internal_env_addr(fcode_env_t * env)94*7c478bd9Sstevel@tonic-gate internal_env_addr(fcode_env_t *env)
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate fstack_t d;
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "internal_env_addr");
99*7c478bd9Sstevel@tonic-gate d = (fstack_t)get_internal_address(env);
100*7c478bd9Sstevel@tonic-gate PUSH(DS, d);
101*7c478bd9Sstevel@tonic-gate }
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate void
do_buffer_data(fcode_env_t * env,token_t * d,int instance)104*7c478bd9Sstevel@tonic-gate do_buffer_data(fcode_env_t *env, token_t *d, int instance)
105*7c478bd9Sstevel@tonic-gate {
106*7c478bd9Sstevel@tonic-gate if (!*d) { /* check if buffer not alloc'ed yet */
107*7c478bd9Sstevel@tonic-gate token_t *buf;
108*7c478bd9Sstevel@tonic-gate
109*7c478bd9Sstevel@tonic-gate if (instance) {
110*7c478bd9Sstevel@tonic-gate int n, off;
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate n = TOKEN_ROUNDUP(d[1]);
113*7c478bd9Sstevel@tonic-gate buf = alloc_instance_data(env, UINIT_DATA, n, &off);
114*7c478bd9Sstevel@tonic-gate memset(buf, 0, d[1]);
115*7c478bd9Sstevel@tonic-gate } else {
116*7c478bd9Sstevel@tonic-gate buf = (token_t *)HERE;
117*7c478bd9Sstevel@tonic-gate set_here(env, HERE + d[1], "do_buffer_data");
118*7c478bd9Sstevel@tonic-gate }
119*7c478bd9Sstevel@tonic-gate *d = (token_t)buf;
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate PUSH(DS, *d);
122*7c478bd9Sstevel@tonic-gate }
123*7c478bd9Sstevel@tonic-gate
124*7c478bd9Sstevel@tonic-gate void
ibuffer_init(fcode_env_t * env)125*7c478bd9Sstevel@tonic-gate ibuffer_init(fcode_env_t *env)
126*7c478bd9Sstevel@tonic-gate {
127*7c478bd9Sstevel@tonic-gate token_t *d;
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate d = get_instance_address(env);
130*7c478bd9Sstevel@tonic-gate do_buffer_data(env, d, 1);
131*7c478bd9Sstevel@tonic-gate }
132*7c478bd9Sstevel@tonic-gate
133*7c478bd9Sstevel@tonic-gate void
buffer_init(fcode_env_t * env)134*7c478bd9Sstevel@tonic-gate buffer_init(fcode_env_t *env)
135*7c478bd9Sstevel@tonic-gate {
136*7c478bd9Sstevel@tonic-gate token_t *d;
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "buffer_init");
139*7c478bd9Sstevel@tonic-gate d = (token_t *)POP(DS);
140*7c478bd9Sstevel@tonic-gate do_buffer_data(env, d, 0);
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate void
do_defer(fcode_env_t * env)144*7c478bd9Sstevel@tonic-gate do_defer(fcode_env_t *env)
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate fetch(env);
147*7c478bd9Sstevel@tonic-gate execute(env);
148*7c478bd9Sstevel@tonic-gate }
149*7c478bd9Sstevel@tonic-gate
150*7c478bd9Sstevel@tonic-gate token_t *value_actions[NUM_DEFAULT_ACTIONS];
151*7c478bd9Sstevel@tonic-gate token_t value_defines[NUM_DEFAULT_ACTIONS][3] = {
152*7c478bd9Sstevel@tonic-gate { (token_t)&value_fetch, (token_t)&value_store, (token_t)&noop },
153*7c478bd9Sstevel@tonic-gate { (token_t)&fetch_instance_data, (token_t)&set_instance_data,
154*7c478bd9Sstevel@tonic-gate (token_t)&address_instance_data },
155*7c478bd9Sstevel@tonic-gate { (token_t)&internal_env_fetch, (token_t)&internal_env_store,
156*7c478bd9Sstevel@tonic-gate (token_t)&internal_env_addr },
157*7c478bd9Sstevel@tonic-gate { (token_t)&do_defer, (token_t)&store, (token_t)&noop },
158*7c478bd9Sstevel@tonic-gate { (token_t)&idefer_exec, (token_t)&set_instance_data,
159*7c478bd9Sstevel@tonic-gate (token_t)&address_instance_data },
160*7c478bd9Sstevel@tonic-gate { (token_t)&buffer_init, (token_t)&two_drop, (token_t)&noop, },
161*7c478bd9Sstevel@tonic-gate { (token_t)&ibuffer_init, (token_t)&two_drop,
162*7c478bd9Sstevel@tonic-gate (token_t)&address_instance_data }
163*7c478bd9Sstevel@tonic-gate };
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate int
run_action(fcode_env_t * env,acf_t acf,int action)166*7c478bd9Sstevel@tonic-gate run_action(fcode_env_t *env, acf_t acf, int action)
167*7c478bd9Sstevel@tonic-gate {
168*7c478bd9Sstevel@tonic-gate token_t *p = (token_t *)acf;
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate if ((p[0] & 1) == 0) {
171*7c478bd9Sstevel@tonic-gate log_message(MSG_WARN, "run_action: acf: %p @acf: %p not"
172*7c478bd9Sstevel@tonic-gate " indirect\n", acf, p[0]);
173*7c478bd9Sstevel@tonic-gate return (1);
174*7c478bd9Sstevel@tonic-gate }
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate p = (token_t *)(p[0] & ~1);
177*7c478bd9Sstevel@tonic-gate
178*7c478bd9Sstevel@tonic-gate if (action >= p[1] || action < 0) {
179*7c478bd9Sstevel@tonic-gate log_message(MSG_WARN, "run_action: acf: %p action: %d"
180*7c478bd9Sstevel@tonic-gate " out of range: 0-%d\n", acf, action, (int)p[1]);
181*7c478bd9Sstevel@tonic-gate return (1);
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate
184*7c478bd9Sstevel@tonic-gate if (p[0] == (token_t)&do_default_action) {
185*7c478bd9Sstevel@tonic-gate fstack_t d;
186*7c478bd9Sstevel@tonic-gate
187*7c478bd9Sstevel@tonic-gate d = (fstack_t)p[action+2];
188*7c478bd9Sstevel@tonic-gate PUSH(DS, d);
189*7c478bd9Sstevel@tonic-gate execute(env);
190*7c478bd9Sstevel@tonic-gate return (0);
191*7c478bd9Sstevel@tonic-gate }
192*7c478bd9Sstevel@tonic-gate log_message(MSG_WARN, "run_action: acf: %p/%p not default action\n",
193*7c478bd9Sstevel@tonic-gate acf, p[0]);
194*7c478bd9Sstevel@tonic-gate return (1);
195*7c478bd9Sstevel@tonic-gate }
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate void
do_default_action(fcode_env_t * env)198*7c478bd9Sstevel@tonic-gate do_default_action(fcode_env_t *env)
199*7c478bd9Sstevel@tonic-gate {
200*7c478bd9Sstevel@tonic-gate acf_t a;
201*7c478bd9Sstevel@tonic-gate
202*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "do_default_action");
203*7c478bd9Sstevel@tonic-gate a = (acf_t)TOS;
204*7c478bd9Sstevel@tonic-gate (void) run_action(env, (a-1), 0);
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate void
do_set_action(fcode_env_t * env)208*7c478bd9Sstevel@tonic-gate do_set_action(fcode_env_t *env)
209*7c478bd9Sstevel@tonic-gate {
210*7c478bd9Sstevel@tonic-gate acf_t a = (acf_t)TOS;
211*7c478bd9Sstevel@tonic-gate
212*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 1, "do_set_action");
213*7c478bd9Sstevel@tonic-gate TOS += sizeof (acf_t);
214*7c478bd9Sstevel@tonic-gate (void) run_action(env, a, 1);
215*7c478bd9Sstevel@tonic-gate }
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate void
action_colon(fcode_env_t * env)218*7c478bd9Sstevel@tonic-gate action_colon(fcode_env_t *env)
219*7c478bd9Sstevel@tonic-gate {
220*7c478bd9Sstevel@tonic-gate token_roundup(env, "action_colon");
221*7c478bd9Sstevel@tonic-gate env->action_ptr[env->action_count] = (token_t)HERE;
222*7c478bd9Sstevel@tonic-gate COMPILE_TOKEN(&do_colon);
223*7c478bd9Sstevel@tonic-gate env->action_count++;
224*7c478bd9Sstevel@tonic-gate env->state |= 1;
225*7c478bd9Sstevel@tonic-gate }
226*7c478bd9Sstevel@tonic-gate
227*7c478bd9Sstevel@tonic-gate void
actions(fcode_env_t * env)228*7c478bd9Sstevel@tonic-gate actions(fcode_env_t *env)
229*7c478bd9Sstevel@tonic-gate {
230*7c478bd9Sstevel@tonic-gate int n;
231*7c478bd9Sstevel@tonic-gate token_t *d;
232*7c478bd9Sstevel@tonic-gate
233*7c478bd9Sstevel@tonic-gate token_roundup(env, "actions");
234*7c478bd9Sstevel@tonic-gate d = (token_t *)HERE;
235*7c478bd9Sstevel@tonic-gate *d++ = (token_t)&do_default_action;
236*7c478bd9Sstevel@tonic-gate n = (int)POP(DS);
237*7c478bd9Sstevel@tonic-gate *d++ = n;
238*7c478bd9Sstevel@tonic-gate env->num_actions = n;
239*7c478bd9Sstevel@tonic-gate env->action_count = 0;
240*7c478bd9Sstevel@tonic-gate env->action_ptr = d;
241*7c478bd9Sstevel@tonic-gate d += n;
242*7c478bd9Sstevel@tonic-gate set_here(env, (uchar_t *)d, "actions");
243*7c478bd9Sstevel@tonic-gate }
244*7c478bd9Sstevel@tonic-gate
245*7c478bd9Sstevel@tonic-gate void
install_actions(fcode_env_t * env,token_t * table)246*7c478bd9Sstevel@tonic-gate install_actions(fcode_env_t *env, token_t *table)
247*7c478bd9Sstevel@tonic-gate {
248*7c478bd9Sstevel@tonic-gate acf_t *dptr;
249*7c478bd9Sstevel@tonic-gate token_t p;
250*7c478bd9Sstevel@tonic-gate
251*7c478bd9Sstevel@tonic-gate dptr = (acf_t *)LINK_TO_ACF(env->lastlink);
252*7c478bd9Sstevel@tonic-gate p = (token_t)table;
253*7c478bd9Sstevel@tonic-gate p -= (sizeof (token_t) + sizeof (acf_t));
254*7c478bd9Sstevel@tonic-gate *dptr = (acf_t)(p | 1);
255*7c478bd9Sstevel@tonic-gate }
256*7c478bd9Sstevel@tonic-gate
257*7c478bd9Sstevel@tonic-gate void
use_actions(fcode_env_t * env)258*7c478bd9Sstevel@tonic-gate use_actions(fcode_env_t *env)
259*7c478bd9Sstevel@tonic-gate {
260*7c478bd9Sstevel@tonic-gate if (env->state) {
261*7c478bd9Sstevel@tonic-gate TODO; /* use-actions in compile state. */
262*7c478bd9Sstevel@tonic-gate } else {
263*7c478bd9Sstevel@tonic-gate install_actions(env, env->action_ptr);
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate
267*7c478bd9Sstevel@tonic-gate void
perform_action(fcode_env_t * env)268*7c478bd9Sstevel@tonic-gate perform_action(fcode_env_t *env)
269*7c478bd9Sstevel@tonic-gate {
270*7c478bd9Sstevel@tonic-gate int n;
271*7c478bd9Sstevel@tonic-gate acf_t a;
272*7c478bd9Sstevel@tonic-gate
273*7c478bd9Sstevel@tonic-gate CHECK_DEPTH(env, 2, "perform_action");
274*7c478bd9Sstevel@tonic-gate n = POP(DS);
275*7c478bd9Sstevel@tonic-gate a = (acf_t)POP(DS);
276*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)ACF_TO_BODY(a));
277*7c478bd9Sstevel@tonic-gate
278*7c478bd9Sstevel@tonic-gate if (run_action(env, a, n)) {
279*7c478bd9Sstevel@tonic-gate system_message(env, "Bad Object action");
280*7c478bd9Sstevel@tonic-gate }
281*7c478bd9Sstevel@tonic-gate }
282*7c478bd9Sstevel@tonic-gate
283*7c478bd9Sstevel@tonic-gate void
define_actions(fcode_env_t * env,int n,token_t * array)284*7c478bd9Sstevel@tonic-gate define_actions(fcode_env_t *env, int n, token_t *array)
285*7c478bd9Sstevel@tonic-gate {
286*7c478bd9Sstevel@tonic-gate int a;
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)n);
289*7c478bd9Sstevel@tonic-gate actions(env);
290*7c478bd9Sstevel@tonic-gate
291*7c478bd9Sstevel@tonic-gate a = 0;
292*7c478bd9Sstevel@tonic-gate while (n--) {
293*7c478bd9Sstevel@tonic-gate action_colon(env);
294*7c478bd9Sstevel@tonic-gate COMPILE_TOKEN(&array[a]);
295*7c478bd9Sstevel@tonic-gate env->state |= 8;
296*7c478bd9Sstevel@tonic-gate semi(env);
297*7c478bd9Sstevel@tonic-gate a++;
298*7c478bd9Sstevel@tonic-gate }
299*7c478bd9Sstevel@tonic-gate }
300*7c478bd9Sstevel@tonic-gate
301*7c478bd9Sstevel@tonic-gate /*
302*7c478bd9Sstevel@tonic-gate * This is for things like my-self which have meaning to the
303*7c478bd9Sstevel@tonic-gate * forth engine but I don't want to turn them into standard forth values
304*7c478bd9Sstevel@tonic-gate * that would make the 'C' variables hard to understand, instead these
305*7c478bd9Sstevel@tonic-gate * 'global' state variables will act directly upon the native 'C' structures.
306*7c478bd9Sstevel@tonic-gate */
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate void
set_internal_value_actions(fcode_env_t * env)309*7c478bd9Sstevel@tonic-gate set_internal_value_actions(fcode_env_t *env)
310*7c478bd9Sstevel@tonic-gate {
311*7c478bd9Sstevel@tonic-gate ASSERT(value_actions[2]);
312*7c478bd9Sstevel@tonic-gate install_actions(env, value_actions[2]);
313*7c478bd9Sstevel@tonic-gate }
314*7c478bd9Sstevel@tonic-gate
315*7c478bd9Sstevel@tonic-gate void
set_value_actions(fcode_env_t * env,int which)316*7c478bd9Sstevel@tonic-gate set_value_actions(fcode_env_t *env, int which)
317*7c478bd9Sstevel@tonic-gate {
318*7c478bd9Sstevel@tonic-gate ASSERT((which == 0) || (which == 1));
319*7c478bd9Sstevel@tonic-gate ASSERT(value_actions[which]);
320*7c478bd9Sstevel@tonic-gate install_actions(env, value_actions[which]);
321*7c478bd9Sstevel@tonic-gate }
322*7c478bd9Sstevel@tonic-gate
323*7c478bd9Sstevel@tonic-gate void
set_defer_actions(fcode_env_t * env,int which)324*7c478bd9Sstevel@tonic-gate set_defer_actions(fcode_env_t *env, int which)
325*7c478bd9Sstevel@tonic-gate {
326*7c478bd9Sstevel@tonic-gate ASSERT((which == 0) || (which == 1));
327*7c478bd9Sstevel@tonic-gate ASSERT(value_actions[which+3]);
328*7c478bd9Sstevel@tonic-gate install_actions(env, value_actions[which+3]);
329*7c478bd9Sstevel@tonic-gate }
330*7c478bd9Sstevel@tonic-gate
331*7c478bd9Sstevel@tonic-gate void
set_buffer_actions(fcode_env_t * env,int which)332*7c478bd9Sstevel@tonic-gate set_buffer_actions(fcode_env_t *env, int which)
333*7c478bd9Sstevel@tonic-gate {
334*7c478bd9Sstevel@tonic-gate ASSERT((which == 0) || (which == 1));
335*7c478bd9Sstevel@tonic-gate ASSERT(value_actions[which+5]);
336*7c478bd9Sstevel@tonic-gate install_actions(env, value_actions[which+5]);
337*7c478bd9Sstevel@tonic-gate }
338*7c478bd9Sstevel@tonic-gate
339*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
340*7c478bd9Sstevel@tonic-gate
341*7c478bd9Sstevel@tonic-gate void
do_get(fcode_env_t * env)342*7c478bd9Sstevel@tonic-gate do_get(fcode_env_t *env)
343*7c478bd9Sstevel@tonic-gate {
344*7c478bd9Sstevel@tonic-gate PUSH(DS, 0);
345*7c478bd9Sstevel@tonic-gate perform_action(env);
346*7c478bd9Sstevel@tonic-gate }
347*7c478bd9Sstevel@tonic-gate
348*7c478bd9Sstevel@tonic-gate void
do_set(fcode_env_t * env)349*7c478bd9Sstevel@tonic-gate do_set(fcode_env_t *env)
350*7c478bd9Sstevel@tonic-gate {
351*7c478bd9Sstevel@tonic-gate PUSH(DS, 1);
352*7c478bd9Sstevel@tonic-gate perform_action(env);
353*7c478bd9Sstevel@tonic-gate }
354*7c478bd9Sstevel@tonic-gate
355*7c478bd9Sstevel@tonic-gate void
do_addr(fcode_env_t * env)356*7c478bd9Sstevel@tonic-gate do_addr(fcode_env_t *env)
357*7c478bd9Sstevel@tonic-gate {
358*7c478bd9Sstevel@tonic-gate PUSH(DS, 2);
359*7c478bd9Sstevel@tonic-gate perform_action(env);
360*7c478bd9Sstevel@tonic-gate }
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate void
dump_actions(fcode_env_t * env)363*7c478bd9Sstevel@tonic-gate dump_actions(fcode_env_t *env)
364*7c478bd9Sstevel@tonic-gate {
365*7c478bd9Sstevel@tonic-gate int i;
366*7c478bd9Sstevel@tonic-gate for (i = 0; i < NUM_DEFAULT_ACTIONS; i++) {
367*7c478bd9Sstevel@tonic-gate log_message(MSG_INFO, "Action Set: %d = %p\n", i,
368*7c478bd9Sstevel@tonic-gate value_actions[i]);
369*7c478bd9Sstevel@tonic-gate }
370*7c478bd9Sstevel@tonic-gate }
371*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate #pragma init(_init)
374*7c478bd9Sstevel@tonic-gate
375*7c478bd9Sstevel@tonic-gate static void
_init(void)376*7c478bd9Sstevel@tonic-gate _init(void)
377*7c478bd9Sstevel@tonic-gate {
378*7c478bd9Sstevel@tonic-gate fcode_env_t *env = initial_env;
379*7c478bd9Sstevel@tonic-gate int i;
380*7c478bd9Sstevel@tonic-gate
381*7c478bd9Sstevel@tonic-gate ASSERT(env);
382*7c478bd9Sstevel@tonic-gate NOTICE;
383*7c478bd9Sstevel@tonic-gate
384*7c478bd9Sstevel@tonic-gate for (i = 0; i < NUM_DEFAULT_ACTIONS; i++) {
385*7c478bd9Sstevel@tonic-gate define_actions(env, 3, value_defines[i]);
386*7c478bd9Sstevel@tonic-gate value_actions[i] = env->action_ptr;
387*7c478bd9Sstevel@tonic-gate }
388*7c478bd9Sstevel@tonic-gate
389*7c478bd9Sstevel@tonic-gate #if defined(DEBUG)
390*7c478bd9Sstevel@tonic-gate FORTH(0, "get", do_get);
391*7c478bd9Sstevel@tonic-gate FORTH(0, "set", do_set);
392*7c478bd9Sstevel@tonic-gate FORTH(0, "addr", do_addr);
393*7c478bd9Sstevel@tonic-gate FORTH(0, "dump-actions", dump_actions);
394*7c478bd9Sstevel@tonic-gate FORTH(IMMEDIATE, "actions", actions);
395*7c478bd9Sstevel@tonic-gate FORTH(IMMEDIATE, "use-actions", use_actions);
396*7c478bd9Sstevel@tonic-gate FORTH(IMMEDIATE, "action:", action_colon);
397*7c478bd9Sstevel@tonic-gate FORTH(0, "perform-action", perform_action);
398*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
399*7c478bd9Sstevel@tonic-gate }
400