From 039ef3befefad677f6af8815696caa3d94179f53 Mon Sep 17 00:00:00 2001 From: spotlessmind1975 Date: Sun, 15 Dec 2024 14:49:24 +0000 Subject: [PATCH] Add pragma to define MID (instruction) behaviour #1071 --- ugbc/src/targets/common/_infrastructure.c | 10 +++++++++- ugbc/src/ugbc.h | 2 ++ ugbc/src/ugbc.y | 6 ++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ugbc/src/targets/common/_infrastructure.c b/ugbc/src/targets/common/_infrastructure.c index abc751dcd..349ae2ae1 100755 --- a/ugbc/src/targets/common/_infrastructure.c +++ b/ugbc/src/targets/common/_infrastructure.c @@ -7346,10 +7346,15 @@ void variable_string_mid_assign( Environment * _environment, char * _string, cha MAKE_LABEL char emptyLabel[MAX_TEMPORARY_STORAGE]; sprintf( emptyLabel, "%sempty", label ); + char doneLabel[MAX_TEMPORARY_STORAGE]; sprintf( doneLabel, "%sdone", label ); Variable * flag = variable_temporary( _environment, VT_BYTE, "(flag for resizing)"); cpu_less_than_8bit( _environment, size2->realName, len->realName, flag->realName, 1, 0 ); - cpu_bveq( _environment, flag->realName, emptyLabel ); + if ( _environment->midReplace ) { + cpu_bveq( _environment, flag->realName, doneLabel ); + } else { + cpu_bveq( _environment, flag->realName, emptyLabel ); + } Variable * tmp = variable_temporary( _environment, VT_DSTRING, "(tmp)"); Variable * addressTmp = variable_temporary( _environment, VT_ADDRESS, "(result of mid)" ); @@ -7368,6 +7373,9 @@ void variable_string_mid_assign( Environment * _environment, char * _string, cha cpu_dec_16bit( _environment, address2->realName ); cpu_mem_move( _environment, address->realName, address2->realName, len->realName ); + + cpu_label( _environment, doneLabel ); + break; } default: diff --git a/ugbc/src/ugbc.h b/ugbc/src/ugbc.h index ff4d542aa..b8de0a54c 100755 --- a/ugbc/src/ugbc.h +++ b/ugbc/src/ugbc.h @@ -2935,6 +2935,8 @@ typedef struct _Environment { int movementDeltaX; int movementDeltaY; + int midReplace; + /* --------------------------------------------------------------------- */ /* OUTPUT PARAMETERS */ /* --------------------------------------------------------------------- */ diff --git a/ugbc/src/ugbc.y b/ugbc/src/ugbc.y index 73b5372bb..8f1a24299 100755 --- a/ugbc/src/ugbc.y +++ b/ugbc/src/ugbc.y @@ -9225,6 +9225,12 @@ option_read : }; option_definitions : + | MID REPLACE { + ((struct _Environment *)_environment)->midReplace = 1; + } + | MID INSERT { + ((struct _Environment *)_environment)->midReplace = 0; + } FINAL HALT { ((struct _Environment *)_environment)->finalReturn = 0; }