Re: Learning the Octave interpreter code to implement Java class dot-referencing
Hossein Sajjadi <[email protected]>
| Newsgroups | gmane.comp.gnu.octave.maintainers |
|---|---|
| Message-ID | <CAEuvCVMb1V0N1eQmRMhjMVdYvkGSPGO9AZ5c=JMAOdnnvvrpHg@mail.gmail.com> |
On 7/8/20, Andrew Janke <[email protected]> wrote: > Hi, Octave maintainers, > > A while ago, I took a stab at adding support for dot-reference syntax > for Java classes. (https://savannah.gnu.org/bugs/index.php?41239) I > totally failed, because I don't understand the Octave interpreter code > well enough, and don't have bison/yacc skills. > > Can anyone point me at resources for learning about the Octave > interpreter code, or bison/yacc generically, that would help me get good > enough to write a patch for this? > > Cheers, > Andrew > > Backed by developing Octave Coder here are my insights when trying to create an external language interface for python and before placing it in my TODO queue (The same concepts here are applied to java): For each java class/ package used in an expression an equivalent Octave classdef class / package is generated on the fly. Each class has a data member of type ov-java.h/octave_java that holds the underlying java object. The generated class only contains public members. Those on the fly classes can be written to disk as .m classdef files using a code generator. That is a simple solution but the best and the more complex solution is, creating in-memory classdef classes. For it you need to work with functions in ov-classdef.h and ov-classdef.cc and finally use ov-classdef.h/cdef_manager to register new on the fly packages and classes. I'm not sure but I think some functions in ov-classdef.h have been made private that may make that difficult. If you encounter problems you may need help from admin to make those methods public. When you complete developing such an interface there is no need to have special rules to evaluate indexing expressions containing java objects (base_expr_val.isjava () in libinterp/pt-eval.cc) and java objects are evaluated like other classdef objects. This idea can be extended further and an Octave classdef object that is inherited from base java object can be sent to java. But it requires that on-the-fly java classes are generated from octave classdef classes. -- Sincerely, Hossein