-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrb_vm.val.c
More file actions
260 lines (210 loc) · 6.96 KB
/
Copy pathrb_vm.val.c
File metadata and controls
260 lines (210 loc) · 6.96 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* -MODULE----------------------------------------------------------------------
RapidBATCH
Copyright (C) 2008, 2009 by Phorward Software Technologies, Jan Max Meyer
http://www.phorward-software.com ++ mail@phorward-software.com
File: rb_run.c
Author: Jan Max Meyer
Usage: Virtual machine kernel
----------------------------------------------------------------------------- */
/*
* Includes
*/
#include "rb_global.h"
/*
* Global variables
*/
/*
* Functions
*/
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_get_dbl_val()
Author: Jan Max Meyer
Usage: Returns the double value of a vm_val-structure, and
converts it, if desired.
Parameters: vm_val* val Pointer to the value structure
pboolean convert TRUE: Convert if required
FALSE: Don't convert
Returns: Returns the double value. If no conversation is done,
and the value is not of type double, 0.0 is returned.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
double rb_vm_get_dbl_val( vm_val* val, pboolean convert ) /*SDK_EXT*/
{
if( val->type != VAL_DBL )
{
if( convert )
rb_vm_convert_value( val, VAL_DBL );
else
return 0.0;
}
return val->value.vdbl;
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_get_long_val()
Author: Jan Max Meyer
Usage: Returns the long value of a vm_val-structure, and converts
it, if desired.
Parameters: vm_val* val Pointer to the value structure
pboolean convert TRUE: Convert if required
FALSE: Don't convert
Returns: Returns the long value. If no conversation is done,
and the value is not of type long, 0L is returned.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
long rb_vm_get_long_val( vm_val* val, pboolean convert ) /*SDK_EXT*/
{
if( val->type != VAL_LONG )
{
if( convert )
rb_vm_convert_value( val, VAL_LONG );
else
return 0L;
}
return val->value.vlong;
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_get_addr_val()
Author: Jan Max Meyer
Usage: Returns the long value of a vm_val-structure, and converts
it, if desired.
Parameters: vm_val* val Pointer to the value structure
pboolean convert TRUE: Convert if required
FALSE: Don't convert
Returns: Returns the vm_addr value. If no conversation is done,
and the value is not of type vm_addr, 0L is returned.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
vm_addr rb_vm_get_addr_val( vm_val* val, pboolean convert ) /*SDK_EXT*/
{
if( val->type != VAL_ADDR )
{
if( convert )
rb_vm_convert_value( val, VAL_ADDR );
else
return 0L;
}
return val->value.vaddr;
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_get_str_val()
Author: Jan Max Meyer
Usage: Returns the string value of a vm_val-structure, and converts
it, if desired.
Parameters: vm_val* val Pointer to the value structure
pboolean convert TRUE: Convert if required
FALSE: Don't convert
Returns: Returns the string value. If no conversation is done,
and the value is not of type string, (char*)NULL is
returned.
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
char* rb_vm_get_str_val( vm_val* val, pboolean convert ) /*SDK_EXT*/
{
if( val->type != VAL_CSTR
&& val->type != VAL_STR )
{
if( convert )
rb_vm_convert_value( val, VAL_STR );
else
return (char*)NULL;
}
if( val->type == VAL_CSTR )
return val->value.vcstr;
return val->value.vstr.str;
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_free_val()
Author: Jan Max Meyer
Usage: Frees the possibly used memory of a value.
Parameters: vm_val* val Pointer to the value structure
Returns: void
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
void rb_vm_free_val( vm_val* val ) /*SDK_EXT*/
{
if( VAL_TYPE( val ) == VAL_STR )
pfree( val->value.vstr.str );
VAL_TYPE( val ) = VAL_UNDEFINED;
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_copy_val()
Author: Jan Max Meyer
Usage: Copies the possibly used memory of a value.
Parameters: vm_val* dst Pointer to the destination
value structure
vm_val* src Pointer to the source value
structure
Returns: pboolean TRUE on success,
FALSE on error
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
pboolean rb_vm_copy_val( vm_val* dst, vm_val* src, pboolean withdup ) /*SDK_EXT*/
{
PROC( "rb_vm_copy_val" );
PARMS( "dst", "%p", dst );
PARMS( "src", "%p", src );
PARMS( "withdup", "%d", withdup );
if( VAL_TYPE( dst ) == VAL_STR )
pfree( dst->value.vstr.str );
memcpy( dst, src, sizeof( vm_val ) );
if( withdup && VAL_TYPE( src ) == VAL_STR )
{
VAL_SET_STR( dst, pstrdup( VAL_GET_STR( src ) ) );
if( VAL_GET_STR( src ) && !dst )
RETURN( FALSE );
}
RETURN( TRUE );
}
/* -FUNCTION--------------------------------------------------------------------
Function: rb_vm_dump_val()
Author: Jan Max Meyer
Usage: Dumps a value to stderr.
Parameters: vm_val* val The value to be dumped
Returns: void
~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Date: Author: Note:
----------------------------------------------------------------------------- */
void rb_vm_dump_val( FILE* stream, vm_val* val ) /*SDK_EXT*/
{
if( !stream )
stream = stderr;
if( !val )
{
fprintf( stream, "(val is NULL)\n" );
return;
}
switch( val->type )
{
case VAL_LONG:
fprintf( stream, "(long) %ld",
val->value.vlong );
break;
case VAL_ADDR:
fprintf( stream, "(address) %lx",
val->value.vaddr );
break;
case VAL_DBL:
fprintf( stream, "(double) %lf",
val->value.vdbl );
break;
case VAL_STR:
fprintf( stream, "(dynamic string) >%s<",
val->value.vstr.str );
break;
case VAL_CSTR:
fprintf( stream, "(constant string) >%s<",
val->value.vcstr );
break;
case VAL_UNDEFINED:
default:
fprintf( stream, "(undefined) %d",
val->type );
}
fprintf( stream, "\n" );
}