DavidKinder / Inform6

The latest version of the Inform 6 compiler, used for generating interactive fiction games.
http://inform-fiction.org/
Other
199 stars 32 forks source link

Conditional compilation fails inside property value array #254

Open ByteProject opened 8 months ago

ByteProject commented 8 months ago

I am setting up my next game to conditionally compile as a standard edition and an extended cut. To maintain a single codebase, I've set up a constant which flags code I want to trigger via conditional compilation. This does not work when I want to adapt it to an value array of a property. This is the code I have (note the code in-between #ifdef and #endif).

code

And this is what I get when compiling.

compiler_error

Here is a bigger portion of the code with line numbers for context.

code_big

curiousdannii commented 8 months ago

Please post the code directly rather than as images.

ByteProject commented 8 months ago

This is a commercial game which is not yet released, so I am not able to provide the full source that would allow an easy reproduction of the bug (I strongly assume this is a compiler bug). The screenshots were rather meant to give the maintainers of the compiler a general idea about the issue. However, here is the code for the first room, where the screenshots are taken from. This uses PunyInform as a library with Puny's cheap_scenery extension.


Room GreatHall "Great Hall" ! -- locations start here
  with name 'great' 'hall' 'manor' 'blackwood' 'living' 'room' 'exit' 'white' 'layer',
      description [;
        print "Flames dance in the fireplace and wood crackles as it burns slowly, giving off a pleasant warmth. Flickering light wanders across the walls, engulfing the shadows and illuminating the room in a melancholy twilight. In one corner, just below the gallery of ancestors, stands a beautifully decorated Christmas tree. Through the large windows you can see ";
        if (PROGRESS_LEVEL == 0) print "a snowstorm raging, the wind is howling as waves of snowflakes streak by.";
        else print "the manor's feral garden and the surrounding forest blanketed in a white layer.";
        print " The only exit is to the north, leading to the vestibule.";
        if (self hasnt visited) {
          ChangeFgColour(CLR_EMPHASIS_FG); 
          print "^^[Welcome to Ghosts of Blackwood Manor. To learn more about how to play the game, type HELP. First time players should also type ABOUT.]";
          ChangeFgColour(CLR_DEFAULT_FG);
        }
        new_line; ],
      n_to Vestibule,
      cheap_scenery 
          #ifdef EXTENDEDCUT;
          22 'cosy' 'victorian' 'interior' 'furniture' "Just as one would imagine an old country house to be. The lovingly handcrafted pieces of furniture do not seem to be replicas, although you first assumed so because they are in impeccable condition. Witnesses of a bygone era with an inestimable value."
          #endif;
          8 'fireplace' 'fire' 'wood' 'flames' 'warmth' 'twilight' 'shadows' 'light' "For a second you lose yourself in the flames, immersed in the eternal struggle between darkness and light. How many generations must have warmed themselves here over the centuries? What were their worries, their hardships, as they lingered within these venerable walls? For a brief moment we shine brighter than the morning star, but when the Grim Reaper knocks on our door, he leads us back to the infinite gloom from which we once emerged."
          54 'beautifully' 'christmas' 'xmas' 'decorated' 'scottish' 'fir' 'decorations' 'corner' 'tree' "The tree, a Scottish fir, looks wonderful in its red and white Christmas decorations. Cora has really outdone herself this year."
          CS_ADD_LIST GreatHall (cheap_scenery_pt2),
        cheap_scenery_pt2
          14 'large' 'windows' 'window' 'pane' 'panes' 
          [;
            Examine:
              if (PROGRESS_LEVEL == 0) print_ret (string)MESS_STORM;
              "You stand at the window, peering out into the winter landscape beyond. The world outside is covered in a thick blanket of snow.";
          ]
          11 'feral' 'garden' "You definitely have to take care of the garden next spring. It has apparently been neglected a bit in the last few years, but it is not completely overgrown."
          11 'surrounding' 'forest' "The adjacent forest surely holds many secrets, some of which may one day be rediscovered, others will remain hidden forever, buried and forgotten witnesses to a dark past.",
  has light;

Constant MESS_STORM "The window panes rattle from the force of the storm. Heavy snowflakes swirl in the air and blanket the manor's feral garden and the surrounding forest in a white layer.";````
erkyrath commented 8 months ago

This is confirmed but it is a "functioning as (currently) designed" situation.

#ifdef directives (etc) can fall between statements; they can fall between property declarations in an object; but they cannot fall between array elements.

(This is true both of object property arrays and top-level Array declarations.)

It's a reasonable feature to ask about! I think it would be a matter of calling get_next_token_with_directives() instead of get_next_token() in key spots. But it would require a lot of testing to get nailed down.

erkyrath commented 8 months ago

In the meantime, this is legal:

      #ifdef EXTENDEDCUT;
      cheap_scenery 
          22 'cosy' 'victorian' 'interior' 'furniture' "Just as one would imagine an old country house to be. The lovingly handcrafted pieces of furniture do not seem to be replicas, although you first assumed so because they are in impeccable condition. Witnesses of a bygone era with an inestimable value."
          8 'fireplace' 'fire' 'wood' 'flames' 'warmth' 'twilight' 'shadows' 'light' "For a second you lose yourself in the flames, immersed in the eternal struggle between darkness and light. How many generations must have warmed themselves here over the centuries? What were their worries, their hardships, as they lingered within these venerable walls? For a brief moment we shine brighter than the morning star, but when the Grim Reaper knocks on our door, he leads us back to the infinite gloom from which we once emerged."
          54 'beautifully' 'christmas' 'xmas' 'decorated' 'scottish' 'fir' 'decorations' 'corner' 'tree' "The tree, a Scottish fir, looks wonderful in its red and white Christmas decorations. Cora has really outdone herself this year."
          CS_ADD_LIST GreatHall (cheap_scenery_pt2),
      #ifnot;
      cheap_scenery 
          8 'fireplace' 'fire' 'wood' 'flames' 'warmth' 'twilight' 'shadows' 'light' "For a second you lose yourself in the flames, immersed in the eternal struggle between darkness and light. How many generations must have warmed themselves here over the centuries? What were their worries, their hardships, as they lingered within these venerable walls? For a brief moment we shine brighter than the morning star, but when the Grim Reaper knocks on our door, he leads us back to the infinite gloom from which we once emerged."
          54 'beautifully' 'christmas' 'xmas' 'decorated' 'scottish' 'fir' 'decorations' 'corner' 'tree' "The tree, a Scottish fir, looks wonderful in its red and white Christmas decorations. Cora has really outdone herself this year."
          CS_ADD_LIST GreatHall (cheap_scenery_pt2),
      #endif;
ByteProject commented 8 months ago

Ah yes, that is a good workaround. I'd love to see the feature make its way into the compiler. If you need someone for testing, please let me know. I am happy to help!