forked from skulpt/skulpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseqtype.js
133 lines (100 loc) · 3.01 KB
/
seqtype.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/**
* @constructor
* Sk.builtin.seqtype
*
* @description
* Abstract class for Python sequence types.
*
* @extends {Sk.builtin.object}
*
* @return {undefined} Cannot instantiate a Sk.builtin.seqtype object
*/
Sk.builtin.seqtype = function () {
throw new Sk.builtin.ExternalError("Cannot instantiate abstract Sk.builtin.seqtype class");
};
Sk.abstr.setUpInheritance("SequenceType", Sk.builtin.seqtype, Sk.builtin.object);
Sk.builtin.seqtype.sk$abstract = true;
/**
* Python wrapper of `__len__` method.
*
* @name __len__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__len__"] = new Sk.builtin.func(function (self) {
Sk.builtin.pyCheckArgsLen("__len__", arguments.length, 0, 0, false, true);
return new Sk.builtin.int_(self.sq$length());
});
/**
* Python wrapper of `__iter__` method.
*
* @name __iter__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__iter__"] = new Sk.builtin.func(function (self) {
Sk.builtin.pyCheckArgsLen("__iter__", arguments.length, 0, 0, false, true);
return self.tp$iter();
});
/**
* Python wrapper of `__contains__` method.
*
* @name __contains__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__contains__"] = new Sk.builtin.func(function (self, item) {
Sk.builtin.pyCheckArgsLen("__contains__", arguments.length, 1, 1, false, true);
if (self.sq$contains(item)) {
return Sk.builtin.bool.true$;
} else {
return Sk.builtin.bool.false$;
}
});
/**
* Python wrapper of `__getitem__` method.
*
* @name __getitem__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__getitem__"] = new Sk.builtin.func(function (self, key) {
Sk.builtin.pyCheckArgsLen("__getitem__", arguments.length, 1, 1, false, true);
return self.mp$subscript(key);
});
/**
* Python wrapper of `__add__` method.
*
* @name __add__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__add__"] = new Sk.builtin.func(function (self, other) {
Sk.builtin.pyCheckArgsLen("__add__", arguments.length, 1, 1, false, true);
return self.sq$concat(other);
});
/**
* Python wrapper of `__mul__` method.
*
* @name __mul__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__mul__"] = new Sk.builtin.func(function (self, n) {
Sk.builtin.pyCheckArgsLen("__mul__", arguments.length, 1, 1, false, true);
if (!Sk.misceval.isIndex(n)) {
throw new Sk.builtin.TypeError("can't multiply sequence by non-int of type '" + Sk.abstr.typeName(n) + "'");
}
return self.sq$repeat(n);
});
/**
* Python wrapper of `__rmul__` method.
*
* @name __rmul__
* @instance
* @memberOf Sk.builtin.seqtype.prototype
*/
Sk.builtin.seqtype.prototype["__rmul__"] = new Sk.builtin.func(function (self, n) {
Sk.builtin.pyCheckArgsLen("__rmul__", arguments.length, 1, 1, false, true);
return self.sq$repeat(n);
});