From: Thomas Walker Lynch Date: Fri, 28 Mar 2025 16:30:33 +0000 (+0000) Subject: back to working on TM X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.css?a=commitdiff_plain;h=d237ae3b70f72d4f2bd438e71f30b9ba04926614;p=N back to working on TM --- diff --git "a/developer/cc\360\237\226\211/FG.lib.c" "b/developer/cc\360\237\226\211/FG.lib.c" index 566460e..6d659fa 100644 --- "a/developer/cc\360\237\226\211/FG.lib.c" +++ "b/developer/cc\360\237\226\211/FG.lib.c" @@ -1,12 +1,14 @@ /* Template parameters: -FG·Type - Type of FG table, will be used to name the binding struct. + FG·Type - Type used to name the binding struct. Binding struct instances get passed as arguments to functions etc. -Note that template variables are _use once_ per #include. (They are #undef at the bottom of this file.) +Template variables are _use once_ per #include. (They are #undef at the bottom of this file.) */ +#include "cpp_ext.c" + #ifndef FACE #define FG·IMPLEMENTATION #define FACE @@ -15,60 +17,50 @@ Note that template variables are _use once_ per #include. (They are #undef at th //-------------------------------------------------------------------------------- // Interface -#ifndef Ξ(FG·FACE ,FG·Type) -#define Ξ(FG·FACE ,FG·Type) - +// once per translation unit +#ifndef FG·TYPE_LIST +#define FG·TYPE_LIST #define FG·DEBUG #ifdef FG·DEBUG #include #endif - #define FG·ALL ( defined(FG·Type) ) - #define FG·NONE ( !defined(FG·Type) ) - #if !( FG·ALL || FG·NONE ) - #error "FG template inconsistency: must define all or none of: FG·Type" - #endif - - //---------------------------------------- - // Macro to call a function in the FG table with debug checks - // Usage: FG·call(tm, function_name, arg1, arg2, ...) - // Expands to: (tm.fg->function_name)((tm)->t, arg1, arg2, ...) - // With debug checks for NULL pointers when FG·DEBUG is defined - //---------------------------------------- - #if FG·ALL - - //#define ALL_VAL V0··V1··V2 ... - // the double cdot underscore non aliasing across identifiers - #define FG·ALL_VAL FG·Type - // FG is not yet a type, so we don't have this - // #define FG_t Ξ(FG_t ,FG·ALL_VAL) - - // a simplifying naming convention - #define FG·Binding Ξ(FG·Type) - #define FG·FG Ξ(FG·Type ,FG) - #define FG·Tableau Ξ(FG·Type ,Tableau) - - // as a convention, we name the binding after the type - typedef struct{ - FG·FG *fg; - FG·Tableau *tableau; - } FG·Binding; - - inline void FG·wellformed_binding(FG·Binding b){ - #ifdef FG·DEBUG - FG·Guard·init_count(chk); - FG·Guard·fg.check(&chk, 1, b.fg, "NULL fg table"); - FG·Guard·fg.check(&chk, 1, b.tableau, "NULL tableau"); - FG·Guard·assert(chk); - #endif - } - - // note the use of the comma operator to return the result from the b.fg->fn call - #define FG·call(b, fn, ...) \ - ( FG·wellformed_binding(b) ,b.fg->fn(b.tableau, ##__VA_ARGS__) ) - - #endif +#endif + +// once per FG·TYPE value +#if ! FIND_ITEM( FG·TYPE ,FG·TYPE_LIST ) +#define FG·TYPE_LIST APPEND(FG·TYPE_LIST ,FG·TYPE) + + // a simplifying naming convention + #define FG·Binding Ξ(FG·Type) + #define FG·FG Ξ(FG·Type ,FG) + #define FG·Tableau Ξ(FG·Type ,Tableau) + + // as a convention, we name the binding after the type + typedef struct{ + FG·FG *fg; + FG·Tableau *tableau; + } FG·Binding; + + // binds a tableau and FG tabel instance together + inline void FG·wellformed_binding(FG·Binding b){ + #ifdef FG·DEBUG + FG·Guard·init_count(chk); + FG·Guard·fg.check(&chk, 1, b.fg, "NULL fg table"); + FG·Guard·fg.check(&chk, 1, b.tableau, "NULL tableau"); + FG·Guard·assert(chk); + #endif + } + + /* + usage e.g.: FG·call(tm, function_name, arg1, arg2, ...) + Expands to: (tm.fg->function_name)((tm)->t, arg1, arg2, ...) + + note the use of the comma operator to return the result from the b.fg->fn call + */ + #define FG·call(b, fn, ...) \ + ( FG·wellformed_binding(b) ,b.fg->fn(b.tableau, ##__VA_ARGS__) ) #endif // FACE diff --git "a/developer/cc\360\237\226\211/TM.lib.c" "b/developer/cc\360\237\226\211/TM.lib.c" index f748db6..3c49c35 100644 --- "a/developer/cc\360\237\226\211/TM.lib.c" +++ "b/developer/cc\360\237\226\211/TM.lib.c" @@ -1,165 +1,126 @@ /* TM - Tape Machine - This file has the template parameter: `CVT` - - `CVT` Cell Value Type`. It is the type of the datum placed in a cell. By default (when the macro CVT has no definition) the cell value type is taken as AUM. This file must - be included with CVT undefined ,before inclusions with it defined. - - 'Tape' is operated on by the Tape Machine. - - 'Area' is subset of an address space that is used as a virtual Tape by a machine. - - An Area with zero elements has 'length == 0' or is 'empty'. In contrast ,and - area located (position specified) with a null pointer is said not to exist. - - ---- - - CVT is a template variable that affects type names that show on the interface. - They affect all implementations in the same way. - - There are multiple implementations, such as Array. Each has its own FG - table instance. For example Array·fg. Also each has its own Tableau type, for - example, `typedef struct { ... } Ξ(TM·Array ,CVT)` is the Tableau type for - the array implementation. - - This implementation uses pointer pairs to stand for 'TM type' that are - passed around. + `TM·CVT` Cell Value Type`. */ -#define TM·DEBUG -#ifdef TM·DEBUG - #include -#endif - -#define TM·ALL ( defined(CVT) ) // ... && defined( ... -#define TM·NONE ( !defined(CVT) ) -#if !( TM·ALL || TM·NONE ) - #error "TM template inconsistency: must define all or none of: CVT" -#endif - #ifndef FACE #define TM·IMPLEMENTATION #define FACE #endif //-------------------------------------------------------------------------------- -// Interface - always included - -#if TM·ALL - #define TM·ALL_VAL = CVT - #define TM_t Ξ(TM ,TM·ALL_VAL) -#endif +// Interface -#ifndef Ξ(TM ,FACE) -#define Ξ(TM ,FACE) +// once per translation unit +#ifndef TM·TYPE_LIST +#define TM·TYPE_LIST - #include #include + #include "cpp_ext.c" #include "Core.lib.c" #include "FG.lib.c" - //---------------------------------------- - // Tape Machine interface - //---------------------------------------- + #define TM·DEBUG + #ifdef TM·DEBUG + #include + #endif - #if TM·NONE - typedef enum{ - TM·Tape·Topo·mu = 0 - ,TM·Tape·Topo·empty = 1 - ,TM·Tape·Topo·singleton = 1 << 1 - ,TM·Tape·Topo·segment = 1 << 2 - ,TM·Tape·Topo·circle = 1 << 3 - ,TM·Tape·Topo·tail_cyclic = 1 << 4 - ,TM·Tape·Topo·infinite = 1 << 5 - }TM·Tape·Topo; - - const TM·Tape·Topo TM·Tape·Topo·bounded = - TM·Tape·Topo·singleton - | TM·Tape·Topo·segment - ; - - // If tape machine does not support step left ,then Status·leftmost - // will be reported as Status·interim. - typedef enum{ - TM·Head·Status·mu = 0 - ,TM·Head·Status·dismounted = 1 - ,TM·Head·Status·out_of_area = 1 << 1 - ,TM·Head·Status·leftmost = 1 << 2 - ,TM·Head·Status·interim = 1 << 3 - ,TM·Head·Status·rightmost = 1 << 4 - } TM·Head·Status; - - const TM·Head·Status TM·Head·Status·on_tape = - TM·Head·Status·leftmost - | TM·Head·Status·interim - | TM·Head·Status·rightmost - ; - - #endif // #ifndef CVT - - #if TM·All - - // TM··Tableau - typedef struct Ξ(TM ,Tableau); - - // create an FG·Binding so that FG·call will work - #define FG·Type TM - #include "FG.lib.c" - #undef FG·Type - - // extent is an index, hence its effect is a function of CVT - typedef Ξ(extent_t ,CVT) size_t; - - typedef struct{ - - TM·Tape·Topo (*Tape·topo)(TM tm); - bool (*Tape·bounded)(TM 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); - - // tape machine functions - Core·Status (*mount) (TM tm); - Core·Status (*dismount)(TM tm); - - void (*step) (TM tm); - void (*step_left) (TM tm); - void (*rewind) (TM tm); - - TM·FG TM·fg; // points to TM·FG instance - Ξ(extent_t ,CVT) (*extent)(TM tm); - CVT (*read) (TM tm); - void (*write)(TM tm ,CVT *remote_pt); - - } Ξ(TM ,FG); + typedef enum{ + TM·Tape·Topo·mu = 0 + ,TM·Tape·Topo·empty = 1 + ,TM·Tape·Topo·singleton = 1 << 1 + ,TM·Tape·Topo·segment = 1 << 2 + ,TM·Tape·Topo·circle = 1 << 3 + ,TM·Tape·Topo·tail_cyclic = 1 << 4 + ,TM·Tape·Topo·infinite = 1 << 5 + }TM·Tape·Topo; + const TM·Tape·Topo TM·Tape·Topo·bounded = + TM·Tape·Topo·singleton + | TM·Tape·Topo·segment + ; + + typedef enum{ + TM·Head·Status·mu = 0 + ,TM·Head·Status·dismounted = 1 + ,TM·Head·Status·out_of_area = 1 << 1 + ,TM·Head·Status·leftmost = 1 << 2 + ,TM·Head·Status·interim = 1 << 3 + ,TM·Head·Status·rightmost = 1 << 4 + } TM·Head·Status; + + const TM·Head·Status TM·Head·Status·on_tape = + TM·Head·Status·leftmost + | TM·Head·Status·interim + | TM·Head·Status·rightmost + ; + + // set type equality pattern + #define EQ__TM__oo__TM - //---------------------------------------- - // Array interface - //---------------------------------------- +#endif + +// once per TM·CVT value +#if ! FIND_ITEM( TM·CVT ,TM·TYPE_LIST ) +#define TM·TYPE_LIST APPEND(TM·TYPE_LIST ,TM·TYPE) + + // TM··Tableau + typedef struct Ξ(TM ,Tableau); + + // bind the tableau to an FG table, call the binding a 'TM' type + #define FG·Type TM + #include "FG.lib.c" + + // extent is an index, hence its effect is a function of TM·CVT + typedef Ξ(extent_t ,TM·CVT) size_t; + + typedef struct{ + + TM·Tape·Topo (*Tape·topo)(TM tm); + bool (*Tape·bounded)(TM tm); - typedef struct Ξ(TM ,Array)·Tableau; - - TM Ξ(TM ,Array)·init_pe( - Ξ(TM ,Array)·Tableau *t - ,CVT position[] - ,Ξ(extent_t ,CVT) extent - ); + 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 Ξ(TM ,Array)·init_pp( - Ξ(TM ,Array)·Tableau *t - ,CVT *position_left - ,CVT *position_right - ); + // tape machine functions + Core·Status (*mount) (TM tm); + Core·Status (*dismount)(TM tm); - #endif // #ifdef CVT + void (*step) (TM tm); + void (*step_left) (TM tm); + void (*rewind) (TM tm); -#endif // FACE + TM·FG TM·fg; // points to TM·FG instance + Ξ(extent_t ,TM·CVT) (*extent)(TM tm); + TM·CVT (*read) (TM tm); + void (*write)(TM tm ,TM·CVT *remote_pt); + + } Ξ(TM ,FG); + + //---------------------------------------- + // Array interface + //---------------------------------------- + + typedef struct Ξ(TM ,Array)·Tableau; + + TM Ξ(TM ,Array)·init_pe( + Ξ(TM ,Array)·Tableau *t + ,TM·CVT position[] + ,Ξ(extent_t ,TM·CVT) extent + ); + + TM Ξ(TM ,Array)·init_pp( + Ξ(TM ,Array)·Tableau *t + ,TM·CVT *position_left + ,TM·CVT *position_right + ); + +#endif //-------------------------------------------------------------------------------- // Implementation @@ -177,7 +138,7 @@ // Dispatch wrapper //---------------------------------------- - #ifndef CVT + #ifndef TM·CVT //----------------------------------- // common error messages @@ -266,14 +227,14 @@ }; - #endif // ifndef CVT + #endif // ifndef TM·CVT //----------------------------------- - // CVT dependent functions + // TM·CVT dependent functions - #ifdef CVT + #ifdef TM·CVT - Local Ξ(extent_t ,CVT) Ξ(TM ,CVT)·extent(TM *tm){ + 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."); @@ -282,7 +243,7 @@ return tm->fg.extent(tm); } - Local CVT TM·read(TM *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); @@ -291,7 +252,7 @@ return tm->fg.read(tm); } - Local void TM·write(TM *tm ,CVT *write_pt){ + 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); @@ -301,14 +262,14 @@ return tm->fg.write(tm ,write_pt); } - Local Ξ(TM ,CVT)·FG Ξ(TM ,CVT)·fg = { + Local Ξ(TM ,TM·CVT)·FG Ξ(TM ,TM·CVT)·fg = { .parent = TM·fg - ,.extent = Ξ(TM ,CVT)·extent - ,.read = Ξ(TM ,CVT)·read - ,.write = Ξ(TM ,CVT)·write + ,.extent = Ξ(TM ,TM·CVT)·extent + ,.read = Ξ(TM ,TM·CVT)·read + ,.write = Ξ(TM ,TM·CVT)·write }; - #endif // ifdef CVT + #endif // ifdef TM·CVT //---------------------------------------- @@ -333,7 +294,7 @@ // TM·Array implementation //---------------------------------------- - #ifndef CVT + #ifndef TM·CVT //----------------------------------- // common error messages @@ -344,27 +305,27 @@ const char *TM·Array·Msg·status="bad head status"; - #endif // #ifndef CVT + #endif // #ifndef TM·CVT - #ifdef CVT + #ifdef TM·CVT - typedef struct Ξ(TM ,CVT)·Tableau; + typedef struct Ξ(TM ,TM·CVT)·Tableau; typedef struct{ - CVT *hd; - CVT *position; - Ξ(extent_t ,CVT) extent; - }Ξ(TM·Array ,CVT)·Tableau; + TM·CVT *hd; + TM·CVT *position; + Ξ(extent_t ,TM·CVT) extent; + }Ξ(TM·Array ,TM·CVT)·Tableau; //----------------------------------- // TM·Array.tape implementation //---------------------------------------- - // TM Array implementation, not CVT differentiated + // TM Array implementation, not TM·CVT differentiated - Local TM·Tape·Topo TM·Array·Tape·topo( Ξ(TM ,CVT)·Tableau *tableau ){ - Ξ(TM·Array ,CVT)·Tableau *t = (Ξ(TM·Array ,CVT)·Tableau *)tableau; + Local TM·Tape·Topo TM·Array·Tape·topo( Ξ(TM ,TM·CVT)·Tableau *tableau ){ + Ξ(TM·Array ,TM·CVT)·Tableau *t = (Ξ(TM·Array ,TM·CVT)·Tableau *)tableau; if(!t || !t->position) return T·Tape·Topo·mu; if(t->extent == 0) TM·Tape·Topo·singleton; return TM·Tape·Topo·segment; @@ -380,19 +341,19 @@ } // For an Array Tape Machine ,a bound tape will be singleton or segment. - TM·Tape·Topo Ξ(TM·Array ,CVT)·Tape·topo(Ξ(TM·Array ,CVT) *tm){ + TM·Tape·Topo Ξ(TM·Array ,TM·CVT)·Tape·topo(Ξ(TM·Array ,TM·CVT) *tm){ if(!tm || !tm->position) return TM·Tape·Topo·mu; if(tm->extent == 0) TM·Tape·Topo·singleton; return TM·Tape·Topo·segment; } // check the Tape·topo to make sure tape has extent before calling this - // `extent·CVT` returns the index to the rightmost cell in the array. - Local Ξ(extent_t ,CVT) Ξ(TM·Array ,CVT)·extent(Ξ(TM·Array ,CVT) *tm){ + // `extent·TM·CVT` returns the index to the rightmost cell in the array. + Local Ξ(extent_t ,TM·CVT) Ξ(TM·Array ,TM·CVT)·extent(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); Core·Tape·Topo Tape·topo = Core·Tape·Topo·mu; - Core·Status status = Ξ(TM·Array ,CVT)·Tape·topo(tm ,&Tape·topo); + Core·Status status = Ξ(TM·Array ,TM·CVT)·Tape·topo(tm ,&Tape·topo); bool good_Tape·topo = (status == Core·Status·on_track) && (Tape·topo & Core·Tape·Topo·finite_nz) ; @@ -407,8 +368,8 @@ //----------------------------------- // TM·Array.area implementation - Local Core·Status Ξ(TM·Array ,CVT)·mount_pe( - Ξ(TM·Array ,CVT) *tm ,CVT *position ,Ξ(extent_t ,CVT) extent + Local Core·Status Ξ(TM·Array ,TM·CVT)·mount_pe( + Ξ(TM·Array ,TM·CVT) *tm ,TM·CVT *position ,Ξ(extent_t ,TM·CVT) extent ){ #ifdef TM·DEBUG Core·Guard·init_count(chk); @@ -422,9 +383,9 @@ return Core·Status·on_track; } - // If size of CVT is not a power of two this can perform a divide - Local Core·Status Ξ(TM·Array ,CVT)·mount_pp( - Ξ(TM·Array ,CVT) *tm ,CVT *pos_leftmost ,CVT *pos_rightmost + // If size of TM·CVT is not a power of two this can perform a divide + Local Core·Status Ξ(TM·Array ,TM·CVT)·mount_pp( + Ξ(TM·Array ,TM·CVT) *tm ,TM·CVT *pos_leftmost ,TM·CVT *pos_rightmost ){ #ifdef TM·DEBUG Core·Guard·init_count(chk); @@ -438,14 +399,14 @@ Core·Guard·if_return(chk); #endif - Ξ(extent_t ,CVT) extent = pos_rightmost - pos_leftmost); - return Ξ(TM·Array ,CVT)·mount_pe(tm ,pos_leftmost ,extent); + Ξ(extent_t ,TM·CVT) extent = pos_rightmost - pos_leftmost); + return Ξ(TM·Array ,TM·CVT)·mount_pe(tm ,pos_leftmost ,extent); } //----------------------------------- // base Tape Machine operations - Local Core·Status Ξ(TM·Array ,CVT)·mount(Ξ(TM·Array ,CVT) *tm){ + Local Core·Status Ξ(TM·Array ,TM·CVT)·mount(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); @@ -458,7 +419,7 @@ return Core·Status·on_track; } - Local Core·Status Ξ(TM·Array ,CVT)·dismount(Ξ(TM·Array ,CVT) *tm){ + Local Core·Status Ξ(TM·Array ,TM·CVT)·dismount(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); @@ -469,12 +430,12 @@ return Core·Status·on_track; } - Local TM·Head·Status Ξ(TM·Array ,CVT)·head_status(TM *tm){ + Local TM·Head·Status Ξ(TM·Array ,TM·CVT)·head_status(TM *tm){ if(!tm || !tm->position) return TM·Head·Status·mu; if(!tm->hd) return TM·Head·Status·dismounted; if(tm->hd == tm->position) return TM·Head·Status·leftmost; - CVT *rightmost_pt = tm->position + tm->extent; + TM·CVT *rightmost_pt = tm->position + tm->extent; if(tm->hd == rightmost_pt) TM·Head·Status·rightmost; if(tm->hd < tm->position || tm->hd > rightmost_pt) return TM·Head·Status·out_of_area; @@ -482,16 +443,16 @@ return TM·Head·Status·interim; } - bool Ξ(TM·Array ,CVT)·can_read(Ξ(TM·Array ,CVT) *tm){ + bool Ξ(TM·Array ,TM·CVT)·can_read(Ξ(TM·Array ,TM·CVT) *tm){ return tm && tm->position && tm->hd; } // can_read was true - bool Ξ(TM·Array ,CVT)·on_origin(Ξ(TM·Array ,CVT) *tm){ + bool Ξ(TM·Array ,TM·CVT)·on_origin(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif @@ -499,44 +460,44 @@ } // can_read was true - bool Ξ(TM·Array ,CVT)·on_rightmost(Ξ(TM·Array ,CVT) *tm){ + bool Ξ(TM·Array ,TM·CVT)·on_rightmost(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif return tm->hd == tm->position; } - void Ξ(TM·Array ,CVT)·step(Ξ(TM·Array ,CVT) *tm){ + void Ξ(TM·Array ,TM·CVT)·step(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif tm->hd++; } - void Ξ(TM·Array ,CVT)·step_left(Ξ(TM·Array ,CVT) *tm){ + void Ξ(TM·Array ,TM·CVT)·step_left(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif tm->hd--; } - void Ξ(TM·Array ,CVT)·rewind(Ξ(TM·Array ,CVT) *tm){ + void Ξ(TM·Array ,TM·CVT)·rewind(Ξ(TM·Array ,TM·CVT) *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif @@ -544,13 +505,13 @@ } // tm_can_read must be true for both machines. - void Ξ(TM·Array ,CVT)·copy_datum(Ξ(TM·Array ,CVT) *tm_read ,Ξ(TM·Array ,CVT) *tm_write){ + void Ξ(TM·Array ,TM·CVT)·copy_datum(Ξ(TM·Array ,TM·CVT) *tm_read ,Ξ(TM·Array ,TM·CVT) *tm_write){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm_read ,flag) == Control·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm_read ,flag) == Control·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"tm_read head off track"); - s = Ξ(TM·Array ,CVT)·head_on_format(tm_write ,flag) == Control·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm_write ,flag) == Control·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"tm_write head off track"); Core·Guard·assert(chk); #endif @@ -559,11 +520,11 @@ return Core·Status·on_track; } - void Ξ(TM·Array ,CVT)·read(Ξ(TM·Array ,CVT) *tm ,CVT *read_pt){ + void Ξ(TM·Array ,TM·CVT)·read(Ξ(TM·Array ,TM·CVT) *tm ,TM·CVT *read_pt){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif @@ -576,52 +537,52 @@ //---------------------------------------- - // Initialization for Ξ(TM·Array ,CVT)·fg + // Initialization for Ξ(TM·Array ,TM·CVT)·fg - Local Ξ(TM·Array ,CVT)·FG Ξ(TM·Array ,CVT)·fg = { + Local Ξ(TM·Array ,TM·CVT)·FG Ξ(TM·Array ,TM·CVT)·fg = { .tape = { - .Tape·topo = Ξ(TM·Array ,CVT)·Tape·topo - .extent = Ξ(TM·Array ,CVT)·extent + .Tape·topo = Ξ(TM·Array ,TM·CVT)·Tape·topo + .extent = Ξ(TM·Array ,TM·CVT)·extent } ,.area = { - .mount_pe = Ξ(TM·Array ,CVT)·mount_pe - ,.mount_pp = Ξ(TM·Array ,CVT)·mount_pp + .mount_pe = Ξ(TM·Array ,TM·CVT)·mount_pe + ,.mount_pp = Ξ(TM·Array ,TM·CVT)·mount_pp } - ,.mount = Ξ(TM·Array ,CVT)·mount - ,.dismount = Ξ(TM·Array ,CVT)·dismount + ,.mount = Ξ(TM·Array ,TM·CVT)·mount + ,.dismount = Ξ(TM·Array ,TM·CVT)·dismount - ,.status = Ξ(TM·Array ,CVT)·status - ,.head_on_format = Ξ(TM·Array ,CVT)·head_on_format + ,.status = Ξ(TM·Array ,TM·CVT)·status + ,.head_on_format = Ξ(TM·Array ,TM·CVT)·head_on_format - ,.can_read = Ξ(TM·Array ,CVT)·can_read - ,.on_origin = Ξ(TM·Array ,CVT)·on_origin - ,.on_rightmost = Ξ(TM·Array ,CVT)·on_rightmost + ,.can_read = Ξ(TM·Array ,TM·CVT)·can_read + ,.on_origin = Ξ(TM·Array ,TM·CVT)·on_origin + ,.on_rightmost = Ξ(TM·Array ,TM·CVT)·on_rightmost - ,.step = Ξ(TM·Array ,CVT)·step - ,.step_left = Ξ(TM·Array ,CVT)·step_left - ,.step_right = Ξ(TM·Array ,CVT)·step_right // Synonym for step - ,.rewind = Ξ(TM·Array ,CVT)·rewind + ,.step = Ξ(TM·Array ,TM·CVT)·step + ,.step_left = Ξ(TM·Array ,TM·CVT)·step_left + ,.step_right = Ξ(TM·Array ,TM·CVT)·step_right // Synonym for step + ,.rewind = Ξ(TM·Array ,TM·CVT)·rewind - ,.copy_datum = Ξ(TM·Array ,CVT)·copy_datum - ,.read = Ξ(TM·Array ,CVT)·read - ,.write = Ξ(TM·Array ,CVT)·write + ,.copy_datum = Ξ(TM·Array ,TM·CVT)·copy_datum + ,.read = Ξ(TM·Array ,TM·CVT)·read + ,.write = Ξ(TM·Array ,TM·CVT)·write }; - #endif // ifdef CVT + #endif // ifdef TM·CVT #endif // LOCAL #endif // IMPLEMENTATION -void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *tm ,CVT *write_pt){ +void Ξ(TM·Array ,TM·CVT)·write(Ξ(TM·Array ,TM·CVT) *tm ,TM·CVT *write_pt){ #ifdef TM·DEBUG Core·Guard·init_count(chk); bool flag = true ,s; - s = Ξ(TM·Array ,CVT)·head_on_format(tm ,flag) == Core·Status·on_track; + s = Ξ(TM·Array ,TM·CVT)·head_on_format(tm ,flag) == Core·Status·on_track; Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); Core·Guard·assert(chk); #endif @@ -633,7 +594,7 @@ void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *tm ,CVT *write_pt){ // TM struct initializers Local Core·Status TM·mount_pe( - TM *tm ,CVT *position ,Ξ(extent_t ,CVT) extent + TM *tm ,TM·CVT *position ,Ξ(extent_t ,TM·CVT) extent ){ #ifdef TM·DEBUG Core·Guard·init_count(chk); @@ -647,9 +608,9 @@ void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *tm ,CVT *write_pt){ return Core·Status·on_track; } - // If size of CVT is not a power of two this can perform a divide + // If size of TM·CVT is not a power of two this can perform a divide Local Core·Status TM·mount_pp( - TM *tm ,CVT *pos_leftmost ,CVT *pos_rightmost + TM *tm ,TM·CVT *pos_leftmost ,TM·CVT *pos_rightmost ){ #ifdef TM·DEBUG Core·Guard·init_count(chk); @@ -663,7 +624,7 @@ void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *tm ,CVT *write_pt){ Core·Guard·if_return(chk); #endif - Ξ(extent_t ,CVT) extent = pos_rightmost - pos_leftmost); + Ξ(extent_t ,TM·CVT) extent = pos_rightmost - pos_leftmost); return TM·mount_pe(tm ,pos_leftmost ,extent); } diff --git "a/developer/cc\360\237\226\211/cpp_ext.c" "b/developer/cc\360\237\226\211/cpp_ext.c" index 91e81da..680bbf5 100644 --- "a/developer/cc\360\237\226\211/cpp_ext.c" +++ "b/developer/cc\360\237\226\211/cpp_ext.c" @@ -1,6 +1,72 @@ #ifndef CPP_EXT #define CPP_EXT + #include "cpp_ext_0.c" #include "cpp_ext_1.c" + + /* + Types must be registered with predicates. + + // all legal FG·Type are registered here + #define EQ__int__oo__int + #define EQ__float__oo__float + #define EQ__char__oo__char + #define EQ__void__oo__void + + */ + + #define FIRST_SEEN(type ,list) \ + NOT(FIND_ITEM(type ,list)) ) + + // CAT(SEP, ...) will soon be added to cpp_ext_1, then this will be: + // #define Ξ(...) CAT(· ,__VA_ARGS__) + + // Individual macros for specific argument counts + #define _Ξ0() + #define Ξ0() _Ξ0() + + #define _Ξ1(a) a + #define Ξ1(a) _Ξ1(a) + + #define _Ξ2(a ,b) a##·##b + #define Ξ2(a ,b) _Ξ2(a ,b) + + #define _Ξ3(a ,b ,c) a##·##b##·##c + #define Ξ3(a ,b ,c) _Ξ3(a ,b ,c) + + #define _Ξ4(a ,b ,c ,d) a##·##b##·##c##·##d + #define Ξ4(a ,b ,c ,d) _Ξ4(a ,b ,c ,d) + + #define _Ξ5(a ,b ,c ,d ,e) a##·##b##·##c##·##d##·##e + #define Ξ5(a ,b ,c ,d ,e) _Ξ5(a ,b ,c ,d ,e) + + #define _Ξ6(a ,b ,c ,d ,e ,f) a##·##b##·##c##·##d##·##e##·##f + #define Ξ6(a ,b ,c ,d ,e ,f) _Ξ6(a ,b ,c ,d ,e ,f) + + #define _Ξ7(a ,b ,c ,d ,e ,f ,g) a##·##b##·##c##·##d##·##e##·##f##·##g + #define Ξ7(a ,b ,c ,d ,e ,f ,g) _Ξ7(a ,b ,c ,d ,e ,f ,g) + + #define _Ξ8(a ,b ,c ,d ,e ,f ,g ,h) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h + #define Ξ8(a ,b ,c ,d ,e ,f ,g ,h) _Ξ8(a ,b ,c ,d ,e ,f ,g ,h) + + #define _Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h##·##i + #define Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) _Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) + + #define _Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h##·##i##·##j + #define Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) _Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) + + // Argument counting mechanism + #define _ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + #define COUNT_ARGS(...) _ARG_N(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) + + // Macro name concatenation + #define _CONCAT(a, b) a##b + #define CONCAT(a, b) _CONCAT(a, b) + + // Selector that chooses the right macro based on argument count + #define Ξ_EXPAND(count, ...) CONCAT(Ξ, count)(__VA_ARGS__) + #define Ξ(...) Ξ_EXPAND(COUNT_ARGS(__VA_ARGS__), __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 90a0120..573c27c 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_0.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_0.c" @@ -37,7 +37,7 @@ Macros starting with an '_' (underscore) are private. - EQ comparisons apart from logic comparisons, must be registered in advance. They take the form of, _RWR_EQ____oo__, note comments below. + EQ comparisons apart from logic comparisons, must be registered in advance. They take the form of, EQ____oo__, note comments below. 5. todo @@ -93,8 +93,8 @@ Constants #define _RWR_OR__0__oo__0 // add more of this form to register other equivalences -#define _RWR_EQ__0__oo__0 -#define _RWR_EQ__1__oo__1 +#define EQ__0__oo__0 +#define EQ__1__oo__1 /*=========================================================================== Primitive Concatenation @@ -166,7 +166,7 @@ Logic Connectors #define _BOOL(x_item) \ _AND( \ EXISTS_ITEM( x_item ) \ - ,NOT_MATCH_RWR( CAT2(_RWR_EQ__0__oo__ ,x_item) ) \ + ,NOT_MATCH_RWR( CAT2(EQ__0__oo__ ,x_item) ) \ ) #define BOOL(x_item) _BOOL(_FIRST(x_item)) @@ -180,18 +180,18 @@ Logic Connectors more general than a connector because more rules can be added. each registered equality rule has the form - _RWR_EQ____oo__ + EQ____oo__ for example, logic equalities are already registered: - _RWR_EQ__0__oo__0 - _RWR_EQ__1__oo__1 + EQ__0__oo__0 + EQ__1__oo__1 ===========================================================================*/ #define EQ(x_item ,y_item) \ - MATCH_RWR( CAT4(_RWR_EQ__ ,x_item ,__oo__ ,y_item) ) + MATCH_RWR( CAT4(EQ__ ,x_item ,__oo__ ,y_item) ) #define NOT_EQ(x_item ,y_item) \ - NOT_MATCH_RWR( CAT4(_RWR_EQ__ ,x_item ,__oo__ ,y_item) ) + NOT_MATCH_RWR( CAT4(EQ__ ,x_item ,__oo__ ,y_item) ) /*=========================================================================== IF-ELSE construct. 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 1980b93..bc241d7 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_1.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_1.c" @@ -71,5 +71,20 @@ DROPE_NOT_EXISTS_RIGHT // number of evals required depends upon length of not found list prefix #define FIND(predicate ,...) EVAL( _FIND(predicate ,__VA_ARGS__) ) +#define _FIND_ITEM(item ,...) \ + IF \ + ( NOT_EXISTS(__VA_ARGS__) ) \ + () \ + (IF \ + ( EQ(item ,FIRST(__VA_ARGS__)) ) \ + ( FIRST( ,__VA_ARGS__) ) \ + ( DEFER3(_FIND_ITEM_CONFEDERATE) ()(predicate ,REST(__VA_ARGS__)) ) \ + ) +#define _FIND_ITEM_CONFEDERATE() _FIND_ITEM + +// number of evals required depends upon length of not found list prefix +#define FIND_ITEM(predicate ,...) EVAL( _FIND_ITEM(predicate ,__VA_ARGS__) ) + + #endif diff --git "a/developer/cc\360\237\226\211/xi.c" "b/developer/cc\360\237\226\211/xi.c" deleted file mode 100644 index ae2b85c..0000000 --- "a/developer/cc\360\237\226\211/xi.c" +++ /dev/null @@ -1,66 +0,0 @@ -/* Xi (Ξ) macro implementation with variable argument support - * - * This file provides macros from Ξ0 through Ξ10 along with a selector - * that automatically chooses the right macro based on argument count. - * - * Usage: - * Ξ(a) -> a - * Ξ(a ,b) -> a·b - * Ξ(a ,b ,c) -> a·b·c - * ... - * Ξ(a ,b ,c ,d ,e ,f) -> a·b·c·d·e·f - * - * For Map with two template parameters: - * Ξ(Map ,CVT_read ,CVT_write) -> Map·CVT_read·CVT_write - */ - -#ifndef XI_C -#define XI_C - -// Individual macros for specific argument counts -#define _Ξ0() -#define Ξ0() _Ξ0() - -#define _Ξ1(a) a -#define Ξ1(a) _Ξ1(a) - -#define _Ξ2(a ,b) a##·##b -#define Ξ2(a ,b) _Ξ2(a ,b) - -#define _Ξ3(a ,b ,c) a##·##b##·##c -#define Ξ3(a ,b ,c) _Ξ3(a ,b ,c) - -#define _Ξ4(a ,b ,c ,d) a##·##b##·##c##·##d -#define Ξ4(a ,b ,c ,d) _Ξ4(a ,b ,c ,d) - -#define _Ξ5(a ,b ,c ,d ,e) a##·##b##·##c##·##d##·##e -#define Ξ5(a ,b ,c ,d ,e) _Ξ5(a ,b ,c ,d ,e) - -#define _Ξ6(a ,b ,c ,d ,e ,f) a##·##b##·##c##·##d##·##e##·##f -#define Ξ6(a ,b ,c ,d ,e ,f) _Ξ6(a ,b ,c ,d ,e ,f) - -#define _Ξ7(a ,b ,c ,d ,e ,f ,g) a##·##b##·##c##·##d##·##e##·##f##·##g -#define Ξ7(a ,b ,c ,d ,e ,f ,g) _Ξ7(a ,b ,c ,d ,e ,f ,g) - -#define _Ξ8(a ,b ,c ,d ,e ,f ,g ,h) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h -#define Ξ8(a ,b ,c ,d ,e ,f ,g ,h) _Ξ8(a ,b ,c ,d ,e ,f ,g ,h) - -#define _Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h##·##i -#define Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) _Ξ9(a ,b ,c ,d ,e ,f ,g ,h ,i) - -#define _Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) a##·##b##·##c##·##d##·##e##·##f##·##g##·##h##·##i##·##j -#define Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) _Ξ10(a ,b ,c ,d ,e ,f ,g ,h ,i ,j) - -// Argument counting mechanism -#define _ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N -#define COUNT_ARGS(...) _ARG_N(__VA_ARGS__, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) - -// Macro name concatenation -#define _CONCAT(a, b) a##b -#define CONCAT(a, b) _CONCAT(a, b) - -// Selector that chooses the right macro based on argument count -#define Ξ_EXPAND(count, ...) CONCAT(Ξ, count)(__VA_ARGS__) -#define Ξ(...) Ξ_EXPAND(COUNT_ARGS(__VA_ARGS__), __VA_ARGS__) - -#endif /* XI_C */ diff --git a/developer/example/cpp_ext_0.c b/developer/example/cpp_ext_0.c index 90a0120..573c27c 100644 --- a/developer/example/cpp_ext_0.c +++ b/developer/example/cpp_ext_0.c @@ -37,7 +37,7 @@ Macros starting with an '_' (underscore) are private. - EQ comparisons apart from logic comparisons, must be registered in advance. They take the form of, _RWR_EQ____oo__, note comments below. + EQ comparisons apart from logic comparisons, must be registered in advance. They take the form of, EQ____oo__, note comments below. 5. todo @@ -93,8 +93,8 @@ Constants #define _RWR_OR__0__oo__0 // add more of this form to register other equivalences -#define _RWR_EQ__0__oo__0 -#define _RWR_EQ__1__oo__1 +#define EQ__0__oo__0 +#define EQ__1__oo__1 /*=========================================================================== Primitive Concatenation @@ -166,7 +166,7 @@ Logic Connectors #define _BOOL(x_item) \ _AND( \ EXISTS_ITEM( x_item ) \ - ,NOT_MATCH_RWR( CAT2(_RWR_EQ__0__oo__ ,x_item) ) \ + ,NOT_MATCH_RWR( CAT2(EQ__0__oo__ ,x_item) ) \ ) #define BOOL(x_item) _BOOL(_FIRST(x_item)) @@ -180,18 +180,18 @@ Logic Connectors more general than a connector because more rules can be added. each registered equality rule has the form - _RWR_EQ____oo__ + EQ____oo__ for example, logic equalities are already registered: - _RWR_EQ__0__oo__0 - _RWR_EQ__1__oo__1 + EQ__0__oo__0 + EQ__1__oo__1 ===========================================================================*/ #define EQ(x_item ,y_item) \ - MATCH_RWR( CAT4(_RWR_EQ__ ,x_item ,__oo__ ,y_item) ) + MATCH_RWR( CAT4(EQ__ ,x_item ,__oo__ ,y_item) ) #define NOT_EQ(x_item ,y_item) \ - NOT_MATCH_RWR( CAT4(_RWR_EQ__ ,x_item ,__oo__ ,y_item) ) + NOT_MATCH_RWR( CAT4(EQ__ ,x_item ,__oo__ ,y_item) ) /*=========================================================================== IF-ELSE construct. diff --git a/developer/example/cpp_ext_1.c b/developer/example/cpp_ext_1.c index 1980b93..bc241d7 100644 --- a/developer/example/cpp_ext_1.c +++ b/developer/example/cpp_ext_1.c @@ -71,5 +71,20 @@ DROPE_NOT_EXISTS_RIGHT // number of evals required depends upon length of not found list prefix #define FIND(predicate ,...) EVAL( _FIND(predicate ,__VA_ARGS__) ) +#define _FIND_ITEM(item ,...) \ + IF \ + ( NOT_EXISTS(__VA_ARGS__) ) \ + () \ + (IF \ + ( EQ(item ,FIRST(__VA_ARGS__)) ) \ + ( FIRST( ,__VA_ARGS__) ) \ + ( DEFER3(_FIND_ITEM_CONFEDERATE) ()(predicate ,REST(__VA_ARGS__)) ) \ + ) +#define _FIND_ITEM_CONFEDERATE() _FIND_ITEM + +// number of evals required depends upon length of not found list prefix +#define FIND_ITEM(predicate ,...) EVAL( _FIND_ITEM(predicate ,__VA_ARGS__) ) + + #endif diff --git a/developer/example/try_6_list.c b/developer/example/try_6_list.c index 886aec3..2bcc339 100644 --- a/developer/example/try_6_list.c +++ b/developer/example/try_6_list.c @@ -4,10 +4,10 @@ #define LIST int ,float ,char ,void // register equality -#define _RWR_EQ__int__oo__int -#define _RWR_EQ__float__oo__float -#define _RWR_EQ__char__oo__char -#define _RWR_EQ__void__oo__void +#define EQ__int__oo__int +#define EQ__float__oo__float +#define EQ__char__oo__char +#define EQ__void__oo__void // make predicates #define IS_int(x) EQ(x ,int) diff --git "a/developer/tool\360\237\226\211/makefile" "b/developer/tool\360\237\226\211/makefile" index 56f2283..7b3660f 100644 --- "a/developer/tool\360\237\226\211/makefile" +++ "b/developer/tool\360\237\226\211/makefile" @@ -3,7 +3,7 @@ RT-INCOMMON:=$(REPO_HOME)/tool_shared/third_party/RT-project-share/release include $(RT-INCOMMON)/make/environment_RT_0 -CFLAGS+=-Werror -include "$(RT-INCOMMON)/make/RT_0.h" +CFLAGS+=-Werror -Wno-macro-redefined -include "$(RT-INCOMMON)/make/RT_0.h" LINKFLAGS+= -l$(PROJECT) LIBFILE=$(LIBDIR)/lib$(PROJECT).a