-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdynamic_types.h
148 lines (134 loc) · 4.21 KB
/
dynamic_types.h
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
/**
* @file dynamic_types.h
* @author André Dietrich
* @date 9 April 2016
*
* @copyright Copyright 2016 André Dietrich. All rights reserved.
*
* @license This project is released under the MIT-License.
*
* @brief Definition of internal settings and applied data types.
*
*
*/
#include <stdint.h>
#ifndef DYNAMIC_TYPES_C_H
#define DYNAMIC_TYPES_C_H
/** @brief basic return type for truth values
*/
typedef enum {
DYN_FALSE = 0, ///< represents boolean false
DYN_TRUE = 1, ///< represents boolean true
DYN_NONE = -1 ///< represents a third unknown state, which is not true or false
} trilean;
/** @brief Basic 8bit signed integer
*/
typedef char dyn_char;
/** @brief Basic 8bit integer (0 - 255)
*/
typedef unsigned char dyn_byte;
/** @brief Standard dynamic C string
*/
typedef char* dyn_str;
/** @brief Standard dynamic C const string
*/
typedef const char* dyn_const_str;
/** @brief 16bit unsigned integer
*/
typedef uint16_t dyn_ushort;
/** @brief 16bit signed integer
*/
typedef int16_t dyn_short;
/** @brief 32bit signed integer, standard Integer type.
*/
typedef int32_t dyn_int;
/** @brief 32bit unsigned integer
*/
typedef uint32_t dyn_uint;
/** @brief basic float definition (32 bit)
*/
typedef float dyn_float;
/**
* @brief Basic data type definitions
*/
typedef enum {
NONE, ///< None type without any value
BOOL, ///< Boolean 0==False, 1==True
BYTE, ///< not used
INTEGER, ///< signed integer 32 bit
FLOAT, ///< float 32 bit
STRING, ///< char*
LIST, ///< list of type dyn_list
SET, ///< set of type dyn_list
DICT, ///< dictionary of type dyn_dict
// TEMP, ///< not used
FUNCTION, ///< function pointer of type dyn_fct
EXTERN, ///< void*
REFERENCE, ///< dyn_c* for internal usage only
REFERENCE2, ///< dyn_c*, explicite reference
MISCELLANEOUS ///< can be used for different purposes
} TYPE;
/** @brief common dynamic data type
*/
typedef struct dynamic dyn_c;
/** @brief common dynamic list data type
*/
typedef struct dynamic_list dyn_list;
/** @brief common dynamic dictionary data type
*/
typedef struct dynamic_dict dyn_dict;
/** @brief common dynamic procedure/bytecode data type
*/
typedef struct dynamic_function dyn_fct;
/**
* @brief Basic container for dynamic data types.
*
* Basic container consisting of two parts, a union data for storing or
* referencing to values. The type value contains enum TYPE in order to define
* which value of data has to be used.
*/
struct dynamic {
union { /*@{*/
dyn_char b; //!< boolean value
dyn_int i; //!< basic integer
dyn_float f; //!< float value
dyn_str str; //!< pointer to character-array
dyn_list* list; //!< pointer to dynamic list
dyn_dict* dict; //!< pointer to dynamic dictionary
dyn_fct* fct; //!< pointer to function
const void* ex; //!< external (pointer to everything)
dyn_c* ref; //!< reference pointer to dynamic elements
/*@}*/
} data;
char type; //!< type definition
} __attribute__ ((packed));
/**
* @brief Basic container for lists.
*
* todo.
*/
struct dynamic_list {
dyn_ushort length; //!< elements in use
dyn_ushort space; //!< elements available
dyn_c *container; //!< pointer to an array of dynamic elements
} __attribute__ ((packed));
/**
* @brief Basic container for dictionaries.
*
* todo.
*/
struct dynamic_dict {
dyn_str* key; //!< array to C strings used as identifiers
dyn_c value; //!< dynamic element of type dyn_list
} __attribute__ ((packed));
/**
* @brief Basic container/pointer to functions.
*
* todo.
*/
struct dynamic_function {
dyn_ushort type; //!< 0 basic C-fct, 1 system C-fct, else procedure (length of bytecode)
void* ptr; //!< pointer to function
dyn_str info; //!< info string
} __attribute__ ((packed));
#endif // DYNAMIC_TYPES_C_H