info-sather
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fixes for GNU Sather 1.2.2


From: Sather User
Subject: Fixes for GNU Sather 1.2.2
Date: Thu, 18 Jun 2009 03:01:07 +0930 (CST)

I have appended to this message diffs which can be applied to GNU
Sather-1.2.2 to allow it to build and test successfully on 32 and
64-bit machines.

Mostly they are just fixes for bugs that slept under the carpet while
C ints and longs were the same size.

But the changes include word-size-specific tests in int_test.sa.
E.g. INT::nil goes from -2147483648 on 32bit to -9223372036854775808
on 64 bit.  The "correct answer" to the test changes, depending on the
word size.

M4 is used to make a substitution, producing the file Library/
System/sys_word.sa which contains the word size as a Sather constant.

I suggest you avoid GNU Sather-1.2.3 and apply the patches to 1.2.2.

Here are the differences between 1.2.2 and 1.2.3, other than copyright
changes.  I.e. these are the differences in actual code.

$ diff -r -U0 -x GPL -x LGPL sather-1.2.2 sather -1.2.3 | \
  grep -v 000000000 | grep -v license | grep -v @@ | \
  grep -v '^diff' | grep -v Free | grep -v Binary
-
\ No newline at end of file
+
+GNU Sather 1.2.3 - Jul 7, 2007 - Michael R. Taylor
+
+* Made INT 32-bit even on 64-bit systems
+
+-----------------------------------------------------------------
+
-       $(MAKE) -C Test testfull
+       $(MAKE) -C Test test-full
-typedef long INT;
-#define SUINT_MAX ULONG_MAX
-#define SINT_MAX LONG_MAX
-#define SINT_MIN LONG_MIN
+typedef int INT;
+#define SUINT_MAX UINT_MAX
+#define SINT_MAX INT_MAX
+#define SINT_MIN INT_MIN
-1.2.2
\ No newline at end of file
+1.2.3

That's it, folks.  But Sather has only one size of INT.  Therefore the
designers of the language made it equivalent to a C long.  It makes no
sense for maintainers to decide it is going to be a C int from now on.
Perhaps it is a great achievement to make "INT 32-bit even on 64-bit
systems", but I don't see it.

I think it would be good practice to avoid mixing code and
copyright/license diffs.  Perhaps the few changes above can be edited
out of the 1.2.3 source code.  Then the diffs below could be applied
to that version, and 1.2.3 could be purely a vehicle for the license
change.

I don't use GNU Sather.  I don't like it.  I've adapted these changes
from "my" version, based on ICSI Sather 1.2b, which has remained under
the Sather license.

The terms of that license require a comment to appear wherever the
code has been changed.  The GNU licence doesn't require that AFAIK.
You can put these diffs under it, and remove the comments and initials
that are still there.

Snip out the above 1.2.2-1.2.3 diffs before applying this message as a
patch.

Regards,
Mike

==================================================================
diff -NaurBbw sather-1.2.2/Library/Base/int.config 
gnu_sather32+64-1.2.2/Library/Base/int.config
--- sather-1.2.2/Library/Base/int.config        1999-07-26 00:06:27.000000000 
+0930
+++ gnu_sather32+64-1.2.2/Library/Base/int.config       2009-06-17 
17:32:29.000000000 +0930
@@ -49,7 +49,7 @@
 INT_FLTX:      PP,VSTD,exec "$$=(FLT)$0;" "$$";
 INT_FLTDX:     PP,VSTD,exec "$$=(FLT)$0;" "$$";
 INT_CHAR:      PP,VSTD,exec "$$=(CHAR)$0;" "$$";
-INT_C_UNSIGNED_INT:    PP,VSTD,exec "$$=(unsigned int)$0;" "$$";
+INT_C_UNSIGNED_INT:    PP,VSTD,exec "$$=(long unsigned int)$0;" "$$";
 INT_INT:       PP,exec "$0";
 INT_ABS:       PP,VSTD,exec "$$=($0<0)?-$0:$0;" "$$";
 INT_SQUARE:    APP,VSTD,exec "$$=INTTIMES($0,$0);" "$$";
@@ -63,19 +63,19 @@
 INT_UTIMES:    APP,VSTD,exec "$$=INTUTIMES($0,$1);" "$$";
 INT_UDIV:      FPP,VSTD,exec "$$=INTUDIV($0,$1);" "$$";
 INT_UMOD:      FPP,VSTD,exec "$$=INTUMOD($0,$1);" "$$";
