mirror of
https://github.com/AleoHQ/leo.git
synced 2025-01-03 07:16:50 +03:00
char eq operators in, they just call the field ones for now, so when those are in they will work
This commit is contained in:
parent
1377fc5d75
commit
08022bb383
@ -39,6 +39,10 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
let unique_namespace = cs.ns(|| namespace_string);
|
||||
bool_1.evaluate_equal(unique_namespace, &bool_2)
|
||||
}
|
||||
(ConstrainedValue::Char(char_1), ConstrainedValue::Char(char_2)) => {
|
||||
let unique_namespace = cs.ns(|| namespace_string);
|
||||
char_1.evaluate_equal(unique_namespace, &char_2)
|
||||
}
|
||||
(ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => {
|
||||
let unique_namespace = cs.ns(|| namespace_string);
|
||||
num_1.evaluate_equal(unique_namespace, &num_2)
|
||||
|
@ -23,10 +23,18 @@ use crate::{
|
||||
|
||||
use leo_ast::{InputValue, Span};
|
||||
use snarkvm_fields::PrimeField;
|
||||
use snarkvm_r1cs::ConstraintSystem;
|
||||
use snarkvm_gadgets::{
|
||||
fields::FpGadget,
|
||||
utilities::{
|
||||
boolean::Boolean,
|
||||
eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget},
|
||||
select::CondSelectGadget,
|
||||
},
|
||||
};
|
||||
use snarkvm_r1cs::{ConstraintSystem, SynthesisError};
|
||||
|
||||
/// A char
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Char<F: PrimeField> {
|
||||
pub character: char,
|
||||
pub field: FieldType<F>,
|
||||
@ -41,6 +49,43 @@ impl<F: PrimeField> Char<F> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> PartialEq for Char<F> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.field.eq(&other.field)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> Eq for Char<F> {}
|
||||
|
||||
impl<F: PrimeField> PartialOrd for Char<F> {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.field.partial_cmp(&other.field)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> EvaluateEqGadget<F> for Char<F> {
|
||||
fn evaluate_equal<CS: ConstraintSystem<F>>(&self, cs: CS, other: &Self) -> Result<Boolean, SynthesisError> {
|
||||
self.field.evaluate_equal(cs, &other.field)
|
||||
}
|
||||
}
|
||||
|
||||
impl<F: PrimeField> EqGadget<F> for Char<F> {}
|
||||
|
||||
impl<F: PrimeField> ConditionalEqGadget<F> for Char<F> {
|
||||
fn conditional_enforce_equal<CS: ConstraintSystem<F>>(
|
||||
&self,
|
||||
cs: CS,
|
||||
other: &Self,
|
||||
condition: &Boolean,
|
||||
) -> Result<(), SynthesisError> {
|
||||
self.field.conditional_enforce_equal(cs, &other.field, condition)
|
||||
}
|
||||
|
||||
fn cost() -> usize {
|
||||
2 * <FpGadget<F> as CondSelectGadget<F>>::cost()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn char_from_input<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
cs: &mut CS,
|
||||
name: &str,
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
expectation: Pass
|
||||
input_file:
|
||||
- inputs/ascii.in
|
||||
- inputs/escaped_unicode.in
|
||||
@ -15,5 +15,7 @@ circuit Foo {
|
||||
|
||||
function main(character: char) -> char {
|
||||
let f = Foo { character };
|
||||
return f.character;
|
||||
|
||||
let character = f.character == 'a' ? 'a' : 'Z';
|
||||
return character;
|
||||
}
|
Loading…
Reference in New Issue
Block a user