v: add support for `$if freestanding {`, without using it (part 1) (#9656)
parent
f0a67a4813
commit
903dd49212
|
@ -3700,8 +3700,8 @@ Full list of builtin options:
|
|||
| --- | --- | --- | --- |
|
||||
| `windows`, `linux`, `macos` | `gcc`, `tinyc` | `amd64`, `aarch64` | `debug`, `prod`, `test` |
|
||||
| `mac`, `darwin`, `ios`, | `clang`, `mingw` | `x64`, `x32` | `js`, `glibc`, `prealloc` |
|
||||
| `android`,`mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking` |
|
||||
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` | |
|
||||
| `android`,`mach`, `dragonfly` | `msvc` | `little_endian` | `no_bounds_checking`, `freestanding` |
|
||||
| `gnu`, `hpux`, `haiku`, `qnx` | `cplusplus` | `big_endian` |
|
||||
| `solaris`, `linux_or_macos` | | | |
|
||||
|
||||
#### $embed_file
|
||||
|
|
|
@ -198,15 +198,15 @@ pub fn (v Builder) get_builtin_files() []string {
|
|||
for location in v.pref.lookup_path {
|
||||
if os.exists(os.join_path(location, 'builtin')) {
|
||||
mut builtin_files := []string{}
|
||||
if v.pref.is_bare {
|
||||
builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin',
|
||||
'bare'))
|
||||
} else if v.pref.backend == .js {
|
||||
if v.pref.backend == .js {
|
||||
builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin',
|
||||
'js'))
|
||||
} else {
|
||||
builtin_files << v.v_files_from_dir(os.join_path(location, 'builtin'))
|
||||
}
|
||||
if v.pref.is_bare {
|
||||
builtin_files << v.v_files_from_dir(v.pref.bare_builtin_dir)
|
||||
}
|
||||
if v.pref.backend == .c {
|
||||
// TODO JavaScript backend doesn't handle os for now
|
||||
if v.pref.is_vsh && os.exists(os.join_path(location, 'os')) {
|
||||
|
|
|
@ -25,8 +25,7 @@ const (
|
|||
valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
|
||||
valid_comp_if_platforms = ['amd64', 'aarch64', 'x64', 'x32', 'little_endian', 'big_endian']
|
||||
valid_comp_if_other = ['js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
|
||||
'no_bounds_checking',
|
||||
]
|
||||
'no_bounds_checking', 'freestanding']
|
||||
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort',
|
||||
'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop']
|
||||
)
|
||||
|
@ -5582,6 +5581,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
|
|||
'glibc' { return false } // TODO
|
||||
'prealloc' { return !c.pref.prealloc }
|
||||
'no_bounds_checking' { return cond.name !in c.pref.compile_defines_all }
|
||||
'freestanding' { return !c.pref.is_bare }
|
||||
else { return false }
|
||||
}
|
||||
} else if cond.name !in c.pref.compile_defines_all {
|
||||
|
|
|
@ -575,6 +575,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string
|
|||
'no_bounds_checking' {
|
||||
return 'CUSTOM_DEFINE_no_bounds_checking'
|
||||
}
|
||||
'freestanding' {
|
||||
return '_VFREESTANDING'
|
||||
}
|
||||
// architectures:
|
||||
'amd64' {
|
||||
return '__V_amd64'
|
||||
|
|
|
@ -130,6 +130,9 @@ pub fn (mut p Preferences) fill_with_defaults() {
|
|||
// eprintln('-usecache and -shared flags are not compatible')
|
||||
p.use_cache = false
|
||||
}
|
||||
if p.bare_builtin_dir == '' {
|
||||
p.bare_builtin_dir = os.join_path(p.vroot, 'vlib', 'builtin', 'linux_bare')
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut p Preferences) find_cc_if_cross_compiling() {
|
||||
|
|
|
@ -123,19 +123,20 @@ pub mut:
|
|||
// This is on by default, since a vast majority of users do not
|
||||
// work on the builtin module itself.
|
||||
// generating_vh bool
|
||||
enable_globals bool // allow __global for low level code
|
||||
is_fmt bool
|
||||
is_vet bool
|
||||
is_bare bool
|
||||
no_preludes bool // Prevents V from generating preludes in resulting .c files
|
||||
custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files
|
||||
lookup_path []string
|
||||
output_cross_c bool
|
||||
prealloc bool
|
||||
vroot string
|
||||
out_name_c string // full os.real_path to the generated .tmp.c file; set by builder.
|
||||
out_name string
|
||||
path string // Path to file/folder to compile
|
||||
enable_globals bool // allow __global for low level code
|
||||
is_fmt bool
|
||||
is_vet bool
|
||||
is_bare bool
|
||||
no_preludes bool // Prevents V from generating preludes in resulting .c files
|
||||
custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files
|
||||
lookup_path []string
|
||||
bare_builtin_dir string // Path to implementation of malloc, memset, etc. Only used if is_bare is true
|
||||
output_cross_c bool
|
||||
prealloc bool
|
||||
vroot string
|
||||
out_name_c string // full os.real_path to the generated .tmp.c file; set by builder.
|
||||
out_name string
|
||||
path string // Path to file/folder to compile
|
||||
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another ? { will NOT get here }`
|
||||
compile_defines []string // just ['vfmt']
|
||||
compile_defines_all []string // contains both: ['vfmt','another']
|
||||
|
@ -464,6 +465,12 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
|
|||
res.lookup_path = path.replace('|', os.path_delimiter).split(os.path_delimiter)
|
||||
i++
|
||||
}
|
||||
'-bare-builtin-dir' {
|
||||
bare_builtin_dir := cmdline.option(current_args, arg, '')
|
||||
res.build_options << '$arg "$bare_builtin_dir"'
|
||||
res.bare_builtin_dir = bare_builtin_dir
|
||||
i++
|
||||
}
|
||||
'-custom-prelude' {
|
||||
path := cmdline.option(current_args, '-custom-prelude', '')
|
||||
res.build_options << '$arg $path'
|
||||
|
|
|
@ -8,6 +8,9 @@ pub fn (prefs &Preferences) should_compile_filtered_files(dir string, files_ []s
|
|||
files.sort()
|
||||
mut all_v_files := []string{}
|
||||
for file in files {
|
||||
if prefs.is_bare && os.join_path(dir, file).ends_with('/vlib/builtin/builtin_nix.c.v') {
|
||||
continue
|
||||
}
|
||||
if !file.ends_with('.v') && !file.ends_with('.vh') {
|
||||
continue
|
||||
}
|
||||
|
@ -123,6 +126,9 @@ pub fn (prefs &Preferences) should_compile_c(file string) bool {
|
|||
if prefs.os == .all {
|
||||
return true
|
||||
}
|
||||
if !prefs.is_bare && file.ends_with('.freestanding.v') {
|
||||
return false
|
||||
}
|
||||
if (file.ends_with('_windows.c.v') || file.ends_with('_windows.v')) && prefs.os != .windows {
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue