From: Thomas Walker Lynch Date: Sat, 5 Apr 2025 07:26:43 +0000 (+0000) Subject: checkpoint before xi -> cdot X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.js?a=commitdiff_plain;h=189d5b15777370d9f1d8af479f1cea7701acd937;p=N checkpoint before xi -> cdot --- diff --git "a/developer/cc\360\237\226\211/Binding.lib.c" "b/developer/cc\360\237\226\211/Binding.lib.c" index c1bad54..5684bbc 100644 --- "a/developer/cc\360\237\226\211/Binding.lib.c" +++ "b/developer/cc\360\237\226\211/Binding.lib.c" @@ -1,19 +1,22 @@ /* +Namespace: Binding +Template parameters: + + Binding - Type used to name the binding struct. Binding struct instances get passed as arguments to functions etc. + This files declares a binding struct named [Binding]. It also provides the macro `call` that uses the binding. Note this file does not make an instance of the binding, and does not intialize fields in an instance. -Template parameters: - Binding - Type used to name the binding struct. Binding struct instances get passed as arguments to functions etc. */ -//-------------------------------------------------------------------------------- -// Interface -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Interface +-------------------------------------------------------------------------------*/ // once per translation unit @@ -38,7 +41,7 @@ Template parameters: #define Binding·call(b, fn, ...) \ ( \ Binding·wellformed_binding(b) , \ - b.fg->fn(b.tableau __VA_OPT__(,) __VA_ARGS__) \ + b.fg->fn(b __VA_OPT__(,) __VA_ARGS__) \ ) #endif @@ -57,10 +60,10 @@ Template parameters: struct Ξ(Binding ,Tableau); typedef struct Ξ(Binding ,Tableau) Ξ(Binding ,Tableau); - typedef struct Ξ(Binding){ + typedef struct Binding{ Ξ(Binding ,Tableau) *tableau; Ξ(Binding ,FG) *fg; - } Ξ(Binding); + } Binding; static void Binding·wellformed_binding(Ξ(Binding) b){ #ifdef Binding·DEBUG @@ -75,25 +78,24 @@ Template parameters: #endif -//-------------------------------------------------------------------------------- -// Local - at bottom of translation unit, to keep some functions private -// Binding currently has no local component -//-------------------------------------------------------------------------------- - +/*-------------------------------------------------------------------------------- + Local - at bottom of translation unit, to keep some functions private + Binding currently has no local component +--------------------------------------------------------------------------------*/ #ifdef LOCAL #endif -//-------------------------------------------------------------------------------- -// Library - compiled into a lib.a file by the current make -// Binding has no library component -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Library - compiled into a lib.a file by the current make + Binding has no library component +--------------------------------------------------------------------------------*/ #ifdef LIBRARY #endif -//-------------------------------------------------------------------------------- -// undef the template parameters -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + undef the template parameters +-------------------------------------------------------------------------------*/ #undef Binding diff --git "a/developer/cc\360\237\226\211/Core.lib.c" "b/developer/cc\360\237\226\211/Core.lib.c" index 162b278..9ac6fca 100644 --- "a/developer/cc\360\237\226\211/Core.lib.c" +++ "b/developer/cc\360\237\226\211/Core.lib.c" @@ -16,9 +16,9 @@ */ -//-------------------------------------------------------------------------------- -// Interface -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ #ifndef Core·FACE #define Core·FACE @@ -136,9 +136,9 @@ #endif // #if CORE·FACE -//-------------------------------------------------------------------------------- -// Local - at bottom of translation unit, to keep some functions private -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Local - at bottom of translation unit, to keep some functions private + --------------------------------------------------------------------------------*/ #ifdef LOCAL // once per translation unit @@ -228,14 +228,14 @@ #endif // Core·LOCAL #endif // LOCAL -//-------------------------------------------------------------------------------- -// Library - compiled into a lib.a file by the current make -// Core currently has no library components -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Library - compiled into a lib.a file by the current make + Core currently has no library components +--------------------------------------------------------------------------------*/ #ifdef LIBRARY #endif -//-------------------------------------------------------------------------------- -// undef the template parameters -// Core currently has not template parameters -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + undef the template parameters + Core currently has not template parameters +--------------------------------------------------------------------------------*/ diff --git "a/developer/cc\360\237\226\211/TM.lib.c" "b/developer/cc\360\237\226\211/TM.lib.c" index ba2d80c..6763e5f 100644 --- "a/developer/cc\360\237\226\211/TM.lib.c" +++ "b/developer/cc\360\237\226\211/TM.lib.c" @@ -1,21 +1,19 @@ /* - TM - Tape Machine Model - - User must define the equivalence template: + Namespace: TM + Template parameters: - EQ_TM·__oo__TM· + `TM·CVT` Cell Value Type`. - While filling in the CVT values of course. For pointers, struct, arrays, etc. use a typedef to reduce the type to an identifier. + TM - Tape Machine Model - Template parameters - - `TM·CVT` Cell Value Type`. + Caller must declare TM set members: + #define SET__Binding__TM· // replacing with the actual value of CVT */ -//-------------------------------------------------------------------------------- -// Interface -//-------------------------------------------------------------------------------- +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ // once per translation unit #ifndef TM·FACE @@ -62,61 +60,56 @@ | TM·Head·Status·rightmost ; -#endif +#endif //#ifndef TM·FACE +// once per TM·CVT value +// Caller must #define SET__Binding__TM·, after inclusion, to prevent re-inclusion #ifdef TM·CVT -#if BOOLEAN(NOT_IN(TM·SET ,TM·CVT)) -#ifdef TM·CVT·DEBUG - #pragma message( "adding binding for:" STR_VAL(Binding) ) +#if BOOLEAN( NOT_IN(Binding ,Ξ(TM,TM·CVT)) ) +#ifdef TM·DEBUG + #pragma message( "Creating TM type with a CVT of:" STR_VAL(TM·CVT) ) #endif - // some synonyms to make this section easier to read - #undef TM - #define TM Ξ(TM ,TM·CVT) - #undef EXTENT_T - #define EXTENT_T Ξ(extent_t ,TM·CVT) - - // declare 'TM·CVT' as a type - // (or more specifically, make a struct for binding the FG table to the tableau) - #undef Binding·Type - #define Binding·Type TM + #define Binding Ξ(TM,TM·CVT) #include "Binding.lib.c" - // `extent_t` is an index, so element size matters, so I associate it with TM·CVT - typedef Ξ(extent_t ,TM·CVT) size_t; + typedef size_t Ξ(extent_t,TM·CVT); - typedef struct Ξ(TM ,FG){ + typedef struct Ξ(TM,TM·CVT,FG){ - TM·Tape·Topo (*Tape·topo)(TM tm); - bool (*Tape·bounded)(TM tm); + TM·Tape·Topo (*Tape·topo) ( Ξ(TM,TM·CVT) tm ); + bool (*Tape·bounded) ( Ξ(TM,TM·CVT) tm ); + Ξ(extent_t,TM·CVT) (*Tape·extent) ( Ξ(TM,TM·CVT) tm ); - TM·Head·Status (*Head·status)(TM tm); - bool (*Head·on_tape)(TM tm); - bool (*Head·on_leftmost) (TM tm); - bool (*Head·on_rightmost)(TM tm); + TM·Head·Status (*Head·status) ( Ξ(TM,TM·CVT) tm ); + bool (*Head·dismounted) ( Ξ(TM,TM·CVT) tm ); + bool (*Head·on_tape) ( Ξ(TM,TM·CVT) tm ); + bool (*Head·on_leftmost)( Ξ(TM,TM·CVT) tm ); + bool (*Head·on_rightmost)( Ξ(TM,TM·CVT) tm ); // tape machine functions - Core·Status (*mount) (TM tm); - Core·Status (*dismount)(TM tm); + void (*mount) ( Ξ(TM,TM·CVT) tm ); + void (*dismount) ( Ξ(TM,TM·CVT) tm ); - void (*step) (TM tm); - void (*step_left) (TM tm); - void (*rewind) (TM tm); + void (*step) ( Ξ(TM,TM·CVT) tm ); + void (*step_right) ( Ξ(TM,TM·CVT) tm ); + void (*step_left) ( Ξ(TM,TM·CVT) tm ); + void (*rewind) ( Ξ(TM,TM·CVT) tm ); - EXTENT_T (*extent)(TM tm); - TM·CVT (*read) (TM tm); - void (*write) (TM tm ,TM·CVT *remote_pt); + TM·CVT (*read) ( Ξ(TM,TM·CVT) tm ); + void (*write) ( Ξ(TM,TM·CVT) tm ,TM·CVT *remote_pt ); - } Ξ(TM ,FG); + } Ξ(TM,TM·CVT,FG); //---------------------------------------- // Array interface - #undef TM·ARRAY - #define TM·ARRAY Ξ(TM ,ARRAY) + #undef TM·ARRAY + #define TM·ARRAY Ξ(TM,TM·CVT,ARRAY) + + struct Ξ(TM,TM·CVT,ARRAY,Tableau); + typedef struct Ξ(TM,TM·CVT,ARRAY,Tableau) Ξ(TM,TM·CVT,ARRAY,Tableau); - struct Ξ(TM·ARRAY ,Tableau); - /* We assume that the binding produced by init is valid. Thus it does not have null pointers to the tableau or the fg table; it points to an initialized tableau; it points to a valid array fg table; and, that the fg table and tableau go together. @@ -125,172 +118,210 @@ The resulting binding object returned is what the user will call an instance of the type. */ - TM Ξ(TM·ARRAY ,init_pe)( - struct Ξ(TM·ARRAY ,Tableau) *t - ,TM·CVT position[] - ,EXTENT_T extent - ); - - TM Ξ(TM·ARRAY ,init_pp)( - Ξ(TM·ARRAY ,Tableau) *t - ,TM·CVT *position_left - ,TM·CVT *position_right - ); - -#endif - - -//-------------------------------------------------------------------------------- -// Local - at bottom of translation unit, to keep some functions private -//-------------------------------------------------------------------------------- + TM Ξ(TM,TM·CVT,ARRAY,init_pe)( + Ξ(TM,TM·CVT,ARRAY,Tableau) *t + ,TM·CVT position[] + ,Ξ(extent_t,TM·CVT) extent + ); + + TM Ξ(TM,TM·CVT,ARRAY,init_pp)( + Ξ(TM,TM·CVT,ARRAY,Tableau) *t + ,TM·CVT *position_left + ,TM·CVT *position_right + ); + +#endif // #if BOOLEAN( NOT_IN(Binding ,TM) ) +#endif // #ifdef TM·CVT + +/*-------------------------------------------------------------------------------- + Local +--------------------------------------------------------------------------------*/ #ifdef LOCAL -// once per translation unit -#ifndef TM·LOCAL·TYPE_LIST -#define TM·LOCAL·TYPE_LIST - - const char *TM·Msg·tm="given NULL tm"; - const char *TM·Msg·flag="given NULL flag pointer"; - const char *TM·Msg·result="given NULL result pointer"; - const char *TM·Msg·status="bad head status"; - -#endif - -// once per TM·CVT value -#ifdef TM·CVT -#if NOT_CONTAINS( TM·CVT ,TM·LOCAL·TYPE_LIST ) -#ifdef Binding·DEBUG - #pragma message( STR_VAL(TM·LOCAL·TYPE_LIST) ) -#endif + // once per translation unit + #ifndef TM·LOCAL + #define TM·LOCAL - //this is what it takes to append to a list in cpp ... - #undef TEMP - #define TEMP TM·LOCAL·TYPE_LIST ,TM·CVT - #undef TM·LOCAL·TYPE_LIST - #define TM·LOCAL·TYPE_LIST TEMP + const char *TM·Msg·tm = "given NULL tm"; + const char *TM·Msg·flag = "given NULL flag pointer"; + const char *TM·Msg·result = "given NULL result pointer"; + const char *TM·Msg·status = "bad head status"; - // some aliases to make things a little easier to read - #undef TM - #define TM Ξ(TM ,TM·CVT) - #undef EXTENT_T - #define EXTENT_T Ξ(extent_t ,TM·CVT) + #endif - //---------------------------------------- - // TM Array implementation, not TM·CVT differentiated - - // some aliases - #undef TM·ARRAY - #define TM·ARRAY Ξ(TM ,ARRAY) - - typedef struct Ξ(TM·ARRAY ,Tableau){ - TM·CVT *hd; - TM·CVT position[]; - EXTENT_T extent; - } Ξ(TM·ARRAY ,Tableau); - - - typedef struct Ξ(TM·ARRAY ,Tableau){ - TM·CVT *hd; - TM·CVT *position; - Ξ(extent_t ,TM·CVT) extent; - } Ξ(TM·Array ,TM·CVT)·Tableau; - - // with a direct interface, an array can implement three among the possible tape topologies - Local TM·Tape·Topo Ξ(TM·ARRAY ,Tape·topo)(TM tm){ - Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; - if(t->extent == 0) return TM·Tape·Topo·singleton; - return TM·Tape·Topo·segment; - } - Local bool Ξ(TM·ARRAY ,bounded)(TM tm){ - Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; - return Ξ(TM·ARRAY ,Tape·topo)(tm) & TM·Tape·Topo·bounded; - } - - Local TM·Head·Status Ξ(TM·ARRAY ,Head·status)(TM tm){ - Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; - if(!t->hd) return TM·Head·Status·dismounted; - if(t->hd == tm->position) return TM·Head·Status·leftmost; - - TM·CVT *rightmost_pt = t->position + t->extent; - if(t->hd == rightmost_pt) TM·Head·Status·rightmost; - if(t->hd < tm->position || tm->hd > rightmost_pt) - return TM·Head·Status·out_of_area; - - return TM·Head·Status·interim; - } - Local bool Ξ(TM·ARRAY ,Head·on_tape)(TM tm){ - Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; - return Ξ(TM·ARRAY ,Head·status)(tm) & TM·Head·Status·on_tape; - } - - - Ξ(TM ,FG) TM·ARRAY·fg = { - - } - - - TM Ξ(TM·ARRAY ,init_pe)( - struct Ξ(TM·ARRAY ,Tableau) *t - ,TM·CVT position[] - ,EXTENT_T extent - ); - - TM Ξ(TM·ARRAY ,init_pp)( - Ξ(TM·ARRAY ,Tableau) *t - ,TM·CVT *position_left - ,TM·CVT *position_right - ); - --- - TM·Tape·Topo TM·Array·Tape·mount(TM·Tableau *t){ - if(!t || !t->position) return T·Tape·Topo·mu; - if(t->extent == 0) TM·Tape·Topo·singleton; - return TM·Tape·Topo·segment; - } - - Local Ξ(extent_t ,TM·CVT) Ξ(TM ,TM·CVT)·extent(TM *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,TM·Tape·bounded(tm) ,"Tape is not bounded."); - Core·Guard·assert(chk); - #endif - return tm->fg.extent(tm); - } - - Local TM·CVT TM·read(TM *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check( &chk ,1 ,TM·head_on_tape(tm) ,TM·Msg·head); - Core·Guard·assert(chk); - #endif - return tm->fg.read(tm); - } - - Local void TM·write(TM *tm ,TM·CVT *write_pt){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check( &chk ,1 ,TM·head_on_tape(tm) ,TM·Msg·head); - Core·Guard·fg.check( &chk ,1 ,write_pt ,"Given NULL write_pt"); - Core·Guard·assert(chk); - #endif - return tm->fg.write(tm ,write_pt); - } - - Local Ξ(TM ,TM·CVT)·Binding Ξ(TM ,TM·CVT)·fg = { - .parent = TM·fg - ,.extent = Ξ(TM ,TM·CVT)·extent - ,.read = Ξ(TM ,TM·CVT)·read - ,.write = Ξ(TM ,TM·CVT)·write - }; - -#endif // ifdef TM·CVT -#undef TM·CVT + // once per TM·CVT value + // Caller must #define SET__TM·LOCAL__TM·, after inclusion, to prevent re-inclusion + #ifdef TM·CVT + #if BOOLEAN(NOT_IN(TM·LOCAL ,Ξ(TM,TM·CVT))) + #ifdef TM·DEBUG + #pragma message( "Including LOCAL code for:" STR_VAL(TM·CVT) ) + #endif -//-------------------------------------------------------------------------------- -// Library - compiled into a lib.a file by the current make -// Core currently has no library components -//-------------------------------------------------------------------------------- + /*------------------------------------------------------------------------ + Array implementation with a segment tape + */ + + typedef struct Ξ(TM,TM·CVT,ARRAY,Tableau){ + TM·CVT *hd; + TM·CVT position[]; + Ξ(extent_t,TM·CVT) extent; + } Ξ(TM,TM·CVT,ARRAY,Tableau); + + Local TM·Tape·Topo Ξ(TM,TM·CVT,ARRAY,Tape·topo)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + if( t->extent == 0 ) return TM·Tape·Topo·singleton; + return TM·Tape·Topo·segment; + } + + Local bool Ξ(TM,TM·CVT,ARRAY,Tape·bounded)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return Ξ(TM,TM·CVT,ARRAY,Tape·topo)( tm ) & TM·Tape·Topo·bounded; + } + + Local Ξ(extent_t,TM·CVT) Ξ(TM,TM·CVT,ARRAY,Tape·extent)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return t->extent; + } + + + Local TM·Head·Status Ξ(TM,TM·CVT,ARRAY,Head·status)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + if( !t->hd ) return TM·Head·Status·dismounted; + if( t->hd == tm->position ) return TM·Head·Status·leftmost; + + TM·CVT *rightmost_pt = t->position + t->extent; + if( t->hd == rightmost_pt ) return TM·Head·Status·rightmost; + if( t->hd < tm->position || t->hd > rightmost_pt ) + return TM·Head·Status·out_of_area; + + return TM·Head·Status·interim; + } + + Local bool Ξ(TM,TM·CVT,ARRAY,Head·dismounted)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return Ξ(TM,TM·CVT,ARRAY,Head·status)( tm ) & TM·Head·Status·dismounted; + } + + Local bool Ξ(TM,TM·CVT,ARRAY,Head·on_tape)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return Ξ(TM,TM·CVT,ARRAY,Head·status)( tm ) & TM·Head·Status·on_tape; + } + + Local bool Ξ(TM,TM·CVT,ARRAY,Head·on_leftmost)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return Ξ(TM,TM·CVT,ARRAY,Head·status)( tm ) & TM·Head·Status·leftmost; + } + + Local bool Ξ(TM,TM·CVT,ARRAY,Head·on_rightmost)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return Ξ(TM,TM·CVT,ARRAY,Head·status)( tm ) & TM·Head·Status·rightmost; + } + + // does nothing if the hd is already mounted + Local void Ξ(TM,TM·CVT,ARRAY,mount)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + if( !t->hd ) t->hd = t->position; + } + + Local void Ξ(TM,TM·CVT,ARRAY,dismount)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + t->hd = NULL; + } + + // does nothing if the hd is not mounted + Local void Ξ(TM,TM·CVT,ARRAY,step)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + t->hd++; + } + + Local void Ξ(TM,TM·CVT,ARRAY,step_left)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + t->hd--; + } + + Local void Ξ(TM,TM·CVT,ARRAY,rewind)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + if( Ξ(TM,TM·CVT,ARRAY,Head·dismounted)( tm ) ) return; + t->hd = t->position; + } + + Local TM·CVT Ξ(TM,TM·CVT,ARRAY,read)( Ξ(TM,TM·CVT) tm ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + return *t->hd; + } + + Local void Ξ(TM,TM·CVT,ARRAY,write)( Ξ(TM,TM·CVT) tm ,TM·CVT *remote_pt ){ + Ξ(TM,TM·CVT,ARRAY,Tableau) *t = (Ξ(TM,TM·CVT,ARRAY,Tableau) *) tm.tableau; + *remote_pt = *t->hd; + } + + Local TM·Binding Ξ(TM,TM·CVT,FG) Ξ(TM,TM·CVT,ARRAY,fg) = { + + .Tape·topo = Ξ(TM,TM·CVT,ARRAY,Tape·topo) + ,.Tape·bounded = Ξ(TM,TM·CVT,ARRAY,Tape·bounded) + ,.Tape·extent = Ξ(TM,TM·CVT,ARRAY,Tape·extent) + + ,.Head·status = Ξ(TM,TM·CVT,ARRAY,Head·status) + ,.Head·dismounted = Ξ(TM,TM·CVT,ARRAY,Head·dismounted) + ,.Head·on_tape = Ξ(TM,TM·CVT,ARRAY,Head·on_tape) + ,.Head·on_leftmost = Ξ(TM,TM·CVT,ARRAY,Head·on_leftmost) + ,.Head·on_rightmost= Ξ(TM,TM·CVT,ARRAY,Head·on_rightmost) + + ,.mount = Ξ(TM,TM·CVT,ARRAY,mount) + ,.dismount = Ξ(TM,TM·CVT,ARRAY,dismount) + + ,.step = Ξ(TM,TM·CVT,ARRAY,step) + ,.step_right = Ξ(TM,TM·CVT,ARRAY,step) + ,.step_left = Ξ(TM,TM·CVT,ARRAY,step_left) + ,.rewind = Ξ(TM,TM·CVT,ARRAY,rewind) + + ,.read = Ξ(TM,TM·CVT,ARRAY,read) + ,.write = Ξ(TM,TM·CVT,ARRAY,write) + + }; + + /* + tm is up casted from being array specific, to being generic. Later it is downcasted within the array code before being used. This can be seen at the top of each of the array specific function. This is the only loss of static type safety, and it is embedded in the library code. + */ + Ξ(TM,TM·CVT) Ξ(TM,TM·CVT,ARRAY,init_pe)( + Ξ(TM,TM·CVT,ARRAY,Tableau) *t + ,TM·CVT *position + ,Ξ(extent_t,TM·CVT) extent + ){ + t->hd = position; + t->position = position; + t->extent = extent; + + Ξ(TM,TM·CVT) tm = (Ξ(TM,TM·CVT)) { + .tableau = t + ,.fg = &Ξ(TM,TM·CVT,ARRAY,fg) + }; + + return tm; + } + + Ξ(TM,TM·CVT) Ξ(TM,TM·CVT,ARRAY,init_pp)( + Ξ(TM,TM·CVT,ARRAY,Tableau) *t + ,TM·CVT *position_left + ,TM·CVT *position_right + ){ + t->hd = position_left; + t->position = position_left; + t->extent = position_right - position_left; + } + + + + #endif // #if BOOLEAN(NOT_IN(TM·LOCAL ,TM)) + #endif // #ifdef TM·CVT + +#endif // LOCAL + +/*-------------------------------------------------------------------------------- + Library - compiled into a lib.a file by the current make + Core currently has no library components +--------------------------------------------------------------------------------*/ #ifdef LIBRARY #endif diff --git "a/developer/cc\360\237\226\211/cpp_ext.c" "b/developer/cc\360\237\226\211/cpp_ext.c" index 8f0cacd..54374fe 100644 --- "a/developer/cc\360\237\226\211/cpp_ext.c" +++ "b/developer/cc\360\237\226\211/cpp_ext.c" @@ -15,6 +15,6 @@ */ - #define Ξ(...) CAT(· ,__VA_ARGS__) + #define ·(...) CAT(· ,__VA_ARGS__) #endif diff --git "a/developer/cc\360\237\226\211/cpp_ext_0.c" "b/developer/cc\360\237\226\211/cpp_ext_0.c" index 0a8d334..81cd43e 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_0.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_0.c" @@ -20,9 +20,9 @@ #ifndef CPP_EXT_0 #define CPP_EXT_0 -/*=========================================================================== -DEBUG -===========================================================================*/ +/*--------------------------------------------------------------------------- + DEBUG +---------------------------------------------------------------------------*/ #include #define DEBUG_CPP @@ -37,9 +37,9 @@ DEBUG // print the macro and the evaluation of the macro at run time: #define SHOW(expr) printf("%s -> %s\n", #expr, STR(expr)); -/*=========================================================================== +/*--------------------------------------------------------------------------- Constants -===========================================================================*/ +---------------------------------------------------------------------------*/ #define NOTHING @@ -50,7 +50,7 @@ Constants #define _TWION_0 ~,0 #define _TWION_1 ~,1 -/*=========================================================================== +/*--------------------------------------------------------------------------- Fixed arg count concatenation Not implemented for elegance, rather CAT is used to force evaluation of arguments before `##`. @@ -65,7 +65,7 @@ Fixed arg count concatenation #define _CAT4(a ,b ,c ,d) a ## b ## c ## d #define CAT4(a ,b ,c ,d) _CAT4(a ,b ,c ,d) -/*=========================================================================== +/*--------------------------------------------------------------------------- LOGIC empty - false @@ -120,7 +120,7 @@ LOGIC // useful synonym #define MATCH_RWR(x) NOT(x) -/*=========================================================================== +/*--------------------------------------------------------------------------- IF-ELSE construct. Usage: IF_ELSE(condition)()() @@ -134,7 +134,7 @@ LOGIC #define _IF_1_ELSE(...) #define _IF__ELSE(...) __VA_ARGS__ -/*=========================================================================== +/*--------------------------------------------------------------------------- In cpp_ext logic: ε is false and anything else is true @@ -152,7 +152,7 @@ LOGIC #define BOOLEAN(...) IF(__VA_ARGS__) (1) (0) -/*=========================================================================== +/*--------------------------------------------------------------------------- Logic connectors */ #define LEQ2(x ,y) IF(x) (y) (NOT(y)) @@ -160,7 +160,7 @@ LOGIC #define AND2(x ,y) IF(x) (y) () #define OR2(x ,y) IF(x) (1) (y) -/*=========================================================================== +/*--------------------------------------------------------------------------- Set User must define set members manually: @@ -168,17 +168,17 @@ LOGIC For example a set named TRIP with 1 ,2 ,3 in it: - #define TRIP__1 - #define TRIP__2 - #define TRIP__3 + #define SET__TRIP__1 + #define SET__TRIP__2 + #define SET__TRIP__3 */ -#define IN(set ,x) NOT(CAT3(set ,__ ,x)) -#define NOT_IN(set ,x) CAT3(set ,__ ,x) +#define IN(name ,x) NOT(CAT4(SET__ ,name ,__ ,x)) +#define NOT_IN(name ,x) CAT4(SET__ ,name ,__ ,x) -/*=========================================================================== +/*--------------------------------------------------------------------------- Registered Equivalence Checks if x and y have been paired in a rewrite rule. @@ -199,7 +199,7 @@ LOGIC // without this, EQ(,) -> ε #define EQ____oo__ -===========================================================================*/ +---------------------------------------------------------------------------*/ // if empty should be EQ to empty, keep this // without this, EQ(,) -> ε @@ -210,9 +210,9 @@ LOGIC #define EQ(x_token ,y_token) MATCH_RWR( CAT4(EQ__ ,x_token ,__oo__ ,y_token) ) -/*=========================================================================== +/*--------------------------------------------------------------------------- Remainder of list -===========================================================================*/ +---------------------------------------------------------------------------*/ #define _REST(a ,...) __VA_ARGS__ #define REST(...)\ diff --git "a/developer/cc\360\237\226\211/cpp_ext_1.c" "b/developer/cc\360\237\226\211/cpp_ext_1.c" index ee69a22..788c57a 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_1.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_1.c" @@ -29,11 +29,11 @@ Instead of comma separated lists consider instead to make a list with #define: #ifndef CPP_EXT_1 #define CPP_EXT_1 -/*=========================================================================== +/*--------------------------------------------------------------------------- Force extra macro expansion (the EVAL trick) This chain of EVAL macros forces the preprocessor to perform many rescans, which is necessary to “unroll” recursive macros. -===========================================================================*/ +---------------------------------------------------------------------------*/ //#define EVAL(...) EVAL1024(__VA_ARGS__) #define EVAL(...) EVAL32(__VA_ARGS__) #define EVAL1024(...) EVAL512(EVAL512(__VA_ARGS__)) @@ -48,9 +48,9 @@ Instead of comma separated lists consider instead to make a list with #define: #define EVAL2(...) EVAL1(EVAL1(__VA_ARGS__)) #define EVAL1(...) __VA_ARGS__ -/*=========================================================================== +/*--------------------------------------------------------------------------- Defer macros: these help “hide” recursive calls for additional expansion passes. -===========================================================================*/ +---------------------------------------------------------------------------*/ // defined in cpp_ext_0: RETURN_NOTHING() #define DEFER1(m) \ @@ -64,7 +64,7 @@ Instead of comma separated lists consider instead to make a list with #define: #define DEFER5(m) \ m RETURN_NOTHING RETURN_NOTHING RETURN_NOTHING RETURN_NOTHING RETURN_NOTHING()()()()() -/*=========================================================================== +/*--------------------------------------------------------------------------- List operations number of EVALs required depends upon length list that is processed @@ -74,7 +74,7 @@ Instead of comma separated lists consider instead to make a list with #define: after the last comma. To assure that a tailing item always gets sent to the predicate, even when empty, we append an empty item. -===========================================================================*/ +---------------------------------------------------------------------------*/ // defined in cpp_ext_0: _FIRST(a ,...) a // returns found item or EOL() @@ -172,9 +172,9 @@ Instead of comma separated lists consider instead to make a list with #define: #define _APPEND_ss_CONFEDERATE() _APPEND_ss -/*=========================================================================== +/*--------------------------------------------------------------------------- Quantifiers -===========================================================================*/ +---------------------------------------------------------------------------*/ // AKA all quantification, returns true or false #define AND(...) WHILE(EXISTS ,__VA_ARGS__) @@ -182,9 +182,9 @@ Instead of comma separated lists consider instead to make a list with #define: // AKA existence quantification, returns true or false #define OR(...) NOT( WHILE(NOT ,__VA_ARGS__) ) -/*=========================================================================== +/*--------------------------------------------------------------------------- Access -===========================================================================*/ +---------------------------------------------------------------------------*/ #define FIRST(...) \ IF( __VA_ARGS__ ) \ diff --git "a/developer/cc\360\237\226\211/scatch.c" "b/developer/cc\360\237\226\211/scatch.c" index 98ab003..f8aed7d 100644 --- "a/developer/cc\360\237\226\211/scatch.c" +++ "b/developer/cc\360\237\226\211/scatch.c" @@ -1,13 +1,141 @@ + // some aliases to make things a little easier to read + #undef TM + #define TM Ξ(TM ,TM·CVT) + #undef EXTENT_T + #define EXTENT_T Ξ(extent_t ,TM·CVT) + //---------------------------------------- + // TM Array implementation, not TM·CVT differentiated + + // some aliases to make things a little easier to read + #undef TM + #define TM Ξ(TM ,TM·CVT) + #undef EXTENT_T + #define EXTENT_T Ξ(extent_t ,TM·CVT) + #undef TM·ARRAY + #define TM·ARRAY Ξ(TM ,ARRAY) + + typedef struct Ξ(TM·ARRAY ,Tableau){ + TM·CVT *hd; + TM·CVT position[]; + EXTENT_T extent; + } Ξ(TM·ARRAY ,Tableau); + + Local TM·Tape·Topo Ξ(TM·ARRAY ,Tape·topo)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + if(t->extent == 0) return TM·Tape·Topo·singleton; + return TM·Tape·Topo·segment; + } + Local bool Ξ(TM·ARRAY ,Tape·bounded)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return Ξ(TM·ARRAY ,Tape·topo)(tm) & TM·Tape·Topo·bounded; + } + Local EXTENT_T Ξ(TM·ARRAY ,Tape·extent)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return t->extent; + } + + Local TM·Head·Status Ξ(TM·ARRAY ,Head·status)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + if(!t->hd) return TM·Head·Status·dismounted; + if(t->hd == tm->position) return TM·Head·Status·leftmost; + + TM·CVT *rightmost_pt = t->position + t->extent; + if(t->hd == rightmost_pt) TM·Head·Status·rightmost; + if(t->hd < tm->position || tm->hd > rightmost_pt) + return TM·Head·Status·out_of_area; + + return TM·Head·Status·interim; + } + Local bool Ξ(TM·ARRAY ,Head·dismounted)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return Ξ(TM·ARRAY ,Head·status)(tm) & TM·Head·Status·dismounted; + } + Local bool Ξ(TM·ARRAY ,Head·on_tape)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return Ξ(TM·ARRAY ,Head·status)(tm) & TM·Head·Status·on_tape; + } + Local bool Ξ(TM·ARRAY ,Head·on_leftmost)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return Ξ(TM·ARRAY ,Head·status)(tm) & TM·Head·Status·leftmost; + } + Local bool Ξ(TM·ARRAY ,Head·on_rightmost)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return Ξ(TM·ARRAY ,Head·status)(tm) & TM·Head·Status·rightmost; + } + + // does nothing if the hd is already mounted + Local void Ξ(TM·ARRAY ,mount)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + if( !t->hd ) t->hd = t->position; + } + + Local void dismount Ξ(TM·ARRAY ,dismount)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + t->hd = NULL; + } + + // does nothing if the hd is not mounted + Local void Ξ(TM·ARRAY ,step)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + t->hd++; + } + + Local void Ξ(TM·ARRAY ,step_left)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + t->hd--; + } + Local void Ξ(TM·ARRAY ,rewind)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + Ξ(TM·ARRAY ,Head·dismounted)(tm) return; + t->hd = t->position; + } + + Local TM·CVT Ξ(TM·ARRAY ,read)(TM tm){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + return *t->hd; + } + Local void Ξ(TM·ARRAY ,write)(TM tm ,TM·CVT *remote_pt){ + Ξ(TM·ARRAY ,Tableau) *t = (Ξ(TM·ARRAY ,Tableau) *) tm.tableau; + *remote_pt = *t->hd; + } + + Local TM·Binding TM·fg = { + .Tape·topo = Ξ(TM·ARRAY ,Tape·topo) + ,.Tape·bounded = Ξ(TM·ARRAY ,Tape·bounded) + ,.Tape·extent = Ξ(TM·ARRAY ,Tape·extent) + ,.Head·status = Ξ(TM·ARRAY ,Head·status) + ,.Head·dismounted = Ξ(TM·ARRAY ,Head·dismounted) + ,.Head·on_tape = Ξ(TM·ARRAY ,Head·on_tape) + ,.Head·on_leftmost = Ξ(TM·ARRAY ,Head·on_leftmost) + ,.Head·on_rightmost = Ξ(TM·ARRAY ,Head·on_rightmost) + + ,.mount = Ξ(TM·ARRAY ,mount) + ,.dismount = Ξ(TM·ARRAY ,dismount) + + ,.step = Ξ(TM·ARRAY ,step) + ,.step_right = Ξ(TM·ARRAY ,step) + ,.step_left = Ξ(TM·ARRAY ,step_left) + ,.rewind = Ξ(TM·ARRAY ,rewind) + + ,.read = Ξ(TM·ARRAY ,read) + ,.write = Ξ(TM·ARRAY ,write) + + }; + + + +................................................................................ + //----------------------------------- // generic call wrappers @@ -66,24 +194,6 @@ //---------------------------------------- // Initialization for TM·fg - Local TM·Binding TM·fg = { - .Tape·topo = TM·Tape·topo - ,.Tape·bounded = TM·Tape·bounded - ,.Head·status = TM·Head·status - ,.Head·on_tape = TM·Head·on_tape - - ,.Head·on_leftmost = TM·Head·on_leftmost - ,.Head·on_rightmost = TM·Head·on_rightmost - - ,.mount = TM·mount - ,.dismount = TM·dismount - - ,.step = TM·step - ,.step_left = TM·step_left - ,.step_right = TM·step // Synonym - ,.rewind = TM·rewind - - }; #endif // ifndef TM·CVT diff --git "a/developer/document\360\237\226\211/C_features_needed.org" "b/developer/document\360\237\226\211/C_features_needed.org" index ae7f77f..ca3bee2 100644 --- "a/developer/document\360\237\226\211/C_features_needed.org" +++ "b/developer/document\360\237\226\211/C_features_needed.org" @@ -1,29 +1,53 @@ -1. C needs namespaces. The '·' notation seems to accomplish most of what is needed, and I'm doing this in existing C. Scoped 'using' would be nice for shortening the identifiers. +1. Cpp needs namespaces. The '·' notation seems to accomplish most of what is needed, and I'm doing this in existing C. Scoped 'using' would be nice for shortening the identifiers. This can be done without changing the tool chain. -2. control of evaluation in definitions + I am currently using, e.g.: - Currently definitions remain literal text. + Ξ(TM ,TM·CVT ,ARRAY ,Tape·bounded) - Also #reassign assignment to a name an definition, possible with expansion and - using the same macro name taken with its older definition. Selective expansion - in definitions also needed. + This could be: - Without namespaces I can see the problem with developers stepping on each others's macro ames. However, with namespaces it seems that #redefine, or #redef is tractable. + #with Ξ(TM ,TM·CVT ,ARRAY): + ... + ·Tape·bounded = ... + ... + #endwith -3. Something should be done about macros having to be on one line and having to account for, format, all those \. Perhaps an emacs mode similar as used for paragraphs? Anyway something should be done. + I.e. set the prefix, then for identifiers starting with · set the prefix. `with` + can be nested. -4. ability to declare a type hierarchy based on struct types having the same field - names and format, or extensions thereof. + Also native #cat and #Ξ .. perhaps operators + + If the center dot delineated tokens, then we would not need the Ξ function. + +2. cpp control of evaluation in definitions + + #assign name·#eval(space) #eval(body) + + Temporal assignment. Eval, then define. + + Allows defining a macro while using eval in both the name and body. eval happens + once, and the name is not available to be used in the body. + +3. cpp existence logic + +4. Something should be done about macros having to be on one line and having to account for, format, all those \. Perhaps an emacs mode similar as used for paragraphs? Anyway something should be done. + + #begin + #define ... + ... + ... + #end + +5. C type system, ability to declare a type hierarchy based on struct types having the same field names and format, or extensions thereof. typehier pair -> vector-2d -> complex Something like that. -5. compiler switch to put the struct etc. types into the same space with the others. of course. - +6. C type system, put struct, enum types into the same space with the other types. of course. -6. ability to use a macro to define a macro name. first create a value, then - call a function to enter it into the symbol table. +7. A better emacs C formatter + diff --git a/developer/example/bespoke.c b/developer/example/bespoke.c new file mode 100644 index 0000000..ed9816c --- /dev/null +++ b/developer/example/bespoke.c @@ -0,0 +1,103 @@ +/* + This will print at compile time as: + + example/custom_type.cli.c:6:9: note: ‘#pragma message: C -> 7’ + 6 | #pragma message( STR_VAL(C) ) + | ^~~~~~~ + + Note the C->7 on the right side of the first line. That printed + the name of the macro, and its value. This is a 'note' not an 'error'. +*/ + +#include "cpp_ext.c" +#include "Core.lib.c" +#include "Binding.lib.c" + +/* + This defines the Bespoke type. + + Here by 'type' we mean a Tableau to FG table binding. +*/ + + #define Binding Bespoke + #include "Binding.lib.c" + #define SET__Binding__Bespoke + + // This defines the FG table type for Bespoke (aka vtable). Each instance is a different implementation of the type sharing the same interface. + typedef struct Bespoke·FG{ + void (*version)(Bespoke tm); + void (*report)(Bespoke tm ,char *mess); + }Bespoke·FG; + + // This defines the Tableau, the data that is given as a first argument of each FG table entry. + typedef struct Bespoke·Tableau{ + + }Bespoke·Tableau; + + // This creates a FG table to Tableau binding type. We will use this to represent the type. + // The EQ pattern is required for `FIND_ITEM` to recognize the type: + + // these functions will be used for making an instance of the abstract Bespoke type + + void Bespoke·version(Bespoke tm){ printf("version 1.0\n"); }; + void Bespoke·report(Bespoke tm ,char *mess){ printf("The report: %s\n" ,mess);}; + + +int main(){ + + printf("running example binding.cli.c on %s at %s\n", __DATE__, __TIME__); + + SHOW(Ξ(Binding·TYPE ,FG)); + + #define A 5 + SHOW(A); + + #define B Ξ(X,Y) + SHOW(B); + + // one FG table will be shared by many instances of Bespoke, maybe all of them + Bespoke·FG fg = { + .version = Bespoke·version + ,.report = Bespoke·report + }; + + // The Bespoke·Tableau carries the instance data', often is one to one to a binding. + Bespoke·Tableau t; + + // allocate a binding + Bespoke spoke; + + // Initialize the binding, this the job of a type specific init function. + // in C we don't know where the user is allocating the data, otherwise we would + // have a factory instead of an initializer. + spoke.fg = &fg; + spoke.tableau = &t; + + // direct use of the fg table, the user/programmer should not do this + fg.version(spoke); + fg.report(spoke ,"fg.report"); + + // does the binding have null pointers? + printf("fg: %p, tableau: %p\n", (void*)spoke.fg, (void*)spoke.tableau); + + // calling though the binding + spoke.fg->version(spoke); + spoke.fg->report(spoke ,"spoke.fg->report"); + + printf("and version again\n"); + spoke.fg->version(spoke); + printf("before Binding·call to version\n"); + Binding·call(spoke ,version); + printf("after Binding·call to version.\n"); + + printf("before Binding·call to report\n"); + Binding·call(spoke ,report ,"Binding·call to report"); + printf("after Binding·call to report\n"); + + return 0; +} + +#define LOCAL +#include "Core.lib.c" + + diff --git a/developer/example/bespoke_type.cli.c b/developer/example/bespoke_type.cli.c deleted file mode 100644 index a4774f3..0000000 --- a/developer/example/bespoke_type.cli.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - This will print at compile time as: - - example/custom_type.cli.c:6:9: note: ‘#pragma message: C -> 7’ - 6 | #pragma message( STR_VAL(C) ) - | ^~~~~~~ - - Note the C->7 on the right side of the first line. That printed - the name of the macro, and its value. This is a 'note' not an 'error'. -*/ - -#include "cpp_ext.c" -#include "Core.lib.c" -#include "Binding.lib.c" - -/* - This defines the Bespoke type. - - Here by 'type' we mean a Tableau to FG table binding. -*/ - - #define Binding Bespoke - #include "Binding.lib.c" - #define Binding·SET·Bespoke - - // This defines the FG table type for Bespoke (aka vtable). Each instance is a different implementation of the type sharing the same interface. - typedef struct Bespoke·FG{ - void (*version)(Bespoke·Tableau *t); - void (*report)(Bespoke·Tableau *t ,char *mess); - }Bespoke·FG; - - // This defines the Tableau, the data that is given as a first argument of each FG table entry. - typedef struct Bespoke·Tableau{ - - }Bespoke·Tableau; - - // This creates a FG table to Tableau binding type. We will use this to represent the type. - // The EQ pattern is required for `FIND_ITEM` to recognize the type: - - // these functions will be used for making an instance of the abstract Bespoke type - - void Bespoke·version(Bespoke·Tableau *t){ printf("version 1.0\n"); }; - void Bespoke·report(Bespoke·Tableau *t ,char *mess){ printf("The report: %s\n" ,mess);}; - - -int main(){ - - printf("running example binding.cli.c on %s at %s\n", __DATE__, __TIME__); - - SHOW(Ξ(Binding·TYPE ,FG)); - - #define A 5 - SHOW(A); - - #define B Ξ(X,Y) - SHOW(B); - - // one FG table will be shared by many instances of Bespoke, maybe all of them - Bespoke·FG fg = { - .version = Bespoke·version - ,.report = Bespoke·report - }; - - // The Bespoke·Tableau carries the instance data', often is one to one to a binding. - Bespoke·Tableau t; - - // allocate a binding - Bespoke spoke; - - // Initialize the binding, this the job of a type specific init function. - // in C we don't know where the user is allocating the data, otherwise we would - // have a factory instead of an initializer. - spoke.fg = &fg; - spoke.tableau = &t; - - // direct use of the fg table, the user/programmer should not do this - fg.version(spoke.tableau); - fg.report(spoke.tableau ,"fg.report"); - - // does the binding have null pointers? - printf("fg: %p, tableau: %p\n", (void*)spoke.fg, (void*)spoke.tableau); - - // calling though the binding - spoke.fg->version(spoke.tableau); - spoke.fg->report(spoke.tableau ,"spoke.fg->report"); - - printf("and version again\n"); - spoke.fg->version(spoke.tableau); - printf("before Binding·call to version\n"); - Binding·call(spoke ,version); - printf("after Binding·call to version.\n"); - - printf("before Binding·call to report\n"); - Binding·call(spoke ,report ,"Binding·call to report"); - printf("after Binding·call to report\n"); - - return 0; -} - -#define LOCAL -#include "Core.lib.c" - - diff --git a/developer/example/holder/try_TM_1.cli.c b/developer/example/holder/try_TM_1.cli.c deleted file mode 100644 index 1851978..0000000 --- a/developer/example/holder/try_TM_1.cli.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - try_TM.cli.c - Example use of TM·AU type with array backend. -*/ - -#include "cpp_ext.c" -#include "Core.lib.c" -#include "Binding.lib.c" -#include "TM.lib.c" - -#define EQ__TM·AU__oo__TM·AU -#define TM·CVT AU -#include "TM.lib.c" - -int main(){ - - printf("running try_TM.cli.c on %s at %s\n", __DATE__, __TIME__); - - SHOW(Ξ(TM·CVT ,FG)); // TM·AU·FG - SHOW(Ξ(TM·CVT ,Tableau)); // TM·AU·Tableau - - // Create a tape with 5 AU values - AU tape[] = {1 ,2 ,3 ,4 ,5}; - extent_t·AU extent = sizeof(tape) - 1; - - // Init the tableau - Ξ(TM ,AU)·Tableau t; - Ξ(TM ,AU)·init_pe(&t ,tape ,extent); - - // Allocate a binding - TM·AU tm; - tm.fg = &Ξ(TM ,AU)·fg; - tm.tableau = &t; - - // Call version of the TM status - printf("Before any operations:\n"); - Binding·call(tm ,rewind); - - AU datum = Binding·call(tm ,read); - printf("Initial datum: %u\n", datum); - - // Step and read again - Binding·call(tm ,step); - datum = Binding·call(tm ,read); - printf("After step, datum: %u\n", datum); - - // Write a new value - AU value = 99; - Binding·call(tm ,write ,&value); - - // Rewind and read again - Binding·call(tm ,rewind); - datum = Binding·call(tm ,read); - printf("After rewind, datum: %u\n", datum); - - return 0; -} - -#define LOCAL -#include "Core.lib.c" -#include "Binding.lib.c" -#include "TM.lib.c" diff --git a/developer/example/try_TM_1.cli.c b/developer/example/try_TM_1.cli.c new file mode 100644 index 0000000..24dde34 --- /dev/null +++ b/developer/example/try_TM_1.cli.c @@ -0,0 +1,64 @@ +/* + try_TM.cli.c - Example use of TM·AU type with array backend. +*/ + +#include "cpp_ext.c" +#include "Core.lib.c" +#include "Binding.lib.c" +#include "TM.lib.c" + +#define TM·CVT AU +#include "TM.lib.c" +#define SET__Binding__TM·AU + +int main(){ + printf("running try_TM.cli.c on %s at %s\n", __DATE__, __TIME__); + + SHOW(Ξ(TM·CVT ,FG)); // TM·AU·FG + SHOW(Ξ(TM·CVT ,Tableau)); // TM·AU·Tableau + + // Create a tape with 5 AU values + AU tape[] = {1 ,2 ,3 ,4 ,5}; + extent_t·AU extent = sizeof(tape) - 1; + + // Init the tableau +#if 0 + + Ξ(TM ,AU)·Tableau t; + Ξ(TM ,AU)·init_pe(&t ,tape ,extent); + + + // Allocate a binding + TM·AU tm; + tm.fg = &Ξ(TM ,AU)·fg; + tm.tableau = &t; + + // Call version of the TM status + printf("Before any operations:\n"); + Binding·call(tm ,rewind); + + AU datum = Binding·call(tm ,read); + printf("Initial datum: %u\n", datum); + + // Step and read again + Binding·call(tm ,step); + datum = Binding·call(tm ,read); + printf("After step, datum: %u\n", datum); + + // Write a new value + AU value = 99; + Binding·call(tm ,write ,&value); + + // Rewind and read again + Binding·call(tm ,rewind); + datum = Binding·call(tm ,read); + printf("After rewind, datum: %u\n", datum); + +#endif + return 0; +} + +#define LOCAL +#include "Core.lib.c" +#include "Binding.lib.c" +#include "TM.lib.c"