mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-23 23:23:50 +03:00
WIP associated function syntax for group::to_*_coordinate
This commit is contained in:
parent
07d26ea43f
commit
9b7a4ba456
@ -175,6 +175,9 @@ pub enum CoreFunction {
|
||||
MappingGet,
|
||||
MappingGetOrUse,
|
||||
MappingSet,
|
||||
|
||||
GroupToXCoordinate,
|
||||
GroupToYCoordinate,
|
||||
}
|
||||
|
||||
impl CoreFunction {
|
||||
@ -338,6 +341,9 @@ impl CoreFunction {
|
||||
(sym::Mapping, sym::get) => Self::MappingGet,
|
||||
(sym::Mapping, sym::get_or_use) => Self::MappingGetOrUse,
|
||||
(sym::Mapping, sym::set) => Self::MappingSet,
|
||||
|
||||
(sym::group, sym::to_x_coordinate) => Self::GroupToXCoordinate,
|
||||
(sym::group, sym::to_y_coordinate) => Self::GroupToYCoordinate,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@ -502,6 +508,9 @@ impl CoreFunction {
|
||||
Self::MappingGet => 2,
|
||||
Self::MappingGetOrUse => 3,
|
||||
Self::MappingSet => 3,
|
||||
|
||||
Self::GroupToXCoordinate => 1,
|
||||
Self::GroupToYCoordinate => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -357,6 +357,27 @@ impl<'a> CodeGenerator<'a> {
|
||||
}
|
||||
_ => unreachable!("The only variants of Mapping are get, get_or, and set"),
|
||||
},
|
||||
Type::Group => {
|
||||
match input.name {
|
||||
Identifier { name: sym::to_x_coordinate, .. } => {
|
||||
let mut instruction = " cast".to_string();
|
||||
let destination_register = get_destination_register();
|
||||
// Write the argument and the destination register.
|
||||
writeln!(instruction, " {} into {destination_register} as group.x;", arguments[0],)
|
||||
.expect("failed to write to string");
|
||||
(destination_register, instruction)
|
||||
}
|
||||
Identifier { name: sym::to_y_coordinate, .. } => {
|
||||
let mut instruction = " cast".to_string();
|
||||
let destination_register = get_destination_register();
|
||||
// Write the argument and the destination register.
|
||||
writeln!(instruction, " {} into {destination_register} as group.y;", arguments[0],)
|
||||
.expect("failed to write to string");
|
||||
(destination_register, instruction)
|
||||
}
|
||||
_ => unreachable!("The only associated methods of group are to_x_coordinate and to_y_coordinate"),
|
||||
}
|
||||
}
|
||||
_ => unreachable!("All core functions should be known at this phase of compilation"),
|
||||
};
|
||||
// Add the instruction to the list of instructions.
|
||||
|
@ -861,6 +861,11 @@ impl<'a> TypeChecker<'a> {
|
||||
None
|
||||
}
|
||||
}
|
||||
CoreFunction::GroupToXCoordinate | CoreFunction::GroupToYCoordinate => {
|
||||
// Check that the first argument is a group.
|
||||
self.assert_scalar_type(&arguments[0].0, arguments[0].1);
|
||||
Some(Type::Group)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#![forbid(unsafe_code)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
pub mod symbol;
|
||||
pub use symbol::{sym, Symbol};
|
||||
|
@ -175,6 +175,8 @@ symbols! {
|
||||
Poseidon4,
|
||||
Poseidon8,
|
||||
set,
|
||||
to_x_coordinate,
|
||||
to_y_coordinate,
|
||||
|
||||
// types
|
||||
address,
|
||||
|
Loading…
Reference in New Issue
Block a user