Skip to content

Commit d800567

Browse files
committed
Fix statement 1 not appearing
resolve warnings related to for loop func move stmts func
1 parent 37353f2 commit d800567

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

Diff for: src/ast/stmt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ pub enum Stmt {
2121
body: Vec<Stmt>,
2222
},
2323
For {
24+
name: Name,
25+
value: Box<Expr>,
26+
type_: Type,
2427
cond: Box<Expr>,
2528
incr: Box<Stmt>,
2629
body: Vec<Stmt>,

Diff for: src/codegen/sb3.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,6 @@ where T: Write + Seek
354354
)
355355
}
356356

357-
pub fn stmts(
358-
&mut self,
359-
s: S,
360-
d: D,
361-
stmts: &[Stmt],
362-
this_id: NodeID,
363-
parent_id: Option<NodeID>,
364-
) -> io::Result<()> {
365-
self.stmts_with_next(s, d, stmts, this_id, parent_id, None)
366-
}
367-
368357
pub fn substack(&mut self, name: &str, this_id: Option<NodeID>) -> io::Result<()> {
369358
let Some(this_id) = this_id else {
370359
return Ok(());
@@ -978,6 +967,17 @@ where T: Write + Seek
978967
self.stmts(s, d, &event.body, next_id, Some(this_id))
979968
}
980969

970+
pub fn stmts(
971+
&mut self,
972+
s: S,
973+
d: D,
974+
stmts: &[Stmt],
975+
this_id: NodeID,
976+
parent_id: Option<NodeID>,
977+
) -> io::Result<()> {
978+
self.stmts_with_next(s, d, stmts, this_id, parent_id, None)
979+
}
980+
981981
pub fn stmts_with_next(
982982
&mut self,
983983
s: S,
@@ -1022,10 +1022,13 @@ where T: Write + Seek
10221022
match stmt {
10231023
Stmt::Repeat { times, body } => self.repeat(s, d, this_id, times, body),
10241024
Stmt::For {
1025+
name,
1026+
value,
1027+
type_,
10251028
cond,
10261029
incr,
10271030
body
1028-
} => self.r#for(s, d, this_id, cond, incr, body),
1031+
} => self.r#for(s, d, this_id, name, value, type_, cond, incr, body),
10291032
Stmt::ForEach {
10301033
name,
10311034
times,

Diff for: src/codegen/stmt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ where T: Write + Seek
6060
s: S,
6161
d: D,
6262
this_id: NodeID,
63+
_name: &Name,
64+
_value: &Expr,
65+
_type: &Type,
6366
cond: &Expr,
6467
incr: &Stmt,
6568
body: &[Stmt],

Diff for: src/parser/grammar.lalrpop

+1-5
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,10 @@ Stmt: Stmt = {
8888
},
8989
REPEAT <times:BoxedIfExpr> <body:Stmts> => Stmt::Repeat { times, body },
9090
FOR <type_:Type> <l:@L> <name:NAME> <r:@R> "=" <value:BoxedExpr> ";" <cond:BoxedIfExpr> ";" <incr:BoxedStmt> <body:Stmts> => {
91-
Stmt::SetVar {
91+
Stmt::For {
9292
name: Name::Name { name, span: l..r },
9393
value,
9494
type_,
95-
is_local: false,
96-
is_cloud: false,
97-
};
98-
Stmt::For {
9995
cond,
10096
incr,
10197
body,

Diff for: src/visitor/pass1.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ fn visit_stmt(stmt: &mut Stmt, s: S, d: D) {
186186
visit_expr(times, s, d, false);
187187
visit_stmts(body, s, d, false);
188188
}
189-
Stmt::For { incr, cond, body } => {
189+
Stmt::For { name: _, value, type_: _, incr, cond, body } => {
190+
visit_expr(value, s, d, false);
190191
visit_stmt(incr, s, d);
191192
visit_expr(cond, s, d, true);
192193
visit_stmts(body, s, d, false);

Diff for: src/visitor/pass2.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,22 @@ fn visit_stmt(stmt: &mut Stmt, s: &mut S) -> Vec<Stmt> {
100100
visit_expr(times, &mut before, s);
101101
visit_stmts(body, s);
102102
}
103-
Stmt::For { cond, incr, body } => {
103+
Stmt::For {
104+
name,
105+
value,
106+
type_,
107+
cond,
108+
incr,
109+
body
110+
} => {
111+
before.push(Stmt::SetVar {
112+
name: name.clone(),
113+
value: value.clone(),
114+
type_: type_.clone(),
115+
is_local: false,
116+
is_cloud: false,
117+
});
118+
visit_expr(value, &mut before, s);
104119
visit_expr(cond, &mut before, s);
105120
visit_stmt(incr, s);
106121
visit_stmts(body, s);

0 commit comments

Comments
 (0)