mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 03:04:13 +03:00
Support method calls for group coordinates
This commit is contained in:
parent
4bbdf63da9
commit
8062693f3d
@ -36,6 +36,10 @@ pub enum UnaryOperation {
|
|||||||
Square,
|
Square,
|
||||||
/// Square root operation, i.e. `.sqrt()`.
|
/// Square root operation, i.e. `.sqrt()`.
|
||||||
SquareRoot,
|
SquareRoot,
|
||||||
|
/// Converts a group element to its x-coordinate, i.e. `.to_x_coordinate()`.
|
||||||
|
ToXCoordinate,
|
||||||
|
/// Converts a group element to its y-coordinate, i.e. `.to_y_coordinate()`.
|
||||||
|
ToYCoordinate,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UnaryOperation {
|
impl UnaryOperation {
|
||||||
@ -50,6 +54,8 @@ impl UnaryOperation {
|
|||||||
sym::not => Self::Not,
|
sym::not => Self::Not,
|
||||||
sym::square => Self::Square,
|
sym::square => Self::Square,
|
||||||
sym::square_root => Self::SquareRoot,
|
sym::square_root => Self::SquareRoot,
|
||||||
|
sym::to_x_coordinate => Self::ToXCoordinate,
|
||||||
|
sym::to_y_coordinate => Self::ToYCoordinate,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -65,6 +71,8 @@ impl UnaryOperation {
|
|||||||
Self::Not => "not",
|
Self::Not => "not",
|
||||||
Self::Square => "square",
|
Self::Square => "square",
|
||||||
Self::SquareRoot => "square_root",
|
Self::SquareRoot => "square_root",
|
||||||
|
Self::ToXCoordinate => "to_x_coordinate",
|
||||||
|
Self::ToYCoordinate => "to_y_coordinate",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,19 +149,21 @@ impl<'a> CodeGenerator<'a> {
|
|||||||
fn visit_unary(&mut self, input: &'a UnaryExpression) -> (String, String) {
|
fn visit_unary(&mut self, input: &'a UnaryExpression) -> (String, String) {
|
||||||
let (expression_operand, expression_instructions) = self.visit_expression(&input.receiver);
|
let (expression_operand, expression_instructions) = self.visit_expression(&input.receiver);
|
||||||
|
|
||||||
let opcode = match input.op {
|
let (opcode, suffix) = match input.op {
|
||||||
UnaryOperation::Abs => String::from("abs"),
|
UnaryOperation::Abs => ("abs", ""),
|
||||||
UnaryOperation::AbsWrapped => String::from("abs.w"),
|
UnaryOperation::AbsWrapped => ("abs.w", ""),
|
||||||
UnaryOperation::Double => String::from("double"),
|
UnaryOperation::Double => ("double", ""),
|
||||||
UnaryOperation::Inverse => String::from("inv"),
|
UnaryOperation::Inverse => ("inv", ""),
|
||||||
UnaryOperation::Not => String::from("not"),
|
UnaryOperation::Not => ("not", ""),
|
||||||
UnaryOperation::Negate => String::from("neg"),
|
UnaryOperation::Negate => ("neg", ""),
|
||||||
UnaryOperation::Square => String::from("square"),
|
UnaryOperation::Square => ("square", ""),
|
||||||
UnaryOperation::SquareRoot => String::from("sqrt"),
|
UnaryOperation::SquareRoot => ("sqrt", ""),
|
||||||
|
UnaryOperation::ToXCoordinate => ("cast", " as group.x"),
|
||||||
|
UnaryOperation::ToYCoordinate => ("cast", " as group.y"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let destination_register = format!("r{}", self.next_register);
|
let destination_register = format!("r{}", self.next_register);
|
||||||
let unary_instruction = format!(" {opcode} {expression_operand} into {destination_register};\n");
|
let unary_instruction = format!(" {opcode} {expression_operand} into {destination_register}{suffix};\n");
|
||||||
|
|
||||||
// Increment the register counter.
|
// Increment the register counter.
|
||||||
self.next_register += 1;
|
self.next_register += 1;
|
||||||
|
@ -730,6 +730,11 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
|
|||||||
self.assert_field_type(destination, input.span());
|
self.assert_field_type(destination, input.span());
|
||||||
self.visit_expression(&input.receiver, destination)
|
self.visit_expression(&input.receiver, destination)
|
||||||
}
|
}
|
||||||
|
UnaryOperation::ToXCoordinate | UnaryOperation::ToYCoordinate => {
|
||||||
|
// Only field type.
|
||||||
|
self.assert_field_type(destination, input.span());
|
||||||
|
self.visit_expression(&input.receiver, &Some(Type::Group))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user