Skip to content

Commit

Permalink
added RESPONSE_HANDLER_PARAMS to requesting protocol wip #109 #137
Browse files Browse the repository at this point in the history
fixed bugs in PROTOCOL_DEFAULTS handling and in __t_fill_template when fill deletes a slot
also fixes bugs parsing a NULL_SYMBOL in _t_build2 (i.e. if used in base_defs.pl)
  • Loading branch information
zippy committed May 12, 2016
1 parent b08615a commit c8a0159
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 14 deletions.
6 changes: 6 additions & 0 deletions doxy/sys_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,12 @@ <h4>DEV_COMPOSITORY_CONTEXT</h4>
<div class="def-sym-def"><a href="ref_sys_structures.html#PROCESS">PROCESS</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="RESPONSE_HANDLER_PARAMETERS"></a>RESPONSE_HANDLER_PARAMETERS</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#SYMBOL">SYMBOL</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="backnforth"></a>backnforth</div>
Expand Down
1 change: 1 addition & 0 deletions doxy/sys_symbols.html
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@
<tr><td><a name="CHANNEL"></a>CHANNEL</td><td><a href="ref_sys_structures.html#SYMBOL">SYMBOL</a></td><td></td></tr>
<tr><td><a name="REQUEST_HANDLER"></a>REQUEST_HANDLER</td><td><a href="ref_sys_structures.html#PROCESS">PROCESS</a></td><td></td></tr>
<tr><td><a name="RESPONSE_HANDLER"></a>RESPONSE_HANDLER</td><td><a href="ref_sys_structures.html#PROCESS">PROCESS</a></td><td></td></tr>
<tr><td><a name="RESPONSE_HANDLER_PARAMETERS"></a>RESPONSE_HANDLER_PARAMETERS</td><td><a href="ref_sys_structures.html#SYMBOL">SYMBOL</a></td><td></td></tr>
<tr><td><a name="backnforth"></a>backnforth</td><td><a href="ref_sys_structures.html#INTERACTION">INTERACTION</a></td><td></td></tr>
<tr><td><a name="RECOGNIZER"></a>RECOGNIZER</td><td><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></td><td></td></tr>
<tr><td><a name="RECOGNIZEE"></a>RECOGNIZEE</td><td><a href="ref_sys_structures.html#RECEPTOR_ADDRESS">RECEPTOR-ADDRESS</a></td><td></td></tr>
Expand Down
7 changes: 4 additions & 3 deletions spec/protocol_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "../src/protocol.h"
void testProtocolRequesting() {
spec_is_str_equal(t2s(_sem_get_def(G_sem,REQUESTING)),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:REQUESTING)) (PROTOCOL_SEMANTICS (ROLE:REQUESTER) (ROLE:RESPONDER) (GOAL:RESPONSE_HANDLER) (GOAL:REQUEST_HANDLER) (USAGE:CHANNEL) (USAGE:REQUEST_TYPE) (USAGE:RESPONSE_TYPE)) (backnforth (INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request)) (EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))))");
spec_is_str_equal(t2s(_sem_get_def(G_sem,send_request)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_request)) (PROCESS_INTENTION:send request) (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response)) (SIGNATURE_ANY)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (EXPECTED_SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))))");
spec_is_str_equal(t2s(_sem_get_def(G_sem,REQUESTING)),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:REQUESTING)) (PROTOCOL_SEMANTICS (ROLE:REQUESTER) (ROLE:RESPONDER) (GOAL:RESPONSE_HANDLER) (GOAL:REQUEST_HANDLER) (USAGE:CHANNEL) (USAGE:REQUEST_TYPE) (USAGE:RESPONSE_TYPE) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request)) (EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))))");
spec_is_str_equal(t2s(_sem_get_def(G_sem,send_request)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_request)) (PROCESS_INTENTION:send request) (SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (process:REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response)) (SIGNATURE_ANY)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (EXPECTED_SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (EXPECTED_SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (EXPECTED_SLOT (USAGE:REQUEST_TYPE)) (EXPECTED_SLOT (GOAL:RESPONSE_HANDLER)))))");

