Skip to content

Commit

Permalink
chore: reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
rpitasky committed Dec 1, 2024
1 parent 1fcd9f4 commit ba1640d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 23 deletions.
9 changes: 8 additions & 1 deletion ti-basic-optimizer/src/analyze/control_flow/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ impl Program {
}

for (statement, failure_path) in block_failure_paths.iter() {
if matches!(self.lines[*statement], Statement::ControlFlow(ControlFlow::IfThen(_))) && matches!(self.lines[*failure_path - 1], Statement::ControlFlow(ControlFlow::Else)) && literals.contains(&(failure_path - 1)) {
if matches!(
self.lines[*statement],
Statement::ControlFlow(ControlFlow::IfThen(_))
) && matches!(
self.lines[*failure_path - 1],
Statement::ControlFlow(ControlFlow::Else)
) && literals.contains(&(failure_path - 1))
{
literals.insert(*statement);
}
}
Expand Down
25 changes: 16 additions & 9 deletions ti-basic-optimizer/src/analyze/control_flow/parser/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ impl<'a> Visualize<BasicBlockVisSettings<'a>> for BasicBlock {

node.set("shape", shape, false);

let content = match self.flow {
Flow::Goto(label_name) => label_name.stringify(config.tokenizer),
_ => self
.lines
.iter()
.map(|statement| statement.stringify(config.tokenizer))
.join("\n"),
};
let content = self
.lines
.iter()
.map(|statement| statement.stringify(config.tokenizer))
.join("\n");

if let Flow::Goto(label_name) = self.flow {
node.set("xlabel", &label_name.stringify(config.tokenizer), false);
}

node.set_label(&escape(&content).replace(
"\\n",
Expand Down Expand Up @@ -193,7 +194,13 @@ impl<'a> Visualize<CFGVisSettings<'a>> for LabelFragment {
.set_label(&self.name.stringify(config.tokenizer));
}

segment.visualize(&mut inner_context, CFGVisSettings { tokenizer: config.tokenizer, namespace: namespace.clone() });
segment.visualize(
&mut inner_context,
CFGVisSettings {
tokenizer: config.tokenizer,
namespace: namespace.clone(),
},
);

last_namespace = namespace;
}
Expand Down
1 change: 1 addition & 0 deletions ti-basic-optimizer/src/error_reporting.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::Range;
use titokens::tokenizer::TokenBoundaries;

/// Grab the next token, or throw a generic "end of input" error.
macro_rules! next_or_err {
($tokens: ident) => {
$tokens.next().ok_or_else(|| {
Expand Down
2 changes: 1 addition & 1 deletion ti-basic-optimizer/src/optimize/control_flow/label_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::parse::statements::control_flow::Menu;
use crate::parse::{
statements::{Statement, ControlFlow, LabelName},
statements::{ControlFlow, LabelName, Statement},
Program,
};
use itertools::Itertools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use std::mem;
use titokens::Token;

use crate::parse::statements::{Statement, ControlFlow, Generic};
use crate::parse::components::{ListIndex, MatrixIndex, StoreTarget};
use crate::parse::components::{EquationIndex, ListIndex, MatrixIndex, Rand, StoreTarget};
use crate::parse::statements::{ControlFlow, Generic, Statement};
use crate::parse::{
components::{Operand, Operator},
expression::Expression,
Expand Down Expand Up @@ -96,13 +96,12 @@ impl Expression {
}
}

Expression::Operand(Operand::ListAccess(ListIndex { index, .. })) => {
1 + index.optimize_parentheses()
}

Expression::Operand(Operand::MatrixAccess(MatrixIndex { col, .. })) => {
1 + col.optimize_parentheses()
}
Expression::Operand(
Operand::ListAccess(ListIndex { index, .. })
| Operand::MatrixAccess(MatrixIndex { col: index, .. })
| Operand::EquationAccess(EquationIndex { index, .. })
| Operand::Rand(Rand { count: Some(index) }),
) => 1 + index.optimize_parentheses(),

Expression::Operand(Operand::StringLiteral(_) | Operand::ListLiteral(_)) => 1,

Expand Down Expand Up @@ -196,11 +195,11 @@ impl Statement {
index.col.optimize_parentheses();
}

_ => { /* no closing parentheses possible */ }
_ => { /* no closing parentheses savings possible */ }
}
}

_ => { /* no closing parentheses possible */ }
_ => { /* no closing parentheses savings possible */ }
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ti-basic-optimizer/src/parse/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use itertools::Itertools;
use titokens::{Token, Tokens};

pub mod statements;
pub mod components;
pub mod expression;
mod program;
pub mod statements;

pub use program::Program;

Expand Down

0 comments on commit ba1640d

Please sign in to comment.