Update to commit a469d404a7dc4e87e18f367eb4d8e05fc32d20a7
[inform.git] / src / veneer.c
index d32ad40c125db1e0460160e8e22cce81e24f235b..ce29ceb566e464cc261c5460417fd202540693c5 100644 (file)
@@ -3,8 +3,8 @@
 /*              by the compiler (e.g. DefArt) which the program doesn't      */
 /*              provide                                                      */
 /*                                                                           */
-/*   Part of Inform 6.35                                                     */
-/*   copyright (c) Graham Nelson 1993 - 2021                                 */
+/*   Part of Inform 6.40                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2022                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -17,7 +17,7 @@
 /* GNU General Public License for more details.                              */
 /*                                                                           */
 /* You should have received a copy of the GNU General Public License         */
-/* along with Inform. If not, see https://gnu.org/licenses/                  *
+/* along with Inform. If not, see https://gnu.org/licenses/                  */
 /*                                                                           */
 /* ------------------------------------------------------------------------- */
 
@@ -27,7 +27,7 @@ int veneer_mode;                      /*  Is the code currently being
                                           compiled from the veneer?          */
 
 static debug_locations null_debug_locations =
-    { { 0, 0, 0, 0, 0, 0, 0 }, NULL, 0 };
+    { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, NULL, 0 };
 
 extern void compile_initial_routine(void)
 {
@@ -36,6 +36,10 @@ extern void compile_initial_routine(void)
         (since the interpreter begins execution with an empty stack frame):
         and it must "quit" rather than "return".
 
+        (Pedantically, in Z-code 1-5, this is not a routine at all. It's
+        a sequence of opcodes which ends with "quit". The one-byte
+        header generated by assemble_routine_header() is a dummy.)
+
         In order not to impose these restrictions on "Main", we compile a
         trivial routine consisting of a call to "Main" followed by "quit".   */
 
@@ -46,8 +50,8 @@ extern void compile_initial_routine(void)
     assign_symbol(j,
         assemble_routine_header(0, FALSE, "Main__", FALSE, j),
         ROUTINE_T);
-    sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
-    if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
+    symbols[j].flags |= SYSTEM_SFLAG + USED_SFLAG;
+    if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
 
     if (!glulx_mode) {
 
@@ -2182,28 +2186,42 @@ extern assembly_operand veneer_routine(int code)
     return(AO);
 }
 
+extern char *veneer_routine_name(int code)
+{
+    if (code < 0 || code >= VENEER_ROUTINES) {
+        return "???";
+    }
+    if (!glulx_mode) {
+        return VRs_z[code].name;
+    }
+    else {
+        return VRs_g[code].name;
+    }
+}
+
 static void compile_symbol_table_routine(void)
 {   int32 j, nl, arrays_l, routines_l, constants_l;
     assembly_operand AO, AO2, AO3;
 
     /* Assign local var names for the benefit of the debugging information 
-       file. */
-    local_variable_texts[0] = "dummy1";
-    local_variable_texts[1] = "dummy2";
+       file. (We don't set local_variable.keywords because we're not
+       going to be parsing any code.) */
+    strcpy(local_variable_names[0].text, "dummy1");
+    strcpy(local_variable_names[1].text, "dummy2");
 
     veneer_mode = TRUE; j = symbol_index("Symb__Tab", -1);
     assign_symbol(j,
         assemble_routine_header(2, FALSE, "Symb__Tab", FALSE, j),
         ROUTINE_T);
-    sflags[j] |= SYSTEM_SFLAG + USED_SFLAG;
-    if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
+    symbols[j].flags |= SYSTEM_SFLAG + USED_SFLAG;
+    if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
 
   if (!glulx_mode) {
 
     if (define_INFIX_switch == FALSE)
     {   assemblez_0(rfalse_zc);
-        variable_usage[1] = TRUE;
-        variable_usage[2] = TRUE;
+        variables[1].usage = TRUE;
+        variables[2].usage = TRUE;
         assemble_routine_end(FALSE, null_debug_locations);
         veneer_mode = FALSE;
         return;
@@ -2238,16 +2256,16 @@ static void compile_symbol_table_routine(void)
             nl = next_label++;
             sequence_point_follows = FALSE;
             assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
-            AO3.value = array_sizes[j];
+            AO3.value = arrays[j].size;
             AO3.marker = 0;
             assemblez_store(temp_var2, AO3);
-            AO3.value = array_types[j];
-            if (sflags[array_symbols[j]] & (INSF_SFLAG+SYSTEM_SFLAG))
+            AO3.value = arrays[j].type;
+            if (symbols[arrays[j].symbol].flags & (INSF_SFLAG+SYSTEM_SFLAG))
                 AO3.value = AO3.value + 16;
             AO3.marker = 0;
             assemblez_store(temp_var3, AO3);
-            AO3.value = svals[array_symbols[j]];
-            AO3.marker = (!array_locs[j] ? ARRAY_MV : STATIC_ARRAY_MV);
+            AO3.value = symbols[arrays[j].symbol].value;
+            AO3.marker = (!arrays[j].loc ? ARRAY_MV : STATIC_ARRAY_MV);
             assemblez_1(ret_zc, AO3);
             assemble_label_no(nl);
         }
@@ -2263,11 +2281,11 @@ static void compile_symbol_table_routine(void)
         sequence_point_follows = FALSE;
         assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
         AO3.value = 0;
-        if (sflags[named_routine_symbols[j]]
+        if (symbols[named_routine_symbols[j]].flags
             & (INSF_SFLAG+SYSTEM_SFLAG)) AO3.value = 16;
         AO3.marker = 0;
         assemblez_store(temp_var3, AO3);
-        AO3.value = svals[named_routine_symbols[j]];
+        AO3.value = symbols[named_routine_symbols[j]].value;
         AO3.marker = IROUTINE_MV;
         assemblez_1(ret_zc, AO3);
         assemble_label_no(nl);
@@ -2277,9 +2295,9 @@ static void compile_symbol_table_routine(void)
 
     assemble_label_no(constants_l);
     for (j=0, no_named_constants=0; j<no_symbols; j++)
-    {   if (((stypes[j] == OBJECT_T) || (stypes[j] == CLASS_T)
-            || (stypes[j] == CONSTANT_T))
-            && ((sflags[j] & (UNKNOWN_SFLAG+ACTION_SFLAG))==0))
+    {   if (((symbols[j].type == OBJECT_T) || (symbols[j].type == CLASS_T)
+            || (symbols[j].type == CONSTANT_T))
+            && ((symbols[j].flags & (UNKNOWN_SFLAG+ACTION_SFLAG))==0))
         {   AO2.value = no_named_constants++;
             if (AO2.value<256) AO2.type = SHORT_CONSTANT_OT;
             else AO2.type = LONG_CONSTANT_OT;
@@ -2287,9 +2305,9 @@ static void compile_symbol_table_routine(void)
             sequence_point_follows = FALSE;
             assemblez_2_branch(je_zc, AO, AO2, nl, FALSE);
             AO3.value = 0;
-            if (stypes[j] == OBJECT_T) AO3.value = 2;
-            if (stypes[j] == CLASS_T) AO3.value = 1;
-            if (sflags[j] & (INSF_SFLAG+SYSTEM_SFLAG))
+            if (symbols[j].type == OBJECT_T) AO3.value = 2;
+            if (symbols[j].type == CLASS_T) AO3.value = 1;
+            if (symbols[j].flags & (INSF_SFLAG+SYSTEM_SFLAG))
                 AO3.value = AO3.value + 16;
             AO3.marker = 0;
             assemblez_store(temp_var3, AO3);
@@ -2303,8 +2321,8 @@ static void compile_symbol_table_routine(void)
 
     sequence_point_follows = FALSE;
     assemblez_0(rfalse_zc);
-    variable_usage[1] = TRUE;
-    variable_usage[2] = TRUE;
+    variables[1].usage = TRUE;
+    variables[2].usage = TRUE;
     assemble_routine_end(FALSE, null_debug_locations);
     veneer_mode = FALSE;
   }
@@ -2312,8 +2330,8 @@ static void compile_symbol_table_routine(void)
 
     if (define_INFIX_switch == FALSE)
     {   assembleg_1(return_gc, zero_operand);
-        variable_usage[1] = TRUE;
-        variable_usage[2] = TRUE;
+        variables[1].usage = TRUE;
+        variables[2].usage = TRUE;
         assemble_routine_end(FALSE, null_debug_locations);
         veneer_mode = FALSE;
         return;
@@ -2348,7 +2366,7 @@ extern void compile_veneer(void)
         for (i=0; i<VENEER_ROUTINES; i++)
         {   if (veneer_routine_needs_compilation[i] == VR_CALLED)
             {   j = symbol_index(VRs[i].name, -1);
-                if (sflags[j] & UNKNOWN_SFLAG)
+                if (symbols[j].flags & UNKNOWN_SFLAG)
                 {   veneer_mode = TRUE;
                     strcpy(veneer_source_area, VRs[i].source1);
                     strcat(veneer_source_area, VRs[i].source2);
@@ -2361,18 +2379,18 @@ extern void compile_veneer(void)
                             VRs[i].name, TRUE, j),
                         ROUTINE_T);
                     veneer_mode = FALSE;
-                    if (trace_fns_setting==3) sflags[j] |= STAR_SFLAG;
+                    if (trace_fns_setting==3) symbols[j].flags |= STAR_SFLAG;
                 }
                 else
-                {   if (stypes[j] != ROUTINE_T)
+                {   if (symbols[j].type != ROUTINE_T)
                 error_named("The following name is reserved by Inform for its \
 own use as a routine name; you can use it as a routine name yourself (to \
 override the standard definition) but cannot use it for anything else:",
                         VRs[i].name);
                     else
-                        sflags[j] |= USED_SFLAG;
+                        symbols[j].flags |= USED_SFLAG;
                 }
-                veneer_routine_address[i] = svals[j];
+                veneer_routine_address[i] = symbols[j].value;
                 veneer_routine_needs_compilation[i] = VR_COMPILED;
                 try_veneer_again = TRUE;
             }