ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
process_spec.h
Go to the documentation of this file.
1 
7 #include "../src/ceptr.h"
8 #include "../src/process.h"
9 
10 void testRunTree() {
11  T *code;
12 
13  // a process that would look something like this in lisp:
14  // (defun my_if (true_branch false_branch condition) (if (condition) (true_branch) (false_branch)))
15  code = _t_parse(G_sem,0,"(IF (PARAM_REF:/2/3) (PARAM_REF:/2/1) (PARAM_REF:/2/2))");
16 
17  T *signature = __p_make_signature("result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
18  "condition",SIGNATURE_PROCESS,BOOLEAN,
19  "true_branch",SIGNATURE_ANY,NULL_STRUCTURE,
20  "false_branch",SIGNATURE_ANY,NULL_STRUCTURE,
21  NULL);
22 
23  // test that __p_make_signature does what we think it should
24  spec_is_str_equal(t2s(signature),"(PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:result)) (SIGNATURE_PASSTHRU)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:condition)) (SIGNATURE_PROCESS:BOOLEAN)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:true_branch)) (SIGNATURE_ANY)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:false_branch)) (SIGNATURE_ANY)))");
25 
26  Process p = _d_define_process(G_sem,code,"myif","a duplicate of the sys if process with params in different order",signature,NULL,TEST_CONTEXT);
27 
28  T *params = _t_parse(G_sem,0,"(PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321) (BOOLEAN:1))");
29 
30  T *r = _p_make_run_tree(G_sem,p,params,NULL);
31  _t_free(params);
32 
33  spec_is_str_equal(t2s(r),"(RUN_TREE (process:IF (PARAM_REF:/2/3) (PARAM_REF:/2/1) (PARAM_REF:/2/2)) (PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321) (BOOLEAN:1)))");
34 
35  spec_is_equal(_p_reduce(G_sem,r),noReductionErr);
36 
37  spec_is_str_equal(t2s(_t_child(r,1)),"(TEST_INT_SYMBOL:123)");
38 
39  _t_free(r);
40 
41  params = _t_parse(G_sem,0,"(PARAMS (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321))");
42  // you can also create a run tree with a system process
43 
44  r = _p_make_run_tree(G_sem,ADD_INT,params,NULL);
45  _t_free(params);
46  spec_is_str_equal(t2s(r),"(RUN_TREE (process:ADD_INT (TEST_INT_SYMBOL:123) (TEST_INT_SYMBOL:321)) (PARAMS))");
47 
48  _t_free(r);
49 }
50 
51 //-----------------------------------------------------------------------------------------
52 // tests of system processes
53 
54 void testProcessGet() {
55  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
56  Q *q = r->q;
57 
58  T *t = _t_newi(0,TEST_INT_SYMBOL,314);
59  Xaddr x = _r_new_instance(r,t);
60 
61  T *n = _t_newr(0,GET);
62  _t_new(n,WHICH_XADDR,&x,sizeof(Xaddr));
63  T *run_tree = __p_build_run_tree(n,0);
64  _t_free(n);
65  Qe *e = _p_addrt2q(q,run_tree);
66  spec_is_equal(_p_reduceq(q),noReductionErr);
67 
68  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
69  t = _t_new_root(ITERATION_DATA);
70  _a_get_instances(&r->instances,TEST_INT_SYMBOL,t);
71  spec_is_str_equal(t2s(t),"(ITERATION_DATA (TEST_INT_SYMBOL:314))");
72  _t_free(t);
73 
74  _r_free(r);
75 }
76 
77 void testProcessDel() {
78  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
79  Q *q = r->q;
80 
81  T *t = _t_newi(0,TEST_INT_SYMBOL,314);
82  Xaddr x = _r_new_instance(r,t);
83 
84  T *n = _t_newr(0,DEL);
85  _t_new(n,WHICH_XADDR,&x,sizeof(Xaddr));
86  T *run_tree = __p_build_run_tree(n,0);
87  _t_free(n);
88  Qe *e = _p_addrt2q(q,run_tree);
89  spec_is_equal(_p_reduceq(q),noReductionErr);
90 
91  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
92  t = _t_new_root(ITERATION_DATA);
93  _a_get_instances(&r->instances,TEST_INT_SYMBOL,t);
94  spec_is_str_equal(t2s(t),"(ITERATION_DATA)");
95  _t_free(t);
96 
97  _r_free(r);
98 }
99 
100 void testProcessNew() {
101  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
102  Q *q = r->q;
103 
104  T *n = _t_newr(0,NEW);
105  _t_news(n,NEW_TYPE,TEST_INT_SYMBOL);
106  _t_new_str(n,TEST_STR_SYMBOL,"fish");
107  T *run_tree = __p_build_run_tree(n,0);
108  _t_free(n);
109  Qe *e = _p_addrt2q(q,run_tree);
110  _p_reduceq(q);
111 
112  spec_is_equal(r->q->completed->context->err,structureMismatchReductionErr);
113 
114  n = _t_newr(0,NEW);
115  _t_news(n,NEW_TYPE,TEST_INT_SYMBOL);
116  _t_newi(n,TEST_INT_SYMBOL2,314);
117  run_tree = __p_build_run_tree(n,0);
118  _t_free(n);
119  e = _p_addrt2q(q,run_tree);
120  spec_is_equal(_p_reduceq(q),noReductionErr);
121 
122  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (WHICH_XADDR:TEST_INT_SYMBOL.1) (PARAMS))");
123  T *i = _r_get_instance(r,*(Xaddr *)_t_surface(_t_child(run_tree,1)));
124  spec_is_str_equal(t2s(i),"(TEST_INT_SYMBOL:314)");
125  // _t_free(i);
126  _r_free(r);
127 }
128 
129 void testProcessDefine() {
130  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
131 
132  T *p = _t_parse(r->sem,0,"(DEF_SYMBOL (SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:\"age\")) (SYMBOL_STRUCTURE:INTEGER)))");
133  spec_is_equal(__p_reduce_sys_proc(0,DEF_SYMBOL,p,r->q),noReductionErr);
134  spec_is_str_equal(t2s(p),"(RESULT_SYMBOL:age)");
135  T *d = _sem_get_def(r->sem,*(Symbol *)_t_surface(p));
136  spec_is_str_equal(t2s(d),"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:age)) (SYMBOL_STRUCTURE:INTEGER))");
137  _t_free(p);
138 
139  p = _t_parse(r->sem,0,"(DEF_STRUCTURE (STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:\"age_pair\")) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:age) (STRUCTURE_SYMBOL:age)))");
140  spec_is_equal(__p_reduce_sys_proc(0,DEF_STRUCTURE,p,r->q),noReductionErr);
141  spec_is_str_equal(t2s(p),"(RESULT_STRUCTURE:age_pair)");
142  d = _sem_get_def(r->sem,*(Symbol *)_t_surface(p));
143  spec_is_str_equal(t2s(d),"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:age_pair)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:age) (STRUCTURE_SYMBOL:age)))");
144  _t_free(p);
145 
146  p = _t_parse(r->sem,0,"(DEF_PROCESS (PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:\"power\")) (PROCESS_INTENTION:\"takes the mathematical power of the two params\") (NOOP) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"result\")) (SIGNATURE_SYMBOL:NULL_SYMBOL)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"val\")) (SIGNATURE_STRUCTURE:INTEGER)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:\"exponent\")) (SIGNATURE_STRUCTURE:INTEGER))) (PROCESS_LINK (PROCESS_OF_STRUCTURE:INTEGER) (PROCESS_TYPE (OPERATOR))))");
147  spec_is_equal(__p_reduce_sys_proc(0,DEF_PROCESS,p,r->q),noReductionErr);
148  spec_is_str_equal(t2s(p),"(RESULT_PROCESS:power)");
149  d = _sem_get_def(r->sem,*(Symbol *)_t_surface(p));
150  spec_is_str_equal(t2s(d),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:power)) (PROCESS_INTENTION:takes the mathematical power of the two params) (process:NOOP) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:result)) (SIGNATURE_SYMBOL:NULL_SYMBOL)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:val)) (SIGNATURE_STRUCTURE:INTEGER)) (INPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:exponent)) (SIGNATURE_STRUCTURE:INTEGER))) (PROCESS_LINK (PROCESS_OF_STRUCTURE:INTEGER) (PROCESS_TYPE (OPERATOR))))");
151  _t_free(p);
152 
153  p = _t_parse(r->sem,0,"(DEF_RECEPTOR (RECEPTOR_DEFINITION (RECEPTOR_LABEL (ENGLISH_LABEL:\"streamscapes\")) (DEFINITIONS (STRUCTURES) (SYMBOLS) (PROCESSES) (RECEPTORS) (PROTOCOLS) (SCAPES)))");
154  spec_is_equal(__p_reduce_sys_proc(0,DEF_RECEPTOR,p,r->q),noReductionErr);
155  spec_is_str_equal(t2s(p),"(RESULT_RECEPTOR:streamscapes)");
156  d = _sem_get_def(r->sem,*(Symbol *)_t_surface(p));
157  spec_is_str_equal(t2s(d),"(RECEPTOR_DEFINITION (RECEPTOR_LABEL (ENGLISH_LABEL:streamscapes)) (DEFINITIONS (STRUCTURES) (SYMBOLS) (PROCESSES) (RECEPTORS) (PROTOCOLS) (SCAPES)))");
158  _t_free(p);
159 
160  _d_define_symbol(G_sem,RECEPTOR_ADDRESS,"agent",r->context);
161  _d_define_symbol(G_sem,PROCESS,"process",r->context);
162  _d_define_symbol(G_sem,SYMBOL,"data",r->context);
163  _d_define_symbol(G_sem,INTERACTION,"act",r->context);
164 
165  p = _t_parse(r->sem,0,"(DEF_PROTOCOL (PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:\"do\")) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:data) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:process) (SLOT_IS_VALUE_OF:ACTION))))))");
166  spec_is_equal(__p_reduce_sys_proc(0,DEF_PROTOCOL,p,r->q),noReductionErr);
167  spec_is_str_equal(t2s(p),"(RESULT_PROTOCOL:do)");
168  d = _sem_get_def(r->sem,*(Symbol *)_t_surface(p));
169  spec_is_str_equal(t2s(d),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:do)) (PROTOCOL_SEMANTICS (ROLE:agent) (GOAL:process) (USAGE:data)) (act (EXPECT (ROLE:agent) (SOURCE (ROLE:agent)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:data) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (SLOT (GOAL:process) (SLOT_IS_VALUE_OF:ACTION)))))");
170  _t_free(p);
171 
172  _r_free(r);
173 }
174 
175 void testProcessDo() {
176  T *code = _t_parse(G_sem,0,"(DO (SCOPE (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2)))");
177  spec_is_equal(__p_reduce_sys_proc(0,DO,code,0),noReductionErr);
178  spec_is_str_equal(t2s(code),"(TEST_INT_SYMBOL:2)");
179  _t_free(code);
180 }
181 
182 void testProcessTranscode() {
183  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
184 
185  // transcode of same structure should just change the symbol type
186  T *n;
187  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_INT_SYMBOL)) (TRANSCODE_ITEMS (TEST_INT_SYMBOL2:314)))");
188  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
189  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:314)");
190  _t_free(n);
191 
192  // transcode of INTEGER to CSTRING
193  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (TEST_INT_SYMBOL2:314)))");
194  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
195  spec_is_str_equal(t2s(n),"(TEST_STR_SYMBOL:314)");
196  _t_free(n);
197 
198  // transcode of FLOAT to CSTRING
199  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (TEST_FLOAT_SYMBOL:3.14159)))");
200  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
201  spec_is_str_equal(t2s(n),"(TEST_STR_SYMBOL:3.141590)");
202  _t_free(n);
203 
204  // transcode of CHAR to CSTRING
205  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_STR_SYMBOL)) (TRANSCODE_ITEMS (ASCII_CHAR:'x')))");
206  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
207  spec_is_str_equal(t2s(n),"(TEST_STR_SYMBOL:x)");
208  _t_free(n);
209 
210  // transcode of CSTRING to INTEGER
211  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:TEST_INT_SYMBOL)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"314\")))");
212  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
213  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:314)");
214  _t_free(n);
215 
216  //debug_enable(D_TRANSCODE);
217  // transcode of matching optionality structures
218  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (TEST_INTEGERS (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:2) (TEST_INT_SYMBOL:314))))");
219  spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),redoReduction);
220  spec_is_str_equal(t2s(n),"(LINES (LINE:1) (LINE:2) (LINE:314))");
221  _t_free(n);
222  debug_disable(D_TRANSCODE);
223 
224  //transcode of constructed symbol to CSTRING
225  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINE)) (TRANSCODE_ITEMS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE))))");
226  Q *q = r->q;
227  T *run_tree = __p_build_run_tree(n,0);
228  _t_free(n);
229  Qe *e = _p_addrt2q(q,run_tree);
230  spec_is_equal(_p_reduceq(q),noReductionErr);
231  spec_is_str_equal(t2s(_t_child(run_tree,1)),"(LINE:Content-Type: text/ceptr)");
232 
233  // debug_enable(D_REDUCE+D_REDUCEV);
234  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINE)) (TRANSCODE_ITEMS (TODAY (YEAR:2015) (MONTH:1) (DAY:30))))");
235 
236  // spec_is_equal(__p_reduce_sys_proc(0,TRANSCODE,n,r->q),noReductionErr);
237  run_tree = __p_build_run_tree(n,0);
238  _t_free(n);
239  e = _p_addrt2q(q,run_tree);
240  spec_is_equal(_p_reduceq(q),noReductionErr);
241  debug_disable(D_REDUCE+D_REDUCEV);
242  spec_is_str_equal(t2s(_t_child(run_tree,1)),"(US_SHORT_DATE:1/30/2015)");
243 
244  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:LINES)) (TRANSCODE_ITEMS (HTTP_HEADERS (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:CEPTR_TEXT_MEDIA_SUBTYPE)) (CONTENT_TYPE (MEDIA_TYPE_IDENT:TEXT_MEDIA_TYPE) (MEDIA_SUBTYPE_IDENT:HTML_TEXT_MEDIA_SUBTYPE)))))");
245  run_tree = __p_build_run_tree(n,0);
246  _t_free(n);
247  _p_addrt2q(q,run_tree);
248  spec_is_equal(_p_reduceq(q),noReductionErr);
249  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (LINES (LINE:Content-Type: text/ceptr) (LINE:Content-Type: text/html)) (PARAMS))");
250 
251  n = _t_parse(G_sem,0,"(ascii_chars_2_http_req (TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:ASCII_CHARS)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"GET /path/to/file.ext?name=joe&age=30 HTTP/0.9\n\"))))");
252 
253  run_tree = __p_build_run_tree(n,0);
254  _t_free(n);
255  _p_addrt2q(q,run_tree);
256  spec_is_equal(_p_reduceq(q),noReductionErr);
257  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
258 
259  // debug_enable(D_TRANSCODE+D_STEP);
260  // debug_enable(D_REDUCE+D_REDUCEV);
261 
262  n = _t_parse(G_sem,0,"(TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:HTTP_REQUEST)) (TRANSCODE_ITEMS (TRANSCODE (TRANSCODE_PARAMS (TRANSCODE_TO:ASCII_CHARS)) (TRANSCODE_ITEMS (TEST_STR_SYMBOL:\"GET /path/to/file.ext?name=joe&age=30 HTTP/0.9\n\")))))");
263 
264  run_tree = __p_build_run_tree(n,0);
265  _t_free(n);
266  _p_addrt2q(q,run_tree);
267  spec_is_equal(_p_reduceq(q),noReductionErr);
268  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_PATH_QUERY (HTTP_REQUEST_PATH_QUERY_PARAMS (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:name) (PARAM_VALUE:joe)) (HTTP_REQUEST_PATH_QUERY_PARAM (PARAM_KEY:age) (PARAM_VALUE:30)))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
269 
270  debug_disable(D_TRANSCODE);
271  debug_disable(D_REDUCE+D_REDUCEV);
272  debug_disable(D_STEP);
273 
274  _r_free(r);
275 }
276 
277 void testProcessDissolve() {
278  T *n = _t_new_root(DISSOLVE);
279  spec_is_equal(__p_reduce_sys_proc(0,DISSOLVE,n,0),structureMismatchReductionErr);
280  _t_free(n);
281 
282  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
283 
284  n = _t_parse(G_sem,0,"(LINES (LINE:\"fish\") (DISSOLVE (LINES (LINE:\"cat\") (LINE:\"dog\"))) (CONCAT_STR (RESULT_SYMBOL:LINE) (TEST_STR_SYMBOL:\"sh\") (TEST_STR_SYMBOL:\"oe\")))");
285 
286  Q *q = r->q;
287  T *run_tree = __p_build_run_tree(n,0);
288  _t_free(n);
289  Qe *e = _p_addrt2q(q,run_tree);
290  spec_is_equal(_p_reduceq(q),noReductionErr);
291  spec_is_str_equal(t2s(_t_child(run_tree,1)),"(LINES (LINE:fish) (LINE:cat) (LINE:dog) (LINE:shoe))");
292 
293  // @todo when we have var arg signatures then this spec should be made to work
294  /* n = _t_build(G_sem,0,LINES,LINE,"fish",DISSOLVE,LINE,"cat",LINE,"dog",NULL_SYMBOL,NULL_SYMBOL); */
295  /* run_tree = __p_build_run_tree(n,0); */
296  /* _t_free(n); */
297  /* _p_addrt2q(q,run_tree); */
298  /* spec_is_equal(_p_reduceq(q),noReductionErr); */
299  /* spec_is_str_equal(t2s(_t_child(run_tree,1)),"(LINES (LINE:fish) (LINE:cat) (LINE:dog))"); */
300 
301  _r_free(r);
302 }
303 
304 void testProcessSemtrex() {
305 
306  // test string concatenation
307  T *n = _t_new_root(MATCH);
308  T *pattern = _sl(n,TICK);
309  T *t = __r_make_tick();
310  _t_add(n,t);
311  __p_reduce_sys_proc(0,MATCH,n,0);
312  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
313  _t_free(n);
314 
315  n = _t_new_root(MATCH);
316  pattern = _sl(n,TICK);
317  _t_newi(n,TEST_INT_SYMBOL,1);
318  __p_reduce_sys_proc(0,MATCH,n,0);
319  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
320  _t_free(n);
321 
322  n = _t_new_root(MATCH);
323  pattern = _t_newr(n,SEMTREX_WALK);
324  T *g = _t_news(pattern,SEMTREX_GROUP,TEST_CHAR_SYMBOL);
325  __stxcv(g,'s');
326  t = makeASCIITree("fish");
327  _t_add(n,t);
328  _t_newi(n,BOOLEAN,1);
329  __p_reduce_sys_proc(0,MATCH,n,0);
330  spec_is_str_equal(t2s(n),"(SEMTREX_MATCH:1 (SEMTREX_MATCH_SYMBOL:TEST_CHAR_SYMBOL) (SEMTREX_MATCH_PATH:/3) (SEMTREX_MATCH_SIBLINGS_COUNT:1))");
331 
332  _t_free(n);
333 }
334 
335 void testProcessFill() {
336  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
337  T *n = _t_parse(G_sem,0,"(FILL (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (TEST_INT_SYMBOL:1) (SLOT (USAGE:REQUEST_TYPE)))) (SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (TEST_INT_SYMBOL:32))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:ADD_INT)))))");
338  spec_is_equal(__p_reduce_sys_proc(0,FILL,n,r->q),noReductionErr);
339 
340  //@todo, should this have been reduced too? Or should there be an explicit eval kind of thing?
341  spec_is_str_equal(t2s(n),"(process:ADD_INT (TEST_INT_SYMBOL:1) (TEST_INT_SYMBOL:32))");
342  _t_free(n);
343  _r_free(r);
344 }
345 
346 void testProcessFillMatch() {
347  T *t = _t_new_root(RUN_TREE);
348  // test FILL_FROM_MATCH which takes three params, the template tree, the stx-match and the tree it matched on
349  T *n = _t_new_root(FILL_FROM_MATCH);
350  T *p1 = _t_newr(n,TEST_ANYTHING_SYMBOL);
351  T *s = _t_newr(p1,SLOT);
352  _t_news(s,USAGE,TEST_INT_SYMBOL2);
353  T *p2 = _t_newi(n,SEMTREX_MATCH,1);
354  _t_news(p2,SEMTREX_MATCH,TEST_INT_SYMBOL2);
355  int path[] = {TREE_PATH_TERMINATOR};
356  _t_new(p2,SEMTREX_MATCH_PATH,path,2*sizeof(int));
357  _t_newi(p2,SEMTREX_MATCH_SIBLINGS_COUNT,1);
358  T *p3 = _t_newi(n,TEST_INT_SYMBOL2,314);
359 
360  // @todo N.B. SEMTREX_MATCH is not used correctly, the structure is interpreted two different
361  // ways, as both and INT and SYMBOL, so we can't use parse because it will fail on the incorrect type
362  //n = _t_parse(G_sem,0,"(FILL_FROM_MATCH (TEST_ANYTHING_SYMBOL (SLOT (USAGE:TEST_INT_SYMBOL2))) (SEMTREX_MATCH:1 (SEMTREX_MATCH:TEST_INT_SYMBOL2) (SEMTREX_MATCH_PATH:/) (SEMTREX_MATCH_SIBLINGS_COUNT:1)) (TEST_INT_SYMBOL2:314))");
363 
364  T *c = _t_rclone(n);
365  _t_add(t,c);
366  _p_reduce(G_sem,t);
367 
368  spec_is_str_equal(t2s(_t_child(t,1)),"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL2:314))");
369  _t_free(t);
370  _t_free(n);
371 }
372 
373 void testProcessFillMatchFull() {
374  T *t = _t_new_root(RUN_TREE);
375  // test FILL_FROM_MATCH which takes three params, the template tree, the stx-match and the tree it matched on
376  T *n = _t_new_root(FILL_FROM_MATCH);
377  T *p1 = _t_newr(n,TEST_ANYTHING_SYMBOL);
378  T *s = _t_newr(p1,SLOT);
379  _t_news(s,USAGE,NULL_SYMBOL);
380  T *p2 = _t_newi(n,SEMTREX_MATCH,1);
381  _t_news(p2,SEMTREX_MATCH,NULL_SYMBOL);
382  int path[] = {TREE_PATH_TERMINATOR};
383  _t_new(p2,SEMTREX_MATCH_PATH,path,2*sizeof(int));
384  _t_newi(p2,SEMTREX_MATCH_SIBLINGS_COUNT,1);
385  T *p3 = _t_newi(n,TEST_INT_SYMBOL,314);
386 
387  T *c = _t_rclone(n);
388  _t_add(t,c);
389  _p_reduce(G_sem,t);
390 
391  spec_is_str_equal(t2s(_t_child(t,1)),"(TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314))");
392  _t_free(t);
393  _t_free(n);
394 }
395 
397 
399  // test IF which takes three parameters, the condition, the true code tree and the false code tree
400  T *n = _t_new_root(IF);
401  T *p1 = _t_newi(n,BOOLEAN,1);
402  T *p2 = _t_newi(n,TEST_INT_SYMBOL,99);
403  T *p3 = _t_newi(n,TEST_INT_SYMBOL,100);
404 
405  __p_reduce_sys_proc(0,IF,n,0);
406  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:99)");
407 
408  _t_free(n);
409 }
410 
411 void testProcessCond(){
412  T *t = _t_new_root(RUN_TREE);
413  T *n = _t_parse(G_sem,0,"(COND (CONDITIONS (COND_PAIR (BOOLEAN:0) (ASCII_CHAR:'x')) (COND_ELSE (ASCII_CHAR:'y'))))");
414  T *c = _t_rclone(n);
415  _t_add(t,c);
416  _p_reduce(G_sem,t);
417 
418  spec_is_str_equal(t2s(_t_child(t,1)),"(ASCII_CHAR:'y')");
419  _t_free(t);
420  _t_free(n);
421 
422  t = _t_new_root(RUN_TREE);
423  n = _t_parse(G_sem,0,"(COND (CONDITIONS (COND_PAIR (BOOLEAN:0) (ASCII_CHAR:'x')) (COND_PAIR (BOOLEAN:1) (ASCII_CHAR:'y')) (COND_ELSE (ASCII_CHAR:'z'))))");
424  c = _t_rclone(n);
425  _t_add(t,c);
426  _p_reduce(G_sem,t);
427 
428  spec_is_str_equal(t2s(_t_child(t,1)),"(ASCII_CHAR:'y')");
429  _t_free(t);
430  _t_free(n);
431 }
432 
433 void testProcessSym() {
434  T *n = _t_new_root(EQ_SYM);
435  _t_news(n,EQUALITY_TEST_SYMBOL,TEST_INT_SYMBOL);
436  _t_news(n,TEST_SYMBOL_SYMBOL,TEST_INT_SYMBOL);
437  __p_reduce_sys_proc(0,EQ_SYM,n,0);
438  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
439  _t_free(n);
440  n = _t_new_root(EQ_SYM);
441  _t_news(n,EQUALITY_TEST_SYMBOL,TEST_INT_SYMBOL);
442  _t_news(n,TEST_SYMBOL_SYMBOL,TEST_STR_SYMBOL);
443  __p_reduce_sys_proc(0,EQ_SYM,n,0);
444  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
445  _t_free(n);
446 }
447 
449  T *t;
450 
451  // test addition
452  T *n = _t_new_root(ADD_INT);
453  _t_newi(n,TEST_INT_SYMBOL,99);
454  _t_newi(n,TEST_INT_SYMBOL,100);
455  __p_reduce_sys_proc(0,ADD_INT,n,0);
456  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:199)");
457  _t_free(n);
458 
460  // where do we get the defs. Right now they are referred to in the process q
461  // which the contexts don't have direct access to.
462  /* n = _t_new_root(ADD_INT); */
463  /* spec_is_sem_equal(_sem_get_symbol_structure(G_sem,s),INTEGER); */
464  /* _t_newi(n,TEST_INT_SYMBOL,99); */
465  /* T *s = _t_newr(n,SLOT); */
466  /* _t_news(s,USAGE,TEST_INT_SYMBOL); */
467  /* spec_is_equal(__p_reduce_sys_proc(0,ADD_INT,n,0),incompatibleTypeReductionErr); */
468  /* spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:199)"); */
469  /* _t_free(n); */
470 
471  // test subtraction
472  n = _t_new_root(SUB_INT);
473  _t_newi(n,TEST_INT_SYMBOL,100);
474  _t_newi(n,TEST_INT_SYMBOL,98);
475  __p_reduce_sys_proc(0,SUB_INT,n,0);
476  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:2)");
477  _t_free(n);
478 
479  // test multiplication
480  n = _t_new_root(MULT_INT);
481  _t_newi(n,TEST_INT_SYMBOL,100);
482  _t_newi(n,TEST_INT_SYMBOL,98);
483  __p_reduce_sys_proc(0,MULT_INT,n,0);
484  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:9800)");
485  _t_free(n);
486 
487  // test division
488  n = _t_new_root(DIV_INT);
489  _t_newi(n,TEST_INT_SYMBOL,100);
490  _t_newi(n,TEST_INT_SYMBOL,48);
491  __p_reduce_sys_proc(0,DIV_INT,n,0);
492  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:2)");
493  _t_free(n);
494 
495  // test division with divide by zero
496  n = _t_new_root(DIV_INT);
497  _t_newi(n,TEST_INT_SYMBOL,100);
498  _t_newi(n,TEST_INT_SYMBOL,0);
499  spec_is_equal(__p_reduce_sys_proc(0,DIV_INT,n,0),divideByZeroReductionErr);
500  _t_free(n);
501 
502  // test modulo
503  n = _t_new_root(MOD_INT);
504  _t_newi(n,TEST_INT_SYMBOL,100);
505  _t_newi(n,TEST_INT_SYMBOL,2);
506  __p_reduce_sys_proc(0,MOD_INT,n,0);
507  spec_is_str_equal(t2s(n),"(TEST_INT_SYMBOL:0)");
508  _t_free(n);
509 
510  // test modulo with divide by zero
511  n = _t_new_root(MOD_INT);
512  _t_newi(n,TEST_INT_SYMBOL,100);
513  _t_newi(n,TEST_INT_SYMBOL,0);
514  spec_is_equal(__p_reduce_sys_proc(0,MOD_INT,n,0),divideByZeroReductionErr);
515  _t_free(n);
516 
517  // test equals
518  n = _t_new_root(EQ_INT);
519  _t_newi(n,TEST_INT_SYMBOL,100);
520  _t_newi(n,TEST_INT_SYMBOL,2);
521  __p_reduce_sys_proc(0,EQ_INT,n,0);
522  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
523  _t_free(n);
524 
525  n = _t_new_root(EQ_INT);
526  _t_newi(n,TEST_INT_SYMBOL,100);
527  _t_newi(n,TEST_INT_SYMBOL,100);
528  __p_reduce_sys_proc(0,EQ_INT,n,0);
529  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
530  _t_free(n);
531 
532  // test <
533  n = _t_new_root(LT_INT);
534  _t_newi(n,TEST_INT_SYMBOL,2);
535  _t_newi(n,TEST_INT_SYMBOL,100);
536  __p_reduce_sys_proc(0,LT_INT,n,0);
537  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
538  _t_free(n);
539 
540  n = _t_new_root(LT_INT);
541  _t_newi(n,TEST_INT_SYMBOL,100);
542  _t_newi(n,TEST_INT_SYMBOL,100);
543  __p_reduce_sys_proc(0,LT_INT,n,0);
544  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
545  _t_free(n);
546 
547  // test >
548  n = _t_new_root(GT_INT);
549  _t_newi(n,TEST_INT_SYMBOL,2);
550  _t_newi(n,TEST_INT_SYMBOL,100);
551  __p_reduce_sys_proc(0,GT_INT,n,0);
552  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
553  _t_free(n);
554 
555  n = _t_new_root(GT_INT);
556  _t_newi(n,TEST_INT_SYMBOL,101);
557  _t_newi(n,TEST_INT_SYMBOL,100);
558  __p_reduce_sys_proc(0,GT_INT,n,0);
559  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
560  _t_free(n);
561 
562 }
563 
564 void testProcessPath() {
565  T *p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION))");
566  __p_reduce_sys_proc(0,POP_PATH,p,0);
567  spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/4/1)");
568  _t_free(p);
569  p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:2))");
570  __p_reduce_sys_proc(0,POP_PATH,p,0);
571  spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/4)");
572  _t_free(p);
573  p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:3))");
574  __p_reduce_sys_proc(0,POP_PATH,p,0);
575  spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/)");
576  _t_free(p);
577  p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:10))");
578  __p_reduce_sys_proc(0,POP_PATH,p,0);
579  spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/)");
580  _t_free(p);}
581 
582 void testProcessString() {
583 
584  T *run_tree = _t_new_root(RUN_TREE);
585  R *c = __p_make_context(run_tree,0,0,NULL);
586  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
587 
588  // test string concatenation
589  T *n = _t_new_root(CONCAT_STR);
590  _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
591  _t_new_str(n,TEST_STR_SYMBOL,"Fred");
592  _t_new_str(n,TEST_STR_SYMBOL," ");
593  _t_new_str(n,TEST_STR_SYMBOL,"Smith");
594  spec_is_equal(__p_reduce_sys_proc(c,CONCAT_STR,n,r->q),noReductionErr);
595 
596  spec_is_str_equal(t2s(n),"(TEST_NAME_SYMBOL:Fred Smith)");
597  _t_free(n);
598 
599  // test string to char tree conversion
600  n = _t_new_root(EXPAND_STR);
601  _t_new_str(n,TEST_STR_SYMBOL,"fish");
602  spec_is_equal(__p_reduce_sys_proc(0,EXPAND_STR,n,0),noReductionErr);
603  spec_is_str_equal(t2s(n),"(ASCII_CHARS (ASCII_CHAR:'f') (ASCII_CHAR:'i') (ASCII_CHAR:'s') (ASCII_CHAR:'h'))");
604  _t_free(n);
605 
606  // test string contraction
607  n = _t_new_root(CONTRACT_STR);
608  _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
609  char xx = 'F';
610  _t_new(n,ASCII_CHAR,&xx,sizeof(char));
611  _t_new_str(n,TEST_STR_SYMBOL,"red");
612  xx = ' ';
613  _t_new(n,ASCII_CHAR,&xx,sizeof(char));
614  _t_new_str(n,TEST_STR_SYMBOL,"Smith");
615  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),noReductionErr);
616  spec_is_str_equal(t2s(n),"(TEST_NAME_SYMBOL:Fred Smith)");
617  _t_free(n);
618 
619  n = _t_new_root(CONTRACT_STR);
620  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),tooFewParamsReductionErr);
621  _t_newi(n,TEST_INT_SYMBOL,314);
622  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),signatureMismatchReductionErr);
623  _t_news(n,RESULT_SYMBOL,TEST_INT_SYMBOL);
624  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),signatureMismatchReductionErr);
625  _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
626  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),tooFewParamsReductionErr);
627  _t_news(n,RESULT_SYMBOL,TEST_NAME_SYMBOL);
628  _t_newi(n,TEST_INT_SYMBOL,314);
629  spec_is_equal(__p_reduce_sys_proc(c,CONTRACT_STR,n,r->q),incompatibleTypeReductionErr);
630  _t_free(n);
631 
632  _p_free_context(c);
633  _r_free(r);
634 
635 }
636 
637 void testProcessRespond() {
638  // testing responding to a signal requires setting up a sending signal context
639 
640  T *signal_contents = _t_newi(0,TEST_INT_SYMBOL,314);
641  ReceptorAddress f = {3}; // DUMMY ADDR
642  ReceptorAddress t = {4}; // DUMMY ADDR
643 
644  T *s = __r_make_signal(f,t,DEFAULT_ASPECT,TESTING,signal_contents,0,defaultRequestUntil(),0);
645 
646  T *run_tree = _t_new_root(RUN_TREE);
647  T *n = _t_newr(run_tree,RESPOND);
648  _t_news(n,CARRIER,TESTING);
649 
650  T *response_contents = _t_newi(n,TEST_INT_SYMBOL,271);
651 
652  R *c = __p_make_context(run_tree,0,0,NULL);
653 
654  // if this is a run-tree that's not a child of a signal we can't respond!
655  spec_is_equal(__p_reduce_sys_proc(c,RESPOND,n,0),notInSignalContextReductionError);
656 
657  // now add it to the signal and try again
658  _t_add(s,run_tree);
659 
660  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
661 
662  // it should create a response signal with the source UUID as the responding to UUID
663  spec_is_equal(__p_reduce_sys_proc(c,RESPOND,n,r->q),noReductionErr);
664  spec_is_str_equal(t2s(n),"(SIGNAL_UUID)");
665  spec_is_str_equal(_td(r,r->pending_signals),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:4)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (IN_RESPONSE_TO_UUID)) (BODY:{(TEST_INT_SYMBOL:271)}))))");
666  T *u1 = _t_child(_t_child(s,SignalEnvelopeIdx),EnvelopeSignalUUIDIdx);
667  int p[] = {1,SignalMessageIdx,MessageHeadIdx,HeadOptionalsIdx,TREE_PATH_TERMINATOR};
668  T *u2 = _t_get(r->pending_signals,p);
669  spec_is_true(__uuid_equal(_t_surface(u1),_t_surface(u2)));
670 
671  _p_free_context(c);
672  _t_free(s);
673 
674  _r_free(r);
675 }
676 extern int G_next_process_id;
677 
678 void testProcessSay() {
679  T *p = _t_newr(0,SAY);
680  ReceptorAddress to = {99}; // DUMMY ADDR
681 
682  __r_make_addr(p,TO_ADDRESS,to);
683  _t_news(p,ASPECT_IDENT,DEFAULT_ASPECT);
684  _t_news(p,CARRIER,TESTING);
685  _t_newi(p,TEST_INT_SYMBOL,314);
686 
687  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
688 
689  T *run_tree = __p_build_run_tree(p,0);
690  _t_free(p);
691 
692  // add the run tree into a queue and run it
693  G_next_process_id = 0; // reset the process ids so the test will always work
694  Q *q = r->q;
695  T *ps = r->pending_signals;
696  Qe *e =_p_addrt2q(q,run_tree);
697  R *c = e->context;
698 
699  // after reduction the context should be in the blocked state
700  // and the signal should be on the pending signals list
701  // the UUID should be in pending responses list
702  spec_is_equal(_p_reduceq(q),noReductionErr);
703  spec_is_equal(q->contexts_count,0);
704 
705  // say reduces to the UUID generated for the sent signal
706  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (SIGNAL_UUID) (PARAMS))");
707  spec_is_str_equal(t2s(ps),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING)) (BODY:{(TEST_INT_SYMBOL:314)}))))");
708  _r_free(r);
709 }
710 
711 void testProcessRequest() {
712  T *p = _t_newr(0,REQUEST);
713  ReceptorAddress to = {99}; // DUMMY ADDR
714 
715  __r_make_addr(p,TO_ADDRESS,to);
716  _t_news(p,ASPECT_IDENT,DEFAULT_ASPECT);
717  _t_news(p,CARRIER,TESTING);
718  _t_newi(p,TEST_INT_SYMBOL,314);
719  _t_news(p,RESPONSE_CARRIER,TESTING);
720  T *ec = _t_newr(p,END_CONDITIONS);
721  _t_newi(ec,COUNT,1);
722 
723  T *code =_t_rclone(p);
724  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
725 
726  T *run_tree = __p_build_run_tree(code,0);
727 
728  spec_is_str_equal(_td(r,run_tree),"(RUN_TREE (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1))) (PARAMS))");
729 
730  // add the run tree into a queue and run it
731  G_next_process_id = 0; // reset the process ids so the test will always work
732  Q *q = r->q;
733  T *ps = r->pending_signals;
734  Qe *e =_p_addrt2q(q,run_tree);
735  R *c = e->context;
736 
737  // after reduction the context should be in the blocked state
738  // and the signal should be on the pending signals list
739  // the UUID should be in pending responses list
740  spec_is_equal(_p_reduceq(q),noReductionErr);
741  spec_is_equal(q->contexts_count,0);
742  spec_is_ptr_equal(q->blocked,e);
743  spec_is_equal(c->state,Block);
744  spec_is_str_equal(_td(r,r->pending_responses),"(PENDING_RESPONSES (PENDING_RESPONSE (SIGNAL_UUID) (CARRIER:TESTING) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1)) (END_CONDITIONS (COUNT:1))))");
745 
746  // request reduces to the UUID generated for the sent signal
747  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (SIGNAL_UUID) (PARAMS))");
748  spec_is_str_equal(t2s(ps),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (END_CONDITIONS (COUNT:1))) (BODY:{(TEST_INT_SYMBOL:314)}))))");
749 
750  // debug_enable(D_SIGNALS);
751  // generate a response signal
752 
753  T *s = __r_make_signal(r->addr,r->addr,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,"one fish"),_t_surface(_t_child(run_tree,1)),0,0);
754  _r_deliver(r,s);
755  spec_is_str_equal(_td(r,r->pending_responses),"(PENDING_RESPONSES)");
756 
757  // _p_freeq(q);
758  // clear off the signal in the list
759  _t_free(_t_detach_by_idx(r->pending_signals,1));
760 
761  /* // now test the callback request case */
762  /* _t_newi(p,BOOLEAN,1); */
763 
764  /* run_tree = __p_build_run_tree(p,0); */
765 
766  /* r->q = q = _p_newq(r); */
767  /* ps = r->pending_signals; */
768  /* e = _p_addrt2q(q,run_tree); */
769  /* c = e->context; */
770 
771  /* // after reduction the context should have been moved to the completed list */
772  /* // and the signal should be on the pending signals list */
773  /* spec_is_equal(_p_reduceq(q),noReductionErr); */
774 
775  /* spec_is_equal(q->contexts_count,0); */
776  /* spec_is_ptr_equal(q->completed,e); */
777 
778  /* spec_is_str_equal(t2s(run_tree),"(RUN_TREE (SIGNAL_UUID) (PARAMS))"); */
779  /* spec_is_str_equal(t2s(ps),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (FROM_ADDRESS (CONTEXT_NUM:0)) (TO_ADDRESS (CONTEXT_NUM:3)) (DEFAULT_ASPECT) (CARRIER:TEST_INT_SYMBOL) (SIGNAL_UUID)) (BODY:{(TEST_INT_SYMBOL:314)})))"); */
780 
781  debug_disable(D_SIGNALS);
782 
783  _r_free(r);
784  _t_free(p);
785  _t_free(code);
786 }
787 
788 
789 T *_testProcessAddSay(T *parent,int id,T *message) {
790  T *say = _t_newr(parent,SAY);
791  ReceptorAddress to = {id}; // DUMMY ADDR
792  __r_make_addr(say,TO_ADDRESS,to);
793  _t_news(say,ASPECT_IDENT,DEFAULT_ASPECT);
794  _t_news(say,CARRIER,TESTING);
795  _t_add(say,message);
796  return say;
797 }
798 
799 /*
800  (DO
801  (SCOPE
802  (SAY <to> <aspect> <carrier> <message> )
803  (CONVERSE
804  (SCOPE
805  (LISTEN <aspect> <carrier> <action>)
806  (SAY <to> <aspect> <carrier> <message> )
807  )
808  (END_CONDITIONS (UNLIMITED))
809  )
810  )
811  )
812 */
813 
814 void testProcessConverse() {
815  T *p = _t_newr(0,CONVERSE);
816  T *scope = _t_newr(p,SCOPE);
817  _t_newi(p,BOOLEAN,1);
818  _testProcessAddSay(scope,100,_t_newi(0,TEST_INT_SYMBOL,31415));
819  T *code = _testProcessAddSay(0,99,p);
820 
821  T *run_tree = __p_build_run_tree(code,0);
822  _t_free(code);
823 
824  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (process:CONVERSE (SCOPE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:31415))) (BOOLEAN:1))) (PARAMS))");
825 
826  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
827 
828  // add the run tree into a queue and run it
829  G_next_process_id = 0; // reset the process ids so the test will always work
830  Q *q = r->q;
831  T *cons = r->conversations;
832  T *ps = r->pending_signals;
833  Qe *e =_p_addrt2q(q,run_tree);
834  R *c = e->context;
835 
836  // after reduction the context be paused because we set wait to true
837  // and there should also be a conversation recorded
838  //debug_enable(D_STEP);
839  spec_is_equal(_p_reduceq(q),noReductionErr);
840  debug_disable(D_STEP);
841  spec_is_str_equal(t2s(cons),"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1/4))))");
842 
843  //CONVERSE should be reduced to the signal UUID from the containing scope
844  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:SAY (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (SIGNAL_UUID)) (PARAMS))");
845  spec_is_ptr_equal(q->blocked,e);
846 
847  // The signal to 100 should have the conversation id in it
848  spec_is_str_equal(t2s(ps),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_INT_SYMBOL:31415)}))))");
849 
850  // now use the COMPLETE instruction to clean-up
851  code = _t_newr(0,COMPLETE);
852  _t_newi(code,TEST_INT_SYMBOL,123);
853  _t_add(code,_t_clone(_t_getv(cons,1,ConversationIdentIdx,TREE_PATH_TERMINATOR)));
854 
855  T *run_tree2 = __p_build_run_tree(code,0);
856  _t_free(code);
857  Qe *e2 =_p_addrt2q(q,run_tree2);
858  spec_is_equal(_p_reduceq(q),noReductionErr);
859  spec_is_ptr_equal(q->blocked,NULL);
860  spec_is_ptr_equal(q->active,NULL);
861  spec_is_ptr_equal(q->completed,e);
862  spec_is_ptr_equal(q->completed->next,e2);
863 
864  // and the conversation should be cleaned up and the CONVERSE run-tree should have reduced
865  spec_is_str_equal(t2s(cons),"(CONVERSATIONS)");
866  // and the run tree should be completed with the value from the COMPLETE instruction
867  spec_is_str_equal(t2s(run_tree2),"(RUN_TREE (CONVERSATION_IDENT (CONVERSATION_UUID)) (PARAMS))");
868 
869  // and the second signal shouldn't have the conversation id in it and it's body should be the
870  // 'with' value from the COMPLETE
871  spec_is_str_equal(t2s(ps),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_INT_SYMBOL:31415)}))) (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING)) (BODY:{(TEST_INT_SYMBOL:123)}))))");
872 
873 
874  // setup a case for testing the COMPLETE instruction within the CONVERSE SCOPE
875  p = _t_newr(0,CONVERSE);
876  scope = _t_newr(p,SCOPE);
877  T *complete = _t_newr(scope,COMPLETE);
878  _t_newi(complete,TEST_INT_SYMBOL,321);
879  _t_newi(scope,TEST_INT_SYMBOL,123);
880 
881  run_tree = __p_build_run_tree(p,0);
882  _t_free(p);
883 
884  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:CONVERSE (SCOPE (process:COMPLETE (TEST_INT_SYMBOL:321)) (TEST_INT_SYMBOL:123))) (PARAMS))");
885  e =_p_addrt2q(q,run_tree);
886  //debug_enable(D_REDUCE+D_REDUCEV);
887  spec_is_equal(_p_reduceq(q),noReductionErr);
888  debug_disable(D_STEP);
889  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (TEST_INT_SYMBOL:321) (PARAMS))");
890 
891 
892  // setup a case for testing that a conversation scope gets "inherited" by sub-contexts
893  code = _testProcessAddSay(0,100,_t_new_str(0,TEST_STR_SYMBOL,"What I said!"));
894  T *signature = __p_make_signature("result",SIGNATURE_SYMBOL,NULL_SYMBOL,NULL);
895  Process sayer = _d_define_process(G_sem,code,"sayer","sends a signal to 100",signature,0,r->context);
896 
897  p = _t_newr(0,CONVERSE);
898  scope = _t_newr(p,SCOPE);
899  _t_newr(scope,sayer);
900  complete = _t_newr(scope,COMPLETE); // and make sure this scope gets cleaned up
901  _t_newi(complete,TEST_INT_SYMBOL,321);
902 
903  run_tree = __p_build_run_tree(p,0);
904  _t_free(p);
905 
906  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:CONVERSE (SCOPE (process:sayer) (process:COMPLETE (TEST_INT_SYMBOL:321)))) (PARAMS))");
907  e =_p_addrt2q(q,run_tree);
908  //debug_enable(D_STEP);
909  spec_is_equal(_p_reduceq(q),noReductionErr);
910  debug_disable(D_STEP);
911  // the say inside the function call should also be part of the conversation
912  spec_is_str_equal(t2s(_t_child(ps,_t_children(ps))),"(SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:100)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (CONVERSATION_IDENT (CONVERSATION_UUID))) (BODY:{(TEST_STR_SYMBOL:What I said!)})))");
913 
914  // test conversation nesting
915  p = _t_newr(0,CONVERSE);
916  scope = _t_newr(p,SCOPE);
917  T *p2 = _t_newr(scope,CONVERSE);
918  p2 = _t_newr(p2,SCOPE);
919  _t_newr(p2,sayer);
920 
921  run_tree = __p_build_run_tree(p,0);
922  _t_free(p);
923  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:CONVERSE (SCOPE (process:CONVERSE (SCOPE (process:sayer))))) (PARAMS))");
924 
925  e =_p_addrt2q(q,run_tree);
926  //debug_enable(D_STEP);
927  spec_is_equal(_p_reduceq(q),noReductionErr);
928  debug_disable(D_STEP);
929  // the conversation uuid in the signal should match the sub-conversations uuid
930  T *last_sig = _t_child(ps,_t_children(ps));
931  T *head =_t_getv(last_sig,SignalMessageIdx,MessageHeadIdx,TREE_PATH_TERMINATOR);
932  T *s_cid = __t_find(head,CONVERSATION_IDENT,HeadOptionalsIdx);
933  T *cid =_t_getv(r->conversations,1,ConversationConversationsIdx,1,ConversationIdentIdx,TREE_PATH_TERMINATOR);
934  spec_is_true(__uuid_equal(__cid_getUUID(cid),__cid_getUUID(s_cid)));
935 
936  _r_free(r);
937 }
938 
939 void testProcessConverseListen() {
940 
941  T *code = _t_parse(G_sem,0,"(NEW (NEW_TYPE:TEST_INT_SYMBOL) (PARAM_REF:/2/1))");
942 
943  T *signature = __p_make_signature("result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
944  "int",SIGNATURE_SYMBOL,TEST_INT_SYMBOL,
945  NULL);
946  Process p = _d_define_process(G_sem,code,"new_int","",signature,NULL,TEST_CONTEXT);
947 
948  code = _t_parse(G_sem,0,"(CONVERSE (SCOPE (LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)))) (BOOLEAN:1))");
949 
950  T *run_tree = __p_build_run_tree(code,0);
951  _t_free(code);
952 
953  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:CONVERSE (SCOPE (process:LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)))) (BOOLEAN:1)) (PARAMS))");
954 
955  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
956 
957  // add the run tree into a queue and run it
958  G_next_process_id = 0; // reset the process ids so the test will always work
959  Q *q = r->q;
960  T *cons = r->conversations;
961  T *ps = r->pending_signals;
962  Qe *e =_p_addrt2q(q,run_tree);
963  R *c = e->context;
964 
965  spec_is_equal(_p_reduceq(q),noReductionErr);
966  spec_is_ptr_equal(q->blocked,e);
967 
968  T *ex = __r_get_expectations(r,DEFAULT_ASPECT);
969  spec_is_str_equal(t2s(ex),"(EXPECTATIONS (EXPECTATION (CARRIER:TEST_INT_SYMBOL) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_INT_SYMBOL))) (ACTION:new_int (TEST_INT_SYMBOL:314)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED)) (CONVERSATION_IDENT (CONVERSATION_UUID))))");
970 
971  T *t = _t_newi(0,TEST_INT_SYMBOL,314);
972  // debug_enable(D_LISTEN+D_SIGNALS);
973  T *s = __r_make_signal(r->addr,r->addr,DEFAULT_ASPECT,TEST_INT_SYMBOL,t,0,0,0);
974  _r_deliver(r,s);
975  spec_is_equal(_p_reduceq(q),noReductionErr);
976  // we should have no instances in the instance store, because the signal wasn't part of the conversation
977  spec_is_str_equal(t2s(r->instances),"");
978 
979  T *cid = _t_clone(_t_getv(cons,1,ConversationIdentIdx,TREE_PATH_TERMINATOR));
980  s = __r_make_signal(r->addr,r->addr,DEFAULT_ASPECT,TEST_INT_SYMBOL,_t_clone(t),0,0,cid);
981  _r_deliver(r,s);
982  spec_is_equal(_p_reduceq(q),noReductionErr);
983  debug_disable(D_LISTEN+D_SIGNALS);
984  spec_is_str_equal(t2s(r->instances),"(INSTANCE_STORE (INSTANCES (SYMBOL_INSTANCES:TEST_INT_SYMBOL (TEST_INT_SYMBOL:314))))");
985 
986 
987  // test __r_cleanup (should actually be testing it via a call to COMPLETE)
988  __r_cleanup_conversation(r,__cid_getUUID(cid));
989  spec_is_str_equal(t2s(ex),"(EXPECTATIONS)");
990 
991  _r_free(r);
992 }
993 
994 void testProcessThisScope() {
995  T *code = _t_new_root(CONVERSE);
996  T *scope = _t_newr(code,SCOPE);
997  _t_newr(scope,THIS_SCOPE);
998 
999  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1000 
1001  T *run_tree = __p_build_run_tree(code,0);
1002  _t_free(code);
1003 
1004  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:CONVERSE (SCOPE (process:THIS_SCOPE))) (PARAMS))");
1005 
1006  // add the run tree into a queue and run it
1007  G_next_process_id = 0; // reset the process ids so the test will always work
1008  Q *q = r->q;
1009  T *cons = r->conversations;
1010  Qe *e =_p_addrt2q(q,run_tree);
1011  R *c = e->context;
1012 
1013  //debug_enable(D_STEP);
1014  spec_is_equal(_p_reduceq(q),noReductionErr);
1015  debug_disable(D_STEP);
1016  spec_is_str_equal(t2s(cons),"(CONVERSATIONS (CONVERSATION (CONVERSATION_IDENT (CONVERSATION_UUID)) (END_CONDITIONS (UNLIMITED)) (CONVERSATIONS) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1))))");
1017 
1018  // should reduce to the conversations ID because of the THIS_SCOPE instruction
1019  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (CONVERSATION_IDENT (CONVERSATION_UUID)) (PARAMS))");
1020  _r_free(r);
1021 
1022 }
1023 
1024 void testProcessQuote() {
1025  T *t = _t_new_root(RUN_TREE);
1026 
1027  // test process quoting
1028  T *n = _t_new_root(QUOTE);
1029 
1030  T *a = _t_newr(n,ADD_INT);
1031  _t_newi(a,TEST_INT_SYMBOL,99);
1032  _t_newi(a,TEST_INT_SYMBOL,100);
1033 
1034  T *c = _t_rclone(n);
1035  _t_add(t,c);
1036  _p_reduce(G_sem,t);
1037 
1038  spec_is_str_equal(t2s(t),"(RUN_TREE (process:ADD_INT (TEST_INT_SYMBOL:99) (TEST_INT_SYMBOL:100)))");
1039 
1040  _t_free(n);
1041  _t_free(t);
1042 }
1043 
1044 void testProcessStream() {
1045  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1046  Q *q = r->q;
1047 
1048  FILE *stream;
1049  char buffer[500] = "line1\nabc\nGET /path/to/file.ext HTTP/0.9\n";
1050  stream = fmemopen(buffer, 500, "r+");
1051 
1052  // test the basic case of the STREAM_ALIVE process which returns
1053  // a boolean if the stream is readable or not.
1054  T *n = _t_new_root(STREAM_ALIVE);
1055  Stream *st = _st_new_unix_stream(stream,1);
1056  _t_new_cptr(n,EDGE_STREAM,st);
1057  __p_reduce_sys_proc(0,STREAM_ALIVE,n,0);
1058  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
1059  _t_free(n);
1060 
1061  // test reading a stream
1062  n = _t_new_root(STREAM_READ);
1063  _t_new_cptr(n,EDGE_STREAM,st);
1064  _t_news(n,RESULT_SYMBOL,TEST_STR_SYMBOL);
1065 
1066  T *run_tree = __p_build_run_tree(n,0);
1067  _t_free(n);
1068  Qe *e = _p_addrt2q(q,run_tree);
1069  R *c = e->context;
1070 
1071  // after reduction the context should be in the blocked state
1072 
1073  spec_is_equal(_p_reduceq(q),noReductionErr);
1074  spec_is_equal(q->contexts_count,0);
1075  spec_is_ptr_equal(q->blocked,e);
1076  spec_is_equal(c->state,Block);
1077 
1078  // wait for read to complete, after which it should have also unblocked the
1079  // context which should thus be ready for reduction again.
1080  while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1081  spec_is_equal(q->contexts_count,1);
1082 
1083  spec_is_equal(_p_reduceq(q),noReductionErr);
1084  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (TEST_STR_SYMBOL:line1) (PARAMS))");
1085 
1086  // now test reading again but this time into an ASCII_CHARS tree
1087  n = _t_new_root(STREAM_READ);
1088  _t_new_cptr(n,EDGE_STREAM,st);
1089  _t_news(n,RESULT_SYMBOL,ASCII_CHARS);
1090 
1091  run_tree = __p_build_run_tree(n,0);
1092  _t_free(n);
1093  e = _p_addrt2q(q,run_tree);
1094  spec_is_equal(_p_reduceq(q),noReductionErr);
1095  while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1096  spec_is_equal(_p_reduceq(q),noReductionErr);
1097  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (ASCII_CHARS (ASCII_CHAR:'a') (ASCII_CHAR:'b') (ASCII_CHAR:'c')) (PARAMS))");
1098 
1099  // now test reading again but this time into a symbol that requires transcoding
1100  n = _t_new_root(STREAM_READ);
1101  _t_new_cptr(n,EDGE_STREAM,st);
1102  _t_news(n,RESULT_SYMBOL,HTTP_REQUEST);
1103 
1104  run_tree = __p_build_run_tree(n,0);
1105  _t_free(n);
1106  e = _p_addrt2q(q,run_tree);
1107  spec_is_equal(_p_reduceq(q),noReductionErr);
1108  while(!(st->flags&StreamHasData) && st->flags&StreamAlive ) {sleepms(1);};
1109  spec_is_equal(_p_reduceq(q),noReductionErr);
1110  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (HTTP_REQUEST (HTTP_REQUEST_METHOD:GET) (HTTP_REQUEST_PATH (HTTP_REQUEST_PATH_SEGMENTS (HTTP_REQUEST_PATH_SEGMENT:path) (HTTP_REQUEST_PATH_SEGMENT:to) (HTTP_REQUEST_PATH_SEGMENT:file.ext))) (HTTP_REQUEST_VERSION (VERSION_MAJOR:0) (VERSION_MINOR:9))) (PARAMS))");
1111 
1112  // test writing to the stream
1113  fseek(stream,strlen(buffer),SEEK_SET);
1114  n = _t_new_root(STREAM_WRITE);
1115  _t_new_cptr(n,EDGE_STREAM,st);
1116  _t_new_str(n,TEST_STR_SYMBOL,"fish\n");
1117  _t_new_str(n,LINE,"cow");
1118  T *lns = _t_newr(n,LINES);
1119  _t_new_str(lns,LINE,"thing1");
1120  _t_new_str(lns,LINE,"thing2");
1121  _t_newi(n,TEST_INT_SYMBOL,314);
1122 
1123  run_tree = __p_build_run_tree(n,0);
1124  _t_free(n);
1125  e = _p_addrt2q(q,run_tree);
1126 
1127  spec_is_equal(_p_reduceq(q),noReductionErr);
1128 
1129  char *expected_result = "line1\nabc\nGET /path/to/file.ext HTTP/0.9\nfish\ncow\nthing1\nthing2\n(TEST_INT_SYMBOL:314)";
1130 
1131  spec_is_str_equal(buffer,expected_result);
1132 
1133  _st_free(st);
1134 
1135 
1136  // test writing to a readonly stream
1137  stream = fmemopen(buffer, strlen (buffer), "r");
1138  st = _st_new_unix_stream(stream,0);
1139  n = _t_new_root(STREAM_WRITE);
1140 
1141  _t_new_cptr(n,EDGE_STREAM,st);
1142  _t_new_str(n,TEST_STR_SYMBOL,"fish\n");
1143 
1144  run_tree = __p_build_run_tree(n,0);
1145  _t_free(n);
1146  e = _p_addrt2q(q,run_tree);
1147  spec_is_equal(_p_reduceq(q),noReductionErr);
1148 
1149  // context should have recorded the err
1150  spec_is_equal(e->context->err,unixErrnoReductionErr);
1151 
1152  // buffer should remain unchanged
1153  spec_is_str_equal(buffer,expected_result);
1154 
1155  // debug_enable(D_STREAM+D_SOCKET+D_SIGNALS);
1156 
1157  _st_kill(st);
1158  n = _t_new_root(STREAM_ALIVE);
1159  _t_new_cptr(n,EDGE_STREAM,st);
1160  __p_reduce_sys_proc(0,STREAM_ALIVE,n,0);
1161  spec_is_str_equal(t2s(n),"(BOOLEAN:0)");
1162  _t_free(n);
1163 
1164  _st_free(st);
1165  _r_free(r);
1166  debug_disable(D_STREAM+D_SOCKET+D_SIGNALS);
1167 
1168 }
1169 
1170 void testProcessStreamClose() {
1171  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1172  Q *q = r->q;
1173 
1174  FILE *stream;
1175  char buffer[500] = "line1\nabc\n";
1176  stream = fmemopen(buffer, 500, "r+");
1177 
1178  T *n = _t_new_root(STREAM_CLOSE);
1179  Stream *st = _st_new_unix_stream(stream,true);
1180  _t_new_cptr(n,EDGE_STREAM,st);
1181  //debug_enable(D_STREAM+D_SOCKET+D_SIGNALS);
1182  __p_reduce_sys_proc(0,STREAM_CLOSE,n,0);
1183  //@todo figure out what STREAM_CLOSE should really return
1184  spec_is_str_equal(t2s(n),"(BOOLEAN:1)");
1185  _t_free(n);
1186  debug_disable(D_STREAM+D_SOCKET+D_SIGNALS);
1187 
1188  _r_free(r);
1189 }
1190 
1191 
1192 void testProcessInitiate(){
1193  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1194  Q *q = r->q;
1195  Protocol time;
1196  __sem_get_by_label(G_sem,"time",&time,CLOCK_CONTEXT);
1197 
1198  T *n = _t_new_root(INITIATE_PROTOCOL);
1199  T *p = _t_news(n,PNAME,time);
1200  T *i = _t_news(n,WHICH_INTERACTION,tell_time);
1201  T *bindings = _t_newr(n,PROTOCOL_BINDINGS);
1202  T *res = _t_newr(bindings,RESOLUTION);
1203  T *w = _t_newr(res,WHICH_RECEPTOR);
1204  _t_news(w,ROLE,TIME_TELLER);
1205  __r_make_addr(w,ACTUAL_RECEPTOR,r->addr);
1206  res = _t_newr(bindings,RESOLUTION);
1207  w = _t_newr(res,WHICH_RECEPTOR);
1208  _t_news(w,ROLE,TIME_HEARER);
1209  ReceptorAddress clock_addr = {3}; // @todo bogus!!! fix getting clock address somehow
1210  __r_make_addr(w,ACTUAL_RECEPTOR,clock_addr);
1211  res = _t_newr(bindings,RESOLUTION);
1212  w = _t_newr(res,WHICH_PROCESS);
1213  _t_news(w,GOAL,RESPONSE_HANDLER);
1214  T *noop = _t_new_root(NOOP);
1215  _t_newi(noop,TEST_INT_SYMBOL,314);
1216  // Process proc = _r_define_process(r,noop,"do nothing","long desc...",NULL,NULL);
1217  _t_news(w,ACTUAL_PROCESS,NOOP);
1218 
1219  T *run_tree = __p_build_run_tree(n,0);
1220  _t_free(n);
1221  Qe *e = _p_addrt2q(q,run_tree);
1222 
1223  spec_is_str_equal(_td(r,r->pending_signals),"(PENDING_SIGNALS)");
1224  //debug_enable(D_STEP+D_REDUCE+D_REDUCEV);
1225  spec_is_equal(_p_reduceq(q),noReductionErr);
1226  debug_disable(D_REDUCE+D_STEP+D_REDUCEV);
1227  spec_is_equal(_t_children(r->pending_signals),1);
1228  spec_is_str_equal(t2s(run_tree),"");
1229  // DEBUGGER;
1230  _r_free(r);
1231 }
1232 
1233 //-----------------------------------------------------------------------------------------
1234 // tests of process execution (reduction)
1235 
1236 void testProcessReduce() {
1237  T *t = _t_new_root(RUN_TREE);
1238 
1239  T *n = _t_new_root(IF); // multi-level IF to test descending a number of levels
1240  _t_newi(n,BOOLEAN,1);
1241  T *n1 = _t_newr(n,IF);
1242  T *n2 = _t_newr(n1,IF);
1243  _t_newi(n2,BOOLEAN,0);
1244  _t_newi(n2,BOOLEAN,1);
1245  _t_newi(n2,BOOLEAN,0);
1246  _t_newi(n1,TEST_INT_SYMBOL,98);
1247  _t_newi(n1,TEST_INT_SYMBOL,99);
1248  _t_newi(n,TEST_INT_SYMBOL,100);
1249 
1250  T *c = _t_rclone(n);
1251  _t_add(t,c);
1252 
1253  R *context = __p_make_context(t,0,99,NULL);
1254 
1255  spec_is_equal(context->id,99);
1256 
1257  // build a fake Receptor and Q on the stack so _p_step will work
1258  Receptor r;
1259  Q q;
1260  r.root = NULL;
1261  r.q = &q;
1262  q.r = &r;
1263 
1264  spec_is_equal(rt_cur_child(c),0);
1265  // first step is Eval and next step is Descend
1266  spec_is_equal(_p_step(&q,&context),Descend);
1267  spec_is_equal(rt_cur_child(c),0);
1268 
1269  // next step after Descend changes node pointer and moved to Eval
1270  spec_is_equal(_p_step(&q,&context),Eval);
1271  spec_is_ptr_equal(context->node_pointer,_t_child(c,1));
1272  spec_is_equal(rt_cur_child(c),1);
1273 
1274  // after Eval next step will be Ascend
1275  spec_is_equal(_p_step(&q,&context),Ascend);
1276 
1277  // step ascends back to top if and marks boolean complete
1278  spec_is_equal(_p_step(&q,&context),Eval);
1279 
1280  spec_is_equal(rt_cur_child(_t_child(c,1)),RUN_TREE_EVALUATED);
1281  spec_is_ptr_equal(context->node_pointer,c);
1282 
1283  spec_is_equal(_p_step(&q,&context),Descend);
1284 
1285  // third step goes into the second level if
1286  spec_is_equal(_p_step(&q,&context),Eval);
1287  spec_is_equal(rt_cur_child(c),2);
1288  spec_is_ptr_equal(context->node_pointer,_t_child(c,2));
1289 
1290  free(context);
1291  // not specing out all the steps because there are soooo many...
1292 
1293  // just re-running them all for final result
1294  _t_free(_t_detach_by_idx(t,1));
1295  c = _t_rclone(n);
1296  _t_add(t,c);
1297  _p_reduce(G_sem,t);
1298 
1299  spec_is_str_equal(t2s(c),"(TEST_INT_SYMBOL:99)");
1300 
1301  _t_free(n);
1302  _t_free(t);
1303 }
1304 
1305 void testProcessParameter() {
1306  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1307 
1308  T *n = _t_parse(G_sem,0,"(TEST_ANYTHING_SYMBOL (DISSOLVE (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/1)) (PARAMETER_RESULT (RESULT_VALUE)))) (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/2)) (PARAMETER_RESULT (RESULT_SYMBOL:TEST_SYMBOL_SYMBOL))) (PARAMETER (PARAMETER_REFERENCE (PARAM_PATH:/2/1)) (PARAMETER_RESULT (RESULT_LABEL:ENGLISH_LABEL))))");
1309 
1310  T *p1 = _t_newi(0,TEST_INT_SYMBOL,314);
1311  T *p2 = _t_new_str(0,TEST_STR_SYMBOL,"314");
1312  T *run_tree = __p_build_run_tree(n,2,p1,p2);
1313  _t_free(p1);
1314  _t_free(p2);
1315  _t_free(n);
1316  Q *q = r->q;
1317  Qe *e = _p_addrt2q(q,run_tree);
1318 
1319  spec_is_equal(_p_reduceq(q),noReductionErr);
1320  spec_is_str_equal(t2s(run_tree), "(RUN_TREE (TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314) (TEST_SYMBOL_SYMBOL:TEST_STR_SYMBOL) (ENGLISH_LABEL:TEST_INT_SYMBOL)) (PARAMS (TEST_INT_SYMBOL:314) (TEST_STR_SYMBOL:314)))");
1321 
1322  _r_free(r);
1323 }
1324 
1325 void testProcessRefs() {
1326  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1327  Q *q = r->q;
1328 
1329  int pt1[] = {2,1,TREE_PATH_TERMINATOR};
1330  int pt2[] = {SignalMessageIdx,MessageBodyIdx,0,TREE_PATH_TERMINATOR};
1331 
1332  T *n = _t_newr(0,NOOP);
1333  T *t = _t_newr(n,TEST_ANYTHING_SYMBOL);
1334  _t_new(t,PARAM_REF,pt1,sizeof(int)*4);
1335  _t_new(t,SIGNAL_REF,pt2,sizeof(int)*4);
1336  t = _t_newi(0,TEST_INT_SYMBOL,314); // a param to the run tree
1337  T *run_tree = __p_build_run_tree(n,1,t);
1338  _t_free(n);
1339  _t_free(t);
1340  ReceptorAddress fm = {3}; // DUMMY ADDR
1341  ReceptorAddress to = {4}; // DUMMY ADDR
1342  T *signal = __r_make_signal(fm,to,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,"foo"),0,0,0);
1343 
1344  // simulate that this run-tree is on the flux.
1345  _t_add(signal,run_tree);
1346 
1347  Qe *e = _p_addrt2q(q,run_tree);
1348  spec_is_equal(_p_reduceq(q),noReductionErr);
1349 
1350  spec_is_str_equal(t2s(run_tree), "(RUN_TREE (TEST_ANYTHING_SYMBOL (TEST_INT_SYMBOL:314) (TEST_STR_SYMBOL:foo)) (PARAMS (TEST_INT_SYMBOL:314)))");
1351 
1352  // now remove the run-tree from the signal or it won't get cleanup up by the free.
1353  _t_detach_by_ptr(signal,run_tree);
1354  _t_free(signal);
1355 
1356  _r_free(r);
1357 }
1358 
1359 Process G_ifeven;
1365 void _defIfEven() {
1367  T *code = _t_parse(G_sem,0,"(IF (EQ_INT (MOD_INT (PARAM_REF:/2/1) (TEST_INT_SYMBOL:2)) (TEST_INT_SYMBOL:0)) (PARAM_REF:/2/2) (PARAM_REF:/2/3))");
1368 
1369  T *signature = __p_make_signature("result",SIGNATURE_PASSTHRU,NULL_STRUCTURE,
1370  "val",SIGNATURE_STRUCTURE,INTEGER,
1371  "true_branch",SIGNATURE_ANY,NULL_STRUCTURE,
1372  "false_branch",SIGNATURE_ANY,NULL_STRUCTURE,
1373  NULL);
1374 
1375  G_ifeven = _d_define_process(G_sem,code,"if even","return 2nd child if even, third if not",signature,NULL,TEST_CONTEXT);
1376 }
1378 
1384 Process _defDivZero() {
1386  T *code;
1387 
1388  /* a process that would look something like this in lisp:
1389  (defun div_zero (val) (/ val 0))
1390  */
1391  code = _t_new_root(DIV_INT); // IF is a system process
1392  _t_newi(code,TEST_INT_SYMBOL,2);
1393  _t_newi(code,TEST_INT_SYMBOL,0);
1394 
1395  T *signature = __p_make_signature("result",SIGNATURE_SYMBOL,NULL_SYMBOL,
1396  "val",SIGNATURE_STRUCTURE,INTEGER,
1397  NULL);
1398 
1399  return _d_define_process(G_sem,code,"divByZero","create a divide by zero error",signature,NULL,TEST_CONTEXT);
1400 }
1402 
1405 
1406  Process if_even = G_ifeven;
1407  T *processes = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
1408 
1409  // check that it dumps nicely, including showing the param_refs as paths
1410  int p[] = {if_even.id,ProcessDefCodeIdx,TREE_PATH_TERMINATOR};
1411 
1412  spec_is_str_equal(t2s(_t_get(processes,p)),"(process:IF (process:EQ_INT (process:MOD_INT (PARAM_REF:/2/1) (TEST_INT_SYMBOL:2)) (TEST_INT_SYMBOL:0)) (PARAM_REF:/2/2) (PARAM_REF:/2/3))");
1413 
1414 
1415  // create a run tree right in the state to "call"this function
1416  T *n = _t_new_root(PARAMS);
1417  _t_newi(n,TEST_INT_SYMBOL,99);
1418  _t_newi(n,TEST_INT_SYMBOL,123);
1419  _t_newi(n,TEST_INT_SYMBOL,124);
1420  T *t = _p_make_run_tree(G_sem,if_even,n,NULL);
1421 
1422  // confirm that it reduces correctly
1423  spec_is_equal(_p_reduce(G_sem,t),noReductionErr);
1424  spec_is_str_equal(t2s(_t_child(t,1)),"(TEST_INT_SYMBOL:124)");
1425 
1426  _t_free(t);_t_free(n);
1428 }
1429 
1430 void testProcessSignatureMatching() {
1431  Process if_even = G_ifeven;
1432 
1433  T *t = _t_new_root(RUN_TREE);
1434  T *n = _t_new_root(if_even);
1435  T *x = _t_new(n,TEST_STR_SYMBOL,"test",5); // this should be an INTEGER!!
1436  _t_newi(n,TEST_INT_SYMBOL,123);
1437  _t_newi(n,TEST_INT_SYMBOL,124);
1438 
1439  spec_is_equal(__p_check_signature(G_sem,if_even,n,NULL),signatureMismatchReductionErr);
1440 
1441  T *c = _t_rclone(n);
1442  _t_add(t,c);
1443  spec_is_equal(_p_reduce(G_sem,t),signatureMismatchReductionErr);
1444  _t_free(_t_detach_by_idx(t,1));
1445 
1446  // too few params
1447  c = _t_rclone(n);
1448  _t_add(t,c);
1449  _t_free(_t_detach_by_idx(c,1));
1450  spec_is_equal(_p_reduce(G_sem,t),tooFewParamsReductionErr);
1451  _t_free(_t_detach_by_idx(t,1));
1452 
1453  // add too many params
1454  // fix the mismatch in the first param so the test won't fail by mismatch type
1455  int v = 0;
1456  __t_morph(x,TEST_INT_SYMBOL,&v,sizeof(int),0);
1457  c = _t_rclone(n);
1458  // add in the extra param
1459  _t_add(t,c);
1460  __t_newi(c,TEST_INT_SYMBOL,124,1);
1461  spec_is_equal(_p_reduce(G_sem,t),tooManyParamsReductionErr);
1462 
1463  _t_free(t);
1464  _t_free(n);
1465 
1466  n = _t_new_root(send_request);
1467  // test missing semantic map
1468  spec_is_equal(__p_check_signature(G_sem,send_request,n,NULL),missingSemanticMapReductionErr);
1469  T *sm = _t_new_root(SEMANTIC_MAP);
1470  // test map without matching expected slots
1471  spec_is_equal(__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1472  _t_free(sm);
1473  //(TEMPLATE_SIGNATURE (EXPECTED_SLOT (ROLE:RESPONDER)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (USAGE:RESPONSE_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))
1474  sm = _t_build(G_sem,0,
1475  SEMANTIC_MAP,
1476  SEMANTIC_LINK,
1477  USAGE,REQUEST_TYPE,
1478  REPLACEMENT_VALUE,ACTUAL_SYMBOL,PING,NULL_SYMBOL,NULL_SYMBOL,
1479  SEMANTIC_LINK,
1480  USAGE,RESPONSE_TYPE,
1481  REPLACEMENT_VALUE,ACTUAL_SYMBOL,PING,NULL_SYMBOL,NULL_SYMBOL,
1482  SEMANTIC_LINK,
1483  GOAL,REQUEST_HANDLER,
1484  REPLACEMENT_VALUE,ACTUAL_PROCESS,NOOP,NULL_SYMBOL,NULL_SYMBOL,
1485  SEMANTIC_LINK,
1486  GOAL,RESPONSE_HANDLER,
1487  REPLACEMENT_VALUE,ACTUAL_PROCESS,NOOP,NULL_SYMBOL,
1488  NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL
1489  );
1490  spec_is_str_equal(t2s(sm),"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))))");
1491 
1492  spec_is_equal(__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1493 
1494  _t_build(G_sem,sm,
1495  SEMANTIC_LINK,
1496  ROLE,RECOGNIZER,
1497  REPLACEMENT_VALUE,ACTUAL_RECEPTOR,FROM_ADDRESS,RECEPTOR_ADDR,3,NULL_SYMBOL,NULL_SYMBOL);
1498 
1499  spec_is_str_equal(t2s(sm),"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (ROLE:RECOGNIZER) (REPLACEMENT_VALUE (ACTUAL_RECEPTOR (FROM_ADDRESS (RECEPTOR_ADDR:3))))))");
1500 
1501  spec_is_equal(__p_check_signature(G_sem,send_request,n,sm),mismatchSemanticMapReductionErr);
1502 
1504 
1505  _t_build(G_sem,sm,
1506  SEMANTIC_LINK,
1507  ROLE,RESPONDER,
1508  REPLACEMENT_VALUE,ACTUAL_RECEPTOR,FROM_ADDRESS,RECEPTOR_ADDR,3,NULL_SYMBOL,NULL_SYMBOL);
1509 
1510  _t_build(G_sem,sm,
1511  SEMANTIC_LINK,
1512  USAGE,CHANNEL,
1513  REPLACEMENT_VALUE,ASPECT_IDENT,DEFAULT_ASPECT,NULL_SYMBOL,NULL_SYMBOL,NULL_SYMBOL);
1514 
1515  _t_parse(G_sem,sm,"(SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))");
1516 
1517  spec_is_str_equal(t2s(sm),"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:PING))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:NOOP))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ACTUAL_RECEPTOR (FROM_ADDRESS (RECEPTOR_ADDR:3))))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ASPECT_IDENT:DEFAULT_ASPECT))) (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))))");
1518 
1519  spec_is_equal(__p_check_signature(G_sem,send_request,n,sm),noReductionErr);
1520  _t_free(n);
1521  _t_free(sm);
1522 
1523  n = _t_new_root(fill_i_am);
1524 
1525  spec_is_equal(__p_check_signature(G_sem,fill_i_am,n,NULL),noReductionErr);
1526  _t_free(n);
1527 
1528 }
1529 
1530 void testProcessError() {
1531  T *t = _t_new_root(RUN_TREE);
1532  T *n = _t_parse(G_sem,0,"(NOOP (DIV_INT (TEST_INT_SYMBOL:100) (TEST_INT_SYMBOL:0)))");
1533  T *c = _t_rclone(n);
1534  _t_add(t,c);
1535  T *ps = _t_newr(t,PARAMS);
1536 
1537  // error routine is just a param ref to pass back the reduction error
1538  int pt[] = {RunTreeErrorParamsIdx,1,TREE_PATH_TERMINATOR};
1539  __t_new(t,PARAM_REF,pt,sizeof(int)*4,true);
1540 
1541  Error e = _p_reduce(G_sem,t);
1542  spec_is_equal(e,noReductionErr);
1543  spec_is_str_equal(t2s(_t_child(t,1)),"(ZERO_DIVIDE_ERR (ERROR_LOCATION:/1/1))");
1544  _t_free(n);
1545  _t_free(t);
1546 }
1547 
1548 void testProcessRaise() {
1549  T *n = _t_new_root(RAISE);
1550  _t_news(n,REDUCTION_ERROR_SYMBOL,ZERO_DIVIDE_ERR);
1551 
1552  spec_is_equal(__p_reduce_sys_proc(0,RAISE,n,0),raiseReductionErr);
1553  _t_free(n);
1554 
1555  T *t = _t_new_root(RUN_TREE);
1556  n = _t_new_root(RAISE);
1557  _t_news(n,REDUCTION_ERROR_SYMBOL,NOT_A_PROCESS_ERR); // pick a random error to raise
1558  T *c = _t_rclone(n);
1559  _t_add(t,c);
1560  T *ps = _t_newr(t,PARAMS);
1561 
1562  // error routine is just a param ref to pass back the reduction error
1563  int pt[] = {RunTreeErrorParamsIdx,1,TREE_PATH_TERMINATOR};
1564  __t_new(t,PARAM_REF,pt,sizeof(int)*4,true);
1565 
1566  Error e = _p_reduce(G_sem,t);
1567  spec_is_equal(e,noReductionErr);
1568  spec_is_str_equal(t2s(_t_child(t,1)),"(NOT_A_PROCESS_ERR (ERROR_LOCATION:/1))");
1569  _t_free(n);
1570  _t_free(t);
1571 }
1572 
1573 void testProcessIterate() {
1574  FILE *output;
1575 
1576  char *output_data = NULL;
1577  size_t size;
1578  output = open_memstream(&output_data,&size);
1579 
1580  // an iterate process that writes to a stream and 3 times
1581  Stream *st = _st_new_unix_stream(output,0);
1582  T *code = _t_parse(G_sem,0,"(ITERATE (PARAMS) (TEST_INT_SYMBOL:3) (STREAM_WRITE % (LINE:\"testing\")))",_t_new_cptr(0,EDGE_STREAM,st));
1583 
1584  T *t = __p_build_run_tree(code,0);
1585  Error e = _p_reduce(G_sem,t);
1586  spec_is_equal(e,noReductionErr);
1587  spec_is_str_equal(output_data,"testing\ntesting\ntesting\n");
1588  // spec_is_str_equal(t2s(t),"xxx"); @todo something here when we figure out return value
1589 
1590  _t_free(t);
1591  _t_free(code);
1592 
1593  // now test iteration with a condition instead of an INTEGER
1594  // a condition that checks to see if the param is less than 3
1595  code = _t_parse(G_sem,0,"(ITERATE (PARAMS (TEST_INT_SYMBOL:314)) (LT_INT (PARAM_REF:/1/1/1) (TEST_INT_SYMBOL:3)) (STREAM_WRITE % (LINE:\"testing\")))",_t_new_cptr(0,EDGE_STREAM,st));
1596 
1597  t = __p_build_run_tree(code,0);
1598  e = _p_reduce(G_sem,t);
1599  spec_is_equal(e,noReductionErr);
1600  spec_is_str_equal(output_data,"testing\ntesting\ntesting\n");
1601  _t_free(t);
1602 
1603  _st_free(st);
1604  free(output_data);
1605  _t_free(code);
1606 }
1607 
1608 void testProcessIterateOnSymbol() {
1609  FILE *output;
1610 
1611  char *output_data = NULL;
1612  size_t size;
1613  output = open_memstream(&output_data,&size);
1614 
1615  // an iterate process that writes to a stream and 3 times
1616  Stream *st = _st_new_unix_stream(output,0);
1617  T *code = _t_parse(G_sem,0,"(ITERATE (PARAMS) (ITERATE_ON_SYMBOL:TEST_STR_SYMBOL) (STREAM_WRITE % (PARAM_REF:/1/1/1/1)))",_t_new_cptr(0,EDGE_STREAM,st));
1618  T *run_tree = __p_build_run_tree(code,0);
1619  _t_free(code);
1620 
1621  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1622 
1623  Xaddr x;
1624  T *t = _t_new_str(0,TEST_STR_SYMBOL,"thing1 ");
1625  x = _r_new_instance(r,t);
1626  t = _t_new_str(0,TEST_STR_SYMBOL,"thing2 ");
1627  x = _r_new_instance(r,t);
1628 
1629  Q *q = r->q;
1630  Qe *e = _p_addrt2q(q,run_tree);
1631  spec_is_equal(_p_reduceq(q),noReductionErr);
1632  spec_is_equal(q->contexts_count,0);
1633  spec_is_ptr_equal(q->completed,e);
1634  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (REDUCTION_ERROR_SYMBOL:NULL_SYMBOL) (PARAMS))");
1635 
1636  spec_is_str_equal(output_data,"thing1 thing2 ");
1637 
1638  _st_free(st);
1639  free(output_data);
1640  _r_free(r);
1641 }
1642 
1643 void testProcessListen() {
1644  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1645 
1646  // test regular asynchronous listening.
1647  T *n = _t_parse(G_sem,0,"(LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TICK) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TICK))) (ACTION:NOOP (TEST_INT_SYMBOL:314)))");
1648  spec_is_equal(__p_reduce_sys_proc(0,LISTEN,n,r->q),noReductionErr);
1649  spec_is_str_equal(t2s(n),"(REDUCTION_ERROR_SYMBOL:NULL_SYMBOL)"); //@todo is this right??
1650  _t_free(n);
1651 
1652  T *ex = __r_get_expectations(r,DEFAULT_ASPECT);
1653  spec_is_str_equal(t2s(ex),"(EXPECTATIONS (EXPECTATION (CARRIER:TICK) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TICK))) (ACTION:NOOP (TEST_INT_SYMBOL:314)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (UNLIMITED))))");
1654 
1655  _r_remove_expectation(r, _t_child(ex,1));
1656 
1657  // test listen that blocks
1658  n = _t_parse(G_sem,0,"(LISTEN (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL))))");
1659 
1660  G_next_process_id = 0; // reset the process ids so the test will always work
1661  T *run_tree = __p_build_run_tree(n,0);
1662  _t_free(n);
1663  Q *q = r->q;
1664  Qe *e = _p_addrt2q(q,run_tree);
1665 
1666  //debug_enable(D_LISTEN+D_SIGNALS);
1667  spec_is_equal(_p_reduceq(q),noReductionErr);
1668  spec_is_equal(q->contexts_count,0);
1669  spec_is_ptr_equal(q->blocked,e);
1670  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (process:LISTEN) (PARAMS))");
1671 
1672  spec_is_str_equal(t2s(__r_get_expectations(r,DEFAULT_ASPECT)),"(EXPECTATIONS (EXPECTATION (CARRIER:TESTING) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:TEST_STR_SYMBOL))) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1)) (PARAMS (SLOT (USAGE:NULL_SYMBOL))) (END_CONDITIONS (COUNT:1))))");
1673 
1674  T *s = __r_make_signal(r->addr,r->addr,DEFAULT_ASPECT,TESTING,_t_new_str(0,TEST_STR_SYMBOL,"fishy!"),0,0,0);
1675  _r_deliver(r,s);
1676  spec_is_equal(_p_reduceq(q),noReductionErr);
1677 
1678  // because this listen blocked, and can thus only be woken up once, the expectation
1679  // had to have been removed afterwards.
1680  spec_is_str_equal(t2s(__r_get_expectations(r,DEFAULT_ASPECT)),"(EXPECTATIONS)");
1681 
1682  // @todo, ok the two params thing here is wrong, but we don't actually have
1683  // a use case for the blocking listen, so I don't quite know how it should work... @FIXME
1684  spec_is_str_equal(t2s(run_tree),"(RUN_TREE (PARAMS (TEST_STR_SYMBOL:fishy!)) (PARAMS))");
1685  debug_disable(D_LISTEN);
1686  _r_free(r);
1687 }
1688 
1689 void testProcessSelfAddr() {
1690  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1691 
1692  T *n = _t_new_root(SELF_ADDR);
1693  _t_news(n,RESULT_SYMBOL,TO_ADDRESS);
1694  spec_is_equal(__p_reduce_sys_proc(0,SELF_ADDR,n,r->q),noReductionErr);
1695  spec_is_str_equal(t2s(n),"(TO_ADDRESS (RECEPTOR_ADDR:3))");
1696  _t_free(n);
1697  _r_free(r);
1698 }
1699 
1700 void testProcessGetLabel() {
1701  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1702  T *n = _t_parse(G_sem,0,"(GET_LABEL (LABEL_SYMBOL:CONTENT_TYPE) (LABEL_TYPE:HTTP_HEADER_LABEL) (RESULT_SYMBOL:LINE))");
1703  spec_is_equal(__p_reduce_sys_proc(0,GET_LABEL,n,r->q),noReductionErr);
1704  spec_is_str_equal(t2s(n),"(LINE:Content-Type)");
1705  _t_free(n);
1706  _r_free(r);
1707 }
1708 
1711  Process divz = _defDivZero(); // add the if_even process to our defs
1712 
1713  // create a run tree right in the position to "call" this function
1714  T *t = _t_new_root(RUN_TREE);
1715  T *n = _t_new_root(NOOP);
1716  T *d = _t_newr(n,divz);
1717  _t_newi(d,TEST_INT_SYMBOL,124);
1718 
1719  T *c = _t_rclone(n);
1720  _t_add(t,c);
1721  T *ps = _t_newr(t,PARAMS);
1722 
1723  // error routine is just a param ref to pass back the error tree
1724  int pt[] = {4,1,TREE_PATH_TERMINATOR};
1725  __t_new(t,PARAM_REF,pt,sizeof(int)*4,1);
1726 
1727  // confirm that it reduces correctly
1728  spec_is_equal(_p_reduce(G_sem,t),noReductionErr);
1729  spec_is_str_equal(t2s(_t_child(t,1)),"(ZERO_DIVIDE_ERR (ERROR_LOCATION:/1/1))");
1730 
1731  _t_free(t);_t_free(n);
1733 }
1734 
1737 
1738  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1739  Q *q = r->q;
1740 
1741  Process if_even = G_ifeven;
1742 
1743  // create two run trees
1744  T *n = _t_new_root(PARAMS);
1745  __t_newi(n,TEST_INT_SYMBOL,99,1);
1746  __t_newi(n,TEST_INT_SYMBOL,123,1);
1747  __t_newi(n,TEST_INT_SYMBOL,124,1);
1748  T *t1 = _p_make_run_tree(G_sem,if_even,n,NULL);
1749  __t_newi(n,TEST_INT_SYMBOL,100,1);
1750  T *l2 = __t_new(n,if_even,0,0,1);
1751  __t_newi(l2,TEST_INT_SYMBOL,2,1);
1752  __t_newi(l2,TEST_INT_SYMBOL,123,1);
1753  __t_newi(l2,TEST_INT_SYMBOL,124,1);
1754  __t_newi(n,TEST_INT_SYMBOL,314,1);
1755 
1756  T *t2 = _p_make_run_tree(G_sem,if_even,n,NULL);
1757 
1758  // add them to a processing queue
1759  spec_is_equal(q->contexts_count,0);
1760  spec_is_ptr_equal(q->active,NULL);
1761  _p_addrt2q(q,t1);
1762  spec_is_equal(q->contexts_count,1);
1763  spec_is_ptr_equal(q->active->context->run_tree,t1);
1764  spec_is_ptr_equal(q->active->prev,NULL);
1765  _p_addrt2q(q,t2);
1766  spec_is_equal(q->contexts_count,2);
1767  spec_is_ptr_equal(q->active->context->run_tree,t1);
1768  spec_is_ptr_equal(q->active->next->context->run_tree,t2);
1769  spec_is_ptr_equal(q->active->next->prev, q->active);
1770 
1771  spec_is_long_equal(q->active->accounts.elapsed_time,0);
1772  spec_is_long_equal(q->active->next->accounts.elapsed_time,0);
1773 
1774  // confirm that they both reduce correctly
1775  pthread_t thread;
1776  int rc;
1777  rc = pthread_create(&thread,0,_p_reduceq_thread,q);
1778  if (rc){
1779  raise_error("ERROR; return code from pthread_create() is %d\n", rc);
1780  }
1781  void *status;
1782  rc = pthread_join(thread, &status);
1783  if (rc) {
1784  raise_error("ERROR; return code from pthread_join() is %d\n", rc);
1785  }
1786  spec_is_long_equal((long)status,noReductionErr);
1787 
1788  // contexts have been moved to the completed list and now have
1789  // some elapsed time data associated with them.
1790  spec_is_equal(q->contexts_count,0);
1791  spec_is_ptr_equal(q->completed->context->run_tree,t2);
1792  uint64_t et1,et2;
1793  spec_is_true((et1 = q->completed->accounts.elapsed_time)>0);
1794  spec_is_ptr_equal(q->completed->next->context->run_tree,t1);
1795  spec_is_true((et2 = q->completed->next->accounts.elapsed_time)>0);
1796 
1797  // confirm the results of the two run trees
1798  spec_is_str_equal(t2s(_t_child(t1,1)),"(TEST_INT_SYMBOL:124)");
1799  spec_is_str_equal(t2s(_t_child(t2,1)),"(TEST_INT_SYMBOL:123)");
1800 
1801  _p_cleanup(q);
1802 
1803  spec_is_ptr_equal(q->completed,NULL);
1804  // confirm that after cleaning up the two processes, the accounting information
1805  // is updated in a receptor state structure
1806  char buf[200];
1807  sprintf(buf,"(RECEPTOR_ELAPSED_TIME:%ld)",et1+et2);
1808  spec_is_str_equal(t2s(_t_child(_t_child(r->root,ReceptorInstanceStateIdx),ReceptorElapsedTimeIdx)),buf);
1809 
1810  _t_free(n);
1811  _r_free(r);
1813 }
1814 
1815 void testRunTreeTemplate() {
1816 
1817  T *params = _t_new_root(PARAMS);
1818  T *sm = _t_parse(G_sem,0,"(SEMANTIC_MAP (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ASPECT_IDENT:DEFAULT_ASPECT))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (PING))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (PING))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (TO_ADDRESS (RECEPTOR_ADDR:3)))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (NOOP))))");
1819 
1820  T *r = _p_make_run_tree(G_sem,send_request,params,sm);
1821  _t_free(params);
1822  spec_is_str_equal(t2s(r),"(RUN_TREE (process:NOOP (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth) (PING) (CARRIER:backnforth))) (PARAMS))");
1823  _t_free(r);
1824  _t_free(sm);
1825 }
1826 
1827 void testProcessContinue() {
1828 
1829  // CONTINUE allows you to restart reduction some other place on the tree.
1830  T *t = _t_new_root(RUN_TREE);
1831  T *n = _t_parse(G_sem,0,"(NOOP (IF (BOOLEAN:0) (CONTINUE (CONTINUE_LOCATION:/1) (CONTINUE_VALUE (TEST_STR_SYMBOL:\"fish\"))) (TEST_INT_SYMBOL:413)))");
1832  T *c = _t_rclone(n);
1833  _t_add(t,c);
1834  _p_reduce(G_sem,t);
1835 
1836  spec_is_str_equal(t2s(_t_child(t,1)),"(TEST_STR_SYMBOL:fish)");
1837  _t_free(t);
1838  _t_free(n);
1839 }
1840 
1841 void testProcessWakeup() {
1842  Receptor *r = _r_new(G_sem,TEST_RECEPTOR);
1843 
1844  T *p = _t_parse(G_sem,0,"(NOOP (REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1))))");
1845 
1846  T *code =_t_rclone(p);
1847  T *run_tree = __p_build_run_tree(code,0);
1848  _t_free(code);
1849  spec_is_str_equal(_td(r,run_tree),"(RUN_TREE (process:NOOP (process:REQUEST (TO_ADDRESS (RECEPTOR_ADDR:99)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:TESTING) (TEST_INT_SYMBOL:314) (RESPONSE_CARRIER:TESTING) (END_CONDITIONS (COUNT:1)))) (PARAMS))");
1850 
1851  // add the run tree into a queue and run it
1852  G_next_process_id = 0; // reset the process ids so the test will always work
1853  Q *q = r->q;
1854  Qe *e =_p_addrt2q(q,run_tree);
1855  R *c = e->context;
1856 
1857  // after reduction the context should be in the blocked state
1858  spec_is_equal(_p_reduceq(q),noReductionErr);
1859  spec_is_equal(q->contexts_count,0);
1860  spec_is_ptr_equal(q->blocked,e);
1861  spec_is_equal(c->state,Block);
1862  spec_is_str_equal(_td(r,r->pending_responses),"(PENDING_RESPONSES (PENDING_RESPONSE (SIGNAL_UUID) (CARRIER:TESTING) (WAKEUP_REFERENCE (PROCESS_IDENT:1) (CODE_PATH:/1/1)) (END_CONDITIONS (COUNT:1))))");
1863  T *wakeup = _t_getv(r->pending_responses,1,PendingResponseWakeupIdx,TREE_PATH_TERMINATOR);
1864 
1865  _p_wakeup(q,wakeup,NULL,divideByZeroReductionErr);
1866  spec_is_equal(q->contexts_count,1);
1867  spec_is_ptr_equal(q->blocked,NULL);
1868  spec_is_ptr_equal(q->active,e);
1869  spec_is_equal(c->state,divideByZeroReductionErr);
1870  spec_is_equal(_p_reduceq(q),noReductionErr);
1871  spec_is_equal(q->contexts_count,0);
1872 
1873  code =_t_rclone(p);
1874  run_tree = __p_build_run_tree(code,0);
1875  _t_free(code);
1876  e =_p_addrt2q(q,run_tree);
1877  c = e->context;
1878  spec_is_equal(_p_reduceq(q),noReductionErr);
1879  wakeup = _t_getv(r->pending_responses,2,PendingResponseWakeupIdx,TREE_PATH_TERMINATOR);
1880  _p_wakeup(q,wakeup,_t_newi(0,TEST_INT_SYMBOL,314),noReductionErr);
1881  spec_is_ptr_equal(q->blocked,NULL);
1882  spec_is_ptr_equal(q->active,e);
1883  spec_is_equal(c->state,Eval);
1884  spec_is_equal(_p_reduceq(q),noReductionErr);
1885  spec_is_str_equal(_td(r,run_tree),"(RUN_TREE (TEST_INT_SYMBOL:314) (PARAMS))");
1886 
1887  _t_free(p);
1888  _r_free(r);
1889 }
1890 
1891 void testProcess() {
1892  _defIfEven();
1893  testProcessParameter();
1894  testRunTree();
1895  testProcessGet();
1896  testProcessDel();
1897  testProcessNew();
1898  testProcessDefine();
1899  testProcessDo();
1900  testProcessTranscode();
1901  testProcessDissolve();
1902  testProcessSemtrex();
1903  testProcessFill();
1904  testProcessFillMatch();
1905  testProcessFillMatchFull();
1906  testProcessIf();
1907  testProcessCond();
1908  testProcessSym();
1910  testProcessPath();
1911  testProcessString();
1912  testProcessRespond();
1913  testProcessSay();
1914  testProcessRequest();
1915  testProcessConverse();
1916  testProcessConverseListen();
1917  testProcessThisScope();
1918  testProcessQuote();
1919  testProcessStream();
1920  testProcessStreamClose();
1921  testProcessInitiate();
1922  testProcessReduce();
1923  testProcessRefs();
1925  testProcessSignatureMatching();
1926  testProcessError();
1927  testProcessRaise();
1928  testProcessIterate();
1929  testProcessIterateOnSymbol();
1930  testProcessListen();
1931  testProcessSelfAddr();
1932  testProcessGetLabel();
1934  testProcessMulti();
1935  testRunTreeTemplate();
1936  testProcessContinue();
1937  testProcessWakeup();
1938 }
T * _t_new_root(Symbol symbol)
Definition: tree.c:160
Receptor * r
back-pointer to receptor in which this Q is running (for defs and more)
Definition: ceptr_types.h:207
Definition: ceptr_types.h:114
void testProcessIntMath()
Definition: process_spec.h:448
Error _p_step(Q *q, R **contextP)
Definition: process.c:1578
Process _d_define_process(SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
Definition: def.c:336
Definition: stream.h:30
Definition: ceptr_types.h:206
T * __t_newi(T *parent, Symbol symbol, int surface, bool is_run_node)
Definition: tree.c:97
T * _t_get(T *t, int *p)
Definition: tree.c:1441
T * _t_detach_by_idx(T *t, int i)
Definition: tree.c:278
void testProcessIf()
Definition: process_spec.h:398
void _p_wakeup(Q *q, T *wakeup, T *with, Error err)
Definition: process.c:1458
void * _p_reduceq_thread(void *arg)
Definition: process.c:2089
T * _t_clone(T *t)
Definition: tree.c:589
void _r_free(Receptor *r)
Definition: receptor.c:186
Error _p_reduceq(Q *q)
Definition: process.c:2126
int state
process state machine state
Definition: ceptr_types.h:171
void _defIfEven()
[defIfEven]
T * __t_new(T *parent, Symbol symbol, void *surface, size_t size, bool is_run_node)
Definition: tree.c:59
T * _t_child(T *t, int i)
Definition: tree.c:1251
T * makeASCIITree(char *c)
Definition: semtrex.c:1206
int err
process error value
Definition: ceptr_types.h:170
Context context
the context this receptor's definition creates
Definition: ceptr_types.h:240
ReceptorAddress addr
the address by which to get messages to this receptor instance
Definition: ceptr_types.h:241
Error __p_check_signature(SemTable *sem, Process p, T *code, T *sem_map)
Definition: process.c:291
void _st_kill(Stream *st)
Definition: stream.c:481
Instances instances
the instances store
Definition: ceptr_types.h:249
Definition: vmhost.h:20
Q * q
process queue
Definition: ceptr_types.h:250
void testProcessReduceDefinedProcess()
[defDivZero]
void * _t_surface(T *t)
Definition: tree.c:1215
Receptor * _r_new(SemTable *sem, SemanticID r)
Creates a new receptor.
Definition: receptor.c:88
Qe * active
active processes
Definition: ceptr_types.h:209
int id
the process id this context exists in
Definition: ceptr_types.h:169
Error __p_reduce_sys_proc(R *context, Symbol s, T *code, Q *q)
Definition: process.c:395
int contexts_count
number of active processes
Definition: ceptr_types.h:208
Process _defDivZero()
[defIfEven]
void _st_free(Stream *st)
Definition: stream.c:507
Symbol _d_define_symbol(SemTable *sem, Structure s, char *label, Context c)
Definition: def.c:83
T * node_pointer
pointer to the tree node to execute next
Definition: ceptr_types.h:173
T * __r_make_signal(ReceptorAddress from, ReceptorAddress to, Aspect aspect, Symbol carrier, T *signal_contents, UUIDt *in_response_to, T *until, T *cid)
Definition: receptor.c:515
T * __t_find(T *t, SemanticID sym, int start_child)
Definition: tree.c:1328
T * root
RECEPTOR_INSTANCE semantic tree.
Definition: ceptr_types.h:238
void testProcessErrorTrickleUp()
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
void testProcessMulti()
Error _p_reduce(SemTable *sem, T *rt)
Definition: process.c:1506
T * _r_get_instance(Receptor *r, Xaddr x)
Definition: receptor.c:379
#define _sl(t, s)
macro to add a single symbol literal to semtrex tree
Definition: semtrex.h:122
Qe * completed
completed processes (pending cleanup)
Definition: ceptr_types.h:210
T * _t_parse(SemTable *sem, T *parent, char *s,...)
Definition: tree.c:919
T * run_tree
pointer to the root of the run_tree
Definition: ceptr_types.h:172
void _t_add(T *t, T *c)
Definition: tree.c:261
R * __p_make_context(T *run_tree, R *caller, int process_id, T *sem_map)
Definition: process.c:1345
void _p_cleanup(Q *q)
Definition: process.c:2208
Definition: ceptr_types.h:168
void __t_morph(T *t, Symbol s, void *surface, size_t size, int allocate)
Definition: tree.c:325
Error _r_deliver(Receptor *r, T *signal)
Definition: receptor.c:954
int _t_children(T *t)
Definition: tree.c:1205
void _t_detach_by_ptr(T *t, T *c)
Definition: tree.c:291
void _t_free(T *t)
Definition: tree.c:526
T * _t_build(SemTable *sem, T *parent,...)
Definition: tree.c:635
T * _t_getv(T *t,...)
Definition: tree.c:1470
T * _p_make_run_tree(SemTable *sem, Process p, T *params, T *sem_map)
Definition: process.c:1974
T * _t_new_cptr(T *parent, Symbol symbol, void *s)
Definition: tree.c:239
Xaddr _r_new_instance(Receptor *r, T *t)
Definition: receptor.c:365