Skip to content

Commit

Permalink
fix for_bare
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 6, 2024
1 parent 5a5e4b3 commit f2206eb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Expr = ArrayType

type Stmt = AssignStmt
| BlockStmt
| BranchStmt
| CaseClause
| DeclStmt
| DeferStmt
Expand Down Expand Up @@ -262,6 +263,11 @@ struct ReturnStmt {
results []Expr @[json: 'Results']
}

struct BranchStmt {
node_type_str string @[json: '_type']
tok string @[json: 'Tok']
}

struct FuncLit {
node_type_str string @[json: '_type']
typ FuncType @[json: 'Type']
Expand Down
12 changes: 12 additions & 0 deletions stmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ fn (mut app App) stmt(stmt Stmt) {
BlockStmt {
app.block_stmt(stmt)
}
BranchStmt {
app.branch_stmt(stmt)
}
ExprStmt {
// app.genln('expr stmt')
app.expr_stmt(stmt)
Expand Down Expand Up @@ -92,6 +95,10 @@ fn (mut app App) if_stmt(node IfStmt) {

fn (mut app App) for_stmt(f ForStmt) {
app.gen('for ')
if f.init.node_type_str == '' { // == unsafe { nil } {
app.block_stmt(f.body)
return
}
app.assign_stmt(f.init, true)
app.gen('; ')
app.expr(f.cond)
Expand Down Expand Up @@ -168,3 +175,8 @@ fn (mut app App) return_stmt(node ReturnStmt) {
}
}
}

// continue break etc
fn (mut app App) branch_stmt(node BranchStmt) {
app.genln(node.tok)
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit f2206eb

Please sign in to comment.