From e0507e8bb01b6d605810927b99283ba759c3110e Mon Sep 17 00:00:00 2001 From: spotlessmind1975 Date: Tue, 17 Dec 2024 20:47:17 +0000 Subject: [PATCH] Improved behaviour of LEFT (instruction) #1061 --- ugbc/src/targets/common/_infrastructure.c | 30 ++++++++++++++++++++--- ugbc/src/ugbc.h | 2 ++ ugbc/src/ugbc.y | 6 +++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/ugbc/src/targets/common/_infrastructure.c b/ugbc/src/targets/common/_infrastructure.c index 212237271..875f329dd 100755 --- a/ugbc/src/targets/common/_infrastructure.c +++ b/ugbc/src/targets/common/_infrastructure.c @@ -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: diff --git a/ugbc/src/ugbc.h b/ugbc/src/ugbc.h index eaadec51f..96b694228 100755 --- a/ugbc/src/ugbc.h +++ b/ugbc/src/ugbc.h @@ -2941,6 +2941,8 @@ typedef struct _Environment { int midReplace; + int leftReplace; + SIDFILE * sidFiles; /* --------------------------------------------------------------------- */ diff --git a/ugbc/src/ugbc.y b/ugbc/src/ugbc.y index b38ecce16..ef37b8be2 100755 --- a/ugbc/src/ugbc.y +++ b/ugbc/src/ugbc.y @@ -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; }