--- /dev/null
+/*
+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 <stdio.h>
+ #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
*/
-
//--------------------------------------------------------------------------------
-// Interface
+// Interface
+
// once per translation unit
#ifndef Binding·TYPE_LIST
#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 ...
#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
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");
#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
+#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
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
+ #include <assert.h>
#include "cpp_ext.c"
//----------------------------------------
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
#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
#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
===========================================================================*/
//----------------------------------------
// 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
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) );
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) );