diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5edfead89f..8ad8b366e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,6 +39,7 @@ jobs: run: sudo ./v symlink - name: Set up pg database run: | + brew services start postgresql psql -U postgres -c 'create database customerdb;' psql -d customerdb -f examples/database/pg/mydb.sql - name: Test v->c diff --git a/vlib/compiler/cgen.v b/vlib/compiler/cgen.v index c0815cbaf8..ad3903709e 100644 --- a/vlib/compiler/cgen.v +++ b/vlib/compiler/cgen.v @@ -22,6 +22,7 @@ mut: includes []string thread_args []string consts []string + const_defines []string fns []string so_fns []string consts_init []string @@ -119,7 +120,7 @@ fn (p mut Parser) tmp_expr() (string, string) { p.cgen.is_tmp = true // typ := p.bool_expression() - + res := p.cgen.tmp_line if p.cgen.prev_tmps.len > 0 { p.cgen.tmp_line = p.cgen.prev_tmps.last() @@ -175,7 +176,7 @@ fn (g mut CGen) set_placeholder(pos int, val string) { fn (g mut CGen) insert_before(val string) { if g.nogen { return - } + } prev := g.lines[g.lines.len - 1] g.lines[g.lines.len - 1] = '$prev \n $val \n' } @@ -316,7 +317,7 @@ fn platform_postfix_to_ifdefguard(name string) string { '_solaris.v' { '#ifdef __sun' } '_haiku.v' { '#ifdef __haiku__' } else { - + //verror('bad platform_postfix "$name"') // TODO '' @@ -324,7 +325,7 @@ fn platform_postfix_to_ifdefguard(name string) string { } if s == '' { verror('bad platform_postfix "$name"') - } + } return s } @@ -354,7 +355,7 @@ fn (v &V) type_definitions() string { types_to_c(types_sorted, v.table) return res } - + // sort structs by dependant fields fn sort_structs(types []Type) []Type { mut dep_graph := new_dep_graph() @@ -422,7 +423,7 @@ fn (v &V) interface_table() string { } if t.gen_types.len > 0 { // methods = '{TCCSKIP(0)}' -// } +// } sb.writeln('void* (* ${t.name}_name_table[][$t.methods.len]) = ' + '{ $methods }; ') } diff --git a/vlib/compiler/get_type.v b/vlib/compiler/get_type.v index 0f77072d1d..897d5bab48 100644 --- a/vlib/compiler/get_type.v +++ b/vlib/compiler/get_type.v @@ -75,8 +75,13 @@ fn (p mut Parser) get_type2() Type{ for p.tok == .lsbr { p.check(.lsbr) // [10]int - if p.tok == .number { - typ += '[$p.lit]' + if p.tok == .number || (p.tok == .name && !p.inside_const) { + if p.tok == .name { + typ += '[${p.mod}__$p.lit]' + + } else { + typ += '[$p.lit]' + } p.next() } else { diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 7e8070a10c..a756fb2939 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -316,6 +316,7 @@ pub fn (v mut V) compile() { } // All definitions mut def := strings.new_builder(10000)// Avoid unnecessary allocations + def.writeln(cgen.const_defines.join_lines()) $if !js { def.writeln(cgen.includes.join_lines()) def.writeln(cgen.typedefs.join_lines()) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 4767d1879c..ca0c324cbc 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -708,7 +708,7 @@ fn (p mut Parser) const_decl() { // Do not do this when building a module, otherwise the consts // will not be accessible. if p.pref.build_mode != .build_module && is_compile_time_const(p.cgen.cur_line) { - p.cgen.consts << '#define $name $p.cgen.cur_line' + p.cgen.const_defines << '#define $name $p.cgen.cur_line' p.cgen.resetln('') p.fgen_nl() continue