Changeset 133
- Timestamp:
- Apr 10, 2008, 11:07:07 PM (15 years ago)
- Location:
- abuse/trunk/src/lisp
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/lisp/Makefile.am
r130 r133 7 7 lisp_gc.cpp lisp_gc.hpp \ 8 8 trig.cpp \ 9 stack.hpp \9 stack.hpp symbols.hpp \ 10 10 $(NULL) 11 11 -
abuse/trunk/src/lisp/lisp.cpp
r129 r133 21 21 #include "lisp.hpp" 22 22 #include "lisp_gc.hpp" 23 #include "symbols.hpp" 24 23 25 #ifdef NO_LIBS 24 # include "fakelib.hpp"26 # include "fakelib.hpp" 25 27 #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" 32 34 #endif 33 35 … … 44 46 45 47 46 char *space[4], *free_space[4];47 int space_size[4], print_level=0,trace_level=0,trace_print_level=1000;48 char *space[4], *free_space[4]; 49 int space_size[4], print_level=0, trace_level=0, trace_print_level=1000; 48 50 int total_user_functions; 49 51 50 52 int current_space; // normally set to TMP_SPACE, unless compiling or other needs 51 53 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 63 54 int break_level=0; 64 55 65 56 void l1print(void *block) 66 57 { 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 { 83 75 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 81 void 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 } 102 92 } 103 93 104 94 void print_trace_stack(int max_levels) 105 95 { 106 where_print(max_levels);96 where_print(max_levels); 107 97 } 108 98 … … 115 105 va_list ap; 116 106 va_start(ap, format); 117 vsprintf(st, format,ap);107 vsprintf(st, format, ap); 118 108 va_end(ap); 119 dprintf("%s\n", st);109 dprintf("%s\n", st); 120 110 int cont=0; 121 111 do 122 112 { 123 113 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")) 127 117 cont=1; 128 else if (!strcmp(st, "w") || !strcmp(st,"where"))118 else if (!strcmp(st, "w") || !strcmp(st, "where")) 129 119 where_print(); 130 else if (!strcmp(st, "q") || !strcmp(st,"quit"))120 else if (!strcmp(st, "q") || !strcmp(st, "quit")) 131 121 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")) 133 123 { 134 124 dprintf("Enviorment : \nnot supported right now\n"); 135 125 136 } else if (!strcmp(st,"h") || !strcmp(st,"help") || !strcmp(st,"?")) 126 } 127 else if (!strcmp(st, "h") || !strcmp(st, "help") || !strcmp(st, "?")) 137 128 { 138 129 dprintf("CLIVE Debugger\n"); … … 164 155 if (current_space!=PERM_SPACE && current_space!=GC_SPACE) 165 156 { 166 lbreak("%s : action requires permanant space\n", why);157 lbreak("%s : action requires permanant space\n", why); 167 158 exit(0); 168 159 } … … 181 172 void *lmalloc(int size, int which_space) 182 173 { 183 return malloc(size); /* XXX */174 return malloc(size); /* XXX FIXME: do we want to fix this one day? */ 184 175 185 176 #ifdef WORD_ALIGN … … 203 194 if (fart) 204 195 { 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); 206 197 exit(0); 207 198 } … … 229 220 long s=sizeof(lisp_1d_array)+size*sizeof(void *); 230 221 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); 232 223 ((lisp_1d_array *)p)->type=L_1D_ARRAY; 233 224 ((lisp_1d_array *)p)->size=size; 234 225 void **data=(void **)(((lisp_1d_array *)p)+1); 235 memset(data, 0,size*sizeof(void *));226 memset(data, 0, size*sizeof(void *)); 236 227 p_ref r1(p); 237 228 … … 243 234 x=eval(CAR(CDR(rest))); 244 235 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)) 246 237 { 247 238 if (!x) … … 275 266 lisp_fixed_point *new_lisp_fixed_point(int32_t x) 276 267 { 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); 278 269 p->type=L_FIXED_POINT; 279 270 p->x=x; … … 284 275 lisp_object_var *new_lisp_object_var(int16_t number) 285 276 { 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); 287 278 p->type=L_OBJECT_VAR; 288 279 p->number=number; … … 294 285 { 295 286 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); 297 288 p->type=L_POINTER; 298 289 p->addr=addr; … … 302 293 struct lisp_character *new_lisp_character(uint16_t ch) 303 294 { 304 lisp_character *c=(lisp_character *)lmalloc(sizeof(lisp_character), current_space);295 lisp_character *c=(lisp_character *)lmalloc(sizeof(lisp_character), current_space); 305 296 c->type=L_CHARACTER; 306 297 c->ch=ch; … … 313 304 if (size<8) size=8; 314 305 315 lisp_string *s=(lisp_string *)lmalloc(size, current_space);306 lisp_string *s=(lisp_string *)lmalloc(size, current_space); 316 307 s->type=L_STRING; 317 308 char *sloc=((char *)s)+sizeof(lisp_string); 318 strcpy(sloc, string);309 strcpy(sloc, string); 319 310 return s; 320 311 } … … 324 315 int size=sizeof(lisp_string)+length+1; 325 316 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); 327 318 s->type=L_STRING; 328 319 char *sloc=((char *)s)+sizeof(lisp_string); 329 memcpy(sloc, string,length);320 memcpy(sloc, string, length); 330 321 sloc[length]=0; 331 322 return s; … … 336 327 int size=sizeof(lisp_string)+length; 337 328 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); 339 330 s->type=L_STRING; 340 331 char *sloc=((char *)s)+sizeof(lisp_string); 341 strcpy(sloc, "");332 strcpy(sloc, ""); 342 333 return s; 343 334 } … … 346 337 lisp_user_function *new_lisp_user_function(void *arg_list, void *block_list) 347 338 { 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); 350 341 lu->type=L_USER_FUNCTION; 351 342 lu->arg_list=arg_list; … … 360 351 current_space=PERM_SPACE; // make sure all functions get defined in permanant space 361 352 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); 363 354 lu->type=L_USER_FUNCTION; 364 355 lu->alist=arg_list; … … 422 413 lisp_number *new_lisp_node(long num) 423 414 { 424 lisp_number *n=(lisp_number *)lmalloc(sizeof(lisp_number), current_space);415 lisp_number *n=(lisp_number *)lmalloc(sizeof(lisp_number), current_space); 425 416 n->type=L_NUMBER; 426 417 n->num=num; … … 430 421 lisp_symbol *new_lisp_symbol(char *name) 431 422 { 432 lisp_symbol *s=(lisp_symbol *)lmalloc(sizeof(lisp_symbol), current_space);423 lisp_symbol *s=(lisp_symbol *)lmalloc(sizeof(lisp_symbol), current_space); 433 424 s->type=L_SYMBOL; 434 425 s->name=new_lisp_string(name); … … 443 434 lisp_number *new_lisp_number(long num) 444 435 { 445 lisp_number *s=(lisp_number *)lmalloc(sizeof(lisp_number), current_space);436 lisp_number *s=(lisp_number *)lmalloc(sizeof(lisp_number), current_space); 446 437 s->type=L_NUMBER; 447 438 s->num=num; … … 452 443 cons_cell *new_cons_cell() 453 444 { 454 cons_cell *c=(cons_cell *)lmalloc(sizeof(cons_cell), current_space);445 cons_cell *c=(cons_cell *)lmalloc(sizeof(cons_cell), current_space); 455 446 c->type=L_CONS_CELL; 456 447 c->car=NULL; … … 468 459 { 469 460 if (*loc=='\n') lines++; 470 dprintf("%c", *loc);461 dprintf("%c", *loc); 471 462 } 472 463 dprintf("\nPROGRAM LOCATION : \n"); 473 464 } 474 465 if (cause) 475 dprintf("ERROR MESSAGE : %s\n", cause);466 dprintf("ERROR MESSAGE : %s\n", cause); 476 467 lbreak(""); 477 468 exit(0); … … 483 474 if (num<0) 484 475 { 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); 486 477 exit(1); 487 478 } … … 607 598 else if ((n1 && !n2) || (n2 && !n1)) return NULL; 608 599 { 609 int t1=*((ltype *)n1), t2=*((ltype *)n2);600 int t1=*((ltype *)n1), t2=*((ltype *)n2); 610 601 if (t1!=t2) return NULL; 611 602 else if (t1==L_NUMBER) … … 639 630 if (x>=((lisp_1d_array *)a)->size || x<0) 640 631 { 641 lbreak("array refrence out of bounds (%d)\n", x);632 lbreak("array refrence out of bounds (%d)\n", x); 642 633 exit(0); 643 634 } … … 647 638 void *lisp_equal(void *n1, void *n2) 648 639 { 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 { 662 652 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; 665 656 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; 679 669 default : 680 return lisp_eq(n1,n2); 681 break; 682 } 683 } 684 } 670 return lisp_eq(n1, n2); 671 } 685 672 } 686 673 … … 794 781 for (cs=(cons_cell *)symbol_list;cs;cs=(cons_cell *)CDR(cs)) 795 782 { 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)) 797 784 return (lisp_symbol *)(cs->car); 798 785 } … … 828 815 while (p) 829 816 { 830 int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string));817 int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string)); 831 818 if (cmp==0) return p; 832 819 else if (cmp<0) p=p->left; … … 844 831 while (p) 845 832 { 846 int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string));833 int cmp=strcmp(name, ((char *)p->name)+sizeof(lisp_string)); 847 834 if (cmp==0) return p; 848 835 else if (cmp<0) … … 900 887 while (list) 901 888 { 902 if (lisp_eq(CAR(CAR(list)), item))889 if (lisp_eq(CAR(CAR(list)), item)) 903 890 return lcar(list); 904 891 list=(cons_cell *)(CDR(list)); … … 934 921 935 922 void *ret=NULL; 936 long l1=list_length(list1), l2=list_length(list2);923 long l1=list_length(list1), l2=list_length(list2); 937 924 if (l1!=l2) 938 925 { … … 944 931 if (l1!=0) 945 932 { 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); 948 935 while (list1) 949 936 { … … 1008 995 if (s->function!=l_undefined) 1009 996 { 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); 1011 998 exit(0); 1012 999 } 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); 1014 1001 return s; 1015 1002 } … … 1021 1008 if (s->value!=l_undefined) 1022 1009 { 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))); 1024 1011 exit(0); 1025 1012 } … … 1035 1022 if (s->function!=l_undefined) 1036 1023 { 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); 1038 1025 exit(0); 1039 1026 } 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); 1041 1028 return s; 1042 1029 } … … 1049 1036 if (s->function!=l_undefined) 1050 1037 { 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); 1052 1039 exit(0); 1053 1040 } 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); 1055 1042 return s; 1056 1043 } … … 1064 1051 if (s->function!=l_undefined) 1065 1052 { 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); 1067 1054 exit(0); 1068 1055 } 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); 1070 1057 return s; 1071 1058 } … … 1101 1088 { 1102 1089 while (*s && *s!='\n' && *s!='\r' && *s!=26) s++; 1103 return read_ltoken(s, buffer);1090 return read_ltoken(s, buffer); 1104 1091 } else if (*s=='/' && *(s+1)=='*') // c style comment 1105 1092 { 1106 1093 skip_c_comment(s); 1107 return read_ltoken(s, buffer);1094 return read_ltoken(s, buffer); 1108 1095 } 1109 1096 else if (*s==0) … … 1139 1126 int end_of_program(char const *s) 1140 1127 { 1141 return !read_ltoken(s, n);1128 return !read_ltoken(s, n); 1142 1129 } 1143 1130 … … 1145 1132 void push_onto_list(void *object, void *&list) 1146 1133 { 1147 p_ref r1(object), r2(list);1134 p_ref r1(object), r2(list); 1148 1135 cons_cell *c=new_cons_cell(); 1149 1136 c->car=object; … … 1157 1144 { 1158 1145 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")) 1162 1149 return NULL; 1163 1150 else if (toupper(n[0])=='T' && !n[1]) … … 1165 1152 else if (n[0]=='\'') // short hand for quote function 1166 1153 { 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); 1169 1156 1170 1157 ((cons_cell *)cs)->car=quote_symbol; … … 1178 1165 else if (n[0]=='`') // short hand for backquote function 1179 1166 { 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); 1182 1169 1183 1170 ((cons_cell *)cs)->car=backquote_symbol; … … 1190 1177 } else if (n[0]==',') // short hand for comma function 1191 1178 { 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); 1194 1181 1195 1182 ((cons_cell *)cs)->car=comma_symbol; … … 1203 1190 else if (n[0]=='(') // make a list of everything in () 1204 1191 { 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); 1207 1194 int done=0; 1208 1195 do 1209 1196 { 1210 1197 char const *tmp=s; 1211 if (!read_ltoken(tmp, n)) // check for the end of the list1212 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"); 1213 1200 if (n[0]==')') 1214 1201 { 1215 1202 done=1; 1216 read_ltoken(s, n); // read off the ')'1203 read_ltoken(s, n); // read off the ')' 1217 1204 } 1218 1205 else … … 1221 1208 { 1222 1209 if (!first) 1223 lerror(s, "token '.' not allowed here\n");1210 lerror(s, "token '.' not allowed here\n"); 1224 1211 else 1225 1212 { 1226 1213 void *tmp; 1227 read_ltoken(s, n); // skip the '.'1214 read_ltoken(s, n); // skip the '.' 1228 1215 tmp=compile(s); 1229 1216 ((cons_cell *)last)->cdr=tmp; // link the last cdr to … … 1231 1218 } 1232 1219 } else if (!last && first) 1233 lerror(s, "illegal end of dotted list\n");1220 lerror(s, "illegal end of dotted list\n"); 1234 1221 else 1235 1222 { … … 1249 1236 1250 1237 } else if (n[0]==')') 1251 lerror(s, "mismatched )");1238 lerror(s, "mismatched )"); 1252 1239 else if (isdigit(n[0]) || (n[0]=='-' && isdigit(n[1]))) 1253 1240 { 1254 1241 lisp_number *num=new_lisp_number(0); 1255 sscanf(n, "%ld",&num->num);1242 sscanf(n, "%ld", &num->num); 1256 1243 ret=num; 1257 1244 } else if (n[0]=='"') … … 1259 1246 ret=new_lisp_string(str_token_len(s)); 1260 1247 char *start=lstring_value(ret); 1261 for (;*s && (*s!='"' || s[1]=='"');s++, start++)1248 for (;*s && (*s!='"' || s[1]=='"');s++, start++) 1262 1249 { 1263 1250 if (*s=='\\') … … 1277 1264 if (n[1]=='\\') 1278 1265 { 1279 read_ltoken(s, n); // read character name1280 if ( streq(n,"newline"))1266 read_ltoken(s, n); // read character name 1267 if (!strcmp(n, "newline")) 1281 1268 ret=new_lisp_character('\n'); 1282 else if ( streq(n,"space"))1269 else if (!strcmp(n, "space")) 1283 1270 ret=new_lisp_character(' '); 1284 1271 else … … 1287 1274 else if (n[1]==0) // short hand for function 1288 1275 { 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); 1291 1278 tmp=make_find_symbol("function"); 1292 1279 ((cons_cell *)cs)->car=tmp; … … 1299 1286 else 1300 1287 { 1301 lbreak("Unknown #\\ notation : %s\n", n);1288 lbreak("Unknown #\\ notation : %s\n", n); 1302 1289 exit(0); 1303 1290 } … … 1369 1356 { 1370 1357 char num[10]; 1371 sprintf(num, "%ld",((lisp_number *)i)->num);1358 sprintf(num, "%ld", ((lisp_number *)i)->num); 1372 1359 lprint_string(num); 1373 1360 } … … 1394 1381 lprint_string(lstring_value(i)); 1395 1382 else 1396 dprintf("\"%s\"", lstring_value(i));1383 dprintf("\"%s\"", lstring_value(i)); 1397 1384 } 1398 1385 break; … … 1401 1388 { 1402 1389 char ptr[10]; 1403 sprintf(ptr, "%p",lpointer_value(i));1390 sprintf(ptr, "%p", lpointer_value(i)); 1404 1391 lprint_string(ptr); 1405 1392 } … … 1408 1395 { 1409 1396 char num[20]; 1410 sprintf(num, "%g",(lfixed_point_value(i)>>16)+1397 sprintf(num, "%g", (lfixed_point_value(i)>>16)+ 1411 1398 ((lfixed_point_value(i)&0xffff))/(double)0x10000); 1412 1399 lprint_string(num); … … 1417 1404 { 1418 1405 uint8_t ch=((lisp_character *)i)->ch; 1419 current_print_file->write(&ch, 1);1406 current_print_file->write(&ch, 1); 1420 1407 } else 1421 1408 { … … 1429 1416 { dprintf("space"); break; } 1430 1417 default : 1431 dprintf("%c", ch);1418 dprintf("%c", ch); 1432 1419 } 1433 1420 } … … 1468 1455 void *eval_function(lisp_symbol *sym, void *arg_list) 1469 1456 { 1470 1471 1472 1457 #ifdef TYPE_CHECKING 1473 int args, req_min,req_max;1458 int args, req_min, req_max; 1474 1459 if (item_type(sym)!=L_SYMBOL) 1475 1460 { … … 1499 1484 case L_USER_FUNCTION : 1500 1485 { 1501 return eval_user_fun(sym, arg_list);1486 return eval_user_fun(sym, arg_list); 1502 1487 } break; 1503 1488 default : … … 1541 1526 { 1542 1527 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; 1544 1529 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; 1546 1531 case L_USER_FUNCTION : 1547 1532 { 1548 return eval_user_fun(sym, arg_list);1533 return eval_user_fun(sym, arg_list); 1549 1534 } break; 1550 1535 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); 1554 1540 while (arg_list) 1555 1541 { 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)) 1588 1556 ret=true_symbol; 1589 1557 else ret=NULL; 1590 1558 } break; 1591 1559 default : 1592 fprintf(stderr, "not a fun, shouldn't happen\n");1560 fprintf(stderr, "not a fun, shouldn't happen\n"); 1593 1561 } 1594 1562 … … 1598 1566 #endif 1599 1567 1600 1601 1568 return ret; 1602 1569 } … … 1607 1574 if (p) 1608 1575 { 1609 pro_print(out, p->right);1576 pro_print(out, p->right); 1610 1577 { 1611 1578 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); 1616 1583 } 1617 1584 } … … 1619 1586 void preport(char *fn) 1620 1587 { 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); 1623 1590 delete fp; 1624 1591 } … … 1642 1609 } 1643 1610 } 1644 int num_args=list_length(CDR(arg_list)), i,stop=0;1611 int num_args=list_length(CDR(arg_list)), i, stop=0; 1645 1612 if (!num_args) return 0; 1646 1613 … … 1664 1631 } 1665 1632 1666 cons_cell *na_list=NULL, *return_list=NULL,*last_return=NULL;1633 cons_cell *na_list=NULL, *return_list=NULL, *last_return=NULL; 1667 1634 1668 1635 do … … 1692 1659 { 1693 1660 cons_cell *c=new_cons_cell(); 1694 c->car=eval_function((lisp_symbol *)sym, first);1661 c->car=eval_function((lisp_symbol *)sym, first); 1695 1662 if (return_list) 1696 1663 last_return->cdr=c; … … 1710 1677 { 1711 1678 void *el_list=CDR(prog_list); 1712 p_ref ref1(prog_list), ref2(el_list);1679 p_ref ref1(prog_list), ref2(el_list); 1713 1680 void *ret=NULL; 1714 1681 void *rtype=eval(CAR(prog_list)); … … 1722 1689 { 1723 1690 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; 1725 1692 1726 1693 // 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)) 1728 1695 { 1729 1696 str_eval[i]=eval(CAR(el_list)); … … 1777 1744 case L_STRING : 1778 1745 { 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]))); 1780 1747 s+=strlen(lstring_value(str_eval[i])); 1781 1748 } break; … … 1809 1776 else 1810 1777 { 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); 1813 1780 while (args) 1814 1781 { … … 1853 1820 switch (fun->fun_number) 1854 1821 { 1855 case 0 : // print1822 case SYS_FUNC_PRINT: 1856 1823 { 1857 1824 ret=NULL; … … 1863 1830 return ret; 1864 1831 } break; 1865 case 1 : // car1832 case SYS_FUNC_CAR: 1866 1833 { ret=lcar(eval(CAR(arg_list))); } break; 1867 case 2 : // cdr1834 case SYS_FUNC_CDR: 1868 1835 { ret=lcdr(eval(CAR(arg_list))); } break; 1869 case 3 : // length1836 case SYS_FUNC_LENGTH: 1870 1837 { 1871 1838 void *v=eval(CAR(arg_list)); 1872 1839 switch (item_type(v)) 1873 1840 { 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 } 1880 1847 } 1881 1848 } break; 1882 case 4 : // list1883 { 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); 1886 1853 while (arg_list) 1887 1854 { … … 1897 1864 ret=first; 1898 1865 } break; 1899 case 5 : // cons1866 case SYS_FUNC_CONS: 1900 1867 { void *c=new_cons_cell(); 1901 1868 p_ref r1(c); … … 1906 1873 ret=c; 1907 1874 } break; 1908 case 6 : // quote1875 case SYS_FUNC_QUOTE: 1909 1876 ret=CAR(arg_list); 1910 1877 break; 1911 case 7 : // eq1878 case SYS_FUNC_EQ: 1912 1879 { 1913 1880 l_user_stack.push(eval(CAR(arg_list))); 1914 1881 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 : // equal1882 ret=lisp_eq(l_user_stack.pop(1), l_user_stack.pop(1)); 1883 } break; 1884 case SYS_FUNC_EQUAL: 1918 1885 { 1919 1886 l_user_stack.push(eval(CAR(arg_list))); 1920 1887 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: 1924 1891 { 1925 1892 long sum=0; … … 1932 1899 } 1933 1900 break; 1934 case 28 : // *1901 case SYS_FUNC_TIMES: 1935 1902 { 1936 1903 long sum; … … 1960 1927 } 1961 1928 break; 1962 case 29 : // /1963 { 1964 long sum=0, first=1;1929 case SYS_FUNC_SLASH: 1930 { 1931 long sum=0, first=1; 1965 1932 while (arg_list) 1966 1933 { … … 1983 1950 } 1984 1951 break; 1985 case 9 : // -1952 case SYS_FUNC_MINUS: 1986 1953 { 1987 1954 long x=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 1994 1961 } 1995 1962 break; 1996 case 10 : // if1963 case SYS_FUNC_IF: 1997 1964 { 1998 1965 if (eval(CAR(arg_list))) … … 2005 1972 } 2006 1973 } break; 2007 case 63:2008 case 11 : // setf2009 { 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); 2012 1979 i=CAR(arg_list); 2013 1980 … … 2015 1982 switch (item_type(i)) 2016 1983 { 2017 case L_SYMBOL : 2018 { 2019 switch (item_type (((lisp_symbol *)i)->value)) 2020 { 2021 case L_NUMBER : 1984 case L_SYMBOL : 2022 1985 { 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; 2027 2003 } break; 2028 case L_ OBJECT_VAR :2004 case L_CONS_CELL : // this better be an 'aref' 2029 2005 { 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; 2031 2051 } break; 2052 2032 2053 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_CHECKING2040 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 #endif2056 void *a=(lisp_1d_array *)eval(CAR(CDR(i)));2057 p_ref r1(a);2058 #ifdef TYPE_CHECKING2059 if (item_type(a)!=L_1D_ARRAY)2060 2054 { 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"); 2063 2057 exit(0); 2064 2058 } 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: 2095 2062 ret=NULL; 2096 2063 break; 2097 case 13 : // assoc2064 case SYS_FUNC_ASSOC: 2098 2065 { 2099 2066 void *item=eval(CAR(arg_list)); … … 2101 2068 void *list=(cons_cell *)eval(CAR(CDR(arg_list))); 2102 2069 p_ref r2(list); 2103 ret=assoc(item, (cons_cell *)list);2104 } break; 2105 case 20 : // not is the same as null2106 case 14 : // null2070 ret=assoc(item, (cons_cell *)list); 2071 } break; 2072 case SYS_FUNC_NOT: 2073 case SYS_FUNC_NULL: 2107 2074 if (eval(CAR(arg_list))==NULL) ret=true_symbol; else ret=NULL; 2108 2075 break; 2109 case 15 : // acons2110 { 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))); 2112 2079 p_ref r1(i1); 2113 2080 cons_cell *cs=new_cons_cell(); … … 2117 2084 } break; 2118 2085 2119 case 16 : // pairlis2086 case SYS_FUNC_PAIRLIS: 2120 2087 { 2121 2088 l_user_stack.push(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2124 2091 void *n2=l_user_stack.pop(1); 2125 2092 void *n1=l_user_stack.pop(1); 2126 ret=pairlis(n1, n2,n3);2127 } break; 2128 case 17 : // let2093 ret=pairlis(n1, n2, n3); 2094 } break; 2095 case SYS_FUNC_LET: 2129 2096 { 2130 2097 // make an a-list of new variable names and new values 2131 2098 void *var_list=CAR(arg_list), 2132 2099 *block_list=CDR(arg_list); 2133 p_ref r1(block_list), r2(var_list);2100 p_ref r1(block_list), r2(var_list); 2134 2101 long stack_start=l_user_stack.son; 2135 2102 2136 2103 while (var_list) 2137 2104 { 2138 void *var_name=CAR(CAR(var_list)), *tmp;2105 void *var_name=CAR(CAR(var_list)), *tmp; 2139 2106 #ifdef TYPE_CHECKING 2140 2107 if (item_type(var_name)!=L_SYMBOL) … … 2171 2138 } 2172 2139 break; 2173 case 18 : // defun2140 case SYS_FUNC_DEFUN: 2174 2141 { 2175 2142 void *symbol=CAR(arg_list); … … 2194 2161 intptr_t a=cache.reg_lisp_block(lcar(lcdr(arg_list))); 2195 2162 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); 2197 2164 #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); 2201 2168 ret=symbol; 2202 2169 } break; 2203 case 19 : // atom2170 case SYS_FUNC_ATOM: 2204 2171 { ret=lisp_atom(eval(CAR(arg_list))); } 2205 case 21 : // and2172 case SYS_FUNC_AND: 2206 2173 { 2207 2174 void *l=arg_list; … … 2217 2184 } 2218 2185 } break; 2219 case 22 : // or2186 case SYS_FUNC_OR: 2220 2187 { 2221 2188 void *l=arg_list; … … 2231 2198 } 2232 2199 } break; 2233 case 23 : // progn2200 case SYS_FUNC_PROGN: 2234 2201 { ret=eval_block(arg_list); } break; 2235 case 25 : // concatenate2202 case SYS_FUNC_CONCATENATE: 2236 2203 ret=concatenate(arg_list); 2237 2204 break; 2238 case 26 : // char-code2205 case SYS_FUNC_CHAR_CODE: 2239 2206 { 2240 2207 void *i=eval(CAR(arg_list)); … … 2243 2210 switch (item_type(i)) 2244 2211 { 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 } 2255 2222 } 2256 2223 } break; 2257 case 27 : // code-char2224 case SYS_FUNC_CODE_CHAR: 2258 2225 { 2259 2226 void *i=eval(CAR(arg_list)); … … 2267 2234 ret=new_lisp_character(((lisp_number *)i)->num); 2268 2235 } break; 2269 case 30 : // cond2236 case SYS_FUNC_COND: 2270 2237 { 2271 2238 void *block_list=CAR(arg_list); … … 2283 2250 } 2284 2251 } break; 2285 case 31 : // select2252 case SYS_FUNC_SELECT: 2286 2253 { 2287 2254 void *selector=eval(CAR(arg_list)); 2288 2255 void *sel=CDR(arg_list); 2289 p_ref r1(selector), r2(sel);2256 p_ref r1(selector), r2(sel); 2290 2257 while (sel) 2291 2258 { 2292 if (lisp_equal(selector, eval(CAR(CAR(sel)))))2259 if (lisp_equal(selector, eval(CAR(CAR(sel))))) 2293 2260 { 2294 2261 sel=CDR(CAR(sel)); … … 2302 2269 } 2303 2270 } break; 2304 case 32 : // function2271 case SYS_FUNC_FUNCTION: 2305 2272 ret=lookup_symbol_function(eval(CAR(arg_list))); 2306 2273 break; 2307 case 33 : // mapcar2274 case SYS_FUNC_MAPCAR: 2308 2275 ret=mapcar(arg_list); 2309 case 34 : // funcall2276 case SYS_FUNC_FUNCALL: 2310 2277 { 2311 2278 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: 2315 2282 { 2316 2283 long n1=lnumber_value(eval(CAR(arg_list))); … … 2319 2286 } 2320 2287 break; 2321 case 36 : // <2288 case SYS_FUNC_LT: 2322 2289 { 2323 2290 long n1=lnumber_value(eval(CAR(arg_list))); … … 2326 2293 } 2327 2294 break; 2328 case 47 : // >=2295 case SYS_FUNC_GE: 2329 2296 { 2330 2297 long n1=lnumber_value(eval(CAR(arg_list))); … … 2333 2300 } 2334 2301 break; 2335 case 48 : // <=2302 case SYS_FUNC_LE: 2336 2303 { 2337 2304 long n1=lnumber_value(eval(CAR(arg_list))); … … 2341 2308 break; 2342 2309 2343 case 37 : // tmp-space2310 case SYS_FUNC_TMP_SPACE: 2344 2311 tmp_space(); 2345 2312 ret=true_symbol; 2346 2313 break; 2347 case 38 : // perm-space2314 case SYS_FUNC_PERM_SPACE: 2348 2315 perm_space(); 2349 2316 ret=true_symbol; 2350 2317 break; 2351 case 39:2318 case SYS_FUNC_SYMBOL_NAME: 2352 2319 void *symb; 2353 2320 symb=eval(CAR(arg_list)); … … 2362 2329 ret=((lisp_symbol *)symb)->name; 2363 2330 break; 2364 case 40 : // trace2331 case SYS_FUNC_TRACE: 2365 2332 trace_level++; 2366 2333 if (arg_list) … … 2368 2335 ret=true_symbol; 2369 2336 break; 2370 case 41 : // untrace2337 case SYS_FUNC_UNTRACE: 2371 2338 if (trace_level>0) 2372 2339 { … … 2375 2342 } else ret=NULL; 2376 2343 break; 2377 case 42 : // digitstr2378 { 2379 char tmp[50], *tp;2344 case SYS_FUNC_DIGSTR: 2345 { 2346 char tmp[50], *tp; 2380 2347 long num=lnumber_value(eval(CAR(arg_list))); 2381 2348 long dig=lnumber_value(eval(CAR(CDR(arg_list)))); … … 2394 2361 ret=new_lisp_string(tp+1); 2395 2362 } break; 2396 case 98:2397 case 66:2398 case 43: // compile-file2363 case SYS_FUNC_LOCAL_LOAD: 2364 case SYS_FUNC_LOAD: 2365 case SYS_FUNC_COMPILE_FILE: 2399 2366 { 2400 2367 void *fn = eval( CAR( arg_list ) ); … … 2402 2369 p_ref r1( fn ); 2403 2370 bFILE *fp; 2404 if( fun->fun_number == 98 ) // local_load2371 if( fun->fun_number == SYS_FUNC_LOCAL_LOAD ) 2405 2372 { 2406 2373 // A special test for gamma.lsp … … 2420 2387 else 2421 2388 { 2422 fp = open_file(st, "rb");2389 fp = open_file(st, "rb"); 2423 2390 } 2424 2391 … … 2427 2394 delete fp; 2428 2395 if( DEFINEDP(symbol_value(load_warning)) && symbol_value(load_warning) ) 2429 dprintf("Warning : file %s does not exist s\n",st);2396 dprintf("Warning : file %s does not exist\n", st); 2430 2397 ret = NULL; 2431 2398 } … … 2440 2407 } 2441 2408 2442 fp->read(s, l);2409 fp->read(s, l); 2443 2410 s[l]=0; 2444 2411 delete fp; … … 2446 2413 #ifndef NO_LIBS 2447 2414 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); 2450 2417 crc_manager.get_filenumber(st); // make sure this file gets crc'ed 2451 2418 #endif … … 2461 2428 eval(compiled_form); 2462 2429 compiled_form=NULL; 2463 restore_heap(m, TMP_SPACE);2430 restore_heap(m, TMP_SPACE); 2464 2431 } 2465 2432 #ifndef NO_LIBS … … 2471 2438 } 2472 2439 } break; 2473 case 44 : // abs2440 case SYS_FUNC_ABS: 2474 2441 ret=new_lisp_number(abs(lnumber_value(eval(CAR(arg_list))))); break; 2475 case 45 : // min2476 { 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)))); 2478 2445 if (x<y) ret=new_lisp_number(x); else ret=new_lisp_number(y); 2479 2446 } break; 2480 case 46 : // max2481 { 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)))); 2483 2450 if (x>y) ret=new_lisp_number(x); else ret=new_lisp_number(y); 2484 2451 } break; 2485 case 49 : // backquote2452 case SYS_FUNC_BACKQUOTE: 2486 2453 { 2487 2454 ret=backquote_eval(CAR(arg_list)); 2488 2455 } break; 2489 case 50:2456 case SYS_FUNC_COMMA: 2490 2457 { 2491 2458 lprint(arg_list); … … 2494 2461 ret=NULL; 2495 2462 } break; 2496 case 51:2463 case SYS_FUNC_NTH: 2497 2464 { 2498 2465 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: 2506 2477 { 2507 2478 long y=(lnumber_value(eval(CAR(arg_list)))); arg_list=CDR(arg_list); 2508 2479 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: 2512 2483 { 2513 2484 int sp=current_space; … … 2548 2519 current_space=sp; 2549 2520 } break; 2550 case 58:2521 case SYS_FUNC_QUIT: 2551 2522 { 2552 2523 exit(0); 2553 2524 } break; 2554 case 59:2525 case SYS_FUNC_EVAL: 2555 2526 { 2556 2527 ret=eval(eval(CAR(arg_list))); 2557 2528 } 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: 2560 2531 { 2561 2532 long x=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2564 2535 ret=new_lisp_number(x%y); 2565 2536 } break; 2566 /* case 62:2537 /* case SYS_FUNC_WRITE_PROFILE: 2567 2538 { 2568 2539 char *fn=lstring_value(eval(CAR(arg_list))); 2569 FILE *fp=fopen(fn, "wb");2540 FILE *fp=fopen(fn, "wb"); 2570 2541 if (!fp) 2571 lbreak("could not open %s for writing", fn);2542 lbreak("could not open %s for writing", fn); 2572 2543 else 2573 2544 { 2574 2545 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, 2576 2547 lstring_value(((lisp_symbol *)(CAR(s)))->name)); 2577 2548 fclose(fp); 2578 2549 } 2579 2550 } break;*/ 2580 case 64:2551 case SYS_FUNC_FOR: 2581 2552 { 2582 2553 void *bind_var=CAR(arg_list); arg_list=CDR(arg_list); … … 2596 2567 arg_list=CDR(arg_list); 2597 2568 2598 void *block=NULL, *ret=NULL;2569 void *block=NULL, *ret=NULL; 2599 2570 p_ref r3(block); 2600 2571 l_user_stack.push(symbol_value(bind_var)); // save old symbol value 2601 2572 while (ilist) 2602 2573 { 2603 set_symbol_value(bind_var, CAR(ilist));2574 set_symbol_value(bind_var, CAR(ilist)); 2604 2575 for (block=arg_list;block;block=CDR(block)) 2605 2576 ret=eval(CAR(block)); 2606 2577 ilist=CDR(ilist); 2607 2578 } 2608 set_symbol_value(bind_var, l_user_stack.pop(1));2579 set_symbol_value(bind_var, l_user_stack.pop(1)); 2609 2580 ret=ret; 2610 2581 } break; 2611 case 65:2582 case SYS_FUNC_OPEN_FILE: 2612 2583 { 2613 2584 bFILE *old_file=current_print_file; … … 2632 2603 2633 2604 } break; 2634 case 67:2605 case SYS_FUNC_BIT_AND: 2635 2606 { 2636 2607 long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2642 2613 ret=new_lisp_number(first); 2643 2614 } break; 2644 case 68:2615 case SYS_FUNC_BIT_OR: 2645 2616 { 2646 2617 long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2652 2623 ret=new_lisp_number(first); 2653 2624 } break; 2654 case 69:2625 case SYS_FUNC_BIT_XOR: 2655 2626 { 2656 2627 long first=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2662 2633 ret=new_lisp_number(first); 2663 2634 } break; 2664 case 70 : // make-array2635 case SYS_FUNC_MAKE_ARRAY: 2665 2636 { 2666 2637 long l=lnumber_value(eval(CAR(arg_list))); 2667 2638 if (l>=2<<16 || l<=0) 2668 2639 { 2669 lbreak("bad array size %d\n", l);2640 lbreak("bad array size %d\n", l); 2670 2641 exit(0); 2671 2642 } 2672 ret=new_lisp_1d_array(l, CDR(arg_list));2673 } break; 2674 case 71 : // aref2643 ret=new_lisp_1d_array(l, CDR(arg_list)); 2644 } break; 2645 case SYS_FUNC_AREF: 2675 2646 { 2676 2647 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-1progn2648 ret=lget_array_element(eval(CAR(arg_list)), x); 2649 } break; 2650 case SYS_FUNC_IF_1PROGN: 2680 2651 { 2681 2652 if (eval(CAR(arg_list))) … … 2684 2655 2685 2656 } break; 2686 case 73 : // if-2progn2657 case SYS_FUNC_IF_2PROGN: 2687 2658 { 2688 2659 if (eval(CAR(arg_list))) … … 2691 2662 2692 2663 } break; 2693 case 74 : // if-12progn2664 case SYS_FUNC_IF_12PROGN: 2694 2665 { 2695 2666 if (eval(CAR(arg_list))) … … 2698 2669 2699 2670 } break; 2700 case 75 : // eq02671 case SYS_FUNC_EQ0: 2701 2672 { 2702 2673 void *v=eval(CAR(arg_list)); … … 2705 2676 else ret=true_symbol; 2706 2677 } break; 2707 case 76 : // preport2678 case SYS_FUNC_PREPORT: 2708 2679 { 2709 2680 #ifdef L_PROFILE … … 2712 2683 #endif 2713 2684 } break; 2714 case 77 : // search2685 case SYS_FUNC_SEARCH: 2715 2686 { 2716 2687 void *arg1=eval(CAR(arg_list)); arg_list=CDR(arg_list); … … 2719 2690 char *needle=lstring_value(arg1); 2720 2691 2721 char *find=strstr(haystack, needle);2692 char *find=strstr(haystack, needle); 2722 2693 if (find) 2723 2694 ret=new_lisp_number(find-haystack); 2724 2695 else ret=NULL; 2725 2696 } break; 2726 case 78 : // elt2697 case SYS_FUNC_ELT: 2727 2698 { 2728 2699 void *arg1=eval(CAR(arg_list)); arg_list=CDR(arg_list); … … 2735 2706 ret=new_lisp_character(st[x]); 2736 2707 } break; 2737 case 79 : // listp2708 case SYS_FUNC_LISTP: 2738 2709 { 2739 2710 return item_type(eval(CAR(arg_list)))==L_CONS_CELL ? true_symbol : NULL; 2740 2711 } break; 2741 case 80 : // numberp2712 case SYS_FUNC_NUMBERP: 2742 2713 { 2743 2714 int t=item_type(eval(CAR(arg_list))); 2744 2715 if (t==L_NUMBER || t==L_FIXED_POINT) return true_symbol; else return NULL; 2745 2716 } break; 2746 case 81 : // do2717 case SYS_FUNC_DO: 2747 2718 { 2748 2719 void *init_var=CAR(arg_list); 2749 2720 p_ref r1(init_var); 2750 int i, ustack_start=l_user_stack.son; // restore stack at end2721 int i, ustack_start=l_user_stack.son; // restore stack at end 2751 2722 void *sym=NULL; 2752 2723 p_ref r2(sym); … … 2767 2738 2768 2739 // 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++) 2770 2741 { 2771 2742 sym=CAR(CAR(init_var)); 2772 set_symbol_value(sym, *do_evaled);2743 set_symbol_value(sym, *do_evaled); 2773 2744 } 2774 2745 … … 2789 2760 // restore old values for symbols 2790 2761 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++) 2792 2763 { 2793 2764 sym=CAR(CAR(init_var)); 2794 set_symbol_value(sym, *do_evaled);2765 set_symbol_value(sym, *do_evaled); 2795 2766 } 2796 2767 … … 2798 2769 2799 2770 } break; 2800 case 82 : // gc2771 case SYS_FUNC_GC: 2801 2772 { 2802 2773 collect_space(current_space); 2803 2774 } break; 2804 case 83 : // schar2775 case SYS_FUNC_SCHAR: 2805 2776 { 2806 2777 char *s=lstring_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2808 2779 2809 2780 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); } 2811 2782 else if (x<0) 2812 2783 { lbreak("SCHAR: index should not be negative\n"); exit(0); } 2813 2784 return new_lisp_character(s[x]); 2814 2785 } break; 2815 case 84 :// symbolp2786 case SYS_FUNC_SYMBOLP: 2816 2787 { if (item_type(eval(CAR(arg_list)))==L_SYMBOL) return true_symbol; 2817 2788 else return NULL; } break; 2818 case 85 : // num2str2789 case SYS_FUNC_NUM2STR: 2819 2790 { 2820 2791 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)))); 2822 2793 ret=new_lisp_string(str); 2823 2794 } break; 2824 case 86 : // nconc2795 case SYS_FUNC_NCONC: 2825 2796 { 2826 2797 void *l1=eval(CAR(arg_list)); arg_list=CDR(arg_list); 2827 2798 p_ref r1(l1); 2828 void *first=l1, *next;2799 void *first=l1, *next; 2829 2800 p_ref r2(first); 2830 2801 … … 2846 2817 ret=first; 2847 2818 } break; 2848 case 87 : // first2819 case SYS_FUNC_FIRST: 2849 2820 { ret=CAR(eval(CAR(arg_list))); } break; 2850 case 88 : // second2821 case SYS_FUNC_SECOND: 2851 2822 { ret=CAR(CDR(eval(CAR(arg_list)))); } break; 2852 case 89 : // third2823 case SYS_FUNC_THIRD: 2853 2824 { ret=CAR(CDR(CDR(eval(CAR(arg_list))))); } break; 2854 case 90 : // fourth2825 case SYS_FUNC_FOURTH: 2855 2826 { ret=CAR(CDR(CDR(CDR(eval(CAR(arg_list)))))); } break; 2856 case 91 : // fifth2827 case SYS_FUNC_FIFTH: 2857 2828 { ret=CAR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))); } break; 2858 case 92 : // sixth2829 case SYS_FUNC_SIXTH: 2859 2830 { ret=CAR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))); } break; 2860 case 93 : // seventh2831 case SYS_FUNC_SEVENTH: 2861 2832 { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))))); } break; 2862 case 94 : // eight2833 case SYS_FUNC_EIGHTH: 2863 2834 { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))))); } break; 2864 case 95 : // ninth2835 case SYS_FUNC_NINTH: 2865 2836 { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list))))))))))); } break; 2866 case 96 : // tenth2837 case SYS_FUNC_TENTH: 2867 2838 { ret=CAR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(CDR(eval(CAR(arg_list)))))))))))); } break; 2868 case 97:2839 case SYS_FUNC_SUBSTR: 2869 2840 { 2870 2841 long x1=lnumber_value(eval(CAR(arg_list))); arg_list=CDR(arg_list); … … 2878 2849 lisp_string *s=new_lisp_string(x2-x1+2); 2879 2850 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); 2881 2852 2882 2853 *(lstring_value(s)+(x2-x1+1))=0; … … 2885 2856 case 99 : 2886 2857 { 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); 2889 2860 while (arg_list) 2890 2861 { 2891 2892 2893 2894 2895 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); 2896 2867 } 2897 2868 return rstart; … … 2899 2870 2900 2871 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); } 2902 2873 } 2903 2874 return ret; … … 2953 2924 void *fun_arg_list=cache.lblock(fun->alist); 2954 2925 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); 2956 2927 #else 2957 2928 void *fun_arg_list=fun->arg_list; 2958 2929 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); 2960 2931 #endif 2961 2932 … … 3043 3014 if (trace_level<=trace_print_level) 3044 3015 { 3045 dprintf("%d (%d, %d,%d) TRACE : ",trace_level,3016 dprintf("%d (%d, %d, %d) TRACE : ", trace_level, 3046 3017 space_size[PERM_SPACE]-((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]), 3047 3018 space_size[TMP_SPACE]-((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]), … … 3077 3048 case L_CONS_CELL : 3078 3049 { 3079 ret=eval_function((lisp_symbol *)CAR(prog), CDR(prog));3050 ret=eval_function((lisp_symbol *)CAR(prog), CDR(prog)); 3080 3051 } 3081 3052 break; 3082 3053 default : 3083 fprintf(stderr, "shouldn't happen\n");3054 fprintf(stderr, "shouldn't happen\n"); 3084 3055 } 3085 3056 } … … 3088 3059 trace_level--; 3089 3060 if (trace_level<=trace_print_level) 3090 dprintf("%d (%d, %d,%d) TRACE ==> ",trace_level,3061 dprintf("%d (%d, %d, %d) TRACE ==> ", trace_level, 3091 3062 space_size[PERM_SPACE]-((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE]), 3092 3063 space_size[TMP_SPACE]-((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE]), … … 3104 3075 } 3105 3076 3106 #define TOTAL_SYS_FUNCS 993107 char const *sys_funcs[TOTAL_SYS_FUNCS] =3108 {3109 // 0 1 2 3 4 5 6 73110 "print","car","cdr","length","list","cons","quote","eq",3111 // 8 9 10 11 12 13 14 15 163112 "+","-","if","setf","symbol-list","assoc","null","acons","pairlis",3113 // 17 18 19 20 21 22 23 243114 "let","defun","atom","not", "and", "or","progn","equal",3115 // 25 26 27 28 29 30 313116 "concatenate","char-code","code-char","*","/","cond","select",3117 // 32 33 34 35 36 373118 "function", "mapcar", "funcall", ">", "<", "tmp-space",3119 // 38 39 40 41 423120 "perm-space","symbol-name","trace","untrace","digstr",3121 // 43 44 45 46 47 48 493122 "compile-file","abs","min","max",">=","<=","backquote",3123 // 50 51 52 53 54 55 563124 "comma","nth","resize-tmp","resize-perm","cos","sin","atan2",3125 // 57 58 59 60 61 62 633126 "enum", "quit","eval","break","mod","write_profile","setq",3127 // 64 65 66 67 68 69 703128 "for", "open_file","load","bit-and","bit-or","bit-xor","make-array",3129 // 71 72 73 74 75 763130 "aref","if-1progn","if-2progn","if-12progn","eq0","preport",3131 // 77 78 79 80 81 82 833132 "search","elt", "listp", "numberp", "do", "gc", "schar",3133 // 84 85 86 87 88 89 903134 "symbolp","num2str","nconc","first","second","third","fourth",3135 // 91 92 93 94 95 963136 "fifth", "sixth", "seventh","eighth","ninth","tenth",3137 "substr", // 973138 "local_load" // 98, filename3139 };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 83146 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 173148 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 263150 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 353152 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 443154 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 533156 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 623158 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 713160 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 803162 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 893164 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 983166 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 1,1, 3,3, 1,13167 3168 };3169 3170 3077 int total_symbols() 3171 3078 { … … 3177 3084 if (new_size<((char *)free_space[PERM_SPACE]-(char *)space[PERM_SPACE])) 3178 3085 { 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); 3180 3087 exit(0); 3181 3088 } else if (new_size>space_size[PERM_SPACE]) … … 3191 3098 if (new_size<((char *)free_space[TMP_SPACE]-(char *)space[TMP_SPACE])) 3192 3099 { 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); 3194 3101 exit(0); 3195 3102 } else if (new_size>space_size[TMP_SPACE]) … … 3199 3106 } else if (free_space[TMP_SPACE]==space[TMP_SPACE]) 3200 3107 { 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); 3202 3109 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); 3204 3111 } else dprintf("Lisp :tmp not empty, cannot resize\n"); 3205 3112 } … … 3223 3130 3224 3131 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); 3227 3135 clisp_init(); 3228 3136 current_space=TMP_SPACE; 3229 3137 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); 3231 3139 } 3232 3140
Note: See TracChangeset
for help on using the changeset viewer.