1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

make gg work on Windows; prebuild glad and cJSON; new ft module

This commit is contained in:
Alexander Medvednikov
2019-07-10 13:27:35 +02:00
parent 06e7354d18
commit f834644db4
17 changed files with 6593 additions and 340 deletions

View File

@ -40,6 +40,7 @@ fn new_cgen(out_name_c string) *CGen {
gen := &CGen {
out_path: path
out: out
lines: _make(0, 1000, sizeof(string))
}
return gen
}
@ -220,3 +221,24 @@ fn (g mut CGen) add_to_main(s string) {
g.fn_main = g.fn_main + s
}
fn build_thirdparty_obj_file(flag string) {
obj_path := flag.all_after(' ')
if os.file_exists(obj_path) {
return
}
println('$obj_path not found, building it...')
parent := obj_path.all_before_last('/').trim_space()
files := os.ls(parent)
//files := os.ls(parent).filter(_.ends_with('.c')) TODO
mut cfiles := ''
for file in files {
if file.ends_with('.c') {
cfiles += parent + '/' + file + ' '
}
}
cc := if os.user_os() == 'windows' { 'gcc' } else { 'cc' } // TODO clang support on Windows
res := os.exec('$cc -c -o $obj_path $cfiles')
println(res)
}

View File

@ -244,11 +244,9 @@ fn (p mut Parser) fn_decl() {
typ = p.get_type()
}
// Translated C code can have empty functions (just definitions)
is_fn_header := !is_c && !is_sig && (p.pref.translated || p.pref.is_test) &&
(p.tok != .lcbr)// || (p.tok == .name && p.peek() != .lcbr))
is_fn_header := !is_c && !is_sig && (p.pref.translated || p.pref.is_test) && p.tok != .lcbr
if is_fn_header {
f.is_decl = true
// println('.key_goT fn header $f.name')
}
// { required only in normal function declarations
if !is_c && !is_sig && !is_fn_header {

View File

@ -247,7 +247,7 @@ void init_consts();')
// Embed cjson either in embedvlib or in json.o
if imports_json && v.pref.build_mode == .embed_vlib ||
(v.pref.build_mode == .build && v.out_name.contains('json.o')) {
cgen.genln('#include "cJSON.c" ')
//cgen.genln('#include "cJSON.c" ')
}
// We need the cjson header for all the json decoding user will do in default mode
if v.pref.build_mode == .default_mode {
@ -522,7 +522,7 @@ fn (v mut V) cc() {
}
linux_host := os.user_os() == 'linux'
v.log('cc() isprod=$v.pref.is_prod outname=$v.out_name')
mut a := ['-w', '-march=native']// arguments for the C compiler
mut a := ['-w'] // arguments for the C compiler
flags := v.table.flags.join(' ')
//mut shared := ''
if v.pref.is_so {

View File

@ -356,7 +356,7 @@ fn (p mut Parser) const_decl() {
// cur_line has const's value right now. if it's just a number, then optimize generation:
// output a #define so that we don't pollute the binary with unnecessary global vars
if is_compile_time_const(p.cgen.cur_line) {
p.cgen.consts << '#define $name $p.cgen.cur_line'
p.cgen.consts << '#define $name $p.cgen.cur_line'
p.cgen.cur_line = ''
p.fgenln('')
continue
@ -464,7 +464,7 @@ fn (p mut Parser) struct_decl() {
if !is_c {
kind := if is_union{'union'} else { 'struct'}
p.gen_typedef('typedef $kind $name $name;')
p.gen_type('$kind /*kind*/ $name {')
p.gen_type('$kind $name {')
}
}
// V used to have 'type Foo struct', many Go users might use this syntax
@ -591,7 +591,7 @@ fn (p mut Parser) enum_decl(_enum_name string) {
}
// Skip empty enums
if enum_name != 'int' {
p.cgen.typedefs << 'typedef int $enum_name ;\n'
p.cgen.typedefs << 'typedef int $enum_name;'
}
p.check(.lcbr)
mut val := 0
@ -602,7 +602,7 @@ fn (p mut Parser) enum_decl(_enum_name string) {
name := '${p.mod}__${enum_name}_$field'
p.fgenln('')
if p.run == .main {
p.cgen.consts << '#define $name $val \n'
p.cgen.consts << '#define $name $val'
}
if p.tok == .comma {
p.next()
@ -2046,7 +2046,8 @@ fn (p mut Parser) factor() string {
p.next()
return 'T'
case Token.lpar:
p.gen('(/*lpar*/')
//p.gen('(/*lpar*/')
p.gen('(')
p.check(.lpar)
typ = p.bool_expression()
// Hack. If this `)` referes to a ptr cast `(*int__)__`, it was already checked
@ -2686,13 +2687,17 @@ fn (p mut Parser) chash() {
pos := flag.index(' ')
flag = flag.right(pos)
}
has_vroot := flag.contains('@VROOT')
flag = flag.trim_space().replace('@VROOT', p.vroot)
if p.table.flags.contains(flag) {
return
}
p.log('adding flag "$flag"')
p.table.flags << flag// .all_after(' '))
// }
// `@VROOT/thirdparty/glad/glad.o`, make sure it exists, otherwise build it
if has_vroot && flag.contains('.o') {
build_thirdparty_obj_file(flag)
}
p.table.flags << flag
return
}
if hash.starts_with('include') {
@ -2745,7 +2750,6 @@ fn (p mut Parser) if_st(is_expr bool) string {
}
else {
p.genln(') {')
p.genln('/*if*/')
}
p.fgen(' ')
p.check(.lcbr)
@ -2775,7 +2779,6 @@ fn (p mut Parser) if_st(is_expr bool) string {
}
else {
p.genln(' else { ')
p.genln('/*else if*/')
}
p.check(.lcbr)
// statements() returns the type of the last statement
@ -2957,6 +2960,7 @@ fn (p mut Parser) for_st() {
}
p.fspace()
p.check(.lcbr)
p.genln('')
p.statements()
p.cur_fn.close_scope()
p.for_expr_cnt--