Skip to content

Commit

Permalink
Solve 1289 compile opt at main level (#1954)
Browse files Browse the repository at this point in the history
  • Loading branch information
GillesDuvert authored Dec 17, 2024
1 parent 2c5a9bc commit 35d32bb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/GDLLexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
//#include "dinterpreter.hpp"

// defintion in dinterpreter.cpp
//void SetActualCompileOpt( unsigned int cOpt);
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);

class CUSTOM_API GDLLexer : public antlr::CharScanner, public GDLTokenTypes
{
Expand Down
14 changes: 8 additions & 6 deletions src/GDLParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@


#include <fstream>
#include "basegdl.hpp"
//#include "str.hpp"
//#include "dnodefactory.hpp"

#include "GDLParser.hpp"

#include "str.hpp"
#include "dnodefactory.hpp"
#include "objects.hpp"
//#include "initsysvar.hpp"
#include "initsysvar.hpp"

#include <antlr/TokenStreamSelector.hpp>

Expand All @@ -28,7 +30,7 @@
//#include "dinterpreter.hpp"

// defintion in dinterpreter.cpp
//void SetActualCompileOpt( unsigned int cOpt);
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);

class CUSTOM_API GDLParser : public antlr::LLkParser, public GDLTokenTypes
{
Expand Down Expand Up @@ -67,7 +69,7 @@ class CUSTOM_API GDLParser : public antlr::LLkParser, public GDLTokenTypes
else if( opt == "STATIC") compileOpt |= STATIC;
else if( opt == "NOSAVE") compileOpt |= NOSAVE;
else throw GDLException("Unrecognised COMPILE_OPT option: "+opt);
// SetActualCompileOpt( compileOpt);
MemorizeCompileOptForMAINIfNeeded( compileOpt);
}

std::string subName; // name of procedure function to be compiled ("" -> all file)
Expand Down
12 changes: 6 additions & 6 deletions src/dinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ DInterpreter::DInterpreter(): GDLInterpreter()
// tmpList.reserve(100);
}

// void SetActualCompileOpt( unsigned int cOpt)
// {
// if( BaseGDL::interpreter!=NULL && BaseGDL::interpreter->CallStack().size()>0)
// BaseGDL::interpreter->CallStack().back()->SetCompileOpt( cOpt);
// }
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt)
{
if( BaseGDL::interpreter!=NULL && BaseGDL::interpreter->CallStack().size()>0 && BaseGDL::interpreter->CallStack().back()->CallingNode() == 0)
BaseGDL::interpreter->CallStack().back()->SetCompileOpt( cOpt);
}

// used in the statement function.
// runs a new instance of the interpreter if not
Expand Down Expand Up @@ -1238,7 +1238,7 @@ DInterpreter::CommandCode DInterpreter::ExecuteLine( istream* in, SizeT lineOffs
executeLine.clear(); // clear EOF (for executeLine)
executeLine.str( "print,/implied_print," + executeLine.str()); // append new line

lexer.reset( new GDLLexer(executeLine, "", callStack.back()->CompileOpt()));
lexer.reset( new GDLLexer(executeLine, "", 2 )); //2 is HIDDEN //callStack.back()->CompileOpt()));
lexer->Parser().interactive();

break; // no error -> everything ok
Expand Down
4 changes: 2 additions & 2 deletions src/gdlc.g
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ header {
//#include "dinterpreter.hpp"

// defintion in dinterpreter.cpp
//void SetActualCompileOpt( unsigned int cOpt);
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);
}

options {
Expand Down Expand Up @@ -198,7 +198,7 @@ tokens {
else if( opt == "STATIC") compileOpt |= STATIC;
else if( opt == "NOSAVE") compileOpt |= NOSAVE;
else throw GDLException("Unrecognised COMPILE_OPT option: "+opt);
// SetActualCompileOpt( compileOpt);
MemorizeCompileOptForMAINIfNeeded( compileOpt);
}

std::string subName; // name of procedure function to be compiled ("" -> all file)
Expand Down
6 changes: 4 additions & 2 deletions src/pro/utilities/gdl_implied_print.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
;
function pretty_serialize,value,tagname=tagname,flat=flat
common json_serialize_gdl_level, level
COMPILE_OPT idl2, HIDDEN
; warning as this is directly compiled within the $MAIN$ interpretor there must be no COMPILE_OPT here.
;COMPILE_OPT HIDDEN
ON_ERROR,2
;; CATCH, Error_status
;; IF Error_status NE 0 THEN BEGIN
Expand Down Expand Up @@ -159,7 +160,8 @@ endif else tmpstr=''
end

pro gdl_implied_print,out,value
COMPILE_OPT idl2, HIDDEN
; warning as this is directly compiled within the $MAIN$ interpretor there must be no COMPILE_OPT here.
;COMPILE_OPT HIDDEN
ON_ERROR, 2
; get info on out
info=fstat(out)
Expand Down

0 comments on commit 35d32bb

Please sign in to comment.