in reply to Re^2: Using vec() from XS
in thread Using vec() from XS

I don't know the details, but it should be something like this:
  1. synthesize an OP o for vec
  2. set up the runtime environment: push the arguments on the stack, save PL_op and make it point to the synthesized OP o, set any other interpreter globals, stacks, etc.
  3. call CALLRUNOPS
  4. retrieve the result from o->op_targ
  5. clean up
For and example, look at Perl_fold_constants from op.c from the perl source. Try running it inside a C debugger with a simple fold-able expression as print(1+2).

The C function Perl_op_dump can be used to dump an OP tree once it has been properly build (otherwise it will crash).

Replies are listed 'Best First'.
Re^4: Using vec() from XS
by BrowserUk (Patriarch) on Sep 24, 2008 at 01:12 UTC
    1. synthesize an OP o

    That phrase means absolutely nothing to me! So I perldoc'd; I grepped the sources; I filtered the htmlise perldocs; I googled.

    Only the latter turned up that phrase. And other than your post above, the only references google has to "synthesizing an[d] op", from the >25 billion web pages it indexes, are:

    • synthesize an op-. erating procedure
    • synthesize an o p. tima. supervim
    • synthesize an op-. timal topology
    • synthesize an op-. tical matched spatial filter
    • (synthesize) an op-. erationally larger antenna

    So, could you please explain what you mean by that?

    I did look at Perl_fold_constants:

    and I can relate nothing there to that phrase. So, could you please treat me like the thicko I am, and explain what ... you are suggesting, cos I just do not ... understand!

    A long time ago, before the dawn of time, a young, budding mechanical engineer was taken to task for a suggestion he made, but failed to be able to explain. The upshot was: If you cannot explain it, you do not really understand it, so you should not suggest it.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      The problem is me, probably, English is not my native tongue!

      An OP is the structure used internally by perl to represent program code. By synthesize an OP I meant to artificially build and OP (in opposition to its natural birth at the perl parser).

      And that means creating some OPs (maybe just one will do, I am not sure) using the newXXXOP functions, building a tree/sequence with them and setting up its internal state as if they had come from the parser.

      But anyway, all this stuff would be far more complicated than just replicating the code for pp_vec.