| 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); |
| 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 |
default: |
default: |
| 185 |
printf("%ld: %p\n", counter, stack_head->content.ptr); |
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) { |
| 242 |
push_cstring(stack_head, temp); |
push_cstring(stack_head, temp); |
| 243 |
else if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest)) >= 1) |
else if((convert= sscanf(in_line, "%d %[^\n\r]", &itemp, rest)) >= 1) |
| 244 |
push_val(stack_head, itemp); |
push_val(stack_head, itemp); |
| 245 |
else if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest)) >= 1) |
else if((convert= sscanf(in_line, "\\%c%[^\n\r]", temp, rest)) >= 1) { |
| 246 |
|
temp[1]= '\0'; push_ref(stack_head, in_hash, temp); |
| 247 |
|
} else if((convert= sscanf(in_line, "%[^ ;\n\r]%[^\n\r]", temp, rest)) >= 1) |
| 248 |
push_ref(stack_head, in_hash, temp); |
push_ref(stack_head, in_hash, temp); |
| 249 |
else if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) >= 1) |
else if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest)) >= 1) |
| 250 |
if(*temp==';') |
if(*temp==';') |
| 263 |
return 1; |
return 1; |
| 264 |
} |
} |
| 265 |
|
|
|
extern void print(stackitem** stack_head) |
|
|
{ |
|
|
if((*stack_head)==NULL) |
|
|
return; |
|
|
|
|
|
switch((*stack_head)->type){ |
|
|
case value: |
|
|
printf("%d", (*stack_head)->content.val); |
|
|
break; |
|
|
case string: |
|
|
printf("%s", (char*)(*stack_head)->content.ptr); |
|
|
break; |
|
|
case ref: |
|
|
printf("%s", ((stackitem*)(*stack_head)->content.ptr)->id); |
|
|
break; |
|
|
case symbol: |
|
|
default: |
|
|
printf("%p", (*stack_head)->content.ptr); |
|
|
break; |
|
|
} |
|
|
|
|
|
toss(stack_head); |
|
|
} |
|
|
|
|
| 266 |
extern void pack(stackitem** stack_head) |
extern void pack(stackitem** stack_head) |
| 267 |
{ |
{ |
| 268 |
void* delimiter; |
void* delimiter; |
| 292 |
|
|
| 293 |
push(stack_head, pack); |
push(stack_head, pack); |
| 294 |
} |
} |
| 295 |
|
|
| 296 |
|
extern void expand(stackitem** stack_head) |
| 297 |
|
{ |
| 298 |
|
stackitem *temp, *new_head; |
| 299 |
|
|
| 300 |
|
if((*stack_head)==NULL || (*stack_head)->type!=list) |
| 301 |
|
return; |
| 302 |
|
|
| 303 |
|
new_head= temp= (*stack_head)->content.ptr; |
| 304 |
|
toss(stack_head); |
| 305 |
|
|
| 306 |
|
while(temp->next!=NULL) |
| 307 |
|
temp= temp->next; |
| 308 |
|
|
| 309 |
|
temp->next= *stack_head; |
| 310 |
|
*stack_head= new_head; |
| 311 |
|
} |
| 312 |
|
|
| 313 |
|
extern void swap(stackitem** stack_head) |
| 314 |
|
{ |
| 315 |
|
stackitem* temp= (*stack_head); |
| 316 |
|
|
| 317 |
|
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
| 318 |
|
return; |
| 319 |
|
|
| 320 |
extern void nl() |
*stack_head= (*stack_head)->next; |
| 321 |
|
temp->next= (*stack_head)->next; |
| 322 |
|
(*stack_head)->next= temp; |
| 323 |
|
} |
| 324 |
|
|
| 325 |
|
extern void eq(stackitem** stack_head) |
| 326 |
{ |
{ |
| 327 |
printf("\n"); |
void *left, *right; |
| 328 |
|
int result; |
| 329 |
|
|
| 330 |
|
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
| 331 |
|
return; |
| 332 |
|
|
| 333 |
|
left= (*stack_head)->content.ptr; |
| 334 |
|
swap(stack_head); |
| 335 |
|
right= (*stack_head)->content.ptr; |
| 336 |
|
result= (left==right); |
| 337 |
|
|
| 338 |
|
toss(stack_head); toss(stack_head); |
| 339 |
|
push_val(stack_head, (left==right)); |
| 340 |
|
} |
| 341 |
|
|
| 342 |
|
extern void not(stackitem** stack_head) |
| 343 |
|
{ |
| 344 |
|
int value; |
| 345 |
|
|
| 346 |
|
if((*stack_head)==NULL) |
| 347 |
|
return; |
| 348 |
|
|
| 349 |
|
value= (*stack_head)->content.val; |
| 350 |
|
toss(stack_head); |
| 351 |
|
push_val(stack_head, !value); |
| 352 |
} |
} |
| 353 |
|
|
| 354 |
|
extern void neq(stackitem** stack_head) |
| 355 |
|
{ |
| 356 |
|
eq(stack_head); |
| 357 |
|
not(stack_head); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
extern void def(stackitem** stack_head) |
| 361 |
|
{ |
| 362 |
|
stackitem *temp, *value; |
| 363 |
|
|
| 364 |
|
if(*stack_head==NULL || (*stack_head)->next==NULL |
| 365 |
|
|| (*stack_head)->type!=ref) |
| 366 |
|
return; |
| 367 |
|
|
| 368 |
|
temp= (*stack_head)->content.ptr; |
| 369 |
|
value= (*stack_head)->next; |
| 370 |
|
temp->content= value->content; |
| 371 |
|
value->content.ptr=NULL; |
| 372 |
|
temp->type= value->type; |
| 373 |
|
|
| 374 |
|
toss(stack_head); toss(stack_head); |
| 375 |
|
} |
| 376 |
|
|
| 377 |
extern void quit() |
extern void quit() |
| 378 |
{ |
{ |
| 379 |
exit(EXIT_SUCCESS); |
exit(EXIT_SUCCESS); |
| 394 |
printf("okidok\n "); |
printf("okidok\n "); |
| 395 |
} |
} |
| 396 |
|
|
| 397 |
|
exit(EXIT_SUCCESS); |
|
return EXIT_SUCCESS; |
|
| 398 |
} |
} |
| 399 |
|
|
| 400 |
/* Local Variables: */ |
/* Local Variables: */ |