source: to-imperative/trunk/library/Vector/vector_ref.cc @ 1114

Last change on this file since 1114 was 1114, checked in by luba, 17 years ago
  • type_short_int is replaced by type_int32
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 778 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_Ref);
13
14RF_FUNC (Vector_m_Ref, (RF_ARG _vector, _index), (RF_RES _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::Int32* number = p_index->cast_to<rftype::Int32>(type_int32);
23    if (!number)
24      RF_LIB_ERROR("Invalid argument"); 
25    else { 
26      size_t n = number->to_int();
27      if (n > v->get_length())
28        RF_LIB_ERROR("Index out of range");
29      _exp = (*v)[n];
30    }
31  } else
32      RF_LIB_ERROR("Invalid argument");
33
34RF_END
35
36}
37}
Note: See TracBrowser for help on using the repository browser.