Given that I have a subroutine stored in a PMC, is there a way
for me to add that subroutine as a method to an existing class?

In other words, I know I can use <store_global> to add the subroutine
into the current namespace...

    .namespace [ "Foo" ]
    
    .sub main @MAIN
       $S0 = ".sub h @ANON\n    print \"Hello\"\n.end\n"
       $P0 = compreg "PIR"
       $P1 = compile $P0, $S0
       store_global "Foo", "hello", $P1
    
       "hello"()
    .end

but is there a way for me to store such a subroutine as a method of an
existing class?  I.e., I'd like to be able to do something along
the lines of:

    .sub main @MAIN
       $P99 = newclass "Foo"
  
       $S0 = ".sub h @ANON\n    print \"Hello\"\n.end\n"
       $P0 = compreg "PIR"
       $P1 = compile $P0, $S0
       store_global "Foo", "hello", $P1

       $I2 = findclass "Foo"
       $P2 = new $I2
       $P2."hello"()
    .end

Am I totally off-the-wall here, or am I just overlooking a pragma, opcode,
or something similar that would allow this to work?

Pm

Reply via email to