4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <fcode/private.h>
34 #include <fcode/log.h>
37 * the external start point for this goo
41 push_ds(fcode_env_t
*env
, fstack_t d
)
47 pop_ds(fcode_env_t
*env
)
53 push_rs(fcode_env_t
*env
, fstack_t d
)
59 pop_rs(fcode_env_t
*env
)
65 * Pushes a C string on the stack.
68 push_a_string(fcode_env_t
*env
, char *str
)
71 PUSH(DS
, (fstack_t
)str
);
72 PUSH(DS
, strlen(str
));
80 * Pops a (potentially null) string off the stack.
83 pop_a_string(fcode_env_t
*env
, int *lenp
)
89 str
= (char *)POP(DS
);
100 * Pops & strdup's a string off the stack, handles NULL strings.
103 pop_a_duped_string(fcode_env_t
*env
, int *lenp
)
107 str
= pop_a_string(env
, lenp
);
109 return (STRDUP(str
));
114 * Push Forth Double type.
117 push_double(fcode_env_t
*env
, dforth_t d
)
128 * Pop Forth Double type.
131 pop_double(fcode_env_t
*env
)
137 return (MAKE_DFORTH(hi
, lo
));
141 * Peek at top of stack Forth Double type.
144 peek_double(fcode_env_t
*env
)
154 run_fcode(fcode_env_t
*env
, uchar_t
*buff
, int len
)
159 * Really just checking to see if buff is all ascii characters.
160 * Fcode normally starts with 0xfd, so for fcode, this should be
163 for (i
= 0; i
< len
; i
++)
166 PUSH(DS
, (fstack_t
)buff
);
168 /* Non-ascii found, probably Fcode */
169 PUSH(DS
, (fstack_t
)1);
172 /* All ascii found, probably ascii */
179 run_fcode_from_file(fcode_env_t
*env
, char *fname
, int aout_flag
)
184 push_a_string(env
, fname
);
187 p
= (uchar_t
*)POP(DS
);
192 run_fcode(env
, p
, len
);
196 clone_environment(fcode_env_t
*src
, void *private)
202 src
->private = private;
207 src
->private = private;
208 if (src
->my_self
|| src
->state
) {
209 log_message(MSG_WARN
, "Can't clone an active instance or"
210 " compile state!\n");
214 log_message(MSG_WARN
, "Warning: Device-tree state is shared!\n");
217 env
= MALLOC(sizeof (fcode_env_t
));
218 memcpy(env
, src
, sizeof (fcode_env_t
));
221 env
->table
= MALLOC((MAX_FCODE
+ 1) * sizeof (fcode_token
));
222 memcpy(env
->table
, src
->table
, (MAX_FCODE
+ 1) * sizeof (fcode_token
));
225 * Note that cloning the dictionary doesn't make sense unless the
226 * ptrs + XT's in the dictionary are relative to BASE.
228 env
->base
= MALLOC(dict_size
);
229 memcpy(env
->base
, src
->base
, dict_size
);
231 env
->here
= src
->base
- (uchar_t
*)src
+ env
->base
;
234 env
->ds0
= MALLOC(stack_size
* sizeof (fstack_t
));
235 memcpy(env
->ds0
, src
->ds0
, stack_size
* sizeof (fstack_t
));
236 env
->ds
= src
->ds
- src
->ds0
+ env
->ds0
;
238 env
->rs0
= MALLOC(stack_size
* sizeof (fstack_t
));
239 memcpy(env
->rs0
, src
->rs0
, stack_size
* sizeof (fstack_t
));
240 env
->rs
= src
->rs
- src
->rs0
+ env
->rs0
;
242 env
->order
= MALLOC(MAX_ORDER
* sizeof (token_t
));
243 memcpy(env
->order
, src
->order
, MAX_ORDER
* sizeof (token_t
));
245 env
->input
= MALLOC(sizeof (input_typ
));
247 env
->catch_frame
= 0;
255 destroy_environment(fcode_env_t
*env
)
267 if (env
== initial_env
) {
268 /* This call only happens internally */
271 /* You had better not exercise the engine anymore! */