ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
ceptr_types.h
1 #ifndef _CEPTR_TYPES_H
2 #define _CEPTR_TYPES_H
3 
4 #include <stdint.h>
5 #include <stdio.h>
6 #include "uthash.h"
7 #include <stdbool.h>
8 
9 // NOTE: the actual values of the types matter because they must match the order they show
10 // up in the definition trees
11 enum SemanticTypes {SEM_TYPE_STRUCTURE=1,SEM_TYPE_SYMBOL,SEM_TYPE_PROCESS,SEM_TYPE_RECEPTOR,SEM_TYPE_PROTOCOL};
12 #define is_symbol(s) ((s).semtype == SEM_TYPE_SYMBOL)
13 #define is_process(s) ((s).semtype == SEM_TYPE_PROCESS)
14 #define is_structure(s) ((s).semtype == SEM_TYPE_STRUCTURE)
15 #define is_protocol(s) ((s).semtype == SEM_TYPE_PROTOCOL)
16 #define is_receptor(s) ((s).semtype == SEM_TYPE_RECEPTOR)
17 
18 typedef uint32_t Context; // 4G types of receptors
19 typedef uint16_t SemanticType; // 256 types of semantic things (but using 2 bytes for struct alignment!)
20 typedef uint16_t SemanticAddr;// 64K types of symbols/structure per receptor
21 
22 typedef struct SemanticID {
23  Context context;
24  SemanticType semtype;
25  SemanticAddr id;
26  //c uint8_t _reserved; // add an extra 8 bits to make this a 64bit structure.
27 } SemanticID;
28 
29 // creating aliases for SemanticIDs as hints for use.
30 typedef SemanticID Symbol;
31 typedef SemanticID Structure;
32 typedef SemanticID Process;
33 typedef SemanticID Protocol;
34 typedef SemanticID Recept;
35 
36 
37 // ** types for matrix trees
38 typedef uint16_t Mlevel;
39 typedef uint32_t Mindex;
40 typedef uint32_t Mmagic;
41 
42 typedef struct N {
43  Symbol symbol;
44  Mindex parenti;
45  uint32_t flags;
46  uint32_t cur_child; // for active run-trees
47  size_t size;
48  void *surface; // this item must be last!!!
49 } N;
50 
51 typedef struct L {
52  Mindex nodes;
53  N *nP;
54 } L;
55 
56 typedef struct M {
57  Mmagic magic;
58  Mlevel levels;
59  L *lP;
60 } M;
61 
62 // node entries are fixed size but the surface when serialized is an offset
63 // in the blob not a pointer
64 #define SERIALIZED_NODE_SIZE (sizeof(N)-sizeof(void *)+sizeof(size_t))
65 #define SERIALIZED_LEVEL_SIZE(l) (sizeof(Mindex)+SERIALIZED_NODE_SIZE*l->nodes)
66 #define SERIALIZED_HEADER_SIZE(levels) (sizeof(S)+sizeof(uint32_t)*(levels))
67 
68 typedef struct S {
69  Mmagic magic;
70  size_t total_size;
71  Mlevel levels;
72  uint32_t blob_offset;
73  uint32_t level_offsets[];
74 } S;
75 
76 #define NULL_ADDR -1
77 typedef struct Maddr {
78  Mlevel l;
79  Mindex i;
80 } Maddr;
81 
82 // ** generic tree type defs
83 typedef struct H {
84  M *m;
85  Maddr a;
86 } H;
87 
88 enum treeImplementations {ptrImpl=0xfffffffe,matrixImpl=0xffffffff};
89 #define FIRST_TREE_IMPL_TYPE ptrImpl
90 #define LAST_TREE_IMPL_TYPE matrixImpl
91 
92 
93 // ** types for pointer trees
94 typedef struct Tstruct {
95  uint32_t child_count;
96  struct T *parent;
97  struct T **children;
98 } Tstruct;
99 
100 typedef struct Tcontents {
101  Symbol symbol;
102  size_t size;
103  void *surface;
104 } Tcontents;
105 
106 typedef struct Tcontext {
107  uint32_t flags;
108 } Tcontext;
109 
114 typedef struct T {
115  Tstruct structure;
116  Tcontext context;
117  Tcontents contents;
118 } T;
119 
120 #define RUN_TREE_NOT_EVAULATED 0
121 #define RUN_TREE_EVALUATED 0xffffffff
122 
128 typedef struct rT {
129  Tstruct structure;
130  Tcontext context;
131  Tcontents contents;
132  uint32_t cur_child;
133 } rT;
134 
135 // macro helper to get at the cur_child element of a run-tree node when given a regular
136 // node (does the casting to make code look cleaner)
137 #define rt_cur_child(tP) (((rT *)tP)->cur_child)
138 
139 typedef uint32_t TreeHash;
140 
141 // ** types for labels
142 typedef uint32_t Label;
143 
148 typedef struct table_elem {
150  Label label;
151  int path_s;
152 } table_elem;
153 typedef table_elem *LabelTable;
154 
155 // for now store instances in an INSTANCES semantic tree
156 typedef T *Instances;
157 
158 typedef struct ConversationState ConversationState;
161  T *cid;
162  ConversationState *next;
163 };
164 
165 // ** types for processing
166 // run-tree context
167 typedef struct R R;
168 struct R {
169  int id;
170  int err;
171  int state;
175  int idx;
180 };
181 
182 // ** structure to hold in process accounting
183 typedef struct Accounting Accounting;
184 struct Accounting {
185  uint64_t elapsed_time;
186 };
187 
188 // Processing Queue element
189 typedef struct Qe Qe;
190 struct Qe {
191  int id;
192  R *context;
193  Accounting accounts;
194  Qe *next;
195  Qe *prev;
196 };
197 
198 typedef struct ReceptorAddress {
199  int addr;
201 
202 typedef struct Receptor Receptor;
203 
204 // Processing Queue structure
205 typedef struct Q Q;
206 struct Q {
212  pthread_mutex_t mutex;
213 };
214 
215 // SemTable structures
216 typedef struct ContextStore {
217  T *definitions;
218  //LabelTable table; ///< the label table for this context?
219 } ContextStore;
220 
221 //@todo convert to malloc
222 #define MAX_CONTEXTS 100
223 typedef struct SemTable {
224  int contexts;
225  ContextStore stores[MAX_CONTEXTS];
226 } SemTable;
227 
228 
229 // ** types for receptors
230 enum ReceptorStates {Alive=0,Dead};
231 
237 struct Receptor {
238  T *root;
239  Context parent;
240  Context context;
243  T *flux;
244  T *pending_signals;
245  T *pending_responses;
246  T *conversations;
247  pthread_mutex_t pending_signals_mutex;
248  pthread_mutex_t pending_responses_mutex;
250  Q *q;
251  int state;
252  T *edge;
253 };
254 
255 typedef struct UUIDt {
256  uint64_t data;
257  uint64_t time;
258 } UUIDt;
259 
260 // aspects appear on either side of the membrane
261 enum AspectType {EXTERNAL_ASPECT=0,INTERNAL_ASPECT};
262 typedef Symbol Aspect; //aspects are identified by a semantic Symbol identifier
263 
267 typedef struct Xaddr {
268  Symbol symbol;
269  int addr;
270 } Xaddr;
271 
272 typedef int Error;
273 
274 // ** types for scapes
275 
279 typedef struct scape_elem {
280  TreeHash key;
283 } scape_elem;
284 typedef scape_elem *ScapeData;
285 
291 typedef struct Scape {
292  Symbol key_source;
293  Symbol data_source;
295 } Scape;
296 
297 #endif
Receptor * r
back-pointer to receptor in which this Q is running (for defs and more)
Definition: ceptr_types.h:207
T * edge
data store for edge receptors
Definition: ceptr_types.h:252
Definition: ceptr_types.h:114
int state
state information about the receptor that the vmhost manages
Definition: ceptr_types.h:251
T * parent
node_pointer's parent (cached here for efficiency)
Definition: ceptr_types.h:174
Definition: ceptr_types.h:42
Definition: ceptr_types.h:206
Context parent
the context this receptor's definition lives in
Definition: ceptr_types.h:239
TreeHash key
has of the key tree that maps to a given data value
Definition: ceptr_types.h:280
T * converse_pointer
pointer to the CONVERSE instruction in the run tree
Definition: ceptr_types.h:160
R * caller
a pointer to the context that invoked this run-tree/context
Definition: ceptr_types.h:176
T * sem_map
semantic map in effect for this context
Definition: ceptr_types.h:178
UT_hash_handle hh
makes this structure hashable using the uthash library
Definition: ceptr_types.h:282
Definition: ceptr_types.h:68
ScapeData data
the scape data store (hash table)
Definition: ceptr_types.h:294
int state
process state machine state
Definition: ceptr_types.h:171
int path_s
first int of the path to the labeled item in the Receptor tree
Definition: ceptr_types.h:151
Definition: ceptr_types.h:56
UT_hash_handle hh
makes this structure hashable using the uthash library
Definition: ceptr_types.h:149
int err
process error value
Definition: ceptr_types.h:170
T * cid
pointer to CONVERSATION_IDENT in receptors CONVERSATIONS tree
Definition: ceptr_types.h:161
Context context
the context this receptor's definition creates
Definition: ceptr_types.h:240
Xaddr value
instance of data_source pointed to by the key
Definition: ceptr_types.h:281
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
Instances instances
the instances store
Definition: ceptr_types.h:249
Q * q
process queue
Definition: ceptr_types.h:250
T * flux
pointer for quick access to the flux
Definition: ceptr_types.h:243
Qe * active
active processes
Definition: ceptr_types.h:209
int id
the process id this context exists in
Definition: ceptr_types.h:169
R * callee
a pointer to the context we've invoked
Definition: ceptr_types.h:177
int contexts_count
number of active processes
Definition: ceptr_types.h:208
Definition: ceptr_types.h:51
T * node_pointer
pointer to the tree node to execute next
Definition: ceptr_types.h:173
T * root
RECEPTOR_INSTANCE semantic tree.
Definition: ceptr_types.h:238
Qe * blocked
blocked processes
Definition: ceptr_types.h:211
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
Definition: ceptr_types.h:242
Definition: ceptr_types.h:83
Label label
semantic key
Definition: ceptr_types.h:150
ConversationState * conversation
record of the conversation state active in this context frame
Definition: ceptr_types.h:179
int idx
node pointers child index (cached here for efficiency)
Definition: ceptr_types.h:175
Qe * completed
completed processes (pending cleanup)
Definition: ceptr_types.h:210
T * run_tree
pointer to the root of the run_tree
Definition: ceptr_types.h:172
Definition: ceptr_types.h:168