Revision 11387, 1.3 kB
(checked in by mokehehe, 6 years ago)

スタックベースに乗せ換え

Rev  Line  

[11387]  1  //=============================================================================


 2  /// S ������/**


 3  mallloc �Ŋm�ۂ����A�h���X�͂S�̔{���Ɖ���*/


 4  //=============================================================================


 5 


 6  #include "svect.h"


 7  #include "inner.h"


 8 


 9 


 10  SExp make_vector(int size) {


 11  if (size <= 0)


 12  return nil;


 13 


 14  unsigned int n = size;


 15  SVector* p = (SVector*)salloc(sizeof(SVector) + sizeof(SExp) * (n  1), FALSE);


 16  p>type = tVect;


 17  p>size = n;


 18  for (unsigned int i=0; i<n; ++i) {


 19  p>buf[i] = nil;


 20  }


 21 


 22  SExp s;


 23  s.ptr = (SExpExtU*)p;


 24  return s;


 25  }


 26 


 27  void vector_set(SExp v, int i, SExp val) {


 28  type_check(v, tVect);


 29  SVector* p = (SVector*)v.ptr;


 30  unsigned int idx = i;


 31  if (idx < p>size) {


 32  p>buf[idx] = val;


 33  }


 34  }


 35 


 36  SExp vector_ref(SExp v, int i) {


 37  type_check(v, tVect);


 38  SVector* p = (SVector*)v.ptr;


 39  unsigned int idx = i;


 40  if (idx < p>size) {


 41  return p>buf[idx];


 42  } else {


 43  return nil;


 44  }


 45  }


 46 


 47  int vector_length(SExp v) {


 48  type_check(v, tVect);


 49  SVector* p = (SVector*)v.ptr;


 50  return p>size;


 51  }


 52 


 53 


 54  void print_vector(SExp v) {


 55  type_check(v, tVect);


 56  SVector* p = (SVector*)v.ptr;


 57 


 58  printf("#(");


 59  unsigned int n = p>size;


 60  for (unsigned int i = 0; i < n; ++i) {


 61  print_rec(p>buf[i]);


 62  }


 63  printf(")");


 64  }

