forked from cotillion/cd-gamedriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpret.h
185 lines (162 loc) · 4.95 KB
/
interpret.h
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
#ifndef INTERPRET_H
#define INTERPRET_H
#include <stdint.h>
#include <stddef.h>
#include <setjmp.h>
#include "config.h"
#include "exec.h"
#include "simulate.h"
#define push_svalue(val) \
{ \
if (sp + 1 >= &start_of_stack[EVALUATOR_STACK_SIZE]) \
error("Stack overflow\n"); \
sp++; \
assign_svalue_no_free(sp, val); \
}
union u {
char *string;
long long number;
double real;
struct object *ob;
struct vector *vec;
struct svalue *lvalue;
struct mapping *map;
struct closure *func;
};
/*
* The value stack element.
* If it is a string, then the way that the string has been allocated differ,
* wich will affect how it should be freed.
*/
struct svalue {
short type;
short string_type;
union u u;
};
extern struct svalue *sp;
extern struct svalue start_of_stack[];
#define T_INVALID 0x0
#define T_LVALUE 0x1
#define T_NUMBER 0x2
#define T_STRING 0x4
#define T_POINTER 0x8
#define T_OBJECT 0x10
#define T_MAPPING 0x20
#define T_FLOAT 0x40
#define T_FUNCTION 0x80
#define STRING_MSTRING 0 /* Allocated by malloc() */
#define STRING_SSTRING 1 /* Allocated by the shared string library */
#define STRING_CSTRING 2 /* Do not has to be freed at all */
struct vector {
unsigned int size;
unsigned int ref;
#ifdef DEBUG
int extra_ref;
#endif
struct svalue item[1];
};
#define ALLOC_VECTOR(nelem) \
(struct vector *)xalloc(sizeof (struct vector) + \
sizeof(struct svalue) * (nelem - 1))
/*
* Function stuff.
*/
struct closure {
#ifdef FUNCDEBUG
int magic;
#define FUNMAGIC 0xdeadbeef
struct closure *next;
struct object *from;
#endif
unsigned int ref; /* reference counter */
char funtype;
#define FUN_LFUN 1
#define FUN_SFUN 2
#define FUN_EFUN 3
#define FUN_LFUNO 4
#define FUN_COMPOSE 5 /* used for compositions */
#define FUN_EMPTY 6 /* used for empty argument slots */
#define FUN_LFUN_NOMASK 7 /* used for nomask functions */
unsigned short funno, funinh; /* function no, and inherit no. used in call */
struct object *funobj; /* object where function is, or 0 */
struct vector *funargs; /* function arguments, or 0 */
/* "empty" argument slots in the argument array contain
function nodes with the FUN_EMPTY tag */
};
/*
* Control stack element.
* 'prog' is usually same as 'ob->prog' (current_object), except when
* when the current function is defined by inheritance.
* The pointer, csp, will point to the values that will be used at return.
*/
struct control_stack {
struct object *ob; /* Current object */
struct object *prev_ob; /* Save previous object */
struct program *prog; /* Current program */
int num_local_variables; /* Local + arguments */
offset_t pc;
offset_t pc_save;
struct svalue *fp;
int extern_call; /* Flag if evaluator should return */
struct function *funp; /* Only used for tracebacks */
int inh_offset;
char ext_call;
#if defined(PROFILE_LPC)
double startcpu;
double frame_cpu;
double frame_start;
#endif
};
/*
* The following structure is used to create a linked-lists of
* exception frames threaded through the C stack. When an error
* recovery context is desired, a local exception frame is allocated
* on the stack, To create an error recovery context, initialize
* the local exception frame and append it to the list. To restore
* the previous context, remove the frame from the list.
*/
struct gdexception {
struct gdexception *e_exception;
int e_catch;
jmp_buf e_context;
};
/*
* Boolean Type
*/
typedef int bool_t;
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
extern struct gdexception *exception;
extern struct svalue const0, const1, constempty;
extern int variable_index_found;
extern int variable_inherit_found;
extern int variable_type_mod_found;
extern int function_index_found;
extern struct program *function_prog_found;
extern unsigned short function_type_mod_found;
extern int function_inherit_found;
extern struct control_stack *csp; /* Points to last element pushed */
#define INCREF(x) if (x) x++
#define DECREF(x) if (x) x--
void bad_arg(int arg, int instr, struct svalue *sv);
void bad_arg_op(int instr, struct svalue *arg1, struct svalue *arg2);
void push_pop_error_context(int push);
void pop_stack(void);
int search_for_function(char *name, struct program *prog);
void free_closure(struct closure *f);
void push_control_stack(struct object*, struct program *, struct function *funp);
void pop_control_stack(void);
void push_float (double d);
void push_vector(struct vector*i, bool_t);
void push_string (char *, int);
void push_mstring (char *);
void push_number (long long);
void push_object (struct object *);
#ifdef DEALLOCATE_MEMORY_AT_SHUTDOWN
void clear_closure_cache(void);
#endif
#endif