fixed size array with const length (`[N]int`)

pull/2997/head
Alexander Medvednikov 2019-12-06 02:38:35 +03:00
parent be323e2fb6
commit aed22a57e3
5 changed files with 17 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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())

View File

@ -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