-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several changes, preparing for n-ary implementation of the bind macro.
This commit introduces the PPMPF_BDS* constructs that are to be used in the final version of "binding". The two macros already available in testing mode, PPMPF_TUP_BIND and PPMPF_UTUP_BIND are the proof of concept but do not respect n-arity. This commit paves the way for their final implementation and deployment of said feature within high order function semantics at the preprocessor level, and is related to issues #18 and #20. Also introduced: *) PPMPF_NNX macro in core files (next of [0-9] single digits). *) Ability for function macro binding to deal with "constants", provided these are passed enclosed in a _(...) marker during the "binding" signature. *) Some initial workup on the way documentation is to be handled in odreex, starting with macros, in the new bind.hh ppmpf file.
- Loading branch information
1 parent
8c314dd
commit dc0cb88
Showing
5 changed files
with
375 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (C) 2014, George Makrydakis <[email protected]> | ||
* | ||
* This file is part of odreex. | ||
* | ||
* odreex is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* odreex. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
#ifndef _ODREEX_PPMPF_FUNCTIONAL_BIND_HH_ | ||
#define _ODREEX_PPMPF_FUNCTIONAL_BIND_HH_ | ||
|
||
#include <odreex/ppmpf/functional/bind/base.hh> | ||
#include <odreex/ppmpf/functional/bind/internals.hh> | ||
|
||
/*~ | ||
* @desc A prototype for a new kind of function binder; this should be the | ||
* conceptual base upon which the new implementation of PPMPF_TUP_BIND | ||
* and PPMPF_SEQ_BIND should be based on. | ||
* @pfrg f: A preprocessor function macro identifier, for an n-ary function | ||
* macro to be used during binding. | ||
* @pfrg x: A two item ppmpf sequence containing on its first item either of | ||
* _0, __0 placeholders for specifying parenthetical enclosure of the | ||
* application of f to its arguments or not, respectively. The second | ||
* item is a comma separated sequence of identifiers within ranges of | ||
* [_1,_9], [__1,__9] and any amount of _(...) containers representing | ||
* "constants" to be applied at the given ordinal position. | ||
* | ||
* Depending on whether single or double underscore placeholders have | ||
* been chosen, removal of parenthetical enclosure is performed or | ||
* not, respectively. | ||
* @pfrg y: A safe ppmpf tuple of arguments that are to be passed to the macro | ||
* resulting from the "binding" operation. | ||
* @pexp The result of the function application according to the binding | ||
* signature semantics. | ||
*/ | ||
#define PPMPF_BDS22(f,x,y) \ | ||
PPMPF_CAT( PPMPF_BDX \ | ||
, PPMPF_DPAR(PPMPF_SEQ_GET(x)))()( \ | ||
PPMPF_BDS21( f \ | ||
, PPMPF_BDS20(PPMPF_SEQ_POP(x)),y)) | ||
|
||
/*~ | ||
* @desc This is the more useful version of PPMPF_BDS22 for deployment during | ||
* high order function emulation through recursive expansion constructs. | ||
* @pfrg f: A preprocessor function macro identifier, for an n-ary function | ||
* macro to be used during binding. | ||
* @pfrg r: A preprocessor function macro identifier which is either PPMPF_JUST | ||
* or PPMPF_ENCLOSE. | ||
* @pfrg x: A safe ppmpf tuple of the internal accessors after these have been | ||
* derived from an initial comma separated sequence of placeholders | ||
* in ranges [_1,_9] and [__1,__9] and any amount of _(...) "constants" | ||
* used. | ||
* @pfrg y: A safe ppmpf tuple of the arguments that should be passed to the | ||
* "bound" function macro. | ||
* @pexp The result of the function application according to the binding | ||
* signature semantics. | ||
*/ | ||
#define PPMPF_BDS23(f,r,x,y,z) \ | ||
r(PPMPF_APPLY(f,PPMPF_BDS11(x,y,z))) | ||
|
||
/*~ | ||
* @desc Parsing the "signature" part of the "binding" ppmpf macro instruction. | ||
* This is going to be used to introduce binding in the high order | ||
* function emulations. | ||
* | ||
* @pfrig x: A two item sequence where first item is either _0 or __0 of | ||
* the ppmpf placeholders, second is a comma separated sequence of | ||
* any of the remaining placeholders and / or _(...) "constants". | ||
* @pexp A sequence of comma separated tokens where the first is either of | ||
* two preprocessor function macro identifiers (PPMPF_ENCLOSE,PPMPF_JUST), | ||
* the second a safe ppmpf tuple of the metafunction macro identifiers | ||
* replacing the placeholders used and the final third a raw tuple of | ||
* the constants used in _(...) during the binding operation. | ||
*/ | ||
#define PPMPF_BDS24(x) \ | ||
PPMPF_CAT( PPMPF_BDX \ | ||
, PPMPF_DREF(PPMPF_SEQ_GET(x)))() \ | ||
, PPMPF_BDS20(PPMPF_SEQ_POP(x)) | ||
|
||
#endif /* _ODREEX_PPMPF_FUNCTIONAL_BIND_HH_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* -- | ||
* Copyright (C) 2014, George Makrydakis <[email protected]> | ||
* | ||
* This file is part of odreex. | ||
* | ||
* odreex is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* odreex. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
#ifndef _ODREEX_PPMPF_FUNCTIONAL_BIND_BASE_HH_ | ||
#define _ODREEX_PPMPF_FUNCTIONAL_BIND_BASE_HH_ | ||
|
||
#include <odreex/ppmpf/collections/tuple.hh> | ||
#include <odreex/ppmpf/collections/sequence.hh> | ||
|
||
#define PPMPF_BDA_(x) 1 | ||
#define PPMPF_BDB_(x) 0 | ||
|
||
#define PPMPF_BDA__1 0 | ||
#define PPMPF_BDA__2 0 | ||
#define PPMPF_BDA__3 0 | ||
#define PPMPF_BDA__4 0 | ||
#define PPMPF_BDA__5 0 | ||
#define PPMPF_BDA__6 0 | ||
#define PPMPF_BDA__7 0 | ||
#define PPMPF_BDA__8 0 | ||
#define PPMPF_BDA__9 0 | ||
|
||
#define PPMPF_BDA_1 0 | ||
#define PPMPF_BDA_2 0 | ||
#define PPMPF_BDA_3 0 | ||
#define PPMPF_BDA_4 0 | ||
#define PPMPF_BDA_5 0 | ||
#define PPMPF_BDA_6 0 | ||
#define PPMPF_BDA_7 0 | ||
#define PPMPF_BDA_8 0 | ||
#define PPMPF_BDA_9 0 | ||
|
||
#define PPMPF_BDB__1 1 | ||
#define PPMPF_BDB__2 1 | ||
#define PPMPF_BDB__3 1 | ||
#define PPMPF_BDB__4 1 | ||
#define PPMPF_BDB__5 1 | ||
#define PPMPF_BDB__6 1 | ||
#define PPMPF_BDB__7 1 | ||
#define PPMPF_BDB__8 1 | ||
#define PPMPF_BDB__9 1 | ||
|
||
#define PPMPF_BDB_1 1 | ||
#define PPMPF_BDB_2 1 | ||
#define PPMPF_BDB_3 1 | ||
#define PPMPF_BDB_4 1 | ||
#define PPMPF_BDB_5 1 | ||
#define PPMPF_BDB_6 1 | ||
#define PPMPF_BDB_7 1 | ||
#define PPMPF_BDB_8 1 | ||
#define PPMPF_BDB_9 1 | ||
|
||
#define PPMPF_BDC0(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(0),a)) | ||
#define PPMPF_BDC1(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(1),a)) | ||
#define PPMPF_BDC2(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(2),a)) | ||
#define PPMPF_BDC3(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(3),a)) | ||
#define PPMPF_BDC4(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(4),a)) | ||
#define PPMPF_BDC5(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(5),a)) | ||
#define PPMPF_BDC6(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(6),a)) | ||
#define PPMPF_BDC7(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(7),a)) | ||
#define PPMPF_BDC8(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(8),a)) | ||
#define PPMPF_BDC9(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(9),a)) | ||
|
||
#define PPMPF_BDR1(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(0),b))) | ||
#define PPMPF_BDR2(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(1),b))) | ||
#define PPMPF_BDR3(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(2),b))) | ||
#define PPMPF_BDR4(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(3),b))) | ||
#define PPMPF_BDR5(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(4),b))) | ||
#define PPMPF_BDR6(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(5),b))) | ||
#define PPMPF_BDR7(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(6),b))) | ||
#define PPMPF_BDR8(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(7),b))) | ||
#define PPMPF_BDR9(a,b) PPMPF_DPAR(PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(8),b))) | ||
|
||
#define PPMPF_BDJ1(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(0),b)) | ||
#define PPMPF_BDJ2(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(1),b)) | ||
#define PPMPF_BDJ3(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(2),b)) | ||
#define PPMPF_BDJ4(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(3),b)) | ||
#define PPMPF_BDJ5(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(4),b)) | ||
#define PPMPF_BDJ6(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(5),b)) | ||
#define PPMPF_BDJ7(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(6),b)) | ||
#define PPMPF_BDJ8(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(7),b)) | ||
#define PPMPF_BDJ9(a,b) PPMPF_DPAR(PPMPF_TUP_ATPOS((0)(0)(0)(8),b)) | ||
|
||
#define PPMPF_BDX0() (PPMPF_BDC0) | ||
#define PPMPF_BDX1() (PPMPF_BDC1) | ||
#define PPMPF_BDX2() (PPMPF_BDC2) | ||
#define PPMPF_BDX3() (PPMPF_BDC3) | ||
#define PPMPF_BDX4() (PPMPF_BDC4) | ||
#define PPMPF_BDX5() (PPMPF_BDC5) | ||
#define PPMPF_BDX6() (PPMPF_BDC6) | ||
#define PPMPF_BDX7() (PPMPF_BDC7) | ||
#define PPMPF_BDX8() (PPMPF_BDC8) | ||
#define PPMPF_BDX9() (PPMPF_BDC9) | ||
|
||
#define PPMPF_BDX_0() PPMPF_ENCLOSE | ||
#define PPMPF_BDX_1() (PPMPF_BDJ1) | ||
#define PPMPF_BDX_2() (PPMPF_BDJ2) | ||
#define PPMPF_BDX_3() (PPMPF_BDJ3) | ||
#define PPMPF_BDX_4() (PPMPF_BDJ4) | ||
#define PPMPF_BDX_5() (PPMPF_BDJ5) | ||
#define PPMPF_BDX_6() (PPMPF_BDJ6) | ||
#define PPMPF_BDX_7() (PPMPF_BDJ7) | ||
#define PPMPF_BDX_8() (PPMPF_BDJ8) | ||
#define PPMPF_BDX_9() (PPMPF_BDJ9) | ||
|
||
#define PPMPF_BDX__0() PPMPF_JUST | ||
#define PPMPF_BDX__1() (PPMPF_BDR1) | ||
#define PPMPF_BDX__2() (PPMPF_BDR2) | ||
#define PPMPF_BDX__3() (PPMPF_BDR3) | ||
#define PPMPF_BDX__4() (PPMPF_BDR4) | ||
#define PPMPF_BDX__5() (PPMPF_BDR5) | ||
#define PPMPF_BDX__6() (PPMPF_BDR6) | ||
#define PPMPF_BDX__7() (PPMPF_BDR7) | ||
#define PPMPF_BDX__8() (PPMPF_BDR8) | ||
#define PPMPF_BDX__9() (PPMPF_BDR9) | ||
|
||
#endif /* _ODREEX_PPMPF_FUNCTIONAL_BIND_BASE_HH_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* -- | ||
* Copyright (C) 2014, George Makrydakis <[email protected]> | ||
* | ||
* This file is part of odreex. | ||
* | ||
* odreex is free software: you can redistribute it and/or modify it under the | ||
* terms of the GNU General Public License as published by the Free Software | ||
* Foundation, either version 3 of the License, or (at your option) any later | ||
* version. | ||
* | ||
* odreex is distributed in the hope that it will be useful, but WITHOUT ANY | ||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* odreex. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
#ifndef _ODREEX_PPMPF_FUNCTIONAL_BIND_INTERNALS_HH_ | ||
#define _ODREEX_PPMPF_FUNCTIONAL_BIND_INTERNALS_HH_ | ||
|
||
#include <odreex/ppmpf/collections/tuple.hh> | ||
#include <odreex/ppmpf/collections/sequence.hh> | ||
|
||
/*~ | ||
* @info These are all internal for the implementation of the function macro | ||
* binding feature. They could eventually be changed according to the | ||
* needs of the function macro implementation they are assisting in their | ||
* whole. | ||
* @inrl PPMPF_BDS22, PPMPF_BDS23 | ||
*/ | ||
|
||
#define PPMPF_BDP1_(x) x | ||
#define PPMPF_BDP(x) PPMPF_CAT(PPMPF_BDP1,x) | ||
#define PPMPF_BDS0(x) PPMPF_CAT(PPMPF_BDX,x)() | ||
#define PPMPF_BDS1(x) PPMPF_CAT(PPMPF_BDA,x) | ||
#define PPMPF_BDS2(x) PPMPF_CAT(PPMPF_BDB,x) | ||
|
||
#define PPMPF_BDS4(c,g,x,y,n) \ | ||
PPMPF_IFELSE( c(PPMPF_DREF(g(y))) \ | ||
, PPMPF_BDS8 \ | ||
, PPMPF_BDS9)(g,x,y,n) | ||
|
||
#define PPMPF_BDS5(c,g,x,y,n) \ | ||
PPMPF_IFELSE( c(PPMPF_DREF(g(y))) \ | ||
, PPMPF_BDS6 \ | ||
, PPMPF_BDS7)(g,x,y,n) | ||
|
||
#define PPMPF_BDS7(g,x,y,n) (x)(n) | ||
|
||
#define PPMPF_BDS6(g,x,y,n) \ | ||
( ( PPMPF_DREF(x) \ | ||
, PPMPF_BDP(PPMPF_DREF(g(y))))) \ | ||
((PPMPF_NNX(PPMPF_DREF(n)))) | ||
|
||
#define PPMPF_BDS8(g,x,y,n) \ | ||
( (PPMPF_DREF(x) \ | ||
, PPMPF_DREF(g(y))) ) | ||
|
||
#define PPMPF_BDS9(f,x,y,n) \ | ||
(( PPMPF_DREF(x) \ | ||
, PPMPF_DREF(n) )) | ||
|
||
#define PPMPF_BDS10(f,sl,g,c,v,...) \ | ||
(PPMPF_DREF(PPMPF_DREF(g(PPMPF_DREF(PPMPF_SEQ_POP(sl)))))(c,v)) | ||
|
||
#define PPMPF_BDS11(a,b,c) \ | ||
PPMPF_TUP_POP( \ | ||
PPMPF_FLDX0G( \ | ||
, ()(a) \ | ||
, PPMPF_UTUP_GET \ | ||
, PPMPF_TUP_POP \ | ||
, PPMPF_UTUP_EMPTY \ | ||
, PPMPF_BDS10 \ | ||
, PPMPF_FLDX0D \ | ||
, PPMPF_FLDX22, b, c, ) ) | ||
|
||
#define PPMPF_BDS14A(x) \ | ||
PPMPF_UTUP_MAP( PPMPF_BDS0 \ | ||
, PPMPF_TUP_POP(PPMPF_DREF(PPMPF_SEQ_AT09(0,x)))) | ||
|
||
#define PPMPF_BDS14B(x) \ | ||
PPMPF_TUP_POP(PPMPF_DREF(PPMPF_SEQ_AT09(2,x))) | ||
|
||
#define PPMPF_BDS15(f,slbc,g,p,h,i,w,x,...) \ | ||
PPMPF_BDS16( f,g,p,h,i,w,x \ | ||
, PPMPF_DREF(PPMPF_SEQ_AT09(0,slbc)) \ | ||
, PPMPF_DREF(PPMPF_SEQ_AT09(1,slbc)) \ | ||
, PPMPF_DREF(PPMPF_SEQ_AT09(2,slbc)) \ | ||
, PPMPF_DREF(PPMPF_SEQ_AT09(3,slbc)), ) | ||
|
||
#define PPMPF_BDS16(f,g,p,h,i,w,x,s,l,b,c,...) \ | ||
PPMPF_BDS4(x,g,s,l,c)(p(l)) \ | ||
PPMPF_BDS5(w,g,b,l,c) | ||
|
||
#define PPMPF_BDS18(x) \ | ||
PPMPF_FLDX25( \ | ||
, (())(PPMPF_TUPLE(PPMPF_DREF(x)))(())((0)) \ | ||
, PPMPF_TUP_GET \ | ||
, PPMPF_TUP_POP \ | ||
, PPMPF_TUP_EMPTY \ | ||
, PPMPF_FLDX23 \ | ||
, PPMPF_FLDX24 \ | ||
, PPMPF_BDS15 \ | ||
, PPMPF_BDS1 \ | ||
, PPMPF_BDS2, ) | ||
|
||
#define PPMPF_BDS19(x) \ | ||
PPMPF_BDS14A(x), PPMPF_BDS14B(x) | ||
|
||
#define PPMPF_BDS20(x) \ | ||
PPMPF_BDS19(PPMPF_BDS18(x)) | ||
|
||
#define PPMPF_BDS21(f,...) \ | ||
PPMPF_APPLY(f,PPMPF_DREF(PPMPF_BDS11(__VA_ARGS__))) | ||
|
||
#endif /* _ODREEX_PPMPF_FUNCTIONAL_BIND_INTERNALS_HH_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters