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 |
|
|
439 |
env->head->next= temp; |
env->head->next= temp; |
440 |
} |
} |
441 |
|
|
442 |
|
/* Rotate the first three elements on the stack. */ |
443 |
|
extern void rot(environment *env) |
444 |
|
{ |
445 |
|
stackitem *temp= env->head; |
446 |
|
|
447 |
|
if(env->head==NULL || env->head->next==NULL |
448 |
|
|| env->head->next->next==NULL) { |
449 |
|
printerr("Too Few Arguments"); |
450 |
|
env->err=1; |
451 |
|
return; |
452 |
|
} |
453 |
|
|
454 |
|
env->head= env->head->next->next; |
455 |
|
temp->next->next= env->head->next; |
456 |
|
env->head->next= temp; |
457 |
|
} |
458 |
|
|
459 |
/* Recall a value from a symbol, if bound */ |
/* Recall a value from a symbol, if bound */ |
460 |
extern void rcl(environment *env) |
extern void rcl(environment *env) |
461 |
{ |
{ |
1021 |
} |
} |
1022 |
push_val(&(env->head), copy_val(env->head->item)); |
push_val(&(env->head), copy_val(env->head->item)); |
1023 |
} |
} |
1024 |
|
|
1025 |
|
/* If-Then */ |
1026 |
|
extern void ift(environment *env) { |
1027 |
|
|
1028 |
|
int truth; |
1029 |
|
|
1030 |
|
if((env->head)==NULL || env->head->next==NULL) { |
1031 |
|
printerr("Too Few Arguments"); |
1032 |
|
env->err=1; |
1033 |
|
return; |
1034 |
|
} |
1035 |
|
|
1036 |
|
if(env->head->next->item->type != integer) { |
1037 |
|
printerr("Bad Argument Type"); |
1038 |
|
env->err=2; |
1039 |
|
return; |
1040 |
|
} |
1041 |
|
|
1042 |
|
swap(env); |
1043 |
|
if(env->err) return; |
1044 |
|
|
1045 |
|
truth=env->head->item->content.val; |
1046 |
|
|
1047 |
|
toss(env); |
1048 |
|
if(env->err) return; |
1049 |
|
|
1050 |
|
if(truth) |
1051 |
|
eval(env); |
1052 |
|
else |
1053 |
|
toss(env); |
1054 |
|
} |
1055 |
|
|
1056 |
|
|
1057 |
|
/* If-Then-Else */ |
1058 |
|
extern void ifte(environment *env) { |
1059 |
|
|
1060 |
|
int truth; |
1061 |
|
|
1062 |
|
if((env->head)==NULL || env->head->next==NULL |
1063 |
|
|| env->head->next->next==NULL) { |
1064 |
|
printerr("Too Few Arguments"); |
1065 |
|
env->err=1; |
1066 |
|
return; |
1067 |
|
} |
1068 |
|
|
1069 |
|
if(env->head->next->next->item->type != integer) { |
1070 |
|
printerr("Bad Argument Type"); |
1071 |
|
env->err=2; |
1072 |
|
return; |
1073 |
|
} |
1074 |
|
|
1075 |
|
rot(env); |
1076 |
|
if(env->err) return; |
1077 |
|
|
1078 |
|
truth=env->head->item->content.val; |
1079 |
|
|
1080 |
|
toss(env); |
1081 |
|
if(env->err) return; |
1082 |
|
|
1083 |
|
if(!truth) |
1084 |
|
swap(env); |
1085 |
|
if(env->err) return; |
1086 |
|
|
1087 |
|
toss(env); |
1088 |
|
if(env->err) return; |
1089 |
|
|
1090 |
|
eval(env); |
1091 |
|
} |
1092 |
|
|