ceptr
 All Data Structures Files Functions Variables Typedefs Macros Modules Pages
Symbol and Structure Definition

Data has both meaningful and structural aspects, both of which must be defined. More...

Files

file  base_defs.c
 auto-generated system definitions
 
file  base_defs.h
 auto-generated system definitions
 
file  def.c
 implementation file for symbol and structure definition functions
 
file  def.h
 header file for symbol and structure definition functions
 
file  semtable.c
 implementation of table for coordinating meaning across a vmhost
 
file  semtable.h
 header file for table for coordinating meaning across a vmhost
 
file  sys_defs.c
 definition of system semantic elements for bootstrapping
 
file  sys_defs.h
 Defines types and vars for system defined semantics.
 

Macros

#define ST(r, name, num,...)   name = _r_define_structure(r,"" #name "",num,__VA_ARGS__)
 
#define SY(r, name, str)   name = _r_define_symbol(r,str,"" #name "")
 
#define SP(r, code, name, intention, signature, link)   name = _r_define_process(r,code,"" #name "",intention,signature,link)
 
#define t2s(t)   _t2s(G_sem,t)
 
#define t2sp(t)   __t2s(G_sem,t,INDENT)
 
#define _t2s(d, t)   __t2s(d,t,NO_INDENT)
 
#define _d_get_def(defs, s)   _t_child(defs,(s).id);
 
#define _d_get_process_code(processes, p)   _d_get_def(processes,p)
 
#define _d_get_symbol_def(symbols, s)   _d_get_def(symbols,s)
 
#define _d_get_structure_def(structures, s)   _d_get_def(structures,s)
 
#define spec_is_sem_equal(got, expected)   spec_total++; if (semeq(expected,got)){putchar('.');} else {putchar('F');sprintf(failures[spec_failures++],"%s:%d expected %s to be %d.%d.%d but was %d.%d.%d",__FUNCTION__,__LINE__,#got,(expected).context,(expected).semtype,(expected).id,(got).context,(got).semtype,(got).id);}
 

Enumerations

enum  { ReceptorInstanceInstOfIdx =1, ReceptorInstanceContextNumIdx, ReceptorInstanceParentContextIdx, ReceptorInstanceStateIdx }
 
enum  { ReceptorDefinitionLabelIdx =1, ReceptorDefinitionDefsIdx }
 
enum  {
  ReceptorFluxIdx =1, ReceptorPendingSignalsIdx, ReceptorPendingResponsesIdx, ReceptorConversationsIdx,
  ReceptorElapsedTimeIdx
}
 
enum  { SignalEnvelopeIdx =1, SignalMessageIdx }
 
enum  { MessageHeadIdx =1, MessageBodyIdx }
 
enum  {
  HeadFromIdx =1, HeadToIdx, HeadAspectIdx, HeadCarrierIdx,
  HeadOptionalsIdx
}
 
enum  { EnvelopeSignalUUIDIdx =1 }
 
enum  {
  PendingResponseUUIDIdx =1, PendingResponseCarrierIdx, PendingResponseWakeupIdx, PendingResponseEndCondsIdx,
  PendingResponseConversationIdentIdx
}
 
enum  { WakeupReferenceProcessIdentIdx =1, WakeupReferenceCodePathIdx }
 
enum  {
  ExpectationCarrierIdx =1, ExpectationPatternIdx, ExpectationActionIdx, ExpectationParamsIdx,
  ExpectationEndCondsIdx, ExpectationOptionalsIdx
}
 
enum  DATEIndexes { dateYearIdx =1, dateMonthIdx, dateDayIdx }
 
enum  TIMEIndexes { timeHourIdx =1, timeMinuteIdx, timeSecondIdx }
 
enum  TIMESTAMPIndexes { timestampTodayIdx =1, timestampNowIdx }
 
enum  ASPECTIndexes { aspectExpectationsIdx =1, aspectSignalsIdx }
 
enum  {
  ExpectRoleIdx =1, ExpectSourceIdx, ExpectPatternIdx, ExpectActionIdx,
  ExpectParamsIdx
}
 
enum  { InitiateRoleIdx =1, InitiateDestinationIdx, InitiateActionIdx }
 
enum  { SourceRoleIdx =1 }
 
enum  { DefLabelIdx =1, SymbolDefStructureIdx }
 
enum  { StructureDefLabelIdx =1, StructureDefDefIdx }
 
enum  {
  ProcessDefNameIdx =1, ProcessDefIntentionIdx, ProcessDefCodeIdx, ProcessDefSignatureIdx,
  ProcessDefLinkIdx
}
 
enum  { SignatureOutputSigIdx =1 }
 
enum  { InputSigLabelIdx =1, InputSigSemVariantsIdx, InputSigOptionalIdx }
 
enum  { ProtocolDefNameIdx =1, ProtocolDefSemanticsIdx, ProtocolDefOptionalsIdx }
 
enum  { RuntreeCodeIdx =1, RunTreeParamsIdx, RunTreeErrorCodeIdx, RunTreeErrorParamsIdx }
 
enum  { ResolutionWhichIdx =1 }
 
enum  { ConnectionWhichIdx =1 }
 
enum  { SemtrexMatchSymbolIdx =1, SemtrexMatchPathIdx, SemtrexMatchSibsIdx }
 
enum  { InclusionPnameIdx =1 }
 
enum  { SemanticMapSemanticRefIdx =1, SemanticMapReplacementValIdx }
 
enum  { SlotSemanticRefIdx =1, SlotValueOfIdx }
 
enum  { ParameterReferenceIdx =1, ParameterResultIdx =2 }
 
enum  { InstanceStoreInstancesIdx =1, InstanceStoreTokensIdx =2 }
 
enum  { InstanceTokensLastTokenIdx =1 }
 
enum  { ConversationIdentIdx =1, ConversationUntilIdx, ConversationConversationsIdx, ConversationWakeupIdx }
 
enum  { ConversationIdentUUIDIdx =1, ConversationIdentOptionalsIdx }
 
enum  { NO_INDENT =0, INDENT =-1 }
 

Functions

int semeq (SemanticID s1, SemanticID s2)
 
SemanticID _d_define (SemTable *sem, T *def, SemanticType semtype, Context c)
 
void __d_validate_symbol (SemTable *sem, Symbol s, char *n)
 
void __d_validate_structure (SemTable *sem, Structure s, char *n)
 
void __d_set_symbol_structure (T *symbols, Symbol sym, Structure s)
 
SemanticAddr _d_get_def_addr (T *def)
 
Symbol _d_define_symbol (SemTable *sem, Structure s, char *label, Context c)
 
Structure _d_define_structure (SemTable *sem, char *label, T *structure_def, Context c)
 
Structure _d_define_structure_v (SemTable *sem, char *label, Context c, int num_params,...)
 
T_d_make_vstruc_def (SemTable *sem, char *label, int num_params, va_list params)
 
Structure __d_get_symbol_structure (T *symbols, Symbol s)
 
size_t _d_get_symbol_size (SemTable *sem, Symbol s, void *surface)
 
size_t _d_get_structure_size (SemTable *sem, Symbol s, void *surface)
 
T_d_make_process_def (T *code, char *name, char *intention, T *signature, T *link)
 
Process _d_define_process (SemTable *sem, T *code, char *name, char *intention, T *signature, T *link, Context c)
 
Protocol _d_define_protocol (SemTable *sem, T *def, Context c)
 
T_d_make_protocol_def (SemTable *sem, char *label,...)
 
T_d_build_def_semtrex (SemTable *sem, Symbol s, T *parent)
 
size_t _sys_structure_size (int id, void *surface)
 
SemanticID _d_define_receptor (SemTable *sem, char *label, T *definitions, Context c)
 
SemanticID __d_define_receptor (SemTable *sem, T *def, Context c)
 
Context _d_get_receptor_context (SemTable *sem, SemanticID r)
 
char * __t2s (SemTable *sem, T *t, int indent)
 
char * _indent_line (int level, char *buf)
 
char * __t_dump (SemTable *sem, T *t, int level, char *buf)
 
SemTabledef_sys ()
 
void sys_free (SemTable *sem)
 

Variables

TG_cursor
 

Detailed Description

Data has both meaningful and structural aspects, both of which must be defined.

Structures are definitons of how data is organized; Symbols are a numeric semantic indicator (like a type) of what a given structure means. For example an "integer"" defines a structures of bits and how to interpret them, whereas a "shoe size" is a symbol for what a use of an integer means.

Function Documentation

SemanticID __d_define_receptor ( SemTable sem,
T def,
Context  c 
)

helper to define a new receptor

this call creates a receptor as a new semantic context inside given context

Parameters
[in]semthe SemanticTable of contexts
[in]defa human readable name for this receptor
[in]defRECEPTOR_DEFINITION for the receptor [in] the context in which to define this receptor

Definition at line 478 of file def.c.

Structure __d_get_symbol_structure ( T symbols,
Symbol  s 
)

get the structure for a given symbol

