1// This file is part of SmallBASIC
2//
3// COMPILER/EXECUTOR/IDE COMMON DEFS
4//
5// This program is distributed under the terms of the GPL v2.0 or later
6// Download the GNU Public License (GPL) from www.gnu.org
7//
8// Copyright(C) 2000 Nicholas Christopoulos
9
10#if !defined(_smbas_h)
11#define _smbas_h
12
13#include "common/sys.h"
14#include "common/var.h"
15#include "common/kw.h"
16#include "common/scan.h"
17
18#if defined(__cplusplus)
19extern "C" {
20#endif
21
22/**
23 * @ingroup exec
24 *
25 * @typedef bc_head_t
26 * byte-code header
27 */
28typedef struct {
29 char sign[4]; /**< always "SBEx" */
30 uint32_t ver; /**< version of this structure */
31 uint32_t sbver; /**< version of SB */
32 uint32_t flags; /**< flags
33 b0 = Big-endian CPU
34 b1 = BC 16bit
35 b2 = BC 32bit */
36
37 uint32_t size; /**< total size (include label-table and bc) */
38 uint32_t bc_count; /**< BC length */
39 uint32_t var_count; /**< number of variables */
40 uint32_t lab_count; /**< number of labels */
41 uint32_t data_ip; /**< default DATA position */
42
43 // ver 2
44 uint32_t lib_count; /**< libraries count (needed units) */
45 uint32_t sym_count; /**< symbol count (linked-symbols) */
46} bc_head_t;
47
48/**
49 * @ingroup exec
50 *
51 * @typedef bc_unit_rec_t
52 * byte-code linked-unit record
53 */
54typedef struct {
55 char lib[OS_FILENAME_SIZE + 1]; /**< library name */
56 char alias[OS_FILENAME_SIZE + 1]; /**< library name alias */
57 int type; /**< library type (unit, c-module) */
58 int id; /**< lib-id in this byte-code */
59 int tid; /**< task id (updated on loading) */
60} bc_lib_rec_t;
61
62typedef struct {
63 int count;
64 bc_lib_rec_t **elem;
65} bc_lib_rec_table_t;
66
67/**
68 * @ingroup exec
69 *
70 * @typedef bc_symbol_rec_t
71 * byte-code linked-symbol record
72 */
73typedef struct {
74 char symbol[SB_KEYWORD_SIZE + 1]; /**< symbol name */
75 int type; /**< symbol type */
76 int lib_id; /**< lib-id in this byte-code */
77 int sym_id; /**< symbol-id in this byte-code */
78 int var_id; /**< related variable-id in this byte-code */
79 int task_id; /**< task id which library is loaded (updated on loading) */
80 int exp_idx; /**< export symbol-index in librarys space (updated on loading) */
81} bc_symbol_rec_t;
82
83typedef struct {
84 int count;
85 bc_symbol_rec_t **elem;
86} bc_symbol_rec_table_t;
87
88#define BRUN_RUNNING 0 /**< brun_status(), the program is still running @ingroup exec */
89#define BRUN_STOPPED 1 /**< brun_status(), an error or 'break' has already stoped the program @ingroup exec */
90
91/*
92 * compiler options
93 */
94#if defined(BRUN_MODULE)
95#define EXTERN
96#else
97#define EXTERN extern
98#endif
99
100#define OPT_CMD_SZ 1024
101#define OPT_MOD_SZ 1024
102
103EXTERN byte opt_graphics; /**< command-line option: start in graphics mode */
104EXTERN byte opt_quiet; /**< command-line option: quiet */
105EXTERN char opt_command[OPT_CMD_SZ]; /**< command-line parameters (COMMAND$) */
106EXTERN int opt_base; /**< OPTION BASE x */
107EXTERN byte opt_loadmod; /**< load all modules */
108EXTERN char opt_modpath[OPT_MOD_SZ]; /**< Modules path */
109EXTERN int opt_verbose; /**< print some additional infos */
110EXTERN int opt_ide; /**< 0=no IDE, 1=IDE is linked, 2=IDE is external exe) */
111EXTERN byte os_charset; /**< use charset encoding */
112EXTERN int opt_pref_width; /**< prefered graphics mode width (0 = undefined) */
113EXTERN int opt_pref_height; /**< prefered graphics mode height */
114EXTERN byte opt_nosave; /**< do not create .sbx files */
115EXTERN byte opt_usepcre; /**< OPTION PREDEF PCRE */
116EXTERN byte opt_file_permitted; /**< file system permission */
117EXTERN byte opt_show_page; /**< SHOWPAGE graphics flush mode */
118EXTERN byte opt_mute_audio; /**< whether to mute sounds */
119EXTERN byte opt_antialias; /**< OPTION ANTIALIAS OFF */
120EXTERN byte opt_autolocal; /**< OPTION AUTOLOCAL */
121EXTERN byte opt_trace_on; /**< initial value for the TRON command */
122
123#define IDE_NONE 0
124#define IDE_INTERNAL 1
125#define IDE_EXTERNAL 2
126
127// globals
128EXTERN int gsb_last_line; /**< source code line of the last error */
129EXTERN int gsb_last_error; /**< error code, 0 = no error, < 0 = local messages (i.e. break), > 0 = error */
130EXTERN char gsb_last_file[OS_PATHNAME_SIZE + 1]; /**< source code file-name of the last error */
131EXTERN char gsb_bas_dir[OS_PATHNAME_SIZE + 1]; /**< source code home dir */
132EXTERN char gsb_last_errmsg[SB_ERRMSG_SIZE + 1]; /**< last error message */
133
134#include "common/units.h"
135#include "common/tasks.h"
136
137#define IF_PROG_ERR_RTN if (ctask->error) { return; }
138#define IF_PROG_ERR_BRK if (ctask->error) { break; }
139
140// emulation
141#define prog_line ctask->line
142#define comp_line ctask->line
143#define prog_error ctask->error
144#define comp_error ctask->error
145#define prog_file ctask->file
146#define prog_errmsg ctask->errmsg
147#define prog_length ctask->sbe.exec.length
148#define prog_ip ctask->sbe.exec.ip
149#define prog_source ctask->sbe.exec.bytecode
150#define prog_dp ctask->sbe.exec.dp
151#define data_org ctask->sbe.exec.org
152#define prog_stack ctask->sbe.exec.stack
153#define prog_stack_alloc ctask->sbe.exec.stack_alloc
154#define prog_sp ctask->sbe.exec.sp
155#define eval_stk ctask->sbe.exec.eval_stk
156#define eval_stk_size ctask->sbe.exec.eval_stk_size
157#define eval_sp ctask->sbe.exec.eval_esp
158#define prog_varcount ctask->sbe.exec.varcount
159#define prog_labcount ctask->sbe.exec.labcount
160#define prog_libcount ctask->sbe.exec.libcount
161#define prog_symcount ctask->sbe.exec.symcount
162#define prog_expcount ctask->sbe.exec.expcount
163#define prog_vartable ctask->sbe.exec.vartable
164#define prog_labtable ctask->sbe.exec.labtable
165#define prog_libtable ctask->sbe.exec.libtable
166#define prog_symtable ctask->sbe.exec.symtable
167#define prog_exptable ctask->sbe.exec.exptable
168#define prog_timer ctask->sbe.exec.timer
169#define comp_extfunctable ctask->sbe.comp.extfunctable
170#define comp_extfunccount ctask->sbe.comp.extfunccount
171#define comp_extfuncsize ctask->sbe.comp.extfuncsize
172#define comp_extproctable ctask->sbe.comp.extproctable
173#define comp_extproccount ctask->sbe.comp.extproccount
174#define comp_extprocsize ctask->sbe.comp.extprocsize
175#define comp_vartable ctask->sbe.comp.vartable
176#define comp_varcount ctask->sbe.comp.varcount
177#define comp_varsize ctask->sbe.comp.varsize
178#define comp_imptable ctask->sbe.comp.imptable
179#define comp_impcount ctask->sbe.comp.imptable.count
180#define comp_exptable ctask->sbe.comp.exptable
181#define comp_expcount ctask->sbe.comp.exptable.count
182#define comp_libtable ctask->sbe.comp.libtable
183#define comp_libcount ctask->sbe.comp.libtable.count
184#define comp_labtable ctask->sbe.comp.labtable
185#define comp_labcount ctask->sbe.comp.labtable.count
186#define comp_bc_sec ctask->sbe.comp.bc_sec
187#define comp_block_level ctask->sbe.comp.block_level
188#define comp_block_id ctask->sbe.comp.block_id
189#define comp_prog ctask->sbe.comp.bc_prog
190#define comp_data ctask->sbe.comp.bc_data
191#define comp_proc_level ctask->sbe.comp.proc_level
192#define comp_bc_proc ctask->sbe.comp.bc_proc
193#define comp_bc_temp ctask->sbe.comp.bc_temp
194#define comp_bc_tmp2 ctask->sbe.comp.bc_tmp2
195#define comp_bc_name ctask->sbe.comp.bc_name
196#define comp_bc_parm ctask->sbe.comp.bc_parm
197#define comp_udptable ctask->sbe.comp.udptable
198#define comp_udpcount ctask->sbe.comp.udpcount
199#define comp_udpsize ctask->sbe.comp.udpsize
200#define comp_use_global_vartable ctask->sbe.comp.use_global_vartable
201#define comp_stack ctask->sbe.comp.stack
202#define comp_sp ctask->sbe.comp.stack.count
203#define comp_do_close_cmd ctask->sbe.comp.do_close_cmd
204#define comp_unit_flag ctask->sbe.comp.unit_flag
205#define comp_unit_name ctask->sbe.comp.unit_name
206#define comp_first_data_ip ctask->sbe.comp.first_data_ip
207#define comp_file_name ctask->sbe.comp.file_name
208#define tlab prog_labtable
209#define tvar prog_vartable
210#define eval_size eval_stk_size
211#define prog_stack_sp prog_sp
212#define prog_stack_count prog_stack_sp
213
214#undef EXTERN
215
216#include "common/hotspots.h"
217
218/**
219 * @ingroup exec
220 *
221 * create a 'break' - display message, too
222 *
223 * the 'break' will stops the program's execution
224 */
225void brun_break(void);
226
227/**
228 * @ingroup exec
229 *
230 * stops the program's execution
231 */
232void brun_stop(void);
233
234/**
235 * @ingroup exec
236 *
237 * returns the execution status (runing or stopped)
238 *
239 * @return BRUN_STOPPED or BRUN_RUNNING
240 */
241int brun_status(void);
242
243/**
244 * returns the last-modified time of the file
245 *
246 * @param file the filename
247 * @return the last-modified time of the file; on error returns 0L
248 */
249time_t sys_filetime(const char *file);
250
251/**
252 * search a set of directories for the given file
253 * directories on path must be separated with symbol ':'
254 *
255 * @param path the path
256 * @param file the file
257 * @param retbuf a buffer to store the full-path-name file (can be NULL)
258 * @return non-zero if found
259 */
260int sys_search_path(const char *path, const char *file, char *retbuf);
261
262/**
263 * synchronize exported variables
264 */
265void exec_sync_variables(int dir);
266
267#if defined(__cplusplus)
268}
269#endif
270#endif
271