Introduce notion of "op class" and op_class() method instead of magic macros

Theoretically, everyone could use dynamic_cast<> on Term and Op objects
instead of using that op_class method, but that seems a) more hassle and
b) less elegant. Very open to feedback on this.