From 2e9410464d200ec6ce2319da3b065cdc0da57cbf Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 15 Aug 2014 23:43:59 +0800 Subject: [PATCH] language/core: add int64 --- artiq/language/core.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/artiq/language/core.py b/artiq/language/core.py index 0ac2f0d4f..16a404df2 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -2,6 +2,34 @@ from collections import namedtuple from artiq.language import units +class int64(int): + pass + +def _make_int64_op_method(int_method): + def method(self, *args): + r = int_method(self, *args) + if isinstance(r, int): + r = int64(r) + return r + return method + +for _op_name in ( + "neg", "pos", "abs", "invert", "round", + "add", "radd", "sub", "rsub", "mul", "rmul", "pow", "rpow", + "lshift", "rlshift", "rshift", "rrshift", + "and", "rand", "xor", "rxor", "or", "ror", + "floordiv", "rfloordiv", "mod", "rmod"): + method_name = "__" + _op_name + "__" + orig_method = getattr(int, method_name) + setattr(int64, method_name, _make_int64_op_method(orig_method)) + +for _op_name in ( + "add", "sub", "mul", "floordiv", "mod", + "pow", "lshift", "rshift", "lshift", + "and", "xor", "or"): + op_method = getattr(int, "__" + _op_name + "__") + setattr(int64, "__i" + _op_name + "__", _make_int64_op_method(op_method)) + def _make_kernel_ro(value): return isinstance(value, (int, float, str, units.Quantity))