forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharguments.cpp
90 lines (66 loc) · 2.05 KB
/
arguments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "arguments.hpp"
#include "builtin/array.hpp"
namespace rubinius {
void Arguments::append(STATE, Array* ary) {
Tuple* tup = Tuple::create(state, ary->size() + total());
for(uint32_t i = 0; i < total(); i++) {
tup->put(state, i, get_argument(i));
}
for(uint32_t i = 0, n = total(); i < ary->size(); i++, n++) {
tup->put(state, n, ary->get(state, i));
}
use_tuple(tup, total() + ary->size());
}
void Arguments::prepend(STATE, Array* ary) {
Tuple* tup = Tuple::create(state, ary->size() + total());
for(uint32_t i = 0; i < ary->size(); i++) {
tup->put(state, i, ary->get(state, i));
}
for(uint32_t i = 0, n = ary->size(); i < total(); i++, n++) {
tup->put(state, n, get_argument(i));
}
use_tuple(tup, total() + ary->size());
}
Array* Arguments::as_array(STATE) {
Array* ary = Array::create(state, total());
for(uint32_t i = 0; i < total(); i++) {
ary->set(state, i, get_argument(i));
}
return ary;
}
void Arguments::unshift(STATE, Object* val) {
Tuple* tup = Tuple::create(state, total() + 1);
tup->put(state, 0, val);
for(uint32_t i = 0; i < total(); i++) {
tup->put(state, i + 1, get_argument(i));
}
use_tuple(tup, total() + 1);
}
void Arguments::unshift2(STATE, Object* one, Object* two) {
Tuple* tup = Tuple::create(state, total() + 2);
tup->put(state, 0, one);
tup->put(state, 1, two);
for(uint32_t i = 0; i < total(); i++) {
tup->put(state, i + 2, get_argument(i));
}
use_tuple(tup, total() + 2);
}
Object* Arguments::shift(STATE) {
Object* first = arguments_[0];
if(argument_container_) {
Tuple* tup = Tuple::create(state, total() - 1);
for(uint32_t i = 1; i < total_; i++) {
tup->put(state, i - 1, get_argument(i));
}
use_tuple(tup, total_ - 1);
} else {
total_--;
arguments_++;
}
return first;
}
void Arguments::update_argument_container(Tuple* tup) {
arguments_ = tup->field;
argument_container_ = tup;
}
}