Parameters
[in]symbolsa symbol def tree containing symbol definitions
[in]sthe symbol
Returns
a Structure

Examples (from test suite):

Definition at line 156 of file def.c.

char* __t2s ( SemTable sem,
T t,
int  indent 
)

tree 2 string: returns a string representation of a tree make this actually not break on large trees!

Definition at line 518 of file def.c.

T* _d_build_def_semtrex ( SemTable sem,
Symbol  s,
T parent 
)

Walks the definition of a symbol to build a semtrex that would match that definiton

Parameters
[in]semthe semantic context
[in]sthe symbol to build a semtrex for
[in]parentthe parent semtrex node because this function calls itself recursively. Pass in 0 to start.
Returns
the completed semtrex
Todo:
currently this won't detect an incorrect strcture with extra children. This is because we don't haven't yet implemented the equivalent of "$" for semtrex.

Examples (from test suite):

Definition at line 433 of file def.c.

Process _d_define_process ( SemTable sem,
T code,
char *  name,
char *  intention,
T signature,
T link,
Context  c 
)

add a new process definition to the processes tree

Parameters
[in,out]processesa process def tree containing process codings which will be added to
[in]codethe code tree for this process
[in]namethe name of the process
[in]intentiona description of what the process intends to do/transform
[in]signaturethe signature for the process
Returns
the process identifier
Todo:
this is not thread safe!

Examples (from test suite):

T *defs = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
T *code = _t_new_root(NOOP); // fake code
T *signature = __p_make_signature("result",SIGNATURE_SYMBOL,NULL_SYMBOL,
"val",SIGNATURE_STRUCTURE,INTEGER,
"exponent",SIGNATURE_STRUCTURE,INTEGER,
NULL);
T *link = _t_build(G_sem,0,PROCESS_LINK,
PROCESS_OF_STRUCTURE,INTEGER,PROCESS_TYPE,OPERATOR,
NULL_SYMBOL,NULL_SYMBOL
);
Process p = _d_define_process(G_sem,code,"power","takes the mathematical power of the two params",signature,link,TEST_CONTEXT);
spec_is_true(is_process(p));
spec_is_true(!is_symbol(p));
spec_is_equal(_t_children(defs),p.id);
T *s = _t_child(defs,p.id);
spec_is_str_equal(t2s(s),"(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))))");

Definition at line 336 of file def.c.

Protocol _d_define_protocol ( SemTable sem,
T def,
Context  c 
)

add a protocol definition to a protocol defs tree

Parameters
[in]semis the semantic table to which to add the protocol
[in]defthe protocol definition
[in]thecontext in which this protocol is being defined
[out]thesemantic id of the new protocol

Definition at line 357 of file def.c.

SemanticID _d_define_receptor ( SemTable sem,
char *  label,
T definitions,
Context  c 
)

helper to define a new receptor

this call creates a receptor as a new semantic context inside given context

Parameters
[in]semthe SemanticTable of contexts
[in]labela human readable name for this receptor
[in]defdefinitions that make up the receptor [in] the context in which to define this receptor

Definition at line 457 of file def.c.

Structure _d_define_structure ( SemTable sem,
char *  label,
T structure_def,
Context  c 
)

define a new structure

Parameters
[in]semis the semantic table to which to add the structure
[in]labela c-string label for this structures
[in]structure_defthe STRUCTURE_DEF definitions
Returns
the new structure def

Examples (from test suite):

T *defs = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
Structure st = _d_define_structure_v(G_sem,"boolean pair",TEST_CONTEXT,2,BOOLEAN,BOOLEAN);
spec_is_str_equal(t2s(_sem_get_def(G_sem,st)),"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:boolean pair)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:BOOLEAN) (STRUCTURE_SYMBOL:BOOLEAN)))");

Definition at line 104 of file def.c.

Structure _d_define_structure_v ( SemTable sem,
char *  label,
Context  c,
int  num_params,
  ... 
)

helper to add a STRUCTURE_SEQUENCE of symbols structure definition to a semantic table

Parameters
[in]semis the semantic table to which to add the structure
[in]labela c-string label for this structures
[in]num_paramsnumber of symbols in the structure
[in]...variable list of Symbol type symbols
Returns
the new structure def

Examples (from test suite):

T *defs = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
Structure st = _d_define_structure_v(G_sem,"boolean pair",TEST_CONTEXT,2,BOOLEAN,BOOLEAN);
spec_is_str_equal(t2s(_sem_get_def(G_sem,st)),"(STRUCTURE_DEFINITION (STRUCTURE_LABEL (ENGLISH_LABEL:boolean pair)) (STRUCTURE_SEQUENCE (STRUCTURE_SYMBOL:BOOLEAN) (STRUCTURE_SYMBOL:BOOLEAN)))");

