diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index ea67b82818..35a4695fc8 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -113,6 +113,7 @@ pub mut: // This is on by default, since a vast majority of users do not // work on the builtin module itself. //generating_vh bool + comptime_define string // -D vfmt for `if $vfmt {` } // Should be called by main at the end of the compilation process, to cleanup @@ -279,7 +280,7 @@ pub fn (v mut V) compile() { // parse generated V code (str() methods etc) mut vgen_parser := v.new_parser_from_string(v.vgen_buf.str()) // free the string builder which held the generated methods - vgen_parser.is_vgen = true + vgen_parser.is_vgen = true v.vgen_buf.free() vgen_parser.parse(.main) // v.parsers.add(vgen_parser) @@ -765,6 +766,7 @@ pub fn new_v(args[]string) &V { joined_args := args.join(' ') target_os := get_arg(joined_args, 'os', '') + comptime_define := get_arg(joined_args, 'd', '') mut out_name := get_arg(joined_args, 'o', 'a.out') mut dir := args.last() @@ -922,6 +924,7 @@ pub fn new_v(args[]string) &V { cflags: cflags ccompiler: find_c_compiler() building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || dir.contains('vlib')) + comptime_define: comptime_define } if pref.is_verbose || pref.is_debug { println('C compiler=$pref.ccompiler') diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 2dd78e6667..56210fd4fe 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -3872,7 +3872,13 @@ fn (p mut Parser) js_decode() string { fn (p mut Parser) attribute() { p.check(.lsbr) - p.attr = p.check_name() + if p.tok == .key_if { + // [if vfmt] + p.next() + p.attr = 'if ' + p.check_name() + } else { + p.attr = p.check_name() + } attr_token_idx := p.cur_tok_index() if p.tok == .colon { p.check(.colon) diff --git a/vlib/compiler/vfmt.v b/vlib/compiler/vfmt.v index 7375dd9768..f7b5dacf62 100644 --- a/vlib/compiler/vfmt.v +++ b/vlib/compiler/vfmt.v @@ -7,6 +7,7 @@ module compiler import strings // fmt helpers +//[if vfmt] fn (scanner mut Scanner) fgen(s_ string) { mut s := s_ if scanner.fmt_line_empty {