浏览代码

* Sets are now internally sets.

daniel 23 年之前
父节点
当前提交
3a134c6e07
共有 8 个文件被更改,包括 104 次插入134 次删除
  1. 37 66
      compiler/nadd.pas
  2. 9 3
      compiler/ncgcon.pas
  3. 8 6
      compiler/ncgset.pas
  4. 10 14
      compiler/ncnv.pas
  5. 13 28
      compiler/ncon.pas
  6. 5 2
      compiler/node.pas
  7. 8 8
      compiler/nset.pas
  8. 14 7
      compiler/ptconst.pas

+ 37 - 66
compiler/nadd.pas

@@ -92,7 +92,7 @@ implementation
          htype   : ttype;
          ot      : tnodetype;
          concatstrings : boolean;
-         resultset : pconstset;
+         resultset : Tconstset;
          i       : longint;
          b       : boolean;
          s1,s2   : pchar;
@@ -472,80 +472,48 @@ implementation
                  left:=nil;
                  exit;
                end;
-              new(resultset);
               case nodetype of
                  addn :
-                   begin
-                      for i:=0 to 31 do
-                        resultset^[i]:=tsetconstnode(right).value_set^[i] or tsetconstnode(left).value_set^[i];
-                      t:=csetconstnode.create(resultset,left.resulttype);
-                   end;
+		    begin
+			resultset:=tsetconstnode(right).value_set^ + tsetconstnode(left).value_set^;
+                        t:=csetconstnode.create(@resultset,left.resulttype);
+		    end;
                  muln :
-                   begin
-                      for i:=0 to 31 do
-                        resultset^[i]:=tsetconstnode(right).value_set^[i] and tsetconstnode(left).value_set^[i];
-                      t:=csetconstnode.create(resultset,left.resulttype);
-                   end;
+		    begin
+			resultset:=tsetconstnode(right).value_set^ * tsetconstnode(left).value_set^;
+                        t:=csetconstnode.create(@resultset,left.resulttype);
+		    end;
                  subn :
-                   begin
-                      for i:=0 to 31 do
-                        resultset^[i]:=tsetconstnode(left).value_set^[i] and not(tsetconstnode(right).value_set^[i]);
-                      t:=csetconstnode.create(resultset,left.resulttype);
-                   end;
+		    begin
+			resultset:=tsetconstnode(right).value_set^ - tsetconstnode(left).value_set^;
+                        t:=csetconstnode.create(@resultset,left.resulttype);
+		    end;
                  symdifn :
-                   begin
-                      for i:=0 to 31 do
-                        resultset^[i]:=tsetconstnode(left).value_set^[i] xor tsetconstnode(right).value_set^[i];
-                      t:=csetconstnode.create(resultset,left.resulttype);
-                   end;
+                    begin
+			resultset:=tsetconstnode(right).value_set^ >< tsetconstnode(left).value_set^;
+            		t:=csetconstnode.create(@resultset,left.resulttype);
+                    end;
                  unequaln :
-                   begin
-                      b:=true;
-                      for i:=0 to 31 do
-                       if tsetconstnode(right).value_set^[i]=tsetconstnode(left).value_set^[i] then
-                        begin
-                          b:=false;
-                          break;
-                        end;
-                      t:=cordconstnode.create(ord(b),booltype);
-                   end;
+                    begin
+			b:=tsetconstnode(right).value_set^ <> tsetconstnode(left).value_set^;
+            		t:=cordconstnode.create(byte(b),booltype);
+                    end;
                  equaln :
-                   begin
-                      b:=true;
-                      for i:=0 to 31 do
-                       if tsetconstnode(right).value_set^[i]<>tsetconstnode(left).value_set^[i] then
-                        begin
-                          b:=false;
-                          break;
-                        end;
-                      t:=cordconstnode.create(ord(b),booltype);
-                   end;
+                    begin
+			b:=tsetconstnode(right).value_set^ = tsetconstnode(left).value_set^;
+            		t:=cordconstnode.create(byte(b),booltype);
+                    end;
                  lten :
