Below is some stuff, which I'm unsure of how it should be implemented
eventually. Input is highly welcome.
Thanks,
leo
TODO items and design issues
1) bitwise or, and, xor
We currently have two distinct sets of opcodes and MMD functions for
numeric (i.e. integer) and string bitwise functionality. E.g.
bor Px, Py # $x +|= $y
bors Px, Py, Pz # $x = $y ~| $z
It now depends on the Perl6 code generator how the Parrot
implementation should behave (or vice versa :)
a) just do MMD
Px = Px.__as_number() # numeric context
$P1 = Py.__as_number()
bor Px, $P1 # MM dispatch on <Int, Int>
$P0 = Py.__as_string() # string context
$P1 = Pz.__as_string()
bor Px, $P0, $P1 # MM dispatch on <Str, Str>
b) use current distinct opcodes
bor Px, Py # call get_integer() internally
bors Px, Py, Pz # call get_string() internally
If a) is true, we would have just one set of bitwise MMD functions.
If b) is true, then there is no MMD needed as the functionality is
always the same: make numeric/string and do the bitwise operation.
This would be better implemented with a vtable method.
2) logical or, and, xor
The functionality depends only on the truth value of the operands.
That is e.g.:
Px = Py or Pz # Px = Py.bool() ? Py : Pz
For Perl5 we might need a different implementation that returns the
boolean value instead of the value itself. But there is not much to MMD
for this operations IMHO, a plain vtable would suffice.
3) logical (unsigned) and arithmetic shifts
It's again the question, if there is much multi on the dispatch. The
implementation for
shl Px, Py, Pz
is just something like:
Px = Py << Pz.get_integer()
Folks could of course implement fancy stuff that doesn't resemble a
shift operation at all by going full MMD. But it's not much reasonable
to allow it IMHO.
4) Missing infix MMD (or vtable) methods
- C<lsr> - unsigned shift right has no PMC equivalent
- C<rotl>, C<rotr> - rotate opcodes and methods
The latter was discussed some time ago. The problem with these
operations is probably that there are too many possiblities: rotate
how much of the bits and what happens with the other bits. We could
design these opcodes like PPCs "rlw*" opcodes, which are said to be
turing complete on their own :) But we probably need just a small
subset as e.g. used in runtime/parrot/library/Digest/MD5.imc
5) new opcodes that return a new result:
Px = n_add Py, Pz # new Px created
These opcodes will be done RSN.