Browse Source

* I hope, the case bug is fixed now

florian 27 years ago
parent
commit
438de2d913
2 changed files with 49 additions and 17 deletions
  1. 28 16
      compiler/cg386set.pas
  2. 21 1
      compiler/types.pas

+ 28 - 16
compiler/cg386set.pas

@@ -500,6 +500,12 @@ implementation
           begin
           begin
              if assigned(t^.less) then
              if assigned(t^.less) then
                genitem(t^.less);
                genitem(t^.less);
+             { need we to test the first value }
+             if first and (t^._low>get_min_value(p^.left^.resulttype)) then
+               begin
+                  exprasmlist^.concat(new(pai386,op_const_reg(A_CMP,opsize,t^._low,hregister)));
+                  emitl(jmp_le,elselabel);
+               end;
              if t^._low=t^._high then
              if t^._low=t^._high then
                begin
                begin
                   if t^._low-last=1 then
                   if t^._low-last=1 then
@@ -519,34 +525,37 @@ implementation
                   { ELSE-label                                      }
                   { ELSE-label                                      }
                   if first then
                   if first then
                     begin
                     begin
-                       if t^._low-1=1 then
-                         exprasmlist^.concat(new(pai386,op_reg(A_DEC,opsize,
-                           hregister)))
-                       else if t^._low-1=0 then
-                         exprasmlist^.concat(new(pai386,op_reg_reg(A_OR,opsize,
-                           hregister,hregister)))
-                       else
-                         exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,
-                           t^._low-1,hregister)));
+                       { have we to ajust the first value ?}
+                       if t^._low>get_min_value(p^.left^.resulttype) then
+                         begin
+                            if t^._low=1 then
+                              exprasmlist^.concat(new(pai386,op_reg(A_DEC,opsize,
+                                hregister)))
+                            else
+                              exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,
+                                t^._low,hregister)));
+                         end;
                        { work around: if the lower range=0 and we
                        { work around: if the lower range=0 and we
                          do the subtraction we have to take care
                          do the subtraction we have to take care
                          of the sign!
                          of the sign!
-                       }
+                       this isn't necessary, this is tested before now (FK)
                        if t^._low=0 then
                        if t^._low=0 then
                          emitl(A_JBE,elselabel)
                          emitl(A_JBE,elselabel)
                        else
                        else
-                         emitl(jmp_lee,elselabel);
+                       emitl(jmp_lee,elselabel);
+                       }
                     end
                     end
+                  else
                   { if there is no unused label between the last and the }
                   { if there is no unused label between the last and the }
                   { present label then the lower limit can be checked    }
                   { present label then the lower limit can be checked    }
                   { immediately. else check the range in between:        }
                   { immediately. else check the range in between:        }
-                  else if (t^._low-last>1)then
+                  if (t^._low-last>1) then
                     begin
                     begin
                        if t^._low-last-1=1 then
                        if t^._low-last-1=1 then
                          exprasmlist^.concat(new(pai386,op_reg(A_DEC,opsize,hregister)))
                          exprasmlist^.concat(new(pai386,op_reg(A_DEC,opsize,hregister)))
                        else
                        else
                          exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,t^._low-last-1,hregister)));
                          exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,t^._low-last-1,hregister)));
-                       emitl(jmp_lee,elselabel);
+                       emitl(jmp_le,elselabel);
                     end;
                     end;
                   exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,t^._high-t^._low+1,hregister)));
                   exprasmlist^.concat(new(pai386,op_const_reg(A_SUB,opsize,t^._high-t^._low+1,hregister)));
                   emitl(jmp_lee,t^.statement);
                   emitl(jmp_lee,t^.statement);
@@ -713,8 +722,8 @@ implementation
                   { a linear list is always smaller than a jump tree }
                   { a linear list is always smaller than a jump tree }
                      genlinearlist(p^.nodes)
                      genlinearlist(p^.nodes)
                    else
                    else
-                          { if the labels less or more a continuum then }
-                          genjumptable(p^.nodes,min_label,max_label);
+                  { if the labels less or more a continuum then }
+                     genjumptable(p^.nodes,min_label,max_label);
                 end
                 end
               else
               else
                 begin
                 begin
@@ -775,7 +784,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.13  1998-09-07 18:45:54  peter
+  Revision 1.14  1998-09-09 16:44:21  florian
+    * I hope, the case bug is fixed now
+
+  Revision 1.13  1998/09/07 18:45:54  peter
     * update smartlinking, uses getdatalabel
     * update smartlinking, uses getdatalabel
     * renamed ptree.value vars to value_str,value_real,value_set
     * renamed ptree.value vars to value_str,value_real,value_set
 
 

+ 21 - 1
compiler/types.pas

@@ -34,6 +34,9 @@ unit types;
     { returns true, if def defines an ordinal type }
     { returns true, if def defines an ordinal type }
     function is_ordinal(def : pdef) : boolean;
     function is_ordinal(def : pdef) : boolean;
 
 
+    { returns the min. value of the type }
+    function get_min_value(def : pdef) : longint;
+
     { returns true, if def defines an ordinal type }
     { returns true, if def defines an ordinal type }
     function is_integer(def : pdef) : boolean;
     function is_integer(def : pdef) : boolean;
 
 
@@ -178,6 +181,20 @@ unit types;
          end;
          end;
       end;
       end;
 
 
+    { returns the min. value of the type }
+    function get_min_value(def : pdef) : longint;
+
+      begin
+         case def^.deftype of
+            orddef:
+                get_min_value:=porddef(def)^.low;
+            enumdef:
+                get_min_value:=penumdef(def)^.min;
+         else
+            get_min_value:=0;
+         end;
+      end;
+
 
 
     { true if p is an integer }
     { true if p is an integer }
     function is_integer(def : pdef) : boolean;
     function is_integer(def : pdef) : boolean;
@@ -902,7 +919,10 @@ unit types;
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.27  1998-09-07 17:37:07  florian
+  Revision 1.28  1998-09-09 16:44:23  florian
+    * I hope, the case bug is fixed now
+
+  Revision 1.27  1998/09/07 17:37:07  florian
     * first fixes for published properties
     * first fixes for published properties
 
 
   Revision 1.26  1998/09/04 12:24:31  florian
   Revision 1.26  1998/09/04 12:24:31  florian