46 |
out_hash[i]= NULL; |
out_hash[i]= NULL; |
47 |
} |
} |
48 |
|
|
49 |
/* Returns a pointer to an element in the hash table. */ |
/* Returns a pointer to a pointer to an element in the hash table. */ |
50 |
stackitem** hash(hashtbl in_hashtbl, const char* in_string) |
stackitem** hash(hashtbl in_hashtbl, const char* in_string) |
51 |
{ |
{ |
52 |
long i= 0; |
long i= 0; |
205 |
return; |
return; |
206 |
} |
} |
207 |
|
|
208 |
while(temp->type==ref) |
while(temp->type==ref) { |
209 |
temp= temp->content.ptr; |
temp= temp->content.ptr; |
210 |
|
|
211 |
|
if(temp->type!=ref) { |
212 |
|
printf("ref-> %s", temp->id); |
213 |
|
return; |
214 |
|
} |
215 |
|
} |
216 |
|
|
217 |
switch(temp->type) { |
switch(temp->type) { |
218 |
case value: |
case value: |
219 |
printf("%d", temp->content.val); |
printf("%d", temp->content.val); |
260 |
} |
} |
261 |
} |
} |
262 |
|
|
263 |
|
/* Swap the two top elements on the stack. */ |
264 |
|
extern void swap(stackitem** stack_head) |
265 |
|
{ |
266 |
|
stackitem* temp= (*stack_head); |
267 |
|
|
268 |
|
if((*stack_head)==NULL) { |
269 |
|
printerr("Stack empty"); |
270 |
|
return; |
271 |
|
} |
272 |
|
|
273 |
|
if((*stack_head)->next==NULL) |
274 |
|
return; |
275 |
|
|
276 |
|
*stack_head= (*stack_head)->next; |
277 |
|
temp->next= (*stack_head)->next; |
278 |
|
(*stack_head)->next= temp; |
279 |
|
} |
280 |
|
|
281 |
|
stackitem* copy(stackitem* in_item) |
282 |
|
{ |
283 |
|
stackitem* out_item= malloc(sizeof(stackitem)); |
284 |
|
|
285 |
|
memcpy(out_item, in_item, sizeof(stackitem)); |
286 |
|
out_item->next= NULL; |
287 |
|
|
288 |
|
return out_item; |
289 |
|
} |
290 |
|
|
291 |
|
|
292 |
/* If the top element is a reference, determine if it's a reference to a |
/* If the top element is a reference, determine if it's a reference to a |
293 |
function, and if it is, toss the reference and execute the function. */ |
function, and if it is, toss the reference and execute the function. */ |
294 |
extern void eval(stackitem** stack_head) |
extern void eval(stackitem** stack_head) |
309 |
toss(stack_head); |
toss(stack_head); |
310 |
(*in_func)(stack_head); |
(*in_func)(stack_head); |
311 |
return; |
return; |
312 |
} |
} |
313 |
|
|
314 |
printerr("Couldn't evaluate"); |
push(stack_head, copy(temp)); |
315 |
|
swap(stack_head); |
316 |
|
toss(stack_head); |
317 |
} |
} |
318 |
|
|
319 |
/* Make a list. */ |
/* Make a list. */ |
455 |
*stack_head= new_head; /* ...and voila! */ |
*stack_head= new_head; /* ...and voila! */ |
456 |
} |
} |
457 |
|
|
|
/* Swap the two top elements on the stack. */ |
|
|
extern void swap(stackitem** stack_head) |
|
|
{ |
|
|
stackitem* temp= (*stack_head); |
|
|
|
|
|
if((*stack_head)==NULL) { |
|
|
printerr("Stack empty"); |
|
|
return; |
|
|
} |
|
|
|
|
|
if((*stack_head)->next==NULL) |
|
|
return; |
|
|
|
|
|
*stack_head= (*stack_head)->next; |
|
|
temp->next= (*stack_head)->next; |
|
|
(*stack_head)->next= temp; |
|
|
} |
|
|
|
|
458 |
/* Compares two elements by reference. */ |
/* Compares two elements by reference. */ |
459 |
extern void eq(stackitem** stack_head) |
extern void eq(stackitem** stack_head) |
460 |
{ |
{ |
548 |
|
|
549 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
550 |
} |
} |
|
|
|
|
/* Local Variables: */ |
|
|
/* compile-command:"make CFLAGS=\"-Wall -g -rdynamic -ldl\" stack" */ |
|
|
/* End: */ |
|