/* 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( ); }