source: to-imperative/trunk/library/Vector/subvector.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: 938 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(Subvector);
13
14RF_FUNC (Subvector, (RF_ARG _vector, _index, _length), (RF_RES _result))
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* t = _index.get_first();
22    rftype::Int32* p = t->cast_to<rftype::Int32>(type_int32);
23    if (!p)
24      RF_LIB_ERROR("Invalid argument"); 
25    size_t ind = p->to_int();
26    t = _length.get_first();
27    p = t->cast_to<rftype::Int32>(type_int32);
28    if (!p)
29      RF_LIB_ERROR("Invalid argument");
30    size_t len = p->to_int();   
31    if (ind + len > v->get_length())
32      RF_LIB_ERROR("Index out of range");
33    _result = Expr (new rftype::Vector(*v, ind, len));
34  } else
35      RF_LIB_ERROR("Invalid argument");
36
37RF_END
38
39}
40}
Note: See TracBrowser for help on using the repository browser.