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; |
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 |
} |
} |
179 |
break; |
break; |
180 |
case func: |
case func: |
181 |
case symbol: |
case symbol: |
182 |
|
default: |
183 |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
184 |
break; |
break; |
185 |
} |
} |
266 |
toss(stack_head); |
toss(stack_head); |
267 |
} |
} |
268 |
|
|
269 |
|
extern void pack(stackitem** stack_head) |
270 |
|
{ |
271 |
|
void* delimiter; |
272 |
|
stackitem *iterator, *temp, *pack; |
273 |
|
|
274 |
|
if((*stack_head)==NULL) |
275 |
|
return; |
276 |
|
|
277 |
|
delimiter= (*stack_head)->content.ptr; |
278 |
|
toss(stack_head); |
279 |
|
|
280 |
|
iterator= *stack_head; |
281 |
|
|
282 |
|
while(iterator->next!=NULL && iterator->next->content.ptr!=delimiter) |
283 |
|
iterator= iterator->next; |
284 |
|
|
285 |
|
temp= *stack_head; |
286 |
|
*stack_head= iterator->next; |
287 |
|
iterator->next= NULL; |
288 |
|
|
289 |
|
if(*stack_head!=NULL && (*stack_head)->content.ptr==delimiter) |
290 |
|
toss(stack_head); |
291 |
|
|
292 |
|
pack= malloc(sizeof(stackitem)); |
293 |
|
pack->type= list; |
294 |
|
pack->content.ptr= temp; |
295 |
|
|
296 |
|
push(stack_head, pack); |
297 |
|
} |
298 |
|
|
299 |
|
|
300 |
extern void nl() |
extern void nl() |
301 |
{ |
{ |
302 |
printf("\n"); |
printf("\n"); |