mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fixed size array with const length ([N]int
)
This commit is contained in:
parent
be323e2fb6
commit
aed22a57e3
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -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
|
||||
|
@ -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 }; ')
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user