Definition at line 124 of file def.c.

Symbol _d_define_symbol ( SemTable sem,
Structure  s,
char *  label,
Context  c 
)

add a symbol definition to a symbol defs tree

Parameters
[in]semis the semantic table to which to add the symbol
[in]sthe structure type for this symbol
[in]labela c-string label for this symbol
[in]thecontext in which this symbol is being declared
Returns
the new symbol
Todo:
this is not thread safe!

Examples (from test suite):

T *d = __r_make_definitions();
int ctx = _sem_new_context(G_sem,d);
T *defs = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,ctx);
Symbol ss = _d_define_symbol(G_sem,INTEGER,"shoe size",ctx);
T *def = _sem_get_def(G_sem,ss);
spec_is_equal(_d_get_def_addr(def),1);
spec_is_true(is_symbol(ss));
spec_is_equal(_t_children(defs),ss.id);
spec_is_ptr_equal(_t_child(defs,ss.id),def);
spec_is_sem_equal(_t_symbol(_t_child(defs,ss.id)),SYMBOL_DEFINITION);
spec_is_sem_equal(_t_symbol(_t_child(_t_child(defs,ss.id),SymbolDefStructureIdx)),SYMBOL_STRUCTURE);
spec_is_sem_equal(_t_symbol(_t_child(_t_child(defs,ss.id),DefLabelIdx)),SYMBOL_LABEL);
spec_is_str_equal(t2s(defs),"(SYMBOLS (SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:shoe size)) (SYMBOL_STRUCTURE:INTEGER)))");
ss = _d_define_symbol(G_sem,NULL_STRUCTURE,"street number",ctx); // pre-declared to NULL
spec_is_equal(ss.id,2);
spec_is_str_equal(t2s(_t_child(defs,ss.id)),"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:street number)) (SYMBOL_STRUCTURE:NULL_STRUCTURE))");
__d_set_symbol_structure(defs,ss,INTEGER);
spec_is_str_equal(t2s(_t_child(defs,ss.id)),"(SYMBOL_DEFINITION (SYMBOL_LABEL (ENGLISH_LABEL:street number)) (SYMBOL_STRUCTURE:INTEGER))");
spec_is_equal(_d_get_def_addr(_t_child(defs,ss.id)),ss.id);
_sem_free_context(G_sem,ctx);
_t_free(d);

Definition at line 83 of file def.c.

size_t _d_get_structure_size ( SemTable sem,
Structure  s,
void *  surface 
)

get the size of a structure

Parameters
[in]semis the semantic table where symbols and structures are defined
[in]sthe structure
[in]surfacethe surface of the structure (may be necessary beause some structures have length info in the data)
Returns
size of the structure

Examples (from test suite):

// test a few built-in symbols and structures
spec_is_long_equal(_d_get_structure_size(G_sem,INTEGER,0),sizeof(int));
spec_is_long_equal(_d_get_structure_size(G_sem,BIT,0),sizeof(int));
spec_is_long_equal(_d_get_structure_size(G_sem,FLOAT,0),sizeof(float));
spec_is_long_equal(_d_get_structure_size(G_sem,XADDR,0),sizeof(Xaddr));
spec_is_long_equal(_d_get_symbol_size(G_sem,STRUCTURE_SYMBOL,0),sizeof(Symbol));
spec_is_long_equal(_d_get_symbol_size(G_sem,ENGLISH_LABEL,"shoe_size"),10);
// test user-defined symbols and structures
T *symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,TEST_CONTEXT);
T *structures = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
Symbol lat = _d_define_symbol(G_sem,FLOAT,"latitude",TEST_CONTEXT); // symbols are declared, structures are defined
Symbol lon = _d_define_symbol(G_sem,FLOAT,"longitude",TEST_CONTEXT); // here we declare two meaningful ways to use the structure float
// Two symbols, lat and lon are assembled into the structure "latlong"
Structure latlong = _d_define_structure_v(G_sem,"latlong",TEST_CONTEXT, 2, lat, lon);
// House location is a meaningful use of the structure latlong
Symbol house_loc = _d_define_symbol(G_sem,latlong,"house location",TEST_CONTEXT);
// Here's the surface of the latlong.
float ll[] = {2.0,90.3};
spec_is_long_equal(_d_get_symbol_size(G_sem,house_loc,ll),sizeof(ll));
spec_is_long_equal(_d_get_structure_size(G_sem,latlong,ll),sizeof(ll));
//structure sizing when structure is a singleton
Structure latstruct = _d_define_structure_v(G_sem,"latstruct",TEST_CONTEXT, 1, lat);
float ls[] = {2.0};
spec_is_long_equal(_d_get_structure_size(G_sem,latstruct,ll),sizeof(ls));
//@todo what about sizing with optional structural elements...

