-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrb_vm.var.tool.c
More file actions
239 lines (187 loc) · 6.26 KB
/
Copy pathrb_vm.var.tool.c
File metadata and controls
239 lines (187 loc) · 6.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2008, 2009 by Phorward Software Technologies, Jan Max Meyer
http://www.phorward-software.com ++ mail@phorward-software.com
File: rb_vm.var.tool.c
Author: Jan Max Meyer
Usage: Virtual machine variable access tool functions
(mainly written for variable manipulation beyond the virtual machine)
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
/*
* Functions
*/
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_var_resolve()
Author: Jan Max Meyer
Usage: Resolves a variable pointer according to an array of
indexes.
Parameters: vm_var* var Base pointer to a variable
structure.
vm_val* idx Pointer to begin of index
array. This must be dynamically
allocated.
int idx_depth Number/depth of elements in idx.
pboolean allocate Performs a variable allocation
if required.
Returns: Returns the vm_var-pointer of the desired index, or
(vm_var*)NULL if the index does not exists and could not
be allocated.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
/*SDK_EXT:rb_resolve_var*/
vm_var* rb_vm_var_resolve( vm_var* var, vm_val* idx,
int idx_depth, pboolean allocate )
{
int i;
PROC( "rb_vm_var_resolve" );
PARMS( "var", "%p", var );
PARMS( "idx", "%p", idx );
PARMS( "idx_depth", "%d", idx_depth );
PARMS( "allocate", "%d", allocate );
if( !( var && idx_depth < 0 ) )
{
MSG( "Arguments invalid!" );
RETURN( (vm_var*)NULL );
}
for( i = 0; i < idx_depth; i++ )
{
VARS( "Getting index i", "%d", i );
if( !( var = rb_vm_var_get_idx( var, &( idx[i] ), allocate ) ) )
{
MSG( "Unable to get and/or allocate" );
break;
}
}
VARS( "var (is result!)", "%p", var );
RETURN( var );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_var_dim()
Author: Jan Max Meyer
Usage: Dimensions a variable to a desired size, within all its
dimensions.
Parameters: vm_var* var Base pointer to a variable
structure.
vm_val* idx Pointer to begin of index
array. This must be dynamically
allocated.
int idx_depth Number/depth of elements in idx.
pboolean allocate Performs a variable allocation
if required.
Returns: Returns the vm_var-pointer of the desired index, or
(vm_var*)NULL if the index does not exists and could not
be allocated.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
/*SDK_EXT:rb_dim_var*/
vm_var* rb_vm_var_dim( vm_var* var, vm_val* idx,
int idx_depth, pboolean allocate )
{
int i;
PROC( "rb_vm_var_dim" );
PARMS( "var", "%p", var );
PARMS( "idx", "%p", idx );
PARMS( "idx_depth", "%d", idx_depth );
PARMS( "allocate", "%d", allocate );
if( !( var && idx_depth < 0 ) )
{
MSG( "Arguments invalid!" );
RETURN( (vm_var*)NULL );
}
for( i = 0; i < idx_depth; i++ )
{
VARS( "Getting index i", "%d", i );
if( !( var = rb_vm_var_get_idx( var, &( idx[i] ), allocate ) ) )
{
MSG( "Unable to get and/or allocate" );
break;
}
}
VARS( "var (is result!)", "%p", var );
RETURN( var );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_var_copy()
Author: Jan Max Meyer
Usage: Copies an entire variable into another one. The other
variable will be entierely deleted before. Both target
and source can be sub-dimensions of other variables...
Parameters: vm_var* dest Pointer to target variable.
vm_var* src Pointer to source variable.
Returns: pboolean TRUE on success,
FALSE on error.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
/*SDK_EXT:rb_copy_var*/
pboolean rb_vm_var_copy( vm_var* dest, vm_var* src )
{
vm_addr i;
PROC( "rb_vm_var_copy" );
PARMS( "dest", "%p", dest );
PARMS( "src", "%p", src );
if( !( dest && src ) )
{
MSG( "Nothing to do here" );
RETURN( FALSE );
}
rb_vm_var_free( dest );
dest->key = pstrdup( src->key );
rb_vm_copy_val( VAR_VAL_STRUCT( dest ),
VAR_VAL_STRUCT( src ), TRUE );
if( !( dest->begin = (vm_var*)pmalloc(
src->begin_cnt * sizeof( vm_var ) ) ) )
OUTOFMEM;
dest->begin_cnt = src->begin_cnt;
memset( dest->begin, 0, src->begin_cnt * sizeof( vm_var ) );
if( src->ht )
{
if( !( dest->ht = (vm_addr*)pmemdup( src->ht,
VM_ASSOC_HASH_SIZE * sizeof( vm_addr ) ) ) )
OUTOFMEM;
}
for( i = 0; i < src->begin_cnt; i++ )
if( !rb_vm_var_copy( &( dest->begin[ i ] ), &( src->begin[ i ] ) ) )
RETURN( FALSE );
MSG( "All right here!" );
RETURN( TRUE );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_make_var()
Author: Jan Max Meyer
Usage: Validates and creates a variable from a stack item, if this
is not a variable type. If rb_vm_make_var() gets a value
type parameter, it converts this value into a variable and
assigns it to this variable after conversion.
Parameters: vm_stackitem* item Pointer to item to be converted
Returns: vm_var* A pointer to the variable
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
/*SDK_EXT:rb_value_to_var*/
vm_var* rb_vm_make_var( vm_stackitem* item )
{
vm_val tval;
PROC( "rb_vm_make_var" );
PARMS( "item", "%p", item );
if( item->type != ITEM_VAL )
{
MSG( "Can't convert, or this is already a variable" );
RETURN( ITEM_GET_VAR( item ) );
}
memcpy( &tval, ITEM_VAL_STRUCT( item ), sizeof( vm_val ) );
memset( item, 0, sizeof( vm_stackitem ) );
item->type = ITEM_VAR;
rb_vm_var_set( ITEM_GET_VAR( item ),
&tval, DONT_COPY_STRING );
RETURN( ITEM_GET_VAR( item ) );
}