From: Thomas Walker Lynch Date: Thu, 20 Mar 2025 16:19:08 +0000 (+0000) Subject: checkpoint TM in progress X-Git-Url: https://git.reasoningtechnology.com/style/static/git-logo.png?a=commitdiff_plain;h=7317157d639b686ecaf583316cc40111d07372c7;p=N checkpoint TM in progress --- diff --git "a/developer/cc\360\237\226\211/Core.lib.c" "b/developer/cc\360\237\226\211/Core.lib.c" index f70d7ea..a14ec2e 100644 --- "a/developer/cc\360\237\226\211/Core.lib.c" +++ "b/developer/cc\360\237\226\211/Core.lib.c" @@ -32,47 +32,43 @@ #include #include - // the template filling macro - #include - //---------------------------------------- // memory interface //---------------------------------------- - // Expand namespace with a macro parameter given value. - // The namespace and the extended value will be evaluated for macros. - // Greek capital letter 'Xi' for eXtend. - #define _Ξ(a ,b) a##·##b - #define Ξ(a ,b) _Ξ(a ,b) - - // ask the machine what this is - // C language standard left this undefined, probably why unicode uses 'octet' - // AToW industry uses uint8_t - // reminds me of FORTRAN star types - #define AU uint8_t - #define AU2 uint16_t - #define AU4 uint32_t - #define AU8 uint64_t - - #define AU_MAX (~(AU)0) - #define AU2_MAX (~(AU2)0) - #define AU4_MAX (~(AU4)0) - #define AU8_MAX (~(AU8)0) + // Define a namespace. + // #define _Ξ(a ,b) a##·##b + /// #define Ξ(a ,b) _Ξ(a ,b) + #include + + // extent is the maximum index in an address space, tape or area, the doted + // unit is the cell type. + typedef extent_t·AU size_t + #define extent_of·AU(x) (sizeof(x) - 1) + + // Funny, we seldom check for this, perhaps that matters on some tiny machine. + #define extent·AU_address_space ~(uintptr)0; + + // addressable unit for the machine + // C language standard left this undefined. AToW industry uses uint8_t. + typedef AU uint8_t; + typedef AU2 uint16_t; + typedef AU4 uint32_t; + typedef AU8 uint64_t; + + const AU AU_max = (~(AU)0); + const AU2 AU2_max = (~(AU2)0); + const AU4 AU4_max = (~(AU4)0); + const AU8 AU8_max = (~(AU8)0); // ask the compiler what this is // when using enums we get this whether we want it or not - #define WU unsigned int - #define WU_MAX (~(WU)0) - - // extent is an address or an index. It is not a length. - // The index scaling CVT type is appended to the end of the extent related identifiers.. - // E.g. extent_of·AU(uint64_t) == 7 while extent_of·uint16_t(uint64_t) == 3; - // extent_of·AU of the address space is ~(uintptr)0; - #define extent_of·AU(x)(sizeof(x) - 1) - #define extent_t·AU size_t + typedef WU unsigned int; + const WU WU_max = (~(WU)0); - // Funny, we seldom check for this, but maybe someone is running a microcontroller or something, so we will here. Also, too bad that address 0 can't be used. - #define extent_address_space·AU ~(uintptr)0; + //---------------------------------------- + // flag facility, argument guard facility + //---------------------------------------- typedef enum{ Core·Status·mu = 0 @@ -80,10 +76,6 @@ ,Core·Status·derailed }Core·Status; - //---------------------------------------- - // flag facility, argument guard facility - //---------------------------------------- - typedef void (*Core·Flag·Fn)(WU *flag ,WU err); void Core·Flag·count(WU *flag ,WU err){ diff --git "a/developer/cc\360\237\226\211/TM.lib.c" "b/developer/cc\360\237\226\211/TM.lib.c" index 9936426..4580104 100644 --- "a/developer/cc\360\237\226\211/TM.lib.c" +++ "b/developer/cc\360\237\226\211/TM.lib.c" @@ -81,16 +81,7 @@ // tape and area are included with Tape Machine to facilitate abstract interfaces. typedef struct{ - struct { - Core·Status (*topo) ( TM *tm ,TM·Tape·Topo *result ); - Ξ(extent_t ,CVT) (*extent)( TM *tm ); - } tape; - - struct { - // Initialize tm - Core·Status (*mount_pe)(TM *tm ,CVT position[] ,Ξ(extent_t ,CVT) extent); - Core·Status (*mount_pp)(TM *tm ,CVT *position_left ,CVT *position_right); - } area; + Core·Status (*topo) (TM *tm ,TM·Tape·Topo *result); // tape machine functions Core·Status (*mount) (TM *tm); @@ -108,28 +99,28 @@ void (*step_right)(TM *tm); // Synonym for step void (*rewind) (TM *tm); - void (*copy_datum)( TM *tm_read ,TM *tm_write ); - void (*apply)( TM *tm_read , TM·FN); - } TM·FG; - #endif // #ifndef CVT #ifdef CVT + typedef Ξ(extent_t ,CVT) size_t; + // instance struct with vtable pointer as first entry typedef struct{ - - void (*read) ( TM *tm ,CVT *remote_pt ); - void (*write) ( TM *tm ,CVT *remote_pt ); - + Ξ(extent_t ,CVT) (*extent)(TM *tm); + CVT (*read) (TM *tm); + void (*write)(TM *tm ,CVT *remote_pt); } Ξ(TM ,CVT); - // default table for TM implemented by an Array - #ifdef Array - Ξ(TM ,CVT)·FG Ξ(TM·Array ,CVT)·fg; - #endif + // Array Initializers + typedef struct{ + TM *(*mount_pe)( Ξ(TM·Array ,CVT) *tm ,CVT position[] ,Ξ(extent_t ,CVT) extent ); + TM *(*mount_pp)( Ξ(TM·Array ,CVT) *tm ,CVT *position_left ,CVT *position_right ); + } Ξ(TM·Array ,CVT)·FG; + + Ξ(TM ,CVT)·FG Ξ(TM·Array ,CVT)·fg; #endif // #ifdef CVT @@ -161,239 +152,112 @@ //----------------------------------- // common error messages - const char *TM·Array·Msg·tm="given NULL tm"; - const char *TM·Array·Msg·flag="given NULL flag pointer"; - const char *TM·Array·Msg·result="given NULL result pointer"; - const char *TM·Array·Msg·position= + const char *TM·Msg·tm="given NULL tm"; + const char *TM·Msg·position= "Null position.This is only possible when the tape machine has not been initialized."; + const char *TM·Msg·flag="given NULL flag pointer"; + const char *TM·Msg·result="given NULL result pointer"; - #endif // #ifndef CVT - - #ifdef CVT + //----------------------------------- + // generic instance type, with vtable pointer at top struct{ - Ξ(TM ,CVT)·FG *fg - }Ξ(TM ,CVT); + TM·FG *fg; + } TM; //----------------------------------- - // TM·Array.tape implementation + // generic call wrappers - /* - For an Array Tape Machine ,a bound tape will be singleton or segment. - An initialized Array Tape Machine always has a bound tape. - */ - Core·Status Ξ(TM ,CVT)·topo(Ξ(TM·Array ,CVT) *tm ,TM·Tape·Topo *result){ + Core·Status TM·topo(TM *tm ,TM·Tape·Topo *result){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); - Core·Guard·fg.check(&chk ,1 ,result ,TM·Array·Msg·result); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); + Core·Guard·fg.check(&chk ,1 ,result ,TM·Msg·result); Core·Guard·if_return(chk); #endif - if(tm->extent == 0){ - *result = TM·Tape·Topo·singleton; - }else{ - *result = TM·Tape·Topo·segment; - } - return Core·Status·on_track; + return tm->fg.topo(tm ,result); } - // check the 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){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - Core·Tape·Topo topo = Core·Tape·Topo·mu; - Core·Status status = Ξ(TM·Array ,CVT)·topo(tm ,&topo); - bool good_topo = - (status == Core·Status·on_track) && (topo & Core·Tape·Topo·finite_nz) - ; - Core·Guard·fg.check(&chk ,1 ,good_topo ,"Tape does not have an extent."); - Core·Guard·assert(chk); - #endif - - *result = tm->extent; - return Core·Status·on_track; + // mount dismount + #define Core·Status_tm(name) \ + Local Core·Status TM##name##(TM *tm) { \ + #ifdef TM·DEBUG \ + Core·Guard·init_count(chk); \ + Core·Guard·fg.check(&chk, 1, tm, TM·Msg·tm); \ + Core·Guard·if_return(chk); \ + #endif \ + return tm->fg.##name##(tm); \ } - //----------------------------------- - // TM·Array.area implementation - - Local Core·Status Ξ(TM·Array ,CVT)·mount_pe( - Ξ(TM·Array ,CVT) *tm ,CVT *position ,Ξ(extent_t ,CVT) extent - ){ + Core·Status_tm(mount); + Core·Status_tm(dismount); + + Local TM·Head·Status TM·status(TM *tm ,TM·Head·Status *result){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); - Core·Guard·fg.check(&chk ,1 ,position ,"Given NULL position."); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); + Core·Guard·fg.check(&chk ,1 ,result ,TM·Msg·result); Core·Guard·if_return(chk); #endif - tm->position = position; - tm->extent = extent; - tm->hd = position; // mount the head on the origin cell - return Core·Status·on_track; + return tm->fg.status(tm ,result); } - // 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 - ){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,pos_leftmost ,"Null pos_leftmost."); - Core·Guard·fg.check(&chk ,1 ,pos_rightmost ,"Null pos_rightmost."); - if(pos_leftmost && pos_rightmost){ - Core·Guard·fg.check(&chk ,1 ,pos_rightmost >= pos_leftmost - ,"pos_rightmost < pos_leftmost" - ); - } - Core·Guard·if_return(chk); - #endif - - Ξ(extent_t ,CVT) extent = pos_rightmost - pos_leftmost); - return Ξ(TM·Array ,CVT)·mount_pe(tm ,pos_leftmost ,extent); - } - - //----------------------------------- - // base Tape Machine operations - - Local Core·Status Ξ(TM·Array ,CVT)·mount(Ξ(TM·Array ,CVT) *tm){ + // Stronger than `can_read`. Used mostly for debugging. + // as it checks for a legal head position. + Local Core·Status TM·head_on_format(TM *tm ,bool *flag){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); - if(tm) Core·Guard·fg.check(&chk ,1 ,tm->position ,TM·Array·Msg·position); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); + Core·Guard·fg.check(&chk ,1 ,flag ,TM·Msg·flag); Core·Guard·if_return(chk); #endif - - // mounting an already mounted head does nothing ,perhaps you meant `rewind`? - if(!tm->hd) tm->hd = tm->position; - return Core·Status·on_track; + return tm->fg.head_on_format(tm ,flag); } - Local Core·Status Ξ(TM·Array ,CVT)·dismount(Ξ(TM·Array ,CVT) *tm){ + bool bool_fn_tm(TM *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); Core·Guard·if_return(chk); #endif - - tm->hd = NULL; - return Core·Status·on_track; + return tm->fg.read(tm); } - Local TM·Head·Status Ξ(TM·Array ,CVT)·status( - Ξ(TM·Array ,CVT) *tm ,TM·Head·Status *status - ){ + bool TM·on_leftmost(TM *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); - Core·Guard·fg.check(&chk ,1 ,status ,"given NULL status pointer"); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); Core·Guard·if_return(chk); #endif - - if(tm->hd == NULL){ - *status = TM·Head·Status·not_on_tape; - }else if(tm->hd == tm->position){ - *status = TM·Head·Status·origin; - }else if(tm->hd == tm->position + tm->extent){ - *status = TM·Head·Status·rightmost; - }else{ - *status = TM·Head·Status·interim; - } - - return Core·Status·on_track; + return tm->fg.on_leftmost(tm); } - // Stronger than `can_read`. Used mostly for debugging. - // as it checks for a legal head position. - Local Core·Status Ξ(TM·Array ,CVT)·head_on_format( - Ξ(TM·Array ,CVT) *tm ,bool *flag - ){ + bool TM·on_rigthmost(TM *tm){ #ifdef TM·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·Msg·tm); - if(tm) Core·Guard·fg.check(&chk ,1 ,tm->position ,TM·Array·Msg·position); - Core·Guard·fg.check(&chk ,1 ,flag ,TM·Array·Msg·flag); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); Core·Guard·if_return(chk); #endif - - *flag = - tm->hd - && tm->hd >= tm->position - && tm->hd - tm->position <= tm->extent - && ( (AU *)tm->hd - (AU *)tm->position ) % sizeof(CVT) == 0 // '%' expensive - ; - return Core·Status·on_track; - } - - bool Ξ(TM·Array ,CVT)·can_read(Ξ(TM·Array ,CVT) *tm){ - return tm && tm->position && tm->hd; - } - - // can_read was true - bool Ξ(TM·Array ,CVT)·on_origin(Ξ(TM·Array ,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; - Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); - Core·Guard·assert(chk); - #endif - return tm->hd == tm->position; + return tm->fg.on_rigthmost(tm); } - // can_read was true - bool Ξ(TM·Array ,CVT)·on_rightmost(Ξ(TM·Array ,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; - 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){ - #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; - 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){ - #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; - 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){ - #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; - Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); - Core·Guard·assert(chk); - #endif - tm->hd = tm->position; - } + Local bool TM·Given1(can_read); + Local bool TM·Given1(on_leftmost); + Local bool TM·Given1(on_rightmost); + Local bool TM·Given1(step); + Local bool TM·Given1(step_left); + Local bool TM·Given1(rewind); // 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·copy_datum(TM *tm_read ,TM *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·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·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 @@ -402,11 +266,11 @@ return Core·Status·on_track; } - void Ξ(TM·Array ,CVT)·read(Ξ(TM·Array ,CVT) *tm ,CVT *read_pt){ + void TM·read(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·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 @@ -414,11 +278,11 @@ *read_pt = *(tm->hd); } - void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *tm ,CVT *write_pt){ + void TM·write(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·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 @@ -428,40 +292,50 @@ // step_right is a synonym for step + // check the 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·extent(TM *tm){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); + Core·Guard·assert(chk); + #endif + return tm->fg.extent(tm); + } + + //---------------------------------------- - // Initialization for Ξ(TM·Array ,CVT)·fg + // Initialization for TM·fg - Local Ξ(TM·Array ,CVT)·FG Ξ(TM·Array ,CVT)·fg = { + Local TM·FG TM·fg = { .tape = { - .topo = Ξ(TM·Array ,CVT)·topo - .extent = Ξ(TM·Array ,CVT)·extent + .topo = TM·topo + .extent = TM·extent } ,.area = { - .mount_pe = Ξ(TM·Array ,CVT)·mount_pe - ,.mount_pp = Ξ(TM·Array ,CVT)·mount_pp + .mount_pe = TM·mount_pe + ,.mount_pp = TM·mount_pp } - ,.mount = Ξ(TM·Array ,CVT)·mount - ,.dismount = Ξ(TM·Array ,CVT)·dismount + ,.mount = TM·mount + ,.dismount = TM·dismount - ,.status = Ξ(TM·Array ,CVT)·status - ,.head_on_format = Ξ(TM·Array ,CVT)·head_on_format + ,.status = TM·status + ,.head_on_format = TM·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·can_read + ,.on_origin = TM·on_origin + ,.on_rightmost = TM·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 - - ,.copy_datum = Ξ(TM·Array ,CVT)·copy_datum - ,.read = Ξ(TM·Array ,CVT)·read - ,.write = Ξ(TM·Array ,CVT)·write + ,.step = TM·step + ,.step_left = TM·step_left + ,.step_right = TM·step_right // Synonym for step + ,.rewind = TM·rewind + ,.read = TM·read + ,.write = TM·write }; #endif // ifdef CVT @@ -750,17 +624,6 @@ *read_pt = *(tm->hd); } - void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *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; - Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); - Core·Guard·assert(chk); - #endif - - *(tm->hd) = *write_pt; - } // step_right is a synonym for step @@ -805,3 +668,55 @@ #endif // LOCAL #endif // IMPLEMENTATION + + +void Ξ(TM·Array ,CVT)·write(Ξ(TM·Array ,CVT) *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; + Core·Guard·fg.check(&chk ,1 ,s && flag ,"head off format"); + Core·Guard·assert(chk); + #endif + + *(tm->hd) = *write_pt; +} + + //----------------------------------- + // TM struct initializers + + Local Core·Status TM·mount_pe( + TM *tm ,CVT *position ,Ξ(extent_t ,CVT) extent + ){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Msg·tm); + Core·Guard·fg.check(&chk ,1 ,position ,"Given NULL position."); + Core·Guard·if_return(chk); + #endif + tm->position = position; + tm->extent = extent; + tm->hd = position; // mount the head on the origin cell + return Core·Status·on_track; + } + + // If size of 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 + ){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,pos_leftmost ,"Null pos_leftmost."); + Core·Guard·fg.check(&chk ,1 ,pos_rightmost ,"Null pos_rightmost."); + if(pos_leftmost && pos_rightmost){ + Core·Guard·fg.check(&chk ,1 ,pos_rightmost >= pos_leftmost + ,"pos_rightmost < pos_leftmost" + ); + } + Core·Guard·if_return(chk); + #endif + + Ξ(extent_t ,CVT) extent = pos_rightmost - pos_leftmost); + return TM·mount_pe(tm ,pos_leftmost ,extent); + } + diff --git a/developer/experiment/macro_equality.c b/developer/experiment/macro_equality.c new file mode 100644 index 0000000..1d8b1e5 --- /dev/null +++ b/developer/experiment/macro_equality.c @@ -0,0 +1,60 @@ +#include +#include + +int main(){ + +#define AU uint8_t +#define CVT AU + +#if CVT == uint16_t + printf("CVT == uint16_t\n"); +#else + printf("CVT != uint16_t\n"); +#endif + +#if CVT != uint16_t + printf("CVT != uint16_t\n"); +#else + printf("CVT == uint16_t\n"); +#endif + +#if CVT == AU + printf("CVT == AU\n"); +#else + printf("CVT != AU\n"); +#endif + +#if CVT != AU + printf("CVT != AU\n"); +#else + printf("CVT == AU\n"); +#endif + +#if CVT == uint8_t + printf("CVT == uint8_t\n"); +#else + printf("CVT != uint8_t\n"); +#endif + +#if CVT != uint8_t + printf("CVT != uint8_t\n"); +#else + printf("CVT == uint8_t\n"); +#endif + +} + +/* + The macros is evaluated for its numeric value, so this does not work. + +> gcc macro_equality.c + +> ./a.out +CVT == uint16_t +CVT == uint16_t +CVT == AU +CVT == AU +CVT == uint8_t +CVT == uint8_t + +*/