Initial revision
This commit is contained in:
250
lang/cem/ctest/ctinit/init.c
Normal file
250
lang/cem/ctest/ctinit/init.c
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
||||
*
|
||||
* This product is part of the Amsterdam Compiler Kit.
|
||||
*
|
||||
* Permission to use, sell, duplicate or disclose this software must be
|
||||
* obtained in writing. Requests for such permissions may be sent to
|
||||
*
|
||||
* Dr. Andrew S. Tanenbaum
|
||||
* Wiskundig Seminarium
|
||||
* Vrije Universiteit
|
||||
* Postbox 7161
|
||||
* 1007 MC Amsterdam
|
||||
* The Netherlands
|
||||
*
|
||||
*/
|
||||
|
||||
/* Author: E.G. Keizer */
|
||||
|
||||
/* Test initialisation of a V7 C-compiler */
|
||||
/* 1 sept 1980 */
|
||||
#include "../local.h"
|
||||
|
||||
/* Integers and constant expressions */
|
||||
|
||||
int in1 = 4 ;
|
||||
int in2 = MAXINT ;
|
||||
int in3 = MININT ;
|
||||
int in4 ;
|
||||
int inzero ;
|
||||
|
||||
int ice1 = (1-2+3*4/2)%3 ;
|
||||
int ice2 = ((((1&3)|4)^014) >> 1) <<1 ;
|
||||
int ice3 = ( (1==2) & (3<4) ) | (4>3) | (0<=0) | -2>=17 ;
|
||||
int ice4 = (~-1) ;
|
||||
int ice5 = (1==1 ? 3+4 : 5+6 ) ;
|
||||
int ice6 = (1!=1 ? 7+8 : 9+10 ) ;
|
||||
int ina[] = { 1, 3, 5 } ;
|
||||
|
||||
pint() {
|
||||
static int sint = -1 ;
|
||||
int lint = in1+in3+sint ;
|
||||
|
||||
printf("Integers:\n\n") ;
|
||||
printf("in1\t%d\nin2\t%d\nin3\t%d\nin4\t%d\ninzero\t%d\n\n",
|
||||
in1,in2,in3,in4,inzero ) ;
|
||||
printf("ice1\t%d\nice2\t%d\nice3\t%d\nice4\t%d\nice5\t%d\nice6\t%d\n\n",
|
||||
ice1,ice2,ice3,ice4,ice5,ice6 ) ;
|
||||
printf("ina\t%d,%d,%d\n\n",ina[0],ina[1],ina[2]) ;
|
||||
printf("sint\t%d\nlint\t%d\n\n",sint,lint) ;
|
||||
}
|
||||
|
||||
/* Characters */
|
||||
|
||||
char ch1 = 'a' ;
|
||||
char ch2 ;
|
||||
char cha1[] = "Mesg" ;
|
||||
char cha2[] = "" ;
|
||||
char cha3[] = "1" ;
|
||||
char cha4[] = "12" ;
|
||||
char cha5[] = "0123456789112345678921234567893123456789412345678951234567896123456789712345678981234567899123456789" ;
|
||||
|
||||
char cha6[2][3] = {
|
||||
{ 1, 2, 3 },
|
||||
{ 4, 5, 6 }
|
||||
};
|
||||
char *pch1 = cha2 ;
|
||||
char *pch2 = "pch2" ;
|
||||
char *pch3 = "ppch3" ;
|
||||
char *pch4 = 0 ;
|
||||
|
||||
pch() {
|
||||
static char stc[] = "123" ;
|
||||
static char stc1[] = "1234" ;
|
||||
static char *mult[] = { "ab" , "bc" , "de" } ;
|
||||
|
||||
printf("Characters:\n\n") ;
|
||||
|
||||
printf("ch1\t%c(%d)\n",ch1,ch1) ;
|
||||
printf("ch2\t%d\n",ch2) ;
|
||||
printf("cha1\t%s\ncha2\t%s\ncha3\t%s\ncha4\t%s\n",
|
||||
cha1,cha2,cha3,cha4 ) ;
|
||||
printf("cha5\t%s\n\n",cha5) ;
|
||||
printf("cha6\t%d, %d, %d\n\t%d, %d, %d\n",
|
||||
cha6[0][0],cha6[0][1],cha6[0][2],cha6[1][0],cha6[1][1],cha6[1][2]);
|
||||
printf("pch1==cha2\t%s\n",(pch1 == cha2 ? "yes" : "no" ) ) ;
|
||||
printf("pch2\t%s\npch3\t%s\n",pch2,pch3+1) ;
|
||||
printf("pch4==0\t%s\n\n",(pch4 != 0 ? "no" : "yes" ) ) ;
|
||||
printf("stc\t%s\nstc1\t%s\n",stc,stc1) ;
|
||||
printf("mult[0],mult[1],mult[2] %s, %s, %s\n",mult[0],mult[1],mult[2]);
|
||||
}
|
||||
|
||||
/* floats */
|
||||
|
||||
float fl1 = 0 ;
|
||||
float fl2 = 2 ;
|
||||
float fl3 = 2e-10 ;
|
||||
float fl4 = 4.0 ;
|
||||
float fl5 = EPSFLOAT ;
|
||||
float fl6 = MAXFLOAT ;
|
||||
float fl7 ;
|
||||
|
||||
float fla1[4][3] = {
|
||||
{ 1, 3, 5 },
|
||||
{ 2, 4, 6 },
|
||||
{ 3, 5, 7 }
|
||||
} ;
|
||||
float fla2[4][3] = {
|
||||
-1,-3,-5,-2,-4,-6,-3,-5,-7
|
||||
} ;
|
||||
float fla3[4][3] = {
|
||||
{ 11 } , { 12 } , { 13 } , { 14 }
|
||||
} ;
|
||||
|
||||
pflt() {
|
||||
register i,j ;
|
||||
|
||||
printf("Floats:\n\n") ;
|
||||
|
||||
printf("fl1\t%.20e\nfl2\t%.20e\nfl2\t%.20e\nfl4\t%.20e\nfl5\t%.20e\nfl6\t%.20e\nfl7\t%.20e\n",
|
||||
fl1,fl2,fl2,fl4,fl5,fl6,fl7 ) ;
|
||||
|
||||
printf(" fla1 fla2 fla3\n") ;
|
||||
for ( i=0 ; i<4 ; i++ ) {
|
||||
for ( j=0 ; j<3 ; j++ ) {
|
||||
printf(" %20e %20e %20e\n",
|
||||
fla1[i][j],fla2[i][j],fla3[i][j]) ;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n") ;
|
||||
}
|
||||
|
||||
/* doubles */
|
||||
|
||||
double dbl1 = 0 ;
|
||||
double dbl2 = 2 ;
|
||||
double dbl3 = 2e-10 ;
|
||||
double dbl4 = 4.0 ;
|
||||
double dbl5 = EPSDOUBLE ;
|
||||
double dbl6 = MAXDOUBLE ;
|
||||
double dbl7 ;
|
||||
|
||||
double dbla1[4][3] = {
|
||||
{ 1, 3, 5 },
|
||||
{ 2, 4, 6 },
|
||||
{ 3, 5, 7 }
|
||||
} ;
|
||||
double dbla2[4][3] = {
|
||||
-1,-3,-5,-2,-4,-6,-3,-5,-7
|
||||
} ;
|
||||
double dbla3[4][3] = {
|
||||
{ 11 } , { 12 } , { 13 } , { 14 }
|
||||
} ;
|
||||
|
||||
pdbl() {
|
||||
register i,j ;
|
||||
|
||||
printf("Doubles:\n\n") ;
|
||||
|
||||
printf("dbl1\t%.20e\ndbl2\t%.20e\ndbl2\t%.20e\ndbl4\t%.20e\ndbl5\t%.20e\ndbl6\t%.20e\ndbl7\t%.20e\n",
|
||||
dbl1,dbl2,dbl2,dbl4,dbl5,dbl6,dbl7 ) ;
|
||||
|
||||
printf(" dbla1 dbla2 dbla3\n") ;
|
||||
for ( i=0 ; i<4 ; i++ ) {
|
||||
for ( j=0 ; j<3 ; j++ ) {
|
||||
printf(" %20e %20e %20e\n",
|
||||
dbla1[i][j],dbla2[i][j],dbla3[i][j]) ;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n") ;
|
||||
}
|
||||
|
||||
/* long */
|
||||
long lo1 = 14L ;
|
||||
long lo2 = -17 ;
|
||||
long lo3 = MAXLONG ;
|
||||
long lo4 = MINLONG ;
|
||||
long lo5 ;
|
||||
long lo6 = ( 0==1 ? -1L : 1L ) ;
|
||||
|
||||
plong() {
|
||||
printf("long\n\n") ;
|
||||
|
||||
printf("lo1\t%D\nlo2\t%D\nlo3\t%D\nlo4\t%D\nlo5\t%D\nlo6\t%D\n\n",
|
||||
lo1,lo2,lo3,lo4,lo5,lo6 ) ;
|
||||
}
|
||||
|
||||
/* structures and bit fields */
|
||||
|
||||
struct s1 {
|
||||
int s_i ;
|
||||
char s_ca[3] ;
|
||||
long s_l ;
|
||||
double s_f ;
|
||||
struct s1 *s_s1 ;
|
||||
} ;
|
||||
struct s1 st1 ;
|
||||
struct s1 sta[3] = {
|
||||
1 , { 'a' , 'b' , 'c' } , 10 , -10 , &sta[0] ,
|
||||
{ 2 } ,
|
||||
3
|
||||
} ;
|
||||
struct s2 {
|
||||
int s2_1 :1 ;
|
||||
int s2_2 :2 ;
|
||||
int s2_3 :4 ;
|
||||
int s2_4 :7 ;
|
||||
int s2_5 :2 ;
|
||||
int s2_6 :11 ;
|
||||
int s2_7 :6 ;
|
||||
} stb = {
|
||||
1,2,3,4,3,6,7
|
||||
} ;
|
||||
|
||||
pstruct() {
|
||||
printf("structures\n\n") ;
|
||||
|
||||
printf("\t st1 sta[0..2]\n") ;
|
||||
|
||||
printf("s_i\t%15d%15d%15d%15d\n",
|
||||
st1.s_i,sta[0].s_i,sta[1].s_i,sta[2].s_i) ;
|
||||
printf("s_ca[0]\t%15d%15d%15d%15d\n",
|
||||
st1.s_ca[0],sta[0].s_ca[0],sta[1].s_ca[0],sta[2].s_ca[0]) ;
|
||||
printf("s_ca[1]\t%15d%15d%15d%15d\n",
|
||||
st1.s_ca[1],sta[0].s_ca[1],sta[1].s_ca[1],sta[2].s_ca[1]) ;
|
||||
printf("s_ca[2]\t%15d%15d%15d%15d\n",
|
||||
st1.s_ca[2],sta[0].s_ca[2],sta[1].s_ca[2],sta[2].s_ca[2]) ;
|
||||
printf("s_l\t%15D%15D%15D%15D\n",
|
||||
st1.s_l,sta[0].s_l,sta[1].s_l,sta[2].s_l) ;
|
||||
printf("s_f\t %13e %13e %13e %13e\n\n",
|
||||
st1.s_f,sta[0].s_f,sta[1].s_f,sta[2].s_f) ;
|
||||
printf("(sta[0].s_s1)->s_i = %d\n",(sta[0].s_s1)->s_i) ;
|
||||
|
||||
printf("\nbit fields:\n\n") ;
|
||||
printf("sizeof stb %d\n",sizeof stb) ;
|
||||
printf("stb\t%d %d %d %d %d %d %d\n\n",
|
||||
stb.s2_1,stb.s2_2,stb.s2_3,stb.s2_4,stb.s2_5,stb.s2_6,stb.s2_7);
|
||||
}
|
||||
|
||||
main() {
|
||||
pint() ;
|
||||
pch() ;
|
||||
pflt() ;
|
||||
pdbl() ;
|
||||
plong() ;
|
||||
pstruct() ;
|
||||
return(0) ;
|
||||
}
|
||||
112
lang/cem/ctest/ctinit/init.cem.g
Normal file
112
lang/cem/ctest/ctinit/init.cem.g
Normal file
@@ -0,0 +1,112 @@
|
||||
Integers:
|
||||
|
||||
in1 4
|
||||
in2 32767
|
||||
in3 -32768
|
||||
in4 0
|
||||
inzero 0
|
||||
|
||||
ice1 2
|
||||
ice2 8
|
||||
ice3 1
|
||||
ice4 0
|
||||
ice5 7
|
||||
ice6 19
|
||||
|
||||
ina 1,3,5
|
||||
|
||||
sint -1
|
||||
lint -32765
|
||||
|
||||
Characters:
|
||||
|
||||
ch1 a(97)
|
||||
ch2 0
|
||||
cha1 Mesg
|
||||
cha2
|
||||
cha3 1
|
||||
cha4 12
|
||||
cha5 0123456789112345678921234567893123456789412345678951234567896123456789712345678981234567899123456789
|
||||
|
||||
cha6 1, 2, 3
|
||||
4, 5, 6
|
||||
pch1==cha2 yes
|
||||
pch2 pch2
|
||||
pch3 pch3
|
||||
pch4==0 yes
|
||||
|
||||
stc 123
|
||||
stc1 1234
|
||||
mult[0],mult[1],mult[2] ab, bc, de
|
||||
Floats:
|
||||
|
||||
fl1 0.00000000000000000000e+00
|
||||
fl2 2.00000000000000000000e+00
|
||||
fl2 2.00000000000000000000e+00
|
||||
fl4 4.00000000000000000000e+00
|
||||
fl5 2.93873587705571892581e-39
|
||||
fl6 1.70141163178059625000e+38
|
||||
fl7 0.00000000000000000000e+00
|
||||
fla1 fla2 fla3
|
||||
1.000000e+00 -1.000000e+00 1.100000e+01
|
||||
3.000000e+00 -3.000000e+00 0.000000e+00
|
||||
5.000000e+00 -5.000000e+00 0.000000e+00
|
||||
2.000000e+00 -2.000000e+00 1.200000e+01
|
||||
4.000000e+00 -4.000000e+00 0.000000e+00
|
||||
6.000000e+00 -6.000000e+00 0.000000e+00
|
||||
3.000000e+00 -3.000000e+00 1.300000e+01
|
||||
5.000000e+00 -5.000000e+00 0.000000e+00
|
||||
7.000000e+00 -7.000000e+00 0.000000e+00
|
||||
0.000000e+00 0.000000e+00 1.400000e+01
|
||||
0.000000e+00 0.000000e+00 0.000000e+00
|
||||
0.000000e+00 0.000000e+00 0.000000e+00
|
||||
|
||||
Doubles:
|
||||
|
||||
dbl1 0.00000000000000000000e+00
|
||||
dbl2 2.00000000000000000000e+00
|
||||
dbl2 2.00000000000000000000e+00
|
||||
dbl4 4.00000000000000000000e+00
|
||||
dbl5 2.93873600000000034793e-39
|
||||
dbl6 1.70141170000000000000e+38
|
||||
dbl7 0.00000000000000000000e+00
|
||||
dbla1 dbla2 dbla3
|
||||
1.000000e+00 -1.000000e+00 1.100000e+01
|
||||
3.000000e+00 -3.000000e+00 0.000000e+00
|
||||
5.000000e+00 -5.000000e+00 0.000000e+00
|
||||
2.000000e+00 -2.000000e+00 1.200000e+01
|
||||
4.000000e+00 -4.000000e+00 0.000000e+00
|
||||
6.000000e+00 -6.000000e+00 0.000000e+00
|
||||
3.000000e+00 -3.000000e+00 1.300000e+01
|
||||
5.000000e+00 -5.000000e+00 0.000000e+00
|
||||
7.000000e+00 -7.000000e+00 0.000000e+00
|
||||
0.000000e+00 0.000000e+00 1.400000e+01
|
||||
0.000000e+00 0.000000e+00 0.000000e+00
|
||||
0.000000e+00 0.000000e+00 0.000000e+00
|
||||
|
||||
long
|
||||
|
||||
lo1 14
|
||||
lo2 -17
|
||||
lo3 2147483647
|
||||
lo4 -2147483648
|
||||
lo5 0
|
||||
lo6 1
|
||||
|
||||
structures
|
||||
|
||||
st1 sta[0..2]
|
||||
s_i 0 1 2 3
|
||||
s_ca[0] 0 97 0 0
|
||||
s_ca[1] 0 98 0 0
|
||||
s_ca[2] 0 99 0 0
|
||||
s_l 0 10 0 0
|
||||
s_f 0.000000e+00 -1.000000e+01 0.000000e+00 0.000000e+00
|
||||
|
||||
(sta[0].s_s1)->s_i = 1
|
||||
|
||||
bit fields:
|
||||
|
||||
sizeof stb 6
|
||||
stb 1 2 3 4 3 6 7
|
||||
|
||||
1
lang/cem/ctest/ctinit/run
Normal file
1
lang/cem/ctest/ctinit/run
Normal file
@@ -0,0 +1 @@
|
||||
make "P=init" -fsk ../makefile ${1-gen}
|
||||
Reference in New Issue
Block a user