160 |
else |
else |
161 |
def_sym(in_hash, in_string); /* Make symbol */ |
def_sym(in_hash, in_string); /* Make symbol */ |
162 |
|
|
163 |
new_item->content.ptr= *hash(in_hash, in_string); /* XXX */ |
new_item->content.ptr= *hash(in_hash, in_string); /* The new reference |
164 |
|
shouldn't point at |
165 |
|
NULL */ |
166 |
new_item->type= ref; |
new_item->type= ref; |
167 |
} |
} |
168 |
|
|
198 |
} |
} |
199 |
|
|
200 |
/* Prints the top element of the stack. */ |
/* Prints the top element of the stack. */ |
201 |
void print_(stackitem** stack_head) |
extern void print_(stackitem** stack_head) |
202 |
{ |
{ |
203 |
if((*stack_head)==NULL) { |
stackitem* temp= *stack_head; |
204 |
|
|
205 |
|
if(temp==NULL) { |
206 |
printerr("Stack empty"); |
printerr("Stack empty"); |
207 |
return; |
return; |
208 |
} |
} |
209 |
|
|
210 |
switch((*stack_head)->type) { |
while(temp->type==ref) |
211 |
|
temp= temp->content.ptr; |
212 |
|
|
213 |
|
switch(temp->type) { |
214 |
case value: |
case value: |
215 |
printf("%d", (*stack_head)->content.val); |
printf("%d", temp->content.val); |
216 |
break; |
break; |
217 |
case string: |
case string: |
218 |
printf("%s", (char*)(*stack_head)->content.ptr); |
printf("\"%s\"", (char*)temp->content.ptr); |
|
break; |
|
|
case ref: |
|
|
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
|
219 |
break; |
break; |
220 |
case symbol: |
case symbol: |
221 |
|
printf("%s", temp->id); |
222 |
|
break; |
223 |
default: |
default: |
224 |
printf("%p", (*stack_head)->content.ptr); |
printf("%p", temp->content.ptr); |
225 |
break; |
break; |
226 |
} |
} |
227 |
} |
} |
249 |
{ |
{ |
250 |
if(*stack_head != NULL) { |
if(*stack_head != NULL) { |
251 |
print_st(*stack_head, 1); |
print_st(*stack_head, 1); |
252 |
printf("\n"); |
nl(); |
253 |
} else { |
} else { |
254 |
printerr("Stack empty"); |
printerr("Stack empty"); |
255 |
} |
} |
260 |
extern void eval(stackitem** stack_head) |
extern void eval(stackitem** stack_head) |
261 |
{ |
{ |
262 |
funcp in_func; |
funcp in_func; |
263 |
|
stackitem* temp= *stack_head; |
264 |
|
|
265 |
if((*stack_head)==NULL || (*stack_head)->type!=ref) { |
if(temp==NULL) { |
266 |
printerr("Stack empty or not a reference"); |
printerr("Stack empty"); |
267 |
return; |
return; |
268 |
} |
} |
269 |
|
|
270 |
if(((stackitem*)(*stack_head)->content.ptr)->type==func) { |
while(temp->type==ref) |
271 |
in_func= (funcp)((stackitem*)(*stack_head)->content.ptr)->content.ptr; |
temp= temp->content.ptr; |
272 |
|
|
273 |
|
if(temp->type==func) { |
274 |
|
in_func= (funcp)(temp->content.ptr); |
275 |
toss(stack_head); |
toss(stack_head); |
276 |
(*in_func)(stack_head); |
(*in_func)(stack_head); |
277 |
return; |
return; |
278 |
} else |
} |
279 |
printerr("Not a function"); |
|
280 |
|
printerr("Couldn't evaluate"); |
281 |
} |
} |
282 |
|
|
283 |
/* Make a list. */ |
/* Make a list. */ |
346 |
break; |
break; |
347 |
} |
} |
348 |
/* If symbol */ |
/* If symbol */ |
349 |
if((convert= sscanf(in_line, "%[^] ;\n\r]%[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "%[^][ ;\n\r]%[^\n\r]", temp, rest))) { |
350 |
push_ref(stack_head, in_hash, temp); |
push_ref(stack_head, in_hash, temp); |
351 |
break; |
break; |
352 |
} |
} |
353 |
/* If single char */ |
/* If single char */ |
354 |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { |
355 |
if(*temp==';') { |
if(*temp==';') { |
356 |
if(non_eval_flag) { |
if(!non_eval_flag) { |
357 |
eval(stack_head); /* Evaluate top element */ |
eval(stack_head); /* Evaluate top element */ |
358 |
break; |
break; |
359 |
} |
} |
365 |
if(*temp==']') { |
if(*temp==']') { |
366 |
push_ref(stack_head, in_hash, "["); |
push_ref(stack_head, in_hash, "["); |
367 |
pack(stack_head); |
pack(stack_head); |
368 |
non_eval_flag--; |
if(non_eval_flag!=0) |
369 |
|
non_eval_flag--; |
370 |
break; |
break; |
371 |
} |
} |
372 |
|
|