diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-09 10:56:17 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2019-02-09 10:56:17 +0100 |
commit | 60444dbdb4164464c84c2ae6d33939f4f32859cd (patch) | |
tree | 9b12bfdd314df8dd3de6f063bcc7097b66d43bdf /minie | |
parent | 6f060c85719e9a9ebe2429e06e83aa79a01773c7 (diff) | |
download | compilertests-60444dbdb4164464c84c2ae6d33939f4f32859cd.tar.gz compilertests-60444dbdb4164464c84c2ae6d33939f4f32859cd.tar.bz2 |
added a getc wrapper returning 0 on end of stream
Diffstat (limited to 'minie')
-rw-r--r-- | minie/e2c.c | 6 | ||||
-rw-r--r-- | minie/test9.e | 1 |
2 files changed, 5 insertions, 2 deletions
diff --git a/minie/e2c.c b/minie/e2c.c index baaa1b8..e2388b7 100644 --- a/minie/e2c.c +++ b/minie/e2c.c @@ -727,6 +727,7 @@ static void prologue( void ) emitLn( "#include <stdio.h>" ); emitLn( "#include <stdlib.h>" ); emitLn( "#include <string.h>" ); + emitLn( "int getc_wrapper( void ) { int c = getc( stdin ); if( c == EOF ) return '\\0'; else return c; }" ); register_internal_functions( ); register_internal_constants( ); @@ -958,7 +959,8 @@ static void assignment( void ) /* right hand side, any expression */ expression( ); if( type.type == TYPE_ARRAY && type.details.array.type->type == TYPE_CHAR ) { - emit( ", %d )", type.details.array.len ); + emit( ", %d ); ", type.details.array.len ); + emit( "%s[%d-1] = '\\0'", varName, type.details.array.len ); } emitLn( ";" ); } @@ -1039,7 +1041,7 @@ static void parameterList( void ) Expect( S_lparen ); if( sym == S_rparen ) { if( strcmp( funcName, "system.readchar" ) == 0 ) { - emit( "getc( stdin )" ); + emit( "getc_wrapper( )" ); sym = getSym( ); return; } diff --git a/minie/test9.e b/minie/test9.e index c625bce..9b087dd 100644 --- a/minie/test9.e +++ b/minie/test9.e @@ -19,6 +19,7 @@ begin i := i + 1; c := system.readchar( ) end; + s[i] := char( 0 ); d := s; system.writeline( d ); end |