From e6f0ac5a88130bd5f8b79a5261283c9a543622ce Mon Sep 17 00:00:00 2001 From: Thomas Walker Lynch Date: Sat, 29 Mar 2025 15:12:11 +0000 Subject: [PATCH] put cpp examples in example_cpp, debugged `FIND`, making example for type --- "developer/cc\360\237\226\211/Binding.lib.c" | 103 ++++++++++++++++++ "developer/cc\360\237\226\211/Core.lib.c" | 93 +++++----------- "developer/cc\360\237\226\211/FG.lib.c" | 88 --------------- "developer/cc\360\237\226\211/TM.lib.c" | 42 +++---- "developer/cc\360\237\226\211/cpp_ext_0.c" | 8 +- "developer/cc\360\237\226\211/cpp_ext_1.c" | 10 +- .../2025-03-29/N16.lib.c" | 0 .../2025-03-29/N32.lib.c" | 0 .../2025-03-29/N64.lib.c" | 0 .../2025-03-29/N8.lib.c" | 0 .../2025-03-29/TM_scratch.c" | 0 .../2025-03-29/environment.h" | 0 .../2025-03-29/test_setup.cli.c" | 0 .../2025-03-29/update.lib.c" | 0 .../cpp_evaluation.org" | 4 + developer/example/0_readme.org | 3 + developer/example/bespoke_type.cli.c | 74 +++++++++++++ developer/example/try_6_list.c | 48 -------- developer/example_cpp/.githolder | 0 developer/example_cpp/0_readme.org | 9 ++ .../{example => example_cpp}/cpp_ext_0.c | 0 .../{example => example_cpp}/cpp_ext_1.c | 0 .../{example => example_cpp}/example_A.c | 0 .../{example => example_cpp}/example_eval.c | 0 .../{example => example_cpp}/example_grow.c | 0 .../{example => example_cpp}/example_grow2.c | 0 .../example_recurse.c | 0 .../{example => example_cpp}/try_1_exists.c | 2 +- .../try_2_connectors.c | 2 +- developer/{example => example_cpp}/try_3_eq.c | 2 +- developer/{example => example_cpp}/try_4_if.c | 2 +- .../{example => example_cpp}/try_5_access.c | 2 +- developer/example_cpp/try_6_list.c | 60 ++++++++++ "developer/tool\360\237\226\211/make" | 4 - "developer/tool\360\237\226\211/makefile" | 8 +- 35 files changed, 321 insertions(+), 243 deletions(-) create mode 100644 "developer/cc\360\237\226\211/Binding.lib.c" delete mode 100644 "developer/cc\360\237\226\211/FG.lib.c" rename "developer/cc\360\237\226\211/N16.lib.c" => "developer/deprecated\360\237\226\211/2025-03-29/N16.lib.c" (100%) rename "developer/cc\360\237\226\211/N32.lib.c" => "developer/deprecated\360\237\226\211/2025-03-29/N32.lib.c" (100%) rename "developer/cc\360\237\226\211/N64.lib.c" => "developer/deprecated\360\237\226\211/2025-03-29/N64.lib.c" (100%) rename "developer/cc\360\237\226\211/N8.lib.c" => "developer/deprecated\360\237\226\211/2025-03-29/N8.lib.c" (100%) rename "developer/cc\360\237\226\211/TM_scratch.c" => "developer/deprecated\360\237\226\211/2025-03-29/TM_scratch.c" (100%) rename "developer/cc\360\237\226\211/environment.h" => "developer/deprecated\360\237\226\211/2025-03-29/environment.h" (100%) rename "developer/cc\360\237\226\211/test_setup.cli.c" => "developer/deprecated\360\237\226\211/2025-03-29/test_setup.cli.c" (100%) rename "developer/cc\360\237\226\211/update.lib.c" => "developer/deprecated\360\237\226\211/2025-03-29/update.lib.c" (100%) create mode 100644 developer/example/0_readme.org create mode 100644 developer/example/bespoke_type.cli.c delete mode 100644 developer/example/try_6_list.c create mode 100644 developer/example_cpp/.githolder create mode 100644 developer/example_cpp/0_readme.org rename developer/{example => example_cpp}/cpp_ext_0.c (100%) rename developer/{example => example_cpp}/cpp_ext_1.c (100%) rename developer/{example => example_cpp}/example_A.c (100%) rename developer/{example => example_cpp}/example_eval.c (100%) rename developer/{example => example_cpp}/example_grow.c (100%) rename developer/{example => example_cpp}/example_grow2.c (100%) rename developer/{example => example_cpp}/example_recurse.c (100%) rename developer/{example => example_cpp}/try_1_exists.c (98%) rename developer/{example => example_cpp}/try_2_connectors.c (99%) rename developer/{example => example_cpp}/try_3_eq.c (98%) rename developer/{example => example_cpp}/try_4_if.c (98%) rename developer/{example => example_cpp}/try_5_access.c (97%) create mode 100644 developer/example_cpp/try_6_list.c 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..67e7082 --- /dev/null +++ "b/developer/cc\360\237\226\211/Binding.lib.c" @@ -0,0 +1,103 @@ +/* +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 +#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" ) +#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) +#if 0 + + // 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; + + 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 +#endif + +//-------------------------------------------------------------------------------- +// Implementation +// Binding has no implementation + +#ifdef IMPLEMENTATION + + //---------------------------------------- + // implementation to go into the lib.a file + //---------------------------------------- + #ifndef LOCAL + #endif //#ifndef LOCAL + + //---------------------------------------- + // implementation to go at the bottom of the translation unit + //---------------------------------------- + #ifdef LOCAL + #endif // #ifdef LOCAL + +#endif // IMPLEMENTATION + +//-------------------------------------------------------------------------------- +// template variables work once + +#undef Binding·TYPE diff --git "a/developer/cc\360\237\226\211/Core.lib.c" "b/developer/cc\360\237\226\211/Core.lib.c" index 3e78126..031fd69 100644 --- "a/developer/cc\360\237\226\211/Core.lib.c" +++ "b/developer/cc\360\237\226\211/Core.lib.c" @@ -16,58 +16,49 @@ */ -#define Core·DEBUG -#ifdef FG·DEBUG - #include -#endif - -#ifndef FACE -#define Core·IMPLEMENTATION -#define FACE -#endif - //-------------------------------------------------------------------------------- -// Interface +// Interface #ifndef Core·FACE #define Core·FACE + #define Core·DEBUG + #ifdef FG·DEBUG + #include + #endif + #include + #include #include + #include "cpp_ext.c" //---------------------------------------- // memory interface //---------------------------------------- - // Define a namespace. - // #define _Ξ(a ,b) a##·##b - /// #define Ξ(a ,b) _Ξ(a ,b) - #include - // extent is the maximum index in an address space, tape or area, the doted // unit is the cell type. - typedef extent_t·AU size_t + typedef size_t extent_t·AU; #define extent_of·AU(x) (sizeof(x) - 1) - // Funny, we seldom check for this, perhaps that matters on some tiny machine. #define extent·AU_address_space ~(uintptr)0; // addressable unit for the machine // C language standard left this undefined. AToW industry uses uint8_t. - typedef AU uint8_t; - typedef AU2 uint16_t; - typedef AU4 uint32_t; - typedef AU8 uint64_t; + typedef uint8_t AU ; + typedef uint16_t AU2; + typedef uint32_t AU4; + typedef uint64_t AU8; - const AU AU_max = (~(AU)0); - const AU2 AU2_max = (~(AU2)0); - const AU4 AU4_max = (~(AU4)0); - const AU8 AU8_max = (~(AU8)0); + const AU AU_MAX = (~(AU)0); + const AU2 AU2_MAX = (~(AU2)0); + const AU4 AU4_MAX = (~(AU4)0); + const AU8 AU8_MAX = (~(AU8)0); // ask the compiler what this is // when using enums we get this whether we want it or not - typedef WU unsigned int; - const WU WU_max = (~(WU)0); + typedef unsigned int WU; + const WU WU_MAX = (~(WU)0); //---------------------------------------- // flag facility, argument guard facility @@ -129,38 +120,6 @@ else return Core·Status·on_track; #define Core·Guard·assert(chk) assert(!chk.flag); - //---------------------------------------- - // Macro to call a function in the FG table with debug checks - // Usage: FG·call(tm, function_name, arg1, arg2, ...) - // Expands to: ((tm)->fg->function_name)((tm)->t, arg1, arg2, ...) - // With debug checks for NULL pointers when FG·DEBUG is defined - //---------------------------------------- - - typedef struct FG·FG; - typedef struct FG·Tableau; - - typedef struct{ - FG·FG *fg; - FG·Tableau *tableau; - } FG·Binding; - - inline void FG·wellformed_binding(FG·Binding b) { - #ifdef FG·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 - } - - // note the use of the comma operator to return the result from b.fg->fn - #define FG·call(b, fn, ...) \ - ( \ - FG·wellformed_binding(b) \ - ,b.fg->fn(b.tableau, ##__VA_ARGS__ ) \ - ) - - //---------------------------------------- // functions interface //---------------------------------------- @@ -170,25 +129,25 @@ typedef struct{ Core·Status (*on_track)(); Core·Status (*derailed)(); - Core·Status (*is_aligned)(AU *p ,extent·AU alignment ,bool *flag); - Core·Status (*round_down)(AU *p ,extent·AU alignment ,AU **result); - Core·Status (*round_up)(AU *p ,extent·AU alignment ,AU **result); + Core·Status (*is_aligned)(AU *p ,extent_t·AU alignment ,bool *flag); + Core·Status (*round_down)(AU *p ,extent_t·AU alignment ,AU **result); + Core·Status (*round_up)(AU *p ,extent_t·AU alignment ,AU **result); } Core·F; Local Core·F Core·f; -#endif // FACE +#endif // #if CORE·FACE //-------------------------------------------------------------------------------- // Implementation -#ifdef Core·IMPLEMENTATION +#ifdef IMPLEMENTATION //-------------------------------------------------------------------------------- // implementation to go into the lib.a file // - #ifndef LOCAL - #endif + #ifndef LOCAL + #endif //-------------------------------------------------------------------------------- #ifdef LOCAL diff --git "a/developer/cc\360\237\226\211/FG.lib.c" "b/developer/cc\360\237\226\211/FG.lib.c" deleted file mode 100644 index 6d659fa..0000000 --- "a/developer/cc\360\237\226\211/FG.lib.c" +++ /dev/null @@ -1,88 +0,0 @@ -/* -Template parameters: - - FG·Type - Type used to name the binding struct. Binding struct instances get passed as arguments to functions etc. - -Template variables are _use once_ per #include. (They are #undef at the bottom of this file.) - -*/ - -#include "cpp_ext.c" - -#ifndef FACE -#define FG·IMPLEMENTATION -#define FACE -#endif - -//-------------------------------------------------------------------------------- -// Interface - -// once per translation unit -#ifndef FG·TYPE_LIST -#define FG·TYPE_LIST - - #define FG·DEBUG - #ifdef FG·DEBUG - #include - #endif - -#endif - -// once per FG·TYPE value -#if ! FIND_ITEM( FG·TYPE ,FG·TYPE_LIST ) -#define FG·TYPE_LIST APPEND(FG·TYPE_LIST ,FG·TYPE) - - // a simplifying naming convention - #define FG·Binding Ξ(FG·Type) - #define FG·FG Ξ(FG·Type ,FG) - #define FG·Tableau Ξ(FG·Type ,Tableau) - - // as a convention, we name the binding after the type - typedef struct{ - FG·FG *fg; - FG·Tableau *tableau; - } FG·Binding; - - // binds a tableau and FG tabel instance together - inline void FG·wellformed_binding(FG·Binding b){ - #ifdef FG·DEBUG - FG·Guard·init_count(chk); - FG·Guard·fg.check(&chk, 1, b.fg, "NULL fg table"); - FG·Guard·fg.check(&chk, 1, b.tableau, "NULL tableau"); - FG·Guard·assert(chk); - #endif - } - - /* - usage e.g.: FG·call(tm, function_name, arg1, arg2, ...) - Expands to: (tm.fg->function_name)((tm)->t, arg1, arg2, ...) - - note the use of the comma operator to return the result from the b.fg->fn call - */ - #define FG·call(b, fn, ...) \ - ( FG·wellformed_binding(b) ,b.fg->fn(b.tableau, ##__VA_ARGS__) ) - -#endif // FACE - -//-------------------------------------------------------------------------------- -// Implementation - -#ifdef FG·IMPLEMENTATION - - //---------------------------------------- - // implementation to go into the lib.a file - //---------------------------------------- - #ifndef LOCAL - #endif //#ifndef LOCAL - - //---------------------------------------- - // implementation to go at the bottom of the source file - //---------------------------------------- - #ifdef LOCAL - #endif // #ifdef LOCAL - -#endif // IMPLEMENTATION - -// template variables are use once -#undef FG·Type - diff --git "a/developer/cc\360\237\226\211/TM.lib.c" "b/developer/cc\360\237\226\211/TM.lib.c" index 3c49c35..75d54af 100644 --- "a/developer/cc\360\237\226\211/TM.lib.c" +++ "b/developer/cc\360\237\226\211/TM.lib.c" @@ -1,14 +1,11 @@ /* - TM - Tape Machine + TM - Tape Machine Model - `TM·CVT` Cell Value Type`. + Template parameters -*/ + `TM·CVT` Cell Value Type`. -#ifndef FACE -#define TM·IMPLEMENTATION -#define FACE -#endif +*/ //-------------------------------------------------------------------------------- // Interface @@ -22,7 +19,7 @@ #include "cpp_ext.c" #include "Core.lib.c" - #include "FG.lib.c" + #include "Binding.lib.c" #define TM·DEBUG #ifdef TM·DEBUG @@ -58,23 +55,19 @@ | TM·Head·Status·rightmost ; - // set type equality pattern - #define EQ__TM__oo__TM - #endif // once per TM·CVT value +#ifdef TM·CVT #if ! FIND_ITEM( TM·CVT ,TM·TYPE_LIST ) #define TM·TYPE_LIST APPEND(TM·TYPE_LIST ,TM·TYPE) - // TM··Tableau - typedef struct Ξ(TM ,Tableau); + // declare 'TM' as a type + #define EQ__TM__oo__TM + #define Binding·Type TM + #include "Binding.lib.c" - // bind the tableau to an FG table, call the binding a 'TM' type - #define FG·Type TM - #include "FG.lib.c" - - // extent is an index, hence its effect is a function of TM·CVT + // `extent_t` is an index, so element size matters, so TM·CVT matters typedef Ξ(extent_t ,TM·CVT) size_t; typedef struct{ @@ -95,7 +88,7 @@ void (*step_left) (TM tm); void (*rewind) (TM tm); - TM·FG TM·fg; // points to TM·FG instance + TM·Binding TM·fg; // points to TM·Binding instance Ξ(extent_t ,TM·CVT) (*extent)(TM tm); TM·CVT (*read) (TM tm); void (*write)(TM tm ,TM·CVT *remote_pt); @@ -121,11 +114,12 @@ ); #endif +#endif //-------------------------------------------------------------------------------- // Implementation -#ifdef TM·IMPLEMENTATION +#ifdef IMPLEMENTATION // implementation to go into the lib.a file // @@ -135,7 +129,7 @@ #ifdef LOCAL //---------------------------------------- - // Dispatch wrapper + // included first without defining TM·CVT //---------------------------------------- #ifndef TM·CVT @@ -208,7 +202,7 @@ //---------------------------------------- // Initialization for TM·fg - Local TM·FG TM·fg = { + Local TM·Binding TM·fg = { .Tape·topo = TM·Tape·topo ,.Tape·bounded = TM·Tape·bounded ,.Head·status = TM·Head·status @@ -262,7 +256,7 @@ return tm->fg.write(tm ,write_pt); } - Local Ξ(TM ,TM·CVT)·FG Ξ(TM ,TM·CVT)·fg = { + Local Ξ(TM ,TM·CVT)·Binding Ξ(TM ,TM·CVT)·fg = { .parent = TM·fg ,.extent = Ξ(TM ,TM·CVT)·extent ,.read = Ξ(TM ,TM·CVT)·read @@ -539,7 +533,7 @@ //---------------------------------------- // Initialization for Ξ(TM·Array ,TM·CVT)·fg - Local Ξ(TM·Array ,TM·CVT)·FG Ξ(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 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 573c27c..dd89cd9 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_0.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_0.c" @@ -65,9 +65,15 @@ DEBUG #include #define DEBUG_CPP + +// print the macro and the evaluation of the macro at compile time: +// #pragma message( STR_VAL() ) + #define STR(...) #__VA_ARGS__ +#define VAL(...) STR(__VA_ARGS__) +#define STR_VAL(...) #__VA_ARGS__ " -> " VAL(__VA_ARGS__) -// print the macro and the evaluation of the macro +// print the macro and the evaluation of the macro at run time: #define SHOW(expr) printf("%s -> %s\n", #expr, STR(expr)) /*=========================================================================== diff --git "a/developer/cc\360\237\226\211/cpp_ext_1.c" "b/developer/cc\360\237\226\211/cpp_ext_1.c" index bc241d7..a188507 100644 --- "a/developer/cc\360\237\226\211/cpp_ext_1.c" +++ "b/developer/cc\360\237\226\211/cpp_ext_1.c" @@ -62,8 +62,8 @@ DROPE_NOT_EXISTS_RIGHT ( NOT_EXISTS(__VA_ARGS__) ) \ () \ (IF \ - ( predicate(FIRST(__VA_ARGS__)) ) \ - ( FIRST( ,__VA_ARGS__) ) \ + ( predicate(FIRST(,__VA_ARGS__)) ) \ + ( FIRST(,__VA_ARGS__) ) \ ( DEFER3(_FIND_CONFEDERATE) ()(predicate ,REST(__VA_ARGS__)) ) \ ) #define _FIND_CONFEDERATE() _FIND @@ -76,9 +76,9 @@ DROPE_NOT_EXISTS_RIGHT ( NOT_EXISTS(__VA_ARGS__) ) \ () \ (IF \ - ( EQ(item ,FIRST(__VA_ARGS__)) ) \ - ( FIRST( ,__VA_ARGS__) ) \ - ( DEFER3(_FIND_ITEM_CONFEDERATE) ()(predicate ,REST(__VA_ARGS__)) ) \ + ( EQ(item ,FIRST(,__VA_ARGS__)) ) \ + ( item ) \ + ( DEFER3(_FIND_ITEM_CONFEDERATE) ()(item ,REST(__VA_ARGS__)) ) \ ) #define _FIND_ITEM_CONFEDERATE() _FIND_ITEM diff --git "a/developer/cc\360\237\226\211/N16.lib.c" "b/developer/deprecated\360\237\226\211/2025-03-29/N16.lib.c" similarity index 100% rename from "developer/cc\360\237\226\211/N16.lib.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/N16.lib.c" diff --git "a/developer/cc\360\237\226\211/N32.lib.c" "b/developer/deprecated\360\237\226\211/2025-03-29/N32.lib.c" similarity index 100% rename from "developer/cc\360\237\226\211/N32.lib.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/N32.lib.c" diff --git "a/developer/cc\360\237\226\211/N64.lib.c" "b/developer/deprecated\360\237\226\211/2025-03-29/N64.lib.c" similarity index 100% rename from "developer/cc\360\237\226\211/N64.lib.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/N64.lib.c" diff --git "a/developer/cc\360\237\226\211/N8.lib.c" "b/developer/deprecated\360\237\226\211/2025-03-29/N8.lib.c" similarity index 100% rename from "developer/cc\360\237\226\211/N8.lib.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/N8.lib.c" diff --git "a/developer/cc\360\237\226\211/TM_scratch.c" "b/developer/deprecated\360\237\226\211/2025-03-29/TM_scratch.c" similarity index 100% rename from "developer/cc\360\237\226\211/TM_scratch.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/TM_scratch.c" diff --git "a/developer/cc\360\237\226\211/environment.h" "b/developer/deprecated\360\237\226\211/2025-03-29/environment.h" similarity index 100% rename from "developer/cc\360\237\226\211/environment.h" rename to "developer/deprecated\360\237\226\211/2025-03-29/environment.h" diff --git "a/developer/cc\360\237\226\211/test_setup.cli.c" "b/developer/deprecated\360\237\226\211/2025-03-29/test_setup.cli.c" similarity index 100% rename from "developer/cc\360\237\226\211/test_setup.cli.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/test_setup.cli.c" diff --git "a/developer/cc\360\237\226\211/update.lib.c" "b/developer/deprecated\360\237\226\211/2025-03-29/update.lib.c" similarity index 100% rename from "developer/cc\360\237\226\211/update.lib.c" rename to "developer/deprecated\360\237\226\211/2025-03-29/update.lib.c" diff --git "a/developer/document\360\237\226\211/cpp_evaluation.org" "b/developer/document\360\237\226\211/cpp_evaluation.org" index ba92ca2..b320ac4 100644 --- "a/developer/document\360\237\226\211/cpp_evaluation.org" +++ "b/developer/document\360\237\226\211/cpp_evaluation.org" @@ -29,6 +29,10 @@ In a call, space is allowed between the macro name and the argument list. + Not in strings, not embedded in other tokens. If a macro definition has the same name as the call, then that is a redefinition, an redefinition is not allowed. + + cpp scans the tokens in the translation unit, upon finding a macro call it replaces it with the body from the macro definition using the following steps: + ** 1. Argument Substitution Phase When the macro is invoked: diff --git a/developer/example/0_readme.org b/developer/example/0_readme.org new file mode 100644 index 0000000..d8f8a7d --- /dev/null +++ b/developer/example/0_readme.org @@ -0,0 +1,3 @@ + +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 + diff --git a/developer/example/bespoke_type.cli.c b/developer/example/bespoke_type.cli.c new file mode 100644 index 0000000..b8de24b --- /dev/null +++ b/developer/example/bespoke_type.cli.c @@ -0,0 +1,74 @@ +/* + This will print at compile time as: + + example/custom_type.cli.c:6:9: note: ‘#pragma message: C -> 7’ + 6 | #pragma message( STR_VAL(C) ) + | ^~~~~~~ + + Note the C->7 on the right side of the first line. That printed + the name of the macro, and its value. This is a 'note' not an 'error'. +*/ + +#include "cpp_ext.c" +#include "Core.lib.c" +#include "Binding.lib.c" + +/* + This defines the Bespoke type. + + Here by 'type' we mean a Tableau to FG table binding. +*/ + + #define EQ__Bespoke__oo__Bespoke + #undef Binding·TYPE + #define Binding·TYPE Bespoke + #include "../cc🖉/Binding.lib.c" + +#if 0 + + // 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{ + void (*version)(Bespoke c); + void (*report)(Bespoke c ,*mess); + }Bespoke·FG; + + // This defines the Tableau, the data that is given as a first argument of each FG table entry. + typedef struct{ + void (*version)(Bespoke c); + void (*report)(Bespoke c ,*mess); + }Bespoke·Tableau; + + // This creates a FG table to Tableau binding type. We will use this to represent the type. + // The EQ pattern is required for `FIND_ITEM` to recognize the type: + + // these functions will be used for making an instance of the abstract Bespoke type + void Bespoke·version(Bespoke c){ printf("A Bespoke instance") }; + void Bespoke·report(Bespoke c ,*mess){ printf("A Bespoke instance says %s" ,mess)}; + +#endif + +int main(){ + printf("running example binding.cli.c on %s at %s\n", __DATE__, __TIME__); + + #define A 5 + SHOW(A); + + #define B Ξ(X,Y) + SHOW(B); + +#if 0 + Bespoke·FG = { + .version = Bespoke·version + ,.report = Bespoke·report + }; +#endif + + + return 0; +} + +#define IMPLEMENTATION +#define LOCAL + +//#include "../cc🖉/Core.lib.c" +//#include "../cc🖉/Binding.lib.c" diff --git a/developer/example/try_6_list.c b/developer/example/try_6_list.c deleted file mode 100644 index 2bcc339..0000000 --- a/developer/example/try_6_list.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "cpp_ext_0.c" -#include "cpp_ext_1.c" - -#define LIST int ,float ,char ,void - -// register equality -#define EQ__int__oo__int -#define EQ__float__oo__float -#define EQ__char__oo__char -#define EQ__void__oo__void - -// make predicates -#define IS_int(x) EQ(x ,int) -#define IS_float(x) EQ(x ,float) -#define IS_double(x) EQ(x ,double) -#define IS_char(x) EQ(x ,char) -#define IS_void(x) EQ(x ,void) - -int main(void){ - -#define BE(...) __VA_ARGS__ - - SHOW(IS_char(int)); - SHOW(IS_char(char)); - printf("\n"); - - SHOW( FIND(IS_char ,) ); - SHOW( FIND(IS_char ,char) ); // → char - SHOW( FIND(IS_char ,int) ); // → - printf("\n"); - - SHOW( FIND(IS_char ,int ,void) ); // → - SHOW( FIND(IS_void ,int ,void) ); // → - printf("\n"); - - SHOW( FIND(IS_int ,LIST) ); - SHOW( FIND(IS_float ,LIST) ); - SHOW( FIND(IS_double ,LIST) ); - SHOW( FIND(IS_char ,LIST) ); - SHOW( FIND(IS_void ,LIST) ); - SHOW( FIND(IS_big ,LIST) ); - printf("\n"); - - - //#endif - - return 0; -} diff --git a/developer/example_cpp/.githolder b/developer/example_cpp/.githolder new file mode 100644 index 0000000..e69de29 diff --git a/developer/example_cpp/0_readme.org b/developer/example_cpp/0_readme.org new file mode 100644 index 0000000..d10769b --- /dev/null +++ b/developer/example_cpp/0_readme.org @@ -0,0 +1,9 @@ +These are direct built one at a time, for example: + + #+BEGIN_SRC bash + > gcc try_6_list.c + > ./a.out + IS_char(int) -> 0 + IS_char(char) -> 1 + ... + EOF diff --git a/developer/example/cpp_ext_0.c b/developer/example_cpp/cpp_ext_0.c similarity index 100% rename from developer/example/cpp_ext_0.c rename to developer/example_cpp/cpp_ext_0.c diff --git a/developer/example/cpp_ext_1.c b/developer/example_cpp/cpp_ext_1.c similarity index 100% rename from developer/example/cpp_ext_1.c rename to developer/example_cpp/cpp_ext_1.c diff --git a/developer/example/example_A.c b/developer/example_cpp/example_A.c similarity index 100% rename from developer/example/example_A.c rename to developer/example_cpp/example_A.c diff --git a/developer/example/example_eval.c b/developer/example_cpp/example_eval.c similarity index 100% rename from developer/example/example_eval.c rename to developer/example_cpp/example_eval.c diff --git a/developer/example/example_grow.c b/developer/example_cpp/example_grow.c similarity index 100% rename from developer/example/example_grow.c rename to developer/example_cpp/example_grow.c diff --git a/developer/example/example_grow2.c b/developer/example_cpp/example_grow2.c similarity index 100% rename from developer/example/example_grow2.c rename to developer/example_cpp/example_grow2.c diff --git a/developer/example/example_recurse.c b/developer/example_cpp/example_recurse.c similarity index 100% rename from developer/example/example_recurse.c rename to developer/example_cpp/example_recurse.c diff --git a/developer/example/try_1_exists.c b/developer/example_cpp/try_1_exists.c similarity index 98% rename from developer/example/try_1_exists.c rename to developer/example_cpp/try_1_exists.c index 5b52fb3..c2ca07d 100644 --- a/developer/example/try_1_exists.c +++ b/developer/example_cpp/try_1_exists.c @@ -1,4 +1,4 @@ -#include "cpp_ext_0.c" +#include "../cc🖉/cpp_ext_0.c" #define F 1 #define O1 2 diff --git a/developer/example/try_2_connectors.c b/developer/example_cpp/try_2_connectors.c similarity index 99% rename from developer/example/try_2_connectors.c rename to developer/example_cpp/try_2_connectors.c index 1e99ee3..98078f1 100644 --- a/developer/example/try_2_connectors.c +++ b/developer/example_cpp/try_2_connectors.c @@ -1,4 +1,4 @@ -#include "cpp_ext_0.c" +#include "../cc🖉/cpp_ext_0.c" int main(void){ diff --git a/developer/example/try_3_eq.c b/developer/example_cpp/try_3_eq.c similarity index 98% rename from developer/example/try_3_eq.c rename to developer/example_cpp/try_3_eq.c index 6cb8aaf..c388f03 100644 --- a/developer/example/try_3_eq.c +++ b/developer/example_cpp/try_3_eq.c @@ -1,4 +1,4 @@ -#include "cpp_ext_0.c" +#include "../cc🖉/cpp_ext_0.c" int main(void){ diff --git a/developer/example/try_4_if.c b/developer/example_cpp/try_4_if.c similarity index 98% rename from developer/example/try_4_if.c rename to developer/example_cpp/try_4_if.c index cdb60e6..4d9d3ae 100644 --- a/developer/example/try_4_if.c +++ b/developer/example_cpp/try_4_if.c @@ -1,4 +1,4 @@ -#include "cpp_ext_0.c" +#include "../cc🖉/cpp_ext_0.c" int main(void){ diff --git a/developer/example/try_5_access.c b/developer/example_cpp/try_5_access.c similarity index 97% rename from developer/example/try_5_access.c rename to developer/example_cpp/try_5_access.c index e9db0ae..aee6c94 100644 --- a/developer/example/try_5_access.c +++ b/developer/example_cpp/try_5_access.c @@ -1,4 +1,4 @@ -#include "cpp_ext_0.c" +#include "../cc🖉/cpp_ext_0.c" int main(void){ diff --git a/developer/example_cpp/try_6_list.c b/developer/example_cpp/try_6_list.c new file mode 100644 index 0000000..a9ba619 --- /dev/null +++ b/developer/example_cpp/try_6_list.c @@ -0,0 +1,60 @@ +#include "../cc🖉/cpp_ext_0.c" +#include "../cc🖉/cpp_ext_1.c" + +#define LIST Integer ,Float ,Char ,Void + +// register equality +#define EQ__Integer__oo__Integer +#define EQ__Float__oo__Float +#define EQ__Char__oo__Char +#define EQ__Void__oo__Void + +// make predicates +#define IS_Integer(x) EQ(x ,Integer) +#define IS_Float(x) EQ(x ,Float) +#define IS_Missing(x) EQ(x ,Missing) +#define IS_Char(x) EQ(x ,Char) +#define IS_Void(x) EQ(x ,Void) + +int main(void){ + + SHOW(IS_Char(Integer)); + SHOW(IS_Char(Char)); + printf("\n"); + + SHOW( FIND(IS_Char ,) ); + SHOW( FIND(IS_Char ,Char) ); // → Char + SHOW( FIND(IS_Char ,Integer) ); // → + printf("\n"); + + SHOW( FIND(IS_Char ,Integer ,Void) ); // → + SHOW( FIND(IS_Void ,Integer ,Void) ); // → + printf("\n"); + + SHOW( FIND(IS_Integer ,LIST) ); + SHOW( FIND(IS_Float ,LIST) ); + SHOW( FIND(IS_Missing ,LIST) ); + SHOW( FIND(IS_Char ,LIST) ); + SHOW( FIND(IS_Void ,LIST) ); + SHOW( FIND(IS_big ,LIST) ); // literal 'IS_big' will be seen as true + printf("\n"); + + SHOW( FIND_ITEM(Char ,) ); + SHOW( FIND_ITEM(Char ,Char) ); // → Char + SHOW( FIND_ITEM(Char ,Integer) ); // → + printf("\n"); + + SHOW( FIND_ITEM(Char ,Integer ,Void) ); // → + SHOW( FIND_ITEM(Void ,Integer ,Void) ); // → + printf("\n"); + + SHOW( FIND_ITEM(Integer ,LIST) ); + SHOW( FIND_ITEM(Float ,LIST) ); + SHOW( FIND_ITEM(Missing ,LIST) ); + SHOW( FIND_ITEM(Char ,LIST) ); + SHOW( FIND_ITEM(Void ,LIST) ); + SHOW( FIND_ITEM(big ,LIST) ); + printf("\n"); + + return 0; +} diff --git "a/developer/tool\360\237\226\211/make" "b/developer/tool\360\237\226\211/make" index cfc2138..246d8df 100755 --- "a/developer/tool\360\237\226\211/make" +++ "b/developer/tool\360\237\226\211/make" @@ -13,10 +13,6 @@ set -e set -x cd "$REPO_HOME"/developer || exit 1 - - pushd python - ./fill_template - popd /bin/make -f tool🖉/makefile $@ set +x diff --git "a/developer/tool\360\237\226\211/makefile" "b/developer/tool\360\237\226\211/makefile" index 7b3660f..8dfa07c 100644 --- "a/developer/tool\360\237\226\211/makefile" +++ "b/developer/tool\360\237\226\211/makefile" @@ -3,7 +3,13 @@ RT-INCOMMON:=$(REPO_HOME)/tool_shared/third_party/RT-project-share/release include $(RT-INCOMMON)/make/environment_RT_0 -CFLAGS+=-Werror -Wno-macro-redefined -include "$(RT-INCOMMON)/make/RT_0.h" +# to compile only the example directory +# comment these out for a normal compile +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 -- 2.20.1