11 |
|
|
12 |
typedef struct stack_item |
typedef struct stack_item |
13 |
{ |
{ |
14 |
enum {value, string, ref, func, symbol} type; |
enum {value, string, ref, func, symbol, list} type; |
15 |
union { |
union { |
16 |
void* ptr; |
void* ptr; |
17 |
int val; |
int val; |
128 |
new_item->content.ptr= *hash(in_hash, in_string); |
new_item->content.ptr= *hash(in_hash, in_string); |
129 |
new_item->type= ref; |
new_item->type= ref; |
130 |
|
|
|
if(handle==NULL) |
|
|
handle= dlopen(NULL, RTLD_LAZY); |
|
|
|
|
131 |
if(new_item->content.ptr==NULL) { |
if(new_item->content.ptr==NULL) { |
132 |
|
if(handle==NULL) |
133 |
|
handle= dlopen(NULL, RTLD_LAZY); |
134 |
|
|
135 |
symbol= dlsym(handle, in_string); |
symbol= dlsym(handle, in_string); |
136 |
if(dlerror()==NULL) |
if(dlerror()==NULL) |
137 |
def_func(in_hash, symbol, in_string); |
def_func(in_hash, symbol, in_string); |
150 |
{ |
{ |
151 |
stackitem* temp= *stack_head; |
stackitem* temp= *stack_head; |
152 |
|
|
153 |
|
if((*stack_head)==NULL) |
154 |
|
return; |
155 |
|
|
156 |
|
if((*stack_head)->type==string) |
157 |
|
free((*stack_head)->content.ptr); |
158 |
|
|
159 |
*stack_head= (*stack_head)->next; |
*stack_head= (*stack_head)->next; |
160 |
free(temp); |
free(temp); |
161 |
} |
} |
162 |
|
|
163 |
|
extern void nl() |
164 |
|
{ |
165 |
|
printf("\n"); |
166 |
|
} |
167 |
|
|
168 |
/* print_stack(stack); */ |
void print_(stackitem** stack_head) |
169 |
void print_st(stackitem* stack_head, long counter) |
{ |
170 |
{ |
if((*stack_head)==NULL) |
171 |
if(stack_head->next != NULL) |
return; |
|
print_st(stack_head->next, counter+1); |
|
172 |
|
|
173 |
switch(stack_head->type){ |
switch((*stack_head)->type) { |
174 |
case value: |
case value: |
175 |
printf("%ld: %d\n", counter, (int)stack_head->content.val); |
printf("%d", (*stack_head)->content.val); |
176 |
break; |
break; |
177 |
case string: |
case string: |
178 |
printf("%ld: \"%s\"\n", counter, (char*)stack_head->content.ptr); |
printf("%s", (char*)(*stack_head)->content.ptr); |
179 |
break; |
break; |
180 |
case ref: |
case ref: |
181 |
printf("%ld: %s\n", counter, ((stackitem*)stack_head->content.ptr)->id); |
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
182 |
break; |
break; |
|
case func: |
|
183 |
case symbol: |
case symbol: |
184 |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
default: |
185 |
|
printf("%p", (*stack_head)->content.ptr); |
186 |
break; |
break; |
187 |
} |
} |
188 |
} |
} |
189 |
|
|
190 |
|
extern void print(stackitem** stack_head) |
191 |
|
{ |
192 |
|
print_(stack_head); |
193 |
|
toss(stack_head); |
194 |
|
} |
195 |
|
|
196 |
|
/* print_stack(stack); */ |
197 |
|
void print_st(stackitem* stack_head, long counter) |
198 |
|
{ |
199 |
|
if(stack_head->next != NULL) |
200 |
|
print_st(stack_head->next, counter+1); |
201 |
|
|
202 |
|
printf("%ld: ", counter); |
203 |
|
print_(&stack_head); |
204 |
|
nl(); |
205 |
|
} |
206 |
|
|
207 |
extern void printstack(stackitem** stack_head) |
extern void printstack(stackitem** stack_head) |
208 |
{ |
{ |
209 |
if(*stack_head != NULL) { |
if(*stack_head != NULL) { |
261 |
return 1; |
return 1; |
262 |
} |
} |
263 |
|
|
264 |
extern void print(stackitem** stack_head) |
extern void pack(stackitem** stack_head) |
265 |
{ |
{ |
266 |
|
void* delimiter; |
267 |
|
stackitem *iterator, *temp, *pack; |
268 |
|
|
269 |
if((*stack_head)==NULL) |
if((*stack_head)==NULL) |
270 |
return; |
return; |
271 |
|
|
272 |
switch((*stack_head)->type){ |
delimiter= (*stack_head)->content.ptr; |
273 |
case value: |
toss(stack_head); |
274 |
printf("%d", (*stack_head)->content.val); |
|
275 |
break; |
iterator= *stack_head; |
276 |
case string: |
|
277 |
printf("%s", (char*)(*stack_head)->content.ptr); |
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
278 |
break; |
iterator= iterator->next; |
279 |
case ref: |
|
280 |
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
temp= *stack_head; |
281 |
break; |
*stack_head= iterator->next; |
282 |
case symbol: |
iterator->next= NULL; |
283 |
default: |
|
284 |
printf("%p", (*stack_head)->content.ptr); |
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
285 |
break; |
toss(stack_head); |
286 |
} |
|
287 |
|
pack= malloc(sizeof(stackitem)); |
288 |
|
pack->type= list; |
289 |
|
pack->content.ptr= temp; |
290 |
|
|
291 |
|
push(stack_head, pack); |
292 |
|
} |
293 |
|
|
294 |
|
extern void expand(stackitem** stack_head) |
295 |
|
{ |
296 |
|
stackitem *temp, *new_head; |
297 |
|
|
298 |
|
if((*stack_head)==NULL || (*stack_head)->type!=list) |
299 |
|
return; |
300 |
|
|
301 |
|
new_head= temp= (*stack_head)->content.ptr; |
302 |
toss(stack_head); |
toss(stack_head); |
303 |
|
|
304 |
|
while(temp->next!=NULL) |
305 |
|
temp= temp->next; |
306 |
|
|
307 |
|
temp->next= *stack_head; |
308 |
|
*stack_head= new_head; |
309 |
} |
} |
310 |
|
|
311 |
extern void nl() |
extern void swap(stackitem** stack_head) |
312 |
{ |
{ |
313 |
printf("\n"); |
stackitem* temp= (*stack_head); |
314 |
|
|
315 |
|
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
316 |
|
return; |
317 |
|
|
318 |
|
*stack_head= (*stack_head)->next; |
319 |
|
temp->next= (*stack_head)->next; |
320 |
|
(*stack_head)->next= temp; |
321 |
|
} |
322 |
|
|
323 |
|
extern void eq(stackitem** stack_head) |
324 |
|
{ |
325 |
|
void *left, *right; |
326 |
|
int result; |
327 |
|
|
328 |
|
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
329 |
|
return; |
330 |
|
|
331 |
|
left= (*stack_head)->content.ptr; |
332 |
|
right= (*stack_head)->next->content.ptr; |
333 |
|
result= (left==right); |
334 |
|
|
335 |
|
toss(stack_head); toss(stack_head); |
336 |
|
push_val(stack_head, (left==right)); |
337 |
|
} |
338 |
|
|
339 |
|
extern void not(stackitem** stack_head) |
340 |
|
{ |
341 |
|
int value; |
342 |
|
|
343 |
|
if((*stack_head)==NULL) |
344 |
|
return; |
345 |
|
|
346 |
|
value= (*stack_head)->content.val; |
347 |
|
toss(stack_head); |
348 |
|
push_val(stack_head, !value); |
349 |
|
} |
350 |
|
|
351 |
|
extern void neq(stackitem** stack_head) |
352 |
|
{ |
353 |
|
eq(stack_head); |
354 |
|
not(stack_head); |
355 |
} |
} |
356 |
|
|
357 |
extern void quit() |
extern void quit() |
374 |
printf("okidok\n "); |
printf("okidok\n "); |
375 |
} |
} |
376 |
|
|
377 |
|
exit(EXIT_SUCCESS); |
|
return EXIT_SUCCESS; |
|
378 |
} |
} |
379 |
|
|
380 |
/* Local Variables: */ |
/* Local Variables: */ |