-INT_MPLUS:     PP,VSTD,exec "$$=((unsigned)$0+(unsigned)$1);" "$$";
-INT_MMINUS:    PP,VSTD,exec "$$=((unsigned)$0-(unsigned)$1);" "$$";
-INT_MNEGATE:   PP,VSTD,exec "$$=(-(unsigned)$0);" "$$";
-INT_MTIMES:    PP,VSTD,exec "$$=((unsigned)$0*(unsigned)$1);" "$$";
-INT_MDIV:      FPP,VSTD,exec "$$=((unsigned)$0/(unsigned)$1);" "$$";
-INT_MMOD:      FPP,VSTD,exec "$$=((unsigned)$0%%(unsigned)$1);" "$$";
+INT_MPLUS:     PP,VSTD,exec "$$=((long unsigned int)$0+(long unsigned 
int)$1);" "$$";
+INT_MMINUS:    PP,VSTD,exec "$$=((long unsigned int)$0-(long unsigned 
int)$1);" "$$";
+INT_MNEGATE:   PP,VSTD,exec "$$=(-(long unsigned int)$0);" "$$";
+INT_MTIMES:    PP,VSTD,exec "$$=((long unsigned int)$0*(long unsigned 
int)$1);" "$$";
+INT_MDIV:      FPP,VSTD,exec "$$=((long unsigned int)$0/(long unsigned 
int)$1);" "$$";
+INT_MMOD:      FPP,VSTD,exec "$$=((long unsigned int)$0%%(long unsigned 
int)$1);" "$$";
 INT_BNOT:      PP,VSTD,exec "$$=~$0;" "$$";
 INT_BAND:      PP,VSTD,exec "$$=$0&$1;" "$$";
 INT_BOR:       PP,VSTD,exec "$$=$0|$1;" "$$";
 INT_BXOR:      PP,VSTD,exec "$$=$0\\^$1;" "$$";
-INT_LSHIFT:    PP,VSTD,exec "$$=((unsigned)$0)<<((unsigned)$1);" "$$";
+INT_LSHIFT:    PP,VSTD,exec "$$=((long unsigned int)$0)<<((long unsigned 
int)$1);" "$$";
 INT_RSHIFT:    PP,VSTD,exec "$$=INTRSHIFT($0,$1);" "$$";
-INT_URSHIFT:   PP,VSTD,exec "$$=((unsigned)$0)>>((unsigned)$1);" "$$";
+INT_URSHIFT:   PP,VSTD,exec "$$=((long unsigned int)$0)>>((long unsigned 
int)$1);" "$$";
 INT_CREATE_STR:        FPP,VSTD,exec "$$=atoi(((STR)$1)->arr_part);" "$$";
 INT_AGET:      PP,VSTD,exec "$$=((CHAR)(($0&(1<<$1))!=0));" "$$";
 INT_ASET:      PP,VSTD,exec "$$=((($0)&(~(1<<($1))))|(($2)<<($1)));" "$$";
diff -NaurBbw sather-1.2.2/Library/Base/int.sa 
gnu_sather32+64-1.2.2/Library/Base/int.sa
--- sather-1.2.2/Library/Base/int.sa    1999-07-26 00:06:27.000000000 +0930
+++ gnu_sather32+64-1.2.2/Library/Base/int.sa   2009-06-17 20:36:16.000000000 
+0930
@@ -36,7 +36,8 @@
    -- include AVAL{BOOL} asize->;


-   const asize:INT:=32;
+   -- MTW Jun 2009: Change '32' to actual word size
+   const asize:INT:=SYS_WORD::size;
    -- Size in bits.

    -- Signed operations:
diff -NaurBbw sather-1.2.2/Library/Base/int_test.sa 
gnu_sather32+64-1.2.2/Library/Base/int_test.sa
--- sather-1.2.2/Library/Base/int_test.sa       1999-07-26 00:06:27.000000000 
+0930
+++ gnu_sather32+64-1.2.2/Library/Base/int_test.sa      2009-06-17 
19:37:11.000000000 +0930
@@ -22,20 +22,35 @@
       b ::= 7;
       tp: FSTR := #;
       restp ::= 1101.str_in(tp,10,8,'#');
