Integrating SMOP and P5
This page describes the sketches on how to implement a p5<->SMOP integration that would allow to fully implement Perl 6 cooperatively with p5. The branch is being hosted in github http://github.com/pmurias/perl
- This is going to be a modified p5 interpreter, so it's going to have a different @INC and every module will need to be recompiled to this modified interpreter, just as needed for a new major p5 version.
- The main loop will be the p5 loop, the basic idea is making the p5 interpreter to support the SMOP Interpreter API meaning that you're going to use the p5 interpreter as the SMOP interpreter object.
- This all is possible because SMOP assumes that every object is opaque and that the only one allowed to access the object's structure is its responder interface, which happens to be the first member of the SMOP__Object struct.
- Add polymorphic representation support to p5. This will mean adding the SMOP__ResponderInterface to every value in p5, among them SV and the interpreter itself.
- Dynamically create ResponderInterfaces for each of the p5 values (the interpreter itself, SV and other things) and use them when creating this values. This will allow the interpreter to realize which values belong to it or not. This ResponderInterfaces will be set in the interpreter allowing simple pointer comparison.
- Add checks in every p5 macro to see if the referred value's RI is one of this interpreter's RI, using SMOP_DISPATCH otherwise.
- Implement $interpreter.continuation(), that returns the current continuation. This will, in the case of running p5 code, construct a Coro::State-like object containing the current continuation.
- Implement $interpreter.goto($continuation), that will set that continuation as the current continuation. If that continuation is a p5-continuation it does something like Coro::State load_perl, but if it's something else, it will set a static OP_PolymorphicEval and set the continuation object in the interpreter. This OP_PolymorhicEval will use the SMOP Interpreter Implementation API on the given $continuation.
- Polymorphic representation is probably the coolest feature of Perl 6, implementing that, even without Perl 6, is already a very interesting feature, you wouldn't need to make a SvRV(newSViv(*object)) to embed foreign objects.
- Polymorphic eval is the coolest feature of SMOP, even without Perl 6, that would allow cooperating with other interpreters easily, for instance, one could cooperatively run the stackless python alongside p5.