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

Simplify constructing asg::BlockExpr #106

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
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
16 changes: 2 additions & 14 deletions crates/oq3_semantics/src/asg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,27 +489,15 @@ pub struct Block {
}

impl Block {
pub fn new() -> Block {
Block {
statements: Vec::<Stmt>::new(),
}
}

pub fn insert_stmt(&mut self, stmt: Stmt) {
self.statements.push(stmt);
pub fn new(statements: Vec<Stmt>) -> Block {
Block { statements }
}

pub fn statements(&self) -> &[Stmt] {
&self.statements
}
}

impl Default for Block {
fn default() -> Self {
Self::new()
}
}

#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct GateDeclaration {
name: SymbolIdResult,
Expand Down
18 changes: 6 additions & 12 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,18 +685,12 @@ fn from_literal(literal: &synast::Literal) -> Option<asg::TExpr> {
}

fn from_block_expr(block_synast: synast::BlockExpr, context: &mut Context) -> asg::Block {
let mut block = asg::Block::new();

for parse_stmt in block_synast.statements() {
let stmt = match parse_stmt {
synast::Stmt::ExprStmt(expr_stmt) => from_expr_stmt(expr_stmt, context),
stmt => from_stmt(stmt, context),
};
if let Some(stmt) = stmt {
block.insert_stmt(stmt)
}
}
block
asg::Block::new(
block_synast
.statements()
.map(|syn_stmt| from_stmt(syn_stmt, context).unwrap())
.collect::<Vec<_>>(),
)
}

fn from_classical_declaration_statement(
Expand Down
Loading