xref: /titanic_41/usr/src/lib/efcode/engine/instance.c (revision c138f478d2bc94e73ab8f6a084e323bec25e62f5)
1 /*
2  * CDDL HEADER START
3  *
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
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 
23 /*
24  * Copyright (c) 1999 by Sun Microsystems, Inc.
25  * All rights reserved.
26  */
27 
28 #pragma ident	"%Z%%M%	%I%	%E% SMI"
29 
30 #include <stdio.h>
31 
32 #include <fcode/private.h>
33 
34 /*
35  * Return a pointer to the allocated instance data.
36  * If the data was initialised then return a pointer to the initialisation
37  * buffer otherwise return a pointer to the un-init data.
38  */
39 token_t *
40 alloc_instance_data(fcode_env_t *env, int init, int n, int *offset)
41 {
42 	int ptr;
43 
44 	*offset = ptr = MYSELF->device->data_size[init];
45 	MYSELF->device->data_size[init] += n;
46 	if (init == INIT_DATA)
47 		return (&MYSELF->device->init_data[ptr]);
48 	else
49 		return (&MYSELF->data[init][ptr]);
50 }
51 
52 token_t *
53 get_instance_address(fcode_env_t *env)
54 {
55 	int which;
56 	token_t *ptr;
57 	token_t offset;
58 
59 	CHECK_DEPTH(env, 1, "get_instance_address");
60 	ptr = (token_t *) POP(DS);
61 	offset = *ptr;
62 	if (offset < 0) {
63 		offset = -offset;
64 		which = UINIT_DATA;
65 	} else {
66 		which = INIT_DATA;
67 	}
68 	return (&MYSELF->data[which][offset]);
69 }
70 
71 void
72 fetch_instance_data(fcode_env_t *env)
73 {
74 	token_t *ptr;
75 
76 	CHECK_DEPTH(env, 1, "get_instance_data");
77 	ptr = get_instance_address(env);
78 	PUSH(DS, *ptr);
79 }
80 
81 void
82 set_instance_data(fcode_env_t *env)
83 {
84 	token_t *ptr;
85 
86 	CHECK_DEPTH(env, 2, "set_instance_data");
87 	ptr = get_instance_address(env);
88 	*ptr = POP(DS);
89 }
90 
91 void
92 address_instance_data(fcode_env_t *env)
93 {
94 	token_t *ptr;
95 
96 	CHECK_DEPTH(env, 1, "address_instance_data");
97 	ptr = get_instance_address(env);
98 	PUSH(DS, (fstack_t) ptr);
99 }
100 
101 void
102 instance_variable(fcode_env_t *env)
103 {
104 	token_t *ptr;
105 
106 	PUSH(DS, (fstack_t) WA);
107 	ptr = get_instance_address(env);
108 	PUSH(DS, (fstack_t) ptr);
109 }
110 
111 void
112 idefer_exec(fcode_env_t *env)
113 {
114 	CHECK_DEPTH(env, 1, "idefer_exec");
115 	fetch_instance_data(env);
116 	execute(env);
117 }
118