18 void *_o_add_label(
char *label,
T *def) {
20 _t_new_str(l,ENGLISH_LABEL,label);
21 int path[2] = {1,TREE_PATH_TERMINATOR};
39 va_start(params,label);
44 T *l = _t_newr(p,PROTOCOL_LABEL);
45 _t_new_str(l,ENGLISH_LABEL,label);
46 T *t = _t_newr(p,PROTOCOL_SEMANTICS);
55 if (semeq(_sem_get_symbol_structure(sem,state),INTERACTION)) state = INTERACTION;
61 param = va_arg(params,
Symbol);
64 if (semeq(state,PROTOCOL_DEFINITION)) {
65 if (semeq(param,INTERACTION)) {
68 else if (semeq(param,INCLUSION)) {
72 else if (semeq(param,NULL_SYMBOL)) {
75 else raise_error(
"expecting ROLE,GOAL,USAGE,INCLUSION,INTERACTION or NULL_SYMBOL got %s",
_sem_get_name(sem,param));
77 if (semeq(state,PROTOCOL_SEMANTICS)) {
78 if (semeq(param,ROLE)) {
82 else if (semeq(param,GOAL)) {
86 else if (semeq(param,USAGE)) {
88 _t_news(t,USAGE,role);
92 if (semeq(state,INTERACTION)) {
93 if (semeq(param,INTERACTION)) {
95 t = _t_newr(t,interaction);
97 else if (semeq(param,EXPECT) || semeq(param,INITIATE)) {
103 if (semeq(state,EXPECT)) {
104 if (semeq(param,EXPECT)) {
105 t = _t_newr(p,EXPECT);
107 _t_news(t,ROLE,role);
108 T *s = _t_newr(t,SOURCE);
110 _t_news(s,ROLE,source);
111 T *pattern = va_arg(params,
T*);
113 T *action = va_arg(params,
T*);
118 if (semeq(state,INITIATE)) {
119 if (semeq(param,INITIATE)) {
120 t = _t_newr(p,INITIATE);
122 _t_news(t,ROLE,role);
123 T *s = _t_newr(t,DESTINATION);
125 _t_news(s,ROLE,source);
126 T *action = va_arg(params,
T*);
131 if (semeq(state,INCLUSION)) {
132 if (semeq(param,INCLUSION)) {
133 t = _t_newr(p,INCLUSION);
135 _t_news(t,PNAME,pname);
137 else if (semeq(param,WHICH_SYMBOL)) {
138 T *l = _t_newr(t,RESOLUTION);
139 T *w = _t_newr(l,WHICH_SYMBOL);
140 _t_news(w,USAGE,va_arg(params,
Symbol));
141 _t_news(w,ACTUAL_SYMBOL,va_arg(params,
Symbol));
143 else if (semeq(param,WHICH_PROCESS)) {
144 T *l = _t_newr(t,RESOLUTION);
145 T *w = _t_newr(l,WHICH_PROCESS);
146 _t_news(w,GOAL,va_arg(params,
Process));
147 _t_news(w,ACTUAL_PROCESS,va_arg(params,
Process));
149 else if (semeq(param,WHICH_RECEPTOR)) {
150 T *l = _t_newr(t,RESOLUTION);
151 T *w = _t_newr(l,WHICH_RECEPTOR);
152 _t_news(w,ROLE,va_arg(params,
Symbol));
153 _t_news(w,ACTUAL_RECEPTOR,va_arg(params,
Symbol));
155 else if (semeq(param,WHICH_USAGE)) {
156 T *l = _t_newr(t,LINKAGE);
157 T *w = _t_newr(l,WHICH_USAGE);
158 _t_news(w,USAGE,va_arg(params,
Symbol));
159 _t_news(w,USAGE,va_arg(params,
Symbol));
161 else if (semeq(param,WHICH_GOAL)) {
162 T *l = _t_newr(t,LINKAGE);
163 T *w = _t_newr(l,WHICH_GOAL);
164 _t_news(w,GOAL,va_arg(params,
Process));
165 _t_news(w,GOAL,va_arg(params,
Process));
167 else if (semeq(param,WHICH_ROLE)) {
168 T *l = _t_newr(t,LINKAGE);
169 T *w = _t_newr(l,WHICH_ROLE);
170 _t_news(w,ROLE,va_arg(params,
Symbol));
171 _t_news(w,ROLE,va_arg(params,
Symbol));
183 void _t_replace_sem_refs(
T *t,
T *sem_map) {
187 if (semeq(sym,GOAL)||semeq(sym,ROLE)||semeq(sym,USAGE)) {
195 T *ref =
_t_child(m,SemanticMapSemanticRefIdx);
206 DO_KIDS(t,_t_replace_sem_refs(
_t_child(t,i),sem_map));
211 void _o_merge_sem_map(
T *from,
T *into) {
218 T *s =
_t_parse(G_sem,0,
"(SEMTREX_WALK (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:SEMANTIC_LINK) (SEMTREX_VALUE_LITERAL %)))",v);
240 T *t = _t_newr(sem_map,SEMANTIC_LINK);
242 T *r = _t_newr(t,REPLACEMENT_VALUE);
246 _o_merge_sem_map(defaults,sem_map);
248 debug(D_PROTOCOL,
"converting bindings %s\n",t2sp(bindings));
249 if (defaults) debug(D_PROTOCOL,
"with defaults %s\n",t2sp(defaults));
250 debug(D_PROTOCOL,
"to sem map %s\n",t2sp(sem_map));
265 T *defaults = _t_find(d,PROTOCOL_DEFAULTS);
266 for (i=ProtocolDefOptionalsIdx;i<=
_t_children(d);i++) {
270 T *ps = _sem_get_defs(sem,p);
274 for(j=InclusionPnameIdx+1;j<=c;j++) {
278 T *t = _t_newr(sem_map,SEMANTIC_LINK);
280 T *r = _t_newr(t,REPLACEMENT_VALUE);
283 else if (semeq(
_t_symbol(x),RESOLUTION)) {
284 if (!bindings) bindings =
_t_new_root(PROTOCOL_BINDINGS);
287 else raise_error(
"expecting LINKAGE or RESOLUTION");
291 debug(D_PROTOCOL,
"filling template %s\n",
__t2s(sem,p_def,INDENT));
292 debug(D_PROTOCOL,
"with %s\n",
__t2s(sem,sem_map,INDENT));
293 _t_replace_sem_refs(p_def,sem_map);
294 debug(D_PROTOCOL,
"result %s\n",
__t2s(sem,p_def,INDENT));
297 T *unbound_semantics;
300 unbound_semantics =
_o_resolve(sem,p_def,sem_map);
312 T *parent_semantics =
_t_child(d,ProtocolDefSemanticsIdx);
322 _t_add(parent_semantics,x);
323 debug(D_PROTOCOL,
"adding %s to semantics\n",
_sem_get_name(sem,sym));
330 if (semeq(PROTOCOL_DEFAULTS,
_t_symbol(
_t_child(p_def,ProtocolDefSemanticsIdx)))) {
332 debug(D_PROTOCOL,
"merging defaults: %s",_t2s(sem,x));
335 int path[] = {ProtocolDefOptionalsIdx,TREE_PATH_TERMINATOR};
341 _o_merge_sem_map(x,defaults);
354 debug(D_PROTOCOL,
"unwrapped to: %s\n",
__t2s(sem,d,INDENT));
378 _t_fill_template(def,sem_map);
410 T *p = _sem_get_def(r->
sem,protocol);
411 if (!p) raise_error(
"protocol %s not found",
_sem_get_name(r->
sem,protocol));
418 debug(D_PROTOCOL,
"express %s yelids unbound: %s\n",
_sem_get_name(r->
sem,role),_t2s(r->
sem,unbound));
419 debug(D_PROTOCOL,
"express %s yelids sem_map: %s\n",
_sem_get_name(r->
sem,role),_t2s(r->
sem,sem_map));
430 if (semeq(_sem_get_symbol_structure(r->
sem,interaction),INTERACTION)) {
442 if (!bindings && semeq(
_t_symbol(a),GOAL)) {
445 T *sm = sem_map ?
_t_clone(sem_map) : NULL;
447 if (params) params =
_t_clone(params);
448 T *e = __r_build_expectation(interaction,pattern,a,params,0,sm,NULL);
449 debug(D_PROTOCOL,
"express %s adds expectation: %s\n",
_sem_get_name(r->
sem,role),_t2s(r->
sem,e));
450 __r_add_expectation(r,aspect,e);
474 T *p = _sem_get_def(r->
sem,protocol);
475 if (!p) raise_error(
"protocol %s not found",
_sem_get_name(r->
sem,protocol));
481 T *ia = _t_find(p,interaction);
482 if (!ia) raise_error(
"interaction '%s' not found in protocol definition",
_sem_get_name(r->
sem,interaction));
483 T *initiate = _t_find(ia,INITIATE);
484 if (!initiate) raise_error(
"no INITIATE found in %s interaction",
_sem_get_name(r->
sem,interaction));
487 T *action =
_t_child(initiate,InitiateActionIdx);
508 T *rt =
__o_initiate(r,protocol,interaction,bindings,&sem_map);
T * _t_new_root(Symbol symbol)
char * _sem_get_name(SemTable *sem, SemanticID s)
T * _o_bindings2sem_map(T *bindings, T *sem_map, T *defaults)
T * _t_detach_by_idx(T *t, int i)
Semantic tree regular expression header file.
T * _t_child(T *t, int i)
protocol helpers header file
vmhost implementation header file
void _t_insert_at(T *t, int *path, T *i)
int _t_match(T *semtrex, T *t)
T * _o_unwrap(SemTable *sem, T *def, T *sem_map)
void _t_replace_node(T *t, T *r)
SState * state(StateType type, int *statesP, int level)
void _o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings)
Qe * __p_addrt2q(Q *q, T *run_tree, T *sem_map)
SemTable * sem
pointer back to the genotype table for this receptor's vmhost instance
void _o_express_role(Receptor *r, Protocol protocol, Symbol role, Aspect aspect, T *bindings)
char * __t2s(SemTable *sem, T *t, int indent)
T * _t_parse(SemTable *sem, T *parent, char *s,...)
T * _o_make_protocol_def(SemTable *sem, Context c, char *label,...)
void _t_detach_by_ptr(T *t, T *c)
T * __o_initiate(Receptor *r, SemanticID protocol, SemanticID interaction, T *bindings, T **sem_mapP)
T * _p_make_run_tree(SemTable *sem, Process p, T *params, T *sem_map)
T * _o_resolve(SemTable *sem, T *def, T *sem_map)