3 ms·
I think that while the code expressing MUL is harder to read, since there are a lot more characters strewn about in a small space, it would be more informative
by leksak 11y ago
I think that while the code expressing MUL is harder to read, since there are a lot more characters strewn about in a small space, it would be more informative as to what all the parameters are and I would much more prefer to come back to it three months from now as opposed to the classical approach.
MUL(opcode(0x1c), funct(2), mnemonicPattern("iname rd, rs, rt"),
Example.theMnemonicRepresentation("mul $t1, $t0, $at")
.isRepresentedNumericallyAs(0x71014802),
Example.theMnemonicRepresentation("mul $v0, $a0, $v0")
.isRepresentedNumericallyAs(0x70821002)),
SUB(0x00, 0x22, "iname rd, rs, rt",
Example.from("sub $a0, $zero, $at", 0x12022);
private static String mnemonicPattern(String m) { return m; }
private static int opcode(int opcode) { return opcode; }
private static int funct(int funct) { return funct; }
Now, as you can see I did not have to wrangle Java much for the first three parameters.
The Example class is used so that I do not have to write separate test cases for my assertions nor store valuable information about truisms in different files regarding my objects. Using it I can (in both examples) loop over an Example set and checking that the assertions hold, viz. that my JUnit tests can check that by inputting "mul $t1, $t0, $at" at the appropriate place 0x71014802 comes out at the other end.
For the MUL example, I just had to create a private Stub class and employ a Builder-esque pattern to express what is shown in the example.
It has been awhile since I coded alongside other people, and would love to receive feedback on both the Python keyword emulation as well as your thoughts on the Example ploy.