Menu

[b84aab]: / src / common / bc.h  Maximize  Restore  History

Download this file

259 lines (231 with data), 5.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// This file is part of SmallBASIC
//
// bc module. Bytecode manipulation routines (bytecode segments API)
//
// This program is distributed under the terms of the GPL v2.0 or later
// Download the GNU Public License (GPL) from www.gnu.org
//
// Copyright(C) 2000 Nicholas Christopoulos
#if !defined(_bc_h)
#define _bc_h
#include "common/sys.h"
#include "common/pmem.h"
#include "common/kw.h"
#define BC_ALLOC_INCR 1024
#if defined(OS_ADDR16)
#define BC_MAX_STORE_SIZE 0x7FFF
#else
#define BC_MAX_STORE_SIZE 0x7FFFFFFF
#endif
/**
* @ingroup scan
* @typedef bc_t
*
* byte-code segment
*/
typedef struct {
MemHandle mem_h; /**< memory handle (if it is used) */
code_t *ptr; /**< pointer to byte-code */
addr_t cp; /**< current position (used by readers not writers) */
addr_t size; /**< allocation size (optimization) */
addr_t count; /**< current size (used by writers as the current position) */
} bc_t;
/**
* @ingroup scan
*
* raise compiler error
*
* @param fmt the printf's format
* @param ... format's parameters
*/
void sc_raise(const char *fmt, ...) SEC(BCSCAN);
/**
* @ingroup scan
*
* create a byte-code segment
*
* @param bc the bc structure
*/
void bc_create(bc_t * bc) SEC(BCSCAN);
/**
* @ingroup scan
*
* destroy a byte-code segment
*
* @param bc the bc structure
*/
void bc_destroy(bc_t * bc) SEC(BCSCAN);
/**
* @ingroup scan
*
* resize a byte-code segment
*
* @param bc the bc structure
* @param newsize the new size
*/
void bc_resize(bc_t * bc, dword newsize) SEC(BCSCAN);
/**
* @ingroup scan
*
* add 1 byte to segment
*
* @param bc the bc structure
* @param code the byte
*/
void bc_add1(bc_t * bc, byte code) SEC(BCSCAN);
/**
* @ingroup scan
*
* put 1 byte to specified offset
*
* @param bc the bc structure
* @param code the byte
*/
void bc_store1(bc_t * bc, addr_t offset, byte code) SEC(BCSCAN);
/**
* @ingroup scan
*
* add 1 word (2-bytes) to segment
*
* @param bc the bc structure
* @param code the word
*/
void bc_add_word(bc_t * bc, word code) SEC(BCSCAN);
/**
* @ingroup scan
*
* add 1 dword (4-bytes) to segment
*
* @param bc the bc structure
* @param code the dword
*/
void bc_add_dword(bc_t * bc, dword code) SEC(BCSCAN);
/**
* @ingroup scan
*
* strores a string in the segment
*
* @param bc the bc structure
* @param str the raw-string. the string must starts with \". the string must also contains the ending \".
* @return a pointer of src to the next character after the second \"
*/
char *bc_store_string(bc_t * bc, char *src) SEC(BCSCAN);
/**
* @ingroup scan
*
* strores a string in the segment
*
* @param bc the bc structure
* @param str the raw-string. the string must starts with `. the string must also contains the ending `.
* @return a pointer of src to the next character after the second `
*/
char *bc_store_macro(bc_t * bc, char *src) SEC(BCSCAN);
/**
* @ingroup scan
*
* adds an EOC (end-of-command) mark to segment
*
* @param bc the bc structure
*/
void bc_eoc(bc_t * bc) SEC(BCSCAN);
/**
* @ingroup scan
*
* joins two bc segments
*
* @param dest the destination
* @param src the code to be appended to dest
*/
void bc_append(bc_t * dest, bc_t * src) SEC(BCSCAN);
/**
* @ingroup scan
*
* joins two bc segments
*
* @param dest the destination
* @param src the code to be appended to dest
* @param n the size of the src to be copied
*/
void bc_add_n(bc_t * dest, byte * src, dword n) SEC(BCSCAN);
/**
* @ingroup scan
* add a code
*/
#define bc_add_code(d,i) bc_add1((d),(i))
/**
* @ingroup scan
*
* add a buildin function
*
* @param dest the bc segment
* @param idx the index of the function
*/
void bc_add_fcode(bc_t * dest, long idx) SEC(BCSCAN);
/**
* @ingroup scan
*
* add a buildin procedure
*
* @param dest the bc segment
* @param idx the index of the procedure
*/
void bc_add_pcode(bc_t * dest, long idx) SEC(BCSCAN);
/**
* @ingroup scan
*
* add an external function
*
* @param dest the bc segment
* @param lib the index of the library
* @param idx the index of the function
*/
void bc_add_extfcode(bc_t * dest, int lib, long idx) SEC(BCSCAN);
/**
* @ingroup scan
*
* add an external procedure
*
* @param dest the bc segment
* @param lib the index of the library
* @param idx the index of the procedure
*/
void bc_add_extpcode(bc_t * dest, int lib, long idx) SEC(BCSCAN);
/**
* @ingroup scan
*
* add an address
*
* @param bc the bc segment
* @param idx the address
*/
void bc_add_addr(bc_t * bc, addr_t idx) SEC(BCSCAN);
/**
* @ingroup scan
*
* add a control-code (if, repeat, while)
*
* @param bc the bc segment
* @param code the control's index
* @param true_ip the jump-address when on true
* @param false_ip the jump-address when on false
*/
void bc_add_ctrl(bc_t * bc, code_t code, addr_t true_ip, addr_t false_ip) SEC(BCSCAN);
/**
* @ingroup scan
*
* add a real number
*
* @param bc the bc segment
* @param v the number
*/
void bc_add_creal(bc_t * bc, var_num_t v) SEC(BCSCAN);
/**
* @ingroup scan
*
* add an integer number
*
* @param bc the bc segment
* @param v the number
*/
void bc_add_cint(bc_t * bc, var_int_t v) SEC(BCSCAN);
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.