ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
param.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
48/* <usermanual>
49@keyword PARAM
50
51@english
52The PARAM function takes the result of an expression in an ''END PROC'' / ''END PROCEDURE'' statement
53(or from a ''RETURN'' statement), and returns it. If the variable you are interested
54in is a string variable, the ''$'' character can be used (but it is not mandatory).
55
56@italian
57La funzione ''PARAM'' recupera il risultato di un'espressione in un'istruzione ''END PROC'' / ''END PROCEDURE''
58(o da un'istruzione ''RETURN'') e la restituisce. Se la variabile di interesse
59è una stringa, è possibile utilizzare il carattere ''$'' (ma non è obbligatorio).
60
61@syntax = PARAM(name)
62@syntax = PARAM$(name)
63
64@example CALL factorial
65@example x = PARAM(factorial)
66
67@usedInExample procedures_param_01.bas
68@usedInExample procedures_param_02.bas
69
70</usermanual> */
71Variable * param_procedure( Environment * _environment, char * _name ) {
72
73 if ( _environment->emptyProcedure ) {
74 Variable * param = variable_temporary( _environment, VT_WORD, "(temp)" );
75 return param;
76 }
77
78 Procedure * procedure = _environment->procedures;
79
80 while( procedure ) {
81 if ( strcmp( procedure->name, _name ) == 0 ) {
82 break;
83 }
84 procedure = procedure->next;
85 }
86
87 if ( !procedure ) {
89 }
90
91 char paramName[MAX_TEMPORARY_STORAGE]; sprintf(paramName,"%s__PARAM", _name );
92 Variable * param;
93 if ( variable_exists( _environment, paramName ) ) {
94 param = variable_retrieve( _environment, paramName );
95 } else {
96 param = variable_temporary( _environment, _environment->defaultVariableType, "(temp)" );
97 variable_store( _environment, param->name, 0 );
98 }
99
100 return param;
101
102}
Variable * variable_retrieve(Environment *_environment, char *_name)
int variable_exists(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
Variable * param_procedure(Environment *_environment, char *_name)
Emit code for PARAM(...).
Definition param.c:71
VariableType defaultVariableType
Definition ugbc.h:2956
Procedure * procedures
Definition ugbc.h:2621
int emptyProcedure
Definition ugbc.h:2932
struct _Procedure * next
Definition ugbc.h:1327
char * name
Definition ugbc.h:1256
char * name
Definition ugbc.h:979
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
#define CRITICAL_PROCEDURE_MISSING(n)
Definition ugbc.h:3483
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
struct _Procedure Procedure