Skip to content

Commit 426e13a

Browse files
GillesDuvertGiloo
and
Giloo
authored
WIP testing a lot of changes in order to get full support to SSW software suite for solar satellites. (#2007)
Co-authored-by: Giloo <gildas@localhost>
1 parent 05203d9 commit 426e13a

27 files changed

+1822
-795
lines changed

src/GDLInterpreter.cpp

+78-93
Original file line numberDiff line numberDiff line change
@@ -81,38 +81,22 @@ GDLInterpreter::GDLInterpreter()
8181

8282
try { // for error handling
8383

84-
//optimize speed: differentiate inner loops to avoid one externally implicit comparison on controlc for each loop (if possible)
85-
if (interruptEnable) { //will test for sigControlC
86-
{
87-
do {
88-
last = _retTree;
89-
callStack.back()->SetLineNumber(last->getLine()); // track actual line number
90-
retCode = last->Run(); // Run() sets _retTree
91-
} while (_retTree != NULL && retCode == RC_OK && !(sigControlC) && (debugMode <= DEBUG_RETURN)); //loops if debug_clear or debug_return
92-
if (_retTree != NULL) last = _retTree; //this is OK see https://github.com/gnudatalanguage/gdl/issues/1403#issuecomment-1326490113
93-
goto afterStatement;
94-
}
95-
} else { //will not test for sigControlC
96-
{
97-
do {
98-
last = _retTree;
99-
callStack.back()->SetLineNumber(last->getLine()); // track actual line number
100-
retCode = last->Run(); // Run() sets _retTree
101-
} while (_retTree != NULL && retCode == RC_OK && (debugMode <= DEBUG_RETURN)); //loops if debug_clear or debug_return
102-
if (_retTree != NULL) last = _retTree; //this is OK see https://github.com/gnudatalanguage/gdl/issues/1403#issuecomment-1326490113
84+
//optimize speed: differentiate inner loops to avoid one externally implicit comparison on controlc for each loop (if possible)
85+
if (interruptEnable) { //will test for sigControlC
86+
do {
87+
last = _retTree;
88+
callStack.back()->SetLineNumber(last->getLine()); // track actual line number
89+
retCode = last->Run(); // Run() sets _retTree
90+
} while (_retTree != NULL && retCode == RC_OK && !(sigControlC) && (debugMode <= DEBUG_RETURN)); //loops if debug_clear or debug_return
91+
} else { //will not test for sigControlC
92+
do {
93+
last = _retTree;
94+
callStack.back()->SetLineNumber(last->getLine()); // track actual line number
95+
retCode = last->Run(); // Run() sets _retTree
96+
} while (_retTree != NULL && retCode == RC_OK && (debugMode <= DEBUG_RETURN)); //loops if debug_clear or debug_return
97+
}
98+
if (_retTree != NULL && debugMode != DEBUG_RETURN ) last = _retTree;
10399
goto afterStatement;
104-
}
105-
}
106-
// original single loop with all checks
107-
// {
108-
// do {
109-
// last = _retTree;
110-
// callStack.back()->SetLineNumber(last->getLine()); // track actual line number
111-
// retCode = last->Run(); // Run() sets _retTree
112-
// } while (_retTree != NULL && retCode == RC_OK && !(sigControlC && interruptEnable) && (debugMode <= DEBUG_RETURN)); //loops if debug_clear or debug_return
113-
// if (_retTree != NULL) last = _retTree; //this is OK see https://github.com/gnudatalanguage/gdl/issues/1403#issuecomment-1326490113
114-
// goto afterStatement;
115-
// }
116100

117101
// The following code (up to afterStatement is never executed - here only because ANTLR code needs it, although it should not (not optimized parser)
118102

@@ -358,72 +342,73 @@ GDLInterpreter::GDLInterpreter()
358342
}
359343
}
360344

361-
afterStatement:
362-
// tested a possible optimization: make CtrlCHandler produce a DEBUG_STOP, and do not test sigControlC here at all.
363-
// Apparently does not perform noticeably better and has adverse effects. Forget it.
364-
if (interruptEnable && sigControlC) {
365-
DebugMsg(last, "Interrupted at: ");
366-
sigControlC = false;
367-
retCode = NewInterpreterInstance(last->getLine()); //-1);
368-
} else if (interruptEnable && _retTree == NULL && (debugMode == DEBUG_RETURN || debugMode == DEBUG_OUT)) {
369-
if (debugMode == DEBUG_RETURN) {
370-
if (callStack.back()->GetProName() == MyProName) {
371-
DebugMsg(last, "Return encountered: ");
372-
debugMode = DEBUG_CLEAR;
373-
return NewInterpreterInstance(last->getLine()); //-1);
374-
}
375-
} else { //DEBUG_OUT --> just do an additional .step if we are at MyProName
376-
if (callStack.back()->GetProName() == MyProName) {
377-
debugMode = DEBUG_STEP;
378-
stepCount=1;
379-
return retCode; //continue
380-
}
381-
}
382-
} else if (debugMode != DEBUG_CLEAR) {
383-
if (debugMode == DEBUG_STOP) {
384-
DebugMsg(last, "Stop encountered: ");
385-
if (!interruptEnable) debugMode = DEBUG_PROCESS_STOP;
386-
} else if (debugMode == DEBUG_STOP_SILENT) {
387-
if (!interruptEnable) debugMode = DEBUG_PROCESS_STOP;
388-
}
389-
390-
if (debugMode == DEBUG_STEP) {
391-
if (stepCount == 1) {
392-
stepCount = 0;
393-
DebugMsg(last, "Stepped to: ");
394-
395-
debugMode = DEBUG_CLEAR;
396-
397-
retCode = NewInterpreterInstance(last->getLine()); //-1);
398-
} else {
399-
--stepCount;
345+
afterStatement:
346+
// tested a possible optimization: make CtrlCHandler produce a DEBUG_STOP, and do not test sigControlC here at all.
347+
// Apparently does not perform noticeably better and has adverse effects. Forget it.
348+
if (interruptEnable && sigControlC) {
349+
DebugMsg(last, "Interrupted at: ");
350+
sigControlC = false;
351+
retCode = NewInterpreterInstance(last->getLine()); //-1);
352+
} else if (interruptEnable && _retTree == NULL && (debugMode == DEBUG_RETURN || debugMode == DEBUG_OUT)) {
353+
if (debugMode == DEBUG_RETURN) {
354+
if (callStack.back()->GetProName() == MyProName) {
355+
DebugMsg(last, "Return encountered: ");
356+
debugMode = DEBUG_STOP_SILENT;
357+
return retCode;
358+
}
359+
} else { //DEBUG_OUT --> just do an additional .step if we are at MyProName
360+
if (callStack.back()->GetProName() == MyProName) {
361+
debugMode = DEBUG_STEP;
362+
stepCount=1;
363+
return retCode; //continue
364+
}
365+
}
366+
} else if (debugMode != DEBUG_CLEAR) {
367+
if (debugMode == DEBUG_STOP) {
368+
DebugMsg(last, "Stop encountered: ");
369+
if (!interruptEnable) debugMode = DEBUG_PROCESS_STOP;
370+
} else if (debugMode == DEBUG_STOP_SILENT) {
371+
if (!interruptEnable) debugMode = DEBUG_PROCESS_STOP;
372+
}
373+
if (debugMode == DEBUG_STEP) {
374+
if (stepCount == 1) {
375+
stepCount = 0;
376+
DebugMsg(last, "Stepped to: ");
377+
debugMode = DEBUG_CLEAR;
378+
retCode = NewInterpreterInstance(last->getLine()); //-1);
379+
} else {
380+
--stepCount;
400381
#ifdef GDL_DEBUG
401-
std::cout << "stepCount-- = " << stepCount << std::endl;
382+
std::cout << "stepCount-- = " << stepCount << std::endl;
402383
#endif
403-
}
404-
} else if (debugMode == DEBUG_STEPOVER) {
405-
if (callStack.back()->GetProName() == MyProName) { //we count only in current level
406-
if (stepCount == 1) {
407-
stepCount = 0;
408-
DebugMsg(last, "Stepped to: ");
409-
410-
debugMode = DEBUG_CLEAR;
411-
MyProName="";
412-
retCode = NewInterpreterInstance(last->getLine()); //-1);
413-
} else {
414-
--stepCount;
384+
}
385+
} else if (debugMode == DEBUG_STEPOVER) {
386+
if (callStack.back()->GetProName() == MyProName) { //we count only in current level
387+
if (stepCount == 1) {
388+
stepCount = 0;
389+
DebugMsg(last, "Stepped to: ");
390+
debugMode = DEBUG_CLEAR;
391+
MyProName="";
392+
retCode = NewInterpreterInstance(last->getLine()); //-1);
393+
} else {
394+
--stepCount;
415395
#ifdef GDL_DEBUG
416-
std::cout << "stepCount-- = " << stepCount << std::endl;
396+
std::cout << "stepCount-- = " << stepCount << std::endl;
417397
#endif
418-
}
419-
}
420-
} else if (interruptEnable) {
421-
if (debugMode == DEBUG_PROCESS_STOP) DebugMsg(last, "Stepped to: ");
422-
debugMode = DEBUG_CLEAR;
423-
retCode = NewInterpreterInstance(last->getLine()); //-1);
424-
} else {
425-
retCode = RC_ABORT;
426-
}
398+
}
399+
}
400+
} else if (interruptEnable) {
401+
if (debugMode == DEBUG_PROCESS_STOP) DebugMsg(last, "Stepped to: ");
402+
debugMode = DEBUG_CLEAR;
403+
retCode = NewInterpreterInstance(last->getLine()); //-1);
404+
} else {
405+
if (debugMode == DEBUG_PROCESS_STOP) {
406+
debugMode = DEBUG_CLEAR;
407+
retCode = NewInterpreterInstance(last->getLine());
408+
} else {
409+
retCode = RC_ABORT;
410+
}
411+
}
427412
}
428413
return retCode;
429414

src/basic_pro_jmg.cpp

+71-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <string>
2222
#include <fstream>
2323
#include <limits>
24-
#include "gdleventhandler.hpp"
24+
#include "gdleventhandler.hpp" //for gdlwait_responsive
2525
#include "dinterpreter.hpp"
2626
#include "basic_pro_jmg.hpp"
2727

@@ -483,6 +483,76 @@ namespace lib {
483483
DllContainer::clear();
484484
}
485485

486+
//idem WAIT_PRO, but needed in idlneturl as we wait while some widgets events must happen.
487+
//should NEVER be used elsewhere (the idlneturl.pro procedure should disappear in favor of a pure C/C++ use of the CURL library)
488+
//The real WAIT blocks absolutely anything --- as it should.
489+
void gdlwait_responsive(EnvT* e) {
490+
e->NParam(1); //, "WAIT");
491+
492+
DDouble waittime;
493+
e->AssureDoubleScalarPar(0, waittime);
494+
495+
if (waittime < 0)
496+
throw GDLException(e->CallingNode(),
497+
"WAIT: Argument must be non-negative"
498+
+ e->GetParString(0));
499+
500+
#ifdef _WIN32
501+
LARGE_INTEGER Frequency;
502+
LARGE_INTEGER BeginTime;
503+
LARGE_INTEGER Endtime;
504+
LARGE_INTEGER elapsed;
505+
LARGE_INTEGER waittime_us;
506+
waittime_us.QuadPart = waittime * 1e6;
507+
508+
QueryPerformanceFrequency(&Frequency);
509+
QueryPerformanceCounter(&BeginTime);
510+
511+
while (1) {
512+
QueryPerformanceCounter(&Endtime);
513+
elapsed.QuadPart = (Endtime.QuadPart - BeginTime.QuadPart) / (Frequency.QuadPart / 1000000);
514+
if (elapsed.QuadPart >= waittime_us.QuadPart) break;
515+
else if (elapsed.QuadPart > 100) Sleep(80);
516+
}
517+
#else
518+
int old_version = 0;
519+
520+
if (waittime <= 0.005) old_version = 1;
521+
522+
// AC 2010-09-16
523+
// this version is OK and very accurate for small durations
524+
// but used 100% of one CPU :((
525+
if (old_version == 1) {
526+
struct timeval tval;
527+
struct timezone tzone;
528+
529+
// derivated from the current version of SYSTIME()
530+
gettimeofday(&tval, &tzone);
531+
double t_start = tval.tv_sec + tval.tv_usec / 1e+6; // time in UTC seconds
532+
double t_current = 0.0;
533+
534+
double diff = 0.0;
535+
while (diff < waittime) {
536+
537+
gettimeofday(&tval, &tzone);
538+
t_current = tval.tv_sec + tval.tv_usec / 1e+6;
539+
diff = t_current - t_start;
540+
}
541+
}
542+
543+
// AC 2010-09-16 this version should used much less CPU !
544+
if (old_version == 0) {
545+
//cout << floor(waittime) << " " << waittime-floor(waittime) << endl;
546+
struct timespec tv;
547+
tv.tv_sec = floor(waittime);
548+
tv.tv_nsec = (waittime - floor(waittime))*1e9;
549+
int retval;
550+
retval = nanosleep(&tv, NULL);
551+
}
552+
#endif
553+
GDLEventHandler(); //this is probably not OK, but is at the moment needed to permit delivery of callback functions in idlneturl__define.pro where a waiting loop uses teh WAIT command.
554+
}
555+
486556
void wait_pro( EnvT* e)
487557
{
488558
e->NParam( 1);//, "WAIT");
@@ -548,7 +618,6 @@ namespace lib {
548618
retval=nanosleep(&tv,NULL);
549619
}
550620
#endif
551-
GDLEventHandler(); //this is probably not OK, but is at the moment needed to permit delivery of callback functions in idlneturl__define.pro where a waiting loop uses teh WAIT command.
552621
}
553622

554623

src/basic_pro_jmg.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace lib {
3535
void unlinksymbol( EnvT* e );
3636
void ResetDLLs( void );
3737
void wait_pro( EnvT* e);
38+
void gdlwait_responsive( EnvT* e);
3839

3940
void kwtest( EnvT* e);
4041

src/devicewx.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,8 @@ if(hide) {
231231
return gcFunction;
232232
}
233233

234-
DLongGDL* GetScreenSize(char* disp) {
235-
DLongGDL* res;
236-
res = new DLongGDL(2, BaseGDL::NOZERO);
234+
DIntGDL* GetScreenSize(char* disp) {
235+
DIntGDL* res = new DIntGDL(2, BaseGDL::NOZERO);
237236
(*res)[0] = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
238237
(*res)[1] = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);
239238
return res;

src/devicex.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ class DeviceX : public GraphicsMultiDevice {
182182
return gcFunction;
183183
}
184184

185-
DLongGDL* GetScreenSize(char* disp) {
185+
DIntGDL* GetScreenSize(char* disp) {
186186
Display* display = XOpenDisplay(disp);
187187
int screen_num, screen_width, screen_height;
188-
DLongGDL* res;
189188

190189
if (display == NULL) {
191190
screen_width = 0;
@@ -196,7 +195,7 @@ class DeviceX : public GraphicsMultiDevice {
196195
screen_height = DisplayHeight(display, screen_num);
197196
XCloseDisplay(display);
198197
}
199-
res = new DLongGDL(2, BaseGDL::NOZERO);
198+
DIntGDL* res = new DIntGDL(2, BaseGDL::NOZERO);
200199
(*res)[0]= screen_width;
201200
(*res)[1]= screen_height;
202201
return res;

src/devicez.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class DeviceZ: public GraphicsDevice
220220
memBuffer[i] = bColor;
221221
}
222222

223-
DLong GetPixelDepth() { return 24;}
223+
DInt GetPixelDepth() { return 24;}
224224

225225
bool SetPixelDepth(DInt value) {
226226
static int displayed=0;

src/dpro.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class DLibFunRetNewTP: public DLibFun
318318
bool RetConstant() { return this->retConstant;}
319319
};
320320
// direct call functions must have:
321-
// ony one parameter, no keywords
321+
// only one parameter, no keywords
322322
// these functions are called "direct", no environment is created
323323
class DLibFunDirect: public DLibFunRetNew
324324
{

0 commit comments

Comments
 (0)