Changeset 1045


Ignore:
Timestamp:
Jul 19, 2003, 5:24:32 PM (17 years ago)
Author:
sveta
Message:
  • Methods for Vector are added.
Location:
to-imperative/trunk
Files:
4 added
4 edited

Legend:

Unmodified
Added
Removed
  • to-imperative/trunk/library/Vector/Makefile

    r1043 r1045  
    1111  vector_fill \
    1212  vector_length \
    13   vector_ref
     13  vector_ref \
     14  vector_set \
     15  vector_replace \
     16  subvector \
     17  subvector_fill
    1418 
    1519SOURCES = $(addsuffix .cc, $(MODULES))
  • to-imperative/trunk/library/Vector/vector.cc

    r1040 r1045  
    1414RF_FUNC (Vector, (RF_ARG _source), (RF_RES _vector))
    1515
    16   Term* p = _source.get_first();
    17   Term* q = _source.get_last();
    18   size_t length = 0;
    19   for ( ; p<q; p++) {
    20     if (p->is_ref())
    21       length++;
    22     else {
    23       rftype::Vector* v = p->cast_to<rftype::Vector>(type_vector);
    24       if (!v)
    25         RF_LIB_ERROR("Invalid argument");
    26       else
    27         length += v->get_length();
    28     }
    29   }
    30   _vector = Expr (new rftype::Vector(_source, length));
     16  Expr expr;
     17  vector_meaning(_source, expr);
     18  _vector = Expr (new rftype::Vector(expr, expr.get_len()));
    3119
    3220RF_END
  • to-imperative/trunk/runtime/rf_vector.hh

    r1040 r1045  
    2424  inline Vector (size_t _length, Expr const& _fill) ;
    2525  inline Vector (Expr const& _expr, size_t _length) ;
     26  inline Vector (Vector const& _vector, size_t _index, size_t _length);
    2627
    2728  inline unsigned get_type () const ;
     
    3334  inline void vector_init (size_t _length, Expr const& _fill);
    3435  inline void vector_fill (Expr const& _fill);
     36  inline void vector_replace (size_t _length, Expr const& exp);
     37  inline void subvector_fill (size_t _index, size_t _length, Expr const& _fill);
     38};
    3539
    36 };
     40  inline void vector_meaning (Expr const& _exp, Expr& _result);
    3741
    3842}
  • to-imperative/trunk/runtime/rf_vector.ih

    r1040 r1045  
    77#include "pxx_vector.ih"
    88#include <typeinfo>
    9 
    10 // using namespace rfrt;
    119
    1210namespace rftype
     
    3836      self[index++] = (Expr(p))();
    3937    } else {
    40       Vector* v = p->cast_to<Vector>(type_vector);
    41 //      if (!v)
    42 //        FATAL("Invalid argument");               //  RF_LIB_ERROR - ??????
    43       for (size_t i = 0; i < v->get_length(); i++) {
    44         self[index++] = (*v)[i];
    45       }
     38      FATAL("Invalid argument");               //  RF_LIB_ERROR - ??????
    4639    }
    4740  }
    4841}
     42
     43inline Vector::Vector(Vector const& _vector, size_t _index, size_t _length) :
     44  Object(),
     45  pxx::Vector<Expr> (_length)
     46{
     47  for (size_t i = 0; i < _length; i++)
     48    self[i] = _vector[_index + i];
     49}
     50
    4951
    5052inline unsigned Vector::get_type () const
     
    8688  size_t n = get_length();
    8789  if (n < _length) 
    88       expand (_length-n);
     90      expand (_length - n);
    8991  else
    9092    if (n > _length) {
    91       decrease(n-_length);
     93      decrease(n - _length);
    9294      n = _length;
    9395    }
     
    9698}
    9799
     100inline void Vector::vector_replace (size_t _length, Expr const& _exp)
     101{
     102  size_t n = get_length();
     103  if (n < _length)
     104    expand (_length - n);
     105  else
     106    if (n > _length)
     107      decrease(n - _length);
     108  Term* p = _exp.get_first();
     109  Term* q = _exp.get_last();
     110  n = 0;
     111  for ( ; p < q ; p++) {
     112    if (p->is_ref()) {
     113      self[n++] = (Expr(p))();
     114    } else {
     115      FATAL("Invalid argument");     
     116    }
     117  }
     118}   
     119
     120inline void  vector_meaning (Expr const& _exp, Expr& _result)
     121{
     122  Term* p = _exp.get_first();
     123  Term* q = _exp.get_last();
     124  for ( ; p < q; p++) {
     125    if (p->is_ref()) {
     126      _result = _result + (Expr(p))();
     127    } else {
     128      Vector* v = p->cast_to<Vector> (type_vector);
     129      if (!v)
     130        FATAL ("Invalid argument");
     131      for (size_t i = 0; i < v->get_length(); i++)
     132        _result = _result + (*v)[i];
     133    }
     134  }
     135}     
     136 
    98137inline void Vector::vector_fill (Expr const& _fill)
    99138{
     
    102141}
    103142
     143inline void Vector::subvector_fill (size_t _index, size_t _length, Expr const& _fill)
     144{
     145  for (size_t i = 0; i < _length; i++)
     146    self[_index + i] = _fill();
     147}
     148
    104149}
    105150
Note: See TracChangeset for help on using the changeset viewer.