| author | |
| committer | |
| log | 333a3221275a7bea929f9eb1e2642043027c25f1 |
| tree | 7db1e8a705dbcf3ad41fe802125a729fe556782d |
| parent | e64c0941f9cff66311c969b85be5fe5575c4ce45 |
5 files changed, 32 insertions(+), 43 deletions(-)
example/multiple_files/foo.zig+2-2| ... | @@ -1,9 +1,9 @@ | ... | @@ -1,9 +1,9 @@ |
| 1 | use "libc.zig"; | 1 | use "std.zig"; |
| 2 | 2 | ||
| 3 | // purposefully conflicting function with main.zig | 3 | // purposefully conflicting function with main.zig |
| 4 | // but it's private so it should be OK | 4 | // but it's private so it should be OK |
| 5 | fn private_function() { | 5 | fn private_function() { |
| 6 | puts(c"it works!"); | 6 | print_str("OK 1\n"); |
| 7 | } | 7 | } |
| 8 | 8 | ||
| 9 | pub fn print_text() { | 9 | pub fn print_text() { |
example/multiple_files/libc.zig deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | #link("c") | ||
| 2 | extern { | ||
| 3 | pub fn puts(s: &const u8) -> i32; | ||
| 4 | pub fn exit(code: i32) -> unreachable; | ||
| 5 | } | ||
example/multiple_files/main.zig+5-4| ... | @@ -1,13 +1,14 @@ | ... | @@ -1,13 +1,14 @@ |
| 1 | export executable "test-multiple-files"; | 1 | export executable "test-multiple-files"; |
| 2 | 2 | ||
| 3 | use "libc.zig"; | 3 | use "std.zig"; |
| 4 | use "foo.zig"; | 4 | use "foo.zig"; |
| 5 | 5 | ||
| 6 | export fn _start() -> unreachable { | 6 | pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { |
| 7 | private_function(); | 7 | private_function(); |
| 8 | print_str("OK 2\n"); | ||
| 9 | return 0; | ||
| 8 | } | 10 | } |
| 9 | 11 | ||
| 10 | fn private_function() -> unreachable { | 12 | fn private_function() { |
| 11 | print_text(); | 13 | print_text(); |
| 12 | exit(0); | ||
| 13 | } | 14 | } |
example/rand/main.zig+5-5| ... | @@ -82,13 +82,13 @@ struct Rand { | ... | @@ -82,13 +82,13 @@ struct Rand { |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | /// Initialize random state with the given seed. | 84 | /// Initialize random state with the given seed. |
| 85 | pub fn rand_init(seed: u32) -> (out: Rand) { | 85 | pub fn rand_init(r: &Rand, seed: u32) { |
| 86 | out.index = 0; | 86 | r.index = 0; |
| 87 | out.array[0] = seed; | 87 | r.array[0] = seed; |
| 88 | var i : #typeof(ARRAY_SIZE) = 1; | 88 | var i : #typeof(ARRAY_SIZE) = 1; |
| 89 | while (i < ARRAY_SIZE) { | 89 | while (i < ARRAY_SIZE) { |
| 90 | const prev_value : u64 = out.array[i - 1]; | 90 | const prev_value : u64 = r.array[i - 1]; |
| 91 | out.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32; | 91 | r.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32; |
| 92 | i += 1; | 92 | i += 1; |
| 93 | } | 93 | } |
| 94 | } | 94 | } |
test/run_tests.cpp+20-27| ... | @@ -144,39 +144,32 @@ static void add_compiling_test_cases(void) { | ... | @@ -144,39 +144,32 @@ static void add_compiling_test_cases(void) { |
| 144 | 144 | ||
| 145 | { | 145 | { |
| 146 | TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE( | 146 | TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE( |
| 147 | use "libc.zig"; | 147 | use "std.zig"; |
| 148 | use "foo.zig"; | 148 | use "foo.zig"; |
| 149 | |||
| 150 | export fn main(argc: i32, argv: &&u8, env: &&u8) -> i32 { | ||
| 151 | private_function(); | ||
| 152 | } | ||
| 153 | 149 | ||
| 154 | fn private_function() -> unreachable { | 150 | pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 { |
| 155 | print_text(); | 151 | private_function(); |
| 156 | exit(0); | 152 | print_str("OK 2\n"); |
| 157 | } | 153 | return 0; |
| 158 | )SOURCE", "OK\n"); | 154 | } |
| 159 | 155 | ||
| 160 | add_source_file(tc, "libc.zig", R"SOURCE( | 156 | fn private_function() { |
| 161 | #link("c") | 157 | print_text(); |
| 162 | extern { | 158 | } |
| 163 | pub fn puts(s: &const u8) -> i32; | 159 | )SOURCE", "OK 1\nOK 2\n"); |
| 164 | pub fn exit(code: i32) -> unreachable; | ||
| 165 | } | ||
| 166 | )SOURCE"); | ||
| 167 | 160 | ||
| 168 | add_source_file(tc, "foo.zig", R"SOURCE( | 161 | add_source_file(tc, "foo.zig", R"SOURCE( |
| 169 | use "libc.zig"; | 162 | use "std.zig"; |
| 170 | 163 | ||
| 171 | // purposefully conflicting function with main source file | 164 | // purposefully conflicting function with main.zig |
| 172 | // but it's private so it should be OK | 165 | // but it's private so it should be OK |
| 173 | fn private_function() { | 166 | fn private_function() { |
| 174 | puts(c"OK"); | 167 | print_str("OK 1\n"); |
| 175 | } | 168 | } |
| 176 | 169 | ||
| 177 | pub fn print_text() { | 170 | pub fn print_text() { |
| 178 | private_function(); | 171 | private_function(); |
| 179 | } | 172 | } |
| 180 | )SOURCE"); | 173 | )SOURCE"); |
| 181 | } | 174 | } |
| 182 | 175 |