-                   begin
-                     b := true;
-                     For i := 0 to 31 Do
-                       If (tsetconstnode(right).value_set^[i] And tsetconstnode(left).value_set^[i]) <>
-                           tsetconstnode(left).value_set^[i] Then
-                         Begin
-                           b := false;
-                           Break
-                         End;
-                     t := cordconstnode.create(ord(b),booltype);
-                   End;
+                    begin
+			b:=tsetconstnode(right).value_set^ <= tsetconstnode(left).value_set^;
+            		t:=cordconstnode.create(byte(b),booltype);
+                    end;
                  gten :
-                   Begin
-                     b := true;
-                     For i := 0 to 31 Do
-                       If (tsetconstnode(left).value_set^[i] And tsetconstnode(right).value_set^[i]) <>
-                           tsetconstnode(right).value_set^[i] Then
-                         Begin
-                           b := false;
-                           Break
-                         End;
-                     t := cordconstnode.create(ord(b),booltype);
-                   End;
+                    begin
+			b:=tsetconstnode(right).value_set^ >= tsetconstnode(left).value_set^;
+            		t:=cordconstnode.create(byte(b),booltype);
+                    end;
               end;
-              dispose(resultset);
               result:=t;
               exit;
            end;
@@ -1664,7 +1632,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.54  2002-07-20 11:57:53  florian
+  Revision 1.55  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.54  2002/07/20 11:57:53  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 9 - 3
compiler/ncgcon.pas

@@ -390,6 +390,9 @@ implementation
          lastlabel   : tasmlabel;
          i         : longint;
          neededtyp   : tait;
+      type
+         setbytes=array[0..31] of byte;
+	 Psetbytes=^setbytes;
       begin
         { small sets are loaded as constants }
         if tsetdef(resulttype.def).settype=smallset then
@@ -420,7 +423,7 @@ implementation
                              i:=0;
                              while assigned(hp1) and (i<32) do
                               begin
-                                if tai_const(hp1).value<>value_set^[i] then
+                                if tai_const(hp1).value<>Psetbytes(value_set)^[i] then
                                  break;
                                 inc(i);
                                 hp1:=tai(hp1.next);
@@ -467,7 +470,7 @@ implementation
                  else
                   begin
                     for i:=0 to 31 do
-                      Consts.concat(Tai_const.Create_8bit(value_set^[i]));
+                      Consts.concat(Tai_const.Create_8bit(Psetbytes(value_set)^[i]));
                   end;
                end;
           end;
@@ -519,7 +522,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.13  2002-07-20 11:57:53  florian
+  Revision 1.14  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.13  2002/07/20 11:57:53  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 8 - 6
compiler/ncgset.pas

@@ -137,11 +137,10 @@ implementation
          pushedregs : tmaybesave;
          l,l2,l3       : tasmlabel;
 
-         function analizeset(Aset:pconstset;is_small:boolean):boolean;
-           type
-             byteset=set of byte;
+         function analizeset(const Aset:Tconstset;is_small:boolean):boolean;
            var
              compares,maxcompares:word;
+	     
              i:byte;
            begin
              analizeset:=false;
@@ -160,7 +159,7 @@ implementation
              if is_small then
               maxcompares:=3;
              for i:=0 to 255 do
-              if i in byteset(Aset^) then
+              if i in Aset then
                begin
                  if (numparts=0) or (i<>setparts[numparts].stop+1) then
                   begin
@@ -209,7 +208,7 @@ implementation
 
          { Can we generate jumps? Possible for all types of sets }
          genjumps:=(right.nodetype=setconstn) and
-                   analizeset(tsetconstnode(right).value_set,use_small);
+                   analizeset(Tsetconstnode(right).value_set^,use_small);
          { calculate both operators }
          { the complex one first }
          firstcomplex(self);
@@ -571,7 +570,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.7  2002-07-21 16:58:20  jonas
+  Revision 1.8  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.7  2002/07/21 16:58:20  jonas
     * fixed some bugs in tcginnode.pass_2() and optimized the bit test
 
   Revision 1.6  2002/07/20 11:57:54  florian

