Skip to content

Commit

Permalink
Fix some minor errors found in code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jlapeyre committed Jan 17, 2024
1 parent 5e0ad92 commit f5f6a40
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
12 changes: 9 additions & 3 deletions crates/oq3_semantics/src/asg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub enum Expr {
// But we need to handle these in a consistent way. Is there any situation where the "type" of Range is meaningful or useful?
// For example, in syntax_to_semantics, have a routine that handles out-of-tree expressions.
Range(Range),
Call, // stub function (def) call
Set, // stub
Call, // stub function (def) call
Set, // stub
MeasureExpression(MeasureExpression),
}

Expand Down Expand Up @@ -569,7 +569,13 @@ pub struct MeasureExpression {

impl MeasureExpression {
pub fn new(operand: TExpr) -> MeasureExpression {
MeasureExpression { operand: Box::new(operand) }
MeasureExpression {
operand: Box::new(operand),
}
}

pub fn operand(&self) -> &TExpr {
&self.operand
}

// FIXME: type may not be correct here.
Expand Down
11 changes: 3 additions & 8 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ pub fn syntax_to_semantic<T: SourceTrait>(

fn from_expr_stmt(expr_stmt: synast::ExprStmt, context: &mut Context) -> Option<asg::Stmt> {
let expr = from_expr(expr_stmt.expr().unwrap(), context);
if expr.is_none() {
dbg!(expr_stmt);
}
expr.map_or_else(
|| panic!("expr::ExprStmt is None"),
|ex| Some(asg::Stmt::ExprStmt(ex)),
Expand Down Expand Up @@ -239,7 +236,7 @@ fn from_expr(expr: synast::Expr, context: &mut Context) -> Option<asg::TExpr> {

// Everything else is not yet implemented
_ => {
println!("MeasureExpression not supported {:?}", expr);
println!("Expression not supported {:?}", expr);
None
}
}
Expand All @@ -248,16 +245,14 @@ fn from_expr(expr: synast::Expr, context: &mut Context) -> Option<asg::TExpr> {
fn from_gate_operand(gate_operand: synast::GateOperand, context: &mut Context) -> asg::TExpr {
match gate_operand {
synast::GateOperand::HardwareQubit(ref hwq) => {
asg::GateOperand::HardwareQubit(ast_hardware_qubit(hwq))
.to_texpr(Type::HardwareQubit)
asg::GateOperand::HardwareQubit(ast_hardware_qubit(hwq)).to_texpr(Type::HardwareQubit)
}
synast::GateOperand::Identifier(identifier) => {
let (astidentifier, typ) = ast_identifier(&identifier, context);
asg::GateOperand::Identifier(astidentifier).to_texpr(typ)
}
synast::GateOperand::IndexedIdentifier(indexed_identifier) => {
let (indexed_identifier, typ) =
ast_indexed_identifier(&indexed_identifier, context);
let (indexed_identifier, typ) = ast_indexed_identifier(&indexed_identifier, context);
asg::GateOperand::IndexedIdentifier(indexed_identifier).to_texpr(typ)
}
}
Expand Down
12 changes: 10 additions & 2 deletions crates/oq3_semantics/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,16 @@ impl Type {
pub fn is_const(&self) -> bool {
use Type::*;
match self {
Bit(c) | Int(_, c) | UInt(_, c) | Float(_, c) | Angle(_, c) | Complex(_, c) | Bool(c)
| Duration(c) | Stretch(c) | BitArray(_, c) => matches!(*c, IsConst::True),
Bit(c)
| Int(_, c)
| UInt(_, c)
| Float(_, c)
| Angle(_, c)
| Complex(_, c)
| Bool(c)
| Duration(c)
| Stretch(c)
| BitArray(_, c) => matches!(*c, IsConst::True),
_ => true,
}
}
Expand Down

0 comments on commit f5f6a40

Please sign in to comment.