-      test("1101.str_in",restp,"######2115");
+      test("1101.str_in oct",restp,"######2115");
       tp2: FSTR := #;
       restp2 ::= 1101.str_in(tp2,10,16,'#');
-      test("1101.str_in(hex)",restp2,"#######44D");
+      test("1101.str_in hex",restp2,"#######44D");
+
+      if SYS_WORD::size = 32 then
       tp3: FSTR := #;
       restp3 ::= INT::nil.str_in(tp3,12,10,'#');
-      test("nil.str_in(10)",restp3,"#-2147483648");
+        test("nil.str_in dec",restp3,"#-2147483648");

       tp4: FSTR := #;
       restp4 ::= INT::nil.str_in(tp4,12,16,'#');
-      test("nil.str_in(16)",restp4,"###-80000000");
+        test("nil.str_in hex",restp4,"###-80000000");
       tp5: FSTR := #;
       restp5 ::= INT::nil.str_in(tp5,16,8,'#');
-      test("nil.str_in(16)",restp5,"####-20000000000");
+        test("nil.str_in oct",restp5,"####-20000000000");
+      end;
+
+      if SYS_WORD::size = 64 then
+        tp := #;
+        restp3 ::= INT::nil.str_in(tp,21,10,'#');
+        test("nil.str_in dec",restp3,"#-9223372036854775808");
+        tp := #;
+        restp4 ::= INT::nil.str_in(tp,21,16,'#');
+        test("nil.str_in hex",restp4,"####-8000000000000000");
+        tp := #;
+        restp5 ::= INT::nil.str_in(tp,27,8,'#');
+        test("nil.str_in oct",restp5,"####-1000000000000000000000");
+      end;

       val ::= a.plus(b);
       test("plus",val.str,"12");
diff -NaurBbw sather-1.2.2/Library/System/System.module 
gnu_sather32+64-1.2.2/Library/System/System.module
--- sather-1.2.2/Library/System/System.module   1999-07-26 00:06:34.000000000 
+0930
+++ gnu_sather32+64-1.2.2/Library/System/System.module  2009-06-17 
17:46:31.000000000 +0930
@@ -42,6 +42,9 @@

     runtime.sa -has runtime.sa RUNTIME
     sys.sa -has sys.sa SYS
+    -- MTW added sys_word.sa Jun 2009
+    -has sys_word.sa SYS_WORD
+
     test.sa -has test.sa TEST TEST_TEST

     time.sa -has time.sa TIME TIMES MEMORY_USAGE
diff -NaurBbw sather-1.2.2/Library/System/sys_word.sa.m4 
gnu_sather32+64-1.2.2/Library/System/sys_word.sa.m4
--- sather-1.2.2/Library/System/sys_word.sa.m4  1970-01-01 09:30:00.000000000 
+0930
+++ gnu_sather32+64-1.2.2/Library/System/sys_word.sa.m4 2009-06-17 
17:38:45.000000000 +0930
@@ -0,0 +1,8 @@
+---------------------------> Sather 1.1 source file <--------------------------
+-- sys_word.sa.m4 by M. Talbot-Wilson
+-- The top-level Makefile generates sys_word.sa from it.
+--
+class SYS_WORD is
+   -- computer word size (bits)
+   const size:INT:=__WORDSIZE
+end;
diff -NaurBbw sather-1.2.2/Makefile gnu_sather32+64-1.2.2/Makefile
--- sather-1.2.2/Makefile       2005-05-21 07:05:54.000000000 +0930
+++ gnu_sather32+64-1.2.2/Makefile      2009-06-18 00:22:22.000000000 +0930
@@ -31,6 +31,7 @@
 CP=cp

 CPP=/lib/cpp -C -P
+CPPP=/lib/cpp -P
 CC=gcc
 EXEC_SUFFIX=
 # CC is only used for bootstrapping, check System/Common/CONFIG.proto if
@@ -46,6 +47,7 @@
 #EXEC_SUFFIX=.exe

 # The name of the produced binaries
+CS = sacomp
 SACOMP      =Bin/sacomp$(EXEC_SUFFIX)
 SACOMP-BOOT =Boot/sacomp$(EXEC_SUFFIX)    # This has to be changed lateron
 SABROWSE    =Bin/sabrowse$(EXEC_SUFFIX)
@@ -125,12 +127,18 @@
 # This runs the C compiles after the Sather compiler instead of at
 # the same time, to ease installation for those with small VM.

-compiler: system bootcompiler
+compiler: wordsize system bootcompiler
        @echo; echo "Creating C for installation compiler..." ; echo
        $(SACOMP-BOOT) $(CS_OPT) Compiler/sacomp.module -o $(SACOMP) -only_C
        @echo; echo "Compiling C for installation compiler..." ; echo
        $(MAKE) -C $(SACOMP).code

+.PHONY: wordsize
+wordsize:
+       cd Library/System && \
+       m4 -D __WORDSIZE=$$(echo $$(echo __WORDSIZE \
+       | $(CPPP) -include bits/wordsize.h)) sys_word.sa.m4 >sys_word.sa
+
 optional: bootcompiler
        @echo "*************************************************************"
        @echo "        Trying to compile the optional Browser and Gui"
@@ -177,11 +185,11 @@
        $(SACOMP-BOOT) $(CS_OPT_DEBUG) Compiler/sacomp.module -o $(SACOMP) 
-only_C
        $(MAKE) -C $(SACOMP).code

-profile:
+profile: wordsize
        $(SACOMP-BOOT) $(CS_OPT_PROFILE) Compiler/sacomp.module -o $(SACOMP) 
-only_C
        $(MAKE) -C cd $(SACOMP).code

-bootcompiler: system
+bootcompiler: wordsize system
        @echo; echo "Making boot compiler..." ; echo
        $(MAKE) -C System/Platforms/$(BOOT_PLATFORM) boot CC='$(CC)'

@@ -233,7 +241,7 @@
 #    2. Compile using result.

 testfull:
-       $(MAKE) -C Test testfull
+       $(MAKE) -C Test test-full


 ################################### CLEANING ##################################
@@ -256,6 +264,7 @@
        $(RM) -r Doc/man/{whatis,cat1,windex}
        $(RM) Emacs/*.elc
        $(RM) Emacs/*.info Emacs/*.info??
+       $(RM) Library/System/sys_word.sa
        $(RM) Library/System/Socket/socket.sa
        $(RM) Library/Containers/stack.sa
        $(RM) Library/Containers/nr_stack.sa
@@ -263,5 +272,6 @@
        $(RM) Library/Containers/nr_a_stack.sa
        $(RM) pLibrary/Containers/nr_stack.sa
        $(RM) pLibrary/Containers/nr_a_stack.sa
+       cd Boot/$(CS).code ; $(RM) *.o

        debian/rules clean-safe
diff -NaurBbw sather-1.2.2/System/Common/runtime.h 
gnu_sather32+64-1.2.2/System/Common/runtime.h
--- sather-1.2.2/System/Common/runtime.h        1999-11-04 05:18:17.000000000 
+1030
+++ gnu_sather32+64-1.2.2/System/Common/runtime.h       2009-06-17 
20:08:11.000000000 +0930
@@ -252,11 +252,11 @@
  * # define INTDIV(x,y)     (x>=0||x%y?x/y:y>0?x/y-1:x/y+1)
  * # define INTMOD(x,y)     (x%y>=0?x%y:y<0?x%y-y:x%y+y)
  */
-# define INTUPLUS(x,y)   ((unsigned)x)+((unsigned)y)
-# define INTUMINUS(x,y)  ((unsigned)x)-((unsigned)y)
-# define INTUTIMES(x,y)  ((unsigned)x)*((unsigned)y)
-# define INTUDIV(x,y)    ((unsigned)x)/((unsigned)y)
-# define INTUMOD(x,y)    ((unsigned)x)%((unsigned)y)
+# define INTUPLUS(x,y)   ((unsigned long)x)+((unsigned long)y)
+# define INTUMINUS(x,y)  ((unsigned long)x)-((unsigned long)y)
+# define INTUTIMES(x,y)  ((unsigned long)x)*((unsigned long)y)
+# define INTUDIV(x,y)    ((unsigned long)x)/((unsigned long)y)
+# define INTUMOD(x,y)    ((unsigned long)x)%((unsigned long)y)
 # define INTFLT(x)       (FLT)x
 # define INTFLTD(x)      (FLTD)x
 # define INTRSHIFT(x,s)  (x<0)?x>>s:(~((~x)>>s))
@@ -271,8 +271,8 @@
  * then please contribute a special case for your platform!
 */

-#define INTPLUS(x,y)    
CHKOK(((y>=0&&x<=(SINT_MAX-y))||(y<0&&x>=((signed)(((unsigned)SINT_MIN)-y)))),"Integer
 overflow on plus",x+y)
-#define INTMINUS(x,y)   
CHKOK(((y>=0&&x>=(SINT_MIN+y))||(y<0&&x<=((signed)(((unsigned)SINT_MAX)+y)))),"Integer
 overflow on minus",x-y)
+#define INTPLUS(x,y)    
CHKOK(((y>=0&&x<=(SINT_MAX-y))||(y<0&&x>=((long)(((unsigned 
long)SINT_MIN)-y)))),"Integer overflow on plus",x+y)
+#define INTMINUS(x,y)   
CHKOK(((y>=0&&x>=(SINT_MIN+y))||(y<0&&x<=((long)(((unsigned 
long)SINT_MAX)+y)))),"Integer overflow on minus",x-y)
 #define INTTIMES(x,y)   
CHKOK(((x==0)||(y==0)||(x>0&&y>0&&y<=SINT_MAX/x)||(x>0&&y<0&&y>=SINT_MIN/x)||(x<0&&y>0&&x>=SINT_MIN/y)||(x<0&&y<0&&x!=SINT_MIN&&y!=SINT_MIN&&-x<=SINT_MAX/(-y))),"Integer
 overflow on times",x*y)
 #define INTDIV(x,y)     CHKOK(y!=0,"Division by 
zero",((x<0&&x!=(x/y)*y)?(x/y)-1:(x/y)))
 #define INTMOD(x,y)     CHKOK(y!=0,"Mod by zero",((x%y)<0)?(x%y)+y:(x%y))
@@ -280,11 +280,11 @@
  * #define INTDIV(x,y)     CHKOK(y!=0,"Division by 
zero",(x>=0||x%y?x/y:y>0?x/y-1:x/y+1))
  * #define INTMOD(x,y)     CHKOK(y!=0,"Mod by 
zero",(x%y>=0?x%y:y<0?x%y-y:x%y+y))
  */
-#define INTUPLUS(x,y)   CHKOK(x<=(SUINT_MAX-y),"Integer overflow on unsigned 
plus",((unsigned)x)+((unsigned)y))
-#define INTUMINUS(x,y)  CHKOK(y<=x,"Integer overflow on unsigned 
minus",((unsigned)x)-((unsigned)y))
-#define INTUTIMES(x,y)  CHKOK((x==0)||(y<=SUINT_MAX/x),"Integer overflow on 
unsigned times",((unsigned)x)*((unsigned)y))
-#define INTUDIV(x,y)    CHKOK(y!=0,"Integer unsigned division by 
zero",((unsigned)x)/((unsigned)y))
-#define INTUMOD(x,y)    CHKOK(y!=0,"Integer unsigned mod by 
zero",((unsigned)x)%((unsigned)y))
+#define INTUPLUS(x,y)   CHKOK(x<=(SUINT_MAX-y),"Integer overflow on unsigned 
plus",((unsigned long)x)+((unsigned long)y))
+#define INTUMINUS(x,y)  CHKOK(y<=x,"Integer overflow on unsigned 
minus",((unsigned long)x)-((unsigned long)y))
+#define INTUTIMES(x,y)  CHKOK((x==0)||(y<=SUINT_MAX/x),"Integer overflow on 
unsigned times",((unsigned long)x)*((unsigned long)y))
+#define INTUDIV(x,y)    CHKOK(y!=0,"Integer unsigned division by 
zero",((unsigned long)x)/((unsigned long)y))
+#define INTUMOD(x,y)    CHKOK(y!=0,"Integer unsigned mod by zero",((unsigned 
long)x)%((unsigned long)y))
 #define INTFLT(x)       CHKOK(((INT)((FLT)x))==x,"Integer would overflow 
conversion to FLT",(FLT)x)
 #define INTFLTD(x)      CHKOK(((INT)((FLTD)x))==x,"Integer would overflow 
conversion to FLTD",(FLTD)x)
 #define INTRSHIFT(x,s)  (x<0)?x>>s:(~((~x)>>s))


-- 
Michael Talbot-Wilson




reply via email to

[Prev in Thread] Current Thread [Next in Thread]