diff --git a/doc/docs.md b/doc/docs.md index 27d36d13a7..31cab5d38d 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -1752,7 +1752,7 @@ Global variables are not allowed, so this can be really useful. When naming constants, `snake_case` must be used. In order to distinguish consts from local variables, the full path to consts must be specified. For example, to access the PI const, full `math.pi` name must be used both outside the `math` -module, and inside it. That restriction is relaxed only for the `main` module +module, and inside it. That restriction is relaxed only for the `main` module (the one containing your `fn main()`, where you can use the shorter name of the constants too, i.e. just `println(numbers)`, not `println(main.numbers)` . @@ -3413,7 +3413,7 @@ single block. `customflag` should be a snake_case identifier, it can not contain arbitrary characters (only lower case latin letters + numbers + `_`). NB: a combinatorial `_d_customflag_linux.c.v` postfix will not work. If you do need a custom flag file, that has platform dependent code, use the -postfix `_d_customflag.v`, and then use plaftorm dependent compile time +postfix `_d_customflag.v`, and then use plaftorm dependent compile time conditional blocks inside it, i.e. `$if linux {}` etc. ## Compile time pseudo variables diff --git a/vlib/math/big/big.v b/vlib/math/big/big.v index ccfbed1cb3..f8b4a94575 100644 --- a/vlib/math/big/big.v +++ b/vlib/math/big/big.v @@ -4,6 +4,7 @@ module big #flag -I @VROOT/thirdparty/bignum #flag @VROOT/thirdparty/bignum/bn.o #include "bn.h" + struct C.bn { mut: array [32]u32 diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index fe40e3a4f8..34a6074ddd 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -2,6 +2,7 @@ module os #include // #include #include + struct C.dirent { d_name [256]char } diff --git a/vlib/os/os_darwin.c.v b/vlib/os/os_darwin.c.v index 7b0a0cd769..8635c63644 100644 --- a/vlib/os/os_darwin.c.v +++ b/vlib/os/os_darwin.c.v @@ -4,6 +4,7 @@ module os #include "@VROOT/vlib/os/os_darwin.m" + pub const ( sys_write = 4 sys_open = 5 diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index a44cf63487..30d4cfa3ce 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -6,6 +6,7 @@ import strings #include #include #include + pub const ( path_separator = '/' path_delimiter = ':' diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 10c6206fdb..8017dac138 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -3,6 +3,7 @@ module os import strings #include + pub const ( path_separator = '\\' path_delimiter = ';' diff --git a/vlib/time/time.v b/vlib/time/time.v index 2711d7493b..248fe9e940 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -4,6 +4,7 @@ module time #include + const ( days_string = 'MonTueWedThuFriSatSun' month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] diff --git a/vlib/time/time_darwin.c.v b/vlib/time/time_darwin.c.v index 7450fd61c8..dc92c02175 100644 --- a/vlib/time/time_darwin.c.v +++ b/vlib/time/time_darwin.c.v @@ -1,6 +1,7 @@ module time #include + const ( // start_time is needed on Darwin and Windows because of potential overflows start_time = C.mach_absolute_time() diff --git a/vlib/time/time_nix.c.v b/vlib/time/time_nix.c.v index 65ee96da26..8c5e5759b0 100644 --- a/vlib/time/time_nix.c.v +++ b/vlib/time/time_nix.c.v @@ -4,6 +4,7 @@ module time #include + struct C.tm { tm_sec int tm_min int diff --git a/vlib/time/time_windows.c.v b/vlib/time/time_windows.c.v index 0bda65251a..2e5f7b1660 100644 --- a/vlib/time/time_windows.c.v +++ b/vlib/time/time_windows.c.v @@ -5,6 +5,7 @@ module time #include // #include + struct C.tm { tm_year int tm_mon int diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index baf3cae284..240c56e461 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -7,6 +7,7 @@ import v.cflag #flag windows -l shell32 #flag windows -l dbghelp #flag windows -l advapi32 + struct MsvcResult { full_cl_exe_path string exe_path string diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 3a7cc9a40e..b815f5a4d7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -295,6 +295,9 @@ pub fn (f Fmt) imp_stmt_str(imp ast.Import) string { fn (mut f Fmt) should_insert_newline_before_stmt(stmt ast.Stmt, prev_stmt ast.Stmt) bool { prev_line_nr := prev_stmt.position().last_line + if prev_stmt is ast.HashStmt && stmt !is ast.HashStmt && stmt !is ast.ExprStmt { + return true + } // The stmt either has or shouldn't have a newline before if stmt.position().line_nr - prev_line_nr <= 1 || f.out.last_n(2) == '\n\n' { return false diff --git a/vlib/v/fmt/tests/hashstmt_expected.vv b/vlib/v/fmt/tests/hashstmt_expected.vv new file mode 100644 index 0000000000..057d14ae2a --- /dev/null +++ b/vlib/v/fmt/tests/hashstmt_expected.vv @@ -0,0 +1,3 @@ +#include "header.h" + +struct Foo {} diff --git a/vlib/v/fmt/tests/hashstmt_input.vv b/vlib/v/fmt/tests/hashstmt_input.vv new file mode 100644 index 0000000000..406f30a0b8 --- /dev/null +++ b/vlib/v/fmt/tests/hashstmt_input.vv @@ -0,0 +1,2 @@ +#include "header.h" +struct Foo {} diff --git a/vlib/v/fmt/tests/hashstmt_keep.vv b/vlib/v/fmt/tests/hashstmt_keep.vv new file mode 100644 index 0000000000..dd994f54ed --- /dev/null +++ b/vlib/v/fmt/tests/hashstmt_keep.vv @@ -0,0 +1,12 @@ +// comment above HashStmt +#flag -I @VROOT/c +#flag @VROOT/c/implementation.o + +#include "@VROOT/c/implementation.h" + +// comment between with newlines around + +#include "header.h" +// comment between without newlines +#include "sqlite3.h" +// comment directly after the HsahStmt diff --git a/vlib/v/fmt/tests/hashstmts_keep.vv b/vlib/v/fmt/tests/hashstmts_keep.vv deleted file mode 100644 index 4c36edb03e..0000000000 --- a/vlib/v/fmt/tests/hashstmts_keep.vv +++ /dev/null @@ -1,8 +0,0 @@ -// comment above HashStmts -#flag linux -lsdl2 -#include "stdio.h" - -// comment between with newlines around - -#include "header.h" -#include "sqlite3.h" diff --git a/vlib/v/fmt/tests/include_vroot_keep.vv b/vlib/v/fmt/tests/include_vroot_keep.vv deleted file mode 100644 index 7c25f4cfd0..0000000000 --- a/vlib/v/fmt/tests/include_vroot_keep.vv +++ /dev/null @@ -1,3 +0,0 @@ -#flag -I @VROOT/c -#flag @VROOT/c/implementation.o -#include "@VROOT/c/implementation.h"