Update to commit e33eef4f8fab800eaf4a32b2d159cde6c4bbb38e
[inform.git] / src / arrays.c
index fc4f7af2c5e6abb7f1f951920138bf7dbdfd991a..9c001ccb0ed57ec678f1c6542910ac257c8be8c2 100644 (file)
@@ -3,9 +3,8 @@
 /*               likewise global variables, which are in some ways a         */
 /*               simpler form of the same thing.                             */
 /*                                                                           */
-/* Copyright (c) Graham Nelson 1993 - 2020                                   */
-/*                                                                           */
-/* This file is part of Inform.                                              */
+/*   Part of Inform 6.35                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2021                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -95,6 +94,10 @@ extern void finish_array(int32 i, int is_static)
       area = static_array_area;
       area_size = static_array_area_size;
   }
+
+  if (i == 0) {
+      error("An array must have at least one entry");
+  }
   
     /*  Write the array size into the 0th byte/word of the array, if it's
         a "table" or "string" array                                          */
@@ -259,7 +262,7 @@ extern void array_entry(int32 i, int is_static, assembly_operand VAL)
 /*                                                                           */
 /*      | ->       |  <number-of-entries>                                    */
 /*      | -->      |  <entry-1> ... <entry-n>                                */
-/*      | string   |  [ <entry-1> [,] [;] <entry-2> ... <entry-n> ];         */
+/*      | string   |  [ <entry-1> [;] <entry-2> ... <entry-n> ];             */
 /*      | table                                                              */
 /*      | buffer                                                             */
 /*                                                                           */
@@ -289,6 +292,8 @@ extern void make_global(int array_flag, int name_only)
     int array_type, data_type;
     int is_static = FALSE;
     assembly_operand AO;
+    
+    int extraspace;
 
     int32 global_symbol;
     const char *global_name;
@@ -311,7 +316,7 @@ extern void make_global(int array_flag, int name_only)
             goto RedefinitionOfSystemVar;
     }
 
-    if ((token_type != SYMBOL_TT) || (!(sflags[i] & UNKNOWN_SFLAG)))
+    if (token_type != SYMBOL_TT)
     {   discard_token_location(beginning_debug_location);
         if (array_flag)
             ebf_error("new array name", token_text);
@@ -319,6 +324,14 @@ extern void make_global(int array_flag, int name_only)
         panic_mode_error_recovery(); return;
     }
 
+    if (!(sflags[i] & UNKNOWN_SFLAG))
+    {   discard_token_location(beginning_debug_location);
+        if (array_flag)
+            ebf_symbol_error("new array name", token_text, typename(stypes[i]), slines[i]);
+        else ebf_symbol_error("new global variable name", token_text, typename(stypes[i]), slines[i]);
+        panic_mode_error_recovery(); return;
+    }
+
     if ((!array_flag) && (sflags[i] & USED_SFLAG))
         error_named("Variable must be defined before use:", token_text);
 
@@ -514,21 +527,17 @@ extern void make_global(int array_flag, int name_only)
 
     /*  Leave room to write the array size in later, if string/table array   */
     
-    int extraspace = 0;
+    extraspace = 0;
     if ((array_type==STRING_ARRAY) || (array_type==TABLE_ARRAY))
         extraspace += array_entry_size;
     if (array_type==BUFFER_ARRAY)
         extraspace += WORDSIZE;
-
-    int orig_area_size;
     
     if (!is_static) {
-        orig_area_size = dynamic_array_area_size;
         array_base = dynamic_array_area_size;
         dynamic_array_area_size += extraspace;
     }
     else {
-        orig_area_size = static_array_area_size;
         array_base = static_array_area_size;
         static_array_area_size += extraspace;
     }
@@ -544,8 +553,8 @@ extern void make_global(int array_flag, int name_only)
 
             CalculatedArraySize:
 
-            if (module_switch && (AO.marker != 0))
-            {   error("Array sizes must be known now, not externally defined");
+            if (AO.marker != 0)
+            {   error("Array sizes must be known now, not defined later");
                 break;
             }
 
@@ -682,12 +691,14 @@ advance as part of 'Zcharacter table':", unicode);
     finish_array(i, is_static);
 
     if (debugfile_switch)
-    {   debug_file_printf("<array>");
+    {
+        int32 new_area_size;
+        debug_file_printf("<array>");
         debug_file_printf("<identifier>%s</identifier>", global_name);
         debug_file_printf("<value>");
         write_debug_array_backpatch(svals[global_symbol]);
         debug_file_printf("</value>");
-        int32 new_area_size = (!is_static ? dynamic_array_area_size : static_array_area_size);
+        new_area_size = (!is_static ? dynamic_array_area_size : static_array_area_size);
         debug_file_printf
             ("<byte-count>%d</byte-count>",
              new_area_size - array_base);