pdxiv / sk2sadat

Convert ScottKit to Scott Adams DAT format
GNU General Public License v2.0
1 stars 1 forks source link

Add optional incompatible language extension: named flags #10

Open pdxiv opened 3 years ago

pdxiv commented 3 years ago

It would be useful to be able to name flags and not have to keep track of numbers.. For instance in The Count, flag #2 is used to signify "sleep", and it would make the code easier to understand if the command set_flag 2 could instead (optionally) be written as set_flag sleep.

This extended behavior should be possible to activate using a commandline switch like --skplus (or something like that).

It would not require you to explicitly define which flag number corresponds to what flag “name” and it would all be handled “under the hood”. This is how I would probably do it:

Initially, when parsing a source code file you would have a “flag reservation table” that’s predefined to look like this:

           0 => 0
          15 => 15
      "dark" => 15
          16 => 16
"empty_lamp" => 16

When an action/occurrence containing flag statements is encountered, entries are added to this table.

occur
    set_flag 3
    set_flag sleep

…and the “flag reservation table” would look like this:

           0 => 0
          15 => 15
      "dark" => 15
          16 => 16
"empty_lamp" => 16
           3 => 3
     "sleep" => undefined

Once all the actions have been read, all the “undefined” values in the table will be assigned the first unique available value, and the final table would look like this:

           0 => 0
          15 => 15
      "dark" => 15
          16 => 16
"empty_lamp" => 16
           3 => 3
     "sleep" => 1

When the time comes to translate the code to an old-fashioned Scott Adams DAT file, any instances of “sleep” will be translated to “1”.

Possibly, flag 0 should be possible to utilize freely for allocations, unless commands set_flag0 or clear_flag0 have been used in any actions.