forked from M-Labs/artiq
pyon: support slices
This commit is contained in:
parent
46b75dba8d
commit
e56c50a8a0
|
@ -39,6 +39,7 @@ _encode_map = {
|
||||||
list: "list",
|
list: "list",
|
||||||
set: "set",
|
set: "set",
|
||||||
dict: "dict",
|
dict: "dict",
|
||||||
|
slice: "slice",
|
||||||
wrapping_int: "number",
|
wrapping_int: "number",
|
||||||
Fraction: "fraction",
|
Fraction: "fraction",
|
||||||
OrderedDict: "ordereddict",
|
OrderedDict: "ordereddict",
|
||||||
|
@ -127,6 +128,9 @@ class _Encoder:
|
||||||
r += "}"
|
r += "}"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def encode_slice(self, x):
|
||||||
|
return repr(x)
|
||||||
|
|
||||||
def encode_fraction(self, x):
|
def encode_fraction(self, x):
|
||||||
return "Fraction({}, {})".format(self.encode(x.numerator),
|
return "Fraction({}, {})".format(self.encode(x.numerator),
|
||||||
self.encode(x.denominator))
|
self.encode(x.denominator))
|
||||||
|
@ -178,6 +182,7 @@ _eval_dict = {
|
||||||
"null": None,
|
"null": None,
|
||||||
"false": False,
|
"false": False,
|
||||||
"true": True,
|
"true": True,
|
||||||
|
"slice": slice,
|
||||||
|
|
||||||
"int": wrapping_int,
|
"int": wrapping_int,
|
||||||
"Fraction": Fraction,
|
"Fraction": Fraction,
|
||||||
|
|
|
@ -9,6 +9,7 @@ from artiq.protocols import pyon
|
||||||
|
|
||||||
_pyon_test_object = {
|
_pyon_test_object = {
|
||||||
(1, 2): [(3, 4.2), (2, )],
|
(1, 2): [(3, 4.2), (2, )],
|
||||||
|
"slice": slice(3),
|
||||||
Fraction(3, 4): np.linspace(5, 10, 1),
|
Fraction(3, 4): np.linspace(5, 10, 1),
|
||||||
"set": {"testing", "sets"},
|
"set": {"testing", "sets"},
|
||||||
"a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5),
|
"a": np.int8(9), "b": np.int16(-98), "c": np.int32(42), "d": np.int64(-5),
|
||||||
|
|
|
@ -18,6 +18,7 @@ def write_test_data(test_dict):
|
||||||
test_dict[key] = value
|
test_dict[key] = value
|
||||||
test_dict[1.5] = 1.5
|
test_dict[1.5] = 1.5
|
||||||
test_dict["list"] = []
|
test_dict["list"] = []
|
||||||
|
test_dict["list"][:] = [34, 31]
|
||||||
test_dict["list"].append(42)
|
test_dict["list"].append(42)
|
||||||
test_dict["list"].insert(1, 1)
|
test_dict["list"].insert(1, 1)
|
||||||
test_dict[100] = 0
|
test_dict[100] = 0
|
||||||
|
|
Loading…
Reference in New Issue