153 |
/* Remove content */ |
/* Remove content */ |
154 |
switch(env->gc_ref->item->type){ |
switch(env->gc_ref->item->type){ |
155 |
case string: |
case string: |
156 |
free(env->gc_ref->item->content.ptr); |
free(env->gc_ref->item->content.string); |
157 |
break; |
break; |
158 |
case tcons: |
case tcons: |
159 |
free(env->gc_ref->item->content.c); |
free(env->gc_ref->item->content.c); |
330 |
return new_string; /* The caller must free() it */ |
return new_string; /* The caller must free() it */ |
331 |
} |
} |
332 |
|
|
|
extern void mangle(environment *env) |
|
|
{ |
|
|
char *new_string; |
|
|
|
|
|
if(env->head->type==empty) { |
|
|
printerr("Too Few Arguments"); |
|
|
env->err= 1; |
|
|
return; |
|
|
} |
|
|
|
|
|
if(CAR(env->head)->type!=string) { |
|
|
printerr("Bad Argument Type"); |
|
|
env->err= 2; |
|
|
return; |
|
|
} |
|
|
|
|
|
new_string= mangle_str(CAR(env->head)->content.string); |
|
|
|
|
|
toss(env); |
|
|
if(env->err) return; |
|
|
|
|
|
push_cstring(env, new_string); |
|
|
} |
|
|
|
|
333 |
/* Push a symbol onto the stack. */ |
/* Push a symbol onto the stack. */ |
334 |
void push_sym(environment *env, const char *in_string) |
void push_sym(environment *env, const char *in_string) |
335 |
{ |
{ |
355 |
|
|
356 |
/* Look up the symbol name in the hash table */ |
/* Look up the symbol name in the hash table */ |
357 |
new_symbol= hash(env->symbols, in_string); |
new_symbol= hash(env->symbols, in_string); |
358 |
new_value->content.ptr= *new_symbol; |
new_value->content.sym= *new_symbol; |
359 |
|
|
360 |
if(*new_symbol==NULL) { /* If symbol was undefined */ |
if(*new_symbol==NULL) { /* If symbol was undefined */ |
361 |
|
|
369 |
strcpy((*new_symbol)->id, in_string); |
strcpy((*new_symbol)->id, in_string); |
370 |
|
|
371 |
/* Intern the new symbol in the hash table */ |
/* Intern the new symbol in the hash table */ |
372 |
new_value->content.ptr= *new_symbol; |
new_value->content.sym= *new_symbol; |
373 |
|
|
374 |
/* Try to load the symbol name as an external function, to see if |
/* Try to load the symbol name as an external function, to see if |
375 |
we should bind the symbol to a new function pointer value */ |
we should bind the symbol to a new function pointer value */ |
1326 |
POSSIBILITY OF SUCH DAMAGES.\n"); |
POSSIBILITY OF SUCH DAMAGES.\n"); |
1327 |
} |
} |
1328 |
|
|
|
/* General assoc function */ |
|
|
void assocgen(environment *env, funcp eqfunc) |
|
|
{ |
|
|
value *key, *item; |
|
|
|
|
|
/* Needs two values on the stack, the top one must be an association |
|
|
list */ |
|
|
if(env->head->type==empty || CDR(env->head)->type==empty) { |
|
|
printerr("Too Few Arguments"); |
|
|
env->err= 1; |
|
|
return; |
|
|
} |
|
|
|
|
|
if(CAR(env->head)->type!=tcons) { |
|
|
printerr("Bad Argument Type"); |
|
|
env->err= 2; |
|
|
return; |
|
|
} |
|
|
|
|
|
key=CAR(CDR(env->head)); |
|
|
item=CAR(env->head); |
|
|
|
|
|
while(item->type == tcons){ |
|
|
if(CAR(item)->type != tcons){ |
|
|
printerr("Bad Argument Type"); |
|
|
env->err= 2; |
|
|
return; |
|
|
} |
|
|
push_val(env, key); |
|
|
push_val(env, CAR(CAR(item))); |
|
|
eqfunc(env); if(env->err) return; |
|
|
|
|
|
/* Check the result of 'eqfunc' */ |
|
|
if(env->head->type==empty) { |
|
|
printerr("Too Few Arguments"); |
|
|
env->err= 1; |
|
|
return; |
|
|
} |
|
|
if(CAR(env->head)->type!=integer) { |
|
|
printerr("Bad Argument Type"); |
|
|
env->err= 2; |
|
|
return; |
|
|
} |
|
|
|
|
|
if(CAR(env->head)->content.i){ |
|
|
toss(env); if(env->err) return; |
|
|
break; |
|
|
} |
|
|
toss(env); if(env->err) return; |
|
|
|
|
|
if(item->type!=tcons) { |
|
|
printerr("Bad Argument Type"); |
|
|
env->err= 2; |
|
|
return; |
|
|
} |
|
|
|
|
|
item=CDR(item); |
|
|
} |
|
|
|
|
|
if(item->type == tcons){ /* A match was found */ |
|
|
push_val(env, CAR(item)); |
|
|
} else { |
|
|
push_int(env, 0); |
|
|
} |
|
|
swap(env); if(env->err) return; |
|
|
toss(env); if(env->err) return; |
|
|
swap(env); if(env->err) return; |
|
|
toss(env); |
|
|
} |
|
|
|
|
1329 |
/* Discard the top element of the stack. */ |
/* Discard the top element of the stack. */ |
1330 |
extern void toss(environment *env) |
extern void toss(environment *env) |
1331 |
{ |
{ |