Frontend AST for Podlang (#432)
* Basic frontend AST and semantic validation * Intro statement support * Simplify validator lifetime * Fix arity validation * Lowering and splitting * Remove legacy processor and use frontend AST by default * Use builders instead of creating middleware types directly * Typos/formatting * Improve error messages when overflowing a batch due to splitting * Add FromStr implementation for NativePredicate * Remove 'raw' fields, and switch HashHex representation to byte vector rather than string * Simpler wrapper types for batch and intro predicate hashes * Parse secret and public keys to their respective data structures earlier * More detail around string escape validity * Simplify native predicate arity handling and move method to NativePredicate impl * Store hashes using middleware::Hash, and simplify lowering by using pre-parsed values * Simplify predicate building * Formatting * Better error messages/suggestions for cases where predicate splitting fails * Formatting * Clippy fix * Return error if we get a too-large int
This commit is contained in:
parent
c382bf487c
commit
42f979c408
11 changed files with 4250 additions and 1431 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
fmt::{self, Display},
|
||||
iter,
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
use plonky2::field::types::Field;
|
||||
|
|
@ -51,6 +52,42 @@ pub enum NativePredicate {
|
|||
ArrayUpdate = 1014,
|
||||
}
|
||||
|
||||
impl NativePredicate {
|
||||
pub fn arity(&self) -> usize {
|
||||
match self {
|
||||
NativePredicate::None | NativePredicate::False => 0,
|
||||
NativePredicate::Equal
|
||||
| NativePredicate::NotEqual
|
||||
| NativePredicate::Lt
|
||||
| NativePredicate::Gt
|
||||
| NativePredicate::GtEq
|
||||
| NativePredicate::LtEq
|
||||
| NativePredicate::NotContains
|
||||
| NativePredicate::SetNotContains
|
||||
| NativePredicate::DictNotContains
|
||||
| NativePredicate::PublicKeyOf
|
||||
| NativePredicate::SignedBy
|
||||
| NativePredicate::SetContains => 2,
|
||||
NativePredicate::Contains
|
||||
| NativePredicate::DictContains
|
||||
| NativePredicate::ArrayContains
|
||||
| NativePredicate::SumOf
|
||||
| NativePredicate::ProductOf
|
||||
| NativePredicate::MaxOf
|
||||
| NativePredicate::HashOf
|
||||
| NativePredicate::SetInsert
|
||||
| NativePredicate::SetDelete => 3,
|
||||
NativePredicate::DictInsert
|
||||
| NativePredicate::DictUpdate
|
||||
| NativePredicate::DictDelete
|
||||
| NativePredicate::ArrayUpdate
|
||||
| NativePredicate::ContainerInsert
|
||||
| NativePredicate::ContainerUpdate
|
||||
| NativePredicate::ContainerDelete => 4,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for NativePredicate {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let s = match self {
|
||||
|
|
@ -95,6 +132,45 @@ impl ToFields for NativePredicate {
|
|||
}
|
||||
}
|
||||
|
||||
impl FromStr for NativePredicate {
|
||||
type Err = Error;
|
||||
fn from_str(s: &str) -> Result<Self> {
|
||||
match s {
|
||||
"Equal" => Ok(NativePredicate::Equal),
|
||||
"NotEqual" => Ok(NativePredicate::NotEqual),
|
||||
"Gt" => Ok(NativePredicate::Gt),
|
||||
"GtEq" => Ok(NativePredicate::GtEq),
|
||||
"Lt" => Ok(NativePredicate::Lt),
|
||||
"LtEq" => Ok(NativePredicate::LtEq),
|
||||
"Contains" => Ok(NativePredicate::Contains),
|
||||
"NotContains" => Ok(NativePredicate::NotContains),
|
||||
"SumOf" => Ok(NativePredicate::SumOf),
|
||||
"ProductOf" => Ok(NativePredicate::ProductOf),
|
||||
"MaxOf" => Ok(NativePredicate::MaxOf),
|
||||
"HashOf" => Ok(NativePredicate::HashOf),
|
||||
"PublicKeyOf" => Ok(NativePredicate::PublicKeyOf),
|
||||
"SignedBy" => Ok(NativePredicate::SignedBy),
|
||||
"ContainerInsert" => Ok(NativePredicate::ContainerInsert),
|
||||
"ContainerUpdate" => Ok(NativePredicate::ContainerUpdate),
|
||||
"ContainerDelete" => Ok(NativePredicate::ContainerDelete),
|
||||
"DictContains" => Ok(NativePredicate::DictContains),
|
||||
"DictNotContains" => Ok(NativePredicate::DictNotContains),
|
||||
"ArrayContains" => Ok(NativePredicate::ArrayContains),
|
||||
"SetContains" => Ok(NativePredicate::SetContains),
|
||||
"SetNotContains" => Ok(NativePredicate::SetNotContains),
|
||||
"DictInsert" => Ok(NativePredicate::DictInsert),
|
||||
"DictUpdate" => Ok(NativePredicate::DictUpdate),
|
||||
"DictDelete" => Ok(NativePredicate::DictDelete),
|
||||
"SetInsert" => Ok(NativePredicate::SetInsert),
|
||||
"SetDelete" => Ok(NativePredicate::SetDelete),
|
||||
"ArrayUpdate" => Ok(NativePredicate::ArrayUpdate),
|
||||
"None" => Ok(NativePredicate::None),
|
||||
"False" => Ok(NativePredicate::False),
|
||||
_ => Err(Error::custom(format!("Invalid native predicate: {}", s))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct IntroPredicateRef {
|
||||
pub name: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue