-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPLISP.h
128 lines (120 loc) · 4.97 KB
/
PPLISP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
MIT License
Copyright (c) 2023 cospplredman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PPLISP_H
#define PPLISP_H
#define PPLISP_EXP10(...)__VA_ARGS__
#define PPLISP_EXP9(...)PPLISP_EXP10(PPLISP_EXP10(PPLISP_EXP10(__VA_ARGS__)))
#define PPLISP_EXP8(...)PPLISP_EXP9(PPLISP_EXP9(PPLISP_EXP9(__VA_ARGS__)))
#define PPLISP_EXP7(...)PPLISP_EXP8(PPLISP_EXP8(PPLISP_EXP8(__VA_ARGS__)))
#define PPLISP_EXP6(...)PPLISP_EXP7(PPLISP_EXP7(PPLISP_EXP7(__VA_ARGS__)))
#define PPLISP_EXP5(...)PPLISP_EXP6(PPLISP_EXP6(PPLISP_EXP6(__VA_ARGS__)))
#define PPLISP_EXP4(...)PPLISP_EXP5(PPLISP_EXP5(PPLISP_EXP5(__VA_ARGS__)))
#define PPLISP_EXP3(...)PPLISP_EXP4(PPLISP_EXP4(PPLISP_EXP4(__VA_ARGS__)))
#define PPLISP_EXP2(...)PPLISP_EXP3(PPLISP_EXP3(PPLISP_EXP3(__VA_ARGS__)))
#define PPLISP_EXP1(...)PPLISP_EXP2(PPLISP_EXP2(PPLISP_EXP2(__VA_ARGS__)))
#define EXP(...)PPLISP_EXP1(__VA_ARGS__)
//utility macros
#define PPLISP_CONS_(...)__VA_ARGS__)
#define PPLISP_CONS(...)(__VA_ARGS__,PPLISP_CONS_
#define PPLISP_WRAP(...)((__VA_ARGS__))
#define PPLISP_SWP(a,...)(__VA_ARGS__,a)
#define PPLISP_FST(a,...)(a)
#define PPLISP_SEC_(a,b,...)(b)
#define PPLISP_SEC(a,...)PPLISP_SEC_(a,__VA_ARGS__,)
#define PPLISP_RST(a,...)(__VA_ARGS__)
#define PPLISP_CAT(a,b)a##b
//avoiding blue paint macros
#define M_(...)__VA_ARGS__
#define PPLISP_CALL_(a)M_##a
#define M_PPLISP_CALL PPLISP_CALL
#define PPLISP_CALL(a,...)PPLISP_CAT M_()(PPLISP_CALL,_)(a)(__VA_ARGS__)
//prediPPLISP_cate macros
#define PPLISP_COM(...),
#define PPLISP_IS_PAREN(a)PPLISP_SEC(PPLISP_COM a T,F)
#define PPLISP_IS_WHITE(a)PPLISP_IF PPLISP_IS_PAREN(a)((F),PPLISP_SEC(PPLISP_COM a()T,F))
#define PPLISP_IS_QUOTE_QUOTE ()
#define PPLISP_IS_QUOTE(a)PPLISP_IS_PAREN(PPLISP_IS_QUOTE_##a)
#define PPLISP_IS_IF_IF ()
#define PPLISP_IS_IF(a)PPLISP_IS_PAREN(PPLISP_IS_IF_##a)
#define PPLISP_IFT(T,F)T
#define PPLISP_IFF(T,F)F
#define PPLISP_IF(a)PPLISP_IF##a
//macro lisp eval
#define M_PPLISP_MAP_1(a,b,c)PPLISP_MAP PPLISP_SWP PPLISP_CONS PPLISP_WRAP PPLISP_SWP PPLISP_CONS PPLISP_WRAP PPLISP_CALL(M_ a,M_ PPLISP_FST b)c(a,PPLISP_RST b)
#define M_PPLISP_MAP PPLISP_MAP
#define PPLISP_MAP(a,b,c)PPLISP_CALL PPLISP_IF PPLISP_IS_WHITE PPLISP_FST b((,c),(PPLISP_MAP_1,a,b,c))
#define M_PPLISP_EVAL_3(a,b,c,d)PPLISP_IF PPLISP_CALL(EVAL,b)((EVAL,c),(EVAL,d))
#define M_PPLISP_EVAL_2(a,...)PPLISP_CALL PPLISP_CALL PPLISP_IF PPLISP_IS_IF (a)((PPLISP_EVAL_3,a,__VA_ARGS__),(PPLISP_MAP,(EVAL),(__VA_ARGS__),(a)))
#define M_EVAL EVAL
#define EVAL(a)PPLISP_CALL PPLISP_IF PPLISP_IS_QUOTE PPLISP_FST a((,PPLISP_RST a),(PPLISP_EVAL_2,M_ a))
//macro lisp primitives
#define $(...)(QUOTE,__VA_ARGS__)
#define M_IS_NIL(a)PPLISP_IS_WHITE a
#define M_FST(a)PPLISP_FST a
#define M_RST(a)PPLISP_RST a
#define M_CONCAT(a, b)PPLISP_IF PPLISP_IS_WHITE PPLISP_FST a(b,PPLISP_IF PPLISP_IS_WHITE PPLISP_FST b(a,PPLISP_CONS a b))
#else
#undef PPLISP_H
#undef PPLISP_EXP10
#undef PPLISP_EXP9
#undef PPLISP_EXP8
#undef PPLISP_EXP7
#undef PPLISP_EXP6
#undef PPLISP_EXP5
#undef PPLISP_EXP4
#undef PPLISP_EXP3
#undef PPLISP_EXP2
#undef PPLISP_EXP1
#undef EXP
#undef PPLISP_CONS_
#undef PPLISP_CONS
#undef PPLISP_WRAP
#undef PPLISP_SWP
#undef PPLISP_FST
#undef PPLISP_SEC_
#undef PPLISP_SEC
#undef PPLISP_RST
#undef PPLISP_CAT
#undef M_
#undef PPLISP_CALL_
#undef M_PPLISP_CALL
#undef PPLISP_CALL
#undef PPLISP_COM
#undef PPLISP_IS_PAREN
#undef PPLISP_IS_WHITE
#undef PPLISP_IS_QUOTE_QUOTE
#undef PPLISP_IS_QUOTE
#undef PPLISP_IS_IF_IF
#undef PPLISP_IS_IF
#undef PPLISP_IFT
#undef PPLISP_IFF
#undef PPLISP_IF
#undef M_PPLISP_MAP_1
#undef M_PPLISP_MAP
#undef PPLISP_MAP
#undef M_PPLISP_EVAL_3
#undef M_PPLISP_EVAL_2
#undef M_EVAL
#undef EVAL
#undef M_IS_NIL
#undef M_FST
#undef M_RST
#undef M_CONCAT
#endif