summaryrefslogtreecommitdiff
path: root/ecomp-c/ec.c
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2020-05-10 21:09:37 +0200
committerAndreas Baumann <mail@andreasbaumann.cc>2020-05-10 21:09:37 +0200
commit1e3452c52d140e43efbfeaa5f4a1057e959b644d (patch)
treec1c9833693316c3555adaa9b926fa02e10a47797 /ecomp-c/ec.c
parentcc41902750e66aa6dc179aabbcfcd2eb50b8254a (diff)
downloadcompilertests-1e3452c52d140e43efbfeaa5f4a1057e959b644d.tar.gz
compilertests-1e3452c52d140e43efbfeaa5f4a1057e959b644d.tar.bz2
some work on char type
Diffstat (limited to 'ecomp-c/ec.c')
-rw-r--r--ecomp-c/ec.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c
index f560d6b..61791f8 100644
--- a/ecomp-c/ec.c
+++ b/ecomp-c/ec.c
@@ -533,6 +533,7 @@ typedef struct Symbol {
int value;
/* variable */
int initialized;
+ int size;
} Symbol;
typedef struct Scope {
@@ -629,6 +630,7 @@ static Symbol *insert_symbol( Scope *scope, char *name, SymbolClass class )
sym->name = Allocate( strlen( name ) + 1 );
strlcpy( sym->name, name, strlen( name ) + 1 );
sym->initialized = 0;
+ sym->size = 0;
sym->next = scope->symbol;
scope->symbol = sym;
@@ -1303,9 +1305,11 @@ static void register_internal_types( Scope *scope )
{
Symbol *type_symbol, *const_symbol;
- insert_symbol( current_scope, "integer", SYMBOL_CLASS_TYPE );
+ type_symbol = insert_symbol( current_scope, "integer", SYMBOL_CLASS_TYPE );
+ type_symbol->size = 4;
type_symbol = insert_symbol( current_scope, "boolean", SYMBOL_CLASS_TYPE );
+ type_symbol->size = 1;
const_symbol = insert_symbol( current_scope, "false", SYMBOL_CLASS_CONSTANT );
const_symbol->type = type_symbol;
@@ -1314,6 +1318,9 @@ static void register_internal_types( Scope *scope )
const_symbol = insert_symbol( current_scope, "true", SYMBOL_CLASS_CONSTANT );
const_symbol->type = type_symbol;
const_symbol->value = 1;
+
+ type_symbol = insert_symbol( current_scope, "char", SYMBOL_CLASS_TYPE );
+ type_symbol->size = 1;
}
static void init( void )
@@ -1346,7 +1353,17 @@ static void epilogue( void )
symbol = current_scope->symbol;
while( symbol != NULL ) {
if( symbol->class == SYMBOL_CLASS_VARIABLE ) {
- Emit( "%s: dd $00000000\n", symbol->name );
+ switch( symbol->type->size ) {
+ case 4:
+ Emit( "%s: dd $00000000\n", symbol->name );
+ break;
+ case 1:
+ Emit( "%s: db $00\n", symbol->name );
+ break;
+ default:
+ Abort( "Unhandled size of type '%s' in variable '%s'",
+ symbol->type->name, symbol->name );
+ }
}
symbol = symbol->next;
}