octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to do with builtin functions not in libinterp subdirectory


From: Daniel J Sebald
Subject: Re: What to do with builtin functions not in libinterp subdirectory
Date: Mon, 18 Mar 2013 04:09:14 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 03/18/2013 02:36 AM, Daniel J Sebald wrote:

What kind of solution can we come up with? I'm thinking

1) Some kind of utility that does what libinterp/Makefile.am is
currently doing, or move that code as a definition to the top level Make
constructs so that it can be used in directories other than libinterp.

2) Attach the directory name as part of the function name inside the
builtins.cc, e.g.,:

void
install_libinterp_builtins (void)
{
...
}

void
install_libgui_builtins (void)
{
...
}

3) Somehow in octave.cc put a hook that runs

install_libinterp_builtins ();
install_libgui_builtins ();

either by a short little include file or something similar.

Have you put much thought into perhaps a more straightforward way of incorporating builtin functions? Perhaps if we all thought about this a bit we could come up with something that utilizes the power and flexibility of C++. I'll just toss around some rough ideas, nothing concrete. For example, say instead of DEFUN, i.e.,

DEFUN (qterrordlg, args, ,
  "-*- texinfo -*-\n\

maybe there could be a base class called "builtin_octave_function" with virtual function "execute". For each builtin function, create a new class with a very simple inheritance and fill in the definition for that virtual function with the current code associated with DEFUN. I'll illustrate without being exact:

builtin_octave_function {
  str namestring;
  str docstring;
  virtual retval execute(args);
  builtin_octave_function (str, str);;
}

builtin_octave_function::builtin_octave_function (str name, str doc);
  namestring = name;
  docstring = doc;
  PUT "this" IN THE FUNCTION TABLE SOMEWHERE;
}

Now, for any builtin function someone wants to create in the source tree, just inherit from the base class:

builtin_qterrordlg::builtin_octave_function {
builtin_qterrordlg::builtin_octave_function ("qterrordlg", "-*- texinfo -*-\n\...)
}

retval builtin_qterrordlg::execute(args) {
  SAME EXACT CODE IN WHAT IS NOW DEFUN();
}
builtin_qterrordlg qterrordlg;

So, just create a global instance right after ever definition of a builtin function that automatically creates the instance in the builtin lexer/parser whatever at startup.

One might ask then: All of that documentation info is stuck inside of Octave, how is a exterior doc file to be created? Well, we could have Octave itself create the external documentation. Build octave, launch octave, then run some private command like "create_doc_string('filename')". It shouldn't be too difficult to replicate in C++ inside Octave what is currently being done with the doc strings via the Makefiles. Just loop through the whole table of builtin functions, extracting the docstring, processing, save it to the file. And I bet it is faster in Octave than doing that via Makefiles.

I'm sure there are other ideas and ways of refining. It might be worth some reprogramming here (instead of making the current method work for builtin GUI files) to avoid the modules-to-definitions-to-df files-to-builtins.cc process. Instead, make the C++ compiler do all that work.

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]