0, default => new InvalidArgumentException("Only bitwise ops except 'shl', 'shr', 'not' are supported") }; $funcName = "{$left->pgName}_{$op->value}"; $cOp = $op->config()->cOp; $fn = "PG_FUNCTION_INFO_V1($funcName);\n"; $fn .= "Datum $funcName(PG_FUNCTION_ARGS) {\n"; $fn .= " $left->name a = $left->pgGetArgMacro(0);\n"; $fn .= " $left->name b = $left->pgGetArgMacro(1);\n"; $fn .= " $left->pgReturnMacro(a $cOp b);\n"; $fn .= "}\n"; return $fn; } function genBitwiseShiftFunc(Type $left, Op $op) { $_ = match ($op) { Op::Shl, Op::Shr => 0, default => new InvalidArgumentException("Only bitwise shift ops are supported") }; $funcName = "{$left->pgName}_{$op->value}"; $cOp = $op->config()->cOp; $fn = "PG_FUNCTION_INFO_V1($funcName);\n"; $fn .= "Datum $funcName(PG_FUNCTION_ARGS) {\n"; $fn .= " $left->name a = $left->pgGetArgMacro(0);\n"; $fn .= " int32 shift = PG_GETARG_INT32(1);\n"; $fn .= " $left->pgReturnMacro(a $cOp shift);\n"; $fn .= "}\n"; return $fn; } function genBitwiseNotFunc(Type $left, Op $op) { $_ = match ($op) { Op::Not => 0, default => new InvalidArgumentException("Only bitwise NOT op is supported") }; $funcName = "{$left->pgName}_{$op->value}"; $cOp = $op->config()->cOp; $fn = "PG_FUNCTION_INFO_V1($funcName);\n"; $fn .= "Datum $funcName(PG_FUNCTION_ARGS) {\n"; $fn .= " $left->pgReturnMacro($cOp($left->pgGetArgMacro(0)));\n"; $fn .= "}\n"; return $fn; } $header = <<