Skip to content

Commit

Permalink
Add pragma to define MID (instruction) behaviour #1071
Browse files Browse the repository at this point in the history
  • Loading branch information
spotlessmind1975 committed Dec 15, 2024
1 parent baaf675 commit 039ef3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ugbc/src/targets/common/_infrastructure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)" );
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions ugbc/src/ugbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -2935,6 +2935,8 @@ typedef struct _Environment {
int movementDeltaX;
int movementDeltaY;

int midReplace;

/* --------------------------------------------------------------------- */
/* OUTPUT PARAMETERS */
/* --------------------------------------------------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions ugbc/src/ugbc.y
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 039ef3b

Please sign in to comment.