| 1 |
/* printf */ |
/* printf, sscanf, fgets, fprintf */ |
| 2 |
#include <stdio.h> |
#include <stdio.h> |
| 3 |
/* EXIT_SUCCESS */ |
/* exit, EXIT_SUCCESS, malloc, free */ |
| 4 |
#include <stdlib.h> |
#include <stdlib.h> |
| 5 |
/* NULL */ |
/* NULL */ |
| 6 |
#include <stddef.h> |
#include <stddef.h> |
| 7 |
/* dlopen, dlsym, dlerror */ |
/* dlopen, dlsym, dlerror */ |
| 8 |
#include <dlfcn.h> |
#include <dlfcn.h> |
| 9 |
/* assert */ |
/* strcmp, strcpy, strlen, strcat, strdup */ |
| 10 |
#include <assert.h> |
#include <string.h> |
| 11 |
|
|
| 12 |
#define HASHTBLSIZE 65536 |
#define HASHTBLSIZE 65536 |
| 13 |
|
|
| 18 |
enum { |
enum { |
| 19 |
integer, |
integer, |
| 20 |
string, |
string, |
|
ref, /* Reference (to an element in the |
|
|
hash table) */ |
|
| 21 |
func, /* Function pointer */ |
func, /* Function pointer */ |
| 22 |
symb, |
symb, |
| 23 |
list |
list |
| 48 |
typedef struct stackitem_struct |
typedef struct stackitem_struct |
| 49 |
{ |
{ |
| 50 |
value *item; /* The value on the stack */ |
value *item; /* The value on the stack */ |
| 51 |
|
/* (This is never NULL) */ |
| 52 |
struct stackitem_struct *next; /* Next item */ |
struct stackitem_struct *next; /* Next item */ |
| 53 |
} stackitem; |
} stackitem; |
| 54 |
|
|
| 58 |
stackitem *head; /* Head of the stack */ |
stackitem *head; /* Head of the stack */ |
| 59 |
hashtbl symbols; /* Hash table of all variable bindings */ |
hashtbl symbols; /* Hash table of all variable bindings */ |
| 60 |
int err; /* Error flag */ |
int err; /* Error flag */ |
| 61 |
|
int non_eval_flag; |
| 62 |
} environment; |
} environment; |
| 63 |
|
|
| 64 |
/* A type for pointers to external functions */ |
/* A type for pointers to external functions */ |
| 68 |
/* Initialize a newly created environment */ |
/* Initialize a newly created environment */ |
| 69 |
void init_env(environment *env) |
void init_env(environment *env) |
| 70 |
{ |
{ |
| 71 |
long i; |
int i; |
| 72 |
|
|
| 73 |
|
env->err= 0; |
| 74 |
|
env->non_eval_flag= 0; |
| 75 |
for(i= 0; i<HASHTBLSIZE; i++) |
for(i= 0; i<HASHTBLSIZE; i++) |
| 76 |
env->symbols[i]= NULL; |
env->symbols[i]= NULL; |
| 77 |
} |
} |
| 78 |
|
|
| 79 |
|
void printerr(const char* in_string) { |
| 80 |
|
fprintf(stderr, "Err: %s\n", in_string); |
| 81 |
|
} |
| 82 |
|
|
| 83 |
|
/* Throw away a value */ |
| 84 |
|
void free_val(value *val){ |
| 85 |
|
stackitem *item, *temp; |
| 86 |
|
|
| 87 |
|
val->refcount--; /* Decrease the reference count */ |
| 88 |
|
if(val->refcount == 0){ |
| 89 |
|
switch (val->type){ /* and free the contents if necessary */ |
| 90 |
|
case string: |
| 91 |
|
free(val->content.ptr); |
| 92 |
|
break; |
| 93 |
|
case list: /* lists needs to be freed recursively */ |
| 94 |
|
item=val->content.ptr; |
| 95 |
|
while(item != NULL) { /* for all stack items */ |
| 96 |
|
free_val(item->item); /* free the value */ |
| 97 |
|
temp=item->next; /* save next ptr */ |
| 98 |
|
free(item); /* free the stackitem */ |
| 99 |
|
item=temp; /* go to next stackitem */ |
| 100 |
|
} |
| 101 |
|
free(val); /* Free the actual list value */ |
| 102 |
|
break; |
| 103 |
|
case integer: |
| 104 |
|
case func: |
| 105 |
|
case symb: |
| 106 |
|
break; |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
/* Discard the top element of the stack. */ |
| 112 |
|
extern void toss(environment *env) |
| 113 |
|
{ |
| 114 |
|
stackitem *temp= env->head; |
| 115 |
|
|
| 116 |
|
if((env->head)==NULL) { |
| 117 |
|
printerr("Too Few Arguments"); |
| 118 |
|
env->err=1; |
| 119 |
|
return; |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
free_val(env->head->item); /* Free the value */ |
| 123 |
|
env->head= env->head->next; /* Remove the top stack item */ |
| 124 |
|
free(temp); /* Free the old top stack item */ |
| 125 |
|
} |
| 126 |
|
|
| 127 |
/* Returns a pointer to a pointer to an element in the hash table. */ |
/* Returns a pointer to a pointer to an element in the hash table. */ |
| 128 |
symbol **hash(hashtbl in_hashtbl, const char *in_string) |
symbol **hash(hashtbl in_hashtbl, const char *in_string) |
| 129 |
{ |
{ |
| 130 |
long i= 0; |
int i= 0; |
| 131 |
unsigned long out_hash= 0; |
unsigned int out_hash= 0; |
| 132 |
char key= '\0'; |
char key= '\0'; |
| 133 |
symbol **position; |
symbol **position; |
| 134 |
|
|
| 154 |
} |
} |
| 155 |
|
|
| 156 |
/* Generic push function. */ |
/* Generic push function. */ |
| 157 |
int push(stackitem** stack_head, stackitem* in_item) |
void push(stackitem** stack_head, stackitem* in_item) |
| 158 |
{ |
{ |
| 159 |
in_item->next= *stack_head; |
in_item->next= *stack_head; |
| 160 |
*stack_head= in_item; |
*stack_head= in_item; |
|
return 1; |
|
| 161 |
} |
} |
| 162 |
|
|
| 163 |
/* Push a value onto the stack */ |
/* Push a value onto the stack */ |
| 170 |
} |
} |
| 171 |
|
|
| 172 |
/* Push an integer onto the stack. */ |
/* Push an integer onto the stack. */ |
| 173 |
int push_int(stackitem **stack_head, int in_val) |
void push_int(stackitem **stack_head, int in_val) |
| 174 |
{ |
{ |
| 175 |
value *new_value= malloc(sizeof(value)); |
value *new_value= malloc(sizeof(value)); |
| 176 |
stackitem *new_item= malloc(sizeof(stackitem)); |
stackitem *new_item= malloc(sizeof(stackitem)); |
| 181 |
new_value->refcount=1; |
new_value->refcount=1; |
| 182 |
|
|
| 183 |
push(stack_head, new_item); |
push(stack_head, new_item); |
|
return 1; |
|
| 184 |
} |
} |
| 185 |
|
|
| 186 |
/* Copy a string onto the stack. */ |
/* Copy a string onto the stack. */ |
| 187 |
int push_cstring(stackitem **stack_head, const char *in_string) |
void push_cstring(stackitem **stack_head, const char *in_string) |
| 188 |
{ |
{ |
| 189 |
value *new_value= malloc(sizeof(value)); |
value *new_value= malloc(sizeof(value)); |
| 190 |
stackitem *new_item= malloc(sizeof(stackitem)); |
stackitem *new_item= malloc(sizeof(stackitem)); |
| 196 |
new_value->refcount=1; |
new_value->refcount=1; |
| 197 |
|
|
| 198 |
push(stack_head, new_item); |
push(stack_head, new_item); |
| 199 |
return 1; |
} |
| 200 |
|
|
| 201 |
|
/* Mangle a symbol name to a valid C identifier name */ |
| 202 |
|
char *mangle_str(const char *old_string){ |
| 203 |
|
char validchars[] |
| 204 |
|
="0123456789abcdef"; |
| 205 |
|
char *new_string, *current; |
| 206 |
|
|
| 207 |
|
new_string=malloc((strlen(old_string)*2)+4); |
| 208 |
|
strcpy(new_string, "sx_"); /* Stack eXternal */ |
| 209 |
|
current=new_string+3; |
| 210 |
|
while(old_string[0] != '\0'){ |
| 211 |
|
current[0]=validchars[(unsigned char)(old_string[0])/16]; |
| 212 |
|
current[1]=validchars[(unsigned char)(old_string[0])%16]; |
| 213 |
|
current+=2; |
| 214 |
|
old_string++; |
| 215 |
|
} |
| 216 |
|
current[0]='\0'; |
| 217 |
|
|
| 218 |
|
return new_string; /* The caller must free() it */ |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
extern void mangle(environment *env){ |
| 222 |
|
value *new_value; |
| 223 |
|
char *new_string; |
| 224 |
|
|
| 225 |
|
if((env->head)==NULL) { |
| 226 |
|
printerr("Too Few Arguments"); |
| 227 |
|
env->err=1; |
| 228 |
|
return; |
| 229 |
|
} |
| 230 |
|
|
| 231 |
|
if(env->head->item->type!=string) { |
| 232 |
|
printerr("Bad Argument Type"); |
| 233 |
|
env->err=2; |
| 234 |
|
return; |
| 235 |
|
} |
| 236 |
|
|
| 237 |
|
new_string= mangle_str((const char *)(env->head->item->content.ptr)); |
| 238 |
|
|
| 239 |
|
toss(env); |
| 240 |
|
if(env->err) return; |
| 241 |
|
|
| 242 |
|
new_value= malloc(sizeof(value)); |
| 243 |
|
new_value->content.ptr= new_string; |
| 244 |
|
new_value->type= string; |
| 245 |
|
new_value->refcount=1; |
| 246 |
|
|
| 247 |
|
push_val(&(env->head), new_value); |
| 248 |
} |
} |
| 249 |
|
|
| 250 |
/* Push a symbol onto the stack. */ |
/* Push a symbol onto the stack. */ |
| 251 |
int push_sym(environment *env, const char *in_string) |
void push_sym(environment *env, const char *in_string) |
| 252 |
{ |
{ |
| 253 |
stackitem *new_item; /* The new stack item */ |
stackitem *new_item; /* The new stack item */ |
| 254 |
/* ...which will contain... */ |
/* ...which will contain... */ |
| 261 |
void *funcptr; /* A function pointer */ |
void *funcptr; /* A function pointer */ |
| 262 |
|
|
| 263 |
static void *handle= NULL; /* Dynamic linker handle */ |
static void *handle= NULL; /* Dynamic linker handle */ |
| 264 |
|
const char *dlerr; /* Dynamic linker error */ |
| 265 |
|
char *mangled; /* Mangled function name */ |
| 266 |
|
|
| 267 |
/* Create a new stack item containing a new value */ |
/* Create a new stack item containing a new value */ |
| 268 |
new_item= malloc(sizeof(stackitem)); |
new_item= malloc(sizeof(stackitem)); |
| 295 |
handle= dlopen(NULL, RTLD_LAZY); |
handle= dlopen(NULL, RTLD_LAZY); |
| 296 |
|
|
| 297 |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
| 298 |
if(dlerror()==NULL) { /* If a function was found */ |
dlerr=dlerror(); |
| 299 |
|
if(dlerr != NULL) { /* If no function was found */ |
| 300 |
|
mangled=mangle_str(in_string); |
| 301 |
|
funcptr= dlsym(handle, mangled); /* try mangling it */ |
| 302 |
|
free(mangled); |
| 303 |
|
dlerr=dlerror(); |
| 304 |
|
} |
| 305 |
|
if(dlerr==NULL) { /* If a function was found */ |
| 306 |
new_fvalue= malloc(sizeof(value)); /* Create a new value */ |
new_fvalue= malloc(sizeof(value)); /* Create a new value */ |
| 307 |
new_fvalue->type=func; /* The new value is a function pointer */ |
new_fvalue->type=func; /* The new value is a function pointer */ |
| 308 |
new_fvalue->content.ptr=funcptr; /* Store function pointer */ |
new_fvalue->content.ptr=funcptr; /* Store function pointer */ |
| 312 |
} |
} |
| 313 |
} |
} |
| 314 |
push(&(env->head), new_item); |
push(&(env->head), new_item); |
|
return 1; |
|
|
} |
|
|
|
|
|
void printerr(const char* in_string) { |
|
|
fprintf(stderr, "Err: %s\n", in_string); |
|
| 315 |
} |
} |
| 316 |
|
|
| 317 |
/* Throw away a value */ |
/* Print newline. */ |
| 318 |
void free_val(value *val){ |
extern void nl() |
| 319 |
stackitem *item, *temp; |
{ |
| 320 |
|
printf("\n"); |
|
val->refcount--; /* Decrease the reference count */ |
|
|
if(val->refcount == 0){ |
|
|
switch (val->type){ /* and free the contents if necessary */ |
|
|
case string: |
|
|
free(val->content.ptr); |
|
|
case list: /* lists needs to be freed recursively */ |
|
|
item=val->content.ptr; |
|
|
while(item != NULL) { /* for all stack items */ |
|
|
free_val(item->item); /* free the value */ |
|
|
temp=item->next; /* save next ptr */ |
|
|
free(item); /* free the stackitem */ |
|
|
item=temp; /* go to next stackitem */ |
|
|
} |
|
|
free(val); /* Free the actual list value */ |
|
|
break; |
|
|
default: |
|
|
break; |
|
|
} |
|
|
} |
|
| 321 |
} |
} |
| 322 |
|
|
| 323 |
/* Discard the top element of the stack. */ |
/* Gets the type of a value */ |
| 324 |
extern void toss(environment *env) |
extern void type(environment *env){ |
| 325 |
{ |
int typenum; |
|
stackitem *temp= env->head; |
|
| 326 |
|
|
| 327 |
if((env->head)==NULL) { |
if((env->head)==NULL) { |
| 328 |
printerr("Stack empty"); |
printerr("Too Few Arguments"); |
| 329 |
|
env->err=1; |
| 330 |
return; |
return; |
| 331 |
} |
} |
| 332 |
|
typenum=env->head->item->type; |
| 333 |
free_val(env->head->item); /* Free the value */ |
toss(env); |
| 334 |
env->head= env->head->next; /* Remove the top stack item */ |
switch(typenum){ |
| 335 |
free(temp); /* Free the old top stack item */ |
case integer: |
| 336 |
} |
push_sym(env, "integer"); |
| 337 |
|
break; |
| 338 |
/* Print newline. */ |
case string: |
| 339 |
extern void nl(environment *env) |
push_sym(env, "string"); |
| 340 |
{ |
break; |
| 341 |
printf("\n"); |
case symb: |
| 342 |
} |
push_sym(env, "symbol"); |
| 343 |
|
break; |
| 344 |
|
case func: |
| 345 |
|
push_sym(env, "function"); |
| 346 |
|
break; |
| 347 |
|
case list: |
| 348 |
|
push_sym(env, "list"); |
| 349 |
|
break; |
| 350 |
|
} |
| 351 |
|
} |
| 352 |
|
|
| 353 |
/* Prints the top element of the stack. */ |
/* Prints the top element of the stack. */ |
| 354 |
void print_h(stackitem *stack_head) |
void print_h(stackitem *stack_head) |
| 355 |
{ |
{ |
|
|
|
|
if(stack_head==NULL) { |
|
|
printerr("Stack empty"); |
|
|
return; |
|
|
} |
|
|
|
|
| 356 |
switch(stack_head->item->type) { |
switch(stack_head->item->type) { |
| 357 |
case integer: |
case integer: |
| 358 |
printf("%d", stack_head->item->content.val); |
printf("%d", stack_head->item->content.val); |
| 359 |
break; |
break; |
| 360 |
case string: |
case string: |
| 361 |
printf("\"%s\"", (char*)stack_head->item->content.ptr); |
printf("%s", (char*)stack_head->item->content.ptr); |
| 362 |
break; |
break; |
| 363 |
case symb: |
case symb: |
| 364 |
printf("'%s'", ((symbol *)(stack_head->item->content.ptr))->id); |
printf("%s", ((symbol *)(stack_head->item->content.ptr))->id); |
| 365 |
break; |
break; |
| 366 |
default: |
case func: |
| 367 |
printf("%p", (funcp)(stack_head->item->content.ptr)); |
printf("#<function %p>", (funcp)(stack_head->item->content.ptr)); |
| 368 |
|
break; |
| 369 |
|
case list: |
| 370 |
|
/* A list is just a stack, so make stack_head point to it */ |
| 371 |
|
stack_head=(stackitem *)(stack_head->item->content.ptr); |
| 372 |
|
printf("[ "); |
| 373 |
|
while(stack_head != NULL) { |
| 374 |
|
print_h(stack_head); |
| 375 |
|
printf(" "); |
| 376 |
|
stack_head=stack_head->next; |
| 377 |
|
} |
| 378 |
|
printf("]"); |
| 379 |
break; |
break; |
| 380 |
} |
} |
| 381 |
} |
} |
| 382 |
|
|
| 383 |
extern void print_(environment *env) { |
extern void print_(environment *env) { |
| 384 |
|
if(env->head==NULL) { |
| 385 |
|
printerr("Too Few Arguments"); |
| 386 |
|
env->err=1; |
| 387 |
|
return; |
| 388 |
|
} |
| 389 |
print_h(env->head); |
print_h(env->head); |
| 390 |
} |
} |
| 391 |
|
|
| 393 |
extern void print(environment *env) |
extern void print(environment *env) |
| 394 |
{ |
{ |
| 395 |
print_(env); |
print_(env); |
| 396 |
|
if(env->err) return; |
| 397 |
toss(env); |
toss(env); |
| 398 |
} |
} |
| 399 |
|
|
| 407 |
nl(); |
nl(); |
| 408 |
} |
} |
| 409 |
|
|
|
|
|
|
|
|
| 410 |
/* Prints the stack. */ |
/* Prints the stack. */ |
| 411 |
extern void printstack(environment *env) |
extern void printstack(environment *env) |
| 412 |
{ |
{ |
| 413 |
if(env->head != NULL) { |
if(env->head == NULL) { |
| 414 |
print_st(env->head, 1); |
return; |
|
nl(); |
|
|
} else { |
|
|
printerr("Stack empty"); |
|
| 415 |
} |
} |
| 416 |
|
print_st(env->head, 1); |
| 417 |
|
nl(); |
| 418 |
} |
} |
| 419 |
|
|
| 420 |
/* Swap the two top elements on the stack. */ |
/* Swap the two top elements on the stack. */ |
| 422 |
{ |
{ |
| 423 |
stackitem *temp= env->head; |
stackitem *temp= env->head; |
| 424 |
|
|
| 425 |
if((env->head)==NULL) { |
if(env->head==NULL || env->head->next==NULL) { |
| 426 |
printerr("Stack empty"); |
printerr("Too Few Arguments"); |
| 427 |
return; |
env->err=1; |
|
} |
|
|
|
|
|
if(env->head->next==NULL) { |
|
|
printerr("Not enough arguments"); |
|
| 428 |
return; |
return; |
| 429 |
} |
} |
| 430 |
|
|
| 433 |
env->head->next= temp; |
env->head->next= temp; |
| 434 |
} |
} |
| 435 |
|
|
| 436 |
stackitem* copy(stackitem* in_item) |
/* Rotate the first three elements on the stack. */ |
| 437 |
|
extern void rot(environment *env) |
| 438 |
{ |
{ |
| 439 |
stackitem *out_item= malloc(sizeof(stackitem)); |
stackitem *temp= env->head; |
| 440 |
|
|
| 441 |
memcpy(out_item, in_item, sizeof(stackitem)); |
if(env->head==NULL || env->head->next==NULL |
| 442 |
out_item->next= NULL; |
|| env->head->next->next==NULL) { |
| 443 |
|
printerr("Too Few Arguments"); |
| 444 |
|
env->err=1; |
| 445 |
|
return; |
| 446 |
|
} |
| 447 |
|
|
| 448 |
return out_item; |
env->head= env->head->next->next; |
| 449 |
|
temp->next->next= env->head->next; |
| 450 |
|
env->head->next= temp; |
| 451 |
} |
} |
| 452 |
|
|
| 453 |
/* Recall a value from a symbol, if bound */ |
/* Recall a value from a symbol, if bound */ |
| 456 |
value *val; |
value *val; |
| 457 |
|
|
| 458 |
if(env->head == NULL) { |
if(env->head == NULL) { |
| 459 |
printerr("Stack empty"); |
printerr("Too Few Arguments"); |
| 460 |
|
env->err=1; |
| 461 |
return; |
return; |
| 462 |
} |
} |
| 463 |
|
|
| 464 |
if(env->head->item->type!=symb) { |
if(env->head->item->type!=symb) { |
| 465 |
printerr("Not a symbol"); |
printerr("Bad Argument Type"); |
| 466 |
|
env->err=2; |
| 467 |
return; |
return; |
| 468 |
} |
} |
| 469 |
|
|
| 470 |
val=((symbol *)(env->head->item->content.ptr))->val; |
val=((symbol *)(env->head->item->content.ptr))->val; |
| 471 |
if(val == NULL){ |
if(val == NULL){ |
| 472 |
printerr("Unbound variable"); |
printerr("Unbound Variable"); |
| 473 |
|
env->err=3; |
| 474 |
return; |
return; |
| 475 |
} |
} |
| 476 |
toss(env); /* toss the symbol */ |
toss(env); /* toss the symbol */ |
| 477 |
|
if(env->err) return; |
| 478 |
push_val(&(env->head), val); /* Return its bound value */ |
push_val(&(env->head), val); /* Return its bound value */ |
| 479 |
} |
} |
| 480 |
|
|
| 481 |
|
void stack_read(environment*, char*); |
| 482 |
|
|
| 483 |
/* If the top element is a symbol, determine if it's bound to a |
/* If the top element is a symbol, determine if it's bound to a |
| 484 |
function value, and if it is, toss the symbol and execute the |
function value, and if it is, toss the symbol and execute the |
| 485 |
function. */ |
function. */ |
| 486 |
extern void eval(environment *env) |
extern void eval(environment *env) |
| 487 |
{ |
{ |
| 488 |
funcp in_func; |
funcp in_func; |
| 489 |
value* val; |
value* temp_val; |
| 490 |
|
stackitem* iterator; |
| 491 |
|
char* temp_string; |
| 492 |
|
|
| 493 |
if(env->head==NULL) { |
if(env->head==NULL) { |
| 494 |
printerr("Stack empty"); |
printerr("Too Few Arguments"); |
| 495 |
|
env->err=1; |
| 496 |
return; |
return; |
| 497 |
} |
} |
| 498 |
|
|
| 499 |
/* if it's a symbol */ |
switch(env->head->item->type) { |
| 500 |
if(env->head->item->type==symb) { |
/* if it's a symbol */ |
| 501 |
|
case symb: |
| 502 |
/* If it's not bound to anything */ |
rcl(env); /* get its contents */ |
| 503 |
if (((symbol *)(env->head->item->content.ptr))->val == NULL) { |
if(env->err) return; |
| 504 |
printerr("Unbound variable"); |
if(env->head->item->type!=symb){ /* don't recurse symbols */ |
| 505 |
return; |
return eval(env); /* evaluate the value */ |
|
} |
|
|
|
|
|
/* If it contains a function */ |
|
|
if (((symbol *)(env->head->item->content.ptr))->val->type == func) { |
|
|
in_func= |
|
|
(funcp)(((symbol *)(env->head->item->content.ptr))->val->content.ptr); |
|
|
toss(env); |
|
|
(*in_func)(env); /* Run the function */ |
|
|
return; |
|
|
} else { /* If it's not a function */ |
|
|
val=((symbol *)(env->head->item->content.ptr))->val; |
|
|
toss(env); /* toss the symbol */ |
|
|
push_val(&(env->head), val); /* Return its bound value */ |
|
| 506 |
} |
} |
| 507 |
} |
return; |
| 508 |
|
|
| 509 |
/* If it's a lone function value, run it */ |
/* If it's a lone function value, run it */ |
| 510 |
if(env->head->item->type==func) { |
case func: |
| 511 |
in_func= (funcp)(env->head->item->content.ptr); |
in_func= (funcp)(env->head->item->content.ptr); |
| 512 |
toss(env); |
toss(env); |
| 513 |
(*in_func)(env); |
if(env->err) return; |
| 514 |
|
return (*in_func)(env); |
| 515 |
|
|
| 516 |
|
/* If it's a list */ |
| 517 |
|
case list: |
| 518 |
|
temp_val= env->head->item; |
| 519 |
|
env->head->item->refcount++; |
| 520 |
|
toss(env); |
| 521 |
|
if(env->err) return; |
| 522 |
|
iterator= (stackitem*)temp_val->content.ptr; |
| 523 |
|
while(iterator!=NULL) { |
| 524 |
|
push_val(&(env->head), iterator->item); |
| 525 |
|
if(env->head->item->type==symb |
| 526 |
|
&& strcmp(";", ((symbol*)(env->head->item->content.ptr))->id)==0) { |
| 527 |
|
toss(env); |
| 528 |
|
if(env->err) return; |
| 529 |
|
if(iterator->next == NULL){ |
| 530 |
|
free_val(temp_val); |
| 531 |
|
return eval(env); |
| 532 |
|
} |
| 533 |
|
eval(env); |
| 534 |
|
if(env->err) return; |
| 535 |
|
} |
| 536 |
|
iterator= iterator->next; |
| 537 |
|
} |
| 538 |
|
free_val(temp_val); |
| 539 |
|
return; |
| 540 |
|
|
| 541 |
|
/* If it's a string */ |
| 542 |
|
case string: |
| 543 |
|
temp_val= env->head->item; |
| 544 |
|
env->head->item->refcount++; |
| 545 |
|
toss(env); |
| 546 |
|
if(env->err) return; |
| 547 |
|
temp_string= malloc(strlen((char*)temp_val->content.ptr)+5); |
| 548 |
|
strcpy(temp_string, "[ "); |
| 549 |
|
strcpy(temp_string+2, (char*)temp_val->content.ptr); |
| 550 |
|
free_val(temp_val); |
| 551 |
|
strcat(temp_string, " ]"); |
| 552 |
|
stack_read(env, temp_string); |
| 553 |
|
free(temp_string); |
| 554 |
|
return eval(env); |
| 555 |
|
|
| 556 |
|
case integer: |
| 557 |
return; |
return; |
| 558 |
} |
} |
| 559 |
|
} |
| 560 |
|
|
| 561 |
|
/* Reverse (flip) a list */ |
| 562 |
|
extern void rev(environment *env){ |
| 563 |
|
stackitem *old_head, *new_head, *item; |
| 564 |
|
|
| 565 |
|
if((env->head)==NULL) { |
| 566 |
|
printerr("Too Few Arguments"); |
| 567 |
|
env->err=1; |
| 568 |
|
return; |
| 569 |
|
} |
| 570 |
|
|
| 571 |
|
if(env->head->item->type!=list) { |
| 572 |
|
printerr("Bad Argument Type"); |
| 573 |
|
env->err=2; |
| 574 |
|
return; |
| 575 |
|
} |
| 576 |
|
|
| 577 |
|
old_head=(stackitem *)(env->head->item->content.ptr); |
| 578 |
|
new_head=NULL; |
| 579 |
|
while(old_head != NULL){ |
| 580 |
|
item=old_head; |
| 581 |
|
old_head=old_head->next; |
| 582 |
|
item->next=new_head; |
| 583 |
|
new_head=item; |
| 584 |
|
} |
| 585 |
|
env->head->item->content.ptr=new_head; |
| 586 |
} |
} |
| 587 |
|
|
| 588 |
/* Make a list. */ |
/* Make a list. */ |
| 625 |
temp->item= pack; |
temp->item= pack; |
| 626 |
|
|
| 627 |
push(&(env->head), temp); |
push(&(env->head), temp); |
| 628 |
|
rev(env); |
| 629 |
} |
} |
| 630 |
|
|
| 631 |
/* Parse input. */ |
/* Parse input. */ |
| 632 |
int stack_read(environment *env, char *in_line) |
void stack_read(environment *env, char *in_line) |
| 633 |
{ |
{ |
| 634 |
char *temp, *rest; |
char *temp, *rest; |
| 635 |
int itemp; |
int itemp; |
| 636 |
size_t inlength= strlen(in_line)+1; |
size_t inlength= strlen(in_line)+1; |
| 637 |
int convert= 0; |
int convert= 0; |
|
static int non_eval_flag= 0; |
|
| 638 |
|
|
| 639 |
temp= malloc(inlength); |
temp= malloc(inlength); |
| 640 |
rest= malloc(inlength); |
rest= malloc(inlength); |
| 641 |
|
|
| 642 |
do { |
do { |
| 643 |
|
/* If comment */ |
| 644 |
|
if((convert= sscanf(in_line, "#%[^\n\r]", rest))) { |
| 645 |
|
free(temp); free(rest); |
| 646 |
|
return; |
| 647 |
|
} |
| 648 |
|
|
| 649 |
/* If string */ |
/* If string */ |
| 650 |
if((convert= sscanf(in_line, "\"%[^\"\n\r]\" %[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "\"%[^\"\n\r]\" %[^\n\r]", temp, rest))) { |
| 651 |
push_cstring(&(env->head), temp); |
push_cstring(&(env->head), temp); |
| 663 |
break; |
break; |
| 664 |
} |
} |
| 665 |
/* If symbol */ |
/* If symbol */ |
| 666 |
if((convert= sscanf(in_line, "%[^][ ;\n\r_]%[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "%[^][ ;\n\r]%[^\n\r]", temp, rest))) { |
| 667 |
push_sym(env, temp); |
push_sym(env, temp); |
| 668 |
break; |
break; |
| 669 |
} |
} |
| 670 |
/* If single char */ |
/* If single char */ |
| 671 |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { |
if((convert= sscanf(in_line, "%c%[^\n\r]", temp, rest))) { |
| 672 |
if(*temp==';') { |
if(*temp==';') { |
| 673 |
if(!non_eval_flag) { |
if(!env->non_eval_flag) { |
| 674 |
eval(env); /* Evaluate top element */ |
eval(env); /* Evaluate top element */ |
| 675 |
break; |
break; |
| 676 |
} |
} |
| 682 |
if(*temp==']') { |
if(*temp==']') { |
| 683 |
push_sym(env, "["); |
push_sym(env, "["); |
| 684 |
pack(env); |
pack(env); |
| 685 |
if(non_eval_flag!=0) |
if(env->non_eval_flag) |
| 686 |
non_eval_flag--; |
env->non_eval_flag--; |
| 687 |
break; |
break; |
| 688 |
} |
} |
| 689 |
|
|
| 690 |
if(*temp=='[') { |
if(*temp=='[') { |
| 691 |
push_sym(env, "["); |
push_sym(env, "["); |
| 692 |
non_eval_flag++; |
env->non_eval_flag++; |
| 693 |
break; |
break; |
| 694 |
} |
} |
| 695 |
} |
} |
| 696 |
} while(0); |
} while(0); |
| 697 |
|
|
|
|
|
| 698 |
free(temp); |
free(temp); |
| 699 |
|
|
| 700 |
if(convert<2) { |
if(convert<2) { |
| 701 |
free(rest); |
free(rest); |
| 702 |
return 0; |
return; |
| 703 |
} |
} |
| 704 |
|
|
| 705 |
stack_read(env, rest); |
stack_read(env, rest); |
| 706 |
|
|
| 707 |
free(rest); |
free(rest); |
|
return 1; |
|
| 708 |
} |
} |
| 709 |
|
|
| 710 |
/* Relocate elements of the list on the stack. */ |
/* Relocate elements of the list on the stack. */ |
| 713 |
stackitem *temp, *new_head; |
stackitem *temp, *new_head; |
| 714 |
|
|
| 715 |
/* Is top element a list? */ |
/* Is top element a list? */ |
| 716 |
if(env->head==NULL || env->head->item->type!=list) { |
if(env->head==NULL) { |
| 717 |
printerr("Stack empty or not a list"); |
printerr("Too Few Arguments"); |
| 718 |
|
env->err=1; |
| 719 |
|
return; |
| 720 |
|
} |
| 721 |
|
if(env->head->item->type!=list) { |
| 722 |
|
printerr("Bad Argument Type"); |
| 723 |
|
env->err=2; |
| 724 |
return; |
return; |
| 725 |
} |
} |
| 726 |
|
|
| 727 |
|
rev(env); |
| 728 |
|
|
| 729 |
|
if(env->err) |
| 730 |
|
return; |
| 731 |
|
|
| 732 |
/* The first list element is the new stack head */ |
/* The first list element is the new stack head */ |
| 733 |
new_head= temp= env->head->item->content.ptr; |
new_head= temp= env->head->item->content.ptr; |
| 734 |
|
|
| 752 |
int result; |
int result; |
| 753 |
|
|
| 754 |
if((env->head)==NULL || env->head->next==NULL) { |
if((env->head)==NULL || env->head->next==NULL) { |
| 755 |
printerr("Not enough elements to compare"); |
printerr("Too Few Arguments"); |
| 756 |
|
env->err=1; |
| 757 |
return; |
return; |
| 758 |
} |
} |
| 759 |
|
|
| 771 |
{ |
{ |
| 772 |
int val; |
int val; |
| 773 |
|
|
| 774 |
if((env->head)==NULL || env->head->item->type!=integer) { |
if((env->head)==NULL) { |
| 775 |
printerr("Stack empty or element is not a integer"); |
printerr("Too Few Arguments"); |
| 776 |
|
env->err=1; |
| 777 |
|
return; |
| 778 |
|
} |
| 779 |
|
|
| 780 |
|
if(env->head->item->type!=integer) { |
| 781 |
|
printerr("Bad Argument Type"); |
| 782 |
|
env->err=2; |
| 783 |
return; |
return; |
| 784 |
} |
} |
| 785 |
|
|
| 802 |
symbol *sym; |
symbol *sym; |
| 803 |
|
|
| 804 |
/* Needs two values on the stack, the top one must be a symbol */ |
/* Needs two values on the stack, the top one must be a symbol */ |
| 805 |
if(env->head==NULL || env->head->next==NULL |
if(env->head==NULL || env->head->next==NULL) { |
| 806 |
|| env->head->item->type!=symb) { |
printerr("Too Few Arguments"); |
| 807 |
printerr("Define what?"); |
env->err=1; |
| 808 |
|
return; |
| 809 |
|
} |
| 810 |
|
|
| 811 |
|
if(env->head->item->type!=symb) { |
| 812 |
|
printerr("Bad Argument Type"); |
| 813 |
|
env->err=2; |
| 814 |
return; |
return; |
| 815 |
} |
} |
| 816 |
|
|
| 856 |
} |
} |
| 857 |
} |
} |
| 858 |
|
|
| 859 |
|
/* Forgets a symbol (remove it from the hash table) */ |
| 860 |
|
extern void forget(environment *env) |
| 861 |
|
{ |
| 862 |
|
char* sym_id; |
| 863 |
|
stackitem *stack_head= env->head; |
| 864 |
|
symbol **hash_entry, *temp; |
| 865 |
|
|
| 866 |
|
if(stack_head==NULL) { |
| 867 |
|
printerr("Too Few Arguments"); |
| 868 |
|
env->err=1; |
| 869 |
|
return; |
| 870 |
|
} |
| 871 |
|
|
| 872 |
|
if(stack_head->item->type!=symb) { |
| 873 |
|
printerr("Bad Argument Type"); |
| 874 |
|
env->err=2; |
| 875 |
|
return; |
| 876 |
|
} |
| 877 |
|
|
| 878 |
|
sym_id= ((symbol*)(stack_head->item->content.ptr))->id; |
| 879 |
|
toss(env); |
| 880 |
|
|
| 881 |
|
hash_entry= hash(env->symbols, sym_id); |
| 882 |
|
temp= *hash_entry; |
| 883 |
|
*hash_entry= (*hash_entry)->next; |
| 884 |
|
|
| 885 |
|
if(temp->val!=NULL) { |
| 886 |
|
free_val(temp->val); |
| 887 |
|
} |
| 888 |
|
free(temp->id); |
| 889 |
|
free(temp); |
| 890 |
|
} |
| 891 |
|
|
| 892 |
|
/* Returns the current error number to the stack */ |
| 893 |
|
extern void errn(environment *env){ |
| 894 |
|
push_int(&(env->head), env->err); |
| 895 |
|
} |
| 896 |
|
|
| 897 |
int main() |
int main() |
| 898 |
{ |
{ |
| 899 |
environment myenv; |
environment myenv; |
| 905 |
|
|
| 906 |
while(fgets(in_string, 100, stdin) != NULL) { |
while(fgets(in_string, 100, stdin) != NULL) { |
| 907 |
stack_read(&myenv, in_string); |
stack_read(&myenv, in_string); |
| 908 |
|
if(myenv.err) { |
| 909 |
|
printf("(error %d) ", myenv.err); |
| 910 |
|
myenv.err=0; |
| 911 |
|
} |
| 912 |
printf("okidok\n "); |
printf("okidok\n "); |
| 913 |
} |
} |
| 914 |
|
quit(&myenv); |
| 915 |
|
return EXIT_FAILURE; |
| 916 |
|
} |
| 917 |
|
|
| 918 |
exit(EXIT_SUCCESS); |
/* + */ |
| 919 |
|
extern void sx_2b(environment *env) { |
| 920 |
|
int a, b; |
| 921 |
|
size_t len; |
| 922 |
|
char* new_string; |
| 923 |
|
value *a_val, *b_val; |
| 924 |
|
|
| 925 |
|
if((env->head)==NULL || env->head->next==NULL) { |
| 926 |
|
printerr("Too Few Arguments"); |
| 927 |
|
env->err=1; |
| 928 |
|
return; |
| 929 |
|
} |
| 930 |
|
|
| 931 |
|
if(env->head->item->type==string |
| 932 |
|
&& env->head->next->item->type==string) { |
| 933 |
|
a_val= env->head->item; |
| 934 |
|
b_val= env->head->next->item; |
| 935 |
|
a_val->refcount++; |
| 936 |
|
b_val->refcount++; |
| 937 |
|
toss(env); if(env->err) return; |
| 938 |
|
toss(env); if(env->err) return; |
| 939 |
|
len= strlen(a_val->content.ptr)+strlen(b_val->content.ptr)+1; |
| 940 |
|
new_string= malloc(len); |
| 941 |
|
strcpy(new_string, b_val->content.ptr); |
| 942 |
|
strcat(new_string, a_val->content.ptr); |
| 943 |
|
free_val(a_val); free_val(b_val); |
| 944 |
|
push_cstring(&(env->head), new_string); |
| 945 |
|
free(new_string); |
| 946 |
|
return; |
| 947 |
|
} |
| 948 |
|
|
| 949 |
|
if(env->head->item->type!=integer |
| 950 |
|
|| env->head->next->item->type!=integer) { |
| 951 |
|
printerr("Bad Argument Type"); |
| 952 |
|
env->err=2; |
| 953 |
|
return; |
| 954 |
|
} |
| 955 |
|
a=env->head->item->content.val; |
| 956 |
|
toss(env); |
| 957 |
|
if(env->err) return; |
| 958 |
|
if(env->head->item->refcount == 1) |
| 959 |
|
env->head->item->content.val += a; |
| 960 |
|
else { |
| 961 |
|
b=env->head->item->content.val; |
| 962 |
|
toss(env); |
| 963 |
|
if(env->err) return; |
| 964 |
|
push_int(&(env->head), a+b); |
| 965 |
|
} |
| 966 |
|
} |
| 967 |
|
|
| 968 |
|
/* - */ |
| 969 |
|
extern void sx_2d(environment *env) { |
| 970 |
|
int a, b; |
| 971 |
|
|
| 972 |
|
if((env->head)==NULL || env->head->next==NULL) { |
| 973 |
|
printerr("Too Few Arguments"); |
| 974 |
|
env->err=1; |
| 975 |
|
return; |
| 976 |
|
} |
| 977 |
|
|
| 978 |
|
if(env->head->item->type!=integer |
| 979 |
|
|| env->head->next->item->type!=integer) { |
| 980 |
|
printerr("Bad Argument Type"); |
| 981 |
|
env->err=2; |
| 982 |
|
return; |
| 983 |
|
} |
| 984 |
|
a=env->head->item->content.val; |
| 985 |
|
toss(env); |
| 986 |
|
if(env->err) return; |
| 987 |
|
if(env->head->item->refcount == 1) |
| 988 |
|
env->head->item->content.val -= a; |
| 989 |
|
else { |
| 990 |
|
b=env->head->item->content.val; |
| 991 |
|
toss(env); |
| 992 |
|
if(env->err) return; |
| 993 |
|
push_int(&(env->head), b-a); |
| 994 |
|
} |
| 995 |
|
} |
| 996 |
|
|
| 997 |
|
/* > */ |
| 998 |
|
extern void sx_3e(environment *env) { |
| 999 |
|
int a, b; |
| 1000 |
|
|
| 1001 |
|
if((env->head)==NULL || env->head->next==NULL) { |
| 1002 |
|
printerr("Too Few Arguments"); |
| 1003 |
|
env->err=1; |
| 1004 |
|
return; |
| 1005 |
|
} |
| 1006 |
|
|
| 1007 |
|
if(env->head->item->type!=integer |
| 1008 |
|
|| env->head->next->item->type!=integer) { |
| 1009 |
|
printerr("Bad Argument Type"); |
| 1010 |
|
env->err=2; |
| 1011 |
|
return; |
| 1012 |
|
} |
| 1013 |
|
a=env->head->item->content.val; |
| 1014 |
|
toss(env); |
| 1015 |
|
if(env->err) return; |
| 1016 |
|
if(env->head->item->refcount == 1) |
| 1017 |
|
env->head->item->content.val = (env->head->item->content.val > a); |
| 1018 |
|
else { |
| 1019 |
|
b=env->head->item->content.val; |
| 1020 |
|
toss(env); |
| 1021 |
|
if(env->err) return; |
| 1022 |
|
push_int(&(env->head), b>a); |
| 1023 |
|
} |
| 1024 |
|
} |
| 1025 |
|
|
| 1026 |
|
/* Return copy of a value */ |
| 1027 |
|
value *copy_val(value *old_value){ |
| 1028 |
|
stackitem *old_item, *new_item, *prev_item; |
| 1029 |
|
|
| 1030 |
|
value *new_value=malloc(sizeof(value)); |
| 1031 |
|
|
| 1032 |
|
new_value->type=old_value->type; |
| 1033 |
|
new_value->refcount=0; /* This is increased if/when this |
| 1034 |
|
value is referenced somewhere, like |
| 1035 |
|
in a stack item or a variable */ |
| 1036 |
|
switch(old_value->type){ |
| 1037 |
|
case integer: |
| 1038 |
|
new_value->content.val=old_value->content.val; |
| 1039 |
|
break; |
| 1040 |
|
case string: |
| 1041 |
|
(char *)(new_value->content.ptr) |
| 1042 |
|
= strdup((char *)(old_value->content.ptr)); |
| 1043 |
|
break; |
| 1044 |
|
case func: |
| 1045 |
|
case symb: |
| 1046 |
|
new_value->content.ptr=old_value->content.ptr; |
| 1047 |
|
break; |
| 1048 |
|
case list: |
| 1049 |
|
new_value->content.ptr=NULL; |
| 1050 |
|
|
| 1051 |
|
prev_item=NULL; |
| 1052 |
|
old_item=(stackitem *)(old_value->content.ptr); |
| 1053 |
|
|
| 1054 |
|
while(old_item != NULL) { /* While list is not empty */ |
| 1055 |
|
new_item= malloc(sizeof(stackitem)); |
| 1056 |
|
new_item->item=copy_val(old_item->item); /* recurse */ |
| 1057 |
|
new_item->next=NULL; |
| 1058 |
|
if(prev_item != NULL) /* If this wasn't the first item */ |
| 1059 |
|
prev_item->next=new_item; /* point the previous item to the |
| 1060 |
|
new item */ |
| 1061 |
|
else |
| 1062 |
|
new_value->content.ptr=new_item; |
| 1063 |
|
old_item=old_item->next; |
| 1064 |
|
prev_item=new_item; |
| 1065 |
|
} |
| 1066 |
|
break; |
| 1067 |
|
} |
| 1068 |
|
return new_value; |
| 1069 |
|
} |
| 1070 |
|
|
| 1071 |
|
/* duplicates an item on the stack */ |
| 1072 |
|
extern void dup(environment *env) { |
| 1073 |
|
if((env->head)==NULL) { |
| 1074 |
|
printerr("Too Few Arguments"); |
| 1075 |
|
env->err=1; |
| 1076 |
|
return; |
| 1077 |
|
} |
| 1078 |
|
push_val(&(env->head), copy_val(env->head->item)); |
| 1079 |
|
} |
| 1080 |
|
|
| 1081 |
|
/* "if", If-Then */ |
| 1082 |
|
extern void sx_6966(environment *env) { |
| 1083 |
|
|
| 1084 |
|
int truth; |
| 1085 |
|
|
| 1086 |
|
if((env->head)==NULL || env->head->next==NULL) { |
| 1087 |
|
printerr("Too Few Arguments"); |
| 1088 |
|
env->err=1; |
| 1089 |
|
return; |
| 1090 |
|
} |
| 1091 |
|
|
| 1092 |
|
if(env->head->next->item->type != integer) { |
| 1093 |
|
printerr("Bad Argument Type"); |
| 1094 |
|
env->err=2; |
| 1095 |
|
return; |
| 1096 |
|
} |
| 1097 |
|
|
| 1098 |
|
swap(env); |
| 1099 |
|
if(env->err) return; |
| 1100 |
|
|
| 1101 |
|
truth=env->head->item->content.val; |
| 1102 |
|
|
| 1103 |
|
toss(env); |
| 1104 |
|
if(env->err) return; |
| 1105 |
|
|
| 1106 |
|
if(truth) |
| 1107 |
|
eval(env); |
| 1108 |
|
else |
| 1109 |
|
toss(env); |
| 1110 |
|
} |
| 1111 |
|
|
| 1112 |
|
/* If-Then-Else */ |
| 1113 |
|
extern void ifelse(environment *env) { |
| 1114 |
|
|
| 1115 |
|
int truth; |
| 1116 |
|
|
| 1117 |
|
if((env->head)==NULL || env->head->next==NULL |
| 1118 |
|
|| env->head->next->next==NULL) { |
| 1119 |
|
printerr("Too Few Arguments"); |
| 1120 |
|
env->err=1; |
| 1121 |
|
return; |
| 1122 |
|
} |
| 1123 |
|
|
| 1124 |
|
if(env->head->next->next->item->type != integer) { |
| 1125 |
|
printerr("Bad Argument Type"); |
| 1126 |
|
env->err=2; |
| 1127 |
|
return; |
| 1128 |
|
} |
| 1129 |
|
|
| 1130 |
|
rot(env); |
| 1131 |
|
if(env->err) return; |
| 1132 |
|
|
| 1133 |
|
truth=env->head->item->content.val; |
| 1134 |
|
|
| 1135 |
|
toss(env); |
| 1136 |
|
if(env->err) return; |
| 1137 |
|
|
| 1138 |
|
if(!truth) |
| 1139 |
|
swap(env); |
| 1140 |
|
if(env->err) return; |
| 1141 |
|
|
| 1142 |
|
toss(env); |
| 1143 |
|
if(env->err) return; |
| 1144 |
|
|
| 1145 |
|
eval(env); |
| 1146 |
|
} |
| 1147 |
|
|
| 1148 |
|
/* while */ |
| 1149 |
|
extern void sx_7768696c65(environment *env) { |
| 1150 |
|
|
| 1151 |
|
int truth; |
| 1152 |
|
value *loop, *test; |
| 1153 |
|
|
| 1154 |
|
if((env->head)==NULL || env->head->next==NULL) { |
| 1155 |
|
printerr("Too Few Arguments"); |
| 1156 |
|
env->err=1; |
| 1157 |
|
return; |
| 1158 |
|
} |
| 1159 |
|
|
| 1160 |
|
loop= env->head->item; |
| 1161 |
|
loop->refcount++; |
| 1162 |
|
toss(env); if(env->err) return; |
| 1163 |
|
|
| 1164 |
|
test= env->head->item; |
| 1165 |
|
test->refcount++; |
| 1166 |
|
toss(env); if(env->err) return; |
| 1167 |
|
|
| 1168 |
|
do { |
| 1169 |
|
push_val(&(env->head), test); |
| 1170 |
|
eval(env); |
| 1171 |
|
|
| 1172 |
|
if(env->head->item->type != integer) { |
| 1173 |
|
printerr("Bad Argument Type"); |
| 1174 |
|
env->err=2; |
| 1175 |
|
return; |
| 1176 |
|
} |
| 1177 |
|
|
| 1178 |
|
truth= env->head->item->content.val; |
| 1179 |
|
toss(env); if(env->err) return; |
| 1180 |
|
|
| 1181 |
|
if(truth) { |
| 1182 |
|
push_val(&(env->head), loop); |
| 1183 |
|
eval(env); |
| 1184 |
|
} else { |
| 1185 |
|
toss(env); |
| 1186 |
|
} |
| 1187 |
|
|
| 1188 |
|
} while(truth); |
| 1189 |
|
|
| 1190 |
|
free_val(test); |
| 1191 |
|
free_val(loop); |
| 1192 |
} |
} |