Skip to content

Commit 8a8924d

Browse files
Fixed constant emission in empty procedures.
1 parent e87cd9e commit 8a8924d

File tree

1 file changed

+77
-59
lines changed

1 file changed

+77
-59
lines changed

ugbc/src/ugbc.y

Lines changed: 77 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9431,89 +9431,107 @@ statement2nc:
94319431
| DIM dim_definitions
94329432
| FILL fill_definitions
94339433
| const_instruction STRING Identifier OP_ASSIGN const_expr_string_const {
9434-
Constant * c1 = constant_find( ((Environment *)_environment)->constants, $5 );
9435-
9436-
Constant * c3 = malloc( sizeof( Constant ) );
9437-
memset( c3, 0, sizeof( Constant ) );
9438-
c3->name = strdup( $3 );
9439-
c3->realName = strdup( $3 );
9440-
9441-
c3->valueString = malloc( sizeof( StaticString ) );
9442-
memset( c3->valueString, 0, sizeof( StaticString ) );
9443-
9444-
c3->valueString->id = UNIQUE_ID;
9445-
c3->valueString->value = malloc( c1->valueString->size );
9446-
memcpy( c3->valueString->value, c1->valueString->value, c1->valueString->size );
9447-
c3->valueString->size = c1->valueString->size;
9448-
c3->valueString->next = ((Environment *)_environment)->strings;
9449-
((Environment *)_environment)->strings = c3->valueString;
9450-
9451-
c3->type = CT_STRING;
9452-
Constant * constLast = ((Environment *)_environment)->constants;
9453-
if ( constLast ) {
9454-
while( constLast->next ) {
9455-
constLast = constLast->next;
9434+
if ( !((Environment *)_environment)->emptyProcedure ) {
9435+
Constant * c1 = constant_find( ((Environment *)_environment)->constants, $5 );
9436+
9437+
Constant * c3 = malloc( sizeof( Constant ) );
9438+
memset( c3, 0, sizeof( Constant ) );
9439+
c3->name = strdup( $3 );
9440+
c3->realName = strdup( $3 );
9441+
9442+
c3->valueString = malloc( sizeof( StaticString ) );
9443+
memset( c3->valueString, 0, sizeof( StaticString ) );
9444+
9445+
c3->valueString->id = UNIQUE_ID;
9446+
c3->valueString->value = malloc( c1->valueString->size );
9447+
memcpy( c3->valueString->value, c1->valueString->value, c1->valueString->size );
9448+
c3->valueString->size = c1->valueString->size;
9449+
c3->valueString->next = ((Environment *)_environment)->strings;
9450+
((Environment *)_environment)->strings = c3->valueString;
9451+
9452+
c3->type = CT_STRING;
9453+
Constant * constLast = ((Environment *)_environment)->constants;
9454+
if ( constLast ) {
9455+
while( constLast->next ) {
9456+
constLast = constLast->next;
9457+
}
9458+
constLast->next = c3;
9459+
} else {
9460+
((Environment *)_environment)->constants = c3;
94569461
}
9457-
constLast->next = c3;
9458-
} else {
9459-
((Environment *)_environment)->constants = c3;
9460-
}
94619462

9462-
// const_emit( _environment, c1->name );
9463+
// const_emit( _environment, c1->name );
9464+
}
94639465
}
94649466
| const_instruction Identifier OP_ASSIGN const_expr_string {
9465-
const_define_string( _environment, $2, $4 );
9467+
if ( !((Environment *)_environment)->emptyProcedure ) {
9468+
const_define_string( _environment, $2, $4 );
9469+
}
94669470
}
94679471
| const_instruction Identifier OP_ASSIGN const_expr {
9468-
const_define_numeric( _environment, $2, $4 );
9472+
if ( !((Environment *)_environment)->emptyProcedure ) {
9473+
const_define_numeric( _environment, $2, $4 );
9474+
}
94699475
}
94709476
| const_instruction POSITIVE Identifier OP_ASSIGN const_expr {
9471-
if ( $5 < 0 ) {
9472-
CRITICAL_NEGATIVE_CONSTANT( $3, $5 );
9477+
if ( !((Environment *)_environment)->emptyProcedure ) {
9478+
if ( $5 < 0 ) {
9479+
CRITICAL_NEGATIVE_CONSTANT( $3, $5 );
9480+
}
9481+
const_define_numeric( _environment, $3, $5 );
94739482
}
9474-
const_define_numeric( _environment, $3, $5 );
94759483
}
94769484
| POSITIVE const_instruction Identifier OP_ASSIGN const_expr {
9477-
if ( $5 < 0 ) {
9478-
CRITICAL_NEGATIVE_CONSTANT( $3, $5 );
9485+
if ( !((Environment *)_environment)->emptyProcedure ) {
9486+
if ( $5 < 0 ) {
9487+
CRITICAL_NEGATIVE_CONSTANT( $3, $5 );
9488+
}
9489+
const_define_numeric( _environment, $3, $5 );
94799490
}
9480-
const_define_numeric( _environment, $3, $5 );
94819491
}
94829492
| const_instruction Identifier IN OP const_expr OP_COMMA const_expr CP OP_ASSIGN const_expr {
9483-
if ( $10 < $5 ) {
9484-
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9485-
}
9486-
if ( $10 > $7 ) {
9487-
CRITICAL_TOO_BIG_CONSTANT( $2 );
9493+
if ( !((Environment *)_environment)->emptyProcedure ) {
9494+
if ( $10 < $5 ) {
9495+
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9496+
}
9497+
if ( $10 > $7 ) {
9498+
CRITICAL_TOO_BIG_CONSTANT( $2 );
9499+
}
9500+
const_define_numeric( _environment, $2, $10 );
94889501
}
9489-
const_define_numeric( _environment, $2, $10 );
94909502
}
94919503
| const_instruction Identifier IN OSP const_expr OP_COMMA const_expr CP OP_ASSIGN const_expr {
9492-
if ( $10 <= $5 ) {
9493-
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9494-
}
9495-
if ( $10 > $7 ) {
9496-
CRITICAL_TOO_BIG_CONSTANT( $2 );
9504+
if ( !((Environment *)_environment)->emptyProcedure ) {
9505+
if ( $10 <= $5 ) {
9506+
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9507+
}
9508+
if ( $10 > $7 ) {
9509+
CRITICAL_TOO_BIG_CONSTANT( $2 );
9510+
}
9511+
const_define_numeric( _environment, $2, $10 );
94979512
}
9498-
const_define_numeric( _environment, $2, $10 );
94999513
}
95009514
| const_instruction Identifier IN OP const_expr OP_COMMA const_expr CSP OP_ASSIGN const_expr {
9501-
if ( $10 < $5 ) {
9502-
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9503-
}
9504-
if ( $10 >= $7 ) {
9505-
CRITICAL_TOO_BIG_CONSTANT( $2 );
9515+
if ( !((Environment *)_environment)->emptyProcedure ) {
9516+
if ( $10 < $5 ) {
9517+
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9518+
}
9519+
if ( $10 >= $7 ) {
9520+
CRITICAL_TOO_BIG_CONSTANT( $2 );
9521+
}
9522+
const_define_numeric( _environment, $2, $10 );
95069523
}
9507-
const_define_numeric( _environment, $2, $10 );
95089524
}
95099525
| const_instruction Identifier IN OSP const_expr OP_COMMA const_expr CSP OP_ASSIGN const_expr {
9510-
if ( $10 <= $5 ) {
9511-
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9512-
}
9513-
if ( $10 >= $7 ) {
9514-
CRITICAL_TOO_BIG_CONSTANT( $2 );
9526+
if ( !((Environment *)_environment)->emptyProcedure ) {
9527+
if ( $10 <= $5 ) {
9528+
CRITICAL_TOO_LITTLE_CONSTANT( $2 );
9529+
}
9530+
if ( $10 >= $7 ) {
9531+
CRITICAL_TOO_BIG_CONSTANT( $2 );
9532+
}
9533+
const_define_numeric( _environment, $2, $10 );
95159534
}
9516-
const_define_numeric( _environment, $2, $10 );
95179535
}
95189536
| TI OP_ASSIGN expr {
95199537
set_timer( _environment, $3 );

0 commit comments

Comments
 (0)