ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
respawn.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
47/* <usermanual>
48@keyword RESPAWN (instruction)
49
50@english
51
52This keyword will restart a (finished) (parallel) procedure.
53
54@italian
55
56Questa parola chiave fa ricominciare una funzione terminata,
57affinché sia eseguita in parallelo.
58
59@syntax RESPAWN identifier
60
61@example RESPAWN factorialHandle
62
63</usermanual> */
64
65/* <usermanual>
66@keyword RESPAWN (function)
67
68@english
69
70This keyword will restart a (finished) (parallel) procedure,
71giving back a thread id.
72
73@italian
74
75Questa parola chiave fa ricominciare una funzione terminata,
76affinché sia eseguita in parallelo, restituendo il codice
77identificativo del thread.
78
79@syntax = RESPAWN identifier
80
81@example newHandle = RESPAWN factorialHandle
82
83</usermanual> */
84
85Variable * respawn_procedure( Environment * _environment, char * _name ) {
86
88
89 Variable * threadId = variable_retrieve( _environment, _name );
90 Variable * threadState = variable_temporary( _environment, VT_BYTE, "(current thread state)" );
91
92 if ( threadId->type != VT_THREAD ) {
94 }
95
96 if ( _environment->protothreadForbid ) {
98 }
99
100 _environment->anyProtothread = 1;
101
102 char doNothingLabel[MAX_TEMPORARY_STORAGE]; sprintf(doNothingLabel, "%snothing", label );
103
104 cpu_protothread_get_state( _environment, threadId->realName, threadState->realName );
105 cpu_compare_and_branch_8bit_const( _environment, threadState->realName, PROTOTHREAD_STATUS_ENDED, doNothingLabel, 0 );
106 cpu_protothread_set_state( _environment, threadId->realName, PROTOTHREAD_STATUS_WAITING );
107 cpu_protothread_save( _environment, threadId->realName, 0 );
108
109 cpu_label( _environment, doNothingLabel );
110
111 return threadId;
112
113}
114
void cpu_protothread_get_state(Environment *_environment, char *_index, char *_state)
Definition 6309.c:6237
void cpu_protothread_save(Environment *_environment, char *_index, int _step)
Definition 6309.c:6203
void cpu_protothread_set_state(Environment *_environment, char *_index, int _state)
Definition 6309.c:6226
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void cpu_compare_and_branch_8bit_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:876
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * respawn_procedure(Environment *_environment, char *_name)
Emit code for SPAWN ....
Definition respawn.c:85
int anyProtothread
Definition ugbc.h:2835
int protothreadForbid
Definition ugbc.h:2845
char * realName
Definition ugbc.h:982
#define PROTOTHREAD_STATUS_ENDED
Definition ugbc.h:4550
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define PROTOTHREAD_STATUS_WAITING
Definition ugbc.h:4546
#define CRITICAL_CANNOT_RESPAWN_NOT_THREADID(v)
Definition ugbc.h:3565
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_THREAD
Definition ugbc.h:492
@ VT_BYTE
Definition ugbc.h:450
#define CRITICAL_MULTITASKING_FORBIDDEN()
Definition ugbc.h:3703
#define MAKE_LABEL
Definition ugbc.h:3351