source: to-imperative/trunk/library/Vector/vector_set.cc @ 1045

Last change on this file since 1045 was 1045, checked in by sveta, 18 years ago
  • Methods for Vector are added.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 801 bytes
Line 
1#include <rf_core.hh>
2#include <rf_types.hh>
3
4using namespace rfrt;
5
6namespace refal
7{
8
9namespace Vector
10{
11
12RF_DECL(Vector_m_Set);
13
14RF_FUNC (Vector_m_Set, (RF_ARG _vector, _index, _exp), ())
15
16  if (_vector.get_len() == 1) {
17    Term* p_vector = _vector.get_first();
18    rftype::Vector* v = p_vector->cast_to<rftype::Vector>(type_vector);
19    if (!v)
20      RF_LIB_ERROR("Invalid argument");
21    Term* p_index = _index.get_first();
22    rftype::ShortInt* numb = p_index->cast_to<rftype::ShortInt>(type_short_int);
23    if (!numb)
24      RF_LIB_ERROR("Invalid argument"); 
25    else {
26      size_t index = numb->to_int();
27      if (index < v->get_length())
28        (*v)[index] = _exp;
29      else
30        RF_LIB_ERROR("Index out of range");
31    }
32  } else
33      RF_LIB_ERROR("Invalid argument");
34
35RF_END
36
37}
38}
Note: See TracBrowser for help on using the repository browser.