mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-19 00:16:29 +08:00
compiler: add support for bytes values in RPC (#714).
This commit is contained in:
parent
778e7dc2ab
commit
66a683f583
@ -1168,6 +1168,8 @@ class LLVMIRGenerator:
|
|||||||
return b"f"
|
return b"f"
|
||||||
elif builtins.is_str(typ):
|
elif builtins.is_str(typ):
|
||||||
return b"s"
|
return b"s"
|
||||||
|
elif builtins.is_bytes(typ):
|
||||||
|
return b"B"
|
||||||
elif builtins.is_list(typ):
|
elif builtins.is_list(typ):
|
||||||
return b"l" + self._rpc_tag(builtins.get_iterable_elt(typ),
|
return b"l" + self._rpc_tag(builtins.get_iterable_elt(typ),
|
||||||
error_handler)
|
error_handler)
|
||||||
|
@ -369,6 +369,8 @@ class CommKernel:
|
|||||||
return Fraction(numerator, denominator)
|
return Fraction(numerator, denominator)
|
||||||
elif tag == "s":
|
elif tag == "s":
|
||||||
return self._read_string()
|
return self._read_string()
|
||||||
|
elif tag == "B":
|
||||||
|
return self._read_bytes()
|
||||||
elif tag == "l":
|
elif tag == "l":
|
||||||
length = self._read_int32()
|
length = self._read_int32()
|
||||||
return [self._receive_rpc_value(embedding_map) for _ in range(length)]
|
return [self._receive_rpc_value(embedding_map) for _ in range(length)]
|
||||||
@ -461,6 +463,10 @@ class CommKernel:
|
|||||||
check(isinstance(value, str) and "\x00" not in value,
|
check(isinstance(value, str) and "\x00" not in value,
|
||||||
lambda: "str")
|
lambda: "str")
|
||||||
self._write_string(value)
|
self._write_string(value)
|
||||||
|
elif tag == "B":
|
||||||
|
check(isinstance(value, bytes),
|
||||||
|
lambda: "bytes")
|
||||||
|
self._write_bytes(value)
|
||||||
elif tag == "l":
|
elif tag == "l":
|
||||||
check(isinstance(value, list),
|
check(isinstance(value, list),
|
||||||
lambda: "list")
|
lambda: "list")
|
||||||
|
@ -28,7 +28,7 @@ unsafe fn recv_value(reader: &mut Read, tag: Tag, data: &mut *mut (),
|
|||||||
consume_value!(u64, |ptr| {
|
consume_value!(u64, |ptr| {
|
||||||
*ptr = reader.read_u64()?; Ok(())
|
*ptr = reader.read_u64()?; Ok(())
|
||||||
}),
|
}),
|
||||||
Tag::String => {
|
Tag::String | Tag::Bytes => {
|
||||||
consume_value!(CMutSlice<u8>, |ptr| {
|
consume_value!(CMutSlice<u8>, |ptr| {
|
||||||
let length = reader.read_u32()? as usize;
|
let length = reader.read_u32()? as usize;
|
||||||
*ptr = CMutSlice::new(alloc(length)? as *mut u8, length);
|
*ptr = CMutSlice::new(alloc(length)? as *mut u8, length);
|
||||||
@ -108,6 +108,9 @@ unsafe fn send_value(writer: &mut Write, tag: Tag, data: &mut *const ()) -> io::
|
|||||||
Tag::String =>
|
Tag::String =>
|
||||||
consume_value!(CSlice<u8>, |ptr|
|
consume_value!(CSlice<u8>, |ptr|
|
||||||
writer.write_string(str::from_utf8((*ptr).as_ref()).unwrap())),
|
writer.write_string(str::from_utf8((*ptr).as_ref()).unwrap())),
|
||||||
|
Tag::Bytes =>
|
||||||
|
consume_value!(CSlice<u8>, |ptr|
|
||||||
|
writer.write_bytes((*ptr).as_ref())),
|
||||||
Tag::Tuple(it, arity) => {
|
Tag::Tuple(it, arity) => {
|
||||||
let mut it = it.clone();
|
let mut it = it.clone();
|
||||||
writer.write_u8(arity)?;
|
writer.write_u8(arity)?;
|
||||||
@ -202,6 +205,7 @@ mod tag {
|
|||||||
Int64,
|
Int64,
|
||||||
Float64,
|
Float64,
|
||||||
String,
|
String,
|
||||||
|
Bytes,
|
||||||
Tuple(TagIterator<'a>, u8),
|
Tuple(TagIterator<'a>, u8),
|
||||||
List(TagIterator<'a>),
|
List(TagIterator<'a>),
|
||||||
Array(TagIterator<'a>),
|
Array(TagIterator<'a>),
|
||||||
@ -219,6 +223,7 @@ mod tag {
|
|||||||
Tag::Int64 => b'I',
|
Tag::Int64 => b'I',
|
||||||
Tag::Float64 => b'f',
|
Tag::Float64 => b'f',
|
||||||
Tag::String => b's',
|
Tag::String => b's',
|
||||||
|
Tag::Bytes => b'B',
|
||||||
Tag::Tuple(_, _) => b't',
|
Tag::Tuple(_, _) => b't',
|
||||||
Tag::List(_) => b'l',
|
Tag::List(_) => b'l',
|
||||||
Tag::Array(_) => b'a',
|
Tag::Array(_) => b'a',
|
||||||
@ -236,6 +241,7 @@ mod tag {
|
|||||||
Tag::Int64 => 8,
|
Tag::Int64 => 8,
|
||||||
Tag::Float64 => 8,
|
Tag::Float64 => 8,
|
||||||
Tag::String => 4,
|
Tag::String => 4,
|
||||||
|
Tag::Bytes => 4,
|
||||||
Tag::Tuple(it, arity) => {
|
Tag::Tuple(it, arity) => {
|
||||||
let mut size = 0;
|
let mut size = 0;
|
||||||
for _ in 0..arity {
|
for _ in 0..arity {
|
||||||
@ -280,6 +286,7 @@ mod tag {
|
|||||||
b'I' => Tag::Int64,
|
b'I' => Tag::Int64,
|
||||||
b'f' => Tag::Float64,
|
b'f' => Tag::Float64,
|
||||||
b's' => Tag::String,
|
b's' => Tag::String,
|
||||||
|
b'B' => Tag::Bytes,
|
||||||
b't' => {
|
b't' => {
|
||||||
let count = self.data[0];
|
let count = self.data[0];
|
||||||
self.data = &self.data[1..];
|
self.data = &self.data[1..];
|
||||||
@ -327,6 +334,8 @@ mod tag {
|
|||||||
write!(f, "Float64")?,
|
write!(f, "Float64")?,
|
||||||
Tag::String =>
|
Tag::String =>
|
||||||
write!(f, "String")?,
|
write!(f, "String")?,
|
||||||
|
Tag::Bytes =>
|
||||||
|
write!(f, "Bytes")?,
|
||||||
Tag::Tuple(it, _) => {
|
Tag::Tuple(it, _) => {
|
||||||
write!(f, "Tuple(")?;
|
write!(f, "Tuple(")?;
|
||||||
it.fmt(f)?;
|
it.fmt(f)?;
|
||||||
|
@ -38,6 +38,9 @@ class RoundtripTest(ExperimentCase):
|
|||||||
def test_str(self):
|
def test_str(self):
|
||||||
self.assertRoundtrip("foo")
|
self.assertRoundtrip("foo")
|
||||||
|
|
||||||
|
def test_bytes(self):
|
||||||
|
self.assertRoundtrip(b"foo")
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
self.assertRoundtrip([10])
|
self.assertRoundtrip([10])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user