ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
cgoto.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
41/* <usermanual>
42@keyword CGOTO
43
44@english
45
46Calculate the number of the line to which the program execution must pass.
47Allows you to jump to a variable program line number, determined by the result
48of a calculation. ''CGOTO'' is a command that replaces long jump tables behind
49the BASIC command ''ON''.
50
51Instead of specifying the jump targets as with ''ON''
52and then calling them by specifying the location number of the desired target,
53the desired target line can be targeted immediately by calculation after
54''CGOTO'' without much typing.
55
56The use of ''CGOTO'' requires that the lines
57are arranged in such a way when programming that these lines remain accessible
58for the algorithm ''expression'' behind ''CGOTO''.
59
60@italian
61
62Calcola il numero della riga a cui deve passare l'esecuzione del programma.
63Consente di saltare a un numero di riga di programma variabile, determinato
64dal risultato di un calcolo.
65
66''CGOTO'' è un comando che sostituisce le tabelle
67di salto in lungo dietro il comando BASIC ''ON''. Invece di specificare i target
68di salto come con ''ON'' e quindi chiamarli specificando il numero di posizione
69del target desiderato, la riga del target desiderato può essere mirata immediatamente
70tramite calcolo dopo ''CGOTO'' senza molta digitazione.
71
72L'uso di ''CGOTO''
73richiede che le righe siano disposte in modo tale durante la programmazione che queste
74righe rimangano accessibili per l'algoritmo ''espressione'' dietro ''CGOTO''.
75
76@syntax CGOTO expression
77
78@example CGOTO 10*i+100
79
80@usedInExample tsb_cgoto_01.bas
81
82@target all
83@verified
84</usermanual> */
85void cgoto( Environment * _environment, char * _expression ) {
86
88
89 Variable * expression = variable_retrieve_or_define( _environment, _expression, VT_WORD, 0 );
90 Variable * address = variable_temporary( _environment, VT_WORD, 0 );
91
92 _environment->hasCGoto = 1;
93
94 cpu_address_table_call( _environment, "CGOTOADDRESS", expression->realName, address->realName );
95
96 cpu_compare_and_branch_16bit_const( _environment, address->realName, 0, label, 1 );
97
98 cpu_jump_indirect( _environment, address->realName );
99
100 cpu_label( _environment, label );
101
102}
void cpu_jump_indirect(Environment *_environment, char *_value)
Definition 6309.c:3783
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:1578
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_address_table_call(Environment *_environment, char *_table, char *_value, char *_address)
Definition 6309.c:7374
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
void cgoto(Environment *_environment, char *_expression)
Definition cgoto.c:85
int hasCGoto
Definition ugbc.h:2654
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
#define MAKE_LABEL
Definition ugbc.h:3351