rename to \@CCOMPILER, add \@BACKEND

This commit is contained in:
kbkpbot 2025-08-26 22:44:30 +08:00
parent d2eb2dfc7f
commit c8133b7ad7
6 changed files with 22 additions and 10 deletions

View file

@ -6139,7 +6139,8 @@ that are substituted at compile time:
- `@BUILD_TIME` => replaced with the build time, for example '12:32:07' . - `@BUILD_TIME` => replaced with the build time, for example '12:32:07' .
- `@BUILD_TIMESTAMP` => replaced with the build timestamp, for example '1726219885' . - `@BUILD_TIMESTAMP` => replaced with the build timestamp, for example '1726219885' .
- `@OS` => replaced with the OS type, for example 'linux' . - `@OS` => replaced with the OS type, for example 'linux' .
- `@COMPILER` => replaced with the C compiler type, for example 'gcc' . - `@CCOMPILER` => replaced with the C compiler type, for example 'gcc' .
- `@BACKEND` => replaced with current language backend, for example 'c' or 'golang' .
- `@PLATFORM` => replaced with the platform type, for example 'amd64' . - `@PLATFORM` => replaced with the platform type, for example 'amd64' .
Note: `@BUILD_DATE`, `@BUILD_TIME`, `@BUILD_TIMESTAMP` represent times in the UTC timezone. Note: `@BUILD_DATE`, `@BUILD_TIME`, `@BUILD_TIMESTAMP` represent times in the UTC timezone.
By default, they are based on the current time of the compilation/build. They can be overridden By default, they are based on the current time of the compilation/build. They can be overridden

View file

@ -4033,9 +4033,12 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
.os { .os {
node.val = pref.get_host_os().lower() node.val = pref.get_host_os().lower()
} }
.compiler { .ccompiler {
node.val = c.pref.ccompiler_type.str() node.val = c.pref.ccompiler_type.str()
} }
.backend {
node.val = c.pref.backend.str()
}
.platform { .platform {
node.val = c.pref.arch.str() node.val = c.pref.arch.str()
} }

View file

@ -512,7 +512,8 @@ fn (mut p Parser) at() ast.AtExpr {
'@BUILD_TIME' { token.AtKind.build_time } '@BUILD_TIME' { token.AtKind.build_time }
'@BUILD_TIMESTAMP' { token.AtKind.build_timestamp } '@BUILD_TIMESTAMP' { token.AtKind.build_timestamp }
'@OS' { token.AtKind.os } '@OS' { token.AtKind.os }
'@COMPILER' { token.AtKind.compiler } '@CCOMPILER' { token.AtKind.ccompiler }
'@BACKEND' { token.AtKind.backend }
'@PLATFORM' { token.AtKind.platform } '@PLATFORM' { token.AtKind.platform }
else { token.AtKind.unknown } else { token.AtKind.unknown }
} }

View file

@ -5,5 +5,5 @@ vlib/v/scanner/tests/unknown_comptime_var_err.vv:2:9: error: @ must be used befo
3 | } 3 | }
Details: available compile time variables: @VROOT, @VMODROOT, @VEXEROOT, @FN, @METHOD, @MOD, Details: available compile time variables: @VROOT, @VMODROOT, @VEXEROOT, @FN, @METHOD, @MOD,
@STRUCT, @VEXE, @FILE, @DIR, @LINE, @COLUMN, @VHASH, @VCURRENTHASH, @VMOD_FILE, @VMODHASH, @STRUCT, @VEXE, @FILE, @DIR, @LINE, @COLUMN, @VHASH, @VCURRENTHASH, @VMOD_FILE, @VMODHASH,
@FILE_LINE, @LOCATION, @BUILD_DATE, @BUILD_TIME, @BUILD_TIMESTAMP, @OS, @COMPILER, @FILE_LINE, @LOCATION, @BUILD_DATE, @BUILD_TIME, @BUILD_TIMESTAMP, @OS, @CCOMPILER,
@PLATFORM @BACKEND, @PLATFORM

View file

@ -206,9 +206,15 @@ fn test_at_os() {
'js_node', 'js_freestanding', 'js_browser'] 'js_node', 'js_freestanding', 'js_browser']
} }
fn test_at_compiler() { fn test_at_ccompiler() {
println('Current Compiler is ${@COMPILER}') println('Current C Compiler is ${@CCOMPILER}')
assert @COMPILER in ['gcc', 'tinyc', 'clang', 'emcc', 'mingw', 'msvc', 'cplusplus'] assert @CCOMPILER in ['gcc', 'tinyc', 'clang', 'emcc', 'mingw', 'msvc', 'cplusplus']
}
fn test_at_backend() {
println('Current language backend is ${@BACKEND}')
assert @BACKEND in ['c', 'golang', 'interpret', 'js_node', 'js_browser', 'js_freestanding',
'native', 'wasm']
} }
fn test_at_platform() { fn test_at_platform() {

View file

@ -190,7 +190,8 @@ pub enum AtKind {
build_time build_time
build_timestamp build_timestamp
os os
compiler ccompiler
backend
platform platform
} }
@ -201,7 +202,7 @@ pub const assign_tokens = [Kind.assign, .decl_assign, .plus_assign, .minus_assig
pub const valid_at_tokens = ['@VROOT', '@VMODROOT', '@VEXEROOT', '@FN', '@METHOD', '@MOD', '@STRUCT', pub const valid_at_tokens = ['@VROOT', '@VMODROOT', '@VEXEROOT', '@FN', '@METHOD', '@MOD', '@STRUCT',
'@VEXE', '@FILE', '@DIR', '@LINE', '@COLUMN', '@VHASH', '@VCURRENTHASH', '@VMOD_FILE', '@VEXE', '@FILE', '@DIR', '@LINE', '@COLUMN', '@VHASH', '@VCURRENTHASH', '@VMOD_FILE',
'@VMODHASH', '@FILE_LINE', '@LOCATION', '@BUILD_DATE', '@BUILD_TIME', '@BUILD_TIMESTAMP', '@OS', '@VMODHASH', '@FILE_LINE', '@LOCATION', '@BUILD_DATE', '@BUILD_TIME', '@BUILD_TIMESTAMP', '@OS',
'@COMPILER', '@PLATFORM'] '@CCOMPILER', '@BACKEND', '@PLATFORM']
pub const token_str = build_token_str() pub const token_str = build_token_str()