/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.106 by masse, Tue Mar 12 15:13:48 2002 UTC revision 1.109 by masse, Thu Mar 14 10:39:11 2002 UTC
# Line 37  Line 37 
37  #include <unistd.h>  #include <unistd.h>
38  /* EX_NOINPUT, EX_USAGE */  /* EX_NOINPUT, EX_USAGE */
39  #include <sysexits.h>  #include <sysexits.h>
40    /* assert */
41    #include <assert.h>
42    
43    #ifdef __linux__
44  /* mtrace, muntrace */  /* mtrace, muntrace */
45  #include <mcheck.h>  #include <mcheck.h>
46  /* ioctl */  /* ioctl */
47  #include <sys/ioctl.h>  #include <sys/ioctl.h>
48  /* KDMKTONE */  /* KDMKTONE */
49  #include <linux/kd.h>  #include <linux/kd.h>
50    #endif /* __linux__ */
51    
52  #include "stack.h"  #include "stack.h"
53    
# Line 118  value* new_val(environment *env) Line 123  value* new_val(environment *env)
123    stackitem *nitem= malloc(sizeof(stackitem));    stackitem *nitem= malloc(sizeof(stackitem));
124    
125    nval->content.ptr= NULL;    nval->content.ptr= NULL;
126      nval->type= integer;
127    
128    nitem->item= nval;    nitem->item= nval;
129    nitem->next= env->gc_ref;    nitem->next= env->gc_ref;
# Line 255  void push_val(environment *env, value *v Line 261  void push_val(environment *env, value *v
261    value *new_value= new_val(env);    value *new_value= new_val(env);
262    
263    new_value->content.c= malloc(sizeof(cons));    new_value->content.c= malloc(sizeof(cons));
264      assert(new_value->content.c!=NULL);
265    new_value->type= tcons;    new_value->type= tcons;
266    CAR(new_value)= val;    CAR(new_value)= val;
267    CDR(new_value)= env->head;    CDR(new_value)= env->head;
# Line 883  extern void quit(environment *env) Line 890  extern void quit(environment *env)
890    if(env->free_string!=NULL)    if(env->free_string!=NULL)
891      free(env->free_string);      free(env->free_string);
892        
893    #ifdef __linux__
894    muntrace();    muntrace();
895    #endif
896    
897    exit(EXIT_SUCCESS);    exit(EXIT_SUCCESS);
898  }  }
# Line 958  int main(int argc, char **argv) Line 967  int main(int argc, char **argv)
967    
968    int c;                        /* getopt option character */    int c;                        /* getopt option character */
969    
970    #ifdef __linux__
971    mtrace();    mtrace();
972    #endif
973    
974    init_env(&myenv);    init_env(&myenv);
975    
# Line 1256  value *copy_val(environment *env, value Line 1267  value *copy_val(environment *env, value
1267    
1268    protect(old_value);    protect(old_value);
1269    new_value= new_val(env);    new_value= new_val(env);
   protect(new_value);  
1270    new_value->type= old_value->type;    new_value->type= old_value->type;
1271    
1272    switch(old_value->type){    switch(old_value->type){
# Line 1271  value *copy_val(environment *env, value Line 1281  value *copy_val(environment *env, value
1281        strdup((char *)(old_value->content.ptr));        strdup((char *)(old_value->content.ptr));
1282      break;      break;
1283    case tcons:    case tcons:
     new_value= NULL;  
1284    
1285      new_value->content.c= malloc(sizeof(cons));      new_value->content.c= malloc(sizeof(cons));
1286        assert(new_value->content.c!=NULL);
1287    
1288      CAR(new_value)= copy_val(env, CAR(old_value)); /* recurse */      CAR(new_value)= copy_val(env, CAR(old_value)); /* recurse */
1289      CDR(new_value)= copy_val(env, CDR(old_value)); /* recurse */      CDR(new_value)= copy_val(env, CDR(old_value)); /* recurse */
1290      break;      break;
1291    }    }
1292    
1293    unprotect(old_value); unprotect(new_value);    unprotect(old_value);
1294    
1295    return new_value;    return new_value;
1296  }  }
# Line 1365  extern void ifelse(environment *env) Line 1376  extern void ifelse(environment *env)
1376  extern void sx_656c7365(environment *env)  extern void sx_656c7365(environment *env)
1377  {  {
1378    if(env->head==NULL || CDR(env->head)==NULL    if(env->head==NULL || CDR(env->head)==NULL
1379       || CDR(CDR(env->head))==NULL || CDR(CDR(CDR(env->head)))==NULL) {       || CDR(CDR(env->head))==NULL || CDR(CDR(CDR(env->head)))==NULL
1380         || CDR(CDR(CDR(CDR(env->head))))==NULL) {
1381        printerr("Too Few Arguments");
1382        env->err= 1;
1383        return;
1384      }
1385    
1386      if(CAR(CDR(env->head))->type!=symb
1387         || strcmp(CAR(CDR(env->head))->content.sym->id, "then")!=0
1388         || CAR(CDR(CDR(CDR(env->head))))->type!=symb
1389         || strcmp(CAR(CDR(CDR(CDR(env->head))))->content.sym->id, "if")!=0) {
1390        printerr("Bad Argument Type");
1391        env->err= 2;
1392        return;
1393      }
1394    
1395      swap(env); toss(env); rot(env); toss(env);
1396      ifelse(env);
1397    }
1398    
1399    extern void then(environment *env)
1400    {
1401      if(env->head==NULL || CDR(env->head)==NULL
1402         || CDR(CDR(env->head))==NULL) {
1403      printerr("Too Few Arguments");      printerr("Too Few Arguments");
1404      env->err= 1;      env->err= 1;
1405      return;      return;
# Line 1379  extern void sx_656c7365(environment *env Line 1413  extern void sx_656c7365(environment *env
1413    }    }
1414    
1415    swap(env); toss(env);    swap(env); toss(env);
1416    ifelse(env);    sx_6966(env);
1417  }  }
1418    
1419  /* "while" */  /* "while" */
# Line 1672  extern void sx_72656164(environment *env Line 1706  extern void sx_72656164(environment *env
1706      return sx_72656164(env);      return sx_72656164(env);
1707  }  }
1708    
1709    #ifdef __linux__
1710  extern void beep(environment *env)  extern void beep(environment *env)
1711  {  {
1712    int freq, dur, period, ticks;    int freq, dur, period, ticks;
# Line 1714  extern void beep(environment *env) Line 1749  extern void beep(environment *env)
1749      abort();      abort();
1750    }    }
1751  }  }
1752    #endif /* __linux__ */
1753    
1754  /* "wait" */  /* "wait" */
1755  extern void sx_77616974(environment *env)  extern void sx_77616974(environment *env)

Legend:
Removed from v.1.106  
changed lines
  Added in v.1.109

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26