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

cgen: fix several errors

This commit is contained in:
Alexander Medvednikov 2020-03-06 16:31:40 +01:00
parent ed9075b937
commit be2480c320
5 changed files with 11 additions and 6 deletions

View File

@ -141,6 +141,7 @@ pub:
is_method bool
rec_mut bool // is receiver mutable
is_c bool
no_body bool // just a definition `fn C.malloc()`
}
pub struct BranchStmt {

View File

@ -173,7 +173,7 @@ fn (g mut Gen) stmt(node ast.Stmt) {
}
}
ast.FnDecl {
if it.is_c || it.name == 'malloc' {
if it.is_c || it.name == 'malloc' || it.no_body {
return
}
g.reset_tmp_count()
@ -276,8 +276,8 @@ fn (g mut Gen) stmt(node ast.Stmt) {
g.writeln('}')
}
ast.GlobalDecl {
// TODO
g.writeln('__global')
styp := g.typ(g.table.get_type_symbol(it.typ).name)
g.definitions.writeln('$styp $it.name; // global')
}
ast.GotoLabel {
g.writeln('$it.name:')
@ -620,7 +620,8 @@ fn (g mut Gen) const_decl(node ast.ConstDecl) {
g.writeln('')
}
else {
g.writeln('$field_type_sym.name $name; // inited later') // = ')
styp := g.typ(field_type_sym.name)
g.definitions.writeln('$styp $name; // inited later') // = ')
// TODO
// g.expr(node.exprs[i])
}

View File

@ -15,6 +15,7 @@ typedef struct {
string arg1;
} multi_return_int_string;
// end of definitions #endif
int pi2; // inited later
void foo(int a);
void User_inc_age(User u, int n);
int get_int(string a);
@ -30,7 +31,6 @@ void end();
void localmod__pub_foo();
int localmod__get_int_10();
#define pi 3
int pi2; // inited later
typedef enum {
Color_red, // 0

View File

@ -24,7 +24,7 @@ pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
args: args
muts: muts
// tok: tok
pos: tok.position()
is_c: is_c
or_block: ast.OrExpr{
@ -155,6 +155,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
})
}
mut stmts := []ast.Stmt
no_body := p.tok.kind != .lcbr
if p.tok.kind == .lcbr {
stmts = p.parse_block()
}
@ -175,6 +176,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
is_method: is_method
rec_mut: rec_mut
is_c: is_c
no_body: no_body
}
}

View File

@ -1593,6 +1593,7 @@ fn (p mut Parser) global_decl() ast.GlobalDecl {
return ast.GlobalDecl{
name: name
typ: typ
}
}