4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fcode/private.h>
33 #include <fcode/log.h>
35 fcode_env_t
*initial_env
= 0;
36 int dict_size
= 0x4000000; /* 64Mb, hopefully big enough... */
37 int stack_size
= 0x200;
40 safe_malloc(size_t n
, char *f
, int l
)
44 p
= malloc((size_t)n
);
46 memset(p
, 0, (size_t)n
);
48 log_message(MSG_ERROR
, "%s:%d:Malloc(%llx) failed\n", f
, l
,
54 safe_realloc(void *p
, size_t n
, char *f
, int l
)
58 if ((newp
= safe_malloc(n
, f
, l
)) == NULL
) {
59 log_message(MSG_ERROR
, "%s:%d:realloc(%p, %x) failed\n", f
, l
,
72 safe_free(void *p
, char *f
, int l
)
80 safe_strdup(char *s
, char *f
, int l
)
99 env
= MALLOC(sizeof (fcode_env_t
));
100 env
->table
= MALLOC((MAX_FCODE
+ 1) * sizeof (fcode_token
));
101 env
->base
= MALLOC(dict_size
);
102 env
->here
= env
->base
;
103 env
->ds
= env
->ds0
= MALLOC(stack_size
* sizeof (fstack_t
));
104 env
->rs
= env
->rs0
= MALLOC(stack_size
* sizeof (fstack_t
));
105 env
->order
= MALLOC(MAX_ORDER
* sizeof (token_t
));
106 env
->input
= MALLOC(sizeof (input_typ
));
107 env
->num_base
= 0x10;
109 /* Setup the initial forth environment */
112 install_handlers(env
);
117 * Need to define this early because it is the default for
118 * all unimpl, FCODE functions
120 P1275(0x0fc, IMMEDIATE
, "ferror", f_error
);
121 f_error_addr
= LINK_TO_ACF(env
->lastlink
);
122 for (i
= 0; i
<= MAX_FCODE
; i
++) {
123 DEBUGF(ANY
, env
->table
[i
].usage
= 0);
124 SET_TOKEN(i
, IMMEDIATE
, "ferror", f_error_addr
);
126 fcode_impl_count
= 0;