spec_is_str_equal(t2s(_sem_get_def(G_sem,send_response)),"(PROCESS_DEFINITION (PROCESS_NAME (ENGLISH_LABEL:send_response)) (PROCESS_INTENTION:send response) (process:RESPOND (SIGNAL_REF:/2/1/4) (SLOT (GOAL:REQUEST_HANDLER))) (PROCESS_SIGNATURE (OUTPUT_SIGNATURE (SIGNATURE_LABEL (ENGLISH_LABEL:response id)) (SIGNATURE_SYMBOL:SIGNAL_UUID)) (TEMPLATE_SIGNATURE (EXPECTED_SLOT (GOAL:REQUEST_HANDLER)))))");

Expand All @@ -25,7 +25,7 @@ void testProtocolRecognize() {
T *sem_map = _t_new_root(SEMANTIC_MAP);
T *t = _o_unwrap(G_sem,recog,sem_map);
// and also check how it gets unwrapped because it's defined in terms of REQUESTING
spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS (ROLE:RECOGNIZER) (GOAL:RECOGNITION)) (backnforth (INITIATE (ROLE:RECOGNIZER) (DESTINATION (ROLE:RECOGNIZEE)) (ACTION:send_request)) (EXPECT (ROLE:RECOGNIZEE) (SOURCE (ROLE:RECOGNIZER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response))))");
spec_is_str_equal(t2s(t),"(PROTOCOL_DEFINITION (PROTOCOL_LABEL (ENGLISH_LABEL:RECOGNIZE)) (PROTOCOL_SEMANTICS (ROLE:RECOGNIZER) (GOAL:RECOGNITION) (USAGE:RESPONSE_HANDLER_PARAMETERS)) (PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL)))) (backnforth (INITIATE (ROLE:RECOGNIZER) (DESTINATION (ROLE:RECOGNIZEE)) (ACTION:send_request)) (EXPECT (ROLE:RECOGNIZEE) (SOURCE (ROLE:RECOGNIZER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SEMTREX_SYMBOL:are_you))) (ACTION:send_response))))");

// the unwrapping should build up a semantic map
spec_is_str_equal(t2s(sem_map),"(SEMANTIC_MAP (SEMANTIC_LINK (ROLE:REQUESTER) (REPLACEMENT_VALUE (ROLE:RECOGNIZER))) (SEMANTIC_LINK (ROLE:RESPONDER) (REPLACEMENT_VALUE (ROLE:RECOGNIZEE))) (SEMANTIC_LINK (GOAL:RESPONSE_HANDLER) (REPLACEMENT_VALUE (GOAL:RECOGNITION))) (SEMANTIC_LINK (USAGE:REQUEST_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:are_you))) (SEMANTIC_LINK (USAGE:RESPONSE_TYPE) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:i_am))) (SEMANTIC_LINK (USAGE:CHANNEL) (REPLACEMENT_VALUE (ACTUAL_SYMBOL:DEFAULT_ASPECT))) (SEMANTIC_LINK (GOAL:REQUEST_HANDLER) (REPLACEMENT_VALUE (ACTUAL_PROCESS:fill_i_am))))");
Expand Down Expand Up @@ -110,6 +110,7 @@ void testProtocolRecognize() {
_p_reduceq(self->q);
debug_disable(D_TREE);
debug_disable(D_PROTOCOL);
debug_disable(D_STEP);
debug_disable(D_REDUCE+D_REDUCEV);

spec_is_str_equal(_td(self,self->pending_signals),"(PENDING_SIGNALS (SIGNAL (ENVELOPE (SIGNAL_UUID)) (MESSAGE (HEAD (FROM_ADDRESS (RECEPTOR_ADDR:3)) (TO_ADDRESS (RECEPTOR_ADDR:3)) (ASPECT_IDENT:DEFAULT_ASPECT) (CARRIER:backnforth) (IN_RESPONSE_TO_UUID)) (BODY:{(i_am (RECEPTOR_LABEL (ENGLISH_LABEL:super cept)) (RECEPTOR_IDENTIFIER:314159))}))))");
Expand Down
7 changes: 5 additions & 2 deletions src/base_defs
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,11 @@ Symbol: RESPONSE_TYPE,SYMBOL;
Symbol: CHANNEL,SYMBOL;
Symbol: REQUEST_HANDLER,PROCESS;
Symbol: RESPONSE_HANDLER,PROCESS;
Symbol: RESPONSE_HANDLER_PARAMETERS,SYMBOL;

Symbol: backnforth,INTERACTION;
Data: req_code,(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))));

