compiler: fix array initialisation generation for msvc

pull/1803/head
Emily Hudson 2019-08-30 22:59:21 +01:00 committed by Alexander Medvednikov
parent a9a4032a11
commit 04a200d3d8
2 changed files with 16 additions and 4 deletions

View File

@ -275,7 +275,7 @@ pub fn (v mut V) cc_msvc() {
// The C file we are compiling // The C file we are compiling
//a << '"$TmpPath/$v.out_name_c"' //a << '"$TmpPath/$v.out_name_c"'
a << '".$v.out_name_c"' a << '"$v.out_name_c"'
// Emily: // Emily:
// Not all of these are needed (but the compiler should discard them if they are not used) // 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"' cmd := '""$escaped_path\\cl.exe" $args"'
if v.pref.show_c_cmd || v.pref.is_verbose {
println('\n==========')
println(cmd)
}
// println('$cmd') // println('$cmd')
res := os.exec(cmd) or { res := os.exec(cmd) or {

View File

@ -2718,6 +2718,7 @@ fn (p mut Parser) array_init() string {
if no_alloc { if no_alloc {
p.next() p.next()
} }
// [1,2,3]!! => [3]int{1,2,3} // [1,2,3]!! => [3]int{1,2,3}
is_fixed_size := p.tok == .not is_fixed_size := p.tok == .not
if is_fixed_size { 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: // 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}` // `a = {1,2,3}`, not `a = (int[]) {1,2,3}`
if p.inside_const { if p.inside_const {
p.cgen.set_placeholder(new_arr_ph, '{ ') p.cgen.set_placeholder(new_arr_ph, '{')
} }
else { else {
p.cgen.set_placeholder(new_arr_ph, '($typ[]) { ') p.cgen.set_placeholder(new_arr_ph, '($typ[]) {')
} }
} }
return '[$i]$typ' return '[$i]$typ'
@ -2742,7 +2743,13 @@ fn (p mut Parser) array_init() string {
if no_alloc { if no_alloc {
new_arr += '_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 );') // 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 // Need to do this in the second pass, otherwise it goes to the very top of the out.c file
if !p.first_pass() { if !p.first_pass() {