1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fmt: run on cmd/v; cgen: fix anonymous functions

This commit is contained in:
Alexander Medvednikov
2020-04-20 07:04:31 +02:00
parent efff96d622
commit c1fc768c1b
5 changed files with 129 additions and 81 deletions

View File

@@ -551,7 +551,7 @@ pub fn (c mut Checker) call_fn(call_expr mut ast.CallExpr) table.Type {
}
}
if !found {
c.error('unknown fn: $fn_name', call_expr.pos)
c.error('unknown function: $fn_name', call_expr.pos)
return table.void_type
}
call_expr.return_type = f.return_type

View File

@@ -17,10 +17,10 @@ const (
'char'
'default'
'do'
'double', 'extern', 'float', 'inline', 'int', 'long', 'register', 'restrict', 'short',
'signed'
'sizeof', 'static', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while'
]
'double'
'extern', 'float', 'inline', 'int', 'long', 'register', 'restrict', 'short', 'signed'
'sizeof'
'static', 'switch', 'typedef', 'union', 'unsigned', 'void', 'volatile', 'while']
)
fn foo(t token.Token) {
@@ -1853,6 +1853,22 @@ fn (var g Gen) const_decl(node ast.ConstDecl) {
g.expr(field.expr)
val := g.out.after(pos)
g.out.go_back(val.len)
/*
if field.typ == table.byte_type {
g.const_decl_simple_define(name, val)
return
}
*/
/*
if table.is_number(field.typ) {
g.const_decl_simple_define(name, val)
} else if field.typ == table.string_type {
g.definitions.writeln('string _const_$name; // a string literal, inited later')
if g.pref.build_mode != .build_module {
g.stringliterals.writeln('\t_const_$name = $val;')
}
} else {
*/
match field.expr {
ast.CharLiteral {
g.const_decl_simple_define(name, val)

View File

@@ -67,7 +67,7 @@ pub fn (var p Parser) expr(precedence int) ast.Expr {
node = ast.None{}
}
.key_sizeof {
p.next() // sizeof
p.next() // sizeof
p.check(.lpar)
if p.tok.lit == 'C' {
p.next()
@@ -102,7 +102,7 @@ pub fn (var p Parser) expr(precedence int) ast.Expr {
if p.peek_tok.kind == .pipe {
node = p.assoc()
} else if p.peek_tok.kind == .colon || p.tok.kind == .rcbr {
node = p.struct_init(true) // short_syntax: true
node = p.struct_init(true) // short_syntax: true
} else if p.tok.kind == .name {
p.next()
lit := if p.tok.lit != '' { p.tok.lit } else { p.tok.kind.str() }
@@ -113,6 +113,11 @@ pub fn (var p Parser) expr(precedence int) ast.Expr {
}
p.check(.rcbr)
}
.key_fn {
// Anonymous function
node = p.anon_fn()
return node
}
else {
if p.tok.kind == .comment {
println(p.tok.lit)