- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
#include <stdio.h>
#define PRIM_CAT_(a, ...) a ## __VA_ARGS__
#define PRIM_CAT(...) PRIM_CAT_(__VA_ARGS__)
#define PRIM_JOIN(sep, a, ...) PRIM_CAT(PRIM_CAT(a, sep), __VA_ARGS__)
#define PRIM_QUOTE_(...) # __VA_ARGS__
#define PRIM_QUOTE(...) PRIM_QUOTE_(__VA_ARGS__)
#define PRIM_EAT(...) /* nothing */
#define PRIM_EXPAND(...) __VA_ARGS__
#define PRIM_HEAD_(x, ...) x
#define PRIM_HEAD(...) PRIM_HEAD_(__VA_ARGS__)
#define PRIM_TAIL_(x, ...) __VA_ARGS__
#define PRIM_TAIL(...) PRIM_TAIL_(__VA_ARGS__)
#define PRIM_CHECK(...) PRIM_CHECK_N(__VA_ARGS__, 0)
#define PRIM_CHECK_N(x, n, ...) n
#define PRIM_PROBE(x) x, 1
#define PRIM_TEST(...) int main(){puts(PRIM_QUOTE(__VA_ARGS__)); return 0;}
#define BOOL_TO_BOOL(x) BOOL_COMPL(BOOL_NOT(x))
#define BOOL_COMPL(x) PRIM_CAT(BOOL_COMPL_, x)
#define BOOL_COMPL_1 0
#define BOOL_COMPL_0 1
#define BOOL_NOT(x) PRIM_CHECK(PRIM_CAT(BOOL_NOT_, x))
#define BOOL_NOT_0 PROBE(?)
#define BOOL_AND(x, y) PRIM_CAT(BOOL_AND_, x)(y)
#define BOOL_AND_0(x) 0
#define BOOL_AND_1(x) x
#define BOOL_OR(x, y) PRIM_CAT(BOOL_OR_, x)(y)
#define BOOL_OR_1(x) 1
#define BOOL_OR_0(x) x
#define BOOL_XOR(x, y) PRIM_CAT(BOOL_XOR_, x)(y)
#define BOOL_XOR_1(x) BOOL_COMPL(x)
#define BOOL_XOR_0(x) x
#define BOOL_EQ(x, y) BOOL_COMPL(BOOL_XOR(x, y))
#define ARITH_ADD_(a7, a6, a5, a4, a3, a2, a1, a0, b7, b6, b5, b4, b3, b2, b1, b0) \
BOOL_XOR(BOOL_XOR(a7, b7), BOOL_OR(BOOL_AND(a6, b6), BOOL_AND(BOOL_XOR(a6, b6), BOOL_OR(BOOL_AND(a5, b5), BOOL_AND(BOOL_XOR(a5, b5), BOOL_OR(BOOL_AND(a4, b4), BOOL_AND(BOOL_XOR(a4, b4), BOOL_OR(BOOL_AND(a3, b3), BOOL_AND(BOOL_XOR(a3, b3), BOOL_OR(BOOL_AND(a2, b2), BOOL_AND(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))))))))))))), \
BOOL_XOR(BOOL_XOR(a6, b6), BOOL_OR(BOOL_AND(a5, b5), BOOL_AND(BOOL_XOR(a5, b5), BOOL_OR(BOOL_AND(a4, b4), BOOL_AND(BOOL_XOR(a4, b4), BOOL_OR(BOOL_AND(a3, b3), BOOL_AND(BOOL_XOR(a3, b3), BOOL_OR(BOOL_AND(a2, b2), BOOL_AND(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))))))))))), \
BOOL_XOR(BOOL_XOR(a5, b5), BOOL_OR(BOOL_AND(a4, b4), BOOL_AND(BOOL_XOR(a4, b4), BOOL_OR(BOOL_AND(a3, b3), BOOL_AND(BOOL_XOR(a3, b3), BOOL_OR(BOOL_AND(a2, b2), BOOL_AND(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))))))))), \
BOOL_XOR(BOOL_XOR(a4, b4), BOOL_OR(BOOL_AND(a3, b3), BOOL_AND(BOOL_XOR(a3, b3), BOOL_OR(BOOL_AND(a2, b2), BOOL_AND(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))))))), \
BOOL_XOR(BOOL_XOR(a3, b3), BOOL_OR(BOOL_AND(a2, b2), BOOL_AND(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))))), \
BOOL_XOR(BOOL_XOR(a2, b2), BOOL_OR(BOOL_AND(a1, b1), BOOL_AND(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)))), \
BOOL_XOR(BOOL_XOR(a1, b1), BOOL_AND(a0, b0)), \
BOOL_XOR(a0, b0)
#define ARITH_ADD(...) ARITH_ADD_(__VA_ARGS__)
#define ARITH_INC_(b7, b6, b5, b4, b3, b2, b1, b0) ARITH_ADD(b7, b6, b5, b4, b3, b2, b1, b0, 0, 0, 0, 0, 0, 0, 0, 1)
#define ARITH_INC(...) ARITH_INC_(__VA_ARGS__)
#define ARITH_NEGATE_(b7, b6, b5, b4, b3, b2, b1, b0) ARITH_INC(BOOL_COMPL(b7), BOOL_COMPL(b6), BOOL_COMPL(b5), BOOL_COMPL(b4), BOOL_COMPL(b3), BOOL_COMPL(b2), BOOL_COMPL(b1), BOOL_COMPL(b0))
#define ARITH_NEGATE(...) ARITH_NEGATE_(__VA_ARGS__)
#define ARITH_SUB_(a7, a6, a5, a4, a3, a2, a1, a0, b7, b6, b5, b4, b3, b2, b1, b0) ARITH_ADD(a7, a6, a5, a4, a3, a2, a1, a0, ARITH_NEGATE(b7, b6, b5, b4, b3, b2, b1, b0))
#define ARITH_SUB(...) ARITH_SUB_(__VA_ARGS__)
#define ARITH_DEC_(a7, a6, a5, a4, a3, a2, a1, a0) ARITH_SUB(a7, a6, a5, a4, a3, a2, a1, a0, 0, 0, 0, 0, 0, 0, 0, 1)
#define ARITH_DEC(...) ARITH_DEC_(__VA_ARGS__)
#define ARITH_TO_C_NUMBER_(b7, b6, b5, b4, b3, b2, b1, b0) PRIM_CAT(0b, PRIM_CAT(b7, PRIM_CAT(b6, PRIM_CAT(b5, PRIM_CAT(b4, PRIM_CAT(b3, PRIM_CAT(b2, PRIM_CAT(b1, b0))))))))
#define ARITH_TO_C_NUMBER(...) ARITH_TO_C_NUMBER_(__VA_ARGS__)
PRIM_TEST(
ARITH_TO_C_NUMBER(ARITH_ADD(0,0,0,0,0,0,1,1, ARITH_INC(0,1,0,1,1,1,1,1))),
ARITH_TO_C_NUMBER(ARITH_DEC(0,0,0,0,0,0,0,0))
)
А я всё не уймусь...
https://ideone.com/pudErG