ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
exit_proc_if.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
49/* <usermanual>
50@keyword EXIT PROCEDURE IF
51
52@english
53
54The ''EXIT PROCEDURE IF'' command is used to stop execution of a specific procedure,
55and transfer control of the program to the first statement following the calling
56of that procedure, in case an expression is true.''TRUE''
57
58The command is useful to exit when an error or unexpected condition occurs, and it
59can be used to end the procedure and handle the error appropriately. In some cases,
60using ''EXIT PROCEDURE IF'' can make your code more efficient by avoiding executing unnecessary
61statements. ''EXIT PROCEDURE IF'' allows you to create more complex control flows and
62make dynamic decisions during program execution. Excessive use of ''EXIT PROCEDURE IF'', however,
63can make your code more difficult to read and maintain.
64
65@italian
66
67Il comando ''EXIT PROCEDURE IF'' viene utilizzato per interrompere l'esecuzione
68di una procedura specifica e trasferire il controllo del programma alla prima
69istruzione successiva alla chiamata di tale procedura, nel caso la condizione
70indicata sia ''TRUE''.
71
72Il comando è utile per uscire quando si verifica un errore o una condizione imprevista,
73e può essere utilizzato per terminare la procedura e gestire l'errore in modo appropriato.
74In alcuni casi, l'utilizzo di ''EXIT PROCEDURE IF'' può rendere il codice più efficiente
75evitando di eseguire istruzioni non necessarie. ''EXIT PROCEDURE IF'' consente di creare
76flussi di controllo più complessi e prendere decisioni dinamiche durante l'esecuzione
77del programma. Tuttavia, un utilizzo eccessivo di ''EXIT PROCEDURE IF'' può rendere il
78codice più difficile da leggere e gestire.
79
80@syntax EXIT PROCEDURE IF expression
81
82@example PROCEDURE test[ x AS INTEGER ]
83@example EXIT PROCEDURE IF x > 10
84@example PRINT "X is less or equal to 10"
85@example END PROC
86
87@alias EXIT PROC IF
88
89</usermanual> */
90
91/* <usermanual>
92@keyword EXIT PROC IF
93
94@english
95
96@italian
97
98@syntax EXIT PROC IF expression
99
100@example EXIT PROC IF
101
102@usedInExample procedures_jumping_02.bas
103
104@alias EXIT PROCEDURE IF
105
106</usermanual> */
107
108/* <usermanual>
109@keyword EXIT PROCEDURE WITH...IF
110
111@english
112
113The ''EXIT PROCEDURE WITH...IF'' command is used to stop execution of a specific function,
114and transfer control of the program to the first statement following the calling
115of that procedure, giving back a value in case an expression is true.''TRUE''
116
117The command is useful to exit when an error or unexpected condition occurs, and it
118can be used to end the procedure and handle the error appropriately. In some cases,
119using ''EXIT PROCEDURE WITH...IF'' can make your code more efficient by avoiding executing unnecessary
120statements. ''EXIT PROCEDURE WITH...IF'' allows you to create more complex control flows and
121make dynamic decisions during program execution. Excessive use of ''EXIT PROCEDURE WITH...IF'', however,
122can make your code more difficult to read and maintain.
123
124@italian
125
126Il comando ''EXIT PROCEDURE WITH...IF'' viene utilizzato per interrompere l'esecuzione
127di una funzione specifica e trasferire il controllo del programma alla prima
128istruzione successiva alla chiamata di tale procedura, restituendo un valore,
129nel caso la condizione indicata sia ''TRUE''.
130
131Il comando è utile per uscire quando si verifica un errore o una condizione imprevista,
132e può essere utilizzato per terminare la procedura e gestire l'errore in modo appropriato.
133In alcuni casi, l'utilizzo di ''EXIT PROCEDURE WITH...IF'' può rendere il codice più efficiente
134evitando di eseguire istruzioni non necessarie. ''EXIT PROCEDURE WITH...IF'' consente di creare
135flussi di controllo più complessi e prendere decisioni dinamiche durante l'esecuzione
136del programma. Tuttavia, un utilizzo eccessivo di ''EXIT PROCEDURE WITH...IF'' può rendere il
137codice più difficile da leggere e gestire.
138
139@syntax EXIT PROCEDURE WITH value IF expression
140
141@example PROCEDURE test[ x AS INTEGER ]
142@example EXIT PROCEDURE WITH 0 IF x > 10
143@example PRINT "X is less or equal to 10"
144@example RETURN 1
145@example END PROC
146
147@alias EXIT PROC IF
148
149</usermanual> */
150
151/* <usermanual>
152@keyword EXIT PROC WITH...IF
153
154@english
155
156@italian
157
158@syntax EXIT PROC WITH value IF expression
159
160@example PROCEDURE test[ x AS INTEGER ]
161@example EXIT PROC WITH 0 IF x > 10
162@example PRINT "X is less or equal to 10"
163@example RETURN 1
164@example END PROC
165
166@alias EXIT PROCEDURE WITH...IF
167
168</usermanual> */
169
170void exit_proc_if( Environment * _environment, char * _expression, char * _value ) {
171
173
174 Variable * expression = variable_retrieve( _environment, _expression );
175
176 cpu_bveq( _environment, expression->realName, label );
177
178 if ( _value ) {
179 return_procedure( _environment, _value );
180 } else {
181 cpu_return( _environment );
182 }
183
184 cpu_label( _environment, label );
185
186}
void cpu_bveq(Environment *_environment, char *_value, char *_label)
Definition 6309.c:334
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_return(Environment *_environment)
Definition 6309.c:4030
Variable * variable_retrieve(Environment *_environment, char *_name)
void exit_proc_if(Environment *_environment, char *_expression, char *_value)
Emit ASM code for EXIT PROC IF.
void return_procedure(Environment *_environment, char *_value)
Emit code for RETURN ....
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
#define MAKE_LABEL
Definition ugbc.h:3351