From: Thomas Walker Lynch Date: Sat, 29 Mar 2025 15:35:41 +0000 (+0000) Subject: checkpoint before moving to empty as false X-Git-Url: https://git.reasoningtechnology.com/style/static/gitweb.js?a=commitdiff_plain;h=afd29e71abfa8d9b647114c3cc91c41d6787000a;p=N checkpoint before moving to empty as false --- diff --git "a/developer/cc\360\237\226\211/#Binding.lib.c#" "b/developer/cc\360\237\226\211/#Binding.lib.c#" new file mode 100644 index 0000000..0ca7be7 --- /dev/null +++ "b/developer/cc\360\237\226\211/#Binding.lib.c#" @@ -0,0 +1,86 @@ +/* +Template parameters: + + Binding·TYPE - Type used to name the binding struct. Binding struct instances get passed as arguments to functions etc. + +*/ + +//-------------------------------------------------------------------------------- +// Interface + +// once per translation unit +#ifndef Binding·TYPE_LIST +#define Binding·TYPE_LIST + + #define Binding·DEBUG + #ifdef Binding·DEBUG + #include + #endif + + #include "cpp_ext.c" + #include "Core.lib.c" + +#endif + +// once per Binding·TYPE value +#ifdef Binding·TYPE +#if NOT( FIND_ITEM(Binding·TYPE ,Binding·TYPE_LIST) ) +#pragma message( STR_VAL(Binding·TYPE) ) + + //this is what it takes to append to a list in cpp ... + #undef TEMP + #define TEMP Binding·TYPE_LIST ,Binding·TYPE + #undef Binding·TYPE_LIST + #define Binding·TYPE_LIST TEMP + + // a simplifying naming convention + #define Binding Ξ(Binding·TYPE) + #define Binding·FG Ξ(Binding·TYPE ,FG) + #define Binding·Tableau Ξ(Binding·TYPE ,Tableau) + + // binds a tableau and Binding table instance together + // as a convention, we name the binding after the Type + typedef struct Binding·FG Binding·FG; + typedef struct Binding·Tableau Binding·Tableau; + typedef struct{ + Binding·FG *fg; + Binding·Tableau *tableau; + } Binding; + + Local inline void Binding·wellformed_binding(Binding b){ + #ifdef Binding·DEBUG + Core·Guard·init_count(chk); + Core·Guard·fg.check(&chk, 1, b.fg, "NULL fg table"); + Core·Guard·fg.check(&chk, 1, b.tableau, "NULL tableau"); + Core·Guard·assert(chk); + #endif + } + + /* + 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 + */ + #define Binding·call(b, fn, ...) \ + ( Binding·wellformed_binding(b) ,b.fg->fn(b, ##__VA_ARGS__) ) + +#endif +#endif + +//-------------------------------------------------------------------------------- +// Implementation +// Binding has no implementation + +#ifdef LOCAL + +#endif + +#ifdef LIBRARY + +#endif + +//-------------------------------------------------------------------------------- +// template variables work once + +#undef Binding·TYPE diff --git "a/developer/cc\360\237\226\211/Binding.lib.c" "b/developer/cc\360\237\226\211/Binding.lib.c" index 67e7082..cdf6bb5 100644 --- "a/developer/cc\360\237\226\211/Binding.lib.c" +++ "b/developer/cc\360\237\226\211/Binding.lib.c" @@ -5,9 +5,9 @@ Template parameters: */ - //-------------------------------------------------------------------------------- -// Interface +// Interface + // once per translation unit #ifndef Binding·TYPE_LIST @@ -24,11 +24,8 @@ Template parameters: #endif // once per Binding·TYPE value -#pragma message( "before gate" ) -#pragma message( STR_VAL(Binding·TYPE) ) #ifdef Binding·TYPE -#if ! FIND_ITEM( Binding·TYPE ,Binding·TYPE_LIST ) -#pragma message( "after gate" ) +#if NOT( FIND_ITEM(Binding·TYPE ,Binding·TYPE_LIST) ) #pragma message( STR_VAL(Binding·TYPE) ) //this is what it takes to append to a list in cpp ... @@ -41,7 +38,6 @@ Template parameters: #define Binding Ξ(Binding·TYPE) #define Binding·FG Ξ(Binding·TYPE ,FG) #define Binding·Tableau Ξ(Binding·TYPE ,Tableau) -#if 0 // binds a tableau and Binding table instance together // as a convention, we name the binding after the Type @@ -52,7 +48,7 @@ Template parameters: Binding·Tableau *tableau; } Binding; - inline void Binding·wellformed_binding(Binding b){ + Local inline void Binding·wellformed_binding(Binding b){ #ifdef Binding·DEBUG Core·Guard·init_count(chk); Core·Guard·fg.check(&chk, 1, b.fg, "NULL fg table"); @@ -70,10 +66,6 @@ Template parameters: #define Binding·call(b, fn, ...) \ ( Binding·wellformed_binding(b) ,b.fg->fn(b, ##__VA_ARGS__) ) - - -#endif - #endif #endif @@ -81,21 +73,13 @@ Template parameters: // Implementation // Binding has no implementation -#ifdef IMPLEMENTATION +#ifdef LOCAL - //---------------------------------------- - // implementation to go into the lib.a file - //---------------------------------------- - #ifndef LOCAL - #endif //#ifndef LOCAL +#endif - //---------------------------------------- - // implementation to go at the bottom of the translation unit - //---------------------------------------- - #ifdef LOCAL - #endif // #ifdef LOCAL +#ifdef LIBRARY -#endif // IMPLEMENTATION +#endif //-------------------------------------------------------------------------------- // template variables work once diff --git "a/developer/cc\360\237\226\211/Core.lib.c" "b/developer/cc\360\237\226\211/Core.lib.c" index 031fd69..c3bed46 100644 --- "a/developer/cc\360\237\226\211/Core.lib.c" +++ "b/developer/cc\360\237\226\211/Core.lib.c" @@ -30,6 +30,7 @@ #include #include #include + #include #include "cpp_ext.c" //---------------------------------------- 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 dd89cd9..9b90e07 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_0.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_0.c" @@ -43,7 +43,7 @@ cpp_ext as separate project make the try into tests -make EXISTS true, leave an empty element as false +make EXISTS true, leave an empty element as false, NOT() would then be 'true' IS_LIST to distinguish element from list, though it will be tough to detect IS_LIST on a list with NOT_EXISTS elements, then a list with all @@ -83,11 +83,7 @@ Constants #define COMMA , #define SEMICOLON ; -#define FALSE 0 -#define TRUE 1 - -//--------- - +// 'twion' is a two component object that masquerades as a single object #define _TWION_0 ~,0 #define _TWION_1 ~,1 @@ -118,10 +114,6 @@ Primitive Concatenation #define _CAT4(a ,b ,c ,d) a ## b ## c ## d #define CAT4(a ,b ,c ,d) _CAT4(a ,b ,c ,d) -#define APPEND(list ,...) list ,__VA_ARGS__ - - - /*=========================================================================== Existence ===========================================================================*/ @@ -129,7 +121,7 @@ Existence //---------------------------------------- // primitive access - // note: _FIRST of nothing, _FIRST(), means passing an empty_item as the first item + // note: _FIRST(), means passing an empty_item as the first item // so it will return empty. #define _FIRST(a ,...) a #define _SECOND(a ,b ,...) b diff --git a/developer/example_cpp/try_6_list.c b/developer/example_cpp/try_6_list.c index a9ba619..75506ec 100644 --- a/developer/example_cpp/try_6_list.c +++ b/developer/example_cpp/try_6_list.c @@ -23,12 +23,12 @@ int main(void){ printf("\n"); SHOW( FIND(IS_Char ,) ); - SHOW( FIND(IS_Char ,Char) ); // → Char - SHOW( FIND(IS_Char ,Integer) ); // → + SHOW( FIND(IS_Char ,Char) ); + SHOW( FIND(IS_Char ,Integer) ); printf("\n"); - SHOW( FIND(IS_Char ,Integer ,Void) ); // → - SHOW( FIND(IS_Void ,Integer ,Void) ); // → + SHOW( FIND(IS_Char ,Integer ,Void) ); + SHOW( FIND(IS_Void ,Integer ,Void) ); printf("\n"); SHOW( FIND(IS_Integer ,LIST) ); @@ -40,12 +40,12 @@ int main(void){ printf("\n"); SHOW( FIND_ITEM(Char ,) ); - SHOW( FIND_ITEM(Char ,Char) ); // → Char - SHOW( FIND_ITEM(Char ,Integer) ); // → + SHOW( FIND_ITEM(Char ,Char) ); + SHOW( FIND_ITEM(Char ,Integer) ); printf("\n"); - SHOW( FIND_ITEM(Char ,Integer ,Void) ); // → - SHOW( FIND_ITEM(Void ,Integer ,Void) ); // → + SHOW( FIND_ITEM(Char ,Integer ,Void) ); + SHOW( FIND_ITEM(Void ,Integer ,Void) ); printf("\n"); SHOW( FIND_ITEM(Integer ,LIST) );