Skip to content

Commit 35d32bb

Browse files
authored
Solve 1289 compile opt at main level (#1954)
1 parent 2c5a9bc commit 35d32bb

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

src/GDLLexer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//#include "dinterpreter.hpp"
3131

3232
// defintion in dinterpreter.cpp
33-
//void SetActualCompileOpt( unsigned int cOpt);
33+
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);
3434

3535
class CUSTOM_API GDLLexer : public antlr::CharScanner, public GDLTokenTypes
3636
{

src/GDLParser.hpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010

1111

1212
#include <fstream>
13-
#include "basegdl.hpp"
14-
//#include "str.hpp"
15-
//#include "dnodefactory.hpp"
13+
14+
#include "GDLParser.hpp"
15+
16+
#include "str.hpp"
17+
#include "dnodefactory.hpp"
1618
#include "objects.hpp"
17-
//#include "initsysvar.hpp"
19+
#include "initsysvar.hpp"
1820

1921
#include <antlr/TokenStreamSelector.hpp>
2022

@@ -28,7 +30,7 @@
2830
//#include "dinterpreter.hpp"
2931

3032
// defintion in dinterpreter.cpp
31-
//void SetActualCompileOpt( unsigned int cOpt);
33+
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);
3234

3335
class CUSTOM_API GDLParser : public antlr::LLkParser, public GDLTokenTypes
3436
{
@@ -67,7 +69,7 @@ class CUSTOM_API GDLParser : public antlr::LLkParser, public GDLTokenTypes
6769
else if( opt == "STATIC") compileOpt |= STATIC;
6870
else if( opt == "NOSAVE") compileOpt |= NOSAVE;
6971
else throw GDLException("Unrecognised COMPILE_OPT option: "+opt);
70-
// SetActualCompileOpt( compileOpt);
72+
MemorizeCompileOptForMAINIfNeeded( compileOpt);
7173
}
7274

7375
std::string subName; // name of procedure function to be compiled ("" -> all file)

src/dinterpreter.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ DInterpreter::DInterpreter(): GDLInterpreter()
101101
// tmpList.reserve(100);
102102
}
103103

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

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

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

12441244
break; // no error -> everything ok

src/gdlc.g

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ header {
4646
//#include "dinterpreter.hpp"
4747

4848
// defintion in dinterpreter.cpp
49-
//void SetActualCompileOpt( unsigned int cOpt);
49+
void MemorizeCompileOptForMAINIfNeeded( unsigned int cOpt);
5050
}
5151

5252
options {
@@ -198,7 +198,7 @@ tokens {
198198
else if( opt == "STATIC") compileOpt |= STATIC;
199199
else if( opt == "NOSAVE") compileOpt |= NOSAVE;
200200
else throw GDLException("Unrecognised COMPILE_OPT option: "+opt);
201-
// SetActualCompileOpt( compileOpt);
201+
MemorizeCompileOptForMAINIfNeeded( compileOpt);
202202
}
203203

204204
std::string subName; // name of procedure function to be compiled ("" -> all file)

src/pro/utilities/gdl_implied_print.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
;
2020
function pretty_serialize,value,tagname=tagname,flat=flat
2121
common json_serialize_gdl_level, level
22-
COMPILE_OPT idl2, HIDDEN
22+
; warning as this is directly compiled within the $MAIN$ interpretor there must be no COMPILE_OPT here.
23+
;COMPILE_OPT HIDDEN
2324
ON_ERROR,2
2425
;; CATCH, Error_status
2526
;; IF Error_status NE 0 THEN BEGIN
@@ -159,7 +160,8 @@ endif else tmpstr=''
159160
end
160161

161162
pro gdl_implied_print,out,value
162-
COMPILE_OPT idl2, HIDDEN
163+
; warning as this is directly compiled within the $MAIN$ interpretor there must be no COMPILE_OPT here.
164+
;COMPILE_OPT HIDDEN
163165
ON_ERROR, 2
164166
; get info on out
165167
info=fstat(out)

0 commit comments

Comments
 (0)