Skip to content

Commit 2e94104

Browse files
committedAug 15, 2014
language/core: add int64
1 parent 8bdc796 commit 2e94104

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 

‎artiq/language/core.py

+28
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,34 @@
22

33
from artiq.language import units
44

5+
class int64(int):
6+
pass
7+
8+
def _make_int64_op_method(int_method):
9+
def method(self, *args):
10+
r = int_method(self, *args)
11+
if isinstance(r, int):
12+
r = int64(r)
13+
return r
14+
return method
15+
16+
for _op_name in (
17+
"neg", "pos", "abs", "invert", "round",
18+
"add", "radd", "sub", "rsub", "mul", "rmul", "pow", "rpow",
19+
"lshift", "rlshift", "rshift", "rrshift",
20+
"and", "rand", "xor", "rxor", "or", "ror",
21+
"floordiv", "rfloordiv", "mod", "rmod"):
22+
method_name = "__" + _op_name + "__"
23+
orig_method = getattr(int, method_name)
24+
setattr(int64, method_name, _make_int64_op_method(orig_method))
25+
26+
for _op_name in (
27+
"add", "sub", "mul", "floordiv", "mod",
28+
"pow", "lshift", "rshift", "lshift",
29+
"and", "xor", "or"):
30+
op_method = getattr(int, "__" + _op_name + "__")
31+
setattr(int64, "__i" + _op_name + "__", _make_int64_op_method(op_method))
32+
533
def _make_kernel_ro(value):
634
return isinstance(value, (int, float, str, units.Quantity))
735

0 commit comments

Comments
 (0)
Please sign in to comment.