ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
proc.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
42/* <usermanual>
43@keyword PROC
44
45@english
46This keyword has multiple meaning. If the identifier that follows this
47command is not already defined, this can be used to give a label (name)
48to a part of the program. This makes subprograms independent of their
49position in the program and makes it easier for the programmer to keep
50track of things (names are easier to assign to a purpose than line numbers).
51
52The ''PROC'' command is used to define the name of such a subprogram
53(or jump target). Following the convention in other BASICs of the time,
54such as Simon's BASIC or Tuned Simon's BASIC, the procedure name can also
55contain spaces. In this case, the trailing space will not be considered as
56part of the name.
57
58If, instead, the identifier has been already used for a procedure, then this
59command will call the procedure, as the instruction ''CALL''.
60
61@italian
62
63Questa parola chiave ha molteplici significati. Se l'identificatore che
64segue questo comando non è già definito, può essere utilizzato per assegnare
65un'etichetta (nome) a una parte del programma. Ciò rende i sottoprogrammi
66indipendenti dalla loro posizione nel programma e semplifica per il programmatore
67il monitoraggio delle cose (è più facile assegnare uno scopo ai nomi rispetto
68ai numeri di riga).
69
70Il comando ''PROC'' viene utilizzato per definire il nome di tale sottoprogramma
71(o destinazione di salto). Seguendo la convenzione di altri BASIC dell'epoca,
72come Simon BASIC o Tuned Simon BASIC, il nome della procedura può anche contenere
73spazi. In questo caso, lo spazio finale non verrà considerato parte del nome.
74
75Se, tuttavia, l'identificatore è già stato utilizzato per una procedura, questo
76comando chiamerà la procedura, come l'istruzione ''CALL''.
77
78@syntax PROC name
79
80@example PROC factorial
81
82@usedInExample tsb_option_call_01.bas
83
84@target all
85</usermanual> */
86void proc( Environment * _environment, char * _label ) {
87
88 Procedure * procedure = _environment->procedures;
89 while ( procedure ) {
90 if ( strcmp( procedure->name, _label ) == 0 ) {
91 break;
92 }
93 procedure = procedure->next;
94 }
95
96 if ( procedure ) {
97 call_procedure( _environment, procedure->name );
98 } else {
99 begin_procedure( _environment, _label );
100 }
101
102}
void begin_procedure(Environment *_environment, char *_name)
Emit code for PROCEDURE ... END PROC.
void call_procedure(Environment *_environment, char *_name)
Emit code for CALL/PROC ....
Definition call.c:139
void proc(Environment *_environment, char *_label)
Emit ASM code for PROC.
Definition proc.c:86
Procedure * procedures
Definition ugbc.h:2621
struct _Procedure * next
Definition ugbc.h:1327
char * name
Definition ugbc.h:1256
struct _Environment Environment
Structure of compilation environment.
struct _Procedure Procedure