ifndef RefalRTS_H_ define RefalRTS_H_ namespace refalrts typedef enum

  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
#ifndef RefalRTS_H_
#define RefalRTS_H_
namespace refalrts {
typedef enum FnResult {
cRecognitionImpossible = 0,
cNoMemory = 1,
cSuccess = 2,
cExit = 3
} FnResult;
typedef struct Node Node;
typedef struct Node *NodePtr;
typedef struct Node *Iter;
typedef enum DataTag {
cDataIllegal = 0,
cDataSwapHead,
cDataChar,
cDataNumber,
cDataFunction,
cDataIdentifier,
cDataOpenADT, cDataCloseADT,
cDataOpenBracket, cDataCloseBracket,
cDataOpenCall, cDataCloseCall,
cDataFile,
cDataClosure,
cDataUnwrappedClosure,
cDataClosureHead
} DataTag;
typedef FnResult (*RefalFunctionPtr) ( Iter begin, Iter end );
typedef struct RefalFunction {
RefalFunctionPtr ptr;
const char *name;
} RefalFunction;
typedef unsigned long RefalNumber;
typedef const char *(*RefalIdentifier) ();
typedef struct RefalSwapHead {
Iter next_head;
const char *name;
} RefalSwapHead;
typedef struct Node {
NodePtr prev;
NodePtr next;
DataTag tag;
union {
char char_info;
RefalNumber number_info;
RefalFunction function_info;
RefalIdentifier ident_info;
NodePtr link_info;
void *file_info;
RefalSwapHead swap_info;
};
} Node;
typedef enum iCmd {
icChar,
icInt,
icFunc,
icIdent,
icString,
icBracket,
icSpliceSTVar,
icSpliceEVar,
icCopySTVar,
icCopyEVar,
icEnd
} iCmd;
typedef enum BracketType {
ibOpenADT,
ibOpenBracket,
ibOpenCall,
ibCloseADT,
ibCloseBracket,
ibCloseCall
} BracketType;
typedef struct ResultAction {
iCmd cmd;
void *ptr_value1;
void *ptr_value2;
int value;
} ResultAction;
extern void use( Iter& );
// Операции распознавания образца
extern void move_left( Iter& begin, Iter& end );
extern void move_right( Iter& begin, Iter& end );
extern bool empty_seq( Iter begin, Iter end );
extern bool function_left( RefalFunctionPtr func, Iter& first, Iter& last );
extern bool function_right( RefalFunctionPtr func, Iter& first, Iter& last );
extern bool char_left( char ch, Iter& first, Iter& last );
extern bool char_right( char ch, Iter& first, Iter& last );
extern bool number_left( RefalNumber num, Iter& first, Iter& last );
extern bool number_right( RefalNumber num, Iter& first, Iter& last );
extern bool ident_left( RefalIdentifier ident, Iter& first, Iter& last );
extern bool ident_right( RefalIdentifier ident, Iter& first, Iter& last );
extern bool adt_left(
Iter& res_first, Iter& res_last,
RefalFunctionPtr tag,
Iter& first, Iter& last
);
extern bool adt_right(
Iter& res_first, Iter& res_last,
RefalFunctionPtr tag,
Iter& first, Iter& last
);
extern bool brackets_left( Iter& res_first, Iter& res_last, Iter& first, Iter& last );
extern bool brackets_right( Iter& res_first, Iter& res_last, Iter& first, Iter& last );
extern bool svar_left( Iter& svar, Iter& first, Iter& last );
extern bool svar_right( Iter& svar, Iter& first, Iter& last );
extern bool tvar_left( Iter& tvar, Iter& first, Iter& last );
extern bool tvar_right( Iter& tvar, Iter& first, Iter& last );
extern bool next_term( Iter& first, Iter& last );
extern bool repeated_stvar_left( Iter& stvar, Iter stvar_sample, Iter& first, Iter& last );
extern bool repeated_stvar_right( Iter& stvar, Iter stvar_sample, Iter& first, Iter& last );
extern bool repeated_evar_left(
Iter& evar_b, Iter& evar_e,
Iter evar_b_sample, Iter evar_e_sample,
Iter& first, Iter& last
);
extern bool repeated_evar_right(
Iter& evar_b, Iter& evar_e,
Iter evar_b_sample, Iter evar_e_sample,
Iter& first, Iter& last
);
extern unsigned read_chars(
char buffer[], unsigned buflen, Iter& first, Iter& last
);
// Операции построения результата
extern void reset_allocator();
extern bool copy_evar(
Iter& evar_res_b, Iter& evar_res_e, Iter evar_b_sample, Iter evar_e_sample
);
extern bool copy_stvar( Iter& stvar_res, Iter stvar_sample );
extern bool alloc_char( Iter& res, char ch );
extern bool alloc_number( Iter& res, RefalNumber num );
extern bool alloc_name(
Iter& res, RefalFunctionPtr func, const char *name = ""
);
extern bool alloc_ident( Iter& res, RefalIdentifier ident );
extern bool alloc_open_adt( Iter& res );
extern bool alloc_close_adt( Iter& res );
extern bool alloc_open_bracket( Iter& res );
extern bool alloc_close_bracket( Iter& res );
extern bool alloc_open_call( Iter& res );
extern bool alloc_close_call( Iter& res );
extern bool alloc_chars(
Iter& res_b, Iter& res_e, const char buffer[], unsigned buflen
);
extern bool alloc_string( Iter& res_b, Iter& res_e, const char *string );
extern void push_stack( Iter call_bracket );
extern void link_brackets( Iter left, Iter right );
extern Iter splice_elem( Iter res, Iter elem );
extern Iter splice_stvar( Iter res, Iter var );
extern Iter splice_evar( Iter res, Iter first, Iter last );
extern void splice_to_freelist( Iter first, Iter last );
extern FnResult create_closure( Iter begin, Iter end );
Iter unwrap_closure( Iter closure ); // Развернуть замыкание
Iter wrap_closure( Iter closure ); // Свернуть замыкание
// Работа со статическими ящиками
extern Iter initialize_swap_head( Iter head );
extern void swap_info_bounds( Iter& first, Iter& last, Iter head );
extern void swap_save( Iter head, Iter first, Iter last );
// Профилирование
extern void this_is_generated_function();
// Прочие функции
extern void set_return_code( int retcode );
// Интерпретатор
extern FnResult interpret_array(
const ResultAction raa[],
Iter allocs[],
Iter begin,
Iter end
);
} //namespace refalrts
#endif //RefalRTS_H_