64 |
out_hash= out_hash%HASHTBLSIZE; |
out_hash= out_hash%HASHTBLSIZE; |
65 |
position= &(in_hashtbl[out_hash]); |
position= &(in_hashtbl[out_hash]); |
66 |
|
|
67 |
while(position != NULL){ |
while(1){ |
68 |
if(*position==NULL) /* If empty */ |
if(*position==NULL) /* If empty */ |
69 |
return position; |
return position; |
70 |
|
|
73 |
|
|
74 |
position= &((*position)->next); /* Try next */ |
position= &((*position)->next); /* Try next */ |
75 |
} |
} |
|
return NULL; /* end of list reached without finding |
|
|
an empty position */ |
|
76 |
} |
} |
77 |
|
|
78 |
/* Generic push function. */ |
/* Generic push function. */ |
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); |
222 |
printf("\"%s\"", (char*)temp->content.ptr); |
printf("\"%s\"", (char*)temp->content.ptr); |
223 |
break; |
break; |
224 |
case symbol: |
case symbol: |
225 |
|
case func: |
226 |
printf("%s", temp->id); |
printf("%s", temp->id); |
227 |
break; |
break; |
228 |
default: |
default: |
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 |
{ |
{ |