1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
|
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "include.h"
/* The functions IisProp check the property holds, and return the
argument. They may in future allow resetting the argument.
*/
object
IisSymbol(object f)
{ if (type_of(f) != t_symbol)
{ FEerror("Not a symbol ~s",1,f); }
return f;
}
/* object */
/* IisFboundp(object f) */
/* { */
/* IisSymbol(f); */
/* if (f->s.s_gfdef ==0) */
/* { FEerror("Not a fboundp ~s",1,f);} */
/* return f; */
/* } */
object
IisArray(object f)
{ if (TS_MEMBER(type_of(f),
TS(t_array)
|TS(t_vector)
|TS(t_bitvector)
|TS(t_string)))
return f;
else
{ FEwrong_type_argument(sLarray,f); return f;
}
}
object
Iis_fixnum(object f)
{ if (type_of(f)==t_fixnum)
{ return f;}
else
{ FEerror("Not a fixnum ~s",1,f); return f;
}
}
void Wrong_type_error(char *str,int n,...) {
FEerror("Wrong type error",0);
}
/* static object */
/* Iapply_ap(object (*f) (/\* ??? *\/), va_list ap) */
/* Apply f to the va_list ap, with an implicit number of args
passed in VFUN_NARGS */
/* { int n = VFUN_NARGS; */
/* object *new; */
/* COERCE_VA_LIST(new,ap,n); */
/* return c_apply_n(f,n,new); */
/* } */
object
Ifuncall_n(object fun,int n,...) {
/* call fun on the n optional args supplied, and set the fcall.nvalues etc
return the first value */
va_list ap;
object *new;
va_start(ap,n);
COERCE_VA_LIST(new,ap,n);
va_end(ap);
return IapplyVector(fun,n,new);
}
/* For applying FUN to args in VA_LIST, where n are supplied directly
and the last one is itself a va_list */
/* object */
/* Iapply_fun_n(object fun,int n,int m,...) { */
/* va_list ap1,ap; */
/* object b[F_ARG_LIMIT]; */
/* int i = 0; */
/* va_start(ap1,m); */
/* while (--n >= 0) */
/* { b[i++] = va_arg(ap1,object);} */
/* if (m > 0) { */
/* ap = va_arg(ap1,va_list); */
/* while (--m >= 0) */
/* { b[i++] = va_arg(ap,object);} */
/* } */
/* va_end(ap1); */
/* return IapplyVector(fun,i,b); */
/* } */
/* For applying FUN to args in VA_LIST, where n are supplied directly
and the last one is itself a va_list */
/* object */
/* Iapply_fun_n1(object (*fun)(),int n,int m,...) { */
/* va_list ap; */
/* object b[F_ARG_LIMIT],*bb; */
/* int i = 0; */
/* va_start(ap,m); */
/* while (--n >= 0) { */
/* b[i++] = va_arg(ap,object);} */
/* if (m > 0) { */
/* bb = va_arg(ap,object *); */
/* while (--m >= 0) */
/* b[i++] = *bb++; */
/* } */
/* va_end(ap); */
/* return IapplyVector(make_sfun(Cnil,fun,i,Cnil),i,b); */
/* } */
/* For applying FUN to args in VA_LIST, where n are supplied directly
and the last one is itself a va_list */
/* object */
/* Iapply_fun_n2(object fun,int n,int m,...) { */
/* va_list ap,*app; */
/* object b[F_ARG_LIMIT]; */
/* int i = 0; */
/* va_start(ap,m); */
/* while (--n >= 0) { */
/* b[i++] = va_arg(ap,object);} */
/* if (m > 0) { */
/* app = va_arg(ap,va_list *); */
/* while (--m >= 0) */
/* b[i++] = va_arg(*app,object); */
/* } */
/* va_end(ap); */
/* return IapplyVector(fun,i,b); */
/* } */
/* static object */
/* ImakeStructure(int n, object *p) */
/* p[0]= structure name , p[1] = 1'st elt,.... p[n-1] = last elt. */
/* { object * r = vs_top; */
/* object res; */
/* if (p+n != r) { FEerror("bad make struct",0);} */
/* vs_base= p; */
/* siLmake_structure(); */
/* res = vs_base[0]; */
/* vs_top=p; */
/* return res; */
/* } */
/* static void */
/* Ineed_in_image(object (*foo) (/\* ??? *\/)) */
/* {;} */
/* Convert a value stack type return to an fcall multiple vaule return
and return the actual value (or nil if no values); */
object
Ivs_values(void)
{ fixnum n = fcall.nvalues = vs_top - vs_base;
object *b = vs_base,*p=&fcall.values[0];
object res = (n > 0 ? b[0] : sLnil);
if (n>=(fixnum)(sizeof(fcall.values)/sizeof(*fcall.values)))
FEerror("Too many function call values",0);
while (--n > 0)
{ *++p= *++b;}
return res;
}
/* static void */
/* fatal(char *s, int i1, int i2) */
/* { */
/* fprintf(stderr,s,i1,i2); */
/* exit(1); */
/* } */
/* Copy STRING to BUF which has N bytes available.
If there is not enough space, malloc some */
char *
lisp_copy_to_null_terminated(object string, char *buf, int n)
{ if(type_of(string) != t_string
&& type_of(string) != t_symbol)
FEerror("Need to give symbol or string",0);
if (string->st.st_fillp +1 > n)
{ buf= (void *)malloc(string->st.st_fillp +1);
}
bcopy(string->st.st_self,buf,string->st.st_fillp);
buf[string->st.st_fillp] = 0;
return buf;
}
|