Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Adding from_designator + notes for usage #224

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ fn from_stmt(stmt: synast::Stmt, context: &mut Context) -> Option<asg::Stmt> {
return Some(asg::DeclareHardwareQubit::new(ast_hardware_qubit(&hw_qubit)).to_stmt());
};
let qubit_type = q_decl.qubit_type().unwrap();
let width = match qubit_type.designator().and_then(|x| x.expr()) {
let width = match from_designator(qubit_type.designator()) {
Some(synast::Expr::Literal(ref literal)) => {
match literal.kind() {
synast::LiteralKind::IntNumber(int_num) => {
Expand Down Expand Up @@ -969,7 +969,7 @@ fn from_scalar_type(
// not complex
scalar_type.designator()
};
let width = match designator.and_then(|desg| desg.expr()) {
let width = match from_designator(designator) {
// We only support literal integer designators at the moment.
Some(synast::Expr::Literal(ref literal)) => {
match literal.kind() {
Expand Down Expand Up @@ -1243,6 +1243,13 @@ fn bind_typed_parameter_list(
})
}

fn from_designator(arg: Option<synast::Designator>) -> Option<synast::Expr> {
arg.and_then(|desg| desg.expr())
// NOTE: Other uses of this pattern above have certain error checking,
// but because it was not standardized, it is not included
// in this helper function
}

// This works, but using it is pretty clumsy.
// fn with_scope<F>(context: &mut Context, scope: ScopeType, func: F) where
// F: FnOnce(&mut Context)
Expand Down
Loading