ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_var.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
41void variable_on_memory_init( Environment * _environment, int _imported_too ) {
42
43 int i=0;
44
45 cpu_label( _environment, "VARINIT" );
46 Variable * variable = _environment->variables;
47 while( variable ) {
48 int imported = variable->imported;
49 if ( _imported_too ) {
50 imported = 0;
51 }
52 if ( ! variable->staticalInit && ! imported && ( variable->realName[0] != '_' ) ) {
53 switch( variable->type ) {
54 case VT_STRING:
55 case VT_DSTRING:
56 case VT_MSPRITE:
57 case VT_SPRITE:
58 case VT_DOJOKA:
59 case VT_TILESET:
60 case VT_TILES:
61 case VT_BUFFER:
62 case VT_TYPE:
63 case VT_IMAGE:
64 case VT_IMAGES:
65 case VT_SEQUENCE:
66 case VT_TILEMAP:
67 case VT_MUSIC:
68 case VT_TARRAY:
69 case VT_BLIT:
70 case VT_FLOAT:
71 case VT_NUMBER:
72 break;
73 default:
74 if ( variable->value != 0 ) {
75 variable_store( _environment, variable->name, variable->initialValue );
76 }
77 }
78 }
79 variable = variable->next;
80 }
81
82 cpu_label( _environment, "VARINITCLEAR" );
83 variable = _environment->variables;
84 while( variable ) {
85 int imported = variable->imported;
86 if ( _imported_too ) {
87 imported = 0;
88 }
89 if ( ! variable->staticalInit && ! imported && ( variable->realName[0] == '_' ) ) {
90 switch( variable->type ) {
91 case VT_STRING:
92 case VT_DSTRING:
93 case VT_MSPRITE:
94 case VT_DOJOKA:
95 case VT_TILESET:
96 case VT_TILES:
97 case VT_BUFFER:
98 case VT_TYPE:
99 case VT_IMAGE:
100 case VT_IMAGES:
101 case VT_SEQUENCE:
102 case VT_TILEMAP:
103 case VT_MUSIC:
104 case VT_TARRAY:
105 case VT_BLIT:
106 case VT_FLOAT:
107 case VT_NUMBER:
108 break;
109 default:
110 if ( variable->value != 0 ) {
111 variable_store( _environment, variable->name, variable->initialValue );
112 }
113 }
114 }
115 variable = variable->next;
116 }
117
118 cpu_return( _environment );
119
120}
121
123
124 if ( _environment->hasCGoto ) {
125
126 int numericLabels = 0;
127 Label * first = _environment->labels;
128 while( first ) {
129 if ( first->number ) {
130 ++numericLabels;
131 }
132 first = first->next;
133 }
134
135 if ( numericLabels ) {
136
137 int * values = malloc( numericLabels * sizeof( int ) );
138 char ** address = malloc( numericLabels * sizeof( char * ) );
139
140 int i = 0;
141 first = _environment->labels;
142 while( first ) {
143 if ( first->number ) {
144 values[i] = first->number;
145 char lineNumber[MAX_TEMPORARY_STORAGE];
146 sprintf(lineNumber, "_linenumber%d", first->number );
147 address[i] = strdup( lineNumber );
148 ++i;
149 }
150 first = first->next;
151 }
152
153 cpu_address_table_build( _environment, "CGOTOADDRESS", values, address, numericLabels );
154
155 cpu_address_table_lookup( _environment, "CGOTOADDRESS", numericLabels );
156
157 }
158 }
159
160}
161
void cpu_address_table_build(Environment *_environment, char *_table, int *_values, char *_address[], int _count)
Definition 6309.c:7344
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_return(Environment *_environment)
Definition 6309.c:4030
void cpu_address_table_lookup(Environment *_environment, char *_table, int _count)
Definition 6309.c:7353
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
void generate_cgoto_address_table(Environment *_environment)
Definition _var.c:122
void variable_on_memory_init(Environment *_environment, int _imported_too)
Definition _var.c:41
int hasCGoto
Definition ugbc.h:2654
Label * labels
Definition ugbc.h:2545
Variable * variables
Definition ugbc.h:2616
struct _Label * next
Definition ugbc.h:848
int number
Definition ugbc.h:845
struct _Variable * next
Definition ugbc.h:1225
int initialValue
Definition ugbc.h:1030
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
int staticalInit
Definition ugbc.h:1139
int value
Definition ugbc.h:1025
int imported
Definition ugbc.h:1014
char * realName
Definition ugbc.h:982
void * malloc(YYSIZE_T)
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_FLOAT
Definition ugbc.h:522
@ VT_BLIT
Definition ugbc.h:519
@ VT_TARRAY
Definition ugbc.h:480
@ VT_NUMBER
Definition ugbc.h:549
@ VT_MSPRITE
Definition ugbc.h:531
@ VT_STRING
Definition ugbc.h:474
@ VT_TILEMAP
Definition ugbc.h:525
@ VT_TILES
Definition ugbc.h:507
@ VT_BUFFER
Definition ugbc.h:477
@ VT_SPRITE
Definition ugbc.h:501
@ VT_IMAGES
Definition ugbc.h:495
@ VT_MUSIC
Definition ugbc.h:516
@ VT_TYPE
Definition ugbc.h:546
@ VT_TILESET
Definition ugbc.h:510
@ VT_DSTRING
Definition ugbc.h:483
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
struct _Label Label
Structure of a single label.