From ce73ced932f5122231c4b98e80ef4df75dfaa61b Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 22 Mar 2020 14:54:31 +0100 Subject: [PATCH] cgen: #else --- vlib/v/ast/ast.v | 1 + vlib/v/gen/cgen.v | 12 ++++++++---- vlib/v/parser/comptime.v | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 1d9dbd9813..942fde14d4 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -391,6 +391,7 @@ pub: stmts []Stmt pos token.Position mut: + has_else bool else_stmts []Stmt } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 8276ef3226..eaf9284c65 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -270,10 +270,12 @@ fn (g mut Gen) stmt(node ast.Stmt) { ast.CompIf { g.writeln('\n#ifdef ' + comp_if_to_ifdef(it.val)) g.writeln('// #if $it.val') - // g.expr(it.cond) // println('comp if stmts $g.file.path:$it.pos.line_nr') g.stmts(it.stmts) - // println('done') + if it.has_else { + g.writeln('#else') + g.stmts(it.else_stmts) + } g.writeln('#endif') } ast.DeferStmt { @@ -1728,8 +1730,7 @@ fn (g mut Gen) write_types(types []table.TypeSymbol) { g.definitions.writeln('};\n') } // table.Alias, table.SumType { TODO - table.Alias { - } + table.Alias {} table.Enum { g.definitions.writeln('typedef enum {') for j, val in it.vals { @@ -2021,6 +2022,9 @@ fn comp_if_to_ifdef(name string) string { 'linux_or_macos' { return '' } + 'mingw' { + return '__MINGW32__' + } 'no_bounds_checking' { return 'NO_BOUNDS_CHECK' } diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 78af8a4353..ab42be1b42 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -23,6 +23,7 @@ pub fn (p mut Parser) comp_if() ast.CompIf { if p.tok.kind == .dollar && p.peek_tok.kind == .key_else { p.next() p.check(.key_else) + node.has_else = true node.else_stmts = p.parse_block() } return node