Skip to content

Commit

Permalink
type sumtype
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 5, 2024
1 parent 715d717 commit a9cbecd
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
10 changes: 9 additions & 1 deletion ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type Stmt = AssignStmt
| ReturnStmt
| SwitchStmt

type Type2 = ArrayType | Ident | StarExpr

struct GoFile {
name Ident @[json: 'Name']
decls []Decl @[json: 'Decls']
Expand All @@ -56,7 +58,8 @@ struct Spec {

struct ArrayType {
node_type_str string @[json: '_type']
elt Ident @[json: 'Elt']
// elt Ident @[json: 'Elt']
elt Expr @[json: 'Elt']
}

struct Ellipsis {
Expand Down Expand Up @@ -240,6 +243,11 @@ struct ParenExpr {
x Expr @[json: 'X']
}

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

struct DeferStmt {
node_type_str string @[json: '_type']
call Expr @[json: 'Call']
Expand Down
15 changes: 9 additions & 6 deletions fn_call.v
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@ fn (mut app App) call_expr(call CallExpr) {
}

// []byte(str) => str.bytes()
if fun is ArrayType && fun.elt.name == 'byte' {
x := call.args[0]
if x is BasicLit {
app.expr(x)
app.gen('.bytes()')
return
if fun is ArrayType {
elt := fun.elt
if elt is Ident && elt.name == 'byte' {
x := call.args[0]
if x is BasicLit {
app.expr(x)
app.gen('.bytes()')
return
}
}
}
if !is_println {
Expand Down
3 changes: 3 additions & 0 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ fn (mut app App) generate_v_code(go_file GoFile) string {
return app.sb.str()
}

fn (mut app App) typ() {
}

fn type_or_ident(typ TypeOrIdent) string {
return if typ.elt.name != '' { '[]${typ.elt.name}' } else { typ.name }
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a9cbecd

Please sign in to comment.