From 04a200d3d81216893eddf7d947e9db67243cca01 Mon Sep 17 00:00:00 2001 From: Emily Hudson Date: Fri, 30 Aug 2019 22:59:21 +0100 Subject: [PATCH] compiler: fix array initialisation generation for msvc --- compiler/msvc.v | 7 ++++++- compiler/parser.v | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/compiler/msvc.v b/compiler/msvc.v index 948b7953b9..f7834ddf85 100644 --- a/compiler/msvc.v +++ b/compiler/msvc.v @@ -275,7 +275,7 @@ pub fn (v mut V) cc_msvc() { // The C file we are compiling //a << '"$TmpPath/$v.out_name_c"' - a << '".$v.out_name_c"' + a << '"$v.out_name_c"' // Emily: // Not all of these are needed (but the compiler should discard them if they are not used) @@ -408,6 +408,11 @@ pub fn (v mut V) cc_msvc() { cmd := '""$escaped_path\\cl.exe" $args"' + if v.pref.show_c_cmd || v.pref.is_verbose { + println('\n==========') + println(cmd) + } + // println('$cmd') res := os.exec(cmd) or { diff --git a/compiler/parser.v b/compiler/parser.v index 2d66c25ad1..bc8737db81 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -2718,6 +2718,7 @@ fn (p mut Parser) array_init() string { if no_alloc { p.next() } + // [1,2,3]!! => [3]int{1,2,3} is_fixed_size := p.tok == .not if is_fixed_size { @@ -2727,10 +2728,10 @@ fn (p mut Parser) array_init() string { // If we are defining a const array, we don't need to specify the type: // `a = {1,2,3}`, not `a = (int[]) {1,2,3}` if p.inside_const { - p.cgen.set_placeholder(new_arr_ph, '{ ') + p.cgen.set_placeholder(new_arr_ph, '{') } else { - p.cgen.set_placeholder(new_arr_ph, '($typ[]) { ') + p.cgen.set_placeholder(new_arr_ph, '($typ[]) {') } } return '[$i]$typ' @@ -2742,7 +2743,13 @@ fn (p mut Parser) array_init() string { if no_alloc { new_arr += '_no_alloc' } - p.gen(' })') + + if i == 0 { + p.gen(' 0 })') + } else { + p.gen(' })') + } + // p.gen('$new_arr($vals.len, $vals.len, sizeof($typ), ($typ[$vals.len]) $c_arr );') // Need to do this in the second pass, otherwise it goes to the very top of the out.c file if !p.first_pass() {