Skip to content

Commit

Permalink
cgen: add autofree comptime check (#21197)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Apr 7, 2024
1 parent 01a9448 commit d692d88
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vlib/v/ast/comptime_valid_idents.v
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub const valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_
pub const 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',
'native']
'native', 'autofree']
pub const valid_comptime_not_user_defined = all_valid_comptime_idents()
pub const valid_comptime_compression_types = ['none', 'zlib']

Expand Down
3 changes: 3 additions & 0 deletions vlib/v/checker/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,9 @@ fn (mut c Checker) comptime_if_branch(mut cond ast.Expr, pos token.Pos) Comptime
'no_bounds_checking' {
return if cname in c.pref.compile_defines_all { .eval } else { .skip }
}
'autofree' {
return if c.pref.autofree { .eval } else { .skip }
}
'freestanding' {
return if c.pref.is_bare && !c.pref.output_cross_c { .eval } else { .skip }
}
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 @@ -1098,6 +1098,9 @@ fn (mut g Gen) comptime_if_to_ifdef(name string, is_comptime_option bool) !strin
'freestanding' {
return '_VFREESTANDING'
}
'autofree' {
return '_VAUTOFREE'
}
// architectures:
'amd64' {
return '__V_amd64'
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 @@ -286,6 +286,9 @@ fn (mut g JsGen) comptime_if_to_ifdef(name string, is_comptime_option bool) !str
'freestanding' {
return '_VFREESTANDING'
}
'autofree' {
return '_VAUTOFREE'
}
// architectures:
'amd64' {
return '(\$process.arch == "x64")'
Expand Down

0 comments on commit d692d88

Please sign in to comment.