From: Thomas Walker Lynch Date: Wed, 30 Apr 2025 15:07:43 +0000 (+0000) Subject: checkpoint separating out TM implementations X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.css?a=commitdiff_plain;h=a42ade4bead8adbf0aa4c140bf0a01e40961eaa1;p=N checkpoint separating out TM implementations --- diff --git "a/developer/cc\360\237\226\211/Binding.lib.c" "b/developer/cc\360\237\226\211/Binding.lib.c" deleted file mode 100644 index d36f1aa..0000000 --- "a/developer/cc\360\237\226\211/Binding.lib.c" +++ /dev/null @@ -1,98 +0,0 @@ -/* -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. - - - -*/ - -/*-------------------------------------------------------------------------------- - Interface --------------------------------------------------------------------------------*/ - - -// once per translation unit -#ifndef Binding·FACE -#define Binding·FACE - - #define Binding·DEBUG - #ifdef Binding·DEBUG - #include - #pragma message( "in #ifndef Binding_LIST section" ) - #endif - - #include "cpp_ext.c" - #include "Core.lib.c" - - /* - usage e.g.: Binding·call(tm, function_name, arg1, arg2, ...) - Expands to: (tm.fg->function_name)(tm ,arg1 ,arg2, ...) - - note the use of the comma operator to return the result from the b.fg->fn call - */ - #ifdef Binding·DEBUG - #include - #define Binding·call(b ,fn ,...) ( \ - assert((b).fg != NULL) \ - ,assert((b).tableau != NULL) \ - ,(b).fg->fn(b __VA_OPT__(,) __VA_ARGS__) \ - ) - #else - #define Binding·call(b ,fn ,...) \ - (b).fg->fn(b __VA_OPT__(,) __VA_ARGS__) - #endif - -#endif - - -// once per Binding value -#ifdef _BINDING_ -#if BOOLEAN(NOT_IN(Binding·SET ,_BINDING_)) -#ifdef Binding·DEBUG - #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) -#endif - - struct ·(_BINDING_ ,FG); - typedef struct ·(_BINDING_ ,FG) ·(_BINDING_ ,FG); - - struct ·(_BINDING_ ,Tableau); - typedef struct ·(_BINDING_ ,Tableau) ·(_BINDING_ ,Tableau); - - typedef struct _BINDING_{ - ·(_BINDING_ ,Tableau) *tableau; - ·(_BINDING_ ,FG) *fg; - } _BINDING_; - -#endif -#endif - - -/*-------------------------------------------------------------------------------- - 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 ---------------------------------------------------------------------------------*/ -#ifdef LIBRARY - -#endif - -/*-------------------------------------------------------------------------------- - 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 9ac6fca..ec6a658 100644 --- "a/developer/cc\360\237\226\211/Core.lib.c" +++ "b/developer/cc\360\237\226\211/Core.lib.c" @@ -12,7 +12,7 @@ `AU` `Addressable Unit for the machine`. The C standard leaves this open to definition by the architecture and calls it `char`. On most all machines today it is uint8_t; - We use structs to group functions into a namespace. When all the functions that have a specific type of given argument are group together ,we call the table a 'Functions Given Type X table' ,or 'FG table' for short. A specific instance of an FG table is an `fg` table. + We use structs to group functions into a namespace. When all the functions that have a specific type of given argument are group together ,we call the table a 'Functions Given Type X table' ,or 'PFT table' for short. A specific instance of an PFT table is an `pft` table. */ @@ -23,7 +23,7 @@ #define Core·FACE #define Core·DEBUG - #ifdef FG·DEBUG + #ifdef PFT·DEBUG #include #endif @@ -99,19 +99,19 @@ ,bool condition ,char *message ); - } Core·Guard·FG; + } Core·Guard·PFT; // Default guard function table // initialized in the implementation section below - Local Core·Guard·FG Core·Guard·fg; + Local Core·Guard·PFT Core·Guard·pft; #define Core·Guard·init_count(chk) \ Core·Guard chk; \ - Core·Guard·fg.init(&chk ,__func__ ,Core·Flag·count); + Core·Guard·pft.init(&chk ,__func__ ,Core·Flag·count); #define Core·Guard·init_collect(chk) \ Core·Guard chk; \ - Core·Guard·fg.init(&chk ,__func__ ,Core·Flag·collect); + Core·Guard·pft.init(&chk ,__func__ ,Core·Flag·collect); #define Core·Guard·if_return(chk) if( chk.flag ) return Core·Status·derailed; #define Core·Guard·return(chk)\ @@ -172,7 +172,7 @@ chk->flag_function(&chk->flag ,err); } - Local Core·Guard·FG Core·Guard·fg = { + Local Core·Guard·PFT Core·Guard·pft = { .init = Core·Guard·init ,.reset = Core·Guard·reset ,.check = Core·Guard·check @@ -187,8 +187,8 @@ Local Core·Status Core·is_aligned(AU *p ,extent_t·AU alignment ,bool *flag){ #ifdef Core·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,p ,"given NULL p"); - Core·Guard·fg.check(&chk ,1 ,flag ,"flag is NULL, so nowhere to write result"); + Core·Guard·pft.check(&chk ,1 ,p ,"given NULL p"); + Core·Guard·pft.check(&chk ,1 ,flag ,"flag is NULL, so nowhere to write result"); Core·Guard·if_return(chk); #endif *flag = ( (uintptr_t)p & alignment ) == 0; @@ -198,8 +198,8 @@ Local Core·Status Core·round_down(AU *p ,extent_t·AU alignment ,AU **result){ #ifdef Core·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,p ,"given NULL p to round"); - Core·Guard·fg.check(&chk ,1 ,result ,"result is NULL, so nowhere to write result"); + Core·Guard·pft.check(&chk ,1 ,p ,"given NULL p to round"); + Core·Guard·pft.check(&chk ,1 ,result ,"result is NULL, so nowhere to write result"); Core·Guard·if_return(chk); #endif *result = (AU *)( (uintptr_t)p & ~(uintptr_t)alignment ); @@ -209,8 +209,8 @@ Local Core·Status Core·round_up(AU *p ,extent_t·AU alignment ,AU **result){ #ifdef Core·DEBUG Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,p ,"given NULL p to round"); - Core·Guard·fg.check(&chk ,1 ,result ,"result is NULL, so nowhere to write result"); + Core·Guard·pft.check(&chk ,1 ,p ,"given NULL p to round"); + Core·Guard·pft.check(&chk ,1 ,result ,"result is NULL, so nowhere to write result"); Core·Guard·if_return(chk); #endif *result = (AU *)( ( (uintptr_t)p + alignment ) & ~(uintptr_t)alignment ); diff --git "a/developer/cc\360\237\226\211/Map.lib.c" "b/developer/cc\360\237\226\211/Map.lib.c" deleted file mode 100644 index 2592129..0000000 --- "a/developer/cc\360\237\226\211/Map.lib.c" +++ /dev/null @@ -1,154 +0,0 @@ -/* Map - mapping functions between tape machines. - - This file has two template parameters: - `CVT_read` Cell Value Type for the source/read tape machine - `CVT_write` Cell Value Type for the destination/write tape machine - - By default (when the macros have no definition) the cell value types are taken as AU. - This file must be included with CVT_read and CVT_write undefined, before inclusions with them 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. -*/ - -#define Map·DEBUG - -#ifndef FACE - #define Map·IMPLEMENTATION - #define FACE -#endif - -//-------------------------------------------------------------------------------- -// Interface - -#ifndef Map·FACE - #define Map·FACE - - #include - #include - #include "Core.lib.c" - #include "TM.lib.c" - - // if only one template parameter is given, we will assume both are the same - - #if defined(CVT_read) && !defined(CVT_write) - #warning "Given CVT_read template value. Missing CVT_write template value, so setting it to CVT_read" - #define CVT_write CVT_read - #endif - - #if !defined(CVT_read) && defined(CVT_write) - #warning "Given CVT_write template value. Missing CVT_read template value, so setting it to CVT_write" - #define CVT_read CVT_write - #endif - - //---------------------------------------- - // Map status and completion enums - //---------------------------------------- - - #if !defined(CVT_read) && !defined(CVT_write) - - typedef enum { - Map·Completion·mu = 0 - ,Map·Completion·failed = 1 - ,Map·Completion·null_fn = 1 << 1 - ,Map·Completion·no_tape_access = 1 << 2 - ,Map·Completion·rightmost_read = 1 << 3 - ,Map·Completion·rightmost_write = 1 << 4 - } Map·Completion; - - // Masks for combinations - const uint Map·Completion·rightmost_both = - Map·Completion·rightmost_read - | Map·Completion·rightmost_write - ; - - const uint Map·Completion·derailed = - Map·Completion·failed - | Map·Completion·null_fn - | Map·Completion·no_tape_access - ; - - const uint Map·Completion·on_track = - Map·Completion·rightmost_read - | Map·Completion·rightmost_write - | Map·Completion·rightmost_both - ; - - #endif - - //---------------------------------------- - // Map interface - //---------------------------------------- - - #if !defined(CVT_read) || !defined(CVT_write) - - typedef struct { - Map·Completion (*copy_byte_to_byte)( - ·(TM·Array ,AU) *read_tm - ,·(TM·Array ,AU) *write_tm - ); - - Map·Completion (*copy_hex_to_byte)( - ·(TM·Array ,uint16_t) *read_tm - ,·(TM·Array ,AU) *write_tm - ); - - Map·Completion (*copy_byte_to_hex)( - ·(TM·Array ,AU) *read_tm - ,·(TM·Array ,uint16_t) *write_tm - ); - - // Terminate string function - Map·Completion (*terminate_string)( - ·(TM·Array ,AU) *write_tm - ); - } Map·FG; - - // a default function given table - Map·FG Map·fg; - - #endif - - - #if defined(CVT_read) && defined(CVT_write) - - // Function passed to map type signature must be this: - typedef Core·Status (*·(Map·fn ,CVT_read ,CVT_write))( - CVT_read *read_value - ,CVT_write *write_value - ); - - typedef struct { - // Map a function over all elements from read_tm to write_tm - Map·Completion (*map)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ); - - // Map a function over elements from read_tm to write_tm until a condition is met - Map·Completion (*map_while)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,bool (*condition)(·(TM·Array ,CVT_read) *read_tm) - ); - - // Map a function over n elements from read_tm to write_tm - Map·Completion (*map_extent)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,·(extent_t ,CVT_read) extent - ); - - } ·(Map·FG ,CVT_read ,CVT_write); - - // Default function given table - ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write); - - #endif - -#endif // #ifndef Map·FACE diff --git "a/developer/cc\360\237\226\211/Map2.lib.c" "b/developer/cc\360\237\226\211/Map2.lib.c" deleted file mode 100644 index e58173e..0000000 --- "a/developer/cc\360\237\226\211/Map2.lib.c" +++ /dev/null @@ -1,500 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/* Map - mapping functions between tape machines. - - This file has two template parameters: - `CVT_read` Cell Value Type for the source/read tape machine - `CVT_write` Cell Value Type for the destination/write tape machine - - By default (when the macros have no definition) the cell value types are taken as AU. - This file must be included with CVT_read and CVT_write undefined, before inclusions with them 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. -*/ - -#define Map·DEBUG - -#ifndef FACE - #define Map·IMPLEMENTATION - #define FACE -#endif - -//-------------------------------------------------------------------------------- -// Interface - -#ifndef Map·FACE - #define Map·FACE - - #include - #include - #include "Core.lib.c" - #include "TM.lib.c" - - // if only one template parameter is given, we will assume both are the same - - #if defined(CVT_read) && !defined(CVT_write) - #warning "Given CVT_read template value. Missing CVT_write template value, so setting it to CVT_read" - #define CVT_write CVT_read - #endif - - #if !defined(CVT_read) && defined(CVT_write) - #warning "Given CVT_write template value. Missing CVT_read template value, so setting it to CVT_write" - #define CVT_read CVT_write - #endif - - //---------------------------------------- - // Map status and completion enums - //---------------------------------------- - - #if !defined(CVT_read) && !defined(CVT_write) - - typedef enum { - Map·Completion·mu = 0 - ,Map·Completion·failed = 1 - ,Map·Completion·null_fn = 1 << 1 - ,Map·Completion·no_tape_access = 1 << 2 - ,Map·Completion·rightmost_read = 1 << 3 - ,Map·Completion·rightmost_write = 1 << 4 - } Map·Completion; - - // Masks for combinations - const uint Map·Completion·rightmost_both = - Map·Completion·rightmost_read - | Map·Completion·rightmost_write - ; - - const uint Map·Completion·derailed = - Map·Completion·failed - | Map·Completion·null_fn - | Map·Completion·no_tape_access - ; - - const uint Map·Completion·on_track = - Map·Completion·rightmost_read - | Map·Completion·rightmost_write - | Map·Completion·rightmost_both - ; - - #endif - - //---------------------------------------- - // Map interface - //---------------------------------------- - - #if !defined(CVT_read) || !defined(CVT_write) - typedef struct { - Map·Completion (*copy_byte_to_byte)( - ·(TM·Array ,AU) *read_tm - ,·(TM·Array ,AU) *write_tm - ); - - Map·Completion (*copy_hex_to_byte)( - ·(TM·Array ,uint16_t) *read_tm - ,·(TM·Array ,AU) *write_tm - ); - - Map·Completion (*copy_byte_to_hex)( - ·(TM·Array ,AU) *read_tm - ,·(TM·Array ,uint16_t) *write_tm - ); - - // Terminate string function - Map·Completion (*terminate_string)( - ·(TM·Array ,AU) *write_tm - ); - } - #endif - - - #if defined(CVT_read) && defined(CVT_write) - - // Function passed to map type signature must be this: - typedef Core·Status (*·(Map·fn ,CVT_read ,CVT_write))( - CVT_read *read_value - ,CVT_write *write_value - ); - - typedef struct { - // Map a function over all elements from read_tm to write_tm - Map·Completion (*map)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ); - - // Map a function over elements from read_tm to write_tm until a condition is met - Map·Completion (*map_while)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,bool (*condition)(·(TM·Array ,CVT_read) *read_tm) - ); - - // Map a function over n elements from read_tm to write_tm - Map·Completion (*map_extent)( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,·(extent_t ,CVT_read) extent - ); - - } ·(Map·FG ,CVT_read ,CVT_write); - - // Default function given table - ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write); - #endif // !defined(CVT_read) && !defined(CVT_write) - -#endif // #ifndef Map·FACE - -//-------------------------------------------------------------------------------- -// Implementation - -#ifdef Map·IMPLEMENTATION - - // declarations available to all of the IMPLEMENTATION go here - #ifdef Map·DEBUG - #include - #endif - - // implementation to go into the lib.a file - #ifndef LOCAL - #endif - - #ifdef LOCAL - //---------------------------------------- - // Map implementation - //---------------------------------------- - - #if !defined(CVT_read) && !defined(CVT_write) - //----------------------------------- - // common error messages - const char *Map·Msg·read_tm = "given NULL read_tm"; - const char *Map·Msg·write_tm = "given NULL write_tm"; - const char *Map·Msg·map_fn = "given NULL map_fn"; - const char *Map·Msg·condition = "given NULL condition function"; - - //----------------------------------- - // Helper functions for copy operations - - // Byte to byte copy function - Local Core·Status Map·byte_to_byte_fn(AU *read_value, AU *write_value) { - *write_value = *read_value; - return Core·Status·on_track; - } - - // Hex to byte conversion function - Local Core·Status Map·hex_to_byte_fn(uint16_t *read_value, AU *write_value) { - // Convert hex value to byte - *write_value = (AU)(*read_value & 0xFF); - return Core·Status·on_track; - } - - // Byte to hex conversion function - Local Core·Status Map·byte_to_hex_fn(AU *read_value, uint16_t *write_value) { - // Convert byte to lowercase hex representation (no prefix) - static const char hex_chars[] = "0123456789abcdef"; - *write_value = hex_chars[(*read_value >> 4) & 0x0F]; - return Core·Status·on_track; - } - #endif // !defined(CVT_read) && !defined(CVT_write) - - #if defined(CVT_read) && defined(CVT_write) - //----------------------------------- - // Map implementation with specific types - - // Map a function over all elements from read_tm to write_tm - Local Core·Status ·(Map ,CVT_read ,CVT_write)·map( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ){ - #ifdef Map·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); - Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); - Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); - Core·Guard·if_return(chk); - #endif - - // Rewind both tape machines to ensure we start at the beginning - ·(TM·Array ,CVT_read)·fg.rewind(read_tm); - ·(TM·Array ,CVT_write)·fg.rewind(write_tm); - - // Initial check if can_read (not part of the loop) - if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; - - // Track completion status - uint completion = 0; - - // Following the first-rest pattern described in TTCA - while(1){ - // Read value from source - CVT_read read_value; - ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); - - // Apply mapping function to get write value - CVT_write write_value; - Core·Status status = map_fn(&read_value ,&write_value); - if(status != Core·gStatus·on_track) { - completion |= Core·Map·Completion·failed; - return status; - } - - // Write result to destination - ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); - - // Check if we're at the rightmost position for read - bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); - if(read_rightmost) { - completion |= Core·Map·Completion·rightmost_read; - } - - // Check if we're at the rightmost position for write - bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); - if(write_rightmost) { - completion |= Core·Map·Completion·rightmost_write; - } - - // Break if either machine is at rightmost - if(read_rightmost || write_rightmost) break; - - // Step both machines - ·(TM·Array ,CVT_read)·fg.step(read_tm); - ·(TM·Array ,CVT_write)·fg.step(write_tm); - } - - return Core·Status·on_track; - } - - // Map a function over elements from read_tm to write_tm until a condition is met - Local Core·Status ·(Map ,CVT_read ,CVT_write)·map_while( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,bool (*condition)(CVT_read *value) - ){ - #ifdef Map·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); - Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); - Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); - Core·Guard·fg.check(&chk ,1 ,condition ,Map·Msg·condition); - Core·Guard·if_return(chk); - #endif - - // Rewind both tape machines to ensure we start at the beginning - ·(TM·Array ,CVT_read)·fg.rewind(read_tm); - ·(TM·Array ,CVT_write)·fg.rewind(write_tm); - - // Initial check if can_read (not part of the loop) - if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; - - // Track completion status - uint completion = 0; - - // Following the first-rest pattern described in TTCA - while(1){ - // Read value from source - CVT_read read_value; - ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); - - // Check condition - if(!condition(&read_value)) break; - - // Apply mapping function to get write value - CVT_write write_value; - Core·Status status = map_fn(&read_value ,&write_value); - if(status != Core·Status·on_track) { - completion |= Core·Map·Completion·failed; - return status; - } - - // Write result to destination - ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); - - // Check if we're at the rightmost position for read - bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); - if(read_rightmost) { - completion |= Core·Map·Completion·rightmost_read; - } - - // Check if we're at the rightmost position for write - bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); - if(write_rightmost) { - completion |= Core·Map·Completion·rightmost_write; - } - - // Break if either machine is at rightmost - if(read_rightmost || write_rightmost) break; - - // Step both machines - ·(TM·Array ,CVT_read)·fg.step(read_tm); - ·(TM·Array ,CVT_write)·fg.step(write_tm); - } - - return Core·Status·on_track; - } - - // Map a function over n elements from read_tm to write_tm - Local Core·Status ·(Map ,CVT_read ,CVT_write)·map_n( - ·(TM·Array ,CVT_read) *read_tm - ,·(TM·Array ,CVT_write) *write_tm - ,·(Map·fn ,CVT_read ,CVT_write) map_fn - ,size_t n - ){ - #ifdef Map·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); - Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); - Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); - Core·Guard·if_return(chk); - #endif - - // Rewind both tape machines to ensure we start at the beginning - ·(TM·Array ,CVT_read)·fg.rewind(read_tm); - ·(TM·Array ,CVT_write)·fg.rewind(write_tm); - - // Initial check if can_read (not part of the loop) - if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; - - // Track completion status - uint completion = 0; - - // Following the first-rest pattern described in TTCA - size_t count = 0; - while(count < n){ - // Read value from source - CVT_read read_value; - ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); - - // Apply mapping function to get write value - CVT_write write_value; - Core·Status status = map_fn(&read_value ,&write_value); - if(status != Core·Status·on_track) { - completion |= Core·Map·Completion·failed; - return status; - } - - // Write result to destination - ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); - - // Increment count - count++; - - // Check if we're at the rightmost position for read - bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); - if(read_rightmost) { - completion |= Core·Map·Completion·rightmost_read; - } - - // Check if we're at the rightmost position for write - bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); - if(write_rightmost) { - completion |= Core·Map·Completion·rightmost_write; - } - - // Break if either machine is at rightmost - if(read_rightmost || write_rightmost) break; - - // Step both machines - ·(TM·Array ,CVT_read)·fg.step(read_tm); - ·(TM·Array ,CVT_write)·fg.step(write_tm); - } - - return Core·Status·on_track; - } - - // Initialize the function given table - ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write) = { - .map = ·(Map ,CVT_read ,CVT_write)·map - ,.map_while = ·(Map ,CVT_read ,CVT_write)·map_while - ,.map_n = ·(Map ,CVT_read ,CVT_write)·map_n - }; - #endif // defined(CVT_read) && defined(CVT_write) - - //---------------------------------------- - // Copy functions implementation - //---------------------------------------- - - // Byte to byte copy - Local Core·Status Map·copy_byte_to_byte( - ·(TM·Array ,AU) *read_tm - ,·(TM·Array ,AU) *write_tm - ){ - #ifdef Map·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); - Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); - Core·Guard·if_return(chk); - #endif - - return ·(Map ,AU ,AU)·fg.map(read_tm, write_tm, Map·byte_to_byte_fn); - } - - // Hex to byte copy - Local Core·Status Map·copy_hex_to_byte( - ·(TM·Array ,uint16_t) *read_tm - ,·(TM·Array ,AU) *write_tm - ){ - #ifdef Map·DEBUG - Core·Guard·init_count(chk); - Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); - Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); - Core·Guard·if_return(chk); - #endif - - return To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for. diff --git "a/developer/cc\360\237\226\211/ParameterConnector.lib.c" "b/developer/cc\360\237\226\211/ParameterConnector.lib.c" new file mode 100644 index 0000000..86f2591 --- /dev/null +++ "b/developer/cc\360\237\226\211/ParameterConnector.lib.c" @@ -0,0 +1,74 @@ +/* +Namespace: ParameterConnector + +Defines a macro for declaring parameter connectors, and for calling a parameterized function. + +Declares a parameter connector, does not initialize it. + +*/ + +/*-------------------------------------------------------------------------------- + Interface +-------------------------------------------------------------------------------*/ + + +// once per translation unit +#ifndef ParameterConnector·FACE +#define ParameterConnector·FACE + + #define ParameterConnector·DEBUG + #ifdef ParameterConnector·DEBUG + #include + #pragma message( "ParameterConnector·FACE" ) + #endif + + #include "cpp_ext.c" + #include "Core.lib.c" + + /* + usage e.g.: ParameterConnector·call(tm, function_name, arg1, arg2, ...) + Expands to: (tm.pft->function_name)(tm ,arg1 ,arg2, ...) + + note the use of the comma operator to return the result from the b.pft->fn call + */ + #ifdef ParameterConnector·DEBUG + #include + #define ParameterConnector·call(pc_instance ,fn ,...) ( \ + assert((pc_instance).pft != NULL) \ + ,assert((pc_instance).tableau != NULL) \ + ,(b).pft->fn(b __VA_OPT__(,) __VA_ARGS__) \ + ) + #else + #define ParameterConnector·call(pc_instance ,fn ,...) \ + (pc_instance).pft->fn(pc_instance __VA_OPT__(,) __VA_ARGS__) + #endif + + #define ParameterConnector·DECLARE(type) \ + typedef struct ·(type ,PFT) ·(type ,PFT); \ + typedef struct ·(type ,Tableau) ·(type ,Tableau); \ + typedef struct type { \ + ·(type ,Tableau) *tableau; \ + ·(type ,PFT) *pft; \ + } type; + +#endif + + + +/*-------------------------------------------------------------------------------- + Local - at bottom of translation unit, to keep some functions private + ParameterConnector currently has no local component +--------------------------------------------------------------------------------*/ +#ifdef LOCAL + +#endif + +/*-------------------------------------------------------------------------------- + Library - compiled into a lib.a file by the current make + ParameterConnector has no library component +--------------------------------------------------------------------------------*/ +#ifdef LIBRARY + +#endif + + diff --git "a/developer/cc\360\237\226\211/TM.lib.c" "b/developer/cc\360\237\226\211/TM.lib.c" index 6f5f1a9..ac59356 100644 --- "a/developer/cc\360\237\226\211/TM.lib.c" +++ "b/developer/cc\360\237\226\211/TM.lib.c" @@ -7,7 +7,7 @@ TM - Tape Machine Model Caller must declare TM set members: - #define SET__Binding__TM· // replacing with the actual value of CVT + #define SET_Binding__TM· // replacing with the actual value of CVT */ @@ -63,21 +63,18 @@ #endif //#ifndef TM·FACE // once per _TM·CVT_ value -// Caller must #define SET__Binding__TM·, after inclusion, to prevent re-inclusion +// Caller must #define SET_Binding__TM·, after inclusion, to prevent re-inclusion #ifdef _TM·CVT_ -#if BOOLEAN( NOT_IN(Binding ,·(TM,_TM·CVT_)) ) +#if BOOLEAN( NOT_IN(TM ,_TM·CVT_) ) #ifdef TM·DEBUG #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) #endif - #define _BINDING_ ·(TM,_TM·CVT_) - #include "Binding.lib.c" - - // debug: TM·AU tm_binding; - typedef size_t ·(extent_t,_TM·CVT_); - typedef struct ·(TM,_TM·CVT_,FG){ + ParameterConnector·DECLARE( ·(TM,_TM·CVT_) ) + + typedef struct ·(TM,_TM·CVT_,PFT){ TM·Topo (*topo) ( ·(TM,_TM·CVT_) tm ); bool (*bounded) ( ·(TM,_TM·CVT_) tm ); @@ -94,84 +91,17 @@ void (*dismount) ( ·(TM,_TM·CVT_) 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 ); _TM·CVT_ (*read) ( ·(TM,_TM·CVT_) tm ); void (*write) ( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ); - } ·(TM,_TM·CVT_,FG); - - //---------------------------------------- - // ZeroLength tape interface - - typedef struct{ - bool hd; - } ·(TM,_TM·CVT_,ZeroLength,Tableau); - - ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,init)( - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t - ); - - //---------------------------------------- - // SingletonSegment tape interface - - typedef struct{ - bool hd; - _TM·CVT_ value; - } ·(TM,_TM·CVT_,SingletonSegment,Tableau); - - ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,SingletonSegment,init)( - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t - ,_TM·CVT_ initial_value - ); - - //---------------------------------------- - // SingletonCircle tape interface - - typedef struct{ - bool hd; - _TM·CVT_ value; - } ·(TM,_TM·CVT_,SingletonCircle,Tableau); + } ·(TM,_TM·CVT_,PFT); - ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,SingletonCircle,init)( - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t - ,_TM·CVT_ initial_value - ); - //---------------------------------------- - // Array interface - - // Not exposing the implementation would be better, but the user needs to allocate these before calling init. - typedef struct{ - _TM·CVT_ *hd; - _TM·CVT_ *position; - ·(extent_t,_TM·CVT_) extent; - } ·(TM,_TM·CVT_,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. - - Calling init is the only time the user/programmer will need to know the implementation name. - - The resulting binding object returned is what the user will call an instance of the - type. - */ - ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,Array,init_pe)( - ·(TM,_TM·CVT_,Array,Tableau) *t - ,_TM·CVT_ position[] - ,·(extent_t,_TM·CVT_) extent - ); - - ·(TM,_TM·CVT_) ·(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_ +#endif +#endif /*-------------------------------------------------------------------------------- Local @@ -193,481 +123,13 @@ #endif // once per _TM·CVT_ value - // Caller must #define SET__TM·LOCAL__TM·, after inclusion, to prevent re-inclusion + // 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_) ) + #pragma message( "Including TM LOCAL code for:" STR_VAL(_TM·CVT_) ) #endif - /*------------------------------------------------------------------------ - ZeroLength tape implementation - */ - - Local TM·Topo ·(TM,_TM·CVT_,ZeroLength,topo)( ·(TM,_TM·CVT_) tm ){ - return TM·Topo·zero_length; - } - - Local bool ·(TM,_TM·CVT_,ZeroLength,bounded)( ·(TM,_TM·CVT_) tm ){ - return true; - } - - Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,extent)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - - Local TM·Status ·(TM,_TM·CVT_,ZeroLength,status)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; - if( !t->hd ) return TM·Status·dismounted; - return TM·Status·out_of_area; - } - - Local bool ·(TM,_TM·CVT_,ZeroLength,dismounted)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; - return !t->hd; - } - - Local bool ·(TM,_TM·CVT_,ZeroLength,on_tape)( ·(TM,_TM·CVT_) tm ){ - return false; - } - - Local bool ·(TM,_TM·CVT_,ZeroLength,on_leftmost)( ·(TM,_TM·CVT_) tm ){ - return false; - } - - Local bool ·(TM,_TM·CVT_,ZeroLength,on_rightmost)( ·(TM,_TM·CVT_) tm ){ - return false; - } - - // does nothing if tape is already mounted - Local void ·(TM,_TM·CVT_,ZeroLength,mount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; - if( !t->hd ) t->hd = true; - } - - Local void ·(TM,_TM·CVT_,ZeroLength,dismount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; - t->hd = false; - } - - Local void ·(TM,_TM·CVT_,ZeroLength,step)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - - Local void ·(TM,_TM·CVT_,ZeroLength,step_left)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - - // rewind does nothing if the tape is dismounted - Local void ·(TM,_TM·CVT_,ZeroLength,rewind)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; - if( ·(TM,_TM·CVT_,ZeroLength,dismounted)( tm ) ) return; - assert(0); - } - - Local _TM·CVT_ ·(TM,_TM·CVT_,ZeroLength,read)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - - Local void ·(TM,_TM·CVT_,ZeroLength,write)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ - assert(0); - } - - Local ·(TM,_TM·CVT_,FG) ·(TM,_TM·CVT_,ZeroLength,fg) = { - - .topo = ·(TM,_TM·CVT_,ZeroLength,topo) - ,.bounded = ·(TM,_TM·CVT_,ZeroLength,bounded) - ,.extent = ·(TM,_TM·CVT_,ZeroLength,extent) - - ,.status = ·(TM,_TM·CVT_,ZeroLength,status) - ,.dismounted = ·(TM,_TM·CVT_,ZeroLength,dismounted) - ,.on_tape = ·(TM,_TM·CVT_,ZeroLength,on_tape) - ,.on_leftmost = ·(TM,_TM·CVT_,ZeroLength,on_leftmost) - ,.on_rightmost = ·(TM,_TM·CVT_,ZeroLength,on_rightmost) - - ,.mount = ·(TM,_TM·CVT_,ZeroLength,mount) - ,.dismount = ·(TM,_TM·CVT_,ZeroLength,dismount) - - ,.step = ·(TM,_TM·CVT_,ZeroLength,step) - ,.step_right = ·(TM,_TM·CVT_,ZeroLength,step) - ,.step_left = ·(TM,_TM·CVT_,ZeroLength,step_left) - ,.rewind = ·(TM,_TM·CVT_,ZeroLength,rewind) - - ,.read = ·(TM,_TM·CVT_,ZeroLength,read) - ,.write = ·(TM,_TM·CVT_,ZeroLength,write) - - }; - - ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,init)( - ·(TM,_TM·CVT_,ZeroLength,Tableau) *t - ){ - t->hd = true; - ·(TM,_TM·CVT_) tm = { - .tableau = (·(TM,_TM·CVT_,Tableau) *)t - ,.fg = &·(TM,_TM·CVT_,ZeroLength,fg) - }; - return tm; - } - - /*------------------------------------------------------------------------ - SingletonSegment tape - */ - - Local TM·Topo ·(TM,_TM·CVT_,SingletonSegment,topo)( ·(TM,_TM·CVT_) tm ){ - return TM·Topo·singleton; - } - Local bool ·(TM,_TM·CVT_,SingletonSegment,bounded)( ·(TM,_TM·CVT_) tm ){ - return true; - } - Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,SingletonSegment,extent)( ·(TM,_TM·CVT_) tm ){ - return 0; - } - Local TM·Status ·(TM,_TM·CVT_,SingletonSegment,status)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - if( !t->hd ) return TM·Status·dismounted; - return TM·Status·leftmost | TM·Status·rightmost; - } - Local bool ·(TM,_TM·CVT_,SingletonSegment,dismounted)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - return !t->hd; - } - - // these could be pulled from the tm.fg table, and defined once - Local bool ·(TM,_TM·CVT_,SingletonSegment,on_tape)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·on_tape; - } - Local bool ·(TM,_TM·CVT_,SingletonSegment,on_leftmost)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·leftmost; - } - Local bool ·(TM,_TM·CVT_,SingletonSegment,on_rightmost)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·rightmost; - } - - // does nothing if tape is already mounted - Local void ·(TM,_TM·CVT_,SingletonSegment,mount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - t->hd = true; - } - Local void ·(TM,_TM·CVT_,SingletonSegment,dismount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - t->hd = false; - } - - Local void ·(TM,_TM·CVT_,SingletonSegment,step)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - Local void ·(TM,_TM·CVT_,SingletonSegment,step_left)( ·(TM,_TM·CVT_) tm ){ - assert(0); - } - Local void ·(TM,_TM·CVT_,SingletonSegment,rewind)( ·(TM,_TM·CVT_) tm ){ - return; - } - - Local _TM·CVT_ ·(TM,_TM·CVT_,SingletonSegment,read)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - return t->value; - } - Local void ·(TM,_TM·CVT_,SingletonSegment,write)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; - t->value = *remote_pt; - } - - Local ·(TM,_TM·CVT_,FG) ·(TM,_TM·CVT_,SingletonSegment,fg) = { - - .topo = ·(TM,_TM·CVT_,SingletonSegment,topo) - ,.bounded = ·(TM,_TM·CVT_,SingletonSegment,bounded) - ,.extent = ·(TM,_TM·CVT_,SingletonSegment,extent) - - ,.status = ·(TM,_TM·CVT_,SingletonSegment,status) - ,.dismounted = ·(TM,_TM·CVT_,SingletonSegment,dismounted) - ,.on_tape = ·(TM,_TM·CVT_,SingletonSegment,on_tape) - ,.on_leftmost = ·(TM,_TM·CVT_,SingletonSegment,on_leftmost) - ,.on_rightmost = ·(TM,_TM·CVT_,SingletonSegment,on_rightmost) - - ,.mount = ·(TM,_TM·CVT_,SingletonSegment,mount) - ,.dismount = ·(TM,_TM·CVT_,SingletonSegment,dismount) - - ,.step = ·(TM,_TM·CVT_,SingletonSegment,step) - ,.step_right = ·(TM,_TM·CVT_,SingletonSegment,step) - ,.step_left = ·(TM,_TM·CVT_,SingletonSegment,step_left) - ,.rewind = ·(TM,_TM·CVT_,SingletonSegment,rewind) - - ,.read = ·(TM,_TM·CVT_,SingletonSegment,read) - ,.write = ·(TM,_TM·CVT_,SingletonSegment,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_,SingletonSegment,init)( - ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t - ,_TM·CVT_ initial_value - ){ - t->hd = true; - t->value = initial_value; - - ·(TM,_TM·CVT_) tm = { - .tableau = (·(TM,_TM·CVT_,Tableau) *)t - ,.fg = &·(TM,_TM·CVT_,SingletonSegment,fg) - }; - - return tm; - } - - - /*------------------------------------------------------------------------ - SingletonCircle tape - */ - - Local TM·Topo ·(TM,_TM·CVT_,SingletonCircle,topo)( ·(TM,_TM·CVT_) tm ){ - return TM·Topo·circle; - } - Local bool ·(TM,_TM·CVT_,SingletonCircle,bounded)( ·(TM,_TM·CVT_) tm ){ - return false; - } - Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,SingletonCircle,extent)( ·(TM,_TM·CVT_) tm ){ - return 0; - } - Local TM·Status ·(TM,_TM·CVT_,SingletonCircle,status)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - if( !t->hd ) return TM·Status·dismounted; - return TM·Status·interim; - } - Local bool ·(TM,_TM·CVT_,SingletonCircle,dismounted)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - return !t->hd; - } - - // these could be pulled from the tm.fg table, and defined once - Local bool ·(TM,_TM·CVT_,SingletonCircle,on_tape)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - return t->hd; - } - Local bool ·(TM,_TM·CVT_,SingletonCircle,on_leftmost)( ·(TM,_TM·CVT_) tm ){ - return false; - } - Local bool ·(TM,_TM·CVT_,SingletonCircle,on_rightmost)( ·(TM,_TM·CVT_) tm ){ - return false; - } - - // does nothing if tape is already mounted - Local void ·(TM,_TM·CVT_,SingletonCircle,mount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - t->hd = true; - } - Local void ·(TM,_TM·CVT_,SingletonCircle,dismount)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - t->hd = false; - } - - Local void ·(TM,_TM·CVT_,SingletonCircle,step)( ·(TM,_TM·CVT_) tm ){ - return; - } - Local void ·(TM,_TM·CVT_,SingletonCircle,step_left)( ·(TM,_TM·CVT_) tm ){ - return; - } - Local void ·(TM,_TM·CVT_,SingletonCircle,rewind)( ·(TM,_TM·CVT_) tm ){ - return; - } - - Local _TM·CVT_ ·(TM,_TM·CVT_,SingletonCircle,read)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - return t->value; - } - Local void ·(TM,_TM·CVT_,SingletonCircle,write)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; - t->value = *remote_pt; - } - - Local ·(TM,_TM·CVT_,FG) ·(TM,_TM·CVT_,SingletonCircle,fg) = { - - .topo = ·(TM,_TM·CVT_,SingletonCircle,topo) - ,.bounded = ·(TM,_TM·CVT_,SingletonCircle,bounded) - ,.extent = ·(TM,_TM·CVT_,SingletonCircle,extent) - - ,.status = ·(TM,_TM·CVT_,SingletonCircle,status) - ,.dismounted = ·(TM,_TM·CVT_,SingletonCircle,dismounted) - ,.on_tape = ·(TM,_TM·CVT_,SingletonCircle,on_tape) - ,.on_leftmost = ·(TM,_TM·CVT_,SingletonCircle,on_leftmost) - ,.on_rightmost = ·(TM,_TM·CVT_,SingletonCircle,on_rightmost) - - ,.mount = ·(TM,_TM·CVT_,SingletonCircle,mount) - ,.dismount = ·(TM,_TM·CVT_,SingletonCircle,dismount) - - ,.step = ·(TM,_TM·CVT_,SingletonCircle,step) - ,.step_right = ·(TM,_TM·CVT_,SingletonCircle,step) - ,.step_left = ·(TM,_TM·CVT_,SingletonCircle,step_left) - ,.rewind = ·(TM,_TM·CVT_,SingletonCircle,rewind) - - ,.read = ·(TM,_TM·CVT_,SingletonCircle,read) - ,.write = ·(TM,_TM·CVT_,SingletonCircle,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_,SingletonCircle,init)( - ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t - ,_TM·CVT_ initial_value - ){ - t->hd = true; - t->value = initial_value; - - ·(TM,_TM·CVT_) tm = { - .tableau = (·(TM,_TM·CVT_,Tableau) *)t - ,.fg = &·(TM,_TM·CVT_,SingletonCircle,fg) - }; - - return tm; - } - - - /*------------------------------------------------------------------------ - Array implementation with a segment tape - */ - - Local TM·Topo ·(TM,_TM·CVT_,Array,topo)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,Array,Tableau) *t = (·(TM,_TM·CVT_,Array,Tableau) *) tm.tableau; - if( t->extent == 0 ) return TM·Topo·singleton; - return TM·Topo·segment; - } - - Local bool ·(TM,_TM·CVT_,Array,bounded)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,Array,Tableau) *t = (·(TM,_TM·CVT_,Array,Tableau) *) tm.tableau; - return ·(TM,_TM·CVT_,Array,topo)( tm ) & TM·Topo·bounded; - } - - Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,Array,extent)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,Array,Tableau) *t = (·(TM,_TM·CVT_,Array,Tableau) *) tm.tableau; - return t->extent; - } - - - Local TM·Status ·(TM,_TM·CVT_,Array,status)( ·(TM,_TM·CVT_) tm ){ - ·(TM,_TM·CVT_,Array,Tableau) *t = (·(TM,_TM·CVT_,Array,Tableau) *) tm.tableau; - if( !t->hd ) return TM·Status·dismounted; - if( t->hd == t->position ) return TM·Status·leftmost; - - _TM·CVT_ *rightmost_pt = t->position + t->extent; - if( t->hd == rightmost_pt ) return TM·Status·rightmost; - if( t->hd < t->position || t->hd > rightmost_pt ) - return TM·Status·out_of_area; - - return TM·Status·interim; - } - - Local bool ·(TM,_TM·CVT_,Array,dismounted)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,Array,status)( tm ) & TM·Status·dismounted; - } - - Local bool ·(TM,_TM·CVT_,Array,on_tape)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,Array,status)( tm ) & TM·Status·on_tape; - } - - Local bool ·(TM,_TM·CVT_,Array,on_leftmost)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,Array,status)( tm ) & TM·Status·leftmost; - } - - Local bool ·(TM,_TM·CVT_,Array,on_rightmost)( ·(TM,_TM·CVT_) tm ){ - return ·(TM,_TM·CVT_,Array,status)( tm ) & TM·Status·rightmost; - } - - // does nothing if tape 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; - } - - 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--; - } - - // rewind does nothing if the tape is dismounted - 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,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; - *t->hd = *remote_pt; - } - - Local ·(TM,_TM·CVT_,FG) ·(TM,_TM·CVT_,Array,fg) = { - - .topo = ·(TM,_TM·CVT_,Array,topo) - ,.bounded = ·(TM,_TM·CVT_,Array,bounded) - ,.extent = ·(TM,_TM·CVT_,Array,extent) - - ,.status = ·(TM,_TM·CVT_,Array,status) - ,.dismounted = ·(TM,_TM·CVT_,Array,dismounted) - ,.on_tape = ·(TM,_TM·CVT_,Array,on_tape) - ,.on_leftmost = ·(TM,_TM·CVT_,Array,on_leftmost) - ,.on_rightmost = ·(TM,_TM·CVT_,Array,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 = { - .tableau = (·(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 - ){ - return ·(TM,_TM·CVT_,Array,init_pe)( - t ,position_left ,position_right - position_left - ); - } - - #endif // #if BOOLEAN(NOT_IN(TM·LOCAL ,TM)) #endif // #ifdef _TM·CVT_ @@ -679,8 +141,3 @@ --------------------------------------------------------------------------------*/ #ifdef LIBRARY #endif - -//-------------------------------------------------------------------------------- -// undef the template parameters -//-------------------------------------------------------------------------------- -#undef _TM·CVT_ diff --git "a/developer/cc\360\237\226\211/TM\302\267Array.lib.c" "b/developer/cc\360\237\226\211/TM\302\267Array.lib.c" new file mode 100644 index 0000000..a8fd814 --- /dev/null +++ "b/developer/cc\360\237\226\211/TM\302\267Array.lib.c" @@ -0,0 +1,243 @@ +/* + Namespace: TM·Array + + Template parameters: + + `_TM·CVT_` Cell Value Type`. + +*/ +#include "TM.lib.c" + +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ + +// once per translation unit +#ifndef TM·Array·FACE +#define TM·Array·FACE + + #define TM·Array·DEBUG + #ifdef TM·Array·DEBUG + #include + #endif + +#endif + +// once per _TM·CVT_ value +// Caller must #define SET_TM·Array·, after inclusion, to prevent re-inclusion +#ifdef _TM·CVT_ +#if BOOLEAN( NOT_IN(TM·Array ,_TM·CVT_) ) + + #include "TM.Lib.c" + + #pragma push(T) + #pragma push(TA) + #pragma push(TE) + + #define T ·(TM,_TM·CVT_) + #define TA ·(TM,Array,_TM·CVT_) + #define TE ·(extent_t,_TM·CVT_) + + #ifdef TM·Array·DEBUG + #pragma message( "Declaring:" STR_VAL(TA) ) + #endif + + typedef struct{ + _TM·CVT_ *hd; + _TM·CVT_ *position; + TE extent; + } ·(TA,Tableau); + + // call signatures for the initialization functions + // + T ·(TA,init_pe)( + ·(TA,Tableau) *t ,_TM·CVT_ position[] ,TE extent + ); + + T ·(TA,init_pp)( + ·(TA,Tableau) *t ,_TM·CVT_ *position_left ,_TM·CVT_ *position_right + ); + + #pragma pop(T) + #pragma pop(TA) + #pragma pop(TE) + +#endif +#endif + +/*-------------------------------------------------------------------------------- + Local +--------------------------------------------------------------------------------*/ +#ifdef LOCAL + + // once per translation unit + #ifndef TM·Array·LOCAL + #define TM·Array·LOCAL + + #endif + + // once per _TM·CVT_ value + #ifdef _TM·CVT_ + #if BOOLEAN( NOT_IN(TM·Array·LOCAL ,_TM·CVT_) ) + + #include "TM.Lib.c" + + #pragma push(T) + #pragma push(TA) + #pragma push(TE) + + #define T ·(TM,_TM·CVT_) + #define TA ·(TM,Array,_TM·CVT_) + #define TE ·(extent_t,_TM·CVT_) + + #ifdef TM·Array·DEBUG + #pragma message( "LOCAL:" STR_VAL(TA) ) + #endif + + Local TM·Topo ·(TA,topo)(T tm){ + ·(TM,_TM·CVT_,Array,Tableau) *t = (·(TM,_TM·CVT_,Array,Tableau) *) tm.tableau; + if( t->extent == 0 ) return TM·Topo·singleton; + return TM·Topo·segment; + } + Local bool ·(TA,bounded)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + return ·(TA,topo)(tm) & TM·Topo·bounded; + } + Local TE ·(TA,extent)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + return t->extent; + } + + Local TM·Status ·(TA,status)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + if( !t->hd ) return TM·Status·dismounted; + if( t->hd == t->position ) return TM·Status·leftmost; + + _TM·CVT_ *rightmost_pt = t->position + t->extent; + if( t->hd == rightmost_pt ) return TM·Status·rightmost; + if( t->hd < t->position || t->hd > rightmost_pt ) + return TM·Status·out_of_area; + + return TM·Status·interim; + } + + Local bool ·(TA,dismounted)(T tm){ + return ·(TA,status)( tm ) & TM·Status·dismounted; + } + + Local bool ·(TA,on_tape)(T tm){ + return ·(TA,status)( tm ) & TM·Status·on_tape; + } + + Local bool ·(TA,on_leftmost)(T tm){ + return ·(TA,status)( tm ) & TM·Status·leftmost; + } + + Local bool ·(TA,on_rightmost)(T tm){ + return ·(TA,status)( tm ) & TM·Status·rightmost; + } + + // does nothing if tape is already mounted + Local void ·(TA,mount)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + if( !t->hd ) t->hd = t->position; + } + + Local void ·(TA,dismount)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + t->hd = NULL; + } + + Local void ·(TA,step)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + t->hd++; + } + + Local void ·(TA,step_left)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + t->hd--; + } + + // rewind does nothing if the tape is dismounted + Local void ·(TA,rewind)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + if( ·(TA,dismounted)( tm ) ) return; + t->hd = t->position; + } + + Local _TM·CVT_ ·(TA,read)(T tm){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + return *t->hd; + } + + Local void ·(TA,write)(T tm ,_TM·CVT_ *remote_pt){ + ·(TA,Tableau) *t = (·(TA,Tableau) *) tm.tableau; + *t->hd = *remote_pt; + } + + Local ·(TM,_TM·CVT_,PFT) ·(TA,pft) = { + + .topo = ·(TA,topo) + ,.bounded = ·(TA,bounded) + ,.extent = ·(TA,extent) + + ,.status = ·(TA,status) + ,.dismounted = ·(TA,dismounted) + ,.on_tape = ·(TA,on_tape) + ,.on_leftmost = ·(TA,on_leftmost) + ,.on_rightmost = ·(TA,on_rightmost) + + ,.mount = ·(TA,mount) + ,.dismount = ·(TA,dismount) + + ,.step = ·(TA,step) + ,.step_left = ·(TA,step_left) + ,.rewind = ·(TA,rewind) + + ,.read = ·(TA,read) + ,.write = ·(TA,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_) ·(TA,init_pe)( + ·(TA,Tableau) *t + ,_TM·CVT_ *position + ,TE extent + ){ + t->hd = position; + t->position = position; + t->extent = extent; + + T tm = { + .tableau = (·(TM,_TM·CVT_,Tableau) *)t + ,.pft = &·(TA,pft) + }; + + return tm; + } + + ·(TM,_TM·CVT_) ·(TA,init_pp)( + ·(TA,Tableau) *t + ,_TM·CVT_ *position_left + ,_TM·CVT_ *position_right + ){ + return ·(TA,init_pe)( + t ,position_left ,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/TM\302\267SingletonCircle.lib.c" "b/developer/cc\360\237\226\211/TM\302\267SingletonCircle.lib.c" new file mode 100644 index 0000000..ee7abe7 --- /dev/null +++ "b/developer/cc\360\237\226\211/TM\302\267SingletonCircle.lib.c" @@ -0,0 +1,182 @@ +/* + Namespace: TM + Template parameters: + + `_TM·CVT_` Cell Value Type`. + + TM - Tape Machine Model + + Caller must declare TM set members: + #define SET_Binding__TM· // replacing with the actual value of CVT + +*/ + +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ + +// once per translation unit +#ifndef TM·FACE +#define TM·FACE + + #define TM·SingletonCircle·DEBUG + #ifdef TM·SingletonCircle·DEBUG + #include + #endif + +#endif //#ifndef TM·FACE + +// once per _TM·CVT_ value +// Caller must #define SET_Binding__TM·SingletonCircle·, after inclusion, to prevent re-inclusion +#ifdef _TM·CVT_ +#if BOOLEAN( NOT_IN(Binding ,·(TM·SingletonCircle,_TM·CVT_)) ) +#ifdef TM·DEBUG + #pragma message( "Creating TM·SingletonCircle type with a CVT of:" STR_VAL(_TM·CVT_) ) +#endif + + typedef struct{ + bool hd; + _TM·CVT_ value; + } ·(TM,_TM·CVT_,SingletonCircle,Tableau); + + ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,SingletonCircle,init)( + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t + ,_TM·CVT_ initial_value + ); + +#endif // #if BOOLEAN( NOT_IN(Binding ,TM) ) +#endif // #ifdef _TM·CVT_ + +/*-------------------------------------------------------------------------------- + Local +--------------------------------------------------------------------------------*/ +#ifdef LOCAL + + // once per translation unit + #ifndef TM·SingletonCircle·LOCAL + #define TM·SingletonCircle·LOCAL + + #endif + + // 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·SingletonCircle·LOCAL ,·(TM,_TM·CVT_))) + #ifdef TM·SingletonCircle·DEBUG + #pragma message( "Including TM·SingletonCircle LOCAL code for:" STR_VAL(_TM·CVT_) ) + #endif + + Local TM·Topo ·(TM,_TM·CVT_,SingletonCircle,topo)( ·(TM,_TM·CVT_) tm ){ + return TM·Topo·circle; + } + Local bool ·(TM,_TM·CVT_,SingletonCircle,bounded)( ·(TM,_TM·CVT_) tm ){ + return false; + } + Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,SingletonCircle,extent)( ·(TM,_TM·CVT_) tm ){ + return 0; + } + Local TM·Status ·(TM,_TM·CVT_,SingletonCircle,status)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + if( !t->hd ) return TM·Status·dismounted; + return TM·Status·interim; + } + Local bool ·(TM,_TM·CVT_,SingletonCircle,dismounted)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + return !t->hd; + } + + // these could be pulled from the tm.pft table, and defined once + Local bool ·(TM,_TM·CVT_,SingletonCircle,on_tape)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + return t->hd; + } + Local bool ·(TM,_TM·CVT_,SingletonCircle,on_leftmost)( ·(TM,_TM·CVT_) tm ){ + return false; + } + Local bool ·(TM,_TM·CVT_,SingletonCircle,on_rightmost)( ·(TM,_TM·CVT_) tm ){ + return false; + } + + // does nothing if tape is already mounted + Local void ·(TM,_TM·CVT_,SingletonCircle,mount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + t->hd = true; + } + Local void ·(TM,_TM·CVT_,SingletonCircle,dismount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + t->hd = false; + } + + Local void ·(TM,_TM·CVT_,SingletonCircle,s)( ·(TM,_TM·CVT_) tm ){ + return; + } + Local void ·(TM,_TM·CVT_,SingletonCircle,step_left)( ·(TM,_TM·CVT_) tm ){ + return; + } + Local void ·(TM,_TM·CVT_,SingletonCircle,rewind)( ·(TM,_TM·CVT_) tm ){ + return; + } + + Local _TM·CVT_ ·(TM,_TM·CVT_,SingletonCircle,r)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + return t->value; + } + Local void ·(TM,_TM·CVT_,SingletonCircle,w)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t = (·(TM,_TM·CVT_,SingletonCircle,Tableau) *) tm.tableau; + t->value = *remote_pt; + } + + Local ·(TM,_TM·CVT_,PFT) ·(TM,_TM·CVT_,SingletonCircle,pft) = { + + .topo = ·(TM,_TM·CVT_,SingletonCircle,topo) + ,.bounded = ·(TM,_TM·CVT_,SingletonCircle,bounded) + ,.extent = ·(TM,_TM·CVT_,SingletonCircle,extent) + + ,.status = ·(TM,_TM·CVT_,SingletonCircle,status) + ,.dismounted = ·(TM,_TM·CVT_,SingletonCircle,dismounted) + ,.on_tape = ·(TM,_TM·CVT_,SingletonCircle,on_tape) + ,.on_leftmost = ·(TM,_TM·CVT_,SingletonCircle,on_leftmost) + ,.on_rightmost = ·(TM,_TM·CVT_,SingletonCircle,on_rightmost) + + ,.mount = ·(TM,_TM·CVT_,SingletonCircle,mount) + ,.dismount = ·(TM,_TM·CVT_,SingletonCircle,dismount) + + ,.step = ·(TM,_TM·CVT_,SingletonCircle,s) + ,.step_left = ·(TM,_TM·CVT_,SingletonCircle,step_left) + ,.rewind = ·(TM,_TM·CVT_,SingletonCircle,rewind) + + ,.r = ·(TM,_TM·CVT_,SingletonCircle,r) + ,.w = ·(TM,_TM·CVT_,SingletonCircle,w) + + }; + + /* + 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_,SingletonCircle,init)( + ·(TM,_TM·CVT_,SingletonCircle,Tableau) *t + ,_TM·CVT_ initial_value + ){ + t->hd = true; + t->value = initial_value; + + ·(TM,_TM·CVT_) tm = { + .tableau = (·(TM,_TM·CVT_,Tableau) *)t + ,.pft = &·(TM,_TM·CVT_,SingletonCircle,pft) + }; + + return tm; + } + + #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/TM\302\267SingletonSegment.lib.c" "b/developer/cc\360\237\226\211/TM\302\267SingletonSegment.lib.c" new file mode 100644 index 0000000..90d55f7 --- /dev/null +++ "b/developer/cc\360\237\226\211/TM\302\267SingletonSegment.lib.c" @@ -0,0 +1,178 @@ +/* + Namespace: TM·SingletonSegment + + Template parameters: + + `_TM·CVT_` Cell Value Type`. + +*/ +#include "TM.lib.c" + +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ + +// once per translation unit +#ifndef TM·FACE +#define TM·FACE + + #define TM·SingletonSegment·DEBUG + #ifdef TM·SingletonSegment·DEBUG + #include + #endif + +#endif //#ifndef TM·FACE + +// once per _TM·CVT_ value +// Caller must #define SET_Binding__TM·SingletonSegment·, after inclusion, to prevent re-inclusion +#ifdef _TM·CVT_ +#if BOOLEAN( NOT_IN(Binding ,·(TM·SingletonSegment,_TM·CVT_)) ) +#ifdef TM·SingletonSegment·DEBUG + #pragma message( "Creating TM·SingletonSegment type with a CVT of:" STR_VAL(_TM·CVT_) ) +#endif + + typedef struct{ + bool hd; + _TM·CVT_ value; + } ·(TM,_TM·CVT_,SingletonSegment,Tableau); + + ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,SingletonSegment,init)( + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t + ,_TM·CVT_ initial_value + ); + +#endif +#endif + +/*-------------------------------------------------------------------------------- + Local +--------------------------------------------------------------------------------*/ +#ifdef LOCAL + + // once per translation unit + #ifndef TM·SingletonSegment·LOCAL + #define TM·SingletonSegment·LOCAL + + #endif + + // 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·SingletonSegment,_TM·CVT_))) + #ifdef TM·SingletonSegment·DEBUG + #pragma message( "Including TM·SingletonSegment LOCAL code for:" STR_VAL(_TM·CVT_) ) + #endif + + Local TM·Topo ·(TM,_TM·CVT_,SingletonSegment,topo)( ·(TM,_TM·CVT_) tm ){ + return TM·Topo·singleton; + } + Local bool ·(TM,_TM·CVT_,SingletonSegment,bounded)( ·(TM,_TM·CVT_) tm ){ + return true; + } + Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,SingletonSegment,extent)( ·(TM,_TM·CVT_) tm ){ + return 0; + } + Local TM·Status ·(TM,_TM·CVT_,SingletonSegment,status)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + if( !t->hd ) return TM·Status·dismounted; + return TM·Status·leftmost | TM·Status·rightmost; + } + Local bool ·(TM,_TM·CVT_,SingletonSegment,dismounted)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + return !t->hd; + } + + // these could be pulled from the tm.pft table, and defined once + Local bool ·(TM,_TM·CVT_,SingletonSegment,on_tape)( ·(TM,_TM·CVT_) tm ){ + return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·on_tape; + } + Local bool ·(TM,_TM·CVT_,SingletonSegment,on_leftmost)( ·(TM,_TM·CVT_) tm ){ + return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·leftmost; + } + Local bool ·(TM,_TM·CVT_,SingletonSegment,on_rightmost)( ·(TM,_TM·CVT_) tm ){ + return ·(TM,_TM·CVT_,SingletonSegment,status)( tm ) & TM·Status·rightmost; + } + + // does nothing if tape is already mounted + Local void ·(TM,_TM·CVT_,SingletonSegment,mount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + t->hd = true; + } + Local void ·(TM,_TM·CVT_,SingletonSegment,dismount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + t->hd = false; + } + + Local void ·(TM,_TM·CVT_,SingletonSegment,s)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + Local void ·(TM,_TM·CVT_,SingletonSegment,step_left)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + Local void ·(TM,_TM·CVT_,SingletonSegment,rewind)( ·(TM,_TM·CVT_) tm ){ + return; + } + + Local _TM·CVT_ ·(TM,_TM·CVT_,SingletonSegment,r)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + return t->value; + } + Local void ·(TM,_TM·CVT_,SingletonSegment,w)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t = (·(TM,_TM·CVT_,SingletonSegment,Tableau) *) tm.tableau; + t->value = *remote_pt; + } + + Local ·(TM,_TM·CVT_,PFT) ·(TM,_TM·CVT_,SingletonSegment,pft) = { + + .topo = ·(TM,_TM·CVT_,SingletonSegment,topo) + ,.bounded = ·(TM,_TM·CVT_,SingletonSegment,bounded) + ,.extent = ·(TM,_TM·CVT_,SingletonSegment,extent) + + ,.status = ·(TM,_TM·CVT_,SingletonSegment,status) + ,.dismounted = ·(TM,_TM·CVT_,SingletonSegment,dismounted) + ,.on_tape = ·(TM,_TM·CVT_,SingletonSegment,on_tape) + ,.on_leftmost = ·(TM,_TM·CVT_,SingletonSegment,on_leftmost) + ,.on_rightmost = ·(TM,_TM·CVT_,SingletonSegment,on_rightmost) + + ,.mount = ·(TM,_TM·CVT_,SingletonSegment,mount) + ,.dismount = ·(TM,_TM·CVT_,SingletonSegment,dismount) + + ,.step = ·(TM,_TM·CVT_,SingletonSegment,s) + ,.step_left = ·(TM,_TM·CVT_,SingletonSegment,step_left) + ,.rewind = ·(TM,_TM·CVT_,SingletonSegment,rewind) + + ,.r = ·(TM,_TM·CVT_,SingletonSegment,r) + ,.w = ·(TM,_TM·CVT_,SingletonSegment,w) + + }; + + /* + 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_,SingletonSegment,init)( + ·(TM,_TM·CVT_,SingletonSegment,Tableau) *t + ,_TM·CVT_ initial_value + ){ + t->hd = true; + t->value = initial_value; + + ·(TM,_TM·CVT_) tm = { + .tableau = (·(TM,_TM·CVT_,Tableau) *)t + ,.pft = &·(TM,_TM·CVT_,SingletonSegment,pft) + }; + + return tm; + } + + #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/TM\302\267ZeroLength.lib.c" "b/developer/cc\360\237\226\211/TM\302\267ZeroLength.lib.c" new file mode 100644 index 0000000..861c7a9 --- /dev/null +++ "b/developer/cc\360\237\226\211/TM\302\267ZeroLength.lib.c" @@ -0,0 +1,180 @@ +/* + Namespace: TM·ZeroLength + + Template parameters: + + `_TM·CVT_` Cell Value Type`. + +*/ +#include "TM.lib.c" + +/*-------------------------------------------------------------------------------- + Interface +--------------------------------------------------------------------------------*/ + +// once per translation unit +#ifndef TM·ZeroLength·FACE +#define TM·ZeroLength·FACE + + #define TM·ZeroLength·DEBUG + #ifdef TM·ZeroLength·DEBUG + #include + #endif + +#endif //#ifndef TM·FACE + +// once per _TM·CVT_ value +// Caller must #define SET_Binding__TM·ZeroLength·, after inclusion, to prevent re-inclusion +#ifdef _TM·CVT_ +#if BOOLEAN( NOT_IN(Binding ,·(TM·ZeroLength,_TM·CVT_)) ) +#ifdef TM·ZeroLength·DEBUG + #pragma message( "Creating TM·ZeroLength type with a CVT of:" STR_VAL(_TM·CVT_) ) +#endif + + typedef struct{ + bool hd; + } ·(TM,_TM·CVT_,ZeroLength,Tableau); + + ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,init)( + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t + ); + +#endif +#endif + +/*-------------------------------------------------------------------------------- + Local +--------------------------------------------------------------------------------*/ +#ifdef LOCAL + + // once per translation unit + #ifndef TM·ZeroLength·LOCAL + #define TM·ZeroLength·LOCAL + + #endif + + // once per _TM·CVT_ value + // Caller must #define SET_TM·ZeroLength·LOCAL__TM·, after inclusion, to prevent re-inclusion + #ifdef _TM·CVT_ + #if BOOLEAN(NOT_IN(TM·LOCAL ,·(TM·ZeroLength,_TM·CVT_))) + #ifdef TM·ZeroLength·DEBUG + #pragma message( "Including TM·ZeroLength LOCAL code for:" STR_VAL(_TM·CVT_) ) + #endif + + Local TM·Topo ·(TM,_TM·CVT_,ZeroLength,topo)( ·(TM,_TM·CVT_) tm ){ + return TM·Topo·zero_length; + } + + Local bool ·(TM,_TM·CVT_,ZeroLength,bounded)( ·(TM,_TM·CVT_) tm ){ + return true; + } + + Local ·(extent_t,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,extent)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + + Local TM·Status ·(TM,_TM·CVT_,ZeroLength,status)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; + if( !t->hd ) return TM·Status·dismounted; + return TM·Status·out_of_area; + } + + Local bool ·(TM,_TM·CVT_,ZeroLength,dismounted)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; + return !t->hd; + } + + Local bool ·(TM,_TM·CVT_,ZeroLength,on_tape)( ·(TM,_TM·CVT_) tm ){ + return false; + } + + Local bool ·(TM,_TM·CVT_,ZeroLength,on_leftmost)( ·(TM,_TM·CVT_) tm ){ + return false; + } + + Local bool ·(TM,_TM·CVT_,ZeroLength,on_rightmost)( ·(TM,_TM·CVT_) tm ){ + return false; + } + + // does nothing if tape is already mounted + Local void ·(TM,_TM·CVT_,ZeroLength,mount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; + if( !t->hd ) t->hd = true; + } + + Local void ·(TM,_TM·CVT_,ZeroLength,dismount)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; + t->hd = false; + } + + Local void ·(TM,_TM·CVT_,ZeroLength,s)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + + Local void ·(TM,_TM·CVT_,ZeroLength,step_left)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + + // rewind does nothing if the tape is dismounted + Local void ·(TM,_TM·CVT_,ZeroLength,rewind)( ·(TM,_TM·CVT_) tm ){ + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t = (·(TM,_TM·CVT_,ZeroLength,Tableau) *) tm.tableau; + if( ·(TM,_TM·CVT_,ZeroLength,dismounted)( tm ) ) return; + assert(0); + } + + Local _TM·CVT_ ·(TM,_TM·CVT_,ZeroLength,r)( ·(TM,_TM·CVT_) tm ){ + assert(0); + } + + Local void ·(TM,_TM·CVT_,ZeroLength,w)( ·(TM,_TM·CVT_) tm ,_TM·CVT_ *remote_pt ){ + assert(0); + } + + Local ·(TM,_TM·CVT_,PFT) ·(TM,_TM·CVT_,ZeroLength,pft) = { + + .topo = ·(TM,_TM·CVT_,ZeroLength,topo) + ,.bounded = ·(TM,_TM·CVT_,ZeroLength,bounded) + ,.extent = ·(TM,_TM·CVT_,ZeroLength,extent) + + ,.status = ·(TM,_TM·CVT_,ZeroLength,status) + ,.dismounted = ·(TM,_TM·CVT_,ZeroLength,dismounted) + ,.on_tape = ·(TM,_TM·CVT_,ZeroLength,on_tape) + ,.on_leftmost = ·(TM,_TM·CVT_,ZeroLength,on_leftmost) + ,.on_rightmost = ·(TM,_TM·CVT_,ZeroLength,on_rightmost) + + ,.mount = ·(TM,_TM·CVT_,ZeroLength,mount) + ,.dismount = ·(TM,_TM·CVT_,ZeroLength,dismount) + + ,.step = ·(TM,_TM·CVT_,ZeroLength,s) + ,.step_left = ·(TM,_TM·CVT_,ZeroLength,step_left) + ,.rewind = ·(TM,_TM·CVT_,ZeroLength,rewind) + + ,.r = ·(TM,_TM·CVT_,ZeroLength,r) + ,.w = ·(TM,_TM·CVT_,ZeroLength,w) + + }; + + ·(TM,_TM·CVT_) ·(TM,_TM·CVT_,ZeroLength,init)( + ·(TM,_TM·CVT_,ZeroLength,Tableau) *t + ){ + t->hd = true; + ·(TM,_TM·CVT_) tm = { + .tableau = (·(TM,_TM·CVT_,Tableau) *)t + ,.pft = &·(TM,_TM·CVT_,ZeroLength,pft) + }; + return tm; + } + + + #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 54374fe..6cff205 100644 --- "a/developer/cc\360\237\226\211/cpp_ext.c" +++ "b/developer/cc\360\237\226\211/cpp_ext.c" @@ -1,4 +1,3 @@ - #ifndef CPP_EXT #define CPP_EXT 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 81cd43e..a04d08d 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_0.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_0.c" @@ -168,14 +168,14 @@ LOGIC For example a set named TRIP with 1 ,2 ,3 in it: - #define SET__TRIP__1 - #define SET__TRIP__2 - #define SET__TRIP__3 + #define SET_TRIP__1 + #define SET_TRIP__2 + #define SET_TRIP__3 */ -#define IN(name ,x) NOT(CAT4(SET__ ,name ,__ ,x)) -#define NOT_IN(name ,x) CAT4(SET__ ,name ,__ ,x) +#define IN(name ,x) NOT(CAT4(SET_ ,name ,__ ,x)) +#define NOT_IN(name ,x) CAT4(SET_ ,name ,__ ,x) /*--------------------------------------------------------------------------- diff --git "a/developer/cc\360\237\226\211/scatch.c" "b/developer/cc\360\237\226\211/scatch.c" deleted file mode 100644 index abf9619..0000000 --- "a/developer/cc\360\237\226\211/scatch.c" +++ /dev/null @@ -1,580 +0,0 @@ - // 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 - - Local TM·Tape·Topo TM·Tape·topo(TM *tm){ - return tm->fg.Tape·topo(tm); - } - Local TM·Tape·Topo TM·Tape·bounded(TM *tm){ - return TM·tape_top(tm) & TM·Tape·Topo·bounded); - } - - Local TM·Head·Status TM·head_status(TM *tm){ - return tm->fg.status(tm ,result); - } - Local TM·Head·Status TM·head_on_tape(TM *tm){ - return TM·status(tm) & TM·Head·Status·on_tape; - } - - // does nothing if the head is already mounted - Local Core·Status TM·mount(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 - if( !TM·head_on_tape(tm) ) return Core·Status·on_track; - return tm->fg.mount(tm); - } - - // does nothing if the head is already dismounted - Local Core·Status TM·dismount(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 - if( TM·head_status(TM *tm) & TM·Head·Status·dismounted) ) return Core·Status·on_track; - return tm->fg.dismount(tm); - } - - #define TM·macro·bool_tm(name) - Local bool name(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.name(tm); \ - } - - Local bool TM·macro·bool_tm(on_leftmost); - Local bool TM·macro·bool_tm(on_rightmost); - Local bool TM·macro·bool_tm(step); - Local bool TM·macro·bool_tm(step_left); - Local bool TM·macro·bool_tm(rewind); - - //---------------------------------------- - // Initialization for TM·fg - - - #endif // ifndef TM·CVT - - //----------------------------------- - // TM·CVT dependent functions - - #ifdef TM·CVT - - 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 - - - - #endif // ifdef TM·CVT - -#endif // LOCAL - -//-------------------------------------------------------------------------------- -// Library - compiled into a lib.a file by the current make -// TM currently has no library components -//-------------------------------------------------------------------------------- -#ifdef LIBRARY -#endif - -//-------------------------------------------------------------------------------- -// undef the template parameters -//-------------------------------------------------------------------------------- -#undef TM·CVT - - //---------------------------------------- - // TM·Array implementation - //---------------------------------------- - - /* - TM·Array is bound to a tape with head on the tape via mount_pe or mount_pp. - - Once a tape is bound, it remains so, though the head can be dismounted - and remounted. - - C lacks an allocation-bound initialization feature, so the library user is responsible - to make sure a TM·Array has been initialized before use. - - The TM·Array has no locking facility, so it is not possible to know if it is in use. - - Re-initializing a TM·Array while in use can lead to unspecified badness. Use `rewind` instead. - */ - - //---------------------------------------- - // TM·Array implementation - //---------------------------------------- - - #ifndef TM·CVT - - //----------------------------------- - // 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·status="bad head status"; - - - #endif // #ifndef TM·CVT - - #ifdef TM·CVT - - - - - - // check the Tape·topo to make sure tape has extent before calling this - // `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 ,TM·CVT)·Tape·topo(tm ,&Tape·topo); - bool good_Tape·topo = - (status == Core·Status·on_track) && (Tape·topo & Core·Tape·Topo·finite_nz) - ; - Core·Guard·fg.check(&chk ,1 ,good_Tape·topo ,"Tape does not have an extent."); - Core·Guard·assert(chk); - #endif - - *result = tm->extent; - return Core·Status·on_track; - } - - //----------------------------------- - // TM·Array.area implementation - - 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); - Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·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 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); - 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 ,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 ,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); - if(tm) Core·Guard·fg.check(&chk ,1 ,tm->position ,TM·Array·Msg·position); - 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; - } - - 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); - Core·Guard·if_return(chk); - #endif - - tm->hd = NULL; - return Core·Status·on_track; - } - - 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; - - 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; - - return TM·Head·Status·interim; - } - - 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 ,TM·CVT)·on_origin(·(TM·Array ,TM·CVT) *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - bool flag = true ,s; - 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; - } - - // can_read was true - 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 ,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 ,TM·CVT)·step(·(TM·Array ,TM·CVT) *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - bool flag = true ,s; - 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 ,TM·CVT)·step_left(·(TM·Array ,TM·CVT) *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - bool flag = true ,s; - 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 ,TM·CVT)·rewind(·(TM·Array ,TM·CVT) *tm){ - #ifdef TM·DEBUG - Core·Guard·init_count(chk); - bool flag = true ,s; - 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 = tm->position; - } - - // tm_can_read must be true for both machines. - 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 ,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 ,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 - - *(tm_write->hd) = *(tm_read->hd); - return Core·Status·on_track; - } - - 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 ,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 - - *read_pt = *(tm->hd); - } - - - // step_right is a synonym for step - - - //---------------------------------------- - // Initialization for ·(TM·Array ,TM·CVT)·fg - - Local ·(TM·Array ,TM·CVT)·Binding ·(TM·Array ,TM·CVT)·fg = { - .tape = { - .Tape·topo = ·(TM·Array ,TM·CVT)·Tape·topo - .extent = ·(TM·Array ,TM·CVT)·extent - } - - ,.area = { - .mount_pe = ·(TM·Array ,TM·CVT)·mount_pe - ,.mount_pp = ·(TM·Array ,TM·CVT)·mount_pp - } - - ,.mount = ·(TM·Array ,TM·CVT)·mount - ,.dismount = ·(TM·Array ,TM·CVT)·dismount - - ,.status = ·(TM·Array ,TM·CVT)·status - ,.head_on_format = ·(TM·Array ,TM·CVT)·head_on_format - - ,.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 ,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 ,TM·CVT)·copy_datum - ,.read = ·(TM·Array ,TM·CVT)·read - ,.write = ·(TM·Array ,TM·CVT)·write - - }; - - -//-------------------------------------------------------------------------------- - -// scrat - - -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 ,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) = *write_pt; -} - - //----------------------------------- - // TM struct initializers - - Local Core·Status TM·mount_pe( - TM *tm ,TM·CVT *position ,·(extent_t ,TM·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 TM·CVT is not a power of two this can perform a divide - Local Core·Status TM·mount_pp( - TM *tm ,TM·CVT *pos_leftmost ,TM·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 ,TM·CVT) extent = pos_rightmost - pos_leftmost); - return TM·mount_pe(tm ,pos_leftmost ,extent); - } - diff --git "a/developer/deprecated\360\237\226\211/Map.lib.c" "b/developer/deprecated\360\237\226\211/Map.lib.c" new file mode 100644 index 0000000..2592129 --- /dev/null +++ "b/developer/deprecated\360\237\226\211/Map.lib.c" @@ -0,0 +1,154 @@ +/* Map - mapping functions between tape machines. + + This file has two template parameters: + `CVT_read` Cell Value Type for the source/read tape machine + `CVT_write` Cell Value Type for the destination/write tape machine + + By default (when the macros have no definition) the cell value types are taken as AU. + This file must be included with CVT_read and CVT_write undefined, before inclusions with them 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. +*/ + +#define Map·DEBUG + +#ifndef FACE + #define Map·IMPLEMENTATION + #define FACE +#endif + +//-------------------------------------------------------------------------------- +// Interface + +#ifndef Map·FACE + #define Map·FACE + + #include + #include + #include "Core.lib.c" + #include "TM.lib.c" + + // if only one template parameter is given, we will assume both are the same + + #if defined(CVT_read) && !defined(CVT_write) + #warning "Given CVT_read template value. Missing CVT_write template value, so setting it to CVT_read" + #define CVT_write CVT_read + #endif + + #if !defined(CVT_read) && defined(CVT_write) + #warning "Given CVT_write template value. Missing CVT_read template value, so setting it to CVT_write" + #define CVT_read CVT_write + #endif + + //---------------------------------------- + // Map status and completion enums + //---------------------------------------- + + #if !defined(CVT_read) && !defined(CVT_write) + + typedef enum { + Map·Completion·mu = 0 + ,Map·Completion·failed = 1 + ,Map·Completion·null_fn = 1 << 1 + ,Map·Completion·no_tape_access = 1 << 2 + ,Map·Completion·rightmost_read = 1 << 3 + ,Map·Completion·rightmost_write = 1 << 4 + } Map·Completion; + + // Masks for combinations + const uint Map·Completion·rightmost_both = + Map·Completion·rightmost_read + | Map·Completion·rightmost_write + ; + + const uint Map·Completion·derailed = + Map·Completion·failed + | Map·Completion·null_fn + | Map·Completion·no_tape_access + ; + + const uint Map·Completion·on_track = + Map·Completion·rightmost_read + | Map·Completion·rightmost_write + | Map·Completion·rightmost_both + ; + + #endif + + //---------------------------------------- + // Map interface + //---------------------------------------- + + #if !defined(CVT_read) || !defined(CVT_write) + + typedef struct { + Map·Completion (*copy_byte_to_byte)( + ·(TM·Array ,AU) *read_tm + ,·(TM·Array ,AU) *write_tm + ); + + Map·Completion (*copy_hex_to_byte)( + ·(TM·Array ,uint16_t) *read_tm + ,·(TM·Array ,AU) *write_tm + ); + + Map·Completion (*copy_byte_to_hex)( + ·(TM·Array ,AU) *read_tm + ,·(TM·Array ,uint16_t) *write_tm + ); + + // Terminate string function + Map·Completion (*terminate_string)( + ·(TM·Array ,AU) *write_tm + ); + } Map·FG; + + // a default function given table + Map·FG Map·fg; + + #endif + + + #if defined(CVT_read) && defined(CVT_write) + + // Function passed to map type signature must be this: + typedef Core·Status (*·(Map·fn ,CVT_read ,CVT_write))( + CVT_read *read_value + ,CVT_write *write_value + ); + + typedef struct { + // Map a function over all elements from read_tm to write_tm + Map·Completion (*map)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ); + + // Map a function over elements from read_tm to write_tm until a condition is met + Map·Completion (*map_while)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,bool (*condition)(·(TM·Array ,CVT_read) *read_tm) + ); + + // Map a function over n elements from read_tm to write_tm + Map·Completion (*map_extent)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,·(extent_t ,CVT_read) extent + ); + + } ·(Map·FG ,CVT_read ,CVT_write); + + // Default function given table + ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write); + + #endif + +#endif // #ifndef Map·FACE diff --git "a/developer/deprecated\360\237\226\211/Map2.lib.c" "b/developer/deprecated\360\237\226\211/Map2.lib.c" new file mode 100644 index 0000000..e58173e --- /dev/null +++ "b/developer/deprecated\360\237\226\211/Map2.lib.c" @@ -0,0 +1,500 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/* Map - mapping functions between tape machines. + + This file has two template parameters: + `CVT_read` Cell Value Type for the source/read tape machine + `CVT_write` Cell Value Type for the destination/write tape machine + + By default (when the macros have no definition) the cell value types are taken as AU. + This file must be included with CVT_read and CVT_write undefined, before inclusions with them 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. +*/ + +#define Map·DEBUG + +#ifndef FACE + #define Map·IMPLEMENTATION + #define FACE +#endif + +//-------------------------------------------------------------------------------- +// Interface + +#ifndef Map·FACE + #define Map·FACE + + #include + #include + #include "Core.lib.c" + #include "TM.lib.c" + + // if only one template parameter is given, we will assume both are the same + + #if defined(CVT_read) && !defined(CVT_write) + #warning "Given CVT_read template value. Missing CVT_write template value, so setting it to CVT_read" + #define CVT_write CVT_read + #endif + + #if !defined(CVT_read) && defined(CVT_write) + #warning "Given CVT_write template value. Missing CVT_read template value, so setting it to CVT_write" + #define CVT_read CVT_write + #endif + + //---------------------------------------- + // Map status and completion enums + //---------------------------------------- + + #if !defined(CVT_read) && !defined(CVT_write) + + typedef enum { + Map·Completion·mu = 0 + ,Map·Completion·failed = 1 + ,Map·Completion·null_fn = 1 << 1 + ,Map·Completion·no_tape_access = 1 << 2 + ,Map·Completion·rightmost_read = 1 << 3 + ,Map·Completion·rightmost_write = 1 << 4 + } Map·Completion; + + // Masks for combinations + const uint Map·Completion·rightmost_both = + Map·Completion·rightmost_read + | Map·Completion·rightmost_write + ; + + const uint Map·Completion·derailed = + Map·Completion·failed + | Map·Completion·null_fn + | Map·Completion·no_tape_access + ; + + const uint Map·Completion·on_track = + Map·Completion·rightmost_read + | Map·Completion·rightmost_write + | Map·Completion·rightmost_both + ; + + #endif + + //---------------------------------------- + // Map interface + //---------------------------------------- + + #if !defined(CVT_read) || !defined(CVT_write) + typedef struct { + Map·Completion (*copy_byte_to_byte)( + ·(TM·Array ,AU) *read_tm + ,·(TM·Array ,AU) *write_tm + ); + + Map·Completion (*copy_hex_to_byte)( + ·(TM·Array ,uint16_t) *read_tm + ,·(TM·Array ,AU) *write_tm + ); + + Map·Completion (*copy_byte_to_hex)( + ·(TM·Array ,AU) *read_tm + ,·(TM·Array ,uint16_t) *write_tm + ); + + // Terminate string function + Map·Completion (*terminate_string)( + ·(TM·Array ,AU) *write_tm + ); + } + #endif + + + #if defined(CVT_read) && defined(CVT_write) + + // Function passed to map type signature must be this: + typedef Core·Status (*·(Map·fn ,CVT_read ,CVT_write))( + CVT_read *read_value + ,CVT_write *write_value + ); + + typedef struct { + // Map a function over all elements from read_tm to write_tm + Map·Completion (*map)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ); + + // Map a function over elements from read_tm to write_tm until a condition is met + Map·Completion (*map_while)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,bool (*condition)(·(TM·Array ,CVT_read) *read_tm) + ); + + // Map a function over n elements from read_tm to write_tm + Map·Completion (*map_extent)( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,·(extent_t ,CVT_read) extent + ); + + } ·(Map·FG ,CVT_read ,CVT_write); + + // Default function given table + ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write); + #endif // !defined(CVT_read) && !defined(CVT_write) + +#endif // #ifndef Map·FACE + +//-------------------------------------------------------------------------------- +// Implementation + +#ifdef Map·IMPLEMENTATION + + // declarations available to all of the IMPLEMENTATION go here + #ifdef Map·DEBUG + #include + #endif + + // implementation to go into the lib.a file + #ifndef LOCAL + #endif + + #ifdef LOCAL + //---------------------------------------- + // Map implementation + //---------------------------------------- + + #if !defined(CVT_read) && !defined(CVT_write) + //----------------------------------- + // common error messages + const char *Map·Msg·read_tm = "given NULL read_tm"; + const char *Map·Msg·write_tm = "given NULL write_tm"; + const char *Map·Msg·map_fn = "given NULL map_fn"; + const char *Map·Msg·condition = "given NULL condition function"; + + //----------------------------------- + // Helper functions for copy operations + + // Byte to byte copy function + Local Core·Status Map·byte_to_byte_fn(AU *read_value, AU *write_value) { + *write_value = *read_value; + return Core·Status·on_track; + } + + // Hex to byte conversion function + Local Core·Status Map·hex_to_byte_fn(uint16_t *read_value, AU *write_value) { + // Convert hex value to byte + *write_value = (AU)(*read_value & 0xFF); + return Core·Status·on_track; + } + + // Byte to hex conversion function + Local Core·Status Map·byte_to_hex_fn(AU *read_value, uint16_t *write_value) { + // Convert byte to lowercase hex representation (no prefix) + static const char hex_chars[] = "0123456789abcdef"; + *write_value = hex_chars[(*read_value >> 4) & 0x0F]; + return Core·Status·on_track; + } + #endif // !defined(CVT_read) && !defined(CVT_write) + + #if defined(CVT_read) && defined(CVT_write) + //----------------------------------- + // Map implementation with specific types + + // Map a function over all elements from read_tm to write_tm + Local Core·Status ·(Map ,CVT_read ,CVT_write)·map( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ){ + #ifdef Map·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); + Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); + Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); + Core·Guard·if_return(chk); + #endif + + // Rewind both tape machines to ensure we start at the beginning + ·(TM·Array ,CVT_read)·fg.rewind(read_tm); + ·(TM·Array ,CVT_write)·fg.rewind(write_tm); + + // Initial check if can_read (not part of the loop) + if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; + + // Track completion status + uint completion = 0; + + // Following the first-rest pattern described in TTCA + while(1){ + // Read value from source + CVT_read read_value; + ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); + + // Apply mapping function to get write value + CVT_write write_value; + Core·Status status = map_fn(&read_value ,&write_value); + if(status != Core·gStatus·on_track) { + completion |= Core·Map·Completion·failed; + return status; + } + + // Write result to destination + ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); + + // Check if we're at the rightmost position for read + bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); + if(read_rightmost) { + completion |= Core·Map·Completion·rightmost_read; + } + + // Check if we're at the rightmost position for write + bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); + if(write_rightmost) { + completion |= Core·Map·Completion·rightmost_write; + } + + // Break if either machine is at rightmost + if(read_rightmost || write_rightmost) break; + + // Step both machines + ·(TM·Array ,CVT_read)·fg.step(read_tm); + ·(TM·Array ,CVT_write)·fg.step(write_tm); + } + + return Core·Status·on_track; + } + + // Map a function over elements from read_tm to write_tm until a condition is met + Local Core·Status ·(Map ,CVT_read ,CVT_write)·map_while( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,bool (*condition)(CVT_read *value) + ){ + #ifdef Map·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); + Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); + Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); + Core·Guard·fg.check(&chk ,1 ,condition ,Map·Msg·condition); + Core·Guard·if_return(chk); + #endif + + // Rewind both tape machines to ensure we start at the beginning + ·(TM·Array ,CVT_read)·fg.rewind(read_tm); + ·(TM·Array ,CVT_write)·fg.rewind(write_tm); + + // Initial check if can_read (not part of the loop) + if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; + + // Track completion status + uint completion = 0; + + // Following the first-rest pattern described in TTCA + while(1){ + // Read value from source + CVT_read read_value; + ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); + + // Check condition + if(!condition(&read_value)) break; + + // Apply mapping function to get write value + CVT_write write_value; + Core·Status status = map_fn(&read_value ,&write_value); + if(status != Core·Status·on_track) { + completion |= Core·Map·Completion·failed; + return status; + } + + // Write result to destination + ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); + + // Check if we're at the rightmost position for read + bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); + if(read_rightmost) { + completion |= Core·Map·Completion·rightmost_read; + } + + // Check if we're at the rightmost position for write + bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); + if(write_rightmost) { + completion |= Core·Map·Completion·rightmost_write; + } + + // Break if either machine is at rightmost + if(read_rightmost || write_rightmost) break; + + // Step both machines + ·(TM·Array ,CVT_read)·fg.step(read_tm); + ·(TM·Array ,CVT_write)·fg.step(write_tm); + } + + return Core·Status·on_track; + } + + // Map a function over n elements from read_tm to write_tm + Local Core·Status ·(Map ,CVT_read ,CVT_write)·map_n( + ·(TM·Array ,CVT_read) *read_tm + ,·(TM·Array ,CVT_write) *write_tm + ,·(Map·fn ,CVT_read ,CVT_write) map_fn + ,size_t n + ){ + #ifdef Map·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); + Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); + Core·Guard·fg.check(&chk ,1 ,map_fn ,Map·Msg·map_fn); + Core·Guard·if_return(chk); + #endif + + // Rewind both tape machines to ensure we start at the beginning + ·(TM·Array ,CVT_read)·fg.rewind(read_tm); + ·(TM·Array ,CVT_write)·fg.rewind(write_tm); + + // Initial check if can_read (not part of the loop) + if(!·(TM·Array ,CVT_read)·fg.can_read(read_tm)) return Core·Status·on_track; + + // Track completion status + uint completion = 0; + + // Following the first-rest pattern described in TTCA + size_t count = 0; + while(count < n){ + // Read value from source + CVT_read read_value; + ·(TM·Array ,CVT_read)·fg.read(read_tm ,&read_value); + + // Apply mapping function to get write value + CVT_write write_value; + Core·Status status = map_fn(&read_value ,&write_value); + if(status != Core·Status·on_track) { + completion |= Core·Map·Completion·failed; + return status; + } + + // Write result to destination + ·(TM·Array ,CVT_write)·fg.write(write_tm ,&write_value); + + // Increment count + count++; + + // Check if we're at the rightmost position for read + bool read_rightmost = ·(TM·Array ,CVT_read)·fg.on_rightmost(read_tm); + if(read_rightmost) { + completion |= Core·Map·Completion·rightmost_read; + } + + // Check if we're at the rightmost position for write + bool write_rightmost = ·(TM·Array ,CVT_write)·fg.on_rightmost(write_tm); + if(write_rightmost) { + completion |= Core·Map·Completion·rightmost_write; + } + + // Break if either machine is at rightmost + if(read_rightmost || write_rightmost) break; + + // Step both machines + ·(TM·Array ,CVT_read)·fg.step(read_tm); + ·(TM·Array ,CVT_write)·fg.step(write_tm); + } + + return Core·Status·on_track; + } + + // Initialize the function given table + ·(Map·FG ,CVT_read ,CVT_write) ·(Map·fg ,CVT_read ,CVT_write) = { + .map = ·(Map ,CVT_read ,CVT_write)·map + ,.map_while = ·(Map ,CVT_read ,CVT_write)·map_while + ,.map_n = ·(Map ,CVT_read ,CVT_write)·map_n + }; + #endif // defined(CVT_read) && defined(CVT_write) + + //---------------------------------------- + // Copy functions implementation + //---------------------------------------- + + // Byte to byte copy + Local Core·Status Map·copy_byte_to_byte( + ·(TM·Array ,AU) *read_tm + ,·(TM·Array ,AU) *write_tm + ){ + #ifdef Map·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); + Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); + Core·Guard·if_return(chk); + #endif + + return ·(Map ,AU ,AU)·fg.map(read_tm, write_tm, Map·byte_to_byte_fn); + } + + // Hex to byte copy + Local Core·Status Map·copy_hex_to_byte( + ·(TM·Array ,uint16_t) *read_tm + ,·(TM·Array ,AU) *write_tm + ){ + #ifdef Map·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk ,1 ,read_tm ,Map·Msg·read_tm); + Core·Guard·fg.check(&chk ,1 ,write_tm ,Map·Msg·write_tm); + Core·Guard·if_return(chk); + #endif + + return To save on context only part of this file has been shown to you. You should retry this tool after you have searched inside the file with `grep -n` in order to find the line numbers of what you are looking for. diff --git "a/developer/deprecated\360\237\226\211/scatch.c" "b/developer/deprecated\360\237\226\211/scatch.c" new file mode 100644 index 0000000..abf9619 --- /dev/null +++ "b/developer/deprecated\360\237\226\211/scatch.c" @@ -0,0 +1,580 @@ + // 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 + + Local TM·Tape·Topo TM·Tape·topo(TM *tm){ + return tm->fg.Tape·topo(tm); + } + Local TM·Tape·Topo TM·Tape·bounded(TM *tm){ + return TM·tape_top(tm) & TM·Tape·Topo·bounded); + } + + Local TM·Head·Status TM·head_status(TM *tm){ + return tm->fg.status(tm ,result); + } + Local TM·Head·Status TM·head_on_tape(TM *tm){ + return TM·status(tm) & TM·Head·Status·on_tape; + } + + // does nothing if the head is already mounted + Local Core·Status TM·mount(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 + if( !TM·head_on_tape(tm) ) return Core·Status·on_track; + return tm->fg.mount(tm); + } + + // does nothing if the head is already dismounted + Local Core·Status TM·dismount(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 + if( TM·head_status(TM *tm) & TM·Head·Status·dismounted) ) return Core·Status·on_track; + return tm->fg.dismount(tm); + } + + #define TM·macro·bool_tm(name) + Local bool name(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.name(tm); \ + } + + Local bool TM·macro·bool_tm(on_leftmost); + Local bool TM·macro·bool_tm(on_rightmost); + Local bool TM·macro·bool_tm(step); + Local bool TM·macro·bool_tm(step_left); + Local bool TM·macro·bool_tm(rewind); + + //---------------------------------------- + // Initialization for TM·fg + + + #endif // ifndef TM·CVT + + //----------------------------------- + // TM·CVT dependent functions + + #ifdef TM·CVT + + 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 + + + + #endif // ifdef TM·CVT + +#endif // LOCAL + +//-------------------------------------------------------------------------------- +// Library - compiled into a lib.a file by the current make +// TM currently has no library components +//-------------------------------------------------------------------------------- +#ifdef LIBRARY +#endif + +//-------------------------------------------------------------------------------- +// undef the template parameters +//-------------------------------------------------------------------------------- +#undef TM·CVT + + //---------------------------------------- + // TM·Array implementation + //---------------------------------------- + + /* + TM·Array is bound to a tape with head on the tape via mount_pe or mount_pp. + + Once a tape is bound, it remains so, though the head can be dismounted + and remounted. + + C lacks an allocation-bound initialization feature, so the library user is responsible + to make sure a TM·Array has been initialized before use. + + The TM·Array has no locking facility, so it is not possible to know if it is in use. + + Re-initializing a TM·Array while in use can lead to unspecified badness. Use `rewind` instead. + */ + + //---------------------------------------- + // TM·Array implementation + //---------------------------------------- + + #ifndef TM·CVT + + //----------------------------------- + // 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·status="bad head status"; + + + #endif // #ifndef TM·CVT + + #ifdef TM·CVT + + + + + + // check the Tape·topo to make sure tape has extent before calling this + // `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 ,TM·CVT)·Tape·topo(tm ,&Tape·topo); + bool good_Tape·topo = + (status == Core·Status·on_track) && (Tape·topo & Core·Tape·Topo·finite_nz) + ; + Core·Guard·fg.check(&chk ,1 ,good_Tape·topo ,"Tape does not have an extent."); + Core·Guard·assert(chk); + #endif + + *result = tm->extent; + return Core·Status·on_track; + } + + //----------------------------------- + // TM·Array.area implementation + + 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); + Core·Guard·fg.check(&chk ,1 ,tm ,TM·Array·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 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); + 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 ,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 ,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); + if(tm) Core·Guard·fg.check(&chk ,1 ,tm->position ,TM·Array·Msg·position); + 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; + } + + 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); + Core·Guard·if_return(chk); + #endif + + tm->hd = NULL; + return Core·Status·on_track; + } + + 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; + + 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; + + return TM·Head·Status·interim; + } + + 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 ,TM·CVT)·on_origin(·(TM·Array ,TM·CVT) *tm){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + bool flag = true ,s; + 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; + } + + // can_read was true + 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 ,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 ,TM·CVT)·step(·(TM·Array ,TM·CVT) *tm){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + bool flag = true ,s; + 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 ,TM·CVT)·step_left(·(TM·Array ,TM·CVT) *tm){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + bool flag = true ,s; + 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 ,TM·CVT)·rewind(·(TM·Array ,TM·CVT) *tm){ + #ifdef TM·DEBUG + Core·Guard·init_count(chk); + bool flag = true ,s; + 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 = tm->position; + } + + // tm_can_read must be true for both machines. + 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 ,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 ,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 + + *(tm_write->hd) = *(tm_read->hd); + return Core·Status·on_track; + } + + 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 ,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 + + *read_pt = *(tm->hd); + } + + + // step_right is a synonym for step + + + //---------------------------------------- + // Initialization for ·(TM·Array ,TM·CVT)·fg + + Local ·(TM·Array ,TM·CVT)·Binding ·(TM·Array ,TM·CVT)·fg = { + .tape = { + .Tape·topo = ·(TM·Array ,TM·CVT)·Tape·topo + .extent = ·(TM·Array ,TM·CVT)·extent + } + + ,.area = { + .mount_pe = ·(TM·Array ,TM·CVT)·mount_pe + ,.mount_pp = ·(TM·Array ,TM·CVT)·mount_pp + } + + ,.mount = ·(TM·Array ,TM·CVT)·mount + ,.dismount = ·(TM·Array ,TM·CVT)·dismount + + ,.status = ·(TM·Array ,TM·CVT)·status + ,.head_on_format = ·(TM·Array ,TM·CVT)·head_on_format + + ,.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 ,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 ,TM·CVT)·copy_datum + ,.read = ·(TM·Array ,TM·CVT)·read + ,.write = ·(TM·Array ,TM·CVT)·write + + }; + + +//-------------------------------------------------------------------------------- + +// scrat + + +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 ,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) = *write_pt; +} + + //----------------------------------- + // TM struct initializers + + Local Core·Status TM·mount_pe( + TM *tm ,TM·CVT *position ,·(extent_t ,TM·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 TM·CVT is not a power of two this can perform a divide + Local Core·Status TM·mount_pp( + TM *tm ,TM·CVT *pos_leftmost ,TM·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 ,TM·CVT) extent = pos_rightmost - pos_leftmost); + return TM·mount_pe(tm ,pos_leftmost ,extent); + } + diff --git "a/developer/document\360\237\226\211/Binding.org" "b/developer/document\360\237\226\211/Binding.org" new file mode 100644 index 0000000..31ca2a4 --- /dev/null +++ "b/developer/document\360\237\226\211/Binding.org" @@ -0,0 +1,170 @@ +#+TITLE: FG Tables and Bindings in RT C +#+AUTHOR: Sorein +#+DATE: 2025-04-25 + +* 1. Overview: FG Tables Revisited + +RT C uses **Function-Given (FG) Tables** to group related functions that all take a **common first argument**. This enables flexible polymorphism and modular encapsulation in pure C. + +For a full explanation of FG tables and an example based on `Core`, see: + +**📎 [[file:fg_tables_core.org][FG Tables in RT C — The Core Example]]** + +In this model: +- Each module defines a **binding struct** (e.g. `TM·AU`, `Core`, etc). +- All methods take the binding as their first argument. +- A function pointer table (FG table) is associated with the binding. +- A macro `Module·call(binding ,method ,...)` expands to safe, type-dispatched function calls. + +* 2. The Tableau: Abstract Identity of the Binding + +In the FG model, we say that functions are *given* a binding. The binding is always a `struct` that pairs: + +1. A **tableau** (a pointer to the module-specific state) +2. An **FG table** (function dispatch table) + +The **tableau** is the key abstraction. + +- It is typically **only ever passed to the functions** in the FG table. +- Therefore, the FG table **defines the meaning** of the tableau: it specifies what functions expect and how they interpret the tableau pointer. +- The tableau has a *type in memory* (e.g. `TM·AU·Array·Tableau`), but also an **abstract type**, as defined by the FG table itself. + +In that sense, the FG table acts as **the type descriptor for the tableau**. + +* 3. Binding.lib.c + +The module `Binding.lib.c` defines the canonical layout of an FG-style binding. + +Below is the full source (excluding comments), organized by section. + +**FACE:** +#+BEGIN_SRC c +#ifndef Binding·FACE +#define Binding·FACE + +typedef struct{ + void *tableau; + void *FG; +} Binding; + +#endif +#+END_SRC + +This is the public interface. The type `Binding` is a generic struct that holds two pointers: +- `tableau`: the implementation-specific data (tape, buffer, object, etc) +- `FG`: pointer to a module-specific function table + +**IMPLEMENTATION:** +#+BEGIN_SRC c +#ifdef Binding·IMPLEMENTATION +#endif +#+END_SRC + +No definitions are required here—the binding struct has no behavior of its own. + +**LOCAL:** +#+BEGIN_SRC c +#ifdef LOCAL +#ifndef Binding·LOCAL +#define Binding·LOCAL + +#include +#include + +#endif +#endif +#+END_SRC + +These are the headers required to define the structure and the environment. It also follows the **RT C sectioning model** described in: + +**📎 [[file:sections.org][RT C File Structure and Sectioning]]** + +* 4. Template Use + +Although `Binding.lib.c` does not directly use template parameters, it is often **included repeatedly** in templated modules to create per-instance bindings. + +For example: +#+BEGIN_SRC c +#define _TM·CVT_ AU +#include "TM.lib.c" +#define SET__Binding__TM·AU +#+END_SRC + +The template name `_TM·CVT_` is used to create: +- `typedef struct TM·AU TM·AU;` +- `typedef struct TM·AU·Array·Tableau TM·AU·Array·Tableau;` +- `TM·AU` instances, each of which is a `Binding` with layout and dispatch tied to a particular tableau type. + +See: + +**📎 [[file:template_box_example.org][Templating in RT C — The Box Example]]** + +* 5. The Binding Struct + +Here’s the struct that every FG-style binding uses: + +#+BEGIN_SRC c +typedef struct{ + void *tableau; + void *FG; +} Binding; +#+END_SRC + +The tableau and FG pointers are opaque to the caller. They are interpreted by the functions in the FG table. + +**The binding is the concrete object passed around the system.** + +In most modules, this struct is **re-wrapped** in a typedef, e.g.: + +#+BEGIN_SRC c +typedef Binding TM·AU; +#+END_SRC + +This means that in function signatures and argument lists, the **binding is visible under its module-specific name**, even though all bindings have the same physical layout. + +This separation allows: +- Static type safety at the source level (per module) +- Shared representation at the binary level + +* 6. Example Usage + +Suppose we define a tape machine `TM·AU` over a byte array. The setup might look like: + +#+BEGIN_SRC c +AU tape[] = {0x01 ,0x02 ,0x03}; +extent_t·AU extent = 2; + +TM·AU·Array·Tableau t; +TM·AU tm = TM·AU·Array·init_pe(&t ,tape ,extent); + +if( TM·AU·call(tm ,on_tape) ){ + uchar x = TM·AU·call(tm ,read); + printf("Head reads: %02x\n", x); +} +#+END_SRC + +Here: +- `tm` is a `TM·AU` binding — a `struct` with `.tableau = &t`, and `.FG = &TM·AU·Array·fg`. +- The functions in the FG table dereference `tm.tableau` into the expected type. +- `TM·AU·call` wraps method access, validating the binding under debug builds. + +* 7. Summary + +A **binding** in RT C is: +- A pair of `(tableau pointer, FG table pointer)` +- Constructed per module or template instantiation +- Passed around as the first argument to all FG methods +- Given a distinct *type name* (like `TM·AU`) to encode its role + +A **tableau** is: +- The backing data storage (often a `struct`) +- Interpreted only by the FG methods that operate on it +- Abstractly defined by the FG table it's paired with + +This design gives RT C the benefits of: +- Polymorphism +- Type encapsulation +- Dispatch +- Template instantiation + +All in a clean, structured C style, without runtime type metadata or compiler extensions. diff --git "a/developer/document\360\237\226\211/FG_tables.org" "b/developer/document\360\237\226\211/FG_tables.org" new file mode 100644 index 0000000..797b909 --- /dev/null +++ "b/developer/document\360\237\226\211/FG_tables.org" @@ -0,0 +1,113 @@ +* Function-Given (FG) Tables in RT C +:PROPERTIES: +:AUTHOR: Sorein +:DATE: 2025-04-25 +:END: + +This document introduces **FG Tables**—Function-Given tables, a structured method in RT C for grouping related functions that operate on a common type or binding. We use the `Core` module as a canonical example, as it contains no template variables or tableaux and thus provides the cleanest view. + +**FG Tables** serve a purpose similar to vtables or method dictionaries: they allow operations to be defined once and called generically, using a consistent interface. Unlike C++ vtables, FG tables are explicit, statically defined, and layered via macros in a readable, extensible style. + +**Key concepts:** +- All function signatures take a common first argument (usually a pointer to a "binding" struct). +- The table itself is a `struct` of function pointers. +- The module defines: + - The **type** (e.g. `Core`) + - The **binding struct** (`Core·Binding`) + - The **table definition** (`Core·FG`) + - The **table instance** (`Core·Tableau`) + - Helper macros for calling (`Core·call(...)`) and checking (`Core·wellformed_binding(...)`) + +* Example: Core +Core provides utilities that are always available to the RT system. It defines an FG table without templates or specializations. + +**Declaration (in the FACE section)**: +#+BEGIN_SRC c +#ifndef Core·FACE +#define Core·FACE + +typedef struct Core·Binding Core; + +typedef struct{ + void(*Free)(Core*); + bool(*is_aligned)(Core* ,void const*,uint ,bool*); + void const*(*round_up)(Core* ,void const*,uint); + void const*(*round_down)(Core* ,void const*,uint); +} Core·FG; + +bool Core·wellformed_binding(Core*); +#define Core·call(B ,f ,...) ((Core·wellformed_binding(B)) ,(B)->FG->f(B ,__VA_ARGS__)) + +#endif +#+END_SRC + +**Explanation of Functions:** + +- `Free(Core*)`: Frees the binding and sets its pointer to `NULL`. This follows the `Free(pt) = free(pt); pt = NULL;` idiom defined in RT. +- `is_aligned(Core* ,void const* p ,uint alignment ,bool* result)`: Determines whether `p` is aligned to `alignment`. Writes result to `*result`, returns false if `p == NULL`. +- `round_up(Core* ,void const* p ,uint alignment)`: Returns the smallest aligned address ≥ `p`. +- `round_down(Core* ,void const* p ,uint alignment)`: Returns the largest aligned address ≤ `p`. + +All alignment operations use address logic with explicit alignments passed at runtime, rather than compile-time constants. + +* Implementation +The FG table instance is defined in the `Core·IMPLEMENTATION` section: + +#+BEGIN_SRC c +#ifdef Core·IMPLEMENTATION + +bool Core·wellformed_binding(Core* B){ + return B && B->FG == &Core·Tableau; +} + +Local void Core·Free(Core* B){ + Free(B); +} + +Local bool Core·is_aligned(Core* B ,void const* p ,uint alignment ,bool* result){ + if(!p){ *result = false; return false; } + uintptr_t up = (uintptr_t)p; + *result = (up % alignment) == 0; + return true; +} + +Local void const* Core·round_up(Core* B ,void const* p ,uint alignment){ + if(!p) return (void const*)(uintptr_t)alignment; + uintptr_t up = (uintptr_t)p; + return (void const*)((up + alignment - 1)/alignment*alignment); +} + +Local void const* Core·round_down(Core* B ,void const* p ,uint alignment){ + if(!p) return NULL; + uintptr_t up = (uintptr_t)p; + return (void const*)(up / alignment * alignment); +} + +Core·FG const Core·Tableau = { + .Free = Core·Free, + .is_aligned = Core·is_aligned, + .round_up = Core·round_up, + .round_down = Core·round_down +}; + +#endif +#+END_SRC + +* Usage Example +#+BEGIN_SRC c +Core* B = malloc(sizeof(Core)); +B->FG = &Core·Tableau; + +bool aligned; +Core·call(B ,is_aligned ,(void*)0x1000 ,16 ,&aligned); + +void const* r = Core·call(B ,round_up ,(void*)0x1003 ,16); +#+END_SRC + +* Summary +- FG Tables provide modular polymorphism in pure C. +- The `Core` FG is the simplest: no template variables, no tableaux layers. +- The FG naming convention (`Module·FG`) and `call(...)` wrapper provide safety and convenience. +- FG patterns scale to support templated modules with `FG·Type`, `FG·Tableau`, and dispatch guards. + +FG tables are foundational to the RT C architecture, forming the dispatch layer behind modular, template-like polymorphism in a static language. diff --git "a/developer/document\360\237\226\211/TapeMachine_howto.org" "b/developer/document\360\237\226\211/TapeMachine_howto.org" new file mode 100644 index 0000000..f156c23 --- /dev/null +++ "b/developer/document\360\237\226\211/TapeMachine_howto.org" @@ -0,0 +1,145 @@ +#+TITLE: How to Use a TM: Tape Machine Structure and Semantics +#+AUTHOR: Sorein +#+DATE: 2025-04-25 + +* 1. Introduction + +The `TM` module in RT C implements a **Tape Machine** abstraction—a generic, forward/backward traversable sequence with a *head*, *bounded extent*, and *cell value type* (CVT). + +Each instantiated TM (e.g. `TM·AU`, `TM·Str`) is a **binding** that combines: +- A `tableau` — the backing data or representation (e.g. array, singleton, zero-length) +- An `FG table` — the dispatch logic defining how the head behaves + +TM is not a container. It is a *lens* or *state machine* for traversing memory in a structured way. + +* 2. Constructing a TM + +To construct a TM instance, you typically: +1. Define the tape data (e.g. an array of AU or Str) +2. Define its extent +3. Allocate a `Tableau` struct (e.g. `TM·AU·Array·Tableau`) +4. Initialize the TM using `init_pe` or `init_pp` + +#+BEGIN_SRC c +AU tape1[] = {0xAA ,0x55 ,0xC2}; +extent_t·AU extent1 = sizeof(tape1) / sizeof(AU) - 1; + +TM·AU·Array·Tableau t1; +TM·AU tm1 = TM·AU·Array·init_pe(&t1 ,tape1 ,extent1); +#+END_SRC + +The resulting `tm1` is a **binding**—you pass it to functions via `Binding·call` or `TM·AU·call`. + +* 3. TM Method Overview + +The key methods in the TM FG table are: + +| Method | Description | +|--------------------+--------------------------------------------------| +| `mount` | Reattach head to the tape if dismounted | +| `dismount` | Detach the head (mark as inactive) | +| `status` | Returns the full head status bitmask | +| `on_tape` | True if the head is on a valid cell | +| `on_leftmost` | True if head is at the leftmost cell | +| `on_rightmost` | True if head is at the rightmost cell | +| `step`, `step_left`| Move head forward or backward | +| `rewind` | Move head back to its starting position | +| `read` | Return the cell value under the head | +| `write` | Overwrite the cell under the head | + +* 4. Loop Structure: Prefix, Separator, Postfix + +Traversal is typically done with **guarded middle-exit loops**, allowing for insertion of: + +- A **prefix** (runs before loop) +- A **separator** (runs between each item) +- A **postfix** (runs after loop) + +Example pattern (printing a tape with separators): +#+BEGIN_SRC c +if( Binding·call(tm ,on_tape) ){ + // Prefix + do{ + // Body + printf("%02x", (unsigned int) Binding·call(tm ,read)); + + // Guarded middle exit + if( Binding·call(tm ,on_rightmost) ) break; + + // Separator + putchar(' '); + + // Step + Binding·call(tm ,step); + }while(1); + // Postfix + putchar('\n'); +} +#+END_SRC + +This avoids the need for counter variables, array indexing, or special cases for first/last iteration. + +* 5. Example: Nested TM Traversal + +The following example demonstrates two tapes—`tm1` of bytes, and `tm2` of strings—printing a byte followed by the full string tape on each outer step. + +#+BEGIN_SRC c +if( Binding·call(tm1 ,on_tape) && Binding·call(tm2 ,on_tape) ){ + do{ + // Prefix of outer loop + printf("%02x\n", (unsigned int) Binding·call(tm1 ,read)); + putchar(' '); + putchar(' '); + + // Inner loop: iterate over strings + do{ + printf("%s", Binding·call(tm2 ,read)); + if( Binding·call(tm2 ,on_rightmost) ) break; + putchar(' '); + Binding·call(tm2 ,step); + }while(1); + + // Postfix of inner loop + putchar('\n'); + + // Guarded exit + if( Binding·call(tm1 ,on_rightmost) ) break; + + // Advance outer head + Binding·call(tm1 ,step); + + // Reset inner head + Binding·call(tm2 ,rewind); + }while(1); + + // Final postfix + printf("\n"); +} +#+END_SRC + +This structure supports: +- Interleaved traversal of coextensive tapes +- Mid-line formatting +- Reusable subroutines for iteration + +* 6. Debugging Tips + +- Use `on_tape`, `on_rightmost`, and `status` to check head validity before reading. +- `rewind` is always safe to call, even on a dismounted tape. +- `dismount` prevents accidental traversal if a tape becomes invalid or externally reallocated. + +* 7. Summary + +The Tape Machine abstraction supports: +- Generic data traversal +- Separation of structure (tableau) from behavior (FG table) +- Elegant loop patterns with predictable control flow +- Multi-instance coexistence via templated bindings + +By adopting TMs, RT C code gains clarity and uniformity when working over ranges, buffers, or token streams—without abandoning type safety or performance. + +For detailed reference on bindings and FG tables, see: + +**📎 [[file:fg_bindings_and_tableaux.org][FG Tables and Bindings in RT C]]** + +**📎 [[file:fg_tables_core.org][FG Tables — Core Module Example]]** diff --git "a/developer/document\360\237\226\211/parameterized_functions.org" "b/developer/document\360\237\226\211/parameterized_functions.org" new file mode 100644 index 0000000..26d1c6a --- /dev/null +++ "b/developer/document\360\237\226\211/parameterized_functions.org" @@ -0,0 +1,120 @@ +* Parameterized Functions + Author: Thomas Walker Lynch / Drafted by Caerith + +* 1. Parameterization in Mathematics +In mathematics, **parameters** are used to define structured families of functions. For example, consider the family: + +#+BEGIN_SRC +{ f_t(x) = t * x, g_t(y) = y + t^2, h_t(z) = sin(tz) } +#+END_SRC + +Each function in this family shares a symbolic parameter `t`, which organizes the family and distinguishes its members. The functions differ in behavior based on the fixed value of `t`, even though they operate on different primary arguments (`x`, `y`, `z`). + +This reveals the core role of a parameter in mathematics: it does not merely serve as an argument to a single function, but rather defines **a space of functions** — a higher-order structure from which individual functions can be selected by fixing the parameter. + +In this context, we say: +> A parameter is an external symbolic structure that appears as an argument in each function, but whose true role is to *coordinate or classify* the family of functions as a whole. + +Once a value is chosen for the parameter, it becomes fixed, and the resulting function behaves purely in terms of the remaining arguments. The collection \( \{f_t, g_t, h_t\} \) for varying `t` forms a **parameterized family**, and the parameter gives it structure. + +* 2. The Confusion in Computer Science +In computer science, the term "parameter" is typically conflated with what are more properly called arguments. One speaks of a "parameter list" when defining a function, but these are just **argument symbols**, and at runtime, **argument values** are supplied. + +To clarify: +- An **argument symbol** is a variable used in a function definition. +- An **argument value** is an input supplied at invocation. + +We reserve **parameter** to mean: *a symbolic value that organizes or shapes a function or function family*. This returns us to the mathematical intent. + +Seen from this angle, **object-oriented programming** is a way of constructing **families of parameterized functions** — each method implicitly taking the object (`this`) as a shared structure. That object acts as a **fixed symbolic input** across many functions: it is the parameter. The set of methods thus defines a family. + +- For one parameter (i.e., one receiver object), the system is straightforward. +- For two, ambiguity emerges: whose methods govern? This gives rise to multiple dispatch, traits, and other formal structures. + +Thus, **object-orientation is a particular implementation of parameterized function families**, where the parameter is embedded as implicit context. + +* 3. When Parameters Can Change: Machines +In pure mathematics, the parameter is fixed during evaluation. But when a function can *modify* its parameter — i.e., mutate the context it depends on — then we are no longer dealing with functions in the mathematical sense. + +> When the parameter is no longer constant, but mutable, it becomes **state**. + +A function family with a mutable parameter is not a function family at all — it is a **machine**. The state evolves over time, and each function application may affect future behavior. + +This is a transition from **functional** to **stateful** systems. The parameter becomes a **tableau**: a symbolic structure that holds state, arguments, results, and evolves during execution. It is the parameter made writable, and the environment through which computational interaction unfolds. + +A tableau is not limited to a single function family — it may participate in multiple. It is both an input/output workspace and a memory of prior execution. + +In this view, TTCA and similar systems operate not just with functions, but with machines — bundles of callable behaviors that mutate their shared tableau. + +* 4. Our Terminology +To capture these distinctions, we adopt the following terminology: + +- **PFT**: A *Parameterized Function Table* over carrier type `T`. This is a symbolic table of functions that each expect a `T` as their first argument. +- **M** or **Machine**: A special case of PFT where `T` is not constant but a **tableau**, and may be mutated during evaluation. +- **Tableau**: A symbolic structure that accumulates inputs, stores return values, and evolves during execution. It is both interface and state — a writable parameter and a staging area for symbolic computation. It generalizes a stack frame and may serve multiple function families simultaneously. + +This language aligns our system with mathematical clarity while preserving the structural richness of the tableau concept. + +* 5. The Parameter Connector: Binding Parameters to Function Families +In mathematics, writing a subscript such as `f_t(x)` indicates that a function family `f` has been **partially applied** by fixing its parameter `t`. This is called **partial application** — and it represents the act of creating a specific instance of a function from a broader, parameterized family. + +In our system, we reflect this idea using a symbolic structure called the **Parameter Connector**. + +> A **Parameter Connector** is a type that declares how a specific parameter (e.g., a `Tableau`) is to be coupled with a Parameterized Function Table (PFT). It is the symbolic form that supports partial application and prepares the ground for dispatch. + +The macro: + +#+BEGIN_SRC c +DECLARE_PARAMETER_CONNECTOR(MyType) +#+END_SRC + +declares a `struct` named `MyType`, which contains: +- a pointer to a `MyType_Tableau` (the parameter value) +- a pointer to a `MyType_PFT` (the function table) + +This struct is the **parameter connector**. It does not yet perform binding, but defines the shape of a pairing. Once an instance is created — with the parameter value assigned — we may dispatch calls via: + +#+BEGIN_SRC c +call(connector, fn_name, args...); +#+END_SRC + +This pattern reflects the subscripting act in mathematics. The `connector` serves as the **parameter-binding context**: it is what affixes the symbolic `t` to the `f` in `f_t(x)`. + +In this way: +- **The connector is to `call()` what a subscript is to a function name**. +- It allows partial application of parameterized function tables. +- It forms the bridge from symbolic family to concrete callable form. + +Thus, the **parameter connector** is the central structure that enables meaningful dispatch in a system of parameterized functions — faithful both to mathematical abstraction and to C's structural constraints. + + + + +#+BEGIN_SRC + ┌──────────────────────┐ + │ Function Family │ + └────────┬─────────────┘ + │ + ┌───────────────┼───────────────┐ + ▼ ▼ +┌──────────────┐ ┌────────────────────┐ +│ Parameter t │ │ Parameterized │ +│ (symbolic) │ │ Function Table PFT │ +└──────┬───────┘ └────────┬───────────┘ + ▼ ▼ + ┌───────────────────────────────────┐ + │ Partial Application Step │ + └──────────────┬────────────────────┘ + ▼ + ┌────────────────────────┐ + │ Parameter Connector │ + └────────────┬───────────┘ + ▼ + ┌─────────────┐ + │ call() │ + └────┬────────┘ + ▼ + ┌───────────────┐ + │ Machine │ + └───────────────┘ +#+END_SRC diff --git "a/developer/document\360\237\226\211/source_file_sectioins.org" "b/developer/document\360\237\226\211/source_file_sectioins.org" new file mode 100644 index 0000000..48d0573 --- /dev/null +++ "b/developer/document\360\237\226\211/source_file_sectioins.org" @@ -0,0 +1,107 @@ +#+TITLE: RT Library Structure Guide +#+AUTHOR: Sorein (on request by Thomas) +#+DATE: 2025-04-25 + +* Purpose +This document describes the architectural sections in `*.lib.c` files of the RT codebase. +It explains the use of `#if`-guarded blocks including `FACE`, `LOCAL`, `LIBRARY`, and template instantiations. + +* Section Overview + +** FACE :: Public Interface and Template Declaration +#+BEGIN_SRC c +#ifndef Module·FACE +#define Module·FACE +... +#endif +#+END_SRC + +- Declares types, enums, constants, and FG tables. +- Includes other modules (`Core.lib.c`, `cpp_ext.c`). +- Safe to include multiple times. +- No runtime state or implementation logic. + +** LOCAL :: Private Implementations and Table Initialization +#+BEGIN_SRC c +#ifdef LOCAL +#ifndef Module·LOCAL +#define Module·LOCAL +... +#endif +#endif +#+END_SRC + +- Defines functions, local constants, and FG table initializations. +- Only included when `LOCAL` is defined. +- Hidden from consumers. +- Use guards to prevent duplicate inclusion. + +** LIBRARY :: Compiled Static Library Content +#+BEGIN_SRC c +#ifdef LIBRARY +... +#endif +#+END_SRC + +- Reserved for future components to be compiled into a `.a` archive. +- Currently unused in `Core`, `TM`, or `Binding`. +- Separates linkable components from inline-included ones. + +** Template Parameters :: Type-Specific Inclusion Guards +#+BEGIN_SRC c +#ifdef _TM·CVT_ +#if BOOLEAN( NOT_IN(Binding ,TM·) ) +... +#endif +#endif +#+END_SRC + +- Allows per-type instantiation (e.g. `TM·AU`, `TM·Str`). +- Ensures that each instantiation happens only once. +- Guards must be defined by the *caller*, e.g.: + #+BEGIN_SRC c + #define _TM·CVT_ AU + #include "TM.lib.c" + #define SET__Binding__TM·AU + #+END_SRC + +** Undef Section :: Template Parameter Cleanup +#+BEGIN_SRC c +#undef _TM·CVT_ +#+END_SRC + +- Prevents leakage of template macros between inclusions. + +* Summary Table + +#+ATTR_LATEX: :environment tabular :align |l|l|l|l| +| *Section* | *Guard Macro* | *Purpose* | *Include Frequency* | +|-----------------+-------------------------+------------------------------------------------+-----------------------------| +| FACE | #ifndef Module·FACE | Public declarations, typedefs, constants | Once per TU or header | +| LOCAL | #ifdef LOCAL | Function definitions, internal state | Only in .cli.c or test file | +| LIBRARY | #ifdef LIBRARY | Static linkable content (future use) | Optional | +| Template Block | #ifdef _TEMPLATE_... | Per-template instantiation | Once per unique value | +| Undef Section | #undef _TEMPLATE_... | Cleanup template identifiers | Always | + +* Best Practices + +- **Order matters:** Include `FACE` before defining templates or using macros. +- **Avoid leakage:** Always `#undef` template variables after instantiation. +- **Limit `FACE` to declarations:** Do not define runtime behavior in `FACE`. +- **Use `LOCAL` in a single TU:** Only one translation unit should include `LOCAL` per template. +- **Separate compile/link concerns:** Use `LIBRARY` only for code compiled outside `cli`. + +* Example + +To use `TM·AU` and `TM·Str` in the same translation unit: +#+BEGIN_SRC c +#define _TM·CVT_ AU +#include "TM.lib.c" +#define SET__Binding__TM·AU + +#define _TM·CVT_ Str +#include "TM.lib.c" +#define SET__Binding__TM·Str" +#+END_SRC + +* End diff --git "a/developer/document\360\237\226\211/template_in_C.org" "b/developer/document\360\237\226\211/template_in_C.org" new file mode 100644 index 0000000..e723a42 --- /dev/null +++ "b/developer/document\360\237\226\211/template_in_C.org" @@ -0,0 +1,83 @@ +* Minimal Templating in RT C: The Box Example +:PROPERTIES: +:AUTHOR: Sorein +:DATE: 2025-04-25 +:END: + +This document presents a minimal and idiomatic example of **templating in RT C**, using a generic "box" type. + +We follow the RT convention for template macros: +- Template parameters are named with **leading and trailing underscores**, e.g. `_Box_T_`. +- A **set macro** (e.g. `SET__Box__int`) must be defined after inclusion to prevent duplicate instantiations. + +This example avoids FG tables, tableaux, or polymorphism—it exists purely to show type reuse through macro-based inclusion. + +* Template Logic: box_template.h + +This header is included multiple times, once per type. It expects `_Box_T_` to be defined. + +#+BEGIN_SRC c +#ifndef _Box_T_ +#error "_Box_T_ must be defined before including box_template.h" +#endif + +#if !defined(·(SET__Box,_Box_T_)) +#define ·(SET__Box,_Box_T_) + +typedef struct{ + _Box_T_ value; +} ·(Box_Box,_Box_T_); + +void ·(Box_set,_Box_T_)( ·(Box_Box,_Box_T_)* b ,_Box_T_ x ){ + b->value = x; +} + +_Box_T_ ·(Box_get,_Box_T_)( ·(Box_Box,_Box_T_)* b ){ + return b->value; +} + +#endif +#+END_SRC + +* Instantiating the Template + +You instantiate the template by defining `_Box_T_` before inclusion. Afterward, define the `SET__...` macro to guard against repeat. + +#+BEGIN_SRC c +#define _Box_T_ int +#include "box_template.h" +#define SET__Box__int + +#define _Box_T_ char* +#include "box_template.h" +#define SET__Box__char_ptr +#+END_SRC + +* Example Usage + +Once the template is instantiated, you can use the generated types and functions. + +#+BEGIN_SRC c +#include + +int main(){ + ·(Box_Box,int) a; + ·(Box_set,int)(&a ,42); + printf("a = %d\n", ·(Box_get,int)(&a)); + + ·(Box_Box,char*) b; + ·(Box_set,char*)(&b ,"hello"); + printf("b = %s\n", ·(Box_get,char*)(&b)); + + return 0; +} +#+END_SRC + +* Summary + +This "box" example demonstrates the foundation of RT C templating: +- Code is included once per type with a unique `_Template_Var_`. +- `SET__...` guards prevent duplicate instantiation. +- Type-specific names (`Box_set,int`) are generated using token pasting macros like `·(...)`. + +From here, this pattern scales naturally to complex modules like `TM·AU`, while retaining clarity, reusability, and full type safety. diff --git a/developer/example/0_readme.org b/developer/example/0_readme.org index d8f8a7d..2a4ebb5 100644 --- a/developer/example/0_readme.org +++ b/developer/example/0_readme.org @@ -1,3 +1,9 @@ -To build these standalone edit the tool🖉/makefil and uncommon the SRC=example and the CEFLAGS+= -I/cpp🖉 lines. Then do the usual make clean dependency; make cli +To build these standalone edit the tool🖉/makefile and uncomment: + SRC=example +and + CEFLAGS+= -I/cc🖉 +. + +Then do the usual make clean dependency; make cli diff --git a/developer/example/bespoke.cli.c b/developer/example/bespoke.cli.c index bc3a2ca..3f2732d 100644 --- a/developer/example/bespoke.cli.c +++ b/developer/example/bespoke.cli.c @@ -21,7 +21,7 @@ #define _BINDING_ Bespoke #include "Binding.lib.c" - #define SET__Binding__Bespoke + #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{ diff --git a/developer/example/try_TM_1-6.transcript b/developer/example/try_TM_1-6.transcript new file mode 100644 index 0000000..93c2fb3 --- /dev/null +++ b/developer/example/try_TM_1-6.transcript @@ -0,0 +1,274 @@ + +2025-04-25T04:43:48Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> make clean ++ cd /home/Thomas/subu_data/developer/N/developer ++ /bin/make -f tool🖉/makefile clean +rm -f scratchpad/makefile-cc.deps scratchpad/libN.a +for obj in scratchpad/bespoke.cli.o scratchpad/try_TM_1.cli.o scratchpad/try_TM_2.cli.o scratchpad/try_TM_3.cli.o scratchpad/try_TM_4.cli.o scratchpad/try_TM_5.cli.o scratchpad/try_TM_6.cli.o; do rm -f $obj || true; done +for i in machine/bespoke machine/try_TM_1 machine/try_TM_2 machine/try_TM_3 machine/try_TM_4 machine/try_TM_5 machine/try_TM_6; do [ -e $i ] && rm $i || true; done ++ set +x +make done. + +2025-04-25T04:43:57Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> make dependency ++ cd /home/Thomas/subu_data/developer/N/developer ++ /bin/make -f tool🖉/makefile dependency +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -MM example/bespoke.cli.c example/try_TM_1.cli.c example/try_TM_2.cli.c example/try_TM_3.cli.c example/try_TM_4.cli.c example/try_TM_5.cli.c example/try_TM_6.cli.c \ + | sed 's|^.*\.o|scratchpad/&|' >> scratchpad/makefile-cc.deps;\ +echo "deps for C linking";\ + # build library:\ +for i in bespoke try_TM_1 try_TM_2 try_TM_3 try_TM_4 try_TM_5 try_TM_6; do\ + echo -e >> scratchpad/makefile-cc.deps;\ + echo -e "machine/$i : scratchpad/$i.cli.o scratchpad/libN.a" >> scratchpad/makefile-cc.deps;\ + echo -e " gcc -o machine/$i scratchpad/$i.cli.o -Lscratchpad -L/lib64 -L/lib -lN" >> scratchpad/makefile-cc.deps;\ +done; +deps for C linking +make: Nothing to be done for 'dependency'. ++ set +x +make done. + +2025-04-25T04:44:01Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> make library ++ cd /home/Thomas/subu_data/developer/N/developer ++ /bin/make -f tool🖉/makefile library +ar rcs scratchpad/libN.a ++ set +x +make done. + +2025-04-25T04:44:07Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> make cli ++ cd /home/Thomas/subu_data/developer/N/developer ++ /bin/make -f tool🖉/makefile cli +make sub_cli ++ cd /home/Thomas/subu_data/developer/N/developer ++ /bin/make -f tool🖉/makefile sub_cli +make[1]: Entering directory '/home/Thomas/subu_data/developer/N/developer' +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/bespoke.cli.o -c example/bespoke.cli.c +In file included from example/bespoke.cli.c:14: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/bespoke.cli.c:23: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> Bespoke’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +gcc -o machine/bespoke scratchpad/bespoke.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_1.cli.o -c example/try_TM_1.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_1.cli.c:7: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_1.cli.c:10: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_1.cli.c:39: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_1 scratchpad/try_TM_1.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_2.cli.o -c example/try_TM_2.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_2.cli.c:7: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_2.cli.c:10: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_2.cli.c:15: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> Str’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·Str’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_2.cli.c:64: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from example/try_TM_2.cli.c:68: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> Str’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_2 scratchpad/try_TM_2.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_3.cli.o -c example/try_TM_3.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_3.cli.c:7: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_3.cli.c:11: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_3.cli.c:16: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> Str’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·Str’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_3.cli.c:22: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from example/try_TM_3.cli.c:27: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> Str’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_3 scratchpad/try_TM_3.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_4.cli.o -c example/try_TM_4.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_4.cli.c:7: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_4.cli.c:10: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_4.cli.c:15: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> Str’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·Str’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_4.cli.c:61: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from example/try_TM_4.cli.c:65: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> Str’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_4 scratchpad/try_TM_4.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_5.cli.o -c example/try_TM_5.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_5.cli.c:8: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_5.cli.c:11: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_5.cli.c:65: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_5 scratchpad/try_TM_5.cli.o -Lscratchpad -L/lib64 -L/lib -lN +gcc -Icc🖉 -include "/home/Thomas/subu_data/developer/N/tool_shared/third_party/RT-project-share/release/make/RT_0.h" -I example -o scratchpad/try_TM_6.cli.o -c example/try_TM_6.cli.c +In file included from cc🖉/TM.lib.c:27, + from example/try_TM_6.cli.c:7: +cc🖉/Binding.lib.c:29:13: note: ‘#pragma message: in #ifndef Binding_LIST section’ + 29 | #pragma message( "in #ifndef Binding_LIST section" ) + | ^~~~~~~ +In file included from example/try_TM_6.cli.c:10: +cc🖉/TM.lib.c:70:11: note: ‘#pragma message: Creating TM type with a CVT of:_TM·CVT_ -> AU’ + 70 | #pragma message( "Creating TM type with a CVT of:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +In file included from cc🖉/TM.lib.c:74: +cc🖉/Binding.lib.c:60:11: note: ‘#pragma message: adding binding for:_BINDING_ -> TM·AU’ + 60 | #pragma message( "adding binding for:" STR_VAL(_BINDING_) ) + | ^~~~~~~ +In file included from example/try_TM_6.cli.c:46: +cc🖉/TM.lib.c:200:13: note: ‘#pragma message: Including LOCAL code for:_TM·CVT_ -> AU’ + 200 | #pragma message( "Including LOCAL code for:" STR_VAL(_TM·CVT_) ) + | ^~~~~~~ +gcc -o machine/try_TM_6 scratchpad/try_TM_6.cli.o -Lscratchpad -L/lib64 -L/lib -lN +make[1]: Leaving directory '/home/Thomas/subu_data/developer/N/developer' ++ set +x +make done. ++ set +x +make done. + +2025-04-25T04:44:15Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ls machine +. .. bespoke .gitignore try_TM_1 try_TM_2 try_TM_3 try_TM_4 try_TM_5 try_TM_6 + +2025-04-25T04:44:51Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_1 +running try_TM_1.cli.c on Apr 25 2025 at 04:44:14 +01 02 03 04 05 + +2025-04-25T04:45:18Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_2 +running try_TM_2.cli.c on Apr 25 2025 at 04:44:14 +TM·AU tape: aa 55 c2 +TM·Str tape: "hello" "world" "Calderis" + +2025-04-25T04:45:25Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_3 +running try_TM_3.cli.c on Apr 25 2025 at 04:44:14 +Initial TM·AU tape: +aa 55 c2 01 +Initial TM·Str tape: +"hello" "world" "Calderis" "(null)" +After dismount/remount, AU read: aa +After step to right and left again: aa + +2025-04-25T04:45:32Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_4 +running try_TM_2.cli.c on Apr 25 2025 at 04:44:14 +aa + hello world Calderis +55 + hello world Calderis +c2 + hello world Calderis + + +2025-04-25T04:45:40Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_5 +running try_TM_5.cli.c on Apr 25 2025 at 04:44:14 +Verifying written tape: +10 11 12 13 + +2025-04-25T04:45:48Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> ./machine/try_TM_6 +running try_TM_6.cli.c on Apr 25 2025 at 04:44:15 +Initial value: 3f +After stepping, value: a5 +After remount, value: a5 + +2025-04-25T04:45:55Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer§ +> diff --git a/developer/example/try_TM_1.cli.c b/developer/example/try_TM_1.cli.c index a43e852..01d17d7 100644 --- a/developer/example/try_TM_1.cli.c +++ b/developer/example/try_TM_1.cli.c @@ -4,11 +4,11 @@ #include #include "cpp_ext.c" -#include "TM.lib.c" +#include "TM·Array.lib.c" #define _TM·CVT_ AU -#include "TM.lib.c" -#define SET__Binding__TM·AU +#include "TM·Array.lib.c" +#define SET_Binding__TM·Array·AU int main(){ printf("running try_TM_1.cli.c on %s at %s\n", __DATE__, __TIME__); @@ -36,5 +36,5 @@ int main(){ #define LOCAL #define _TM·CVT_ AU -#include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#include "TM·Array.lib.c" +#define SET_TM·Array·LOCAL__TM·AU diff --git a/developer/example/try_TM_2.cli.c b/developer/example/try_TM_2.cli.c index b315402..499d28e 100644 --- a/developer/example/try_TM_2.cli.c +++ b/developer/example/try_TM_2.cli.c @@ -8,12 +8,12 @@ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__Binding__TM·AU +#define SET_Binding__TM·AU typedef char* Str; #define _TM·CVT_ Str #include "TM.lib.c" -#define SET__Binding__TM·Str +#define SET_Binding__TM·Str int main(){ printf("running try_TM_2.cli.c on %s at %s\n", __DATE__, __TIME__); @@ -62,9 +62,9 @@ int main(){ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#define SET_TM·LOCAL__TM·AU #define _TM·CVT_ Str #include "TM.lib.c" -#define SET__TM·LOCAL__TM·Str +#define SET_TM·LOCAL__TM·Str diff --git a/developer/example/try_TM_3.cli.c b/developer/example/try_TM_3.cli.c index 496f6d5..9fc8143 100644 --- a/developer/example/try_TM_3.cli.c +++ b/developer/example/try_TM_3.cli.c @@ -9,23 +9,23 @@ // Include the same type twice (should be gate-guarded) #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__Binding__TM·AU +#define SET_Binding__TM·AU #define _TM·CVT_ Str typedef char* Str; #include "TM.lib.c" -#define SET__Binding__TM·Str +#define SET_Binding__TM·Str // Include LOCAL twice as well #define LOCAL #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#define SET_TM·LOCAL__TM·AU #define LOCAL #define _TM·CVT_ Str #include "TM.lib.c" -#define SET__TM·LOCAL__TM·Str +#define SET_TM·LOCAL__TM·Str int main(){ printf("running try_TM_3.cli.c on %s at %s\n", __DATE__, __TIME__); diff --git a/developer/example/try_TM_4.cli.c b/developer/example/try_TM_4.cli.c index 75327f1..b86ddbf 100644 --- a/developer/example/try_TM_4.cli.c +++ b/developer/example/try_TM_4.cli.c @@ -1,5 +1,5 @@ /* - try_TM_2.cli.c - Demonstrates two coexisting TM types: TM·AU and TM·str. + try_TM_4.cli.c - Demonstrates two coexisting TM types: TM·AU and TM·str. */ #include @@ -8,12 +8,12 @@ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__Binding__TM·AU +#define SET_Binding__TM·AU typedef char* Str; #define _TM·CVT_ Str #include "TM.lib.c" -#define SET__Binding__TM·Str +#define SET_Binding__TM·Str int main(){ printf("running try_TM_2.cli.c on %s at %s\n", __DATE__, __TIME__); @@ -59,9 +59,9 @@ int main(){ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#define SET_TM·LOCAL__TM·AU #define _TM·CVT_ Str #include "TM.lib.c" -#define SET__TM·LOCAL__TM·Str +#define SET_TM·LOCAL__TM·Str diff --git a/developer/example/try_TM_5.cli.c b/developer/example/try_TM_5.cli.c index e5494a3..4c814e3 100644 --- a/developer/example/try_TM_5.cli.c +++ b/developer/example/try_TM_5.cli.c @@ -9,7 +9,7 @@ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__Binding__TM·AU +#define SET_Binding__TM·AU int main(){ printf("running try_TM_5.cli.c on %s at %s\n", __DATE__, __TIME__); @@ -63,4 +63,4 @@ int main(){ #define LOCAL #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#define SET_TM·LOCAL__TM·AU diff --git a/developer/example/try_TM_6.cli.c b/developer/example/try_TM_6.cli.c index 519a1e2..2d785ae 100644 --- a/developer/example/try_TM_6.cli.c +++ b/developer/example/try_TM_6.cli.c @@ -8,7 +8,7 @@ #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__Binding__TM·AU +#define SET_Binding__TM·AU int main(){ @@ -44,4 +44,4 @@ int main(){ #define LOCAL #define _TM·CVT_ AU #include "TM.lib.c" -#define SET__TM·LOCAL__TM·AU +#define SET_TM·LOCAL__TM·AU diff --git a/developer/example_cpp/example_A.transcript b/developer/example_cpp/example_A.transcript new file mode 100644 index 0000000..8481a32 --- /dev/null +++ b/developer/example_cpp/example_A.transcript @@ -0,0 +1,19 @@ +2025-04-25T04:26:16Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> gcc example_A.c + +2025-04-25T04:28:46Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> ./a.out + I like the number 123 + A (123) +A (123) --> I like the number 123 +A NULL_FN() (123) --> A (123) + + I like the number 123 +EVAL1(A NULL_FN() (123)) --> I like the number 123 + + +2025-04-25T04:28:50Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> \ No newline at end of file diff --git a/developer/example_cpp/example_eval.c b/developer/example_cpp/example_eval.c index e60af83..c12a4d9 100644 --- a/developer/example_cpp/example_eval.c +++ b/developer/example_cpp/example_eval.c @@ -11,19 +11,6 @@ int main(void){ SHOW(NOT_SO_FAST(5)); #define BE(x) x - SHOW(BE(NOT_SO_FAST(5))) + SHOW(BE(NOT_SO_FAST(5))); } -/* - 2025-03-27T04:47:02Z[developer] - Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ - > gcc example_eval.c - - 2025-03-27T04:47:32Z[developer] - Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ - > ./a.out - example_eval.c - NOT_SO_FAST(5) → NEGATE (5) - BE(NOT_SO_FAST(5)) → -5 - -*/ diff --git a/developer/example_cpp/example_eval.transcript b/developer/example_cpp/example_eval.transcript new file mode 100644 index 0000000..438642f --- /dev/null +++ b/developer/example_cpp/example_eval.transcript @@ -0,0 +1,10 @@ +2025-03-27T04:47:02Z[developer] +Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ +> gcc example_eval.c + +2025-03-27T04:47:32Z[developer] +Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ +> ./a.out +example_eval.c +NOT_SO_FAST(5) → NEGATE (5) +BE(NOT_SO_FAST(5)) → -5 diff --git a/developer/example_cpp/example_grow.c b/developer/example_cpp/example_grow.c index 74f3cca..73a76ba 100644 --- a/developer/example_cpp/example_grow.c +++ b/developer/example_cpp/example_grow.c @@ -90,32 +90,3 @@ int main(void){ // BE(RESULT2) --> 1029 * GROW6 (151) } -/* - 2025-03-27T10:45:39Z[developer] -Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ -> gcc example_grow.c - -2025-03-27T11:43:19Z[developer] -Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ -> ./a.out -example_grow.c - -GROW(7) --> 17 * GROW(7) -GROW(GROW(5)) --> 17 * GROW(17 * GROW(5)) - -GROW2(11) --> 19 * GROW2 (11) - -GROW3(13) --> 119 * 19 * GROW2 (13) - -GROW4(15) --> 123 * GROW4 (15) - -BE(GROW5(21)) --> 541 * 541 * CONFEDERATE () (21) -BE(BE(GROW5(57))) --> 541 * 541 * 541 * CONFEDERATE () (57) - -RESULT1 --> 1029 * GROW6 (51) -BE(RESULT1) --> 1029 * GROW6 (51) - -RESULT2 --> 1029 * GROW6 (151) -BE(RESULT2) --> 1029 * GROW6 (151) - -*/ diff --git a/developer/example_cpp/example_grow.transcript b/developer/example_cpp/example_grow.transcript new file mode 100644 index 0000000..945181c --- /dev/null +++ b/developer/example_cpp/example_grow.transcript @@ -0,0 +1,26 @@ +2025-03-27T10:45:39Z[developer] +Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ +> gcc example_grow.c + +2025-03-27T11:43:19Z[developer] +Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example§ +> ./a.out +example_grow.c + +GROW(7) --> 17 * GROW(7) +GROW(GROW(5)) --> 17 * GROW(17 * GROW(5)) + +GROW2(11) --> 19 * GROW2 (11) + +GROW3(13) --> 119 * 19 * GROW2 (13) + +GROW4(15) --> 123 * GROW4 (15) + +BE(GROW5(21)) --> 541 * 541 * CONFEDERATE () (21) +BE(BE(GROW5(57))) --> 541 * 541 * 541 * CONFEDERATE () (57) + +RESULT1 --> 1029 * GROW6 (51) +BE(RESULT1) --> 1029 * GROW6 (51) + +RESULT2 --> 1029 * GROW6 (151) +BE(RESULT2) --> 1029 * GROW6 (151) diff --git a/developer/example_cpp/example_grow2.transcript b/developer/example_cpp/example_grow2.transcript new file mode 100644 index 0000000..d675bad --- /dev/null +++ b/developer/example_cpp/example_grow2.transcript @@ -0,0 +1,16 @@ +2025-04-25T04:31:47Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> gcc example_grow2.c + +2025-04-25T04:32:50Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> ./a.out +One-trampoline minimal example: + +GROW(7) --> 19 * _GROW ()(7) +BE(GROW(7)) --> 19 * 19 * _GROW ()(7) +BE(BE(GROW(7))) --> 19 * 19 * 19 * _GROW ()(7) + +2025-04-25T04:32:53Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> \ No newline at end of file diff --git a/developer/example_cpp/example_recurse.transcript b/developer/example_cpp/example_recurse.transcript new file mode 100644 index 0000000..5aae4f4 --- /dev/null +++ b/developer/example_cpp/example_recurse.transcript @@ -0,0 +1,27 @@ +2025-04-25T04:32:53Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> gcc example_recurse.c + +2025-04-25T04:33:40Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> ./a.out +No EVAL: + RECURSE() +RECURSE() --> I am recursive, look: _RECURSE ()() + +With EVAL1: + EVAL1(RECURSE()) +EVAL1(RECURSE()) --> I am recursive, look: I am recursive, look: _RECURSE ()() + +With EVAL2: + EVAL2(RECURSE()) +EVAL2(RECURSE()) --> I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: _RECURSE ()() + +With EVAL32: + EVAL32(RECURSE()) +EVAL32(RECURSE()) --> I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: I am recursive, look: _RECURSE ()() + + +2025-04-25T04:33:43Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> \ No newline at end of file diff --git a/developer/example_cpp/try_ext_0.transcript b/developer/example_cpp/try_ext_0.transcript new file mode 100644 index 0000000..3dc632e --- /dev/null +++ b/developer/example_cpp/try_ext_0.transcript @@ -0,0 +1,75 @@ +2025-04-25T04:18:38Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> gcc try_ext_0.c + +2025-04-25T04:24:48Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> ./a.out +_FIRST(1) -> 1 +_FIRST() -> +_SECOND(1,2) -> 2 +_SECOND(1,) -> + +RETURN_NOTHING() -> + +_OR() -> +_OR(1) -> RETURN_NOTHING 1 () +_OR(1,2,3) -> RETURN_NOTHING 1 + +T(x) -> 7 +_NOT_ITEM() -> _NOT_ITEM() +_NOT_ITEM(1) -> _NOT_ITEM(1) +_NOT_ITEM(T(x)) -> _NOT_ITEM(7) + +NOT() -> 1 +NOT(1) -> +NOT(T(x)) -> +NOT(1,2,3) -> + +BOOL() -> BOOL() +CAT2(_IF_ ,BOOL()) -> _IF_BOOL() + +TO_1_OR_0() -> TO_1_OR_0() +TO_1_OR_0(1) -> TO_1_OR_0(1) +TO_1_OR_0(x) -> TO_1_OR_0(x) +TO_1_OR_0(1.2.3) -> TO_1_OR_0(1.2.3) + +EXISTS() -> +EXISTS(0) -> 1 +EXISTS(x,y,z) -> 1 + +LEQ2( , ) -> 1 +LEQ2( , 1 ) -> +LEQ2( 1, ) -> +LEQ2( 1, 0 ) -> 0 + +XOR2( , ) -> +XOR2( , 0 ) -> 0 +XOR2( 0, 0 ) -> + +AND2( , 0 ) -> +AND2( 0, 1 ) -> 1 + +OR2( , ) -> +OR2( , 0 ) -> 0 + +EQ(APPLE ,APPLE) -> 1 +EQ(APPLE ,PEAR) -> +EQ(PEAR ,PEAR) -> 1 +EQ(,) -> 1 +EQ(,PEAR) -> +EQ(PEAR ,) -> + +BOOLEAN() -> 0 +BOOLEAN(0) -> 1 +BOOLEAN(foo) -> 1 +BOOLEAN(1,2,3) -> 1 + +REST() -> +REST(1) -> +REST(1,2) -> 2 +REST(1,2,3) -> 2,3 + +2025-04-25T04:24:52Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> \ No newline at end of file diff --git a/developer/example_cpp/try_ext_1.c b/developer/example_cpp/try_ext_1.c index b0b5eaa..7b64c46 100644 --- a/developer/example_cpp/try_ext_1.c +++ b/developer/example_cpp/try_ext_1.c @@ -103,50 +103,4 @@ int main(void){ printf("\n"); } -/* - 2025-04-01T04:44:40Z[developer] - Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example_cpp§ - > gcc try_ext_1.c - 2025-04-01T04:44:44Z[developer] - Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example_cpp§ - > ./a.out - EVAL(EXAMPLE_CHAIN(3)) -> 3 + 1 + 1 - - FIND(IS_X ,A ,B ,X ,Y ,Z) -> X - FIND(IS_X ,A ,B ,C ,D) -> EOL() - - EQ(A ,B) -> - EQ(B ,B) -> 1 - - CONTAINS(C ,A ,B ,C ,D) -> 1 - CONTAINS(Z ,A ,B ,C ,D) -> - - WHILE(NON_Z ,A ,B ,C ,Z ,D ,E) -> - WHILE(NON_Z ,A ,B ,C) -> 1 - - EXISTS() -> - EXISTS(0) -> 1 - EXISTS(1) -> 1 - EXISTS(X) -> 1 - WHILE(EXISTS ,1 ,X , ) -> - WHILE(EXISTS ,1 , ,X ,0) -> - WHILE(EXISTS ,1 ,X ,0) -> 1 - - LAST(A ,B ,C ,D ,Z) -> Z - LAST(A ,B ,) -> - LAST() -> - - CAT(__oo__,A ,B ,C) -> A__oo__B__oo__C - CAT(,A ,B ,C) -> ABC - CAT(,A ,B ,) -> AB - CAT(,1) -> 1 - CAT(,) -> - - AND(1 ,X ,0) -> 1 - AND(1 ,X ,) -> - - OR( , , ,X) -> 1 - OR( , , ,) -> - -*/ diff --git a/developer/example_cpp/try_ext_1.transcript b/developer/example_cpp/try_ext_1.transcript new file mode 100644 index 0000000..a23bf12 --- /dev/null +++ b/developer/example_cpp/try_ext_1.transcript @@ -0,0 +1,97 @@ + 2025-04-01T04:44:40Z[developer] + Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example_cpp§ + > gcc try_ext_1.c + + 2025-04-01T04:44:44Z[developer] + Thomas-developer@Stanley§/home/Thomas-masu/developer/N/developer/example_cpp§ + > ./a.out + EVAL(EXAMPLE_CHAIN(3)) -> 3 + 1 + 1 + + FIND(IS_X ,A ,B ,X ,Y ,Z) -> X + FIND(IS_X ,A ,B ,C ,D) -> EOL() + + EQ(A ,B) -> + EQ(B ,B) -> 1 + + CONTAINS(C ,A ,B ,C ,D) -> 1 + CONTAINS(Z ,A ,B ,C ,D) -> + + WHILE(NON_Z ,A ,B ,C ,Z ,D ,E) -> + WHILE(NON_Z ,A ,B ,C) -> 1 + + EXISTS() -> + EXISTS(0) -> 1 + EXISTS(1) -> 1 + EXISTS(X) -> 1 + WHILE(EXISTS ,1 ,X , ) -> + WHILE(EXISTS ,1 , ,X ,0) -> + WHILE(EXISTS ,1 ,X ,0) -> 1 + + LAST(A ,B ,C ,D ,Z) -> Z + LAST(A ,B ,) -> + LAST() -> + + CAT(__oo__,A ,B ,C) -> A__oo__B__oo__C + CAT(,A ,B ,C) -> ABC + CAT(,A ,B ,) -> AB + CAT(,1) -> 1 + CAT(,) -> + + AND(1 ,X ,0) -> 1 + AND(1 ,X ,) -> + + OR( , , ,X) -> 1 + OR( , , ,) -> + +-------------------------------------------------------------------------------- + + +2025-04-25T04:18:18Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> gcc try_ext_1.c + +2025-04-25T04:18:34Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> ./a.out +EVAL(EXAMPLE_CHAIN(3)) -> 3 + 1 + 1 + +FIND(IS_X ,A ,B ,X ,Y ,Z) -> X +FIND(IS_X ,A ,B ,C ,D) -> EOL() + +EQ(A ,B) -> +EQ(B ,B) -> 1 + +CONTAINS(C ,A ,B ,C ,D) -> 1 +CONTAINS(Z ,A ,B ,C ,D) -> + +WHILE(NON_Z ,A ,B ,C ,Z ,D ,E) -> +WHILE(NON_Z ,A ,B ,C) -> 1 + +EXISTS() -> +EXISTS(0) -> 1 +EXISTS(1) -> 1 +EXISTS(X) -> 1 +WHILE(EXISTS ,1 ,X , ) -> +WHILE(EXISTS ,1 , ,X ,0) -> +WHILE(EXISTS ,1 ,X ,0) -> 1 + +LAST(A ,B ,C ,D ,Z) -> Z +LAST(A ,B ,) -> +LAST() -> + +CAT(__oo__,A ,B ,C) -> A__oo__B__oo__C +CAT(,A ,B ,C) -> ABC +CAT(,A ,B ,) -> AB +CAT(,1) -> 1 +CAT(,) -> + +AND(1 ,X ,0) -> 1 +AND(1 ,X ,) -> + +OR( , , ,X) -> 1 +OR( , , ,) -> + + +2025-04-25T04:18:38Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/example_cpp§ +> \ No newline at end of file diff --git a/developer/experiment/letter_all.c b/developer/experiment/letter_all.c new file mode 100644 index 0000000..4693878 --- /dev/null +++ b/developer/experiment/letter_all.c @@ -0,0 +1,175 @@ +#include +#include +#include +#include + +int is_identifier_start(uint32_t cp) { + if (cp >= 0xD800 && cp <= 0xDFFF) return 0; // Surrogate halves + if ((cp & 0xFFFF) == 0xFFFF || (cp & 0xFFFF) == 0xFFFE) return 0; // Noncharacters + + // ASCII letters and underscore + if ((cp >= 'A' && cp <= 'Z') || + (cp >= 'a' && cp <= 'z') || + cp == '_') return 1; + + // Latin-1 Supplement + if ((cp >= 0x00C0 && cp <= 0x00D6) || + (cp >= 0x00D8 && cp <= 0x00F6) || + (cp >= 0x00F8 && cp <= 0x00FF)) return 1; + + // Latin Extended-A and B + if ((cp >= 0x0100 && cp <= 0x017F) || + (cp >= 0x0180 && cp <= 0x024F)) return 1; + + // IPA Extensions, Spacing Modifier Letters + if ((cp >= 0x0250 && cp <= 0x02AF) || + (cp >= 0x02B0 && cp <= 0x02FF)) return 1; + + // Greek and Coptic + if (cp >= 0x0370 && cp <= 0x03FF) return 1; + + // Cyrillic + if ((cp >= 0x0400 && cp <= 0x04FF) || + (cp >= 0x0500 && cp <= 0x052F)) return 1; + + // Armenian + if (cp >= 0x0531 && cp <= 0x0556) return 1; + + // Hebrew + if (cp >= 0x05D0 && cp <= 0x05EA) return 1; + + // Arabic + if ((cp >= 0x0620 && cp <= 0x063F) || + (cp >= 0x0641 && cp <= 0x064A)) return 1; + + // Syriac + if (cp >= 0x0710 && cp <= 0x072F) return 1; + + // Thaana + if (cp >= 0x0780 && cp <= 0x07BF) return 1; + + // Devanagari + if (cp >= 0x0900 && cp <= 0x097F) return 1; + + // Bengali + if (cp >= 0x0980 && cp <= 0x09FF) return 1; + + // Gurmukhi + if (cp >= 0x0A00 && cp <= 0x0A7F) return 1; + + // Gujarati + if (cp >= 0x0A80 && cp <= 0x0AFF) return 1; + + // Oriya + if (cp >= 0x0B00 && cp <= 0x0B7F) return 1; + + // Tamil + if (cp >= 0x0B80 && cp <= 0x0BFF) return 1; + + // Telugu + if (cp >= 0x0C00 && cp <= 0x0C7F) return 1; + + // Kannada + if (cp >= 0x0C80 && cp <= 0x0CFF) return 1; + + // Malayalam + if (cp >= 0x0D00 && cp <= 0x0D7F) return 1; + + // Sinhala + if (cp >= 0x0D80 && cp <= 0x0DFF) return 1; + + // Thai + if (cp >= 0x0E00 && cp <= 0x0E7F) return 1; + + // Lao + if (cp >= 0x0E80 && cp <= 0x0EFF) return 1; + + // Tibetan + if (cp >= 0x0F00 && cp <= 0x0FBF) return 1; + + // Myanmar + if (cp >= 0x1000 && cp <= 0x109F) return 1; + + // Georgian + if ((cp >= 0x10A0 && cp <= 0x10FF) || (cp >= 0x2D00 && cp <= 0x2D2F)) return 1; + + // Hangul Jamo + if (cp >= 0x1100 && cp <= 0x11FF) return 1; + + // Ethiopic + if (cp >= 0x1200 && cp <= 0x137F) return 1; + + // Cherokee + if (cp >= 0x13A0 && cp <= 0x13FF) return 1; + + // Unified Canadian Aboriginal Syllabics + if (cp >= 0x1400 && cp <= 0x167F) return 1; + + // Ogham + if (cp >= 0x1680 && cp <= 0x169F) return 1; + + // Runic + if (cp >= 0x16A0 && cp <= 0x16FF) return 1; + + // Khmer + if (cp >= 0x1780 && cp <= 0x17FF) return 1; + + // Mongolian + if (cp >= 0x1800 && cp <= 0x18AF) return 1; + + // Limbu + if (cp >= 0x1900 && cp <= 0x194F) return 1; + + // Tai Le + if (cp >= 0x1950 && cp <= 0x197F) return 1; + + // New Tai Lue + if (cp >= 0x1980 && cp <= 0x19DF) return 1; + + // Bopomofo + if ((cp >= 0x3100 && cp <= 0x312F) || + (cp >= 0x31A0 && cp <= 0x31BF)) return 1; + + // CJK Unified Ideographs (Chinese, Japanese, Korean) + if ((cp >= 0x4E00 && cp <= 0x9FFF) || + (cp >= 0x3400 && cp <= 0x4DBF) || // Extension A + (cp >= 0x20000 && cp <= 0x2A6DF) || // Extension B + (cp >= 0x2A700 && cp <= 0x2B73F) || // Extension C + (cp >= 0x2B740 && cp <= 0x2B81F) || // Extension D + (cp >= 0x2B820 && cp <= 0x2CEAF) || // Extension E + (cp >= 0x2CEB0 && cp <= 0x2EBEF)) // Extension F + return 1; + + // Hiragana, Katakana (Japanese) + if ((cp >= 0x3040 && cp <= 0x309F) || (cp >= 0x30A0 && cp <= 0x30FF)) return 1; + + // Yi Syllables + if (cp >= 0xA000 && cp <= 0xA48F) return 1; + + // Letter Numbers (like Roman numerals) + if (cp >= 0x2160 && cp <= 0x2188) return 1; + + // Modifier letters + if ((cp >= 0x02B0 && cp <= 0x02FF)) return 1; + + return 0; +} + +int main(void) { + setlocale(LC_ALL, ""); + + for (uint32_t cp = 0; cp <= 0x10FFFF; ++cp) { + if (is_identifier_start(cp)) { + if (cp <= 0xFFFF) { + wprintf(L"%lc", (wchar_t)cp); + } else { + // Output surrogate pairs if necessary + uint32_t high = ((cp - 0x10000) >> 10) + 0xD800; + uint32_t low = ((cp - 0x10000) & 0x3FF) + 0xDC00; + wprintf(L"%lc%lc", (wchar_t)high, (wchar_t)low); + } + } + } + + return 0; +} diff --git a/developer/experiment/letter_delta.c b/developer/experiment/letter_delta.c new file mode 100644 index 0000000..234e578 --- /dev/null +++ b/developer/experiment/letter_delta.c @@ -0,0 +1,33 @@ +#include + +// Define interface and instance types +typedef struct { + void (*print_value)(int); +} N32·M; // Interface type + +typedef struct { + int value; +} N32·δ; // Instance type + +// Function implementation for the interface +void print_value_function(int value) { + printf("Value: %d\n", value); +} + +// Default interface instance +const N32·M N32·m = { + .print_value = print_value_function +}; + +int main() { + // Create an instance + N32·δ instance = { 99 }; + int Δ = 5; + + // Call function via interface + printf("Calling via interface: "); + N32·m.print_value(instance.value); + N32·m.print_value(Δ); + + return 0; +} diff --git a/developer/experiment/letter_lm_rm_1.c b/developer/experiment/letter_lm_rm_1.c new file mode 100644 index 0000000..11caebf --- /dev/null +++ b/developer/experiment/letter_lm_rm_1.c @@ -0,0 +1,11 @@ +#include + +//#define Ttype int +#define ▷type int + +int main() { + ▷type x = 1000; + + printf("x: %x %y" ,x); + return 0; +} diff --git a/developer/experiment/letter_lm_rm_2.c b/developer/experiment/letter_lm_rm_2.c new file mode 100644 index 0000000..8f6b018 --- /dev/null +++ b/developer/experiment/letter_lm_rm_2.c @@ -0,0 +1,14 @@ +#include + +//#define Ttype int +//#define ⊏type int +//#define ⊐type int + +int main() { + // ⊏type x = 1000; + // ⊐type y = 2000; + + int ⊏x = 5; + printf("x: %x %y" ,x); + return 0; +} diff --git a/developer/experiment/letter_lm_rm_3.c b/developer/experiment/letter_lm_rm_3.c new file mode 100644 index 0000000..5c05290 --- /dev/null +++ b/developer/experiment/letter_lm_rm_3.c @@ -0,0 +1,21 @@ +#include + +int main() { + int xコ = 5; + int ㄈx = 7; + printf("x: %x %x" ,xコ ,ㄈx); + return 0; +} + +/* +2025-04-25T11:25:54Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/experiment§ +> ./a.out +x: 5 7 +*/ + +/* +Identifier Character(s) Unicode Category Allowed? Font visible? +xコ Katakana KO Lo (Letter, Other) ✅ Yes If font supports Katakana +ㄈx Bopomofo FA Lo (Letter, Other) ✅ Yes Often not visible unless font supports Zhuyin +*/ diff --git a/developer/experiment/letter_lm_rm_4.c b/developer/experiment/letter_lm_rm_4.c new file mode 100644 index 0000000..69b1062 --- /dev/null +++ b/developer/experiment/letter_lm_rm_4.c @@ -0,0 +1,18 @@ +#include + +int main() { + int xƆ = 15; + int Cx = 17; + printf("x: %x %x" ,xƆ ,Cx); + return 0; +} + +/* +2025-04-25T11:29:39Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/experiment§ +> ./a.out +x: f 11 +2025-04-25T11:29:41Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/experiment§ +> +*/ diff --git a/developer/experiment/letter_minus.c b/developer/experiment/letter_minus.c new file mode 100644 index 0000000..f2cf210 --- /dev/null +++ b/developer/experiment/letter_minus.c @@ -0,0 +1,17 @@ +#include + +int main() { + int ˗x = 23; + printf("x: %x %x" ,˗x); + return 0; +} + +/* +2025-04-25T14:49:07Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/experiment§ +> ./a.out +x: 17 bfeedf08 +2025-04-25T14:49:09Z[developer] +Thomas-developer@StanleyPark§/home/Thomas/subu_data/developer/N/developer/experiment§ +> +*/ diff --git a/developer/experiment/letter_mu.c b/developer/experiment/letter_mu.c new file mode 100644 index 0000000..2bf88cd --- /dev/null +++ b/developer/experiment/letter_mu.c @@ -0,0 +1,31 @@ +#include + +// Define interface and instance types +typedef struct { + void (*print_value)(int); +} N32·M; // Interface type + +typedef struct { + int value; +} N32·μ; // Instance type + +// Function implementation for the interface +void print_value_function(int value) { + printf("Value: %d\n", value); +} + +// Default interface instance +const N32·M N32·m = { + .print_value = print_value_function +}; + +int main() { + // Create an instance + N32·μ instance = { 99 }; + + // Call function via interface + printf("Calling via interface: "); + N32·m.print_value(instance.value); + + return 0; +} diff --git a/developer/experiment/letter_theta.c b/developer/experiment/letter_theta.c new file mode 100644 index 0000000..2765a5a --- /dev/null +++ b/developer/experiment/letter_theta.c @@ -0,0 +1,12 @@ +#include + +//#define Ttype int +#define Θtype int + +int main() { + Θtype x = 1000; + //Ttype x = 1000; + + printf("x: %x" ,x); + return 0; +} diff --git a/developer/experiment/temp b/developer/experiment/temp new file mode 100644 index 0000000..ca8e860 --- /dev/null +++ b/developer/experiment/temp @@ -0,0 +1,6 @@ +mv print_id_letters.c letters_legal_all.c +mv try_letter_lm_rm_2.c letter_lm_rm_1.c +mv try_letter_mu.c letter_mu.c +mv try_letters_delta.c letter_delta.c +mv try_letters_lm_rm.c letter_lm_rm_2.c +mv try_letters_theta.c letter_theta.c \ No newline at end of file diff --git a/developer/experiment/try_letters.c b/developer/experiment/try_letters.c deleted file mode 100644 index 2bf88cd..0000000 --- a/developer/experiment/try_letters.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -// Define interface and instance types -typedef struct { - void (*print_value)(int); -} N32·M; // Interface type - -typedef struct { - int value; -} N32·μ; // Instance type - -// Function implementation for the interface -void print_value_function(int value) { - printf("Value: %d\n", value); -} - -// Default interface instance -const N32·M N32·m = { - .print_value = print_value_function -}; - -int main() { - // Create an instance - N32·μ instance = { 99 }; - - // Call function via interface - printf("Calling via interface: "); - N32·m.print_value(instance.value); - - return 0; -} diff --git a/developer/experiment/try_letters_2.c b/developer/experiment/try_letters_2.c deleted file mode 100644 index 234e578..0000000 --- a/developer/experiment/try_letters_2.c +++ /dev/null @@ -1,33 +0,0 @@ -#include - -// Define interface and instance types -typedef struct { - void (*print_value)(int); -} N32·M; // Interface type - -typedef struct { - int value; -} N32·δ; // Instance type - -// Function implementation for the interface -void print_value_function(int value) { - printf("Value: %d\n", value); -} - -// Default interface instance -const N32·M N32·m = { - .print_value = print_value_function -}; - -int main() { - // Create an instance - N32·δ instance = { 99 }; - int Δ = 5; - - // Call function via interface - printf("Calling via interface: "); - N32·m.print_value(instance.value); - N32·m.print_value(Δ); - - return 0; -} diff --git a/developer/experiment/try_letters_3.c b/developer/experiment/try_letters_3.c deleted file mode 100644 index 2765a5a..0000000 --- a/developer/experiment/try_letters_3.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -//#define Ttype int -#define Θtype int - -int main() { - Θtype x = 1000; - //Ttype x = 1000; - - printf("x: %x" ,x); - return 0; -} diff --git "a/developer/tool\360\237\226\211/makefile" "b/developer/tool\360\237\226\211/makefile" index 41932ad..47afa2f 100644 --- "a/developer/tool\360\237\226\211/makefile" +++ "b/developer/tool\360\237\226\211/makefile" @@ -3,15 +3,11 @@ RT-INCOMMON:=$(REPO_HOME)/tool_shared/third_party/RT-project-share/release include $(RT-INCOMMON)/make/environment_RT_0 -# to compile only the example directory -# comment these out for a normal compile -# +# To compile the example directory uncomment the following assignments: SRCDIR_List=example -# -# if the .lib.c interfaces are needed: -# CFLAGS+=-Icc🖉 + CFLAGS+= -include "$(RT-INCOMMON)/make/RT_0.h" LINKFLAGS+= -l$(PROJECT) LIBFILE=$(LIBDIR)/lib$(PROJECT).a diff --git "a/document\360\237\226\211/#temp.txt#" "b/document\360\237\226\211/#temp.txt#" new file mode 100644 index 0000000..3648a70 --- /dev/null +++ "b/document\360\237\226\211/#temp.txt#" @@ -0,0 +1,93 @@ +#+TITLE: TM Bulk Methods Using Area and Extent +#+AUTHOR: Sorein +#+DATE: 2025-04-25 + +* 1. Motivation: Copying Over Areas, Not Just Cells + +In TTCA, a **cell** is the basic unit of memory or tape, and a **Tape Machine (TM)** traverses such cells with a movable head. + +For high-throughput operations like `Copy`, operating on one cell at a time is inefficient. Instead, we want to operate over an **area**: a concrete, contiguous **sequence of cells**, defined by: + +- A **starting address** (typically the current head position) +- An **extent** — the **inclusive upper bound** of the area + +This gives the TM enough structure to reason about **bulk memory access** safely and efficiently. + +TTCA terminology distinguishes: +- **Area**: A sequence of cells between a starting point and an extent. +- **Extent**: The highest address within that area. +- **Distance**: The difference between the head and the extent (extent − head), used internally but not exposed as API input. + +We avoid using “length” as it is ambiguous and may overflow (`distance + 1`). + +* 2. Proposed TM Methods for Bulk Area Access + +Each TM instantiated over a Cell Value Type (CVT) can optionally support the following methods: + +#+BEGIN_SRC c +bool TM·AU·can_area(TM·AU tm ,uintptr_t extent); +AU const* TM·AU·peek_area(TM·AU tm ,uintptr_t extent); +AU* TM·AU·claim_area(TM·AU tm ,uintptr_t extent); +void TM·AU·commit_area(TM·AU tm ,uintptr_t extent); +uintptr_t TM·AU·extent_right(TM·AU tm); +#+END_SRC + +* 3. Method Semantics + +| Method | Meaning | +|-------------------------+-------------------------------------------------------------------------| +| `can_area(extent)` | True if the tape has a contiguous area from head up to this extent | +| `peek_area(extent)` | Returns a const pointer to the area [head … extent], or NULL | +| `claim_area(extent)` | Returns a writable pointer to the area [head … extent], or NULL | +| `commit_area(extent)` | Advances the head from current position to `extent` (inclusive) | +| `extent_right()` | Returns the extent (inclusive upper bound) of the tape | + +All returned areas are assumed to be **concrete**—that is, the TM guarantees: +- All cells in the area are physically allocated +- Their memory layout is contiguous +- They can be safely accessed as an array of CVT values + +If these conditions are not met (e.g. for cyclic or segmented tapes), the TM returns `false` or `NULL`. + +* 4. Area-Based Copy Example + +Using these methods, an efficient `Copy` routine becomes: + +#+BEGIN_SRC c +while( TM·AU·can_area(src ,e) && TM·AU·can_area(dst ,e) ){ + AU const* from = TM·AU·peek_area(src ,e); + AU* to = TM·AU·claim_area(dst ,e); + uintptr_t count = e - src_index + 1; + memcpy(to ,from ,count * sizeof(AU)); + TM·AU·commit_area(src ,e); + TM·AU·commit_area(dst ,e); +} +#+END_SRC + +Note: +- `e` is the intended extent (inclusive). +- `count = extent − head + 1` is used internally, but not exposed as "length". + +* 5. Capability Declaration + +Not all TMs support contiguous areas. To indicate whether a TM supports these methods, we may define: + +#+BEGIN_SRC c +typedef enum{ + TM·Caps·none = 0, + TM·Caps·area = 1 << 0 +} TM·Caps; +#+END_SRC + +This allows dispatchers to check if area-based methods are available for a given tape. + +* 6. Summary + +- We operate on **areas**, defined as `[head … extent]`, where `extent` is inclusive. +- We avoid using "length" in API design, since it implies `distance + 1`, which may overflow. +- **Area methods** allow batch reading or writing with fewer dispatches and better memory performance. +- These methods align TM with TTCA's formal model, supporting structured, efficient, and correct stream operations. + +This sets the foundation for writing `Copy`, `Map`, and other stream-based transformations using TMs as high-level iterators over cell areas. + +Would you like a matching `.org` draft for the FACE section of `Copy.lib.c`, now assuming the availability of these `area` methods? diff --git "a/document\360\237\226\211/Abstracting_Type_in_C.org" "b/document\360\237\226\211/Abstracting_Type_in_C.org" index 9a50785..17b5ec9 100644 --- "a/document\360\237\226\211/Abstracting_Type_in_C.org" +++ "b/document\360\237\226\211/Abstracting_Type_in_C.org" @@ -41,9 +41,9 @@ Despite these limitations, this convention provides many of the organizational b C lacks built-in support for templates or generics, unlike C++ or modern languages like Java or Rust. However, we can implement template-like functionality using the C preprocessor. This section explains the template system used throughout this document. -** The Xi (Ξ) Macro System +** The center dot '·' Macro System -The cpp macro `Ξ` is used for putting identifiers into a namespace. Consider these variables within a namespace. +The cpp macro `·` is used for putting identifiers into a namespace. Consider these variables within a namespace. #+BEGIN_SRC c TM·x // variable x in namespace TM @@ -52,8 +52,8 @@ TM·Array·i // variable i in namespace TM·Array ,#+BEGIN_SRC c -Ξ(TM ,x) // variable x in namespace TM -Ξ(TM·Array ,i) // variable i in namespace TM·Array +·(TM ,x) // variable x in namespace TM +·(TM·Array ,i) // variable i in namespace TM·Array #+END_SRC The reason the macro is needed is that cpp will not replace a macro that is embedded in an identifier. With this macro we can do the following: @@ -61,23 +61,23 @@ The reason the macro is needed is that cpp will not replace a macro that is embe #+BEGIN_SRC c #define CVT uint32_t CVT i; // -> uint32_t i - typedef struct Ξ(TM ,CVT) // -> typedef struct TM·uint32_t + typedef struct ·(TM ,CVT) // -> typedef struct TM·uint32_t #undef CVT #define CVT string typedef string char *; CVT ch; // -> string ch; - typedef struct Ξ(TM ,CVT) // -> typedef struct TM·string + typedef struct ·(TM ,CVT) // -> typedef struct TM·string #+END_SRC This allows us to create type and function names that are specialized for specific types, while maintaining a consistent naming convention. *** Implementation Details -The Ξ macro was initially defined for two operands, as shown below, though now it will take between zero and ten operands. With zero operands it expands to nothing, with one it echos the operand with no center dots, with more than that the operands are appended with a prior center dot. +The · macro was initially defined for two operands, as shown below, though now it will take between zero and ten operands. With zero operands it expands to nothing, with one it echos the operand with no center dots, with more than that the operands are appended with a prior center dot. #+BEGIN_SRC c -#define _Ξ2(a, b) a##·##b -#define Ξ2(a, b) _Ξ2(a, b) +#define _·2(a, b) a##·##b +#define ·2(a, b) _·2(a, b) #+END_SRC ** CVT: Cell Value Type @@ -132,8 +132,8 @@ For example, the tableau for an array-based tape machine might look like: struct { CVT *hd; // Current head position CVT *position; // Base position for the tape (leftmost cell) - Ξ(extent_t, CVT) extent; // Largest index that can be used for accessing the tape -} Ξ(TM·Array, CVT); + ·(extent_t, CVT) extent; // Largest index that can be used for accessing the tape +} ·(TM·Array, CVT); #+END_SRC Notice this struct is templated on `CVT`. Suppose it were in the file `tape.lib.c`, then: @@ -178,10 +178,10 @@ When specialized for a specific cell value type (CVT), we might then have: #+BEGIN_SRC c typedef struct { TM·FG *fg; // Base function table - Ξ(extent_t, CVT) (*extent)(TM *tm); + ·(extent_t, CVT) (*extent)(TM *tm); CVT (*read)(TM *tm); void (*write)(TM *tm, CVT *remote_pt); -} Ξ(TM, CVT)·FG; +} ·(TM, CVT)·FG; #+END_SRC ** The Relationship Between Tableaux and FG Tables @@ -199,9 +199,9 @@ This pattern allows us to achieve polymorphic behavior in C while maintaining ty The template system generates several types of identifiers: -1. **Type names**: `Ξ(TM, CVT)` becomes `TM·int` when CVT is defined as `int` -2. **Function names**: `Ξ(TM·Array, CVT)·init_pe` can become `TM·Array·int·init_pe` -3. **Variable names**: `Ξ(extent_t, CVT)` can become `extent_t·int` +1. **Type names**: `·(TM, CVT)` becomes `TM·int` when CVT is defined as `int` +2. **Function names**: `·(TM·Array, CVT)·init_pe` can become `TM·Array·int·init_pe` +3. **Variable names**: `·(extent_t, CVT)` can become `extent_t·int` ** Function Given (FG) Tables @@ -212,10 +212,10 @@ The FG tables are specialized based on the CVT: #+BEGIN_SRC c typedef struct { TM·FG *fg; // Base function table - Ξ(extent_t, CVT) (*extent)(TM *tm); + ·(extent_t, CVT) (*extent)(TM *tm); CVT (*read)(TM *tm); void (*write)(TM *tm, CVT *remote_pt); -} Ξ(TM, CVT)·FG; +} ·(TM, CVT)·FG; #+END_SRC This allows for type-safe operations while maintaining a consistent interface. @@ -224,7 +224,7 @@ This allows for type-safe operations while maintaining a consistent interface. 1. **Type safety**: The compiler checks that the correct types are used with each specialized function 2. **Code reuse**: Common functionality is defined once and specialized for different types -3. **Consistent naming**: The Ξ macro ensures a consistent naming convention +3. **Consistent naming**: The · macro ensures a consistent naming convention 4. **Modularity**: Different implementations can share the same interface ** Limitations @@ -441,7 +441,7 @@ An FG table with template variabes, will expand out to one or more FG tables (wi There can be multiple instances of an FG table. Each instance will consists of pointers to functions that have the type signature specified in the FG table. However, though all instances of the FG table share the same interface, their implementations can be completely different. -Each template variable binding, and each FG table instance can have a different Tableau type as the given argument. For the Tape Machine, we give each tableau struct the name Ξ(TM·, CVT), where is the FG instance table type. For example, Ξ(TM·Array, CVT) is a struct of state variables for an Array implementation of the TM. +Each template variable binding, and each FG table instance can have a different Tableau type as the given argument. For the Tape Machine, we give each tableau struct the name ·(TM·, CVT), where is the FG instance table type. For example, ·(TM·Array, CVT) is a struct of state variables for an Array implementation of the TM. ------------------------------------------------------------------- @@ -452,36 +452,36 @@ The TM model has functions that are independent of the CVT parameter. ** One for all FG table -The "TM.lib.c" file defines an FG type called Ξ(TM, CVT)·FG. Note that CVT is a template +The "TM.lib.c" file defines an FG type called ·(TM, CVT)·FG. Note that CVT is a template parameter. Hence, giving different CVT bindings, there will be different FG tables. -For each Ξ(TM, CVT)·FG, there can be a number of Ξ(TM·, CVT)·fg instances. For -example, Ξ(TM·Array, CVT)·fg. Each of these is a parameterized table. +For each ·(TM, CVT)·FG, there can be a number of ·(TM·, CVT)·fg instances. For +example, ·(TM·Array, CVT)·fg. Each of these is a parameterized table. A user has an fg table to call functions from. This is either passed in or, more likely, found at global scope after including "TM.lib.c", and then including it again for each value of the CVT variable to be used. -For each implementation type, there is a struct defined called Ξ(TM·, CVT), +For each implementation type, there is a struct defined called ·(TM·, CVT), note the lack of further suffix. Instances of this type are said to be instances of the tape -machine. `FG` stands for `function given`, and what each said function is given is one or more arguments of the Ξ(TM·, CVT) type. +machine. `FG` stands for `function given`, and what each said function is given is one or more arguments of the ·(TM·, CVT) type. -When a user wants a tape machine, the user makes an instance of a Ξ(TM·, CVT). -This is then handed to a function called Ξ(TM·, CVT)·init(). The init function is given whatever parameters are needed for initializing the instance, and it returns a more generalized pointer of type `Ξ(TM, CVT) *`. +When a user wants a tape machine, the user makes an instance of a ·(TM·, CVT). +This is then handed to a function called ·(TM·, CVT)·init(). The init function is given whatever parameters are needed for initializing the instance, and it returns a more generalized pointer of type `·(TM, CVT) *`. -After initialization, the Ξ(TM·, CVT) instance will have a first field value that points to the Ξ(TM·, CVT)·fg table. However, the pointer to this instance will be of the type returned by init, which is `Ξ(TM, CVT) *` (notice it lost the implementation). This more generic pointer can now be used with the generic instance of the -Ξ(TM, CVT)·FG table, Ξ(TM, CVT)·fg, which holds wrapper functions that make use of the +After initialization, the ·(TM·, CVT) instance will have a first field value that points to the ·(TM·, CVT)·fg table. However, the pointer to this instance will be of the type returned by init, which is `·(TM, CVT) *` (notice it lost the implementation). This more generic pointer can now be used with the generic instance of the +·(TM, CVT)·FG table, ·(TM, CVT)·fg, which holds wrapper functions that make use of the first field value to find the real fg table and to call those functions. Hence, after the user calls the correct init for the specific instance made, the resulting pointer points to the same type object independent of the implementation of the functions. Thus, code written to manipulate TMs can be written in a manner that is agnostic to the implementation of those TMs. -When a function is called, say Ξ(TM, CVT)·fg.step(tm), it is passed the generic type `Ξ(TM, CVT) *`, tm. This will call the step wrapper function, which will in turn pass the same arguments (in this case, only `tm`) to the step function found in the fg table pointed to by the first member of the tm struct. +When a function is called, say ·(TM, CVT)·fg.step(tm), it is passed the generic type `·(TM, CVT) *`, tm. This will call the step wrapper function, which will in turn pass the same arguments (in this case, only `tm`) to the step function found in the fg table pointed to by the first member of the tm struct. ** Separate FG tables -In the flat fg table approach described in the prior section, each wrapper function table of the form Ξ(TM, CVT)·fg, obtained by setting the CVT template to a type value, will have a full set of wrapper function pointers. When a wrapper function is the same independent of the CVT variable, it still has a pointer copied into each fg table. Thus, there will be a lot of redundancy in the tables if many functions are not CVT-specific. +In the flat fg table approach described in the prior section, each wrapper function table of the form ·(TM, CVT)·fg, obtained by setting the CVT template to a type value, will have a full set of wrapper function pointers. When a wrapper function is the same independent of the CVT variable, it still has a pointer copied into each fg table. Thus, there will be a lot of redundancy in the tables if many functions are not CVT-specific. -For the layered fg table, there are separate wrapper function tables for the wrappers that are independent of CVT and those that are CVT-differentiated. The user then calls functions from the CVT-independent table when invoking those functions and from the CVT-differentiated functions table when calling those. So, for example, the user would call TM·fg.step(tm) to do a step, as that is CVT-independent, but call Ξ(TM, CVT)·fg.read(tm) to do a read, as the read value is CVT-differentiated. +For the layered fg table, there are separate wrapper function tables for the wrappers that are independent of CVT and those that are CVT-differentiated. The user then calls functions from the CVT-independent table when invoking those functions and from the CVT-differentiated functions table when calling those. So, for example, the user would call TM·fg.step(tm) to do a step, as that is CVT-independent, but call ·(TM, CVT)·fg.read(tm) to do a read, as the read value is CVT-differentiated. ** Direct access through instance field (Orrin suggestion) @@ -491,7 +491,7 @@ Instead of calling fg functions through a globally visible table such as: fg->step(tm); // Wrapper style #+END_SRC -where fg is of type Ξ(TM, CVT)·FG and calls to it require globally accessible wrapper functions, +where fg is of type ·(TM, CVT)·FG and calls to it require globally accessible wrapper functions, we can use the instance's first field directly: @@ -499,7 +499,7 @@ we can use the instance's first field directly: tm->fg->step(tm); #+END_SRC -Here, tm is a Ξ(TM, CVT) * — the generic type returned by init — and fg is the first field of the instance pointing to the correct FG table. +Here, tm is a ·(TM, CVT) * — the generic type returned by init — and fg is the first field of the instance pointing to the correct FG table. This style removes the need for wrapper functions entirely. Each TM implementation embeds its corresponding FG table pointer directly in the instance. Thus, no global wrapper needs to be referenced, and function type-checking is preserved at compile time. diff --git "a/document\360\237\226\211/Abstracting_Type_in_C.pdf" "b/document\360\237\226\211/Abstracting_Type_in_C.pdf" deleted file mode 100644 index ce5ac69..0000000 Binary files "a/document\360\237\226\211/Abstracting_Type_in_C.pdf" and /dev/null differ diff --git "a/document\360\237\226\211/Abstracting_Type_in_C.tex" "b/document\360\237\226\211/Abstracting_Type_in_C.tex" deleted file mode 100644 index 9c540d0..0000000 --- "a/document\360\237\226\211/Abstracting_Type_in_C.tex" +++ /dev/null @@ -1,596 +0,0 @@ -% Created 2025-03-23 Sun 06:28 -% Intended LaTeX compiler: pdflatex -\documentclass[11pt]{article} -\usepackage[utf8]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{graphicx} -\usepackage{longtable} -\usepackage{wrapfig} -\usepackage{rotating} -\usepackage[normalem]{ulem} -\usepackage{amsmath} -\usepackage{amssymb} -\usepackage{capt-of} -\usepackage{hyperref} -\author{Thomas} -\date{\today} -\title{Abstracting Type in C} -\hypersetup{ - pdfauthor={Thomas}, - pdftitle={Abstracting Type in C}, - pdfkeywords={}, - pdfsubject={}, - pdfcreator={Emacs 29.4 (Org mode 9.6.15)}, - pdflang={English}} -\begin{document} - -\maketitle -\tableofcontents - - -\section{Introduction} -\label{sec:org8b18d97} - -Type abstraction is a fundamental challenge in C programming. Unlike object-oriented languages that provide built-in mechanisms for polymorphism, C requires explicit design patterns to achieve similar flexibility. This document explores various approaches to implementing type abstraction in C, using a tape machine (TM) as a concrete example. - -The core problem we're addressing is how to write generic code that can operate on different implementations of the same abstract interface. Specifically, we want to create functions that can work with any tape machine implementation without knowing the implementation details. This separation of interface from implementation facilitates creating modular, maintainable code in C. - -Throughout this document, we use the notation Ξ(TM, CVT) to represent a generic type where TM is the tape machine and CVT is a template parameter for the cell value type. This allows us to discuss both implementation-agnostic and type-specific behaviors. - -\section{Namespaces in C} -\label{sec:org8165afa} - -C does not have built-in namespace support like C++ or other modern languages. However, we can simulate namespaces using naming conventions. In this document, we use the middle dot character (·) as a namespace separator to organize identifiers into logical groups. - -\subsection{The Middle Dot Convention} -\label{sec:org598d1d1} - -The middle dot (·) in identifiers like `TM·Array` or `TM·Function·fg` is not a special operator in C. It is literally part of the identifier name. This convention creates a visual hierarchy that mimics namespaces while remaining valid C code. - -Examples: -```c -\emph{/ TM is the primary namespace -/} Array is a sub-namespace -// init\textsubscript{pe} is a function in that namespace -Ξ(TM·Array, CVT)·init\textsubscript{pe} - -\emph{/ Core is the primary namespace -/} Guard is a sub-namespace -// check is a function in that namespace -Core·Guard·fg.check(\&chk, 1, tm, TM·Msg·tm) -``` - -\subsection{Benefits of This Approach} -\label{sec:orgc15284c} - -\begin{enumerate} -\item \textbf{\textbf{Organization}}: Related functions and types are visually grouped together -\item \textbf{\textbf{Collision avoidance}}: Reduces the risk of name collisions in large codebases -\item \textbf{\textbf{Readability}}: Makes it clear which component a function or type belongs to -\item \textbf{\textbf{Consistency}}: Provides a uniform naming scheme across the codebase -\end{enumerate} - -\subsection{Implementation Details} -\label{sec:org4c7d92c} - -Since the middle dot is part of the identifier, the C compiler treats these names as atomic units. For example, `TM·Array` is a single identifier to the compiler, not two identifiers separated by an operator. - -The Ξ macro system we discussed earlier helps generate these namespace-like identifiers consistently: - -```c -// Generates TM·int -Ξ(TM, int) - -// Generates TM·Array·int·init\textsubscript{pe} -Ξ(TM·Array, int)·init\textsubscript{pe} -``` - -\subsection{Comparison with C++ Namespaces} -\label{sec:org420b759} - -Unlike C++ namespaces, our convention: -\begin{enumerate} -\item Does not provide actual scope isolation -\item Cannot be opened with `using` directives -\item Is purely a naming convention, not a language feature -\end{enumerate} - -Despite these limitations, this convention provides many of the organizational benefits of true namespaces while remaining compatible with standard C. - -\section{Tableau and FG Tables} -\label{sec:org8b1de5b} - -Two key concepts in our type abstraction approach are the "Tableau" and "Function Given (FG) Table." Understanding these concepts is essential for following the rest of this document. - -\subsection{Tableau} -\label{sec:orgdef1786} - -A "Tableau" is our term for a data structure that holds the state of a particular instance. In the context of our tape machine example: - -\begin{enumerate} -\item \textbf{\textbf{Definition}}: A tableau is a struct that contains all the state variables needed for a specific implementation of an abstract interface. - -\item \textbf{\textbf{Purpose}}: The tableau serves as a shared workspace where functions can read and write state information. Think of it as a blackboard where functions can leave "notes" for each other. - -\item \textbf{\textbf{Implementation-specific}}: Each implementation of an abstract interface will have its own tableau structure with different fields appropriate to that implementation. -\end{enumerate} - -For example, the tableau for an array-based tape machine might look like: - -```c -struct \{ - CVT *hd; \emph{/ Current head position - CVT *position; /} Base position (leftmost cell) - Ξ(extent\textsubscript{t}, CVT) extent; // Number of cells in the tape -\} Ξ(TM·Array, CVT); -``` - -While a function-based implementation might have a completely different tableau structure. - -\subsection{Function Given (FG) Tables} -\label{sec:orgdfb6392} - -The "Function Given" (FG) table is a collection of function pointers that implement operations on a specific tableau type. - -\begin{enumerate} -\item \textbf{\textbf{Definition}}: An FG table is a struct containing function pointers that all take a tableau as their first argument (hence "Function Given"). - -\item \textbf{\textbf{Purpose}}: FG tables allow for polymorphic behavior in C by providing different implementations of the same interface. - -\item \textbf{\textbf{Structure}}: Each function in the FG table takes a pointer to a tableau as its first argument, allowing it to access and modify the state. -\end{enumerate} - -A simplified example of an FG table for our tape machine might look like: - -```c -typedef struct \{ - TM·Tape·Topo (*Tape·topo)(TM *tm); - bool (*Tape·bounded)(TM *tm); - TM·Head·Status (*Head·status)(TM *tm); - Core·Status (*mount)(TM *tm); - void (*step)(TM *tm); - void (*rewind)(TM *tm); - // \ldots{} other functions -\} TM·FG; -``` - -When specialized for a specific cell value type (CVT), we might have: - -```c -typedef struct \{ - TM·FG *fg; // Base function table - Ξ(extent\textsubscript{t}, CVT) (*extent)(TM *tm); - CVT (*read)(TM *tm); - void (*write)(TM *tm, CVT *remote\textsubscript{pt}); -\} Ξ(TM, CVT)·FG; -``` - -\subsection{The Relationship Between Tableaux and FG Tables} -\label{sec:org6e5cc1f} - -The tableau and FG table work together to implement polymorphism: - -\begin{enumerate} -\item Each implementation provides its own tableau type and corresponding FG table. -\item The first field of a tableau is typically a pointer to its corresponding FG table. -\item Functions in the FG table operate on the tableau, reading and writing its state. -\item Client code can work with any implementation by using the functions in the FG table without knowing the details of the tableau structure. -\end{enumerate} - -This pattern allows us to achieve polymorphic behavior in C while maintaining type safety and avoiding the overhead of dynamic dispatch mechanisms like those used in object-oriented languages. - -\section{Implementing Templates in C} -\label{sec:orge82e21e} - -C lacks built-in support for templates or generics, unlike C++ or modern languages like Java or Rust. However, we can implement template-like functionality using the C preprocessor. This section explains the template system used throughout this document. - -\subsection{The Xi (Ξ) Macro System} -\label{sec:org1ff0935} - -We use a special macro system, represented by the Greek letter Xi (Ξ), to create template-like behavior in C. This system allows us to parameterize types and functions, similar to templates in C++. - -The Ξ macro concatenates identifiers with a middle dot (·) separator: - -```c -Ξ(TM, CVT) -> TM·CVT -Ξ(TM·Array, CVT)·init -> TM·Array·CVT·init -``` - -This allows us to create type and function names that are specialized for specific types, while maintaining a consistent naming convention. - -\subsubsection{Implementation Details} -\label{sec:org08d9fe2} - -The Ξ macro system is implemented using variadic macros and the C preprocessor's token concatenation operator (\#\#): - -```c -\#define \_Ξ2(a, b) a\#\#·\#\#b -\#define Ξ2(a, b) \_Ξ2(a, b) -``` - -The system includes macros for different numbers of arguments (Ξ0 through Ξ10) and uses argument counting to automatically select the appropriate macro: - -```c -\#define Ξ(\ldots{}) Ξ\textsubscript{EXPAND}(COUNT\textsubscript{ARGS}(\uline{\uline{VA\textsubscript{ARGS}}}), \uline{\uline{VA\textsubscript{ARGS}}}) -``` - -This allows for flexible usage with different numbers of template parameters. - -\subsection{CVT: Cell Value Type} -\label{sec:org8359158} - -Throughout our tape machine implementation, we use CVT (Cell Value Type) as a template parameter. This represents the type of data stored in each cell of the tape. - -The implementation uses conditional compilation to handle different CVT values: - -```c -\#ifndef CVT - // Code for generic, non-specialized case -\#endif - -\#ifdef CVT - // Code specialized for a specific CVT -\#endif -``` - -When using the library, you include it multiple times with different CVT definitions: - -```c -// First include with CVT undefined for base definitions -\#include "TM.lib.c" - -// Then include with CVT defined for each type specialization -\#define CVT int -\#include "TM.lib.c" -\#undef CVT - -\#define CVT float -\#include "TM.lib.c" -\#undef CVT -``` - -\subsection{Template-Based Type Generation} -\label{sec:orgcde6c14} - -The template system generates several types of identifiers: - -\begin{enumerate} -\item \textbf{\textbf{Type names}}: `Ξ(TM, CVT)` becomes `TM·int` when CVT is defined as `int` -\item \textbf{\textbf{Function names}}: `Ξ(TM·Array, CVT)·init\textsubscript{pe}` becomes `TM·Array·int·init\textsubscript{pe}` -\item \textbf{\textbf{Variable names}}: `Ξ(extent\textsubscript{t}, CVT)` becomes `extent\textsubscript{t}·int` -\end{enumerate} - -\subsection{Function Given (FG) Tables} -\label{sec:org691e6ba} - -A key part of our implementation is the Function Given (FG) table pattern. Each implementation of the tape machine provides an FG table containing function pointers for its operations. - -The FG tables are specialized based on the CVT: - -```c -typedef struct \{ - TM·FG *fg; // Base function table - Ξ(extent\textsubscript{t}, CVT) (*extent)(TM *tm); - CVT (*read)(TM *tm); - void (*write)(TM *tm, CVT *remote\textsubscript{pt}); -\} Ξ(TM, CVT)·FG; -``` - -This allows for type-safe operations while maintaining a consistent interface. - -\subsection{Benefits of This Approach} -\label{sec:org5338608} - -\begin{enumerate} -\item \textbf{\textbf{Type safety}}: The compiler checks that the correct types are used with each specialized function -\item \textbf{\textbf{Code reuse}}: Common functionality is defined once and specialized for different types -\item \textbf{\textbf{Consistent naming}}: The Ξ macro ensures a consistent naming convention -\item \textbf{\textbf{Modularity}}: Different implementations can share the same interface -\end{enumerate} - -\subsection{Limitations} -\label{sec:org70b9fc6} - -\begin{enumerate} -\item \textbf{\textbf{Verbosity}}: More verbose than native templates in C++ -\item \textbf{\textbf{Complexity}}: Requires understanding of preprocessor macros and conditional compilation -\item \textbf{\textbf{Debugging}}: Preprocessor-generated code can be harder to debug -\item \textbf{\textbf{Limited IDE support}}: Most IDEs don't understand this template system for code completion -\end{enumerate} - -Despite these limitations, this approach provides a powerful way to implement generic, type-safe code in C without resorting to void pointers or code duplication. - -\section{Generalizing type} -\label{sec:orgbc78d46} - -\subsection{Passing a TM FG table instance} -\label{sec:org326c1a7} - -\begin{enumerate} -\item Suppose we have a generic TM FG table with the declared functions constituting the architecture (user's view, interface) of a tape machine. - -\item Instances of this TM FG table represent different implementations of the architecture. For example, TM·Array·fg for a TM implemented as an array, and TM·Function·fg for a function implementation (similar to the Natural\textsubscript{Number} in the Java implementation). - -\item Now suppose we have a function `map` that is given a TM\textsubscript{read}, a TM\textsubscript{write}, and a function. -The map does not care how the TM is implemented. - -If these first two arguments are declared as TM FG type, then they can accept any fg table whether it be an Array implementation, a Function implementation, etc. The map can then pick the functions it needs, such as step and rightmost, from the -table, and thus get tape behavior. - -This achieves what we wanted: a map function that can use a tape machine and does not care what the implementation of that tape machine is. - -However, the TM functions that map calls require a first argument that holds the TM instance data. Without this, it cannot know which machine is being operated on. -Furthermore, the instance data type must match the TM fg table type. - -Given steps 1 through 3, we never passed in instance data to map, only a TM FG table instance. So map has a type, but not the data. -\end{enumerate} - - -\subsection{Passing TM instance data, compile in the fg table} -\label{sec:orged57256} - -\begin{enumerate} -\item As noted, `map` is given a TM\textsubscript{read}, a TM\textsubscript{write}, and a function. For these first two -arguments, suppose we pass in the instance data, i.e., struct pointers. - -\item The TM·Array struct will hold a base pointer to the array and the head location. The TM·Function struct would hold a handle recognized by the functions or some state used by them. - -\item Then we have a map function for each architecture type, and we compile into each of these a call to the correct default TM·fg table. The map·Array will have TM·Array·fg compiled into it, and the map·Function will have TM·Function·fg compiled into it, etc. - -\item This approach works, but we duplicate the map code many times just to get the types to match the calls. -\end{enumerate} - - -\subsection{Passing in both the TM instance data and corresponding TM FG tables instances} -\label{sec:orgf9f5316} - -\begin{enumerate} -\item Say we have one generic `map` that takes 5 arguments: TM\textsubscript{read} (an instance), TM\textsubscript{read}\textsubscript{fg}, a TM\textsubscript{write} (an instance), and TM\textsubscript{write}\textsubscript{fg}, plus the function to apply. - -\item The instance parameters must be declared `void *` to prevent argument checking on them; otherwise, it will be necessary to implement many map functions for each instance type combination. - -\item This works, though we have no way to know if the correct type of instance data that matches the fg table was actually passed in. - -\item We could create many wrapper functions to accomplish the instance data type check, then call a central map function with `void *` instance data pointers. With any luck, the optimizer would make this extra layer go away, so it will be efficient. Still, map now has 5 arguments instead of the three that are natural for the problem. -\end{enumerate} - - -\subsection{Using a "vtable"} -\label{sec:orga3c331a} - -\begin{enumerate} -\item All TM instance types are structs with a first field that points to the fg table, -regardless of the implementation type. This is not a serious requirement because -each implementation type already has a struct for its implementation data. However, it does make an instance bigger, and it is not clear that the optimizer will be able to -optimize it effectively. - -\item Then a generic fg table is created, where the functions have the signatures as specified -in the FG table. However, each of these functions follows the fg table pointer in the -instance data given to it as a first argument, and then calls that function. - -\item It works, and it is a tried and true method. -\end{enumerate} - -\subsection{Using a pointer pair} -\label{sec:orgc9d996e} - -\begin{enumerate} -\item Instead of the instance data being called the 'TM type', a pair is the 'TM type'. -The first member of the pair points to an instance, the second to a corresponding -fg table. - -\item Again there are some generic TM functions, each accepts a pair as a first argument, and then calls the corresponding fg table function while giving it the instance pointer -from the pair as the first argument. - -\item This approach packs the same information as the vtable approach. If there is a -one-to-one correspondence between instances and pairs, then it is larger by one pointer. - -\item This is a type of 'link' from our continuations, but the tableau pointer is gone due -to using a stack frame, and the continuation table pointer is gone due to flow-through sequencing. Thus it is two pointers instead of 4. - -\item Hopefully, the optimizer would recognize that the pair pointers are redundant. They are only needed to ensure that the instance and fg table go together. -\end{enumerate} - -\subsection{Instance curried dispatch function} -\label{sec:orga7d5cdc} - -\begin{enumerate} -\item In this case, a pointer to a function is the 'TM type'. There is an enum that gives numeric tags to each of the functions in the FG struct instance. - -\item The tag for the desired fg function to be called is passed as the first argument to the dispatch function, and the remaining arguments are for the fg function. - -\item The dispatch function has the instance data and fg table pointer curried into it, so it then calls the correct fg function while providing it with the correct instance data. - -\item In C, it is not immediately obvious how to create a function on the fly each time an -instance is created to curry the instance data into it, and then later how to call -the newly created function. -\end{enumerate} - -\subsection{Self-typed Instance and dispatch function} -\label{sec:orge6b7e0a} - -\begin{enumerate} -\item With this method, an extra field is added to the instance data that identifies its type. Then a globally available TM-specific dispatch function is called to run the desired fg function on the data. It is similar to the dispatch function from above, but the instance data is an additional argument. - -\item The dispatch function uses the type information to know which fg table to call. This type information could be a pointer to the appropriate fg table. - -\item This approach differs from the vtable method in that all the arguments are given to the one TM dispatch function, and it figures out how to do the dispatch. There is not a wrapper-per-function. -\end{enumerate} - -\subsection{Which approach?} -\label{sec:org6c9a58c} - -We want to be able to declare an instance as a local variable, where it will end up being on the stack frame. We want to avoid heap allocation for performance reasons, but not exclude the use of heap memory. - -Dynamically created functions are out of the question. Dispatch approaches require the enum table to have tags. This is not a show-stopper. However, having one dispatch function means the argument types are not checked. That is a problem. - -Doubled-up arguments (one for the instance, the other for the table) either require wrappers or do not check that an instance really goes with the data. Besides, it requires a lot of typing. - -The pointer pair approach requires the separate maintenance of the pair. When these are local variables, the pair has to be tied to the instance. This would require the user to be aware of the existence of both the instance data and the pair, to pass them to an initializer. This could be avoided if the pair were combined with the instance, but that -is identical to the vtable approach (the instance pointer no longer being needed). - -So we are led to the vtable approach, though we are still hoping for the curried dispatch function - lol. - -\section{Implementation Details} -\label{sec:org009bd61} - -\subsection{Main objects} -\label{sec:org4c8ad02} - -\begin{enumerate} -\item Ξ(TM, CVT)·FG table (CVT is a template for the tape cell value type). -\item Ξ(TM, CVT) instance, typically declared as a local variable. -\item FG Ξ(TM·Array, CVT)·fg, which is a Ξ(TM, CVT)·FG type, provides pointers to function -wrappers that are given a Ξ(TM, CVT) instance. Each wrapper then calls the function found in the -instance's vtable. -\end{enumerate} - -\subsection{Declaration} -\label{sec:org2d5c70b} - -\begin{enumerate} -\item With CVT not defined, \#include "TM.lib.c" in FACE section. -\item With each different CVT value defined, \#include "TM.lib.c" in FACE section again. -\item Do the same in the IMPLEMENTATION section. -\end{enumerate} - -\subsection{Instantiation} -\label{sec:orgf6668e0} - -\begin{enumerate} -\item Define a local variable, or get from malloc, a Ξ(TM, CVT) type, say `tm`. -\item Call init(tm). -\end{enumerate} - -\subsection{Use} -\label{sec:orgcb2825f} - -\begin{enumerate} -\item Call, for example, Ξ(TM·Array, CVT)·fg.step(tm), where tm is a Ξ(TM, CVT) type. -\end{enumerate} - -\subsection{FG table instances} -\label{sec:org4267ad9} - -There can be multiple instances of an FG table, each with functions that are implemented differently, though they share the same FG table type. - -Each CVT and FG table instance type will have a different tableau struct. Each tableau struct will have the type Ξ(TM·, CVT), where is the FG instance table type. For example, Ξ(TM·Array, CVT) is a struct of state variables for an Array implementation of the TM. - -\subsection{One for all FG table} -\label{sec:orga349d27} - -The "TM.lib.c" file defines an FG type called Ξ(TM, CVT)·FG. Note that CVT is a template -parameter. Hence, giving different CVT bindings, there will be different FG tables. - -For each Ξ(TM, CVT)·FG, there can be a number of Ξ(TM·, CVT)·fg instances. For -example, Ξ(TM·Array, CVT)·fg. Each of these is a parameterized table. - -A user has an fg table to call functions from. This is either passed in or, more -likely, found at global scope after including "TM.lib.c", and then including it again for -each value of the CVT variable to be used. - -For each implementation type, there is a struct defined called Ξ(TM·, CVT), -note the lack of further suffix. Instances of this type are said to be instances of the tape -machine. `FG` stands for `function given`, and what each said function is given is one or more arguments of the Ξ(TM·, CVT) type. - -When a user wants a tape machine, the user makes an instance of a Ξ(TM·, CVT). -This is then handed to a function called Ξ(TM·, CVT)·init(). The init function is given whatever parameters are needed for initializing the instance, and it returns a more generalized pointer of type `Ξ(TM, CVT) *`. - -After initialization, the Ξ(TM·, CVT) instance will have a first field value that points to the Ξ(TM·, CVT)·fg table. However, the pointer to this instance will be of the type returned by init, which is `Ξ(TM, CVT) *` (notice it lost the implementation). This more generic pointer can now be used with the generic instance of the -Ξ(TM, CVT)·FG table, Ξ(TM, CVT)·fg, which holds wrapper functions that make use of the -first field value to find the real fg table and to call those functions. - -Hence, after the user calls the correct init for the specific instance made, the resulting pointer points to the same type object independent of the implementation of the functions. Thus, code written to manipulate TMs can be written in a manner that is agnostic to the implementation of those TMs. - -When a function is called, say Ξ(TM, CVT)·fg.step(tm), it is passed the generic type `Ξ(TM, CVT) *`, tm. This will call the step wrapper function, which will in turn pass the same arguments (in this case, only `tm`) to the step function found in the fg table pointed to by the first member of the tm struct. - -\subsection{Separate FG tables} -\label{sec:orgafbf17c} - -In the flat fg table approach described in the prior section, each wrapper function table of the form Ξ(TM, CVT)·fg, obtained by setting the CVT template to a type value, will have a full set of wrapper function pointers. When a wrapper function is the same independent of the CVT variable, it still has a pointer copied into each fg table. Thus, there will be a lot of redundancy in the tables if many functions are not CVT-specific. - -For the layered fg table, there are separate wrapper function tables for the wrappers that are independent of CVT and those that are CVT-differentiated. The user then calls functions from the CVT-independent table when invoking those functions and from the CVT-differentiated functions table when calling those. So, for example, the user would call TM·fg.step(tm) to do a step, as that is CVT-independent, but call Ξ(TM, CVT)·fg.read(tm) to do a read, as the read value is CVT-differentiated. - -\subsection{Direct access through instance field (Orrin suggestion)} -\label{sec:orgfe58dd7} - -Instead of calling fg functions through a globally visible table such as: - -```c -fg->step(tm); // Wrapper style -``` - -where fg is of type Ξ(TM, CVT)·FG and calls to it require globally accessible wrapper functions, - -we can use the instance's first field directly: - -```c -tm->fg->step(tm); -``` - -Here, tm is a Ξ(TM, CVT) * — the generic type returned by init — and fg is the first field of the instance pointing to the correct FG table. - -This style removes the need for wrapper functions entirely. Each TM implementation embeds its corresponding FG table pointer directly in the instance. Thus, no global wrapper needs to be referenced, and function type-checking is preserved at compile time. - -If there are CVT-independent functions, we can use a layered FG table. Each CVT-specific FG table includes a pointer to a base table: - -```c -tm->fg->base->step(tm); \emph{/ Access shared, CVT-independent function -tm->fg->read(tm); /} Access CVT-specific function -``` - -This structure mimics prototype delegation in JavaScript, except we resolve the chain explicitly with types, not dynamic name resolution. - -The benefit of this approach is that the user only needs to have the instance in scope — no global FG table declarations. All function dispatch is local and type-safe. - -The only remaining user burden is knowing whether a function is CVT-specific or not. This is made obvious by whether the function appears in the base or CVT-differentiated FG struct, and the compiler will catch mismatches. - -(Contribution by Orrin — co-author) - -\section{Observations} -\label{sec:org46e6336} - -C does not have automatic conversion of a child type to its parent; instead, it will give a type mismatch error. - -The vtable pattern with separate tables will have a CVT-differentiated fg table pointer on the tableau. Without the function wrappers, a call can occur like this: - -```c -tm->fg->step(tm) -``` - -Or even with the wrappers and a globally available fg table: - -```c -fg->step(tm) -``` - -In both of these, `step` will be the CVT-differentiated version of step, so types will match, and these calls work. - -However, things change when we want to call the non-CVT-differentiated shared table: - -```c -tm->TM·fg->mount(tm) -``` - -Due to `mount` being in the shared fg table that has type `TM·fg` where it expects to be given arguments of type `TM *`, and having type `TM·`, there will be a type mismatch -error on the call. The programmer will be compelled to fix this with a cast: - -```c -tm->TM·fg->mount((TM *)tm) -``` - -Requiring the programmer to defeat the type system by habit is not a good approach. - -So the one solution that does work is the one big table per type. All functions will then have correct signatures in the FG declaration. In the implementation, the more generic functions can be cast when assigned directly to the fg table function pointers, or wrappers that delegate can be written and assigned to the fg table function pointers. - -\section{Conclusion} -\label{sec:org1380bd0} - -After examining various approaches to type abstraction in C, the vtable pattern emerges as the most practical solution for our tape machine implementation. While it has some overhead in terms of memory usage, it provides the best balance of type safety, ease of use, and performance. - -The direct access through instance field approach suggested by Orrin offers an elegant alternative that eliminates the need for wrapper functions while maintaining type safety. This approach is particularly appealing for its simplicity and the fact that it keeps all the necessary information localized to the instance. - -For projects where performance is critical, the "one big table per type" approach may be the most efficient, as it avoids the need for type casting while still providing a clean interface. - -Ultimately, the choice of approach depends on the specific requirements of the project, but the vtable pattern and its variations provide a solid foundation for type abstraction in C programming. -\end{document} diff --git "a/document\360\237\226\211/RT_C_namespace.org" "b/document\360\237\226\211/RT_C_namespace.org" index 39aa868..e4d353a 100644 --- "a/document\360\237\226\211/RT_C_namespace.org" +++ "b/document\360\237\226\211/RT_C_namespace.org" @@ -1,21 +1,174 @@ #+TITLE: RT C Namespace Convention -#+AUTHOR: Thomas +#+AUTHOR: Sorein +#+DATE: 2025-04-25 * 1. Namespaces in RT C -C does not provide a built-in mechanism for namespaces, so RT C adopts a *prefix plus scoping operator* convention. The part before the “·” (for example, “N32”) is treated as the namespace name, and the “·” symbol is a stand-in for an (as yet) unofficial scoping operator. +C has no formal namespace system, so RT C introduces a **middle-dot namespace convention** to provide **clarity, collision avoidance, and modular structure** in large, macro-heavy codebases. -For instance, in “N32·allocate_array=”: -- “N32” is the namespace prefix. -- “·” (the middle dot) is our ad hoc scoping operator. -- “=allocate_array=” is the actual function name. +The `·` symbol (U+00B7, **middle dot**) is used as a visual and semantic scoping operator between **namespace components**, similar to how `::` is used in C++ or `.` in Java. -** Advantages of the “Project·Name” Convention -1. **Collision Avoidance**: Prefixing everything with “N32·” (or another module name) ensures identifiers do not collide with those from other libraries or system headers. -2. **Clarity**: Readers can see at a glance which library an identifier belongs to. -3. **Easy to Evolve**: If a future version of C introduces formal namespaces, the “=N32=” prefix and “·” operator could map directly into that syntax. -4. **Organized Reusability**: In large codebases with multiple modules, each module has a unique prefix (“N8·”, “N16·”, “N32·”, etc.), making it straightforward to locate definitions and references in a text search. +This convention applies uniformly to: +- Function names +- Type names +- Structs +- Macros (especially templated forms) +- Dispatch tables -** Example Namespace Prefix -When building a 32-bit numeric library, all its public symbols are prefixed with `N32·`. Private/internal symbols (seen only within the file) may also use the prefix but are marked with `Local` or guarded by `#ifdef LOCAL` so they do not pollute the global symbol table. +Example: +#+BEGIN_SRC c +N32·allocate_array +Core·round_up +TM·AU·Array·init_pe +#+END_SRC +Here, each `·` separates conceptual scopes: +- `TM·AU·Array·init_pe` means: `init_pe` function, inside `Array` implementation, for the `AU` cell type, inside the `TM` module. + +* 1.5 The Middle Dot: Syntactic Sugar and Token Trickery + +The character `·` (U+00B7, **middle dot**) is **not** special in the C language. To the C preprocessor and compiler, it's simply a valid identifier character—just like `A_Z` or `foo42`. + +That means: + +#+BEGIN_SRC c +TM·AU·Array·init_pe +#+END_SRC + +is **just one long identifier**. The compiler doesn't see it as hierarchical—only as a single symbol. The visual segmentation is entirely for the *reader's* benefit, not the *compiler's*. + +> For now, the middle dot is syntactic sugar. But someday, perhaps, a future C or C++ might embrace it as a real scoping operator. We prepare the ground. + +However, when we want to *construct* identifiers programmatically via macros, `·` by itself is not enough. **The C preprocessor does not treat `·` as an operator**, so it won't concatenate tokens with it unless we explicitly instruct it. + +To solve this, RT C defines the following macro in `cpp_ext.c`: + +#+BEGIN_SRC c +#define ·(A,B) A##·##B +#+END_SRC + +This turns: + +#+BEGIN_SRC c +·(TM,AU) → TM·AU +#+END_SRC + +And can be chained: + +#+BEGIN_SRC c +·(·(TM,AU),Array) → TM·AU·Array +#+END_SRC + +For convenience and clarity, template variable values must be defined *before* expansion. For instance: + +#+BEGIN_SRC c +#define _Box_T_ int +#define _TM·CVT_ AU +#+END_SRC + +When these are defined in this manner, the macro `·(...)` allows us to produce the following expansions: + +| Macro Invocation | Resulting Identifier | +|--------------------------------+-------------------------------| +| `·(Box_Box,_Box_T_)` | `Box_Box·int` | +| `·(Box_set,_Box_T_)` | `Box_set·int` | +| `·(TM,_TM·CVT_)` | `TM·AU` | +| `·(TM,_TM·CVT_,Array)` | `TM·AU·Array` | +| `·(TM,_TM·CVT_,Array,init_pe)` | `TM·AU·Array·init_pe` | + +This macro-based approach makes template expansion **predictable, readable, and modular**—while preserving the middle dot as a **structural visual** and a **join point** for layered namespaces. + +In summary: + +- As a **literal**, `·` is a harmless identifier character. +- As a **macro call**, `·(...)` is a *token concatenator* that inserts middle dots between parts. +- This duality is key to templating and namespacing in RT C. + +* 2. Purpose of the Middle Dot + +**The `·` is not just cosmetic**—it encodes structured meaning: + +| Position | Meaning | +|----------+----------------------------------| +| Leftmost | Module namespace (e.g. `TM`) | +| Middle | Type or submodule scoping | +| Rightmost| Symbol or function identifier | + +This gives the illusion of *semantic depth* within a flat C symbol space. It also facilitates: +- Greppable identifiers +- Predictable naming for macros, typedefs, and tables +- Avoidance of conflicts in shared headers + +* 3. Template Variable Convention: `_Var_` + +Template variables are identified with **leading and trailing underscores**, e.g. `_TM·CVT_`. These are used to parameterize includes and define generic logic. + +When a template is instantiated: +- The value of `_Var_` is set (e.g. `_TM·CVT_ = AU`) +- The file is included +- A guard macro (e.g. `SET__TM·AU`) is defined + +This ensures one instantiation per type per translation unit. + +Example: +#+BEGIN_SRC c +#define _TM·CVT_ AU +#include "TM.lib.c" +#define SET__TM·AU + +#define _TM·CVT_ Str +#include "TM.lib.c" +#define SET__TM·Str +#+END_SRC + +* 4. Guard Macros: SET__Module__Type + +To prevent multiple expansions of the same template with the same argument, we define a sentinel macro after inclusion: + +#+BEGIN_SRC c +#if !defined(SET__TM·AU) +#define SET__TM·AU +... +#endif +#+END_SRC + +These guards allow repeated template includes in a single TU, and avoid the fragile workaround of modifying headers manually. + +* 5. Practical Naming Examples + +| Symbol | Meaning | +|----------------------------------+---------------------------------------------------| +| `Core·FG` | Function dictionary for the Core module | +| `TM·AU·FG` | Function dictionary for TM with AU cell type | +| `TM·Str·Array·init_pe` | Init function for TM with Str cell type, Array impl | +| `SET__Binding__TM·AU` | One-time expansion guard for Binding of TM·AU | +| `extent_t·AU` | Type alias for extent of AU array | +| `FG·Type` | Template variable name for FG expansion | + +* 6. Why Not Use Underscores or CamelCase? + +While underscores (`_`) are idiomatic in C, they don't offer visual scoping in the same way, especially when chained deeply. Middle dots provide: + +- **Visual segmentation** across layered modules +- **Improved grepability**: `grep TM·` finds all TM-related symbols +- **Avoidance of macro clashes**: underscores often clash with system headers, especially when using `__NAME__` forms +- **Harmony with macro join operations** like `·(...)` + +* 7. Future Compatibility + +If C ever adopts formal module systems or namespaces, the `·` syntax can be systematically translated into official syntax, e.g.: + +- `TM·AU·Array·init_pe` → `TM::AU::Array::init_pe` +- Greppable → parseable → mappable + +For now, `·` is an elegant compromise between form, function, and forward-compatibility. + +* 8. Summary + +RT C namespaces provide: +- Scoped, composable identifiers +- Greppable structure for large projects +- Seamless macro templating and type specialization +- Collision resistance without verbosity + +By adopting `Module·Type·Submodule·Function` naming, your C code remains modular, clean, and scalable. diff --git "a/document\360\237\226\211/temp.txt" "b/document\360\237\226\211/temp.txt" new file mode 100644 index 0000000..a734ec4 --- /dev/null +++ "b/document\360\237\226\211/temp.txt" @@ -0,0 +1,90 @@ +#+TITLE: Proposed TM Bulk Methods for Multi-Cell Copy +#+AUTHOR: Sorein +#+DATE: 2025-04-25 + +* 1. Motivation: Efficient Copy Needs Bulk Cell Access + +The standard `read` and `write` methods in TM operate on **one cell at a time**, which is: +- Clear +- Safe +- Sufficient for most loops + +However, when implementing **bit-for-bit stream copy** between TMs, we want to: +- **Copy multiple cells at once**, where possible +- Use the largest available unit per cell +- Avoid stepping repeatedly through the same control path + +To support this, TM needs **bulk methods** for cell span access. + +* 2. What Is a Span? + +A **span** is a run of **N contiguous cells** available from the current tape head. + +A TM can only offer a span if: +- The head is *on tape* +- At least `N` cells are accessible to the right +- The memory layout is contiguous + +Not all TM types (e.g. cyclic or zero-length) support spans. For others, it's an optimization. + +* 3. Proposed TM Methods + +Each method is defined per CVT type. For example, `TM·AU` would add: + +#+BEGIN_SRC c +bool TM·AU·can_span(TM·AU tm ,size_t count); +AU const* TM·AU·peek_span(TM·AU tm ,size_t count); +AU* TM·AU·claim_span(TM·AU tm ,size_t count); +void TM·AU·commit_span(TM·AU tm ,size_t count); +size_t TM·AU·remaining(TM·AU tm); +#+END_SRC + +* 4. Semantics + +| Method | Purpose | +|------------------+--------------------------------------------------------------| +| `can_span(n)` | Returns true if N contiguous cells can be read or written | +| `peek_span(n)` | Returns a read-only pointer to N contiguous cells, or NULL | +| `claim_span(n)` | Returns a writable pointer to N cells, or NULL | +| `commit_span(n)` | Advances the head right by N cells (must follow claim) | +| `remaining()` | Returns the number of cells remaining from head to end | + +* 5. Guarded Use Pattern + +A `Copy` implementation might use: + +#+BEGIN_SRC c +while( TM·AU·can_span(src ,n) && TM·AU·can_span(dst ,n) ){ + AU const* s = TM·AU·peek_span(src ,n); + AU* d = TM·AU·claim_span(dst ,n); + memcpy(d ,s ,n * sizeof(AU)); + TM·AU·commit_span(src ,n); + TM·AU·commit_span(dst ,n); +} +#+END_SRC + +This avoids looping through `read`/`write` per cell and reduces dispatch overhead. + +* 6. Optional Implementation and Capability Flag + +Not all TM types can support spans. We can: + +- Add a `supports_span` method to the FG table +- Or define a `TM·Capability` bitfield: + +#+BEGIN_SRC c +typedef enum{ + TM·Caps·none = 0, + TM·Caps·span = 1 << 0 +} TM·Caps; +#+END_SRC + +* 7. Summary + +Bulk cell access enhances TM's ability to support: +- Efficient copy +- Block-based streaming +- Memory-mapped operations +- Potential SIMD and vectorization later + +By introducing the five methods above, TM becomes *not* diff --git a/tool_shared/third_party/RT-project-share b/tool_shared/third_party/RT-project-share index 82f857e..d5af4fd 120000 --- a/tool_shared/third_party/RT-project-share +++ b/tool_shared/third_party/RT-project-share @@ -1 +1 @@ -/home/Thomas-masu/developer/RT-project-share/ \ No newline at end of file +/home/Thomas/subu_data/developer/RT-project-share/ \ No newline at end of file diff --git a/tool_shared/third_party/emacs_30.0.92 b/tool_shared/third_party/emacs_30.0.92 index 3840045..3168c76 120000 --- a/tool_shared/third_party/emacs_30.0.92 +++ b/tool_shared/third_party/emacs_30.0.92 @@ -1 +1 @@ -/home/Thomas-masu/developer/emacs_30.0.92 \ No newline at end of file +/home/Thomas/subu_data/developer/emacs_30.0.92/ \ No newline at end of file