+ 10 - 14
compiler/ncnv.pas

@@ -207,7 +207,7 @@ implementation
         buildp,
         p2,p3,p4    : tnode;
         htype       : ttype;
-        constset    : pconstset;
+        constset    : Pconstset;
         constsetlo,
         constsethi  : longint;
 
@@ -238,22 +238,15 @@ implementation
         end;
 
         procedure do_set(pos : longint);
-        var
-          mask,l : longint;
+
         begin
-          if (pos>255) or (pos<0) then
+          if (pos and not $ff)<>0 then
            Message(parser_e_illegal_set_expr);
           if pos>constsethi then
            constsethi:=pos;
           if pos<constsetlo then
            constsetlo:=pos;
-          { to do this correctly we use the 32bit array }
-          l:=pos shr 5;
-          mask:=1 shl (pos mod 32);
-          { do we allow the same twice }
-          if (pconst32bitset(constset)^[l] and mask)<>0 then
-           Message(parser_e_illegal_set_expr);
-          pconst32bitset(constset)^[l]:=pconst32bitset(constset)^[l] or mask;
+	  include(constset^,pos);
         end;
 
       var
@@ -263,8 +256,8 @@ implementation
       begin
         if p.nodetype<>arrayconstructorn then
          internalerror(200205105);
-        new(constset);
-        FillChar(constset^,sizeof(constset^),0);
+	new(constset);
+	constset^:=[];
         htype.reset;
         constsetlo:=0;
         constsethi:=0;
@@ -1758,7 +1751,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.61  2002-07-20 17:16:02  florian
+  Revision 1.62  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.61  2002/07/20 17:16:02  florian
     + source code page support
 
   Revision 1.60  2002/07/20 11:57:54  florian

+ 13 - 28
compiler/ncon.pas

@@ -253,17 +253,10 @@ implementation
 
     function is_emptyset(p : tnode):boolean;
 
-      var
-        i : longint;
-      begin
-        i:=0;
-        if p.nodetype=setconstn then
-         begin
-           while (i<32) and (tsetconstnode(p).value_set^[i]=0) do
-            inc(i);
-         end;
-        is_emptyset:=(i=32);
-      end;
+    begin
+        is_emptyset:=(p.nodetype=setconstn) and 
+	 (Tsetconstnode(p).value_set^=[]);
+    end;
 
 
     function genconstsymtree(p : tconstsym) : tnode;
@@ -641,22 +634,11 @@ implementation
       end;
 
     function tsetconstnode.docompare(p: tnode): boolean;
