Changeset 133


Ignore:
Timestamp:
Apr 10, 2008, 11:07:07 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Made lisp.cpp slightly more readable by using an enum instead of hardcoded values for the system functions.
Location:
abuse/trunk/src/lisp
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/lisp/Makefile.am

    r130 r133  
    77    lisp_gc.cpp lisp_gc.hpp \
    88    trig.cpp \
    9     stack.hpp \
     9    stack.hpp symbols.hpp \
    1010    $(NULL)
    1111
  • abuse/trunk/src/lisp/lisp.cpp

    r129 r133  
    2121#include "lisp.hpp"
    2222#include "lisp_gc.hpp"
     23#include "symbols.hpp"
     24
    2325#ifdef NO_LIBS
    24 #include "fakelib.hpp"
     26#   include "fakelib.hpp"
    2527#else
    26 #include "status.hpp"
    27 #include "macs.hpp"
    28 #include "specs.hpp"
    29 #include "dprint.hpp"
    30 #include "cache.hpp"
    31 #include "dev.hpp"
     28#   include "status.hpp"
     29#   include "macs.hpp"
     30#   include "specs.hpp"
     31#   include "dprint.hpp"
     32#   include "cache.hpp"
     33#   include "dev.hpp"
    3234#endif
    3335
     
    4446
    4547
    46 char *space[4],*free_space[4];
    47 int space_size[4],print_level=0,trace_level=0,trace_print_level=1000;
     48char *space[4], *free_space[4];
     49int space_size[4], print_level=0, trace_level=0, trace_print_level=1000;
    4850int total_user_functions;
    4951
    5052int current_space;  // normally set to TMP_SPACE, unless compiling or other needs
    5153
    52 // when you don't need as much as strcmp, this is faster...
    53 inline int streq(char const *s1, char const *s2)
    54 {
    55   while (*s1)
    56   {
    57     if (*(s1++)!=*(s2++))
    58       return 0;
    59   }
    60   return (*s2==0);
    61 }
    62 
    6354int break_level=0;
    6455
    6556void l1print(void *block)
    6657{
    67   if (!block)
    68     lprint(block);
    69   else
    70   {
    71     if (item_type(block)==L_CONS_CELL)
    72     {
    73       dprintf("(");
    74       for (;block && item_type(block)==L_CONS_CELL;block=CDR(block))
    75       {
    76     void *a=CAR(block);
    77     if (item_type(a)==L_CONS_CELL)
    78       dprintf("[...]");
    79     else lprint(a);
    80       }
    81       if (block)
    82       {
     58    if(!block || item_type(block) != L_CONS_CELL)
     59    {
     60        lprint(block);
     61        return;
     62    }
     63
     64    dprintf("(");
     65    for( ; block && item_type(block) == L_CONS_CELL; block = CDR(block))
     66    {
     67        void *a = CAR(block);
     68        if(item_type(a) == L_CONS_CELL)
     69            dprintf("[...]");
     70        else
     71            lprint(a);
     72    }
     73    if (block)
     74    {
    8375        dprintf(" . ");
    84     lprint(block);
    85       }
    86       dprintf(")");
    87     } else lprint(block);
    88   }
    89 }
    90 
    91 void where_print(int max_lev=-1)
    92 {
    93   dprintf("Main program\n");
    94   if (max_lev==-1) max_lev=l_ptr_stack.son;
    95   else if (max_lev>=l_ptr_stack.son) max_lev=l_ptr_stack.son-1;
    96 
    97   for (int i=0;i<max_lev;i++)
    98   {
    99     dprintf("%d> ",i);
    100     lprint(*l_ptr_stack.sdata[i]);
    101   }
     76        lprint(block);
     77    }
     78    dprintf(")");
     79}
     80
     81void where_print(int max_lev = -1)
     82{
     83    dprintf("Main program\n");
     84    if (max_lev==-1) max_lev=l_ptr_stack.son;
     85    else if (max_lev>=l_ptr_stack.son) max_lev=l_ptr_stack.son-1;
     86
     87    for (int i=0;i<max_lev;i++)
     88    {
     89        dprintf("%d> ", i);
     90        lprint(*l_ptr_stack.sdata[i]);
     91    }
    10292}
    10393
    10494void print_trace_stack(int max_levels)
    10595{
    106   where_print(max_levels);
     96    where_print(max_levels);
    10797}
    10898
     
    115105  va_list ap;
    116106  va_start(ap, format);
    117   vsprintf(st,format,ap);
     107  vsprintf(st, format, ap);
    118108  va_end(ap);
    119   dprintf("%s\n",st);
     109  dprintf("%s\n", st);
    120110  int cont=0;
    121111  do
    122112  {
    123113    dprintf("type q to quit\n");
    124     dprintf("%d. Break> ",break_level);
    125     dgets(st,300);
    126     if (!strcmp(st,"c") || !strcmp(st,"cont") || !strcmp(st,"continue"))
     114    dprintf("%d. Break> ", break_level);
     115    dgets(st, 300);
     116    if (!strcmp(st, "c") || !strcmp(st, "cont") || !strcmp(st, "continue"))
    127117      cont=1;
    128     else if (!strcmp(st,"w") || !strcmp(st,"where"))
     118    else if (!strcmp(st, "w") || !strcmp(st, "where"))
    129119      where_print();
    130     else if (!strcmp(st,"q") || !strcmp(st,"quit"))
     120    else if (!strcmp(st, "q") || !strcmp(st, "quit"))
    131121      exit(1);
    132     else if (!strcmp(st,"e") || !strcmp(st,"env") || !strcmp(st,"environment"))
     122    else if (!strcmp(st, "e") || !strcmp(st, "env") || !strcmp(st, "environment"))
    133123    {
    134124      dprintf("Enviorment : \nnot supported right now\n");
    135125
    136     } else if (!strcmp(st,"h") || !strcmp(st,"help") || !strcmp(st,"?"))
     126    }
     127    else if (!strcmp(st, "h") || !strcmp(st, "help") || !strcmp(st, "?"))
    137128    {
    138129      dprintf("CLIVE Debugger\n");
     
    164155  if (current_space!=PERM_SPACE && current_space!=GC_SPACE)
    165156  {
    166     lbreak("%s : action requires permanant space\n",why);
     157    lbreak("%s : action requires permanant space\n", why);
    167158    exit(0);
    168159  }
     
    181172void *lmalloc(int size, int which_space)
    182173{
    183   return malloc(size); /* XXX */
     174  return malloc(size); /* XXX FIXME: do we want to fix this one day? */
    184175
    185176#ifdef WORD_ALIGN
     
    203194    if (fart)
    204195    {
    205       lbreak("lisp : cannot malloc %d bytes in space #%d\n",size,which_space);
     196      lbreak("lisp : cannot malloc %d bytes in space #%d\n", size, which_space);
    206197      exit(0);
    207198    }
     
    229220  long s=sizeof(lisp_1d_array)+size*sizeof(void *);
    230221  if (s<8) s=8;
    231   void *p=(lisp_1d_array *)lmalloc(s,current_space);
     222  void *p=(lisp_1d_array *)lmalloc(s, current_space);
    232223  ((lisp_1d_array *)p)->type=L_1D_ARRAY;
    233224  ((lisp_1d_array *)p)->size=size;
    234225  void **data=(void **)(((lisp_1d_array *)p)+1);
    235   memset(data,0,size*sizeof(void *));
     226  memset(data, 0, size*sizeof(void *));
    236227  p_ref r1(p);
    237228
     
    243234      x=eval(CAR(CDR(rest)));
    244235      data=(void **)(((lisp_1d_array *)p)+1);
    245       for (int i=0;i<size;i++,x=CDR(x))
     236      for (int i=0;i<size;i++, x=CDR(x))
    246237      {
    247238    if (!x)
     
    275266lisp_fixed_point *new_lisp_fixed_point(int32_t x)
    276267{
    277   lisp_fixed_point *p=(lisp_fixed_point *)lmalloc(sizeof(lisp_fixed_point),current_space);
     268  lisp_fixed_point *p=(lisp_fixed_point *)lmalloc(sizeof(lisp_fixed_point), current_space);
    278269  p->type=L_FIXED_POINT;
    279270  p->x=x;
     
    284275lisp_object_var *new_lisp_object_var(int16_t number)
    285276{
    286   lisp_object_var *p=(lisp_object_var *)lmalloc(sizeof(lisp_object_var),current_space);
     277  lisp_object_var *p=(lisp_object_var *)lmalloc(sizeof(lisp_object_var), current_space);
    287278  p->type=L_OBJECT_VAR;
    288279  p->number=number;
     
    294285{
    295286  if (addr==NULL) return NULL;
    296   lisp_pointer *p=(lisp_pointer *)lmalloc(sizeof(lisp_pointer),current_space);
     287  lisp_pointer *p=(lisp_pointer *)lmalloc(sizeof(lisp_pointer), current_space);
    297288  p->type=L_POINTER;
    298289  p->addr=addr;
     
    302293struct lisp_character *new_lisp_character(uint16_t ch)
    303294{
    304   lisp_character *c=(lisp_character *)lmalloc(sizeof(lisp_character),current_space);
     295  lisp_character *c=(lisp_character *)lmalloc(sizeof(lisp_character), current_space);
    305296  c->type=L_CHARACTER;
    306297  c->ch=ch;
     
    313304  if (size<8) size=8;
    314305
    315   lisp_string *s=(lisp_string *)lmalloc(size,current_space);
     306  lisp_string *s=(lisp_string *)lmalloc(size, current_space);
    316307  s->type=L_STRING;
    317308  char *sloc=((char *)s)+sizeof(lisp_string);
    318   strcpy(sloc,string);
     309  strcpy(sloc, string);
    319310  return s;
    320311}
     
    324315  int size=sizeof(lisp_string)+length+1;
    325316  if (size<8) size=8;
    326   lisp_string *s=(lisp_string *)lmalloc(size,current_space);
     317  lisp_string *s=(lisp_string *)lmalloc(size, current_space);
    327318  s->type=L_STRING;
    328319  char *sloc=((char *)s)+sizeof(lisp_string);
    329   memcpy(sloc,string,length);
     320  memcpy(sloc, string, length);
    330321  sloc[length]=0;
    331322  return s;
     
    336327  int size=sizeof(lisp_string)+length;
    337328  if (size<8) size=8;
    338   lisp_string *s=(lisp_string *)lmalloc(size,current_space);
     329  lisp_string *s=(lisp_string *)lmalloc(size, current_space);
    339330  s->type=L_STRING;
    340331  char *sloc=((char *)s)+sizeof(lisp_string);
    341   strcpy(sloc,"");
     332  strcpy(sloc, "");
    342333  return s;
    343334}
     
    346337lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list)
    347338{
    348   p_ref r1(arg_list),r2(block_list);
    349   lisp_user_function *lu=(lisp_user_function *)lmalloc(sizeof(lisp_user_function),current_space);
     339  p_ref r1(arg_list), r2(block_list);
     340  lisp_user_function *lu=(lisp_user_function *)lmalloc(sizeof(lisp_user_function), current_space);
    350341  lu->type=L_USER_FUNCTION;
    351342  lu->arg_list=arg_list;
     
    360351    current_space=PERM_SPACE;       // make sure all functions get defined in permanant space
    361352
    362   lisp_user_function *lu=(lisp_user_function *)lmalloc(sizeof(lisp_user_function),current_space);
     353  lisp_user_function *lu=(lisp_user_function *)lmalloc(sizeof(lisp_user_function), current_space);
    363354  lu->type=L_USER_FUNCTION;
    364355  lu->alist=arg_list;
     
    422413lisp_number *new_lisp_node(long num)
    423414{
    424   lisp_number *n=(lisp_number *)lmalloc(sizeof(lisp_number),current_space);
     415  lisp_number *n=(lisp_number *)lmalloc(sizeof(lisp_number), current_space);
    425416  n->type=L_NUMBER;
    426417  n->num=num;
     
    430421lisp_symbol *new_lisp_symbol(char *name)
    431422{
    432   lisp_symbol *s=(lisp_symbol *)lmalloc(sizeof(lisp_symbol),current_space);
     423  lisp_symbol *s=(lisp_symbol *)lmalloc(sizeof(lisp_symbol), current_space);
    433424  s->type=L_SYMBOL;
    434425  s->name=new_lisp_string(name);
     
    443434lisp_number *new_lisp_number(long num)
    444435{
    445   lisp_number *s=(lisp_number *)lmalloc(sizeof(lisp_number),current_space);
     436  lisp_number *s=(lisp_number *)lmalloc(sizeof(lisp_number), current_space);
    446437  s->type=L_NUMBER;
    447438  s->num=num;
     
    452443cons_cell *new_cons_cell()
    453444{
    454   cons_cell *c=(cons_cell *)lmalloc(sizeof(cons_cell),current_space);
     445  cons_cell *c=(cons_cell *)lmalloc(sizeof(cons_cell), current_space);
    455446  c->type=L_CONS_CELL;
    456447  c->car=NULL;
     
    468459    {
    469460      if (*loc=='\n') lines++;
    470       dprintf("%c",*loc);
     461      dprintf("%c", *loc);
    471462    }
    472463    dprintf("\nPROGRAM LOCATION : \n");
    473464  }
    474465  if (cause)
    475     dprintf("ERROR MESSAGE : %s\n",cause);
     466    dprintf("ERROR MESSAGE : %s\n", cause);
    476467  lbreak("");
    477468  exit(0);
     
    483474  if (num<0)
    484475  {
    485     lbreak("NTH: %d is not a nonnegative fixnum and therefore not a valid index\n",num);
     476    lbreak("NTH: %d is not a nonnegative fixnum and therefore not a valid index\n", num);
    486477    exit(1);
    487478  }
     
    607598  else if ((n1 && !n2) || (n2 && !n1)) return NULL;
    608599  {
    609     int t1=*((ltype *)n1),t2=*((ltype *)n2);
     600    int t1=*((ltype *)n1), t2=*((ltype *)n2);
    610601    if (t1!=t2) return NULL;
    611602    else if (t1==L_NUMBER)
     
    639630  if (x>=((lisp_1d_array *)a)->size || x<0)
    640631  {
    641     lbreak("array refrence out of bounds (%d)\n",x);
     632    lbreak("array refrence out of bounds (%d)\n", x);
    642633    exit(0);
    643634  }
     
    647638void *lisp_equal(void *n1, void *n2)
    648639{
    649 
    650   if (!n1 && !n2)           // if both nil, then equal
    651     return true_symbol;   
    652   else if ((n1 && !n2) || (n2 && !n1))   // one nil, nope
    653     return NULL;
    654   else
    655   {
    656     int t1=item_type(n1),t2=item_type(n2);
    657     if (t1!=t2) return NULL;
    658     else
    659     {
    660       switch (t1)
    661       {
     640    if(!n1 && !n2) // if both nil, then equal
     641        return true_symbol;
     642
     643    if(!n1 || !n2) // one nil, nope
     644        return NULL;
     645
     646    int t1 = item_type(n1), t2 = item_type(n2);
     647    if(t1 != t2)
     648        return NULL;
     649
     650    switch (t1)
     651    {
    662652    case L_STRING :
    663     { if (streq(lstring_value(n1),lstring_value(n2))) return true_symbol; else return NULL; }
    664     break;
     653        if (!strcmp(lstring_value(n1), lstring_value(n2)))
     654            return true_symbol;
     655        return NULL;
    665656    case L_CONS_CELL :
    666     {
    667       while (n1 && n2) // loop through the list and compare each element
    668       {
    669         if (!lisp_equal(CAR(n1),CAR(n2)))
    670           return NULL;
    671         n1=CDR(n1);
    672         n2=CDR(n2);
    673         if (n1 && *((ltype *)n1)!=L_CONS_CELL)
    674           return lisp_equal(n1,n2);
    675       }
    676       if (n1 || n2) return NULL;   // if one is longer than the other
    677       else return true_symbol;
    678     } break;
     657        while (n1 && n2) // loop through the list and compare each element
     658        {
     659          if (!lisp_equal(CAR(n1), CAR(n2)))
     660            return NULL;
     661          n1=CDR(n1);
     662          n2=CDR(n2);
     663          if (n1 && *((ltype *)n1)!=L_CONS_CELL)
     664            return lisp_equal(n1, n2);
     665        }
     666        if (n1 || n2)
     667            return NULL;   // if one is longer than the other
     668        return true_symbol;
    679669    default :
    680           return lisp_eq(n1,n2);
    681     break;
    682       }
    683     }
    684   }
     670        return lisp_eq(n1, n2);
     671    }
    685672}
    686673
     
    794781  for (cs=(cons_cell *)symbol_list;cs;cs=(cons_cell *)CDR(cs))
    795782  {
    796     if (streq( ((char *)((lisp_symbol *)cs->car)->name)+sizeof(lisp_string),name))
     783    if (!strcmp( ((char *)((lisp_symbol *)cs->car)->name)+sizeof(lisp_string), name))
    797784      return (lisp_symbol *)(cs->car);
    798785  }
     
    828815  while (p)
    829816  {
    830     int cmp=strcmp(name,((char *)p->name)+sizeof(lisp_string));
     817    int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string));
    831818    if (cmp==0) return p;
    832819    else if (cmp<0) p=p->left;
     
    844831  while (p)
    845832  {
    846     int cmp=strcmp(name,((char *)p->name)+sizeof(lisp_string));
     833    int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string));
    847834    if (cmp==0) return p;
    848835    else if (cmp<0)
     
    900887    while (list)
    901888    {
    902       if (lisp_eq(CAR(CAR(list)),item))
     889      if (lisp_eq(CAR(CAR(list)), item))
    903890        return lcar(list);   
    904891      list=(cons_cell *)(CDR(list));
     
    934921
    935922  void *ret=NULL;
    936   long l1=list_length(list1),l2=list_length(list2);
     923  long l1=list_length(list1), l2=list_length(list2);
    937924  if (l1!=l2)
    938925  {   
     
    944931  if (l1!=0)
    945932  {
    946     void *first=NULL,*last=NULL,*cur=NULL,*tmp;
    947     p_ref r1(first),r2(last),r3(cur);
     933    void *first=NULL, *last=NULL, *cur=NULL, *tmp;
     934    p_ref r1(first), r2(last), r3(cur);
    948935    while (list1)
    949936    {
     
    1008995  if (s->function!=l_undefined)
    1009996  {
    1010     lbreak("add_sys_fucntion -> symbol %s already has a function\n",name);
     997    lbreak("add_sys_fucntion -> symbol %s already has a function\n", name);
    1011998    exit(0);
    1012999  }
    1013   else s->function=new_lisp_sys_function(min_args,max_args,number);
     1000  else s->function=new_lisp_sys_function(min_args, max_args, number);
    10141001  return s;
    10151002}
     
    10211008  if (s->value!=l_undefined)
    10221009  {
    1023     lbreak("add_c_object -> symbol %s already has a value\n",lstring_value(symbol_name(s)));
     1010    lbreak("add_c_object -> symbol %s already has a value\n", lstring_value(symbol_name(s)));
    10241011    exit(0);
    10251012  }
     
    10351022  if (s->function!=l_undefined)
    10361023  {
    1037     lbreak("add_sys_fucntion -> symbol %s already has a function\n",name);
     1024    lbreak("add_sys_fucntion -> symbol %s already has a function\n", name);
    10381025    exit(0);
    10391026  }
    1040   else s->function=new_lisp_c_function(min_args,max_args,number);
     1027  else s->function=new_lisp_c_function(min_args, max_args, number);
    10411028  return s;
    10421029}
     
    10491036  if (s->function!=l_undefined)
    10501037  {
    1051     lbreak("add_sys_fucntion -> symbol %s already has a function\n",name);
     1038    lbreak("add_sys_fucntion -> symbol %s already has a function\n", name);
    10521039    exit(0);
    10531040  }
    1054   else s->function=new_lisp_c_bool(min_args,max_args,number);
     1041  else s->function=new_lisp_c_bool(min_args, max_args, number);
    10551042  return s;
    10561043}
     
    10641051  if (s->function!=l_undefined)
    10651052  {
    1066     lbreak("add_sys_fucntion -> symbol %s already has a function\n",name);
     1053    lbreak("add_sys_fucntion -> symbol %s already has a function\n", name);
    10671054    exit(0);
    10681055  }
    1069   else s->function=new_user_lisp_function(min_args,max_args,number);
     1056  else s->function=new_user_lisp_function(min_args, max_args, number);
    10701057  return s;
    10711058}
     
    11011088  {
    11021089    while (*s && *s!='\n' && *s!='\r' && *s!=26) s++;
    1103     return read_ltoken(s,buffer);
     1090    return read_ltoken(s, buffer);
    11041091  } else if  (*s=='/' && *(s+1)=='*')   // c style comment
    11051092  {
    11061093    skip_c_comment(s);
    1107     return read_ltoken(s,buffer);
     1094    return read_ltoken(s, buffer);
    11081095  }
    11091096  else if (*s==0)
     
    11391126int end_of_program(char const *s)
    11401127{
    1141   return !read_ltoken(s,n);
     1128  return !read_ltoken(s, n);
    11421129}
    11431130
     
    11451132void push_onto_list(void *object, void *&list)
    11461133{
    1147   p_ref r1(object),r2(list);
     1134  p_ref r1(object), r2(list);
    11481135  cons_cell *c=new_cons_cell();
    11491136  c->car=object;
     
    11571144{
    11581145  void *ret=NULL;
    1159   if (!read_ltoken(s,n))
    1160     lerror(NULL,"unexpected end of program");
    1161   if (streq(n,"nil"))
     1146  if (!read_ltoken(s, n))
     1147    lerror(NULL, "unexpected end of program");
     1148  if (!strcmp(n, "nil"))
    11621149    return NULL;
    11631150  else if (toupper(n[0])=='T' && !n[1])
     
    11651152  else if (n[0]=='\'')                    // short hand for quote function
    11661153  {
    1167     void *cs=new_cons_cell(),*c2=NULL,*tmp;
    1168     p_ref r1(cs),r2(c2);
     1154    void *cs=new_cons_cell(), *c2=NULL, *tmp;
     1155    p_ref r1(cs), r2(c2);
    11691156
    11701157    ((cons_cell *)cs)->car=quote_symbol;
     
    11781165  else if (n[0]=='`')                    // short hand for backquote function
    11791166  {
    1180     void *cs=new_cons_cell(),*c2=NULL,*tmp;
    1181     p_ref r1(cs),r2(c2);
     1167    void *cs=new_cons_cell(), *c2=NULL, *tmp;
     1168    p_ref r1(cs), r2(c2);
    11821169
    11831170    ((cons_cell *)cs)->car=backquote_symbol;
     
    11901177  }  else if (n[0]==',')              // short hand for comma function
    11911178  {
    1192     void *cs=new_cons_cell(),*c2=NULL,*tmp;
    1193     p_ref r1(cs),r2(c2);
     1179    void *cs=new_cons_cell(), *c2=NULL, *tmp;
     1180    p_ref r1(cs), r2(c2);
    11941181
    11951182    ((cons_cell *)cs)->car=comma_symbol;
     
    12031190  else if (n[0]=='(')                     // make a list of everything in ()
    12041191  {
    1205     void *first=NULL,*cur=NULL,*last=NULL;
    1206     p_ref r1(first),r2(cur),r3(last);
     1192    void *first=NULL, *cur=NULL, *last=NULL;
     1193    p_ref r1(first), r2(cur), r3(last);
    12071194    int done=0;
    12081195    do
    12091196    {
    12101197      char const *tmp=s;
    1211       if (!read_ltoken(tmp,n))           // check for the end of the list
    1212         lerror(NULL,"unexpected end of program");
     1198      if (!read_ltoken(tmp, n))           // check for the end of the list
     1199        lerror(NULL, "unexpected end of program");
    12131200      if (n[0]==')')
    12141201      {
    12151202                done=1;
    1216                 read_ltoken(s,n);                // read off the ')'
     1203                read_ltoken(s, n);                // read off the ')'
    12171204      }
    12181205      else
     
    12211208                {
    12221209                  if (!first)
    1223                     lerror(s,"token '.' not allowed here\n");   
     1210                    lerror(s, "token '.' not allowed here\n");   
    12241211                  else
    12251212                  {
    12261213                    void *tmp;
    1227                     read_ltoken(s,n);              // skip the '.'
     1214                    read_ltoken(s, n);              // skip the '.'
    12281215                    tmp=compile(s);
    12291216                    ((cons_cell *)last)->cdr=tmp;          // link the last cdr to
     
    12311218                  }
    12321219                } else if (!last && first)
    1233                   lerror(s,"illegal end of dotted list\n");
     1220                  lerror(s, "illegal end of dotted list\n");
    12341221                else
    12351222                {       
     
    12491236
    12501237  } else if (n[0]==')')
    1251     lerror(s,"mismatched )");
     1238    lerror(s, "mismatched )");
    12521239  else if (isdigit(n[0]) || (n[0]=='-' && isdigit(n[1])))
    12531240  {
    12541241    lisp_number *num=new_lisp_number(0);
    1255     sscanf(n,"%ld",&num->num);
     1242    sscanf(n, "%ld", &num->num);
    12561243    ret=num;
    12571244  } else if (n[0]=='"')
     
    12591246    ret=new_lisp_string(str_token_len(s));
    12601247    char *start=lstring_value(ret);
    1261     for (;*s && (*s!='"' || s[1]=='"');s++,start++)
     1248    for (;*s && (*s!='"' || s[1]=='"');s++, start++)
    12621249    {
    12631250      if (*s=='\\')
     
    12771264    if (n[1]=='\\')
    12781265    {
    1279       read_ltoken(s,n);                   // read character name
    1280       if (streq(n,"newline"))
     1266      read_ltoken(s, n);                   // read character name
     1267      if (!strcmp(n, "newline"))
    12811268        ret=new_lisp_character('\n');
    1282       else if (streq(n,"space"))
     1269      else if (!strcmp(n, "space"))
    12831270        ret=new_lisp_character(' ');
    12841271      else
     
    12871274    else if (n[1]==0)                           // short hand for function
    12881275    {
    1289       void *cs=new_cons_cell(),*c2=NULL,*tmp;
    1290       p_ref r4(cs),r5(c2);
     1276      void *cs=new_cons_cell(), *c2=NULL, *tmp;
     1277      p_ref r4(cs), r5(c2);
    12911278      tmp=make_find_symbol("function");
    12921279      ((cons_cell *)cs)->car=tmp;
     
    12991286    else
    13001287    {
    1301       lbreak("Unknown #\\ notation : %s\n",n);
     1288      lbreak("Unknown #\\ notation : %s\n", n);
    13021289      exit(0);
    13031290    }
     
    13691356      {
    13701357                char num[10];
    1371                 sprintf(num,"%ld",((lisp_number *)i)->num);
     1358                sprintf(num, "%ld", ((lisp_number *)i)->num);
    13721359        lprint_string(num);
    13731360      }
     
    13941381                     lprint_string(lstring_value(i));
    13951382                else
    1396              dprintf("\"%s\"",lstring_value(i));
     1383             dprintf("\"%s\"", lstring_value(i));
    13971384      }
    13981385      break;
     
    14011388      {
    14021389                char ptr[10];
    1403                     sprintf(ptr,"%p",lpointer_value(i));
     1390                    sprintf(ptr, "%p", lpointer_value(i));
    14041391                lprint_string(ptr);
    14051392      }
     
    14081395      {
    14091396                char num[20];
    1410                 sprintf(num,"%g",(lfixed_point_value(i)>>16)+
     1397                sprintf(num, "%g", (lfixed_point_value(i)>>16)+
    14111398                          ((lfixed_point_value(i)&0xffff))/(double)0x10000);
    14121399                lprint_string(num);
     
    14171404                {
    14181405                  uint8_t ch=((lisp_character *)i)->ch;
    1419                   current_print_file->write(&ch,1);
     1406                  current_print_file->write(&ch, 1);
    14201407                } else
    14211408                {
     
    14291416                    { dprintf("space"); break; }
    14301417                    default :
    1431                       dprintf("%c",ch);
     1418                      dprintf("%c", ch);
    14321419                  }
    14331420                }
     
    14681455void *eval_function(lisp_symbol *sym, void *arg_list)
    14691456{
    1470 
    1471 
    14721457#ifdef TYPE_CHECKING
    1473   int args,req_min,req_max;
     1458  int args, req_min, req_max;
    14741459  if (item_type(sym)!=L_SYMBOL)
    14751460  {
     
    14991484    case L_USER_FUNCTION :
    15001485    {
    1501       return eval_user_fun(sym,arg_list);
     1486      return eval_user_fun(sym, arg_list);
    15021487    } break;
    15031488    default :
     
    15411526  {
    15421527    case L_SYS_FUNCTION :
    1543     { ret=eval_sys_function( ((lisp_sys_function *)fun),arg_list); } break;
     1528    { ret=eval_sys_function( ((lisp_sys_function *)fun), arg_list); } break;
    15441529    case L_L_FUNCTION :
    1545     { ret=l_caller( ((lisp_sys_function *)fun)->fun_number,arg_list); } break;
     1530    { ret=l_caller( ((lisp_sys_function *)fun)->fun_number, arg_list); } break;
    15461531    case L_USER_FUNCTION :
    15471532    {
    1548       return eval_user_fun(sym,arg_list);
     1533      return eval_user_fun(sym, arg_list);
    15491534    } break;
    15501535    case L_C_FUNCTION :
    1551     {
    1552       void *first=NULL,*cur=NULL,*tmp;
    1553       p_ref r1(first),r2(cur);
     1536    case L_C_BOOL :
     1537    {
     1538      void *first=NULL, *cur=NULL, *tmp;
     1539      p_ref r1(first), r2(cur);
    15541540      while (arg_list)
    15551541      {
    1556                 if (first) {
    1557                   tmp=new_cons_cell();
    1558                   ((cons_cell *)cur)->cdr=tmp;
    1559                   cur=tmp;
    1560                 } else
    1561                   cur=first=new_cons_cell();
    1562            
    1563                 void *val=eval(CAR(arg_list));
    1564                 ((cons_cell *)cur)->car=val;
    1565                 arg_list=lcdr(arg_list);
    1566       }
    1567       ret=new_lisp_number(c_caller( ((lisp_sys_function *)fun)->fun_number,first));
    1568     } break;
    1569     case L_C_BOOL :
    1570     {
    1571       void *first=NULL,*cur=NULL,*tmp;
    1572       p_ref r1(first),r2(cur);
    1573       while (arg_list)
    1574       {
    1575                 if (first) {
    1576                   tmp=new_cons_cell();
    1577                   ((cons_cell *)cur)->cdr=tmp;
    1578                   cur=tmp;
    1579                 } else
    1580                   cur=first=new_cons_cell();
    1581            
    1582                 void *val=eval(CAR(arg_list));
    1583                 ((cons_cell *)cur)->car=val;
    1584                 arg_list=lcdr(arg_list);
    1585       }
    1586 
    1587       if (c_caller( ((lisp_sys_function *)fun)->fun_number,first))
     1542        if (first) {
     1543          tmp=new_cons_cell();
     1544          ((cons_cell *)cur)->cdr=tmp;
     1545          cur=tmp;
     1546        } else
     1547          cur=first=new_cons_cell();
     1548   
     1549        void *val=eval(CAR(arg_list));
     1550        ((cons_cell *)cur)->car=val;
     1551        arg_list=lcdr(arg_list);
     1552      }
     1553      if(t == L_C_FUNCTION)
     1554        ret=new_lisp_number(c_caller( ((lisp_sys_function *)fun)->fun_number, first));
     1555      else if (c_caller( ((lisp_sys_function *)fun)->fun_number, first))
    15881556        ret=true_symbol;
    15891557      else ret=NULL;
    15901558    } break;
    15911559    default :
    1592       fprintf(stderr,"not a fun, shouldn't happen\n");
     1560      fprintf(stderr, "not a fun, shouldn't happen\n");
    15931561  }
    15941562
     
    15981566#endif
    15991567
    1600 
    16011568  return ret;
    16021569}   
     
    16071574  if (p)
    16081575  {
    1609     pro_print(out,p->right);
     1576    pro_print(out, p->right);
    16101577    {
    16111578      char st[100];
    1612       sprintf(st,"%20s %f\n",lstring_value(symbol_name(p)),((lisp_symbol *)p)->time_taken);
    1613       out->write(st,strlen(st));
    1614     }
    1615     pro_print(out,p->left);
     1579      sprintf(st, "%20s %f\n", lstring_value(symbol_name(p)), ((lisp_symbol *)p)->time_taken);
     1580      out->write(st, strlen(st));
     1581    }
     1582    pro_print(out, p->left);
    16161583  }
    16171584}
     
    16191586void preport(char *fn)
    16201587{
    1621   bFILE *fp=open_file("preport.out","wb");
    1622   pro_print(fp,lsym_root);
     1588  bFILE *fp=open_file("preport.out", "wb");
     1589  pro_print(fp, lsym_root);
    16231590  delete fp;
    16241591}
     
    16421609    }
    16431610  }
    1644   int num_args=list_length(CDR(arg_list)),i,stop=0;
     1611  int num_args=list_length(CDR(arg_list)), i, stop=0;
    16451612  if (!num_args) return 0;
    16461613
     
    16641631  }
    16651632
    1666   cons_cell *na_list=NULL,*return_list=NULL,*last_return=NULL;
     1633  cons_cell *na_list=NULL, *return_list=NULL, *last_return=NULL;
    16671634
    16681635  do
     
    16921659    {
    16931660      cons_cell *c=new_cons_cell();
    1694       c->car=eval_function((lisp_symbol *)sym,first);
     1661      c->car=eval_function((lisp_symbol *)sym, first);
    16951662      if (return_list)
    16961663        last_return->cdr=c;
     
    17101677{
    17111678  void *el_list=CDR(prog_list);
    1712   p_ref ref1(prog_list),ref2(el_list);
     1679  p_ref ref1(prog_list), ref2(el_list);
    17131680  void *ret=NULL;
    17141681  void *rtype=eval(CAR(prog_list));
     
    17221689    {
    17231690      void **str_eval=(void **)malloc(elements*sizeof(void *));
    1724       int i,old_ptr_stack_start=l_ptr_stack.son;
     1691      int i, old_ptr_stack_start=l_ptr_stack.son;
    17251692
    17261693      // evalaute all the strings and count their lengths
    1727       for (i=0;i<elements;i++,el_list=CDR(el_list))
     1694      for (i=0;i<elements;i++, el_list=CDR(el_list))
    17281695      {
    17291696        str_eval[i]=eval(CAR(el_list));
     
    17771744      case L_STRING :
    17781745      {
    1779         memcpy(s,lstring_value(str_eval[i]),strlen(lstring_value(str_eval[i])));
     1746        memcpy(s, lstring_value(str_eval[i]), strlen(lstring_value(str_eval[i])));
    17801747        s+=strlen(lstring_value(str_eval[i]));
    17811748      } break;
     
    18091776  else
    18101777  {
    1811     void *first=NULL,*last=NULL,*cur=NULL,*tmp;
    1812     p_ref ref1(first),ref2(last),ref3(cur),ref4(args);
     1778    void *first=NULL, *last=NULL, *cur=NULL, *tmp;
     1779    p_ref ref1(first), ref2(last), ref3(cur), ref4(args);
    18131780    while (args)
    18141781    {
     
    18531820  switch (fun->fun_number)
    18541821  {
    1855     case 0 :                                                    // print
     1822    case SYS_FUNC_PRINT:
    18561823    {
    18571824      ret=NULL;
     
    18631830      return ret;
    18641831    } break;
    1865     case 1 :                                                    // car
     1832    case SYS_FUNC_CAR:
    18661833    { ret=lcar(eval(CAR(arg_list))); } break;
    1867     case 2 :                                                    // cdr
     1834    case SYS_FUNC_CDR:
    18681835    { ret=lcdr(eval(CAR(arg_list))); } break;
    1869     case 3 :                                                    // length
     1836    case SYS_FUNC_LENGTH:
    18701837    {
    18711838      void *v=eval(CAR(arg_list));
    18721839      switch (item_type(v))
    18731840      {
    1874     case L_STRING : ret=new_lisp_number(strlen(lstring_value(v))); break;
    1875     case L_CONS_CELL : ret=new_lisp_number(list_length(v)); break;
    1876     default :
    1877     { lprint(v);
    1878       lbreak("length : type not supported\n");
    1879     }
     1841        case L_STRING : ret=new_lisp_number(strlen(lstring_value(v))); break;
     1842        case L_CONS_CELL : ret=new_lisp_number(list_length(v)); break;
     1843        default :
     1844        { lprint(v);
     1845          lbreak("length : type not supported\n");
     1846        }
    18801847      }
    18811848    } break;                       
    1882     case 4 :                                                    // list
    1883     {
    1884       void *cur=NULL,*last=NULL,*first=NULL;
    1885       p_ref r1(cur),r2(first),r3(last);
     1849    case SYS_FUNC_LIST:
     1850    {
     1851      void *cur=NULL, *last=NULL, *first=NULL;
     1852      p_ref r1(cur), r2(first), r3(last);
    18861853      while (arg_list)
    18871854      {
     
    18971864      ret=first;
    18981865    } break;
    1899     case 5 :                                             // cons
     1866    case SYS_FUNC_CONS:
    19001867    { void *c=new_cons_cell();
    19011868      p_ref r1(c);
     
    19061873      ret=c;
    19071874    } break;
    1908     case 6 :                                             // quote
     1875    case SYS_FUNC_QUOTE:
    19091876    ret=CAR(arg_list);
    19101877    break;
    1911     case 7 :                                             // eq
     1878    case SYS_FUNC_EQ:
    19121879    {
    19131880      l_user_stack.push(eval(CAR(arg_list)));
    19141881      l_user_stack.push(eval(CAR(CDR(arg_list))));
    1915       ret=lisp_eq(l_user_stack.pop(1),l_user_stack.pop(1));
    1916     } break;
    1917     case 24 :                                             // equal
     1882      ret=lisp_eq(l_user_stack.pop(1), l_user_stack.pop(1));
     1883    } break;
     1884    case SYS_FUNC_EQUAL:
    19181885    {
    19191886      l_user_stack.push(eval(CAR(arg_list)));
    19201887      l_user_stack.push(eval(CAR(CDR(arg_list))));
    1921       ret=lisp_equal(l_user_stack.pop(1),l_user_stack.pop(1));
    1922     } break;
    1923     case 8 :                                           // +
     1888      ret=lisp_equal(l_user_stack.pop(1), l_user_stack.pop(1));
     1889    } break;
     1890    case SYS_FUNC_PLUS:
    19241891    {
    19251892      long sum=0;
     
    19321899    }
    19331900    break;
    1934     case 28 :                                          // *
     1901    case SYS_FUNC_TIMES:
    19351902    {
    19361903      long sum;
     
    19601927    }
    19611928    break;
    1962     case 29 :                                           // /
    1963     {
    1964       long sum=0,first=1;
     1929    case SYS_FUNC_SLASH:
     1930    {
     1931      long sum=0, first=1;
    19651932      while (arg_list)
    19661933      {
     
    19831950    }
    19841951    break;
    1985     case 9 :                                           // -
     1952    case SYS_FUNC_MINUS:
    19861953    {
    19871954      long x=lnumber_value(eval(CAR(arg_list)));         arg_list=CDR(arg_list);
     
    19941961    }
    19951962    break;
    1996     case 10 :                                         // if
     1963    case SYS_FUNC_IF:
    19971964    {
    19981965      if (eval(CAR(arg_list)))
     
    20051972      }
    20061973    } break;
    2007     case 63 :
    2008     case 11 :                                         // setf
    2009     {
    2010       void *set_to=eval(CAR(CDR(arg_list))),*i=NULL;
    2011       p_ref r1(set_to),r2(i);
     1974    case SYS_FUNC_SETQ:
     1975    case SYS_FUNC_SETF:
     1976    {
     1977      void *set_to=eval(CAR(CDR(arg_list))), *i=NULL;
     1978      p_ref r1(set_to), r2(i);
    20121979      i=CAR(arg_list);
    20131980
     
    20151982      switch (item_type(i))
    20161983      {
    2017     case L_SYMBOL :
    2018     {
    2019       switch (item_type (((lisp_symbol *)i)->value))
    2020       {
    2021         case L_NUMBER :
     1984        case L_SYMBOL :
    20221985        {
    2023           if (x==L_NUMBER && ((lisp_symbol *)i)->value!=l_undefined)
    2024           ((lisp_number *)(((lisp_symbol *)i)->value))->num=lnumber_value(set_to);
    2025           else
    2026           ((lisp_symbol *)i)->value=set_to;
     1986          switch (item_type (((lisp_symbol *)i)->value))
     1987          {
     1988            case L_NUMBER :
     1989            {
     1990              if (x==L_NUMBER && ((lisp_symbol *)i)->value!=l_undefined)
     1991              ((lisp_number *)(((lisp_symbol *)i)->value))->num=lnumber_value(set_to);
     1992              else
     1993              ((lisp_symbol *)i)->value=set_to;
     1994            } break;
     1995            case L_OBJECT_VAR :
     1996            {
     1997              l_obj_set(((lisp_object_var *)(((lisp_symbol *)i)->value))->number, set_to);
     1998            } break;
     1999            default :
     2000            ((lisp_symbol *)i)->value=set_to;
     2001          }
     2002          ret=((lisp_symbol *)i)->value;
    20272003        } break;
    2028         case L_OBJECT_VAR :
     2004        case L_CONS_CELL :   // this better be an 'aref'
    20292005        {
    2030           l_obj_set(((lisp_object_var *)(((lisp_symbol *)i)->value))->number,set_to);
     2006#ifdef TYPE_CHECKING
     2007          void *car=((cons_cell *)i)->car;
     2008          if (car==car_symbol)
     2009          {
     2010            car=eval(CAR(CDR(i)));
     2011            if (!car || item_type(car)!=L_CONS_CELL)
     2012            { lprint(car); lbreak("setq car : evaled object is not a cons cell\n"); exit(0); }
     2013            ((cons_cell *)car)->car=set_to;
     2014          } else if (car==cdr_symbol)
     2015          {
     2016            car=eval(CAR(CDR(i)));
     2017            if (!car || item_type(car)!=L_CONS_CELL)
     2018            { lprint(car); lbreak("setq cdr : evaled object is not a cons cell\n"); exit(0); }
     2019            ((cons_cell *)car)->cdr=set_to;
     2020          } else if (car==aref_symbol)
     2021          {
     2022#endif
     2023            void *a=(lisp_1d_array *)eval(CAR(CDR(i)));
     2024            p_ref r1(a);
     2025#ifdef TYPE_CHECKING
     2026            if (item_type(a)!=L_1D_ARRAY)
     2027            {
     2028              lprint(a);
     2029              lbreak("is not an array (aref)\n");
     2030              exit(0);
     2031            }
     2032#endif
     2033            long num=lnumber_value(eval(CAR(CDR(CDR(i)))));
     2034#ifdef TYPE_CHECKING
     2035            if (num>=((lisp_1d_array *)a)->size || num<0)
     2036            {
     2037              lbreak("aref : value of bounds (%d)\n", num);
     2038              exit(0);
     2039            }
     2040#endif
     2041            void **data=(void **)(((lisp_1d_array *)a)+1);
     2042            data[num]=set_to;
     2043#ifdef TYPE_CHECKING
     2044          } else
     2045          {
     2046            lbreak("expected (aref, car, cdr, or symbol) in setq\n");
     2047            exit(0);
     2048          }
     2049#endif
     2050          ret=set_to;
    20312051        } break;
     2052
    20322053        default :
    2033         ((lisp_symbol *)i)->value=set_to;
    2034       }
    2035       ret=((lisp_symbol *)i)->value;
    2036     } break;
    2037     case L_CONS_CELL :   // this better be an 'aref'
    2038     {
    2039 #ifdef TYPE_CHECKING
    2040       void *car=((cons_cell *)i)->car;
    2041       if (car==car_symbol)
    2042       {
    2043         car=eval(CAR(CDR(i)));
    2044         if (!car || item_type(car)!=L_CONS_CELL)
    2045         { lprint(car); lbreak("setq car : evaled object is not a cons cell\n"); exit(0); }
    2046         ((cons_cell *)car)->car=set_to;
    2047       } else if (car==cdr_symbol)
    2048       {
    2049         car=eval(CAR(CDR(i)));
    2050         if (!car || item_type(car)!=L_CONS_CELL)
    2051         { lprint(car); lbreak("setq cdr : evaled object is not a cons cell\n"); exit(0); }
    2052         ((cons_cell *)car)->cdr=set_to;
    2053       } else if (car==aref_symbol)
    2054       {
    2055 #endif
    2056         void *a=(lisp_1d_array *)eval(CAR(CDR(i)));
    2057         p_ref r1(a);
    2058 #ifdef TYPE_CHECKING
    2059         if (item_type(a)!=L_1D_ARRAY)
    20602054        {
    2061           lprint(a);
    2062           lbreak("is not an array (aref)\n");
     2055          lprint(i);
     2056          lbreak("setq/setf only defined for symbols and arrays now..\n");
    20632057          exit(0);
    20642058        }
    2065 #endif
    2066         long num=lnumber_value(eval(CAR(CDR(CDR(i)))));
    2067 #ifdef TYPE_CHECKING
    2068         if (num>=((lisp_1d_array *)a)->size || num<0)
    2069         {
    2070           lbreak("aref : value of bounds (%d)\n",num);
    2071           exit(0);
    2072         }
    2073 #endif
    2074         void **data=(void **)(((lisp_1d_array *)a)+1);
    2075         data[num]=set_to;
    2076 #ifdef TYPE_CHECKING
    2077       } else
    2078       {
    2079         lbreak("expected (aref, car, cdr, or symbol) in setq\n");
    2080         exit(0);
    2081       }
    2082 #endif
    2083       ret=set_to;
    2084     } break;
    2085 
    2086     default :
    2087     {
    2088       lprint(i);
    2089       lbreak("setq/setf only defined for symbols and arrays now..\n");
    2090       exit(0);
    2091     }
    2092       }
    2093     } break;
    2094     case 12 :                                      // symbol-list
     2059      }
     2060    } break;
     2061    case SYS_FUNC_SYMBOL_LIST:
    20952062      ret=NULL;
    20962063    break;
    2097     case 13 :                                      // assoc
     2064    case SYS_FUNC_ASSOC:
    20982065    {
    20992066      void *item=eval(CAR(arg_list));
     
    21012068      void *list=(cons_cell *)eval(CAR(CDR(arg_list)));
    21022069      p_ref r2(list);
    2103       ret=assoc(item,(cons_cell *)list);
    2104     } break;
    2105     case 20 :                                       // not is the same as null
    2106     case 14 :                                       // null
     2070      ret=assoc(item, (cons_cell *)list);
     2071    } break;
     2072    case SYS_FUNC_NOT:
     2073    case SYS_FUNC_NULL:
    21072074    if (eval(CAR(arg_list))==NULL) ret=true_symbol; else ret=NULL;
    21082075    break;
    2109     case 15 :                                       // acons
    2110     {
    2111       void *i1=eval(CAR(arg_list)),*i2=eval(CAR(CDR(arg_list)));
     2076    case SYS_FUNC_ACONS:
     2077    {
     2078      void *i1=eval(CAR(arg_list)), *i2=eval(CAR(CDR(arg_list)));
    21122079      p_ref r1(i1);
    21132080      cons_cell *cs=new_cons_cell();
     
    21172084    } break;
    21182085
    2119     case 16 :                                       // pairlis
     2086    case SYS_FUNC_PAIRLIS:
    21202087    {   
    21212088      l_user_stack.push(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    21242091      void *n2=l_user_stack.pop(1);
    21252092      void *n1=l_user_stack.pop(1);
    2126       ret=pairlis(n1,n2,n3);
    2127     } break;
    2128     case 17 :                                      // let
     2093      ret=pairlis(n1, n2, n3);
     2094    } break;
     2095    case SYS_FUNC_LET:
    21292096    {
    21302097      // make an a-list of new variable names and new values
    21312098      void *var_list=CAR(arg_list),
    21322099           *block_list=CDR(arg_list);
    2133       p_ref r1(block_list),r2(var_list);
     2100      p_ref r1(block_list), r2(var_list);
    21342101      long stack_start=l_user_stack.son;
    21352102
    21362103      while (var_list)
    21372104      {
    2138     void *var_name=CAR(CAR(var_list)),*tmp;
     2105    void *var_name=CAR(CAR(var_list)), *tmp;
    21392106#ifdef TYPE_CHECKING
    21402107    if (item_type(var_name)!=L_SYMBOL)
     
    21712138    }
    21722139    break;
    2173     case 18 :                                   // defun
     2140    case SYS_FUNC_DEFUN:
    21742141    {
    21752142      void *symbol=CAR(arg_list);
     
    21942161      intptr_t a=cache.reg_lisp_block(lcar(lcdr(arg_list)));
    21952162      intptr_t b=cache.reg_lisp_block(block_list);
    2196       lisp_user_function *ufun=new_lisp_user_function(a,b);
     2163      lisp_user_function *ufun=new_lisp_user_function(a, b);
    21972164#else
    2198       lisp_user_function *ufun=new_lisp_user_function(lcar(lcdr(arg_list)),block_list);
    2199 #endif
    2200       set_symbol_function(symbol,ufun);
     2165      lisp_user_function *ufun=new_lisp_user_function(lcar(lcdr(arg_list)), block_list);
     2166#endif
     2167      set_symbol_function(symbol, ufun);
    22012168      ret=symbol;
    22022169    } break;
    2203     case 19 :                                       // atom
     2170    case SYS_FUNC_ATOM:
    22042171    { ret=lisp_atom(eval(CAR(arg_list))); }
    2205     case 21 :                                           // and
     2172    case SYS_FUNC_AND:
    22062173    {
    22072174      void *l=arg_list;
     
    22172184      }
    22182185    } break;
    2219     case 22 :                                           // or
     2186    case SYS_FUNC_OR:
    22202187    {
    22212188      void *l=arg_list;
     
    22312198      }
    22322199    } break;
    2233     case 23 :                                          // progn
     2200    case SYS_FUNC_PROGN:
    22342201    { ret=eval_block(arg_list); } break;
    2235     case 25 :                                        // concatenate
     2202    case SYS_FUNC_CONCATENATE:
    22362203      ret=concatenate(arg_list);
    22372204    break;
    2238     case 26 :                                        // char-code
     2205    case SYS_FUNC_CHAR_CODE:
    22392206    {
    22402207      void *i=eval(CAR(arg_list));
     
    22432210      switch (item_type(i))
    22442211      {
    2245     case L_CHARACTER :
    2246     { ret=new_lisp_number(((lisp_character *)i)->ch); } break;
    2247     case L_STRING :
    2248     {  ret=new_lisp_number(*lstring_value(i)); } break;
    2249     default :
    2250     {
    2251       lprint(i);
    2252       lbreak(" is not character type\n");
    2253       exit(0);
    2254     }
     2212        case L_CHARACTER :
     2213        { ret=new_lisp_number(((lisp_character *)i)->ch); } break;
     2214        case L_STRING :
     2215        {  ret=new_lisp_number(*lstring_value(i)); } break;
     2216        default :
     2217        {
     2218          lprint(i);
     2219          lbreak(" is not character type\n");
     2220          exit(0);
     2221        }
    22552222      }       
    22562223    } break;
    2257     case 27 :                                        // code-char
     2224    case SYS_FUNC_CODE_CHAR:
    22582225    {
    22592226      void *i=eval(CAR(arg_list));
     
    22672234      ret=new_lisp_character(((lisp_number *)i)->num);
    22682235    } break;
    2269     case 30 :                                       // cond
     2236    case SYS_FUNC_COND:
    22702237    {
    22712238      void *block_list=CAR(arg_list);
     
    22832250      }
    22842251    } break;
    2285     case 31 :                                       // select
     2252    case SYS_FUNC_SELECT:
    22862253    {
    22872254      void *selector=eval(CAR(arg_list));
    22882255      void *sel=CDR(arg_list);
    2289       p_ref r1(selector),r2(sel);
     2256      p_ref r1(selector), r2(sel);
    22902257      while (sel)
    22912258      {
    2292     if (lisp_equal(selector,eval(CAR(CAR(sel)))))
     2259    if (lisp_equal(selector, eval(CAR(CAR(sel)))))
    22932260    {
    22942261      sel=CDR(CAR(sel));
     
    23022269      }
    23032270    } break;
    2304     case 32 :                                      // function
     2271    case SYS_FUNC_FUNCTION:
    23052272      ret=lookup_symbol_function(eval(CAR(arg_list)));
    23062273    break;
    2307     case 33 :                                      // mapcar
     2274    case SYS_FUNC_MAPCAR:
    23082275      ret=mapcar(arg_list);
    2309     case 34 :                                      // funcall
     2276    case SYS_FUNC_FUNCALL:
    23102277    {
    23112278      void *n1=eval(CAR(arg_list));
    2312       ret=eval_function((lisp_symbol *)n1,CDR(arg_list));
    2313     } break;
    2314     case 35 :                                                   // >
     2279      ret=eval_function((lisp_symbol *)n1, CDR(arg_list));
     2280    } break;
     2281    case SYS_FUNC_GT:
    23152282    {
    23162283      long n1=lnumber_value(eval(CAR(arg_list)));
     
    23192286    }
    23202287    break;
    2321     case 36 :                                                   // <
     2288    case SYS_FUNC_LT:
    23222289    {
    23232290      long n1=lnumber_value(eval(CAR(arg_list)));
     
    23262293    }
    23272294    break;
    2328     case 47 :                                                   // >=
     2295    case SYS_FUNC_GE:
    23292296    {
    23302297      long n1=lnumber_value(eval(CAR(arg_list)));
     
    23332300    }
    23342301    break;
    2335     case 48 :                                                   // <=
     2302    case SYS_FUNC_LE:
    23362303    {
    23372304      long n1=lnumber_value(eval(CAR(arg_list)));
     
    23412308    break;
    23422309
    2343     case 37 :                                                  // tmp-space
     2310    case SYS_FUNC_TMP_SPACE:
    23442311      tmp_space();
    23452312      ret=true_symbol;
    23462313    break;
    2347     case 38 :                                                  // perm-space
     2314    case SYS_FUNC_PERM_SPACE:
    23482315      perm_space();
    23492316      ret=true_symbol;
    23502317    break;
    2351     case 39 :
     2318    case SYS_FUNC_SYMBOL_NAME:
    23522319      void *symb;
    23532320      symb=eval(CAR(arg_list));
     
    23622329      ret=((lisp_symbol *)symb)->name;
    23632330    break;
    2364     case 40 :                                                  // trace
     2331    case SYS_FUNC_TRACE:
    23652332      trace_level++;
    23662333      if (arg_list)
     
    23682335      ret=true_symbol;
    23692336    break;
    2370     case 41 :                                                  // untrace
     2337    case SYS_FUNC_UNTRACE:
    23712338      if (trace_level>0)
    23722339      {
     
    23752342      } else ret=NULL;
    23762343    break;
    2377     case 42 :                                                 // digitstr
    2378     {
    2379       char tmp[50],*tp;
     2344    case SYS_FUNC_DIGSTR:
     2345    {
     2346      char tmp[50], *tp;
    23802347      long num=lnumber_value(eval(CAR(arg_list)));
    23812348      long dig=lnumber_value(eval(CAR(CDR(arg_list))));
     
    23942361      ret=new_lisp_string(tp+1);
    23952362    } break;
    2396     case 98:
    2397     case 66:
    2398     case 43:                                     // compile-file
     2363    case SYS_FUNC_LOCAL_LOAD:
     2364    case SYS_FUNC_LOAD:
     2365    case SYS_FUNC_COMPILE_FILE:
    23992366    {
    24002367            void *fn = eval( CAR( arg_list ) );
     
    24022369            p_ref r1( fn );
    24032370            bFILE *fp;
    2404             if( fun->fun_number == 98 )          // local_load
     2371            if( fun->fun_number == SYS_FUNC_LOCAL_LOAD )
    24052372            {
    24062373                // A special test for gamma.lsp
     
    24202387            else
    24212388            {
    2422                 fp = open_file(st,"rb");
     2389                fp = open_file(st, "rb");
    24232390            }
    24242391
     
    24272394                delete fp;
    24282395                if( DEFINEDP(symbol_value(load_warning)) && symbol_value(load_warning) )
    2429                     dprintf("Warning : file %s does not exists\n",st);
     2396                    dprintf("Warning : file %s does not exist\n", st);
    24302397                ret = NULL;
    24312398            }
     
    24402407                }
    24412408           
    2442                 fp->read(s,l);
     2409                fp->read(s, l);
    24432410                s[l]=0;
    24442411                delete fp;
     
    24462413            #ifndef NO_LIBS
    24472414                char msg[100];
    2448                 sprintf(msg,"(load \"%s\")",st);
    2449                 if (stat_man) stat_man->push(msg,NULL);
     2415                sprintf(msg, "(load \"%s\")", st);
     2416                if (stat_man) stat_man->push(msg, NULL);
    24502417                crc_manager.get_filenumber(st);               // make sure this file gets crc'ed
    24512418            #endif
     
    24612428                  eval(compiled_form);
    24622429                  compiled_form=NULL;
    2463                   restore_heap(m,TMP_SPACE);
     2430                  restore_heap(m, TMP_SPACE);
    24642431                }   
    24652432            #ifndef NO_LIBS
     
    24712438      }
    24722439    } break;
    2473     case 44 :                                                 // abs
     2440    case SYS_FUNC_ABS:
    24742441      ret=new_lisp_number(abs(lnumber_value(eval(CAR(arg_list))))); break;
    2475     case 45 :                                                 // min
    2476     {
    2477       int x=lnumber_value(eval(CAR(arg_list))),y=lnumber_value(eval(CAR(CDR(arg_list))));
     2442    case SYS_FUNC_MIN:
     2443    {
     2444      int x=lnumber_value(eval(CAR(arg_list))), y=lnumber_value(eval(CAR(CDR(arg_list))));
    24782445      if (x<y) ret=new_lisp_number(x); else ret=new_lisp_number(y);
    24792446    } break;
    2480     case 46 :                                                 // max
    2481     {
    2482       int x=lnumber_value(eval(CAR(arg_list))),y=lnumber_value(eval(CAR(CDR(arg_list))));
     2447    case SYS_FUNC_MAX:
     2448    {
     2449      int x=lnumber_value(eval(CAR(arg_list))), y=lnumber_value(eval(CAR(CDR(arg_list))));
    24832450      if (x>y) ret=new_lisp_number(x); else ret=new_lisp_number(y);
    24842451    } break;
    2485     case 49 :                        // backquote
     2452    case SYS_FUNC_BACKQUOTE:
    24862453    {
    24872454      ret=backquote_eval(CAR(arg_list));
    24882455    } break;
    2489     case 50 :
     2456    case SYS_FUNC_COMMA:
    24902457    {
    24912458      lprint(arg_list);
     
    24942461      ret=NULL;
    24952462    } break;
    2496     case 51 :
     2463    case SYS_FUNC_NTH:
    24972464    {
    24982465      long x=lnumber_value(eval(CAR(arg_list)));
    2499       ret=nth(x,eval(CAR(CDR(arg_list))));
    2500     } break;
    2501     case 52 : resize_tmp(lnumber_value(eval(CAR(arg_list)))); break;
    2502     case 53 : resize_perm(lnumber_value(eval(CAR(arg_list)))); break;
    2503     case 54 : ret=new_lisp_fixed_point(lisp_cos(lnumber_value(eval(CAR(arg_list))))); break;
    2504     case 55 : ret=new_lisp_fixed_point(lisp_sin(lnumber_value(eval(CAR(arg_list))))); break;
    2505     case 56 :
     2466      ret=nth(x, eval(CAR(CDR(arg_list))));
     2467    } break;
     2468    case SYS_FUNC_RESIZE_TMP:
     2469        resize_tmp(lnumber_value(eval(CAR(arg_list)))); break;
     2470    case SYS_FUNC_RESIZE_PERM:
     2471        resize_perm(lnumber_value(eval(CAR(arg_list)))); break;
     2472    case SYS_FUNC_COS:
     2473        ret=new_lisp_fixed_point(lisp_cos(lnumber_value(eval(CAR(arg_list))))); break;
     2474    case SYS_FUNC_SIN:
     2475        ret=new_lisp_fixed_point(lisp_sin(lnumber_value(eval(CAR(arg_list))))); break;
     2476    case SYS_FUNC_ATAN2:
    25062477    {
    25072478      long y=(lnumber_value(eval(CAR(arg_list))));   arg_list=CDR(arg_list);
    25082479      long x=(lnumber_value(eval(CAR(arg_list))));
    2509       ret=new_lisp_number(lisp_atan2(y,x));
    2510     } break;
    2511     case 57 :
     2480      ret=new_lisp_number(lisp_atan2(y, x));
     2481    } break;
     2482    case SYS_FUNC_ENUM:
    25122483    {
    25132484      int sp=current_space;
     
    25482519      current_space=sp;
    25492520    } break;
    2550     case 58 :
     2521    case SYS_FUNC_QUIT:
    25512522    {
    25522523      exit(0);
    25532524    } break;
    2554     case 59 :
     2525    case SYS_FUNC_EVAL:
    25552526    {
    25562527      ret=eval(eval(CAR(arg_list)));
    25572528    } break;
    2558     case 60 : lbreak("User break"); break;
    2559     case 61 :
     2529    case SYS_FUNC_BREAK: lbreak("User break"); break;
     2530    case SYS_FUNC_MOD:
    25602531    {
    25612532      long x=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    25642535      ret=new_lisp_number(x%y);
    25652536    } break;
    2566 /*    case 62 :
     2537/*    case SYS_FUNC_WRITE_PROFILE:
    25672538    {
    25682539      char *fn=lstring_value(eval(CAR(arg_list)));
    2569       FILE *fp=fopen(fn,"wb");
     2540      FILE *fp=fopen(fn, "wb");
    25702541      if (!fp)
    2571         lbreak("could not open %s for writing",fn);
     2542        lbreak("could not open %s for writing", fn);
    25722543      else
    25732544      {   
    25742545    for (void *s=symbol_list;s;s=CDR(s))       
    2575       fprintf(fp,"%8d  %s\n",((lisp_symbol *)(CAR(s)))->call_counter,
     2546      fprintf(fp, "%8d  %s\n", ((lisp_symbol *)(CAR(s)))->call_counter,
    25762547          lstring_value(((lisp_symbol *)(CAR(s)))->name));
    25772548    fclose(fp);
    25782549      }
    25792550    } break;*/
    2580     case 64 :
     2551    case SYS_FUNC_FOR:
    25812552    {
    25822553      void *bind_var=CAR(arg_list); arg_list=CDR(arg_list);
     
    25962567      arg_list=CDR(arg_list);
    25972568
    2598       void *block=NULL,*ret=NULL;
     2569      void *block=NULL, *ret=NULL;
    25992570      p_ref r3(block);
    26002571      l_user_stack.push(symbol_value(bind_var));  // save old symbol value
    26012572      while (ilist)
    26022573      {
    2603                 set_symbol_value(bind_var,CAR(ilist));
     2574                set_symbol_value(bind_var, CAR(ilist));
    26042575                for (block=arg_list;block;block=CDR(block))
    26052576                  ret=eval(CAR(block));
    26062577                ilist=CDR(ilist);
    26072578      }
    2608       set_symbol_value(bind_var,l_user_stack.pop(1));
     2579      set_symbol_value(bind_var, l_user_stack.pop(1));
    26092580      ret=ret;
    26102581    } break;
    2611     case 65 :
     2582    case SYS_FUNC_OPEN_FILE:
    26122583    {
    26132584      bFILE *old_file=current_print_file;
     
    26322603
    26332604    } break;
    2634     case 67 :
     2605    case SYS_FUNC_BIT_AND:
    26352606    {
    26362607      long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    26422613      ret=new_lisp_number(first);
    26432614    } break;
    2644     case 68 :
     2615    case SYS_FUNC_BIT_OR:
    26452616    {
    26462617      long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    26522623      ret=new_lisp_number(first);
    26532624    } break;
    2654     case 69 :
     2625    case SYS_FUNC_BIT_XOR:
    26552626    {
    26562627      long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    26622633      ret=new_lisp_number(first);
    26632634    } break;
    2664     case 70 :  // make-array
     2635    case SYS_FUNC_MAKE_ARRAY:
    26652636    {
    26662637      long l=lnumber_value(eval(CAR(arg_list)));
    26672638      if (l>=2<<16 || l<=0)
    26682639      {
    2669                 lbreak("bad array size %d\n",l);
     2640                lbreak("bad array size %d\n", l);
    26702641                exit(0);
    26712642      }
    2672       ret=new_lisp_1d_array(l,CDR(arg_list));
    2673     } break;
    2674     case 71 : // aref
     2643      ret=new_lisp_1d_array(l, CDR(arg_list));
     2644    } break;
     2645    case SYS_FUNC_AREF:
    26752646    {
    26762647      long x=lnumber_value(eval(CAR(CDR(arg_list))));
    2677       ret=lget_array_element(eval(CAR(arg_list)),x);
    2678     } break;
    2679     case 72 : // if-1progn
     2648      ret=lget_array_element(eval(CAR(arg_list)), x);
     2649    } break;
     2650    case SYS_FUNC_IF_1PROGN:
    26802651    {
    26812652      if (eval(CAR(arg_list)))
     
    26842655
    26852656    } break;
    2686     case 73 : // if-2progn
     2657    case SYS_FUNC_IF_2PROGN:
    26872658    {
    26882659      if (eval(CAR(arg_list)))
     
    26912662
    26922663    } break;
    2693     case 74 : // if-12progn
     2664    case SYS_FUNC_IF_12PROGN:
    26942665    {
    26952666      if (eval(CAR(arg_list)))
     
    26982669
    26992670    } break;
    2700     case 75 : // eq0
     2671    case SYS_FUNC_EQ0:
    27012672    {
    27022673      void *v=eval(CAR(arg_list));
     
    27052676      else ret=true_symbol;
    27062677    } break;
    2707     case 76 : // preport
     2678    case SYS_FUNC_PREPORT:
    27082679    {
    27092680#ifdef L_PROFILE
     
    27122683#endif
    27132684    } break;
    2714     case 77 : // search
     2685    case SYS_FUNC_SEARCH:
    27152686    {
    27162687      void *arg1=eval(CAR(arg_list)); arg_list=CDR(arg_list);
     
    27192690      char *needle=lstring_value(arg1);
    27202691
    2721       char *find=strstr(haystack,needle);
     2692      char *find=strstr(haystack, needle);
    27222693      if (find)
    27232694        ret=new_lisp_number(find-haystack);
    27242695      else ret=NULL;
    27252696    } break;
    2726     case 78 : // elt
     2697    case SYS_FUNC_ELT:
    27272698    {
    27282699      void *arg1=eval(CAR(arg_list)); arg_list=CDR(arg_list);
     
    27352706        ret=new_lisp_character(st[x]);
    27362707    } break;
    2737     case 79 : // listp
     2708    case SYS_FUNC_LISTP:
    27382709    {
    27392710      return item_type(eval(CAR(arg_list)))==L_CONS_CELL ? true_symbol : NULL;
    27402711    } break;
    2741     case 80 : // numberp
     2712    case SYS_FUNC_NUMBERP:
    27422713    {
    27432714      int t=item_type(eval(CAR(arg_list)));
    27442715      if (t==L_NUMBER || t==L_FIXED_POINT) return true_symbol; else return NULL;
    27452716    } break;
    2746     case 81 : // do
     2717    case SYS_FUNC_DO:
    27472718    {
    27482719      void *init_var=CAR(arg_list);
    27492720      p_ref r1(init_var);
    2750       int i,ustack_start=l_user_stack.son;      // restore stack at end
     2721      int i, ustack_start=l_user_stack.son;      // restore stack at end
    27512722      void *sym=NULL;
    27522723      p_ref r2(sym);
     
    27672738
    27682739      // now set all the symbols
    2769       for (init_var=CAR(arg_list);init_var;init_var=CDR(init_var),do_evaled++)
     2740      for (init_var=CAR(arg_list);init_var;init_var=CDR(init_var), do_evaled++)
    27702741      {
    27712742                sym=CAR(CAR(init_var));
    2772                 set_symbol_value(sym,*do_evaled);
     2743                set_symbol_value(sym, *do_evaled);
    27732744      }
    27742745
     
    27892760      // restore old values for symbols
    27902761      do_evaled=l_user_stack.sdata+ustack_start;
    2791       for (init_var=CAR(arg_list);init_var;init_var=CDR(init_var),do_evaled++)
     2762      for (init_var=CAR(arg_list);init_var;init_var=CDR(init_var), do_evaled++)
    27922763      {
    27932764                sym=CAR(CAR(init_var));
    2794                 set_symbol_value(sym,*do_evaled);
     2765                set_symbol_value(sym, *do_evaled);
    27952766      }
    27962767
     
    27982769
    27992770    } break;
    2800     case 82 : // gc
     2771    case SYS_FUNC_GC:
    28012772    {
    28022773      collect_space(current_space);
    28032774    } break;
    2804     case 83 : // schar
     2775    case SYS_FUNC_SCHAR:
    28052776    {
    28062777      char *s=lstring_value(eval(CAR(arg_list)));      arg_list=CDR(arg_list);
     
    28082779
    28092780      if ((unsigned)x >= strlen(s))
    2810       { lbreak("SCHAR: index %d should be less than the length of the string\n",x); exit(0); }
     2781      { lbreak("SCHAR: index %d should be less than the length of the string\n", x); exit(0); }
    28112782      else if (x<0)
    28122783      { lbreak("SCHAR: index should not be negative\n"); exit(0); }
    28132784      return new_lisp_character(s[x]);
    28142785    } break;
    2815     case 84 :// symbolp
     2786    case SYS_FUNC_SYMBOLP:
    28162787    { if (item_type(eval(CAR(arg_list)))==L_SYMBOL) return true_symbol;
    28172788      else return NULL; } break;
    2818     case 85 :  // num2str
     2789    case SYS_FUNC_NUM2STR:
    28192790    {
    28202791      char str[20];
    2821       sprintf(str,"%ld",(long int)lnumber_value(eval(CAR(arg_list))));
     2792      sprintf(str, "%ld", (long int)lnumber_value(eval(CAR(arg_list))));
    28222793      ret=new_lisp_string(str);
    28232794    } break;
    2824     case 86 : // nconc
     2795    case SYS_FUNC_NCONC:
    28252796    {
    28262797      void *l1=eval(CAR(arg_list)); arg_list=CDR(arg_list);
    28272798      p_ref r1(l1);
    2828       void *first=l1,*next;
     2799      void *first=l1, *next;
    28292800      p_ref r2(first);
    28302801
     
    28462817      ret=first;
    28472818    } break;
    2848     case 87 : // first
     2819    case SYS_FUNC_FIRST:
    28492820    { ret=CAR(eval(CAR(arg_list))); } break;
    2850     case 88 : // second
     2821    case SYS_FUNC_SECOND:
    28512822    { ret=CAR(CDR(eval(CAR(arg_list)))); } break;
    2852     case 89 : // third
     2823    case SYS_FUNC_THIRD:
    28532824    { ret=CAR(CDR(CDR(eval(CAR(arg_list))))); } break;
    2854     case 90 : // fourth
     2825    case SYS_FUNC_FOURTH:
    28552826    { ret=CAR(CDR(CDR(CDR(eval(CAR(arg_list)))))); } break;
    2856     case 91 : // fifth
     2827    case SYS_FUNC_FIFTH:
    28572828    { ret=CAR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))); } break;
    2858     case 92 : // sixth
     2829    case SYS_FUNC_SIXTH:
    28592830    { ret=CAR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))); } break;
    2860     case 93 : // seventh
     2831    case SYS_FUNC_SEVENTH:
    28612832    { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))))); } break;
    2862     case 94 : // eight
     2833    case SYS_FUNC_EIGHTH:
    28632834    { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))))); } break;
    2864     case 95 : // ninth
     2835    case SYS_FUNC_NINTH:
    28652836    { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))))))); } break;
    2866     case 96 : // tenth
     2837    case SYS_FUNC_TENTH:
    28672838    { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))))))); } break;
    2868     case 97 :
     2839    case SYS_FUNC_SUBSTR:
    28692840    {
    28702841      long x1=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list);
     
    28782849      lisp_string *s=new_lisp_string(x2-x1+2);
    28792850      if (x2-x1)
    2880         memcpy(lstring_value(s),lstring_value(st)+x1,x2-x1+1);
     2851        memcpy(lstring_value(s), lstring_value(st)+x1, x2-x1+1);
    28812852
    28822853      *(lstring_value(s)+(x2-x1+1))=0;
     
    28852856    case 99 :
    28862857    {
    2887       void *r=NULL,*rstart=NULL;
    2888       p_ref r1(r),r2(rstart);
     2858      void *r=NULL, *rstart=NULL;
     2859      p_ref r1(r), r2(rstart);
    28892860      while (arg_list)
    28902861      {
    2891                 void *q=eval(CAR(arg_list));
    2892                 if (!rstart) rstart=q;
    2893                 while (r && CDR(r)) r=CDR(r);
    2894                 CDR(r)=q;   
    2895                 arg_list=CDR(arg_list);
     2862        void *q=eval(CAR(arg_list));
     2863        if (!rstart) rstart=q;
     2864        while (r && CDR(r)) r=CDR(r);
     2865        CDR(r)=q;   
     2866        arg_list=CDR(arg_list);
    28962867      }
    28972868      return rstart;
     
    28992870
    29002871    default :
    2901     { dprintf("Undefined system function number %d\n",((lisp_sys_function *)fun)->fun_number); }
     2872    { dprintf("Undefined system function number %d\n", ((lisp_sys_function *)fun)->fun_number); }
    29022873  }
    29032874  return ret;
     
    29532924  void *fun_arg_list=cache.lblock(fun->alist);
    29542925  void *block_list=cache.lblock(fun->blist);
    2955   p_ref r9(block_list),r10(fun_arg_list);
     2926  p_ref r9(block_list), r10(fun_arg_list);
    29562927#else
    29572928  void *fun_arg_list=fun->arg_list;
    29582929  void *block_list=fun->block_list;
    2959   p_ref r9(block_list),r10(fun_arg_list);
     2930  p_ref r9(block_list), r10(fun_arg_list);
    29602931#endif
    29612932
     
    30433014    if (trace_level<=trace_print_level)
    30443015    {
    3045       dprintf("%d (%d,%d,%d) TRACE : ",trace_level,
     3016      dprintf("%d (%d, %d, %d) TRACE : ", trace_level,
    30463017          space_size[PERM_SPACE]-((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]),
    30473018          space_size[TMP_SPACE]-((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]),
     
    30773048      case L_CONS_CELL :
    30783049      {
    3079         ret=eval_function((lisp_symbol *)CAR(prog),CDR(prog));
     3050        ret=eval_function((lisp_symbol *)CAR(prog), CDR(prog));
    30803051      }
    30813052      break;
    30823053      default :
    3083         fprintf(stderr,"shouldn't happen\n");
     3054        fprintf(stderr, "shouldn't happen\n");
    30843055    }
    30853056  }
     
    30883059    trace_level--;
    30893060    if (trace_level<=trace_print_level)
    3090       dprintf("%d (%d,%d,%d) TRACE ==> ",trace_level,
     3061      dprintf("%d (%d, %d, %d) TRACE ==> ", trace_level,
    30913062          space_size[PERM_SPACE]-((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]),
    30923063          space_size[TMP_SPACE]-((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]),
     
    31043075}
    31053076
    3106 #define TOTAL_SYS_FUNCS 99
    3107 char const *sys_funcs[TOTAL_SYS_FUNCS] =
    3108 {
    3109     //  0      1    2       3       4      5      6      7
    3110     "print","car","cdr","length","list","cons","quote","eq",
    3111     // 8   9   10    11       12          13     14      15      16
    3112     "+","-","if","setf","symbol-list","assoc","null","acons","pairlis",
    3113     // 17     18     19     20     21     22    23      24
    3114     "let","defun","atom","not", "and", "or","progn","equal",
    3115     // 25               26          27       28  29   30     31
    3116     "concatenate","char-code","code-char","*","/","cond","select",
    3117     // 32            33         34     35    36    37
    3118     "function", "mapcar", "funcall", ">", "<", "tmp-space",
    3119     //   38              39        40       41         42
    3120     "perm-space","symbol-name","trace","untrace","digstr",
    3121     //   43            44   45    46    47  48       49
    3122     "compile-file","abs","min","max",">=","<=","backquote",
    3123     //  50      51      52         53           54    55     56
    3124     "comma","nth","resize-tmp","resize-perm","cos","sin","atan2",
    3125     // 57       58     59     60     61   62              63
    3126     "enum", "quit","eval","break","mod","write_profile","setq",
    3127     // 64    65          66      67       68        69        70
    3128     "for", "open_file","load","bit-and","bit-or","bit-xor","make-array",
    3129     // 71      72          73          74        75      76
    3130     "aref","if-1progn","if-2progn","if-12progn","eq0","preport",
    3131     // 77     78         79        80       81     82     83
    3132     "search","elt",    "listp", "numberp", "do",  "gc", "schar",
    3133     // 84       85        86      87      88        89    90
    3134     "symbolp","num2str","nconc","first","second","third","fourth",
    3135     // 91       92       93       94       95      96
    3136     "fifth", "sixth", "seventh","eighth","ninth","tenth",
    3137     "substr",       // 97
    3138     "local_load"    // 98, filename
    3139 };
    3140 
    3141 /* select, digistr, load-file are not a common lisp functions! */
    3142 
    3143 short sys_args[TOTAL_SYS_FUNCS*2]={
    3144 
    3145 // 0      1       2        3       4         5       6      7        8
    3146  1, -1,   1, 1,   1, 1,   0, -1,   0, -1,   2, 2,   1, 1,   2, 2,  0, -1,
    3147 // 9      10      11      12       13       14      15      16      17
    3148  1, -1,   2, 3,   2, 2,   0, 0,    2, 2,    1, 1,   2, 2,   2, 2,   1, -1,
    3149 // 18     19      20      21       22       23      24      25      26
    3150  2, -1,  1, 1,   1, 1,  -1, -1,  -1, -1,  -1, -1,  2, 2,   1,-1,   1, 1,
    3151 // 27      28      29     30       31      32        33,     34      35
    3152  1, 1,   -1,-1,  1,-1,  -1, -1,   1,-1,    1, 1,   2, -1,  1,-1,   2,2,
    3153 // 36     37     38       39       40       41      42      43      44
    3154  2,2,    0,0,   0,0,      1,1,    0,-1,    0,-1,   2,2,    1,1,    1,1,
    3155 // 45     46     47       48       49       50      51      52      53
    3156  2,2,    2,2,   2,2,     2,2,     1,1,     1,1,    2,2,    1,1,    1,1,
    3157 // 54     55     56       57       58       59      60      61      62
    3158  1,1,    1,1,   2,2,     1,-1,    0,0,     1,1,    0,0,    2,2,    1,1,
    3159 // 63     64     65      66        67       68      69      70      71
    3160  2,2,    4,-1,  2,-1,    1,1,     1,-1,    1,-1,   1,-1,   1,-1,    2,2,
    3161 // 72     73     74      75        76       77      78      79       80
    3162  2,3,     2,3,  2,3,     1,1,     1,1,     2,2,    2,2,    1,1,     1,1,
    3163 // 81     82     83      84        85       86      87       88      89
    3164  2,3,     0,0,  2,2,     1,1,     1,1,     2,-1,   1,1,     1,1,    1,1,
    3165 // 90      91    92      93        94       95      96       97     98
    3166  1,1,     1,1,   1,1,    1,1,     1,1,      1,1,     1,1,   3,3,    1,1
    3167 
    3168 };
    3169 
    31703077int total_symbols()
    31713078{
     
    31773084  if (new_size<((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]))
    31783085  {
    3179     lbreak("resize perm : %d is to small to hold current heap\n",new_size);
     3086    lbreak("resize perm : %d is to small to hold current heap\n", new_size);
    31803087    exit(0);
    31813088  } else if (new_size>space_size[PERM_SPACE])
     
    31913098  if (new_size<((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]))
    31923099  {
    3193     lbreak("resize perm : %d is to small to hold current heap\n",new_size);
     3100    lbreak("resize perm : %d is to small to hold current heap\n", new_size);
    31943101    exit(0);
    31953102  } else if (new_size>space_size[TMP_SPACE])
     
    31993106  } else if (free_space[TMP_SPACE]==space[TMP_SPACE])
    32003107  {
    3201     free_space[TMP_SPACE]=space[TMP_SPACE]=(char *)realloc(space[TMP_SPACE],new_size);
     3108    free_space[TMP_SPACE]=space[TMP_SPACE]=(char *)realloc(space[TMP_SPACE], new_size);
    32023109    space_size[TMP_SPACE]=new_size;
    3203     dprintf("Lisp : tmp space resized to %d\n",new_size);
     3110    dprintf("Lisp : tmp space resized to %d\n", new_size);
    32043111  } else dprintf("Lisp :tmp not empty, cannot resize\n");
    32053112}
     
    32233130
    32243131  l_comp_init();
    3225   for (i=0;i<TOTAL_SYS_FUNCS;i++)
    3226     add_sys_function(sys_funcs[i],sys_args[i*2],sys_args[i*2+1],i);
     3132  for(i = 0; i < sizeof(sys_funcs) / sizeof(*sys_funcs); i++)
     3133    add_sys_function(sys_funcs[i].name,
     3134                     sys_funcs[i].min_args, sys_funcs[i].max_args, i);
    32273135  clisp_init();
    32283136  current_space=TMP_SPACE;
    32293137  dprintf("Lisp : %d symbols defined, %d system functions, %d pre-compiled functions\n",
    3230       total_symbols(),TOTAL_SYS_FUNCS,total_user_functions);
     3138      total_symbols(), sizeof(sys_funcs) / sizeof(*sys_funcs), total_user_functions);
    32313139}
    32323140
Note: See TracChangeset for help on using the changeset viewer.