示例#1
0
lref_t lstructure_ref(lref_t st, lref_t index)
{
     if (!STRUCTUREP(st))
          vmerror_wrong_type_n(1, st);

     if (!FIXNUMP(index))
          vmerror_wrong_type_n(2, index);

     fixnum_t idx = get_c_fixnum(index);

     if ((idx >= 0) && ((size_t) idx < STRUCTURE_DIM(st)))
          return STRUCTURE_ELEM(st, idx);

     vmerror_index_out_of_bounds(index, st);

     return NIL; // unreached
}
示例#2
0
文件: io.c 项目: mschaef/vcsh
lref_t lread_binary_string(lref_t l, lref_t port)
{
     _TCHAR buf[STACK_STRBUF_LEN];

     if (!BINARY_PORTP(port))
          vmerror_wrong_type_n(2, port);

     if (!NUMBERP(l))
          vmerror_wrong_type_n(1, l);

     fixnum_t remaining_length = get_c_fixnum(l);

     if (remaining_length <= 0)
          vmerror_arg_out_of_range(l, _T(">0"));

     lref_t new_str = strcons();
     size_t total_read = 0;

     while (remaining_length > 0)
     {
          fixnum_t to_read = remaining_length;

          if (to_read > STACK_STRBUF_LEN)
               to_read = STACK_STRBUF_LEN;

          size_t actual_read = read_bytes(port, buf, (size_t)(remaining_length * sizeof(_TCHAR)));

          if (actual_read <= 0)
               break;

          string_appendd(new_str, buf, actual_read);

          remaining_length -= actual_read;
          total_read += actual_read;
     }

     if (total_read == 0)
          return lmake_eof();

     return new_str;
}
示例#3
0
lref_t lstructure_set(lref_t st, lref_t index, lref_t value)
{
     if (!STRUCTUREP(st))
          vmerror_wrong_type_n(1, st);

     if (!FIXNUMP(index))
          vmerror_wrong_type_n(2, index);

     fixnum_t idx = get_c_fixnum(index);

     if ((idx >= 0) && ((size_t) idx < STRUCTURE_DIM(st)))
     {
          SET_STRUCTURE_ELEM(st, idx, value);

          return st;
     }

     vmerror_index_out_of_bounds(index, st);

     return NIL;
}