1
0
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:
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
- 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

View File

@ -22,6 +22,7 @@ mut:
includes []string
thread_args []string
consts []string
const_defines []string
fns []string
so_fns []string
consts_init []string

View File

@ -75,8 +75,13 @@ fn (p mut Parser) get_type2() Type{
for p.tok == .lsbr {
p.check(.lsbr)
// [10]int
if p.tok == .number {
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 {

View File

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

View File

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