altos/scheme: Rework display/write code
[fw/altos] / src / scheme / ao_scheme_mem.c
index 3659d3ec4a7fa331312bc96f856183c071c148aa..a336fdfe964fccecf901405c0f0b05152a13538f 100644 (file)
@@ -623,6 +623,20 @@ ao_scheme_collect(uint8_t style)
                        top += size;
                }
 
+               /* Short-circuit the rest of the loop when all of the
+                * found objects aren't moving. This isn't strictly
+                * necessary as the rest of the loop is structured to
+                * work in this case, but GCC 7.2.0 with optimization
+                * greater than 2 generates incorrect code for this...
+                */
+               if (i == AO_SCHEME_NCHUNK) {
+                       chunk_low = chunk_high;
+#if DBG_MEM_STATS
+                       loops++;
+#endif
+                       continue;
+               }
+
                /*
                 * Limit amount of chunk array used in mapping moves
                 * to the active region
@@ -1047,7 +1061,7 @@ ao_scheme_print_mark_addr(void *addr)
 #endif
 
        if (!AO_SCHEME_IS_POOL(addr))
-               return 1;
+               return 0;
 
        if (!ao_scheme_print_cleared) {
                ao_scheme_print_cleared = 1;
@@ -1060,14 +1074,23 @@ ao_scheme_print_mark_addr(void *addr)
        return 0;
 }
 
-int
-ao_scheme_print_mark_poly(ao_poly p)
+void
+ao_scheme_print_clear_addr(void *addr)
 {
-       uint8_t type = ao_scheme_poly_base_type(p);
+       int     offset;
 
-       if (type == AO_SCHEME_INT)
-               return 1;
-       return ao_scheme_print_mark_addr(ao_scheme_ref(p));
+#if DBG_MEM
+       if (ao_scheme_collecting)
+               ao_scheme_abort();
+#endif
+
+       if (!AO_SCHEME_IS_POOL(addr))
+               return;
+
+       if (!ao_scheme_print_cleared)
+               return;
+       offset = pool_offset(addr);
+       clear(ao_scheme_busy, offset);
 }
 
 /* Notes that printing has started */
@@ -1077,11 +1100,13 @@ ao_scheme_print_start(void)
        ao_scheme_printing++;
 }
 
-/* Notes that printing has ended */
-void
+/* Notes that printing has ended. Returns 1 if printing is still going on */
+int
 ao_scheme_print_stop(void)
 {
        ao_scheme_printing--;
-       if (ao_scheme_printing == 0)
-               ao_scheme_print_cleared = 0;
+       if (ao_scheme_printing != 0)
+               return 1;
+       ao_scheme_print_cleared = 0;
+       return 0;
 }