GoTo Confused With Var Access in Scripts

Reporter: RobertBColton  |  Status: open  |  Last Modified: May 07, 2019, 09:42:41 AM

What I am reporting here is an issue pointed out to me by @DARKSTAR2 over Discord. goto is only working in object events and not scripts due to a parsing issue. For some reason, JDI is converting the label identifiers into a var access causing compile to fail. It's possible that some of sorlok's changes in #912 may be related as I notice that he did change how variables are collected with respect to goto.

goto my_special_label;
return 0;

my_special_label:
show_message("hello!");
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h: In function 'variant _SCR_scr_0(variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant, variant)':
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:41:16: error: expected ';' before '::' token
     goto enigma::varaccess_my_special_label(int(self));
                ^~
                ;
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:41:18: error: '::varaccess_my_special_label' has not been declared
     goto enigma::varaccess_my_special_label(int(self));
                  ^~~~~~~~~~~~~~~~~~~~~~~~~~
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:41:18: note: suggested alternative:
In file included from SHELLmain.cpp:105:
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectaccess.h:52:9: note:   'enigma::varaccess_my_special_label'
   var  &varaccess_my_special_label(int x)
         ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from SHELLmain.cpp:106:
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:43:50: error: expected ';' before ':' token
     enigma::varaccess_my_special_label(int(self)):
                                                  ^
                                                  ;
C:/Users/Owner/AppData/Local/ENIGMA/Preprocessor_Environment_Editable/IDE_EDIT_objectfunctionality.h:41:10: error: label 'enigma' used but not defined
     goto enigma::varaccess_my_special_label(int(self));
          ^~~~~~
RobertBColton  
I tested reverting #912 and it didn't change a thing.
RobertBColton  

This still occurs with the newer JDI that #1659 just merged.
JoshDreamland  

It's important to recognize that JDI is just the C++ comprehension layer. This is what I'm always bitching at fundies about. JDI interprets C++, so if a function or type is not known to ENIGMA, that is likely a JDI problem. But all other parsing concerns are a problem with ENIGMA's EDL parser/syntax checker.

This can be confusing, because adding a semicolon to the wrong place can be either. It could be ENIGMA not recognizing a declaration because JDI mis-reported a type, or it could be the parser just shitting the bed. After new JDI has been merged, it will be much more likely to be the latter.

In this case, it's pretty obviously a parser problem. The parser isn't classifying labelname: as a label in scripts. This makes sense to me, as it's not something I programmed it to do. It wouldn't be all that hard to fix, but:

  1. The current parser is what we'll call "sunsetting." At the point where I'm literally maintaining a C++ compiler, there's no excuse to outsource any parsing responsibilities to GCC. The EDL comprehension layer should be what Rusky wanted it to be way back in the day.

  2. Use of goto is frowned upon in every programming community. I'm not super sad we broke it somehow. Chances are, whatever you're doing with goto is better accomplished with a break statement or a conditional. This isn't always the case, which is why I attempted to leave goto in the language. But other export languages (such as JavaScript) don't support goto, so it's better that we drop support for it early.

fundies  

  • It's your fault for we call compiler JDI because you have no branding on it. Come up with a name for the compiler because when you say compiler error or bug you think GCC.

  • I see you use goto in c++. Even in JDI :P

  • RobertBColton  

    I found a workaround that makes it work if you just want to use it. Declare your label as a var, that stops JDI from adding the varaccess stuff. Works for me on master.

    var my_special_label;
    goto my_special_label;
    return 0;
    
    my_special_label:
    show_message("hello!");

    Please sign in to post comments, or you can view this issue on GitHub.