Skip to content

Commit

Permalink
added CONTINUE instruction. acts as a kind of "return" #140
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Apr 15, 2016
1 parent b918f70 commit ca6be1f
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 20 deletions.
25 changes: 19 additions & 6 deletions doxy/sys_defs.html
Original file line number Diff line number Diff line change
Expand Up @@ -2391,12 +2391,6 @@ <h4>SYS_CONTEXT</h4>
<div class="def-sig-out">result(SYMBOL:<a href="ref_sys_symbols.html#BOOLEAN">BOOLEAN</a>)</div>
<div class="def-comment"><i>test greater than or equal</i></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="RESTART_AT"></a>RESTART_AT</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#TREE_PATH">TREE-PATH</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="POP_COUNT"></a>POP_COUNT</div>
Expand All @@ -2410,6 +2404,25 @@ <h4>SYS_CONTEXT</h4>
<div class="def-sig-out">result(PASSTHRU:<a href="ref_sys_symbols.html#NULL_SYMBOL">NULL_SYMBOL</a>)</div>
<div class="def-comment"><i>pop values off a tree path</i></div>
</div>
<div class="def-item def-symbol">
<div class="def-type">Symbol:</div>
<div class="def-name"><a name="CONTINUE_LOCATION"></a>CONTINUE_LOCATION</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#TREE_PATH">TREE-PATH</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="CONTINUE_VALUE"></a>CONTINUE_VALUE</div>
<div class="def-sym-def"><a href="ref_sys_structures.html#ANY_SYMBOL">ANY-SYMBOL</a></div>
<div class="def-comment"></div>
</div>
<div class="def-item def-process">
<div class="def-type">Process:</div>
<div class="def-name"><a name="CONTINUE"></a>CONTINUE</div>
<div class="def-sig-in"><li>at(SYMBOL:<a href="ref_sys_symbols.html#CONTINUE_LOCATION">CONTINUE_LOCATION</a>)</li><li>with(SYMBOL:<a href="ref_sys_symbols.html#CONTINUE_VALUE">CONTINUE_VALUE</a>)</li></div>
<div class="def-sig-out">result(PASSTHRU:<a href="ref_sys_symbols.html#NULL_SYMBOL">NULL_SYMBOL</a>)</div>
<div class="def-comment"><i>restart reduction at some parent</i></div>
</div>
<div class="def-item def-process">
<div class="def-type">Process:</div>
<div class="def-name"><a name="INITIATE_PROTOCOL"></a>INITIATE_PROTOCOL</div>
Expand Down
1 change: 1 addition & 0 deletions doxy/sys_processes.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<tr><td><a name="LTE_INT"></a>LTE_INT</td><td><ol><li>int1(STRUCTURE:<a href="ref_sys_symbols.html#INTEGER">INTEGER</a>)</li><li>int2(STRUCTURE:<a href="ref_sys_symbols.html#INTEGER">INTEGER</a>)</li></ol></td><td>result(SYMBOL:<a href="ref_sys_symbols.html#BOOLEAN">BOOLEAN</a>)</td><td><i>test less than or equal</i></td></tr>
<tr><td><a name="GTE_INT"></a>GTE_INT</td><td><ol><li>int1(STRUCTURE:<a href="ref_sys_symbols.html#INTEGER">INTEGER</a>)</li><li>int2(STRUCTURE:<a href="ref_sys_symbols.html#INTEGER">INTEGER</a>)</li></ol></td><td>result(SYMBOL:<a href="ref_sys_symbols.html#BOOLEAN">BOOLEAN</a>)</td><td><i>test greater than or equal</i></td></tr>
<tr><td><a name="POP_PATH"></a>POP_PATH</td><td><ol><li>path(STRUCTURE:<a href="ref_sys_symbols.html#TREE_PATH">TREE_PATH</a>)</li><li>as(SYMBOL:<a href="ref_sys_symbols.html#RESULT_SYMBOL">RESULT_SYMBOL</a>)</li><li>[count(SYMBOL:<a href="ref_sys_symbols.html#POP_COUNT">POP_COUNT</a>)]</li></ol></td><td>result(PASSTHRU:<a href="ref_sys_symbols.html#NULL_SYMBOL">NULL_SYMBOL</a>)</td><td><i>pop values off a tree path</i></td></tr>
<tr><td><a name="CONTINUE"></a>CONTINUE</td><td><ol><li>at(SYMBOL:<a href="ref_sys_symbols.html#CONTINUE_LOCATION">CONTINUE_LOCATION</a>)</li><li>with(SYMBOL:<a href="ref_sys_symbols.html#CONTINUE_VALUE">CONTINUE_VALUE</a>)</li></ol></td><td>result(PASSTHRU:<a href="ref_sys_symbols.html#NULL_SYMBOL">NULL_SYMBOL</a>)</td><td><i>restart reduction at some parent</i></td></tr>
<tr><td><a name="INITIATE_PROTOCOL"></a>INITIATE_PROTOCOL</td><td><ol><li>protocol(SYMBOL:<a href="ref_sys_symbols.html#PNAME">PNAME</a>)</li><li>interaction(SYMBOL:<a href="ref_sys_symbols.html#WHICH_INTERACTION">WHICH_INTERACTION</a>)</li><li>bindings(SYMBOL:<a href="ref_sys_symbols.html#PROTOCOL_BINDINGS">PROTOCOL_BINDINGS</a>)</li></ol></td><td>error(SYMBOL:<a href="ref_sys_symbols.html#REDUCTION_ERROR_SYMBOL">REDUCTION_ERROR_SYMBOL</a>)</td><td><i>initiate the first step of a protocol</i></td></tr>
<tr><td><a name="MAGIC"></a>MAGIC</td><td><ol></ol></td><td>result(ANY:<a href="ref_sys_symbols.html#NULL_STRUCTURE">NULL_STRUCTURE</a>)</td><td><i>dark magic</i><br /> this process reduces to hardcoded special things as a scaffold for things we don't know how to build in ceptr yet.</td></tr>
<tr><td><a name="date2usshortdate"></a>date2usshortdate</td><td><ol><li>from(STRUCTURE:<a href="ref_sys_symbols.html#DATE">DATE</a>)</li></ol></td><td>to(SYMBOL:<a href="ref_sys_symbols.html#US_SHORT_DATE">US_SHORT_DATE</a>)</td><td><i>date to us short format date transcoder</i></td></tr>
Expand Down
3 changes: 2 additions & 1 deletion doxy/sys_symbols.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,9 @@
<tr><td><a name="COND_ELSE"></a>COND_ELSE</td><td><a href="ref_sys_structures.html#ANY_SYMBOL">ANY-SYMBOL</a></td><td></td></tr>
<tr><td><a name="CONDITIONS"></a>CONDITIONS</td><td><a href="ref_sys_structures.html#TUPLE_OF_ZERO_OR_MORE_OF_COND_PAIR_AND_COND_ELSE">TUPLE-OF-ZERO-OR-MORE-OF-COND-PAIR-AND-COND-ELSE</a></td><td></td></tr>
<tr><td><a name="EQUALITY_TEST_SYMBOL"></a>EQUALITY_TEST_SYMBOL</td><td><a href="ref_sys_structures.html#SYMBOL">SYMBOL</a></td><td> a symbol to use when testing the symbol equality</td></tr>
<tr><td><a name="RESTART_AT"></a>RESTART_AT</td><td><a href="ref_sys_structures.html#TREE_PATH">TREE-PATH</a></td><td></td></tr>
<tr><td><a name="POP_COUNT"></a>POP_COUNT</td><td><a href="ref_sys_structures.html#INTEGER">INTEGER</a></td><td></td></tr>
<tr><td><a name="CONTINUE_LOCATION"></a>CONTINUE_LOCATION</td><td><a href="ref_sys_structures.html#TREE_PATH">TREE-PATH</a></td><td></td></tr>
<tr><td><a name="CONTINUE_VALUE"></a>CONTINUE_VALUE</td><td><a href="ref_sys_structures.html#ANY_SYMBOL">ANY-SYMBOL</a></td><td></td></tr>
<tr><td><a name="STX_SL"></a>STX_SL</td><td><a href="ref_sys_structures.html#NULL_STRUCTURE">NULL-STRUCTURE</a></td><td></td></tr>
<tr><td><a name="STX_OP"></a>STX_OP</td><td><a href="ref_sys_structures.html#NULL_STRUCTURE">NULL-STRUCTURE</a></td><td></td></tr>
<tr><td><a name="STX_CP"></a>STX_CP</td><td><a href="ref_sys_structures.html#NULL_STRUCTURE">NULL-STRUCTURE</a></td><td></td></tr>
Expand Down
31 changes: 23 additions & 8 deletions spec/process_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,21 +537,21 @@ void testProcessIntMath() {
}

void testProcessPath() {
T *p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:RESTART_AT))");
T *p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION))");
__p_reduce_sys_proc(0,POP_PATH,p,0);
spec_is_str_equal(t2s(p),"(RESTART_AT:/4/1)");
spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/4/1)");
_t_free(p);
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:RESTART_AT) (POP_COUNT:2))");
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:2))");
__p_reduce_sys_proc(0,POP_PATH,p,0);
spec_is_str_equal(t2s(p),"(RESTART_AT:/4)");
spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:/4)");
_t_free(p);
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:RESTART_AT) (POP_COUNT:3))");
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:3))");
__p_reduce_sys_proc(0,POP_PATH,p,0);
spec_is_str_equal(t2s(p),"(RESTART_AT:)");
spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:)");
_t_free(p);
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:RESTART_AT) (POP_COUNT:10))");
p = _t_parse(G_sem,0,"(POP_PATH (RECEPTOR_PATH:/4/1/1) (RESULT_SYMBOL:CONTINUE_LOCATION) (POP_COUNT:10))");
__p_reduce_sys_proc(0,POP_PATH,p,0);
spec_is_str_equal(t2s(p),"(RESTART_AT:)");
spec_is_str_equal(t2s(p),"(CONTINUE_LOCATION:)");
_t_free(p);}

void testProcessString() {
Expand Down Expand Up @@ -1839,6 +1839,20 @@ void testRunTreeTemplate() {
_t_free(sm);
}

void testProcessContinue() {

// CONTINUE allows you to restart reduction some other place on the tree.
T *t = _t_new_root(RUN_TREE);
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)))");
T *c = _t_rclone(n);
_t_add(t,c);
_p_reduce(G_sem,t);

spec_is_str_equal(t2s(_t_child(t,1)),"(TEST_STR_SYMBOL:fish)");
_t_free(t);
_t_free(n);
}

void testProcess() {
_defIfEven();
testProcessParameter();
Expand Down Expand Up @@ -1884,4 +1898,5 @@ void testProcess() {
testProcessErrorTrickleUp();
testProcessMulti();
testRunTreeTemplate();
testProcessContinue();
}
4 changes: 3 additions & 1 deletion src/base_defs
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,11 @@ ProcessL: LT_INT,0,"test less than",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,B
ProcessL: GT_INT,0,"test greater than",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0;
ProcessL: LTE_INT,0,"test less than or equal",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0;
ProcessL: GTE_INT,0,"test greater than or equal",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0;
Symbol: RESTART_AT,TREE_PATH;
Symbol: POP_COUNT,INTEGER;
Process: POP_PATH,0,"pop values off a tree path","result",SIGNATURE_PASSTHRU,NULL_SYMBOL,"path",SIGNATURE_STRUCTURE,TREE_PATH,"as",SIGNATURE_SYMBOL,RESULT_SYMBOL,"count",SIGNATURE_OPTIONAL,SIGNATURE_SYMBOL,POP_COUNT,0;
Symbol: CONTINUE_LOCATION,TREE_PATH;
Symbol: CONTINUE_VALUE,[!];
Process: CONTINUE,0,"restart reduction at some parent","result",SIGNATURE_PASSTHRU,NULL_SYMBOL,"at",SIGNATURE_SYMBOL,CONTINUE_LOCATION,"with",SIGNATURE_SYMBOL,CONTINUE_VALUE,0;
Process: INITIATE_PROTOCOL,0,"initiate the first step of a protocol","error",SIGNATURE_SYMBOL,REDUCTION_ERROR_SYMBOL,"protocol",SIGNATURE_SYMBOL,PNAME,"interaction",SIGNATURE_SYMBOL,WHICH_INTERACTION,"bindings",SIGNATURE_SYMBOL,PROTOCOL_BINDINGS,0;
Process: MAGIC,0,"dark magic","result",SIGNATURE_ANY,NULL_STRUCTURE,0; this process reduces to hardcoded special things as a scaffold for things we don't know how to build in ceptr yet.

Expand Down
8 changes: 6 additions & 2 deletions src/base_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ SemanticID LT_INT={0,0,0};
SemanticID GT_INT={0,0,0};
SemanticID LTE_INT={0,0,0};
SemanticID GTE_INT={0,0,0};
SemanticID RESTART_AT={0,0,0};
SemanticID POP_COUNT={0,0,0};
SemanticID POP_PATH={0,0,0};
SemanticID CONTINUE_LOCATION={0,0,0};
SemanticID CONTINUE_VALUE={0,0,0};
SemanticID CONTINUE={0,0,0};
SemanticID INITIATE_PROTOCOL={0,0,0};
SemanticID MAGIC={0,0,0};
SemanticID STX_SL={0,0,0};
Expand Down Expand Up @@ -1083,9 +1085,11 @@ void base_defs(SemTable *sem) {
sPL(SYS_CONTEXT,GT_INT,0,"test greater than",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0);
sPL(SYS_CONTEXT,LTE_INT,0,"test less than or equal",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0);
sPL(SYS_CONTEXT,GTE_INT,0,"test greater than or equal",INTEGER,OPERATOR,"result",SIGNATURE_SYMBOL,BOOLEAN,"int1",SIGNATURE_STRUCTURE,INTEGER,"int2",SIGNATURE_STRUCTURE,INTEGER,0);
sY(SYS_CONTEXT,RESTART_AT,TREE_PATH);
sY(SYS_CONTEXT,POP_COUNT,INTEGER);
sP(SYS_CONTEXT,POP_PATH,0,"pop values off a tree path","result",SIGNATURE_PASSTHRU,NULL_SYMBOL,"path",SIGNATURE_STRUCTURE,TREE_PATH,"as",SIGNATURE_SYMBOL,RESULT_SYMBOL,"count",SIGNATURE_OPTIONAL,SIGNATURE_SYMBOL,POP_COUNT,0);
sY(SYS_CONTEXT,CONTINUE_LOCATION,TREE_PATH);
sY(SYS_CONTEXT,CONTINUE_VALUE,ANY_SYMBOL);
sP(SYS_CONTEXT,CONTINUE,0,"restart reduction at some parent","result",SIGNATURE_PASSTHRU,NULL_SYMBOL,"at",SIGNATURE_SYMBOL,CONTINUE_LOCATION,"with",SIGNATURE_SYMBOL,CONTINUE_VALUE,0);
sP(SYS_CONTEXT,INITIATE_PROTOCOL,0,"initiate the first step of a protocol","error",SIGNATURE_SYMBOL,REDUCTION_ERROR_SYMBOL,"protocol",SIGNATURE_SYMBOL,PNAME,"interaction",SIGNATURE_SYMBOL,WHICH_INTERACTION,"bindings",SIGNATURE_SYMBOL,PROTOCOL_BINDINGS,0);
sP(SYS_CONTEXT,MAGIC,0,"dark magic","result",SIGNATURE_ANY,NULL_STRUCTURE,0);
sY(SYS_CONTEXT,STX_SL,NULL_STRUCTURE);
Expand Down
7 changes: 5 additions & 2 deletions src/base_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ enum SYSSymbolIDs {
COND_ELSE_ID,
CONDITIONS_ID,
EQUALITY_TEST_SYMBOL_ID,
RESTART_AT_ID,
POP_COUNT_ID,
CONTINUE_LOCATION_ID,
CONTINUE_VALUE_ID,
STX_SL_ID,
STX_OP_ID,
STX_CP_ID,
Expand Down Expand Up @@ -526,8 +527,8 @@ SemanticID COND_PAIR;
SemanticID COND_ELSE;
SemanticID CONDITIONS;
SemanticID EQUALITY_TEST_SYMBOL;
SemanticID RESTART_AT;
SemanticID POP_COUNT;
SemanticID CONTINUE_LOCATION;
SemanticID STX_SL;
SemanticID STX_OP;
SemanticID STX_CP;
Expand Down Expand Up @@ -882,6 +883,7 @@ enum SYSProcessIDs {
LTE_INT_ID,
GTE_INT_ID,
POP_PATH_ID,
CONTINUE_ID,
INITIATE_PROTOCOL_ID,
MAGIC_ID,
NUM_SYS_PROCESSES
Expand Down Expand Up @@ -931,6 +933,7 @@ SemanticID GT_INT;
SemanticID LTE_INT;
SemanticID GTE_INT;
SemanticID POP_PATH;
SemanticID CONTINUE;
SemanticID INITIATE_PROTOCOL;
SemanticID MAGIC;

Expand Down
12 changes: 12 additions & 0 deletions src/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,18 @@ Error __p_reduce_sys_proc(R *context,Symbol s,T *code,Q *q) {
raise_error("whoa THIS_SCOPE executed outside CONVERSE!");
x = _t_rclone(context->conversation->id);
break;
case CONTINUE_ID:
{
T *at = _t_detach_by_idx(code,1);
T *with = _t_detach_by_idx(_t_child(code,1),1);
int *path = (int *)_t_surface(at);
// @todo validate that the path is on ok path to unwind to...
T *c = _t_get(context->run_tree,path);
if (!c) raise_error("continue at point invalid");
__p_unwind_to_point(context,c,with);
return(noErr);
}
break;
case COMPLETE_ID:
{
T *with = _t_detach_by_idx(code,1);
Expand Down

0 comments on commit ca6be1f

Please sign in to comment.