Skip to content

Commit

Permalink
Improved behaviour of LEFT (instruction) #1061
Browse files Browse the repository at this point in the history
  • Loading branch information
spotlessmind1975 committed Dec 17, 2024
1 parent 9637119 commit e0507e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
30 changes: 27 additions & 3 deletions ugbc/src/targets/common/_infrastructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -6822,18 +6822,42 @@ void variable_string_left_assign( Environment * _environment, char * _string, ch
break;
}
case VT_DSTRING: {

Variable * address = variable_temporary( _environment, VT_ADDRESS, "(result of left)" );
Variable * size = variable_temporary( _environment, VT_BYTE, "(result of left)" );
Variable * address2 = variable_temporary( _environment, VT_ADDRESS, "(result of left)" );
Variable * size2 = variable_temporary( _environment, VT_BYTE, "(result of left)" );

cpu_dswrite( _environment, string->realName );

cpu_dsdescriptor( _environment, string->realName, address->realName, size->realName );

cpu_dsdescriptor( _environment, expression->realName, address2->realName, size2->realName );

cpu_mem_move( _environment, address2->realName, address->realName, position->realName );
MAKE_LABEL

char labelLesser[MAX_TEMPORARY_STORAGE]; sprintf( labelLesser, "%slesser", label );
char labelDone[MAX_TEMPORARY_STORAGE]; sprintf( labelDone, "%sdone", label );

Variable * flag = variable_temporary( _environment, VT_BYTE, "(flag)" );

if ( _environment->leftReplace ) {

cpu_dswrite( _environment, string->realName );

cpu_less_than_8bit( _environment, size2->realName, position->realName, flag->realName, 0, 0 );
cpu_compare_and_branch_8bit_const( _environment, flag->realName, 0xff, labelLesser, 1 );
cpu_mem_move( _environment, address2->realName, address->realName, position->realName );
cpu_jump( _environment, labelDone );
cpu_label( _environment, labelLesser );
cpu_mem_move( _environment, address2->realName, address->realName, size2->realName );
cpu_label( _environment, labelDone );

} else {

Variable * left = variable_string_left( _environment, expression->name, position->name );
Variable * right = variable_string_mid( _environment, string->name, variable_add_const( _environment, position->name, 1 )->name, NULL );
variable_move( _environment, variable_add( _environment, left->name, right->name )->name, string->name );

}
break;
}
default:
Expand Down
2 changes: 2 additions & 0 deletions ugbc/src/ugbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2941,6 +2941,8 @@ typedef struct _Environment {

int midReplace;

int leftReplace;

SIDFILE * sidFiles;

/* --------------------------------------------------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions ugbc/src/ugbc.y
Original file line number Diff line number Diff line change
Expand Up @@ -9230,6 +9230,12 @@ option_read :
};

option_definitions :
LEFT REPLACE {
((struct _Environment *)_environment)->leftReplace = 1;
}
| LEFT INSERT {
((struct _Environment *)_environment)->leftReplace = 0;
}
| MID REPLACE {
((struct _Environment *)_environment)->midReplace = 1;
}
Expand Down

0 comments on commit e0507e8

Please sign in to comment.