summaryrefslogtreecommitdiff
path: root/ecomp-c/ec.c
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-c/ec.c')
-rw-r--r--ecomp-c/ec.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/ecomp-c/ec.c b/ecomp-c/ec.c
index 4243a93..2b88b0e 100644
--- a/ecomp-c/ec.c
+++ b/ecomp-c/ec.c
@@ -1752,6 +1752,7 @@ static Symbol *parseArrayType( Scope *scope )
integer_type->name, node->actual_type->name );
}
num = evaluate_const_expression_as_integer( node );
+ free_expression_node( node );
}
Expect( S_of );
@@ -1938,20 +1939,28 @@ static void parseProcedureBlock( Scope *scope )
Expect( S_procedure );
Expect( S_ident );
- procedure_label = get_scoped_label( scope, ident );
- Emit( "; PROC %s\n", ident );
-
- symbol = insert_symbol( scope, ident, SYMBOL_CLASS_PROCEDURE_TYPE );
- symbol->label = procedure_label;
+ symbol = get_symbol( scope, ident );
+ if( symbol == NULL ) {
+ symbol = insert_symbol( scope, ident, SYMBOL_CLASS_PROCEDURE_TYPE );
+ procedure_label = get_scoped_label( scope, ident );
+ symbol->label = AllocateAndCopyStr( procedure_label );
+ free( procedure_label );
+ } else if( symbol->class == SYMBOL_CLASS_PROCEDURE_TYPE ) {
+ /* TODO: check, if parameter lists and return values match */
+ }
Expect( S_semicolon );
- parseProcedureDeclarationBlock( scope );
+ if( sym == S_const || sym == S_var || sym == S_begin ) {
+ parseProcedureDeclarationBlock( scope );
- Emit( "%s:\n", procedure_label );
- parseStatementBlock( scope );
+ Emit( "; PROC %s\n", symbol->name );
+
+ Emit( "%s:\n", symbol->label );
+ parseStatementBlock( scope );
- Emit( "ret\n" );
+ Emit( "ret\n" );
+ }
}
static void parseDeclarationBlock( Scope *scope )
@@ -1976,12 +1985,18 @@ static void parseModule( Scope *scope )
if( sym == S_ident ) {
strlcpy( moduleName, ident, MAX_IDENT_LEN );
}
+
entry_label = get_local_label( scope );
- Emit( "jmp %s\n", entry_label );
+ Emit( "jmp %s\n", entry_label );
+
Expect( S_semicolon );
+
parseDeclarationBlock( scope );
Emit( "%s:\n", entry_label );
+
parseStatementBlock( scope );
+
+ free( entry_label );
}
static void register_internal_types( Scope *scope )