Add support for constant expressions as operands
This commit also shuffles some code around, but without any other functionality change