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

Refactor BuildMode enum to lowercase

This commit is contained in:
Maulana Akmal 2019-07-01 21:09:16 +07:00 committed by Alexander Medvednikov
parent 32e32cee5c
commit 24b0fd5097
3 changed files with 27 additions and 28 deletions

View File

@ -95,7 +95,7 @@ fn (f mut Fn) clear_vars() {
// vlib header file?
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))
}
@ -173,8 +173,8 @@ fn (p mut Parser) fn_decl() {
// C function header def? (fn C.NSMakeRect(int,int,int,int))
is_c := f.name == 'C' && p.tok == DOT
// Just fn signature? only builtin.v + default build 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.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.is_sig()
// println('\n\nfn decl !!is_sig=$is_sig name=$f.name $p.builtin_pkg')
if is_c {
@ -338,7 +338,7 @@ fn (p mut Parser) fn_decl() {
// Add function definition to the top
if !is_c && f.name != 'main' && p.first_run() {
// 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
}
p.cgen.fns << fn_decl + ';'

View File

@ -11,17 +11,16 @@ const (
Version = '0.1.11'
)
// TODO no caps
enum BuildMode {
// `v program.v'
// 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`
// 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`
// 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 {
@ -243,23 +242,23 @@ void reload_so();
void init_consts();')
imports_json := v.table.imports.contains('json')
// TODO remove global UI hack
if v.os == MAC && ((v.pref.build_mode == EMBED_VLIB && v.table.imports.contains('ui')) ||
(v.pref.build_mode == BUILD && v.dir.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'))) {
cgen.genln('id defaultFont = 0; // main.v')
}
// TODO remove ugly .c include once V has its own json parser
// 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')) {
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" ')
}
// 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 {
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
// `/usr/bin/ld: multiple definition of 'total_m'`
// TODO
@ -304,7 +303,7 @@ void init_consts();')
dd := d.str()
cgen.lines.set(defs_pos, dd)// TODO `def.str()` doesn't compile
// 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()`
cgen.genln('void init_consts() { g_str_buf=malloc(1000); ${cgen.consts_init.join_lines()} }')
// _STR function can't be defined in vlib
@ -344,7 +343,7 @@ string _STR_TMP(const char *fmt, ...) {
}
// Make sure the main function exists
// 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 {
// It can be skipped in single file programs
if v.pref.is_script {
@ -508,13 +507,13 @@ fn (v mut V) cc() {
a << '-g'
}
mut libs := ''// builtin.o os.o http.o etc
if v.pref.build_mode == BUILD {
if v.pref.build_mode == build {
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'
if !os.file_exists(libs) {
println('`builtin.o` not found')
@ -569,7 +568,7 @@ mut args := ''
a << '-x objective-c'
}
// 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'
}
// Find clang executable
@ -596,7 +595,7 @@ mut args := ''
panic('clang error')
}
// 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', '')
obj_file := v.out_name + '.o'
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()
}
// 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++ {
pkg := v.table.imports[i]
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
// TmpPath/vlib
// 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'
}
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', '')
mut out_name := get_arg(joined_args, 'o', 'a.out')
// build mode
mut build_mode := DEFAULT_MODE
mut build_mode := default_mode
if args.contains('-lib') {
build_mode = BUILD
build_mode = build
// v -lib ~/v/os => os.o
base := dir.all_after('/')
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.
else if !args.contains('-embed_vlib') {
build_mode = EMBED_VLIB
build_mode = embed_vlib
}
//
is_test := dir.ends_with('_test.v')
@ -897,7 +896,7 @@ fn new_v(args[]string) *V {
for builtin in builtins {
mut f := '$lang_dir/vlib/builtin/$builtin'
// 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'
}
files << f

View File

@ -2666,7 +2666,7 @@ fn (p mut Parser) chash() {
else if hash.contains('embed') {
pos := hash.index('embed') + 5
file := hash.right(pos)
if p.pref.build_mode != DEFAULT_MODE {
if p.pref.build_mode != default_mode {
p.genln('#include $file')
}
}