Yes, me again....

Most of the time, in the PMC logical_not method, one can write:

    void logical_not (PMC* dest) {
        dest->vtable->set_integer_native(INTERP,dest,NOT_SELF);
    }

where NOT_SELF is 0 if we're "true" and 1 if we're "false".  Or just leave
it out and let default blow up if we're not that kind of PMC.

I had a RubyInteger PMC in P0 and generated

  not P0, P0

which is fine, except that it's still true using the above logical_not,
since all Ruby integers (yes, Virginia, even 0) are true.  (The fact that
dest = src is sort of immaterial; the relevant detail is that the dest is a
PMC that is never false).

Furthermore, this doesn't affect just RubyInteger, but any "not" with a type
like it as the destination.  Arguably, RubyInteger is broken and the rest of
the world is fine using dest->set_integer_native(0), but I think it shows a
problem with logical_not itself, and either

(a) a set_bool PMC method should be added (not the best fix, but at least
    then RubyInteger can morph itself into a false-able PMC), or

(b) logical_not's semantics should be changed to return an INTVAL (0 or 1),
    which of course brings up the question of what is left in the
    destination register -
      (1) clobber it, and set it to be a new boolean PMC, or
      (2) make not take just one param, and have it affect itself, like
          increment, or
      (3) require the destination register to be an Integer (Ix) (not
          presently allowed), or

(c) force people to create a "false-able" PMC as the destination (bad,
    because this introduces an "action at a distance" force; the
    destination of the result shouldn't affect the outcome of an operation)

Similar arguments can be made for the other logical ops, except that it's
more evident that the Right Thing to put in the dest is the usual short-
circuit result, i.e. one of lhs, rhs, or (null? whatever null is for PMCs?),
via get_bool only and without the need for any logical_* PMC methods.

[Oh.  Interesting.  "not P0, P0" alone in a pasm file generates:
logical_not() not implemented in class 'PerlArray'
I see no PerlArray here....]

Enlightenment appreciated as always.

Dave
Isa. 40:31

Reply via email to