Skip to content

Commit

Permalink
defer
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Jul 28, 2024
1 parent af06fe6 commit b6f845f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 6 additions & 1 deletion ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Stmt = AssignStmt
| BlockStmt
| CaseClause
| DeclStmt
| DeferStmt
| ExprStmt
| ForStmt
| IfStmt
Expand Down Expand Up @@ -231,9 +232,13 @@ struct RangeStmt {
}

struct ParenExpr {
x Expr @[json: 'X']
node_type_str string @[json: '_type']
x Expr @[json: 'X']
}

struct DeferStmt {
node_type_str string @[json: '_type']
call Expr @[json: 'Call']
}

fn parse_go_ast(file_path string) !GoFile {
Expand Down
3 changes: 1 addition & 2 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import os
import term
import strings

// const nr_tests = 15

const passing_tests = [
'struct_simple',
'method',
Expand All @@ -25,6 +23,7 @@ const passing_tests = [
'array',
'array_byte',
'array_fixed_size',
'defer',
]

struct App {
Expand Down
9 changes: 9 additions & 0 deletions stmt.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ fn (mut app App) stmt(stmt Stmt) {
RangeStmt {
app.range_stmt(stmt)
}
DeferStmt {
app.defer_stmt(stmt)
}
else {
app.genln('\t// unhandled in stmt: ${stmt}')
} // Add additional handlers as needed
Expand Down Expand Up @@ -132,6 +135,12 @@ fn (mut app App) decl_stmt(d DeclStmt) {
app.genln('')
}

fn (mut app App) defer_stmt(node DeferStmt) {
app.genln('defer {')
app.expr(node.call)
app.genln('}')
}

fn go2v_type(typ string) string {
if typ == 'byte' {
return 'u8'
Expand Down

0 comments on commit b6f845f

Please sign in to comment.