blob: 3ae7604ce451970101d380c5d227395c9487cd4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/* test1 */
int f( )
{
// TODO: i is a local
// return i * 2;
return 42;
}
// TODO: handle forward declaration
//void f3( int i );
void f2( )
{
// TODO: unknown symbol because we don't know about f3 being
// a function with one int parameter
//f3( 44 );
}
void f3( int i )
{
// TODO: unknown identifier 'i' in expression, define them as
// local symbols, code for initializing them (more precise their
// address) being on the stack frame
//putint( i );
}
void main( )
{
// TODO: allow enumeration of variable declarations
char c1;
char c2;
char c3;
char c4;
int i;
int j;
int k;
i = 12+25/5-2*3; // 25/5 -> 5, 12+5 -> 17, 2*3 -> 6, 17-6 -> 11
putint( i ); putnl( );
j = i/3+3*4; // 11 / 3 -> 3, 3*4 -> 12, 3+12 -> 15
putint( j ); putnl( );
k = 7 == 7; putint( k ); putnl( );
k = 8 != 7; putint( k ); putnl( );
k = 8 <= 9; putint( k ); putnl( );
k = 8 < 9; putint( k ); putnl( );
k = 9 > 8; putint( k ); putnl( );
k = 9 >= 8; putint( k ); putnl( );
k = 8 >= 8; putint( k ); putnl( );
k = 8 <= 8; putint( k ); putnl( );
if( i == j ) {
putint( 2 );
} else {
if( i > j ) {
putint( 1 );
} else {
putint( 0 );
}
}
putnl( );
i = 5;
while( i > 0 ) {
putint( i ); putnl( );
i = i - 1;
}
i = 1;
do {
putint( i ); putnl( );
i = i + 1;
} while( i <= 5 );
c1 = 422; // TODO: wrong narrowing from int const to char type, must be catched
c1 = 41;
c2 = c1 + 1;
c3 = c2 + 1;
c4 = c3 + 1;
putchar( c1 );
putchar( c2 );
putchar( c3 );
putchar( c4 );
putnl( );
// TODO: test if parameter types and numbers match
i = f( );
putint( i );
putnl( );
// TODO: handle negative integer literals
//putint( -2147483648 ); putnl( );
putint( 2147483647 ); putnl( );
f2( );
// TODO: expressions as function parameters
f3( 41 + 1 );
// TODO: after calling f3 eax contains 42, which is then printed below?
// eax is blocked and reserved in register, ebx is used to load 2147483647
// we must release the allocated register eax
// TODO: might need spilling of registers before computing parameters for the call
// of 'f'
//f3( ( 43 + 2 ) * f( 3 ) );
// call an undefined function (this works)
//f4( );
putint( 2147483647 ); putnl( );
}
|