Definition at line 218 of file def.c.

size_t _d_get_symbol_size ( SemTable sem,
Symbol  s,
void *  surface 
)

get the size of a symbol

Parameters
[in]semis the semantic table where symbols and structures are define
[in]sthe symbol
[in]surfacethe surface of the structure (may be necessary beause some structures have length info in the data)
Returns
size of the structure

Examples (from test suite):

// test a few built-in symbols and structures
spec_is_long_equal(_d_get_structure_size(G_sem,INTEGER,0),sizeof(int));
spec_is_long_equal(_d_get_structure_size(G_sem,BIT,0),sizeof(int));
spec_is_long_equal(_d_get_structure_size(G_sem,FLOAT,0),sizeof(float));
spec_is_long_equal(_d_get_structure_size(G_sem,XADDR,0),sizeof(Xaddr));
spec_is_long_equal(_d_get_symbol_size(G_sem,STRUCTURE_SYMBOL,0),sizeof(Symbol));
spec_is_long_equal(_d_get_symbol_size(G_sem,ENGLISH_LABEL,"shoe_size"),10);
// test user-defined symbols and structures
T *symbols = __sem_get_defs(G_sem,SEM_TYPE_SYMBOL,TEST_CONTEXT);
T *structures = __sem_get_defs(G_sem,SEM_TYPE_STRUCTURE,TEST_CONTEXT);
Symbol lat = _d_define_symbol(G_sem,FLOAT,"latitude",TEST_CONTEXT); // symbols are declared, structures are defined
Symbol lon = _d_define_symbol(G_sem,FLOAT,"longitude",TEST_CONTEXT); // here we declare two meaningful ways to use the structure float
// Two symbols, lat and lon are assembled into the structure "latlong"
Structure latlong = _d_define_structure_v(G_sem,"latlong",TEST_CONTEXT, 2, lat, lon);
// House location is a meaningful use of the structure latlong
Symbol house_loc = _d_define_symbol(G_sem,latlong,"house location",TEST_CONTEXT);
// Here's the surface of the latlong.
float ll[] = {2.0,90.3};
spec_is_long_equal(_d_get_symbol_size(G_sem,house_loc,ll),sizeof(ll));
spec_is_long_equal(_d_get_structure_size(G_sem,latlong,ll),sizeof(ll));
//structure sizing when structure is a singleton
Structure latstruct = _d_define_structure_v(G_sem,"latstruct",TEST_CONTEXT, 1, lat);
float ls[] = {2.0};
spec_is_long_equal(_d_get_structure_size(G_sem,latstruct,ll),sizeof(ls));
//@todo what about sizing with optional structural elements...

Definition at line 178 of file def.c.

T* _d_make_process_def ( T code,
char *  name,
char *  intention,
T signature,
T link 
)

build a new process definition

Parameters
[in]codethe code tree for this process
[in]namethe name of the process
[in]intentiona description of what the process intends to do/transform
[in]signaturethe signature for the process
Returns
the newly defined process
Todo:
this is not thread safe!

Examples (from test suite):

T *defs = __sem_get_defs(G_sem,SEM_TYPE_PROCESS,TEST_CONTEXT);
T *code = _t_new_root(NOOP); // fake code
T *signature = __p_make_signature("result",SIGNATURE_SYMBOL,NULL_SYMBOL,
"val",SIGNATURE_STRUCTURE,INTEGER,
"exponent",SIGNATURE_STRUCTURE,INTEGER,
NULL);
T *link = _t_build(G_sem,0,PROCESS_LINK,
PROCESS_OF_STRUCTURE,INTEGER,PROCESS_TYPE,OPERATOR,
NULL_SYMBOL,NULL_SYMBOL
);
Process p = _d_define_process(G_sem,code,"power","takes the mathematical power of the two params",signature,link,TEST_CONTEXT);
spec_is_true(is_process(p));
spec_is_true(!is_symbol(p));
spec_is_equal(_t_children(defs),p.id);
T *s = _t_child(defs,p.id);
spec_is_str_equal(t2s(s),"(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))))");

Definition at line 302 of file def.c.