Refactor BuildMode enum to lowercase
parent
32e32cee5c
commit
24b0fd5097
|
@ -95,7 +95,7 @@ fn (f mut Fn) clear_vars() {
|
||||||
|
|
||||||
// vlib header file?
|
// vlib header file?
|
||||||
fn (p mut Parser) is_sig() bool {
|
fn (p mut Parser) is_sig() bool {
|
||||||
return (p.pref.build_mode == DEFAULT_MODE || p.pref.build_mode == BUILD) &&
|
return (p.pref.build_mode == default_mode || p.pref.build_mode == build) &&
|
||||||
(p.file_path.contains(TmpPath))
|
(p.file_path.contains(TmpPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ fn (p mut Parser) fn_decl() {
|
||||||
// C function header def? (fn C.NSMakeRect(int,int,int,int))
|
// C function header def? (fn C.NSMakeRect(int,int,int,int))
|
||||||
is_c := f.name == 'C' && p.tok == DOT
|
is_c := f.name == 'C' && p.tok == DOT
|
||||||
// Just fn signature? only builtin.v + default build mode
|
// Just fn signature? only builtin.v + default build mode
|
||||||
// is_sig := p.builtin_pkg && p.pref.build_mode == DEFAULT_MODE
|
// is_sig := p.builtin_pkg && p.pref.build_mode == default_mode
|
||||||
// is_sig := p.pref.build_mode == DEFAULT_MODE && (p.builtin_pkg || p.file.contains(LANG_TMP))
|
// is_sig := p.pref.build_mode == default_mode && (p.builtin_pkg || p.file.contains(LANG_TMP))
|
||||||
is_sig := p.is_sig()
|
is_sig := p.is_sig()
|
||||||
// println('\n\nfn decl !!is_sig=$is_sig name=$f.name $p.builtin_pkg')
|
// println('\n\nfn decl !!is_sig=$is_sig name=$f.name $p.builtin_pkg')
|
||||||
if is_c {
|
if is_c {
|
||||||
|
@ -338,7 +338,7 @@ fn (p mut Parser) fn_decl() {
|
||||||
// Add function definition to the top
|
// Add function definition to the top
|
||||||
if !is_c && f.name != 'main' && p.first_run() {
|
if !is_c && f.name != 'main' && p.first_run() {
|
||||||
// TODO hack to make Volt compile without -embed_vlib
|
// TODO hack to make Volt compile without -embed_vlib
|
||||||
if f.name == 'darwin__nsstring' && p.pref.build_mode == DEFAULT_MODE {
|
if f.name == 'darwin__nsstring' && p.pref.build_mode == default_mode {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
p.cgen.fns << fn_decl + ';'
|
p.cgen.fns << fn_decl + ';'
|
||||||
|
|
|
@ -11,17 +11,16 @@ const (
|
||||||
Version = '0.1.11'
|
Version = '0.1.11'
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO no caps
|
|
||||||
enum BuildMode {
|
enum BuildMode {
|
||||||
// `v program.v'
|
// `v program.v'
|
||||||
// Build user code only, and add pre-compiled vlib (`cc program.o builtin.o os.o...`)
|
// Build user code only, and add pre-compiled vlib (`cc program.o builtin.o os.o...`)
|
||||||
DEFAULT_MODE
|
default_mode
|
||||||
// `v -embed_vlib program.v`
|
// `v -embed_vlib program.v`
|
||||||
// vlib + user code in one file (slower compilation, but easier when working on vlib and cross-compiling)
|
// vlib + user code in one file (slower compilation, but easier when working on vlib and cross-compiling)
|
||||||
EMBED_VLIB
|
embed_vlib
|
||||||
// `v -lib ~/v/os`
|
// `v -lib ~/v/os`
|
||||||
// build any module (generate os.o + os.vh)
|
// build any module (generate os.o + os.vh)
|
||||||
BUILD // TODO a better name would be smth like `.build_module` I think
|
build //TODO a better name would be smth like `.build_module` I think
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vtmp_path() string {
|
fn vtmp_path() string {
|
||||||
|
@ -243,23 +242,23 @@ void reload_so();
|
||||||
void init_consts();')
|
void init_consts();')
|
||||||
imports_json := v.table.imports.contains('json')
|
imports_json := v.table.imports.contains('json')
|
||||||
// TODO remove global UI hack
|
// TODO remove global UI hack
|
||||||
if v.os == MAC && ((v.pref.build_mode == EMBED_VLIB && v.table.imports.contains('ui')) ||
|
if v.os == MAC && ((v.pref.build_mode == embed_vlib && v.table.imports.contains('ui')) ||
|
||||||
(v.pref.build_mode == BUILD && v.dir.contains('/ui'))) {
|
(v.pref.build_mode == build && v.dir.contains('/ui'))) {
|
||||||
cgen.genln('id defaultFont = 0; // main.v')
|
cgen.genln('id defaultFont = 0; // main.v')
|
||||||
}
|
}
|
||||||
// TODO remove ugly .c include once V has its own json parser
|
// TODO remove ugly .c include once V has its own json parser
|
||||||
// Embed cjson either in embedvlib or in json.o
|
// Embed cjson either in embedvlib or in json.o
|
||||||
if imports_json && v.pref.build_mode == EMBED_VLIB ||
|
if imports_json && v.pref.build_mode == embed_vlib ||
|
||||||
(v.pref.build_mode == BUILD && v.out_name.contains('json.o')) {
|
(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
|
// We need the cjson header for all the json decoding user will do in default mode
|
||||||
if v.pref.build_mode == DEFAULT_MODE {
|
if v.pref.build_mode == default_mode {
|
||||||
if imports_json {
|
if imports_json {
|
||||||
cgen.genln('#include "cJSON.h"')
|
cgen.genln('#include "cJSON.h"')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.pref.build_mode == EMBED_VLIB || v.pref.build_mode == DEFAULT_MODE {
|
if v.pref.build_mode == embed_vlib || v.pref.build_mode == default_mode {
|
||||||
// If we declare these for all modes, then when running `v a.v` we'll get
|
// If we declare these for all modes, then when running `v a.v` we'll get
|
||||||
// `/usr/bin/ld: multiple definition of 'total_m'`
|
// `/usr/bin/ld: multiple definition of 'total_m'`
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -304,7 +303,7 @@ void init_consts();')
|
||||||
dd := d.str()
|
dd := d.str()
|
||||||
cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile
|
cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile
|
||||||
// if v.build_mode in [.default, .embed_vlib] {
|
// if v.build_mode in [.default, .embed_vlib] {
|
||||||
if v.pref.build_mode == DEFAULT_MODE || v.pref.build_mode == EMBED_VLIB {
|
if v.pref.build_mode == default_mode || v.pref.build_mode == embed_vlib {
|
||||||
// vlib can't have `init_consts()`
|
// vlib can't have `init_consts()`
|
||||||
cgen.genln('void init_consts() { g_str_buf=malloc(1000); ${cgen.consts_init.join_lines()} }')
|
cgen.genln('void init_consts() { g_str_buf=malloc(1000); ${cgen.consts_init.join_lines()} }')
|
||||||
// _STR function can't be defined in vlib
|
// _STR function can't be defined in vlib
|
||||||
|
@ -344,7 +343,7 @@ string _STR_TMP(const char *fmt, ...) {
|
||||||
}
|
}
|
||||||
// Make sure the main function exists
|
// Make sure the main function exists
|
||||||
// Obviously we don't need it in libraries
|
// Obviously we don't need it in libraries
|
||||||
if v.pref.build_mode != BUILD {
|
if v.pref.build_mode != build {
|
||||||
if !v.table.main_exists() && !v.pref.is_test {
|
if !v.table.main_exists() && !v.pref.is_test {
|
||||||
// It can be skipped in single file programs
|
// It can be skipped in single file programs
|
||||||
if v.pref.is_script {
|
if v.pref.is_script {
|
||||||
|
@ -508,13 +507,13 @@ fn (v mut V) cc() {
|
||||||
a << '-g'
|
a << '-g'
|
||||||
}
|
}
|
||||||
mut libs := ''// builtin.o os.o http.o etc
|
mut libs := ''// builtin.o os.o http.o etc
|
||||||
if v.pref.build_mode == BUILD {
|
if v.pref.build_mode == build {
|
||||||
a << '-c'
|
a << '-c'
|
||||||
}
|
}
|
||||||
else if v.pref.build_mode == EMBED_VLIB {
|
else if v.pref.build_mode == embed_vlib {
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
else if v.pref.build_mode == DEFAULT_MODE {
|
else if v.pref.build_mode == default_mode {
|
||||||
libs = '$TmpPath/vlib/builtin.o'
|
libs = '$TmpPath/vlib/builtin.o'
|
||||||
if !os.file_exists(libs) {
|
if !os.file_exists(libs) {
|
||||||
println('`builtin.o` not found')
|
println('`builtin.o` not found')
|
||||||
|
@ -569,7 +568,7 @@ mut args := ''
|
||||||
a << '-x objective-c'
|
a << '-x objective-c'
|
||||||
}
|
}
|
||||||
// Without these libs compilation will fail on Linux
|
// Without these libs compilation will fail on Linux
|
||||||
if v.os == LINUX && v.pref.build_mode != BUILD {
|
if v.os == LINUX && v.pref.build_mode != build {
|
||||||
a << '-lm -ldl -lpthread'
|
a << '-lm -ldl -lpthread'
|
||||||
}
|
}
|
||||||
// Find clang executable
|
// Find clang executable
|
||||||
|
@ -596,7 +595,7 @@ mut args := ''
|
||||||
panic('clang error')
|
panic('clang error')
|
||||||
}
|
}
|
||||||
// Link it if we are cross compiling and need an executable
|
// Link it if we are cross compiling and need an executable
|
||||||
if v.os == LINUX && !linux_host && v.pref.build_mode != BUILD {
|
if v.os == LINUX && !linux_host && v.pref.build_mode != build {
|
||||||
v.out_name = v.out_name.replace('.o', '')
|
v.out_name = v.out_name.replace('.o', '')
|
||||||
obj_file := v.out_name + '.o'
|
obj_file := v.out_name + '.o'
|
||||||
println('linux obj_file=$obj_file out_name=$v.out_name')
|
println('linux obj_file=$obj_file out_name=$v.out_name')
|
||||||
|
@ -707,7 +706,7 @@ fn (v mut V) add_user_v_files() {
|
||||||
p.parse()
|
p.parse()
|
||||||
}
|
}
|
||||||
// Parse lib imports
|
// Parse lib imports
|
||||||
if v.pref.build_mode == DEFAULT_MODE {
|
if v.pref.build_mode == default_mode {
|
||||||
for i := 0; i < v.table.imports.len; i++ {
|
for i := 0; i < v.table.imports.len; i++ {
|
||||||
pkg := v.table.imports[i]
|
pkg := v.table.imports[i]
|
||||||
vfiles := v.v_files_from_dir('$TmpPath/vlib/$pkg')
|
vfiles := v.v_files_from_dir('$TmpPath/vlib/$pkg')
|
||||||
|
@ -742,7 +741,7 @@ fn (v mut V) add_user_v_files() {
|
||||||
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
// If we are in default mode, we don't parse vlib .v files, but header .vh files in
|
||||||
// TmpPath/vlib
|
// TmpPath/vlib
|
||||||
// These were generated by vfmt
|
// These were generated by vfmt
|
||||||
if v.pref.build_mode == DEFAULT_MODE || v.pref.build_mode == BUILD {
|
if v.pref.build_mode == default_mode || v.pref.build_mode == build {
|
||||||
module_path = '$TmpPath/vlib/$pkg'
|
module_path = '$TmpPath/vlib/$pkg'
|
||||||
}
|
}
|
||||||
vfiles := v.v_files_from_dir(module_path)
|
vfiles := v.v_files_from_dir(module_path)
|
||||||
|
@ -794,9 +793,9 @@ fn new_v(args[]string) *V {
|
||||||
target_os := get_arg(joined_args, 'os', '')
|
target_os := get_arg(joined_args, 'os', '')
|
||||||
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
||||||
// build mode
|
// build mode
|
||||||
mut build_mode := DEFAULT_MODE
|
mut build_mode := default_mode
|
||||||
if args.contains('-lib') {
|
if args.contains('-lib') {
|
||||||
build_mode = BUILD
|
build_mode = build
|
||||||
// v -lib ~/v/os => os.o
|
// v -lib ~/v/os => os.o
|
||||||
base := dir.all_after('/')
|
base := dir.all_after('/')
|
||||||
println('Building module ${base}...')
|
println('Building module ${base}...')
|
||||||
|
@ -810,7 +809,7 @@ fn new_v(args[]string) *V {
|
||||||
}
|
}
|
||||||
// TODO embed_vlib is temporarily the default mode. It's much slower.
|
// TODO embed_vlib is temporarily the default mode. It's much slower.
|
||||||
else if !args.contains('-embed_vlib') {
|
else if !args.contains('-embed_vlib') {
|
||||||
build_mode = EMBED_VLIB
|
build_mode = embed_vlib
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
is_test := dir.ends_with('_test.v')
|
is_test := dir.ends_with('_test.v')
|
||||||
|
@ -897,7 +896,7 @@ fn new_v(args[]string) *V {
|
||||||
for builtin in builtins {
|
for builtin in builtins {
|
||||||
mut f := '$lang_dir/vlib/builtin/$builtin'
|
mut f := '$lang_dir/vlib/builtin/$builtin'
|
||||||
// In default mode we use precompiled vlib.o, point to .vh files with signatures
|
// In default mode we use precompiled vlib.o, point to .vh files with signatures
|
||||||
if build_mode == DEFAULT_MODE || build_mode == BUILD {
|
if build_mode == default_mode || build_mode == build {
|
||||||
f = '$TmpPath/vlib/builtin/${builtin}h'
|
f = '$TmpPath/vlib/builtin/${builtin}h'
|
||||||
}
|
}
|
||||||
files << f
|
files << f
|
||||||
|
|
|
@ -2666,7 +2666,7 @@ fn (p mut Parser) chash() {
|
||||||
else if hash.contains('embed') {
|
else if hash.contains('embed') {
|
||||||
pos := hash.index('embed') + 5
|
pos := hash.index('embed') + 5
|
||||||
file := hash.right(pos)
|
file := hash.right(pos)
|
||||||
if p.pref.build_mode != DEFAULT_MODE {
|
if p.pref.build_mode != default_mode {
|
||||||
p.genln('#include $file')
|
p.genln('#include $file')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue