-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
comptime: add
vfmt
support, tests, CI job for $compile_value
- Loading branch information
Showing
14 changed files
with
172 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Time CI | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'vlib/**' | ||
- '**/comptime_ci.yml' | ||
- '!**.md' | ||
pull_request: | ||
paths: | ||
- 'vlib/**' | ||
- '**/comptime_ci.yml' | ||
- '!**.md' | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test-comptime-linux: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build V | ||
run: make | ||
- name: Test -cv values | ||
run: ./v -cv my_f64=2.0 -cv my_int=3 -cv my_string="a four" -cv my_bool=true -cv my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
- name: Test -compile-value values | ||
run: ./v -compile-value my_f64=2.0 -compile-value my_int=3 -compile-value my_string="a four" -compile-value my_bool=true -compile-value my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
|
||
test-comptime-macos: | ||
runs-on: macos-14 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build V | ||
run: make | ||
- name: Test -cv values | ||
run: ./v -cv my_f64=2.0 -cv my_int=3 -cv my_string="a four" -cv my_bool=true -cv my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
- name: Test -compile-value values | ||
run: ./v -compile-value my_f64=2.0 -compile-value my_int=3 -compile-value my_string="a four" -compile-value my_bool=true -compile-value my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
|
||
test-time-windows: | ||
runs-on: windows-2019 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build V | ||
run: .\make.bat | ||
- name: Test -cv values | ||
run: ./v -cv my_f64=2.0 -cv my_int=3 -cv my_string="a four" -cv my_bool=true -cv my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
- name: Test -compile-value values | ||
run: ./v -compile-value my_f64=2.0 -compile-value my_int=3 -compile-value my_string="a four" -compile-value my_bool=true -compile-value my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
vlib/v/checker/tests/comptime_const/using_comptime_const.vv
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
vlib/v/checker/tests/comptime_value/default_comptime_values_test.v
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const my_f64 = $compile_value('my_f64', 1.0) | ||
const my_int = $compile_value('my_int', 2) | ||
const my_string = $compile_value('my_string', 'three') | ||
const my_bool = $compile_value('my_bool', false) | ||
const my_char = $compile_value('my_char', `f`) | ||
|
||
fn test_default_compile_values() { | ||
assert my_f64 == 1.0 | ||
assert my_int == 2 | ||
assert my_string == 'three' | ||
assert my_bool == false | ||
assert my_char == `f` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vlib/v/checker/tests/comptime_value/parser_errors_1.vv:1:16: error: -cv/-compile-value values can only be pure literals | ||
1 | const my_f32 = $compile_value('my_f32', f32(42.0)) | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const my_f32 = $compile_value('my_f32', f32(42.0)) |
15 changes: 15 additions & 0 deletions
15
vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// This file should pass if compiled/run with: | ||
// v -cv my_f64=2.0 -cv my_int=3 -cv my_string="a four" -cv my_bool=true -cv my_char=g run vlib/v/checker/tests/comptime_value/use_flag_comptime_values.vv | ||
const my_f64 = $compile_value('my_f64', 1.0) | ||
const my_int = $compile_value('my_int', 2) | ||
const my_string = $compile_value('my_string', 'three') | ||
const my_bool = $compile_value('my_bool', false) | ||
const my_char = $compile_value('my_char', `f`) | ||
|
||
fn main() { | ||
assert my_f64 == 2.0 | ||
assert my_int == 3 | ||
assert my_string == 'a four' | ||
assert my_bool == true | ||
assert my_char == `g` | ||
} |
3 changes: 3 additions & 0 deletions
3
vlib/v/checker/tests/comptime_value/using_comptime_value.run.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
42.0 | ||
false | ||
done |
11 changes: 11 additions & 0 deletions
11
vlib/v/checker/tests/comptime_value/using_comptime_value.vv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// TODO: support #flag -I $const('my_flag','flag_value')/xyz | ||
// TODO: support #include "$const('my_include','/usr/include')/stdio.h" | ||
|
||
const my_f64 = $compile_value('my_f64', 42.0) | ||
|
||
fn main() { | ||
println(my_f64) | ||
cv_bool := $compile_value('my_bool', false) | ||
println(cv_bool) | ||
println('done') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
fn main() { | ||
val_str := $compile_value('key_str', 'value') | ||
val_f64 := $compile_value('key_f64', 42.0) | ||
val_int := $compile_value('key_int', 56) | ||
val_bool := $compile_value('key_bool', false) | ||
val_char := $compile_value('key_char', `f`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters