changeset 24727:11e359eb63f4

move install_builtins function inside symbol_table class * builtins.h: Move install_builtins decl inside symbol_table class. * symtab.h (symbol_table::install_builtins): Provide decl. (symbol_table::symbol_table): Call install_builtins. * mk-builtins.pl: Define static functions inside octave namespace. Define install_builtins inside symbol_table class. * builtins.h: Delete * libinterp/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Sat, 10 Feb 2018 16:03:27 -0500
parents 10c7e236a567
children af11cc7cd336
files libinterp/builtins.h libinterp/corefcn/interpreter.cc libinterp/corefcn/symtab.h libinterp/mk-builtins.pl libinterp/module.mk
diffstat 5 files changed, 31 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/builtins.h	Sat Feb 10 15:57:32 2018 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-/*
-
-Copyright (C) 1993-2017 John W. Eaton
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_builtins_h)
-#define octave_builtins_h 1
-
-#include "octave-config.h"
-
-#include "builtin-defun-decls.h"
-
-extern OCTINTERP_API void install_builtins (void);
-
-#endif
--- a/libinterp/corefcn/interpreter.cc	Sat Feb 10 15:57:32 2018 -0500
+++ b/libinterp/corefcn/interpreter.cc	Sat Feb 10 16:03:27 2018 -0500
@@ -40,7 +40,6 @@
 #include "unistd-wrappers.h"
 
 #include "builtin-defun-decls.h"
-#include "builtins.h"
 #include "defaults.h"
 #include "Cell.h"
 #include "call-stack.h"
@@ -417,8 +416,6 @@
     else
       quit_allowed = false;
 
-    install_builtins ();
-
     bool line_editing = false;
     bool traditional = false;
 
--- a/libinterp/corefcn/symtab.h	Sat Feb 10 15:57:32 2018 -0500
+++ b/libinterp/corefcn/symtab.h	Sat Feb 10 16:03:27 2018 -0500
@@ -59,7 +59,9 @@
       : m_fcn_table (), m_class_precedence_table (),
         m_parent_map (), m_global_scope ("global scope"),
         m_top_scope ("top scope"), m_current_scope (m_top_scope)
-      { }
+      {
+        install_builtins ();
+      }
 
     // No copying!
 
@@ -710,6 +712,9 @@
     symbol_scope m_current_scope;
 
     octave_value dump_fcn_table_map (void) const;
+
+    // This function is generated automatically by mk-builtins.pl.
+    void install_builtins (void);
   };
 
   extern bool out_of_date_check (octave_value& function,
--- a/libinterp/mk-builtins.pl	Sat Feb 10 15:57:32 2018 -0500
+++ b/libinterp/mk-builtins.pl	Sat Feb 10 16:03:27 2018 -0500
@@ -148,17 +148,18 @@
 #  include \"config.h\"
 #endif
 
-#include \"defun.h\"
+#include \"builtin-defun-decls.h\"
 #include \"help.h\"
 #include \"ovl.h\"
+#include \"symtab.h\"
 #include \"variables.h\"
-#include \"builtin-defun-decls.h\"
-#include \"builtins.h\"
 
 #if defined (quad)
 #  undef quad
 #endif
-";
+
+namespace octave
+{";
 
   @installer_functions = ();
 
@@ -176,10 +177,10 @@
     $fcn =~ s/-/_/g;
     $fcn = "install_${fcn}_fcns";
 
-    $fcn_header = "\nstatic void
-$fcn (void)
-{
-  std::string file = \"$arg\";";
+    $fcn_header = "\n  static void
+  $fcn (symbol_table& symtab)
+  {
+    std::string file = \"$arg\";";
 
     open($fh, "<", $file) || die "mk-builtins.pl: failed to open file $file\n";
 
@@ -187,7 +188,7 @@
     ## install the built-in functions or function aliases.
 
     $type = "";
-    $const = 0;
+    $const_param = "";
     $fname = "";
     $name = "";
     $alias = "";
@@ -214,7 +215,7 @@
         $type = "fun";
         $fname = "F$2";
         $name = "$2";
-        $const = 1;
+        $const_param = ", true";
       }
       elsif ($line =~ /^ *DEFALIAS *\( *([^ ,]*) *, *([^ )]*) *\).*$/)
       {
@@ -252,23 +253,16 @@
         ## We use the name appended to the "external-doc" tag to find
         ## the docstring for aliases to this function.
 
-        if ($const)
-        {
-          $fcn_body .= "\n  install_builtin_function ($fname, \"$name\", file, \"external-doc:$name\", true);"
-        }
-        else
-        {
-          $fcn_body .= "\n  install_builtin_function ($fname, \"$name\", file, \"external-doc:$name\");"
-        }
+        $fcn_body .= "\n    symtab.install_built_in_function (\"$name\", octave_value (new octave_builtin ($fname, \"$name\", file, \"external-doc:$name\")));";
 
         $type = "";
         $fname = "";
         $name = "";
-        $const = 0;
+        $const_param = "";
       }
       elsif ($type eq "alias")
       {
-        $fcn_body .= "\n  alias_builtin (\"$alias\", \"$name\");";
+        $fcn_body .= "\n    symtab.alias_built_in_function (\"$alias\", \"$name\");";
 
         ## Preserve dispatch info (if any) that we have for the
         ## original function.
@@ -297,33 +291,33 @@
 
       foreach $class (@classes)
       {
-        $dispatch_code .= "\n  install_builtin_dispatch (\"$fcn\", \"$class\");";
+        $dispatch_code .= "\n    symtab.install_built_in_dispatch (\"$fcn\", \"$class\");";
       }
 
-      if ($dispatch_code)
-        {
-          $fcn_body .= "\n$dispatch_code";
-        }
+    if ($dispatch_code)
+      {
+        $fcn_body .= "\n$dispatch_code";
+      }
     }
 
     if ($fcn_body)
       {
         push (@installer_functions, $fcn);
 
-        print "$fcn_header\n$fcn_body\n}\n";
+        print "$fcn_header\n$fcn_body\n  }\n";
       }
   }
 
   print "
-void
-install_builtins (void)
-{
+  void
+  symbol_table::install_builtins (void)
+  {
 ";
 
   foreach $fcn (@installer_functions)
   {
-    print "  $fcn ();\n"
+    print "    $fcn (*this);\n"
   }
 
-  print "}\n";
+  print "  }\n}\n";
 }
--- a/libinterp/module.mk	Sat Feb 10 15:57:32 2018 -0500
+++ b/libinterp/module.mk	Sat Feb 10 16:03:27 2018 -0500
@@ -95,7 +95,6 @@
   %reldir%/mk-version-h.sh
 
 octinclude_HEADERS += \
-  %reldir%/builtins.h \
   %reldir%/build-env.h \
   %reldir%/liboctinterp-build-info.h \
   %reldir%/octave.h \