Data: req_code,(SLOT (GOAL:RESPONSE_HANDLER) (SLOT_CHILDREN (SLOT (USAGE:RESPONSE_HANDLER_PARAMETERS)) (REQUEST (SLOT (ROLE:RESPONDER) (SLOT_IS_VALUE_OF:TO_ADDRESS)) (SLOT (USAGE:CHANNEL) (SLOT_IS_VALUE_OF:ASPECT_IDENT)) (CARRIER:backnforth) (SLOT (USAGE:REQUEST_TYPE)) (CARRIER:backnforth)))));
Process: send_request,req_code,"send request","response",SIGNATURE_ANY,NULL_STRUCTURE;

Data: resp_code,(RESPOND (SIGNAL_REF:/2/1/4) (SLOT (GOAL:REQUEST_HANDLER)));
Expand All @@ -547,7 +549,8 @@ Data: req_def,(PROTOCOL_DEFINITION
(USAGE:CHANNEL)
(USAGE:REQUEST_TYPE)
(USAGE:RESPONSE_TYPE)
)
(USAGE:RESPONSE_HANDLER_PARAMETERS))
(PROTOCOL_DEFAULTS (SEMANTIC_LINK (USAGE:RESPONSE_HANDLER_PARAMETERS) (REPLACEMENT_VALUE (NULL_SYMBOL))))
(backnforth
(INITIATE (ROLE:REQUESTER) (DESTINATION (ROLE:RESPONDER)) (ACTION:send_request))
(EXPECT (ROLE:RESPONDER) (SOURCE (ROLE:REQUESTER)) (PATTERN (SEMTREX_SYMBOL_LITERAL (SLOT (USAGE:REQUEST_TYPE) (SLOT_IS_VALUE_OF:SEMTREX_SYMBOL)))) (ACTION:send_response))));
Expand Down
6 changes: 4 additions & 2 deletions src/base_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ SemanticID RESPONSE_TYPE={0,0,0};
SemanticID CHANNEL={0,0,0};
SemanticID REQUEST_HANDLER={0,0,0};
SemanticID RESPONSE_HANDLER={0,0,0};
SemanticID RESPONSE_HANDLER_PARAMETERS={0,0,0};
SemanticID backnforth={0,0,0};
SemanticID send_request={0,0,0};
SemanticID send_response={0,0,0};
Expand Down Expand Up @@ -1195,12 +1196,13 @@ void base_defs(SemTable *sem) {
sY(DEV_COMPOSITORY_CONTEXT,CHANNEL,SYMBOL);
sY(DEV_COMPOSITORY_CONTEXT,REQUEST_HANDLER,PROCESS);
sY(DEV_COMPOSITORY_CONTEXT,RESPONSE_HANDLER,PROCESS);
sY(DEV_COMPOSITORY_CONTEXT,RESPONSE_HANDLER_PARAMETERS,SYMBOL);
sY(DEV_COMPOSITORY_CONTEXT,backnforth,INTERACTION);
sData(DEV_COMPOSITORY_CONTEXT,req_code,STX_OP,SLOT,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,SLOT_CHILDREN,STX_OP,REQUEST,STX_OP,SLOT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SLOT_IS_VALUE_OF,TO_ADDRESS,STX_CP,STX_CP,STX_OP,SLOT,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,SLOT_IS_VALUE_OF,ASPECT_IDENT,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
sData(DEV_COMPOSITORY_CONTEXT,req_code,STX_OP,SLOT,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,SLOT_CHILDREN,STX_OP,SLOT,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_CP,STX_OP,REQUEST,STX_OP,SLOT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SLOT_IS_VALUE_OF,TO_ADDRESS,STX_CP,STX_CP,STX_OP,SLOT,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,SLOT_IS_VALUE_OF,ASPECT_IDENT,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_CP,STX_OP,CARRIER,backnforth,STX_CP,STX_CP,STX_CP,STX_CP,STX_CP);
sP(DEV_COMPOSITORY_CONTEXT,send_request,req_code,"send request","response",SIGNATURE_ANY,NULL_STRUCTURE,0L);
sData(DEV_COMPOSITORY_CONTEXT,resp_code,STX_OP,RESPOND,STX_OP,SIGNAL_REF,2,1,4,TREE_PATH_TERMINATOR,STX_CP,STX_OP,SLOT,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_CP,STX_CP);
sP(DEV_COMPOSITORY_CONTEXT,send_response,resp_code,"send response","response id",SIGNATURE_SYMBOL,SIGNAL_UUID,0L);
sData(DEV_COMPOSITORY_CONTEXT,req_def,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_SEMANTICS,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_TYPE,STX_CP,STX_CP,STX_OP,backnforth,STX_OP,INITIATE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,DESTINATION,STX_OP,ROLE,RESPONDER,STX_CP,STX_CP,STX_OP,ACTION,send_request,STX_CP,STX_CP,STX_OP,EXPECT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SOURCE,STX_OP,ROLE,REQUESTER,STX_CP,STX_CP,STX_OP,PATTERN,STX_OP,SEMTREX_SYMBOL_LITERAL,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,SLOT_IS_VALUE_OF,SEMTREX_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,ACTION,send_response,STX_CP,STX_CP,STX_CP,STX_CP);
sData(DEV_COMPOSITORY_CONTEXT,req_def,STX_OP,PROTOCOL_DEFINITION,STX_OP,PROTOCOL_SEMANTICS,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,GOAL,RESPONSE_HANDLER,STX_CP,STX_OP,GOAL,REQUEST_HANDLER,STX_CP,STX_OP,USAGE,CHANNEL,STX_CP,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_TYPE,STX_CP,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_CP,STX_OP,PROTOCOL_DEFAULTS,STX_OP,SEMANTIC_LINK,STX_OP,USAGE,RESPONSE_HANDLER_PARAMETERS,STX_CP,STX_OP,REPLACEMENT_VALUE,STX_OP,NULL_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,backnforth,STX_OP,INITIATE,STX_OP,ROLE,REQUESTER,STX_CP,STX_OP,DESTINATION,STX_OP,ROLE,RESPONDER,STX_CP,STX_CP,STX_OP,ACTION,send_request,STX_CP,STX_CP,STX_OP,EXPECT,STX_OP,ROLE,RESPONDER,STX_CP,STX_OP,SOURCE,STX_OP,ROLE,REQUESTER,STX_CP,STX_CP,STX_OP,PATTERN,STX_OP,SEMTREX_SYMBOL_LITERAL,STX_OP,SLOT,STX_OP,USAGE,REQUEST_TYPE,STX_CP,STX_OP,SLOT_IS_VALUE_OF,SEMTREX_SYMBOL,STX_CP,STX_CP,STX_CP,STX_CP,STX_OP,ACTION,send_response,STX_CP,STX_CP,STX_CP,STX_CP);
sProt(DEV_COMPOSITORY_CONTEXT,REQUESTING,req_def);
sY(DEV_COMPOSITORY_CONTEXT,RECOGNIZER,RECEPTOR_ADDRESS);
sY(DEV_COMPOSITORY_CONTEXT,RECOGNIZEE,RECEPTOR_ADDRESS);
Expand Down
2 changes: 2 additions & 0 deletions src/base_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ enum DEV_COMPOSITORYSymbolIDs {
CHANNEL_ID,
REQUEST_HANDLER_ID,
RESPONSE_HANDLER_ID,
RESPONSE_HANDLER_PARAMETERS_ID,
backnforth_ID,
RECOGNIZER_ID,
RECOGNIZEE_ID,
Expand Down Expand Up @@ -1071,6 +1072,7 @@ SemanticID RESPONSE_TYPE;
SemanticID CHANNEL;
SemanticID REQUEST_HANDLER;
SemanticID RESPONSE_HANDLER;
SemanticID RESPONSE_HANDLER_PARAMETERS;
SemanticID backnforth;
SemanticID RECOGNIZER;
SemanticID RECOGNIZEE;
Expand Down
6 changes: 4 additions & 2 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ T *_o_bindings2sem_map(T *bindings, T *sem_map,T *defaults) {
T * _o_unwrap(SemTable *sem,T *def,T *sem_map) {
T *d = _t_clone(def);
int i;
for (i=1;i<=_t_children(d);i++) {
T *defaults = _t_find(d,PROTOCOL_DEFAULTS);
for (i=ProtocolDefOptionalsIdx;i<=_t_children(d);i++) {
T *t = _t_child(d,i);
if (semeq(_t_symbol(t),INCLUSION)) {
Protocol p = *(Protocol *)_t_surface(_t_child(t,InclusionPnameIdx));
Expand Down Expand Up @@ -329,15 +330,16 @@ T * _o_unwrap(SemTable *sem,T *def,T *sem_map) {
if (semeq(PROTOCOL_DEFAULTS,_t_symbol(_t_child(p_def,ProtocolDefSemanticsIdx)))) {
x = _t_detach_by_idx(p_def,ProtocolDefSemanticsIdx);
debug(D_PROTOCOL,"merging defaults: %s",_t2s(sem,x));
T *defaults = _t_find(d,PROTOCOL_DEFAULTS);
// if the including protocol has no defaults we can just insert them
if (!defaults) {
int path[] = {ProtocolDefOptionalsIdx,TREE_PATH_TERMINATOR};
_t_insert_at(d,path,x);
defaults = x;
}
else {
// otherwise we have to merge in any that don't already exist
_o_merge_sem_map(x,defaults);
_t_free(x);
}
}

Expand Down
17 changes: 13 additions & 4 deletions src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ T *_t_build2(SemTable *sem,T *parent,...) {
param = va_arg(ap,Symbol);
if (semeq(param,STX_OP)) {
node = va_arg(ap,Symbol);
type = _getBuildType(sem,node,&st,&def);
type = NULL_SYMBOL;
if (!semeq(node,NULL_SYMBOL)) type = _getBuildType(sem,node,&st,&def);
if (semeq(type,STRUCTURE_SYMBOL) && semeq(*(Symbol *)_t_surface(def),NULL_SYMBOL)) {
debug(D_TREE,"building sys structure %s\n",_sem_get_name(sem,st));
if (semeq(st,PROCESS) || semeq(st,SYMBOL) || semeq(st,STRUCTURE) || semeq(st,PROTOCOL)) {
Expand Down Expand Up @@ -1038,13 +1039,14 @@ T *__t_find_actual(T *sem_map,Symbol actual_kind,T *replacement_kind) {
*;
* @param[in,out] template the tree with SLOTs to be filled
* @param[in] sem_map mappings used to fill the template
* @returns boolean indicating whether fill resulted in templates removal
*
* @note the template is modified in place, so the caller may need to clone a source template
*
* <b>Examples (from test suite):</b>
* @snippet spec/tree_spec.h testTreeTemplate
*/
void __t_fill_template(T *template, T *sem_map,bool as_run_node) {
bool __t_fill_template(T *template, T *sem_map,bool as_run_node) {
if (!template) return;
debug(D_TREE,"filling template:\n%s\n",__t2s(G_sem,template,INDENT));
debug(D_TREE,"from sem_map:\n%s\n\n",__t2s(G_sem,sem_map,INDENT));
Expand Down Expand Up @@ -1175,16 +1177,23 @@ void __t_fill_template(T *template, T *sem_map,bool as_run_node) {
if (!p) raise_error("not expecting a root node!");
_t_detach_by_ptr(p,template);
_t_free(template);
template = NULL;
}
break;
}
else { debug(D_TREE," nope)\n");}
}
}
else {
DO_KIDS(template,_t_fill_template(_t_child(template,i),sem_map));
int i;
for(i=1;i<=_t_children(template);i++) {
T *t = _t_child(template,i);
// if the fill resulted in deletion we need to decrease the count to not skip a child
if (_t_fill_template(t,sem_map)) i--;
}
}
debug(D_TREE,"results in:\n%s\n\n",__t2s(G_sem,template,INDENT));
debug(D_TREE,"results in:\n%s\n\n",template ? __t2s(G_sem,template,INDENT) : "<nothing>");
return template == NULL;
}

/******************** Node data accessors */
Expand Down
2 changes: 1 addition & 1 deletion src/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ T *__t_tokenize(char *s);
T *_t_parse(SemTable *sem,T *parent,char *s,...);

#define _t_fill_template(t,i) __t_fill_template(t,i,false)
void __t_fill_template(T *template, T *items,bool as_run_node);
bool __t_fill_template(T *template, T *items,bool as_run_node);

/******************** Node data accessors */
int _t_children(T *t);
Expand Down

0 comments on commit c8a0159

Please sign in to comment.