Improved Logic Gates.

Firstly you can use & and | rather than && and || (which may compile to conditional tests and jumps rather than
ALU operations). digitalRead() returns 0 or 1 (== LOW or HIGH), guaranteed.

Secondly for a flexible gate definition use table look-up - then the actual logic function depends on
the table values (for a 2-input gate there are 16 possibilities (several of which aren't very useful!).

For speed direct port manipulation is needed really - even then the speed will several 100ns propagation.

It would be great to find a microcontroller that is 14 or 16 pin and which can be programmed to emulate
any of the different 4000 or 7400 chips of that footprint!! In practice often discrete logic chips are chosen
because the speed is needed (otherwise the MCU would be doing the work).

So what you're really trying to do is re-invent the PLA and FPGA.