fixed size array with const length (`[N]int`)
parent
be323e2fb6
commit
aed22a57e3
|
@ -39,6 +39,7 @@ jobs:
|
||||||
run: sudo ./v symlink
|
run: sudo ./v symlink
|
||||||
- name: Set up pg database
|
- name: Set up pg database
|
||||||
run: |
|
run: |
|
||||||
|
brew services start postgresql
|
||||||
psql -U postgres -c 'create database customerdb;'
|
psql -U postgres -c 'create database customerdb;'
|
||||||
psql -d customerdb -f examples/database/pg/mydb.sql
|
psql -d customerdb -f examples/database/pg/mydb.sql
|
||||||
- name: Test v->c
|
- name: Test v->c
|
||||||
|
|
|
@ -22,6 +22,7 @@ mut:
|
||||||
includes []string
|
includes []string
|
||||||
thread_args []string
|
thread_args []string
|
||||||
consts []string
|
consts []string
|
||||||
|
const_defines []string
|
||||||
fns []string
|
fns []string
|
||||||
so_fns []string
|
so_fns []string
|
||||||
consts_init []string
|
consts_init []string
|
||||||
|
@ -119,7 +120,7 @@ fn (p mut Parser) tmp_expr() (string, string) {
|
||||||
p.cgen.is_tmp = true
|
p.cgen.is_tmp = true
|
||||||
//
|
//
|
||||||
typ := p.bool_expression()
|
typ := p.bool_expression()
|
||||||
|
|
||||||
res := p.cgen.tmp_line
|
res := p.cgen.tmp_line
|
||||||
if p.cgen.prev_tmps.len > 0 {
|
if p.cgen.prev_tmps.len > 0 {
|
||||||
p.cgen.tmp_line = p.cgen.prev_tmps.last()
|
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) {
|
fn (g mut CGen) insert_before(val string) {
|
||||||
if g.nogen {
|
if g.nogen {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
prev := g.lines[g.lines.len - 1]
|
prev := g.lines[g.lines.len - 1]
|
||||||
g.lines[g.lines.len - 1] = '$prev \n $val \n'
|
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' }
|
'_solaris.v' { '#ifdef __sun' }
|
||||||
'_haiku.v' { '#ifdef __haiku__' }
|
'_haiku.v' { '#ifdef __haiku__' }
|
||||||
else {
|
else {
|
||||||
|
|
||||||
//verror('bad platform_postfix "$name"')
|
//verror('bad platform_postfix "$name"')
|
||||||
// TODO
|
// TODO
|
||||||
''
|
''
|
||||||
|
@ -324,7 +325,7 @@ fn platform_postfix_to_ifdefguard(name string) string {
|
||||||
}
|
}
|
||||||
if s == '' {
|
if s == '' {
|
||||||
verror('bad platform_postfix "$name"')
|
verror('bad platform_postfix "$name"')
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,7 +355,7 @@ fn (v &V) type_definitions() string {
|
||||||
types_to_c(types_sorted, v.table)
|
types_to_c(types_sorted, v.table)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort structs by dependant fields
|
// sort structs by dependant fields
|
||||||
fn sort_structs(types []Type) []Type {
|
fn sort_structs(types []Type) []Type {
|
||||||
mut dep_graph := new_dep_graph()
|
mut dep_graph := new_dep_graph()
|
||||||
|
@ -422,7 +423,7 @@ fn (v &V) interface_table() string {
|
||||||
}
|
}
|
||||||
if t.gen_types.len > 0 {
|
if t.gen_types.len > 0 {
|
||||||
// methods = '{TCCSKIP(0)}'
|
// methods = '{TCCSKIP(0)}'
|
||||||
// }
|
// }
|
||||||
sb.writeln('void* (* ${t.name}_name_table[][$t.methods.len]) = ' +
|
sb.writeln('void* (* ${t.name}_name_table[][$t.methods.len]) = ' +
|
||||||
'{ $methods }; ')
|
'{ $methods }; ')
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,8 +75,13 @@ fn (p mut Parser) get_type2() Type{
|
||||||
for p.tok == .lsbr {
|
for p.tok == .lsbr {
|
||||||
p.check(.lsbr)
|
p.check(.lsbr)
|
||||||
// [10]int
|
// [10]int
|
||||||
if p.tok == .number {
|
if p.tok == .number || (p.tok == .name && !p.inside_const) {
|
||||||
typ += '[$p.lit]'
|
if p.tok == .name {
|
||||||
|
typ += '[${p.mod}__$p.lit]'
|
||||||
|
|
||||||
|
} else {
|
||||||
|
typ += '[$p.lit]'
|
||||||
|
}
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -316,6 +316,7 @@ pub fn (v mut V) compile() {
|
||||||
}
|
}
|
||||||
// All definitions
|
// All definitions
|
||||||
mut def := strings.new_builder(10000)// Avoid unnecessary allocations
|
mut def := strings.new_builder(10000)// Avoid unnecessary allocations
|
||||||
|
def.writeln(cgen.const_defines.join_lines())
|
||||||
$if !js {
|
$if !js {
|
||||||
def.writeln(cgen.includes.join_lines())
|
def.writeln(cgen.includes.join_lines())
|
||||||
def.writeln(cgen.typedefs.join_lines())
|
def.writeln(cgen.typedefs.join_lines())
|
||||||
|
|
|
@ -708,7 +708,7 @@ fn (p mut Parser) const_decl() {
|
||||||
// Do not do this when building a module, otherwise the consts
|
// Do not do this when building a module, otherwise the consts
|
||||||
// will not be accessible.
|
// will not be accessible.
|
||||||
if p.pref.build_mode != .build_module && is_compile_time_const(p.cgen.cur_line) {
|
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.cgen.resetln('')
|
||||||
p.fgen_nl()
|
p.fgen_nl()
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue