标题起得比较模糊,是因为我才疏学浅,不知道怎么去描述这个事情
探究的兴趣来源于 V8 的代码:
它定义了一段我看不懂的宏
[code-0]
#define BYTECODE_LIST(V) \
/* Extended width operands */ \
V(Wide, AccumulatorUse::kNone) \
V(ExtraWide, AccumulatorUse::kNone) \
\
/* Debug Breakpoints - one for each possible size of unscaled bytecodes */ \
/* and one for each operand widening prefix bytecode */ \
V(DebugBreakWide, AccumulatorUse::kReadWrite) \
V(DebugBreakExtraWide, AccumulatorUse::kReadWrite) \
V(DebugBreak0, AccumulatorUse::kReadWrite) \
V(DebugBreak1, AccumulatorUse::kReadWrite, OperandType::kReg) \
V(DebugBreak2, AccumulatorUse::kReadWrite, OperandType::kReg, \
OperandType::kReg) \
V(DebugBreak3, AccumulatorUse::kReadWrite, OperandType::kReg,
//假设它只有这么长
后来我看到这个宏定义的作用是:
对于每一行 V(...)
,用里面 ...
的内容作为 V
的参数,生成一个表达式。例如:
#define FCK(...) fck(...);
BYTECODE_LIST(FCK)
那么我们相当于得到了这样一组调用:
fck(Wide, AccumulatorUse::kNone);
fck(ExtraWide, AccumulatorUse::kNone);
fck(DebugBreakWide, AccumulatorUse::kReadWrite)