Kiwi Engine
VM for interpreter
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
KEValue.h
Go to the documentation of this file.
1 
8 #ifndef KEVALUE_H
9 #define KEVALUE_H
10 
11 #include <Coconut/Coconut.h>
12 #include "KEForwarders.h"
13 
15 typedef enum {
16  KENilValue,
17  KEBooleanValue,
18  KESignedIntegerValue,
19  KEUnsignedIntegerValue,
20  KEFloatValue,
21  KEStringValue,
22  KEObjectValue
23 } KEValueType ;
24 
31 static inline CNBoolean
32 KEIsObjectValueType(KEValueType type)
33 {
34  return type >= KEStringValue ;
35 }
36 
40 struct KEValue {
44  union {
45  CNBoolean booleanValue ;
46  int64_t intValue ;
47  uint64_t uIntValue ;
48  double floatValue ;
49  struct CNString * stringValue ;
50  struct KEObject * objectValue ;
51  } ;
52 } ;
53 
58 static inline void
59 KEInitValue(struct KEValue * dst)
60 {
61  dst->type = KENilValue ;
62 }
63 
68 static inline void
69 KEDestroyValue(struct KEValue * dst)
70 {
71  if(KEIsObjectValueType(dst->type)){
72  extern void KEDestroyObjectValue(struct KEValue *) ;
73  KEDestroyObjectValue(dst) ;
74  }
75  dst->type = KENilValue ;
76 }
77 
83 static inline KEValueType
84 KETypeOfValue(const struct KEValue * src)
85 {
86  return src->type ;
87 }
88 
94 static inline struct KEValue
95 KEMakeValue(const struct KEValue * src)
96 {
97  struct KEValue newval ;
98  if(KEIsObjectValueType(src->type)){
99  extern struct KEValue KEMakeObjectValueBody(const struct KEValue * src) ;
100  newval = KEMakeObjectValueBody(src) ;
101  } else {
102  newval = *src ;
103  }
104  return newval ;
105 }
106 
112 static inline void
113 KEUpdateValue(struct KEValue * dst, const struct KEValue * src)
114 {
115  struct KEValue newval = KEMakeValue(src) ;
116  KEDestroyValue(dst) ;
117  *dst = newval ;
118 }
119 
125 static inline struct KEValue
126 KEMakeBooleanValue(CNBoolean src)
127 {
128  struct KEValue val = {
129  .type = KEBooleanValue,
130  .booleanValue = src
131  } ;
132  return val ;
133 }
134 
142 static inline void
143 KEUpdateBooleanValue(struct KEValue * dst, CNBoolean src)
144 {
145  KEDestroyValue(dst) ;
146  *dst = KEMakeBooleanValue(src) ;
147 }
148 
154 static inline struct KEValue
155 KEMakeSignedIntegerValue(int64_t src)
156 {
157  struct KEValue val = {
158  .type = KESignedIntegerValue,
159  .intValue = src
160  } ;
161  return val ;
162 }
163 
171 static inline void
172 KEUpdateSignedIntegerValue(struct KEValue * dst, int64_t src)
173 {
174  KEDestroyValue(dst) ;
175  *dst = KEMakeSignedIntegerValue(src) ;
176 }
177 
183 static inline struct KEValue
184 KEMakeUnsignedIntegerValue(uint64_t src)
185 {
186  struct KEValue val = {
187  .type = KEUnsignedIntegerValue,
188  .uIntValue = src
189  } ;
190  return val ;
191 }
192 
200 static inline void
201 KEUpdateUnsignedIntegerValue(struct KEValue * dst, uint64_t src)
202 {
203  KEDestroyValue(dst) ;
204  *dst = KEMakeUnsignedIntegerValue(src) ;
205 }
206 
212 static inline struct KEValue
213 KEMakeFloatValue(double src)
214 {
215  struct KEValue val = {
216  .type = KEFloatValue,
217  .floatValue = src
218  } ;
219  return val ;
220 }
221 
229 static inline void
230 KEUpdateFloatValue(struct KEValue * dst, double src)
231 {
232  KEDestroyValue(dst) ;
233  *dst = KEMakeFloatValue(src) ;
234 }
235 
241 static inline struct KEValue
242 KEMakeStringValue(struct CNString * src)
243 {
244  struct KEValue val = {
245  .type = KEStringValue,
246  .stringValue = src
247  } ;
248  CNRetainString(val.stringValue) ;
249  return val ;
250 }
251 
259 static inline void
260 KEUpdateStringValue(struct KEValue * dst, struct CNString * src)
261 {
262  CNRetainString(src) ;
263  KEDestroyValue(dst) ;
264  dst->type = KEStringValue ;
265  dst->stringValue = src ;
266 }
267 
274 struct KEFrame *
275 KEFrameInValue(const struct KEValue * src) ;
276 
283 static inline CNBoolean
284 KEIsFrameValue(const struct KEValue * src)
285 {
286  return KEFrameInValue(src) != NULL ;
287 }
288 
294 struct KEValue
295 KEMakeFrameValue(struct KEFrame * src) ;
296 
304 void
305 KEUpdateFrameValue(struct KEValue * dst, struct KEFrame * src) ;
306 
313 struct KEArray *
314 KEArrayInValue(const struct KEValue * src) ;
315 
322 static inline CNBoolean
323 KEIsArrayValue(const struct KEValue * src)
324 {
325  return KEArrayInValue(src) != NULL ;
326 }
327 
333 struct KEValue
334 KEMakeArrayValue(struct KEArray * src) ;
335 
343 void
344 KEUpdateArrayValue(struct KEValue * dst, struct KEArray * src) ;
345 
352 struct KEDictionary *
353 KEDictionaryInValue(const struct KEValue * src) ;
354 
361 static inline CNBoolean
362 KEIsDictionaryValue(const struct KEValue * src)
363 {
364  return KEDictionaryInValue(src) != NULL ;
365 }
366 
372 struct KEValue
373 KEMakeDictionaryValue(struct KEDictionary * src) ;
374 
382 void
383 KEUpdateDictionaryValue(struct KEValue * dst, struct KEDictionary * src) ;
384 
391 struct KEPath *
392 KEPathInValue(const struct KEValue * src) ;
393 
400 static inline CNBoolean
401 KEIsPathValue(const struct KEValue * src)
402 {
403  return KEPathInValue(src) != NULL ;
404 }
405 
411 struct KEValue
412 KEMakePathValue(struct KEPath * src) ;
413 
421 void
422 KEUpdatePathValue(struct KEValue * dst, struct KEPath * src) ;
423 
430 struct KEFunction *
431 KEFunctionInValue(const struct KEValue * src) ;
432 
439 static inline CNBoolean
440 KEIsFunctionValue(const struct KEValue * src)
441 {
442  return KEFunctionInValue(src) != NULL ;
443 }
444 
450 struct KEValue
451 KEMakeFunctionValue(struct KEFunction * src) ;
452 
460 void
461 KEUpdateFunctionValue(struct KEValue * dst, struct KEFunction * src) ;
462 
469 struct KEBuiltinFunc *
470 KEBuiltinFuncInValue(const struct KEValue * src) ;
471 
478 static inline CNBoolean
479 KEIsBuiltinFuncValue(const struct KEValue * src)
480 {
481  return KEBuiltinFuncInValue(src) != NULL ;
482 }
483 
489 struct KEValue
491 
499 void
500 KEUpdateBuiltinFuncValue(struct KEValue * dst, struct KEBuiltinFunc * src) ;
501 
507 static inline CNBoolean
508 KEHasValidValue(struct KEValue * src)
509 {
510  return KETypeOfValue(src) != KENilValue ;
511 }
512 
518 const char *
519 KEStringOfValueType(struct KEValue * src) ;
520 
526 void
527 KEDumpValue(struct CNText * outbuf, const struct KEValue * src) ;
528 
529 #endif /* KEVALUE_H */
void KEUpdateDictionaryValue(struct KEValue *dst, struct KEDictionary *src)
Set the value to dictionary object.
void KEUpdateArrayValue(struct KEValue *dst, struct KEArray *src)
Set the value to array object.
struct KEValue KEMakePathValue(struct KEPath *src)
Make the value which has the dictionary.
struct KEPath * KEPathInValue(const struct KEValue *src)
Get path in value.
KEValueType
Definition: KEValue.h:15
struct KEValue KEMakeBuiltinFuncValue(struct KEBuiltinFunc *src)
Make the value which has the builtin-func.
void KEDumpValue(struct CNText *outbuf, const struct KEValue *src)
Dump context of the buffer.
struct KEFrame * KEFrameInValue(const struct KEValue *src)
Get frame in value.
struct KEValue KEMakeFunctionValue(struct KEFunction *src)
Make the value which has the function.
Definition: KEFrame.h:16
struct KEValue KEMakeArrayValue(struct KEArray *src)
Make the value which has the array.
struct KEArray * KEArrayInValue(const struct KEValue *src)
Get array in value.
Definition: KEFunction.h:18
struct KEValue KEMakeFrameValue(struct KEFrame *src)
Make the value which has the frame.
Array of KEValue.
Definition: KEArray.h:21
Definition: KEBuiltinFunc.h:36
Definition: KEObject.h:42
void KEUpdateFunctionValue(struct KEValue *dst, struct KEFunction *src)
Set the value to function object.
void KEUpdateFrameValue(struct KEValue *dst, struct KEFrame *src)
Set the value to frame object.
Definition: KEValue.h:40
struct KEBuiltinFunc * KEBuiltinFuncInValue(const struct KEValue *src)
Get builtin-func in value.
const char * KEStringOfValueType(struct KEValue *src)
Get description of given type.
Dictionary class. The key is CNString and the value is KEValue.
Definition: KEDictionary.h:24
struct KEFunction * KEFunctionInValue(const struct KEValue *src)
Get function in value.
struct KEValue KEMakeDictionaryValue(struct KEDictionary *src)
Make the value which has the dictionary.
Forward declarations of the data type in KiwiEngine.
Definition: KEPath.h:16
struct KEDictionary * KEDictionaryInValue(const struct KEValue *src)
Get dictionary in value.
void KEUpdatePathValue(struct KEValue *dst, struct KEPath *src)
Set the value to path object.
void KEUpdateBuiltinFuncValue(struct KEValue *dst, struct KEBuiltinFunc *src)
Set the value to builtin-func object.
KEValueType type
Definition: KEValue.h:42