(a, b) = (c, d) みたいな書き方ができるマクロ。見やすくなる時だけ使おう。
特殊展開マクロちゅっちゅちゅー
(a, b) = (c, d) みたいな書き方ができるマクロ。見やすくなる時だけ使おう。
特殊展開マクロちゅっちゅちゅー
// コア
#define global ctype _pairOpPush2(%1, %2) %t_pairOp %s2 %s1 // 逆順 (%pN の N を(左:0→右:max)にするため)
#define global ctype _pairOpPush1(%1) %t_pairOp %s1
#define global _pairOpPop2 %t_pairOp %o0 %o0
#define global _pairOpPop1 %t_pairOp %o0
// 展開後の式の形
#define global _pairEq2Impl %t_pairOp (%p0 == %p2 && %p1 == %p3)
#define global _pairNe2Impl %t_pairOp (%p0 != %p2 || %p1 != %p3)
#define global _pairOp2Impl %t_pairOp %p0 %p4 %p2 , %p1 %p4 %p3
// { push, 展開式, pop }
#define global ctype _pairRel2(%1 = impl, %2 = args, %3) \
_pairOpPush2 %3 _pairOpPush2 %2 \
%1 \
_pairOpPop2 _pairOpPop2
#define global ctype _pairOp2(%1 = impl, %2 = op, %3 = args, %4) \
_pairOpPush1(%2) _pairOpPush2 %4 _pairOpPush2 %3 \
%1 \
_pairOpPop2 _pairOpPop2 _pairOpPop1
// public
#define global ctype pairEq(%1, %2) _pairRel2(_pairEq2Impl, %1, %2)
#define global ctype pairNe(%1, %2) _pairRel2(_pairNe2Impl, %1, %2)
#define global ctype pairOp(%1, %2 = op, %3) _pairOp2(_pairOp2Impl, %2, %1, %3)
// テキトーなサンプル
#if 1
#define ctype dbgstr(%1) ({"%1 = "} + (%1))
#define ctype dbgarr2(%1) ({"%1 = [ "} + %1(0) + ", " + %1(1) + " ]")
a = 1
b = 2
mes dbgstr( pairEq((a, b), (1, 2)) ) // true
mes dbgstr( pairNe((a, b), (3, 2)) ) // true
x = pairOp( (1, 2), +, (3, 4) ) // ←見づらい
mes dbgarr2( x )
#endif
/*
(a, b) を ctype マクロの引数にして、後は特殊展開マクロでよろしくやってるだけ
n-tuple について同様に可能
*/