summaryrefslogtreecommitdiff
path: root/minie/e2c.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2019-02-09 10:56:17 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2019-02-09 10:56:17 +0100
commit60444dbdb4164464c84c2ae6d33939f4f32859cd (patch)
tree9b12bfdd314df8dd3de6f063bcc7097b66d43bdf /minie/e2c.c
parent6f060c85719e9a9ebe2429e06e83aa79a01773c7 (diff)
downloadcompilertests-60444dbdb4164464c84c2ae6d33939f4f32859cd.tar.gz
compilertests-60444dbdb4164464c84c2ae6d33939f4f32859cd.tar.bz2
added a getc wrapper returning 0 on end of stream
Diffstat (limited to 'minie/e2c.c')
-rw-r--r--minie/e2c.c6
1 files changed, 4 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;
}