@@ -81,38 +81,22 @@ GDLInterpreter::GDLInterpreter()
81
81
82
82
try { // for error handling
83
83
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;
103
99
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
- // }
116
100
117
101
// The following code (up to afterStatement is never executed - here only because ANTLR code needs it, although it should not (not optimized parser)
118
102
@@ -358,72 +342,73 @@ GDLInterpreter::GDLInterpreter()
358
342
}
359
343
}
360
344
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;
400
381
#ifdef GDL_DEBUG
401
- std::cout << " stepCount-- = " << stepCount << std::endl;
382
+ std::cout << " stepCount-- = " << stepCount << std::endl;
402
383
#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;
415
395
#ifdef GDL_DEBUG
416
- std::cout << " stepCount-- = " << stepCount << std::endl;
396
+ std::cout << " stepCount-- = " << stepCount << std::endl;
417
397
#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
+ }
427
412
}
428
413
return retCode;
429
414
0 commit comments