DQNEO / babygo

babygo👶 is a small Go compiler made from scratch, which can compile itself. It's going to be the smallest and simplest go compiler in the world.
MIT License
296 stars 20 forks source link

parse.go: Replace struct fields assignments in parser.go by composite literals #94

Closed DQNEO closed 1 year ago

DQNEO commented 1 year ago

When I achieved self-hosting, composite literals were not supported yet, so I had no choice but to write this kind of clumsy field-by-field assignments.

var branchStmt = &ast.BranchStmt{}
branchStmt.Tok = token.Token(tok)
return branchStmt

However, we don't need to do this any more. This can be rewritten in a short form:

return &ast.BranchStmt{
    tok:token.Token(tok),
}
DQNEO commented 1 year ago

Done