Fix type reification of PRNG.
This commit is contained in:
@@ -420,9 +420,13 @@ pub type TypedDataType = DataType<Rc<Type>>;
|
||||
|
||||
impl TypedDataType {
|
||||
pub fn known_enum(name: &str, constructors: &[&str]) -> Self {
|
||||
Self::known_data_type(name, &RecordConstructor::known_enum(constructors))
|
||||
}
|
||||
|
||||
pub fn known_data_type(name: &str, constructors: &[RecordConstructor<Rc<Type>>]) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
constructors: RecordConstructor::known_enum(constructors),
|
||||
constructors: constructors.to_vec(),
|
||||
location: Span::empty(),
|
||||
opaque: false,
|
||||
public: true,
|
||||
@@ -946,7 +950,10 @@ pub struct RecordConstructor<T> {
|
||||
pub sugar: bool,
|
||||
}
|
||||
|
||||
impl<A> RecordConstructor<A> {
|
||||
impl<A> RecordConstructor<A>
|
||||
where
|
||||
A: Clone,
|
||||
{
|
||||
pub fn put_doc(&mut self, new_doc: String) {
|
||||
self.doc = Some(new_doc);
|
||||
}
|
||||
@@ -963,6 +970,16 @@ impl<A> RecordConstructor<A> {
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn known_record(name: &str, args: &[RecordConstructorArg<A>]) -> Self {
|
||||
RecordConstructor {
|
||||
location: Span::empty(),
|
||||
name: name.to_string(),
|
||||
arguments: args.to_vec(),
|
||||
doc: None,
|
||||
sugar: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
|
||||
|
||||
@@ -1588,7 +1588,35 @@ impl TypedDataType {
|
||||
}
|
||||
|
||||
pub fn prng() -> Self {
|
||||
DataType::known_enum(well_known::PRNG, well_known::PRNG_CONSTRUCTORS)
|
||||
let bytearray_arg = |label: &str| RecordConstructorArg {
|
||||
label: Some(label.to_string()),
|
||||
doc: None,
|
||||
annotation: Annotation::bytearray(Span::empty()),
|
||||
location: Span::empty(),
|
||||
tipo: Type::byte_array(),
|
||||
};
|
||||
|
||||
let int_arg = |label: &str| RecordConstructorArg {
|
||||
label: Some(label.to_string()),
|
||||
doc: None,
|
||||
annotation: Annotation::int(Span::empty()),
|
||||
location: Span::empty(),
|
||||
tipo: Type::int(),
|
||||
};
|
||||
|
||||
DataType::known_data_type(
|
||||
well_known::PRNG,
|
||||
&[
|
||||
RecordConstructor::known_record(
|
||||
well_known::PRNG_CONSTRUCTORS[0],
|
||||
&[bytearray_arg("seed"), bytearray_arg("choices")],
|
||||
),
|
||||
RecordConstructor::known_record(
|
||||
well_known::PRNG_CONSTRUCTORS[1],
|
||||
&[int_arg("cursor"), bytearray_arg("choices")],
|
||||
),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn ordering() -> Self {
|
||||
|
||||
Reference in New Issue
Block a user