ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
process.c File Reference

implementation of ceptr processing: instructions and run tree reduction More...

#include "process.h"
#include "def.h"
#include "semtrex.h"
#include <stdarg.h>
#include "receptor.h"
#include "../spec/spec_utils.h"
#include "util.h"
#include "debug.h"
#include <errno.h>
#include "accumulator.h"
#include "protocol.h"
Include dependency graph for process.c:

Go to the source code of this file.

#define __p_dequeue(list, qe)
 
#define __p_enqueue(list, qe)
 
#define __p_append(list, qe)
 
int G_next_process_id = 0
 
char * sn [] ={"Done","Ascend","Descend","Pushed","Pop","Eval","Block"}
 
void rt_check (Receptor *r, T *t)
 
uint32_t get_rt_cur_child (Receptor *r, T *tP)
 
void set_rt_cur_child (Receptor *r, T *tP, uint32_t idx)
 
void processUnblocker (Stream *st)
 
TdefaultRequestUntil ()
 
void _p_fill_from_match (SemTable *sem, T *t, T *match_results, T *match_tree)
 
Process _p_get_transcoder (SemTable *sem, Symbol src_sym, Symbol to_sym)
 
int _p_transcode (SemTable *sem, T *src, Symbol to_sym, Structure to_s, T **result)
 
Error __p_check_signature (SemTable *sem, Process p, T *code, T *sem_map)
 
void __p_unwind_to_point (R *context, T *code_point, T *with)
 
Error __p_reduce_sys_proc (R *context, Symbol s, T *code, Q *q)
 
R__p_make_context (T *run_tree, R *caller, int process_id, T *sem_map)
 
void pq (Qe *qe)
 
void _p_enqueue (Qe **listP, Qe *e)
 
Qe__p_find_context (Qe *e, int process_id)
 
void __p_unblock (Q *q, Qe *e, Error err)
 
Error _p_unblock (Q *q, int id)
 
void _p_wakeup (Q *q, T *wakeup, T *with, Error err)
 
Error _p_reduce (SemTable *sem, T *rt)
 
T__p_buildErr (R *context)
 
Error _p_step (Q *q, R **contextP)
 
T__p_build_wakeup_info (T *code_point, int process_id)
 
T__p_build_run_tree_va (T *code, int num_params, va_list params)
 
T__p_build_run_tree (T *code, int num_params,...)
 
T_p_make_run_tree (SemTable *sem, Process p, T *params, T *sem_map)
 
Q_p_newq (Receptor *r)
 
void _p_free_context (R *c)
 
void _p_free_elements (Qe *e)
 
void _p_freeq (Q *q)
 
Qe__p_addrt2q (Q *q, T *run_tree, T *sem_map)
 
void * _p_reduceq_thread (void *arg)
 
void debug_np (int type, T *np)
 
char * __debug_state_str (R *context)
 
Error _p_reduceq (Q *q)
 
void _p_cleanup (Q *q)
 
T__p_make_form (Symbol sym, char *output_label, Symbol output_type, SemanticID output_sem,...)
 

Detailed Description

implementation of ceptr processing: instructions and run tree reduction

Todo:
implement a way to define sys_processes input and output signatures

Definition in file process.c.

Macro Definition Documentation

#define __p_append (   list,
  qe 
)
Value:
{ \
qe->next = NULL; \
if (!list) {list=qe;} \
else { \
Qe *d = list; \
while(d->next) { \
d = d->next; \
} \
qe->prev = d; \
d->next = qe; \
} \
}

Definition at line 1393 of file process.c.

#define __p_dequeue (   list,
  qe 
)
Value:
if (qe->next) {qe->next->prev = qe->prev;} \
if (!qe->prev) { \
list = qe->next; \
} \
else { \
qe->prev->next = qe->next; \
}

Definition at line 1375 of file process.c.

#define __p_enqueue (   list,
  qe 
)
Value:
{ \
Qe *d = list; \
qe->next = d; \
if (d) d->prev = qe; \
list = qe; \
}

Definition at line 1386 of file process.c.

Function Documentation

Qe* __p_addrt2q ( Q q,
T run_tree,
T sem_map 
)

add a run tree into a processing queue

Todo:
make thread safe. currently you shouldn't call this if the Q is being actively reduced

Definition at line 2068 of file process.c.

T* __p_build_run_tree_va ( T code,
int  num_params,
va_list  params 
)

low level functon to build a run tree from a code tree and a variable list of params

Definition at line 1943 of file process.c.

T* __p_build_wakeup_info ( T code_point,
int  process_id 
)

low level function to build a WAKEUP_REFERENCE symbol used for unblocking a process

Definition at line 1931 of file process.c.

Error __p_check_signature ( SemTable sem,
Process  p,
T code,
T sem_map 
)

check a group of parameters to see if they match a process input signature

Parameters
[in]semSemantic table in use
[in]pthe Process we are checking against
[in]paramslist of parameters
Returns
Error code
Todo:
add SIGNATURE_SYMBOL for setting up process signatures by Symbol not just Structure

Definition at line 291 of file process.c.

R* __p_make_context ( T run_tree,
R caller,
int  process_id,
T sem_map 
)

create a run-tree execution context.

Definition at line 1345 of file process.c.

T* __p_make_form ( Symbol  sym,
char *  output_label,
Symbol  output_type,
SemanticID  output_sem,
  ... 
)

utility function to build process form structures

Parameters
[in]symbolthe type of process form to build, i.e. PROCESS_SIGNATURE
[in]output_label
[in]output_symbol
[in]var_argstriplets of label, symbol type, and symbol value for the signature
[out]formtree
Todo:
add more sensible handling of output signature. We still aren't quite sure what to do about the output label, and how to handle output signature pass through from the results, probably need a special symbol for that

Definition at line 2235 of file process.c.

Error __p_reduce_sys_proc ( R context,
Symbol  s,
T code,
Q q 
)

reduce system level processes in a run tree. Assumes that the children have already been reduced and all parameters have been filled in

these system level processes are the equivalent of the instruction set of the ceptr virtual machine

Todo:
what happens if it has more than one child! validity check?
Todo:
this would probably be faster with just one total realloc for all children
Todo:
what happens if it has more than one child! validity check?
Todo:
interpolation errors?
Todo:
what should this really return?
Todo:
the value returned from the iteration will be what??(what's in x)

Definition at line 395 of file process.c.

void _p_cleanup ( Q q)

cleanup any completed process from the queue, updating the receptor state data as necessary

Parameters
[in]qthe queue to be cleaned up

Definition at line 2208 of file process.c.

void _p_fill_from_match ( SemTable sem,
T t,
T match_results,
T match_tree 
)

implements the FILL_FROM_MATCH process

replaces the template tree with the matched sub-parts from a semtrex match results tree

Parameters
[in]semcurrent semantic context
[in]ttemplate tree to be filled
[in]match_resultsSEMTREX_MATCH_RESULTS tree
[in]match_treeoriginal tree that was matched (needed to build SEMANTIC_MAP)
Todo:
what to do if match has sibs??

Definition at line 76 of file process.c.

void _p_freeq ( Q q)

free the resources in a queue, including any run-trees

Parameters
[in]qthe queue to be freed

Definition at line 2055 of file process.c.

T* _p_make_run_tree ( SemTable sem,
Process  p,
T params,
T sem_map 
)

Build a run tree from a code tree and params

Parameters
[in]semcurrent semantic context
[in]pprocess to be cloned into a run tree
[in]paramsparameters to be added to the run-tree
Note
the params get added, not cloned to the tree
Returns
T RUN_TREE tree

Definition at line 1974 of file process.c.

Q* _p_newq ( Receptor r)

create a new processing queue

Parameters
[in]rreceptor in which to create the Queue
Returns
Q the processing queue

Definition at line 2015 of file process.c.

Error _p_reduce ( SemTable sem,
T rt 
)

reduce a run tree by executing the instructions in it and replacing the tree values in place

a run_tree is expected to have a code tree as the first child, parameters as the second, and optionally an error handling routine as the third child. This is a simplified reducer for testing purposes only, as real reduction happens in the context of a processing Q. This function makes a fake processing Q and Receptor.

Parameters
[in]processescontext of defined processes
[in]run_treethe run tree being reduced
Returns
Error status of the reduction

Examples (from test suite):

Process divz = _defDivZero(); // add the if_even process to our defs
// create a run tree right in the position to "call" this function
T *t = _t_new_root(RUN_TREE);
T *n = _t_new_root(NOOP);
T *d = _t_newr(n,divz);
_t_newi(d,TEST_INT_SYMBOL,124);
T *c = _t_rclone(n);
_t_add(t,c);
T *ps = _t_newr(t,PARAMS);
// error routine is just a param ref to pass back the error tree
int pt[] = {4,1,TREE_PATH_TERMINATOR};
__t_new(t,PARAM_REF,pt,sizeof(int)*4,1);
// confirm that it reduces correctly
spec_is_equal(_p_reduce(G_sem,t),noReductionErr);
spec_is_str_equal(t2s(_t_child(t,1)),"(ZERO_DIVIDE_ERR (ERROR_LOCATION:/1/1))");

Definition at line 1506 of file process.c.

Error _p_reduceq ( Q q)

reduce all the processes in a queue

Parameters
[in]qthe queue to be processed
Todo:
figure out what error we should be sending back here, i.e. what if

Definition at line 2126 of file process.c.

void* _p_reduceq_thread ( void *  arg)

reduce all the processes in a queue, and terminate thread when completed

Parameters
[in]qthe queue to be processed

Definition at line 2089 of file process.c.

Error _p_step ( Q q,
R **  contextP 
)

take one step in the execution state machine given a run-tree context

a run_tree is expected to have a code tree as the first child, parameters as the second, and optionally an error handling routine as the third child.

Parameters
[in]ProcessingQ in which this step is taking place
[in]pointerto context pointer
Returns
the next state that will be called for the context
Todo:
what if the replaced parameter is itself a PARAM_REF tree ??

Definition at line 1578 of file process.c.

Error _p_unblock ( Q q,
int  id 
)

search for the context in the q and unblock it

Definition at line 1426 of file process.c.

void _p_wakeup ( Q q,
T wakeup,
T with,
Error  err 
)

wakeup a process that's been paused

Parameters
[in]qthe processing q in which to search for the process
[in]wakeupthe WAKEUP_REF tree that identifies what needs waking up
[in]witha value to replace the current node_pointer with (i.e. a result)
[in]erran error value if the wakeup should trigger the error handler instead of resuming processing

Definition at line 1458 of file process.c.