Skip to content

Commit

Permalink
add support for native {}
Browse files Browse the repository at this point in the history
  • Loading branch information
Spydr06 committed Oct 3, 2023
1 parent b1fec3d commit 206ecb2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/ast/comptime_valid_idents.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ pub const (
valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian']
valid_comptime_if_other = ['apk', 'js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
'no_bounds_checking', 'freestanding', 'threads', 'js_node', 'js_browser', 'js_freestanding',
'interpreter', 'es5', 'profile', 'wasm32', 'wasm32_emscripten', 'wasm32_wasi', 'fast_math']
'interpreter', 'es5', 'profile', 'wasm32', 'wasm32_emscripten', 'wasm32_wasi', 'fast_math',
'native']
valid_comptime_not_user_defined = all_valid_comptime_idents()
valid_comptime_compression_types = ['none', 'zlib']
)
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/c/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,9 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) !strin
'wasm32_emscripten' {
return '__EMSCRIPTEN__'
}
'native' {
return '_VNATIVE' // when using the native backend, cgen is inactive
}
// compilers:
'gcc' {
return '__V_GCC__'
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/js/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_option bool) !str
'js' {
return 'true'
}
'native' {
return 'false'
}
// compilers:
'gcc' {
return 'false'
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/native/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ fn (mut g Gen) comptime_ident(name string, is_comptime_option bool) bool {
//
// Other
//
'native' {
true
}
'debug' {
g.pref.is_debug
}
Expand Down
4 changes: 4 additions & 0 deletions vlib/v/gen/native/tests/comptime.vv
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ fn comptime_if() {
println('linux or windows or macos')
}

$if native {
println('using the native backend')
}

os := $if linux || windows || macos {
'linux or windows or macos'
} $else {
Expand Down
1 change: 1 addition & 0 deletions vlib/v/gen/native/tests/comptime.vv.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
linux or windows or macos
using the native backend
linux or windows or macos
custom defines work
printing directly
Expand Down

0 comments on commit 206ecb2

Please sign in to comment.