-      var
-        i: 0..31;
-      begin
-        if inherited docompare(p) then
-          begin
-            for i := 0 to 31 do
-              if (value_set^[i] <> tsetconstnode(p).value_set^[i]) then
-                begin
-                  docompare := false;
-                  exit
-                end;
-            docompare := true;
-          end
-        else
-          docompare := false;
-      end;
+
+    begin
+	docompare:=(inherited docompare(p))
+	 and (value_set^=Tsetconstnode(p).value_set^);
+    end;
 
 {*****************************************************************************
                                TNILNODE
@@ -733,7 +715,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.35  2002-07-20 11:57:54  florian
+  Revision 1.36  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.35  2002/07/20 11:57:54  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 5 - 2
compiler/node.pas

@@ -35,7 +35,7 @@ interface
 
     type
        pconstset = ^tconstset;
-       tconstset = array[0..31] of byte;
+       tconstset = set of 0..255;
        pconst32bitset = ^tconst32bitset;
        tconst32bitset = array[0..7] of longint;
 
@@ -823,7 +823,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.31  2002-07-21 06:58:49  daniel
+  Revision 1.32  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.31  2002/07/21 06:58:49  daniel
   * Changed booleans into flags
 
   Revision 1.30  2002/07/19 11:41:36  daniel

+ 8 - 8
compiler/nset.pas

@@ -176,8 +176,7 @@ implementation
 
 
     function tinnode.det_resulttype:tnode;
-      type
-        byteset = set of byte;
+
       var
         t : tnode;
         pst : pconstset;
@@ -195,16 +194,14 @@ implementation
                 pes:=tenumsym(tenumdef(psd.elementtype.def).firstenum);
                 while assigned(pes) do
                   begin
-                    pcs^[pes.value div 8]:=pcs^[pes.value div 8] or (1 shl (pes.value mod 8));
+		    include(pcs^,pes.value);
                     pes:=pes.nextenum;
                   end;
               end;
             orddef :
               begin
                 for i:=torddef(psd.elementtype.def).low to torddef(psd.elementtype.def).high do
-                  begin
-                    pcs^[i div 8]:=pcs^[i div 8] or (1 shl (i mod 8));
-                  end;
+		    include(pcs^,i);
               end;
           end;
           createsetconst:=pcs;
@@ -261,7 +258,7 @@ implementation
          { constant evaulation }
          if (left.nodetype=ordconstn) and (right.nodetype=setconstn) then
           begin
-            t:=cordconstnode.create(byte(tordconstnode(left).value in byteset(tsetconstnode(right).value_set^)),booltype);
+            t:=cordconstnode.create(byte(tordconstnode(left).value in Tsetconstnode(right).value_set^),booltype);
             resulttypepass(t);
             result:=t;
             exit;
@@ -578,7 +575,10 @@ begin
 end.
 {
   $Log$
-  Revision 1.27  2002-07-20 11:57:55  florian
+  Revision 1.28  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.27  2002/07/20 11:57:55  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added

+ 14 - 7
compiler/ptconst.pas

@@ -80,6 +80,10 @@ implementation
          strval    : pchar;
          pw        : pcompilerwidestring;
          error     : boolean;
+	 
+      type
+         setbytes = array[0..31] of byte;
+	 Psetbytes = ^setbytes;
 
       procedure check_range(def:torddef);
         begin
@@ -440,8 +444,8 @@ implementation
 
                         if source_info.endian = target_info.endian then
                           begin
-                            for l:= 0 to p.resulttype.def.size-1 do
-                               curconstsegment.concat(tai_const.create_8bit(tsetconstnode(p).value_set^[l]));
+                            for l:=0 to p.resulttype.def.size-1 do
+                               curconstsegment.concat(tai_const.create_8bit(Psetbytes(tsetconstnode(p).value_set)^[l]));
                           end
                         else
                           begin
@@ -449,10 +453,10 @@ implementation
                             j:=0;
                             for l:=0 to ((p.resulttype.def.size-1) div 4) do
                               begin
-                                curconstsegment.concat(tai_const.create_8bit(tsetconstnode(p).value_set^[j+3]));
-                                curconstsegment.concat(tai_const.create_8bit(tsetconstnode(p).value_set^[j+2]));
-                                curconstsegment.concat(tai_const.create_8bit(tsetconstnode(p).value_set^[j+1]));
-                                curconstsegment.concat(tai_const.create_8bit(tsetconstnode(p).value_set^[j]));
+                                curconstsegment.concat(tai_const.create_8bit(Psetbytes(tsetconstnode(p).value_set)^[j+3]));
+                                curconstsegment.concat(tai_const.create_8bit(Psetbytes(tsetconstnode(p).value_set)^[j+2]));
+                                curconstsegment.concat(tai_const.create_8bit(Psetbytes(tsetconstnode(p).value_set)^[j+1]));
+                                curconstsegment.concat(tai_const.create_8bit(Psetbytes(tsetconstnode(p).value_set)^[j]));
                                 Inc(j,4);
                               end;
                           end;
@@ -971,7 +975,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.51  2002-07-20 11:57:56  florian
+  Revision 1.52  2002-07-22 11:48:04  daniel
+  * Sets are now internally sets.
+
+  Revision 1.51  2002/07/20 11:57:56  florian
     * types.pas renamed to defbase.pas because D6 contains a types
       unit so this would conflicts if D6 programms are compiled
     + Willamette/SSE2 instructions to assembler added