octave-maintainers
[Top][All Lists]
Advanced

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

Re: oct2mat script based on parse tree


From: Muthiah Annamalai
Subject: Re: oct2mat script based on parse tree
Date: Wed, 09 Jan 2008 16:37:57 -0600
User-agent: Thunderbird 2.0.0.6 (X11/20071022)

John W. Eaton wrote:
On  9-Jan-2008, Muthiah Annamalai wrote:

| John W. Eaton wrote:
| > On  9-Jan-2008, Muthiah Annamalai wrote:
| >
| > | we have some
| > | issues,like I didnt have boolean expressions involving strings folded | > | over.
| >
| > I don't understand what you mean by that.
| >
| > jwe
| > | This is the boolean exp -> const , folding I was talking about.

OK.  I suppose it would be useful to have an option to turn off any
optimizations that happen in the parser.  It should be easy to do, and
I see that as independent of your tree walking code.

jwe

I have attached a patch to allow conditional tree folding.
It works using the global variable

bool parser_folding_and_optimization_flag;

which user must push onto unwind stack, and use
the accessor functions

parser_enable/disable_optimization()

and query by

parser_require_optimization()

I have one problem however, the various symbols are not exported,
and I think it maybe due to a clock-skew in my box, which I cannot fix.
So I hope this patch is correct. Waiting for my build to complete.
The changes are correct syntactic/semantically however.

Patch follows. Changelog is

2008-01-09 Muthiah Annamalai <address@hidden>

* parse.h (parser_enable_optimization, parser_disable_optimization,
parser_require_optimization,parser_folding_and_optimization_flag):
New function, boolean flag declaration.
* parse.y (parser_enable_optimization, parser_disable_optimization,
parser_require_optimization,parser_folding_and_optimization_flag):
New boolean flag and functions to make conditional fold()-ing.


-Muthu

2008-01-09  Muthiah Annamalai  <address@hidden>

        * parse.h (parser_enable_optimization, parser_disable_optimization,
        parser_require_optimization,parser_folding_and_optimization_flag): 
        New function, boolean flag declaration.
        * parse.y (parser_enable_optimization, parser_disable_optimization,
        parser_require_optimization,parser_folding_and_optimization_flag):
         New boolean flag and functions to make conditional fold()-ing.

Index: parse.h
===================================================================
RCS file: /cvs/octave/src/parse.h,v
retrieving revision 1.46
diff -u -p -r1.46 parse.h
--- parse.h     28 Dec 2007 20:56:57 -0000      1.46
+++ parse.h     9 Jan 2008 19:52:20 -0000
@@ -67,6 +67,10 @@ extern bool input_from_startup_file;
 // an eval() statement.
 extern bool evaluating_function_body;
 
+// TRUE means the parser invokes fold() wherever applicable. 
+// Default set to TRUE. FALSE turns off parser optimizations.
+extern bool parser_folding_and_optimization_flag;
+
 // Keep track of symbol table information when parsing functions.
 extern std::stack<symbol_table::scope_id> symtab_context;
 
@@ -131,6 +135,16 @@ eval_string (const std::string&, bool si
 extern OCTINTERP_API octave_value
 eval_string (const std::string&, bool silent, int& parse_status);
 
+extern OCTINTERP_API void
+parser_disable_optimization( );
+
+extern OCTINTERP_API void
+parser_enable_optimization( );
+
+extern OCTINTERP_API bool
+parser_require_optimization( );
+
+
 #endif
 
 /*
Index: parse.y
===================================================================
RCS file: /cvs/octave/src/parse.y,v
retrieving revision 1.285
diff -u -p -r1.285 parse.y
--- parse.y     7 Jan 2008 17:57:24 -0000       1.285
+++ parse.y     9 Jan 2008 19:52:21 -0000
@@ -102,6 +102,10 @@ bool input_from_startup_file = false;
 // an eval() statement.
 bool evaluating_function_body = false;
 
+// TRUE means the parser invokes fold() wherever applicable. 
+// Default set to TRUE. FALSE turns off parser optimizations.
+bool parser_folding_and_optimization_flag  = true;
+
 // Keep a count of how many END tokens we expect.
 int end_tokens_expected = 0;
 
@@ -1525,6 +1529,9 @@ fold (tree_binary_expression *e)
 {
   tree_expression *retval = e;
 
+  if ( ! parser_require_optimization() )
+    return retval;
+
   unwind_protect::begin_frame ("fold_binary_expression");
 
   unwind_protect_int (error_state);
@@ -1577,6 +1584,9 @@ fold (tree_unary_expression *e)
 {
   tree_expression *retval = e;
 
+  if ( ! parser_require_optimization() )
+    return retval;
+
   unwind_protect::begin_frame ("fold_unary_expression");
 
   unwind_protect_int (error_state);
@@ -4120,6 +4130,32 @@ context @var{context}, which may be eith
   return retval;
 }
 
+// use the enable/disable optimization
+// and donot touch the parser_folding_and_optimization_flag
+// except storing it on an unwind_protect stack, to preserve
+// its value.
+
+void
+parser_disable_optimization( ) 
+{
+  parser_folding_and_optimization_flag = false;
+}
+
+void
+parser_enable_optimization( )
+{
+  parser_folding_and_optimization_flag = true;
+}
+
+// use this function to check if folding() is
+// required. In future maybe we need this, when
+// we do more levels of optimizations/translations.
+bool
+parser_require_optimization( )
+{
+  return parser_folding_and_optimization_flag;
+}
+
 /*
 ;;; Local Variables: ***
 ;;; mode: text ***

reply via email to

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