-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrange.cpp
More file actions
27 lines (22 loc) · 771 Bytes
/
range.cpp
File metadata and controls
27 lines (22 loc) · 771 Bytes
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
#include "range.h"
#include "assert.h"
#include "range_iterator.h"
value range$int_(value stop) {
return range$int_$int_$int_(make$int_(0), stop, make$int_(1));
}
value range$int_$int_(value start, value stop) {
return range$int_$int_$int_(start, stop, make$int_(1));
}
value range$int_$int_$int_(value start, value stop, value step) {
assert(start.type == value::INT && stop.type == value::INT && step.type == value::INT);
if (step.intval == 0)
throw std::runtime_error("range step must not be zero");
value ret;
ret.type = value::RANGE;
ret.rangeval = new range_t{start.intval, stop.intval, step.intval};
return ret;
}
value __iter__$range(value self) {
assert(self.type == value::RANGE);
return make$range_iterator(self.rangeval);
}