Beispiel #1
0
ikptr
ikrt_directory_list(ikptr filename, ikpcb* pcb){
  DIR* dir;
  struct dirent* de;
  if((dir = opendir((char*)(filename + off_bytevector_data))) == NULL){
    return ik_errno_to_code();
  }
  ikptr ac = null_object;
  pcb->root0 = ∾
  while(1){
    errno = 0;
    de = readdir(dir);
    if(de == NULL){
      pcb->root0 = 0;
      ikptr retval = (errno ? ik_errno_to_code() : ac);
      closedir(dir);
      return retval;
    }
    int len = strlen(de->d_name);
    ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+len+1))
               + bytevector_tag;
    ref(bv, off_bytevector_length) = fix(len);
    memcpy((char*)(bv+off_bytevector_data), de->d_name, len+1);
    pcb->root1 = &bv;
    ikptr p = ik_safe_alloc(pcb, pair_size) + pair_tag;
    pcb->root1 = 0;
    ref(p, off_car) = bv;
    ref(p, off_cdr) = ac;
    ac = p;
  }
}
Beispiel #2
0
ikptr_t
ika_pointer_alloc (ikpcb_t * pcb, ikuword_t memory)
{
  ikptr_t	s_pointer = ik_safe_alloc(pcb, pointer_size) | vector_tag;
  IK_REF(s_pointer, off_pointer_tag)  = pointer_tag;
  IK_REF(s_pointer, off_pointer_data) = (ikptr_t)memory;
  return s_pointer;
}
Beispiel #3
0
ikptr 
ikrt_make_vector2(ikptr len, ikptr obj, ikpcb* pcb){
  if(is_fixnum(len) && ((len >> 31)!=0)){
    pcb->root0 = &obj;
    ikptr s = ik_safe_alloc(pcb, align(((int)len) + disp_vector_data));
    pcb->root0 = 0;
    ref(s, 0) = len;
    memset(s+disp_vector_data, 0, (int)len);
    return s+vector_tag;
  } else {
    return false_object;
Beispiel #4
0
static ikptr 
timespec_bytevector(struct timespec* s, ikpcb* pcb) {
  int len = sizeof(struct timespec);
  ikptr r = ik_safe_alloc(pcb, align(disp_bytevector_data+len+3));
  ref(r, 0) = fix(len+2);
  *((char*)(r+disp_bytevector_data+0)) = sizeof(s->tv_sec);
  *((char*)(r+disp_bytevector_data+1)) = sizeof(s->tv_nsec);
  memcpy((char*)(r+disp_bytevector_data+2), s, len);
  *((char*)(r+disp_bytevector_data+len+2)) = 0;
  return r + bytevector_tag;
}
Beispiel #5
0
ikptr 
ikrt_make_vector1(ikptr len, ikpcb* pcb){
  int intlen = (int)len;
  if(is_fixnum(len) && (intlen >= 0)){
    ikptr s = ik_safe_alloc(pcb, align(len + disp_vector_data));
    ref(s, 0) = len;
    memset((char*)(long)(s+disp_vector_data), 0, len);
    return s+vector_tag;
  } else {
    return 0;
  }
}
Beispiel #6
0
ikptr
ikrt_realpath(ikptr bv, ikpcb* pcb){
  char buff[PATH_MAX];
  char* p = realpath((char*)(bv+off_bytevector_data), buff);
  if(p == NULL){
    return ik_errno_to_code();
  }
  int n = strlen(p);
  ikptr r = ik_safe_alloc(pcb, align(disp_bytevector_data+n+1));
  ref(r, 0) = fix(n);
  memcpy((char*)(r+disp_bytevector_data), p, n+1);
  return r+bytevector_tag;
}
Beispiel #7
0
ikptr 
ikrt_getenv(ikptr bv, ikpcb* pcb){
  char* v = getenv((char*)(long)(bv + off_bytevector_data));
  if(v){
    long int n = strlen(v);
    ikptr s = ik_safe_alloc(pcb, align(n+disp_bytevector_data+1))
              + bytevector_tag;
    ref(s, -bytevector_tag) = fix(n);
    memcpy((char*)(long)(s+off_bytevector_data), v, n+1);
    return s;
  } 
  else {
    return false_object;
  }
}
Beispiel #8
0
ikptr
ikrt_readdir(ikptr ptr, ikpcb* pcb){
  DIR* d = (DIR*) ref(ptr, off_pointer_data);
  errno = 0;
  struct dirent* ent = readdir(d);
  if (ent == NULL){
    return (errno ? ik_errno_to_code() : false_object);
  }
  int len = strlen(ent->d_name);
  ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+len+1))
             + bytevector_tag;
  ref(bv, -bytevector_tag) = fix(len);
  memcpy((char*)(bv+off_bytevector_data), ent->d_name, len+1);
  return bv;
}
Beispiel #9
0
not used
ikptr 
ikrt_getsockname(ikptr s, ikpcb* pcb){
  socklen_t size = sizeof(struct sockaddr);
  ikptr bv = ik_safe_alloc(pcb, align(disp_bytevector_data+size))
             + bytevector_tag;
  int r = getsockname(unfix(s),
                     (struct sockaddr*)(bv+off_bytevector_data),
                     &size);
  if(r == 0){
    ref(bv, off_bytevector_length) = fix(size);
    return bv;
  } else {
    return ik_errno_to_code();
  }
}
Beispiel #10
0
static
ikptr
ik_sigmembers(sigset_t* s, ikpcb* pcb){
  int i;
  signal_info* p;
  ikptr accum = null_object;
  pcb->root0 = &accum;
  for(i = signal_info_table_len - 1; i >= 0; i--){
    p = &signal_info_table[i];
    if (sigismember(s, p->n)) {
      ikptr x = ik_safe_alloc(pcb, pair_size) + pair_tag;
      ref(x, off_car) = p->c;
      ref(x, off_cdr) = accum;
      accum = x;
    }
  }
  pcb->root0 = NULL;
  return accum;
}
Beispiel #11
0
ikptr
ikrt_ffi_prep_cif(ikptr rtptr, ikptr argstptr, ikpcb* pcb) {
  ffi_cif* cif = alloc(sizeof(ffi_cif), 1);
  ffi_abi abi = FFI_DEFAULT_ABI;
  int nargs = unfix(ref(argstptr, off_vector_length));
  ffi_type** argtypes = alloc(sizeof(ffi_type*), nargs+1);
  int i;
  for(i=0; i<nargs; i++){
    ikptr argt = ref(argstptr, off_vector_data + i*wordsize);
    argtypes[i] = scheme_to_ffi_type_cast(argt);
  }
  argtypes[nargs] = NULL;
  ffi_type* rtype = scheme_to_ffi_type_cast(rtptr);
  ffi_status s = ffi_prep_cif(cif, abi, nargs, rtype, argtypes);
  if (s == FFI_OK) {
    ikptr r = ik_safe_alloc(pcb, pointer_size);
    ref(r, 0) = pointer_tag;
    ref(r, wordsize) = (ikptr)cif;
    return r + vector_tag;
  } else {
    return false_object;  
  }
}