authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-04 01:42:09-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-04 01:52:32-07:00
log333a3221275a7bea929f9eb1e2642043027c25f1
tree7db1e8a705dbcf3ad41fe802125a729fe556782d
parente64c0941f9cff66311c969b85be5fe5575c4ce45

multiple files example no longer use libc


5 files changed, 32 insertions(+), 43 deletions(-)

example/multiple_files/foo.zig+2-2
......@@ -1,9 +1,9 @@
1use "libc.zig";
1use "std.zig";
22
33// purposefully conflicting function with main.zig
44// but it's private so it should be OK
55fn private_function() {
6 puts(c"it works!");
6 print_str("OK 1\n");
77}
88
99pub fn print_text() {
example/multiple_files/libc.zig deleted-5
......@@ -1,5 +0,0 @@
1#link("c")
2extern {
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 @@
11export executable "test-multiple-files";
22
3use "libc.zig";
3use "std.zig";
44use "foo.zig";
55
6export fn _start() -> unreachable {
6pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
77 private_function();
8 print_str("OK 2\n");
9 return 0;
810}
911
10fn private_function() -> unreachable {
12fn private_function() {
1113 print_text();
12 exit(0);
1314}
example/rand/main.zig+5-5
......@@ -82,13 +82,13 @@ struct Rand {
8282}
8383
8484/// Initialize random state with the given seed.
85pub fn rand_init(seed: u32) -> (out: Rand) {
86 out.index = 0;
87 out.array[0] = seed;
85pub fn rand_init(r: &Rand, seed: u32) {
86 r.index = 0;
87 r.array[0] = seed;
8888 var i : #typeof(ARRAY_SIZE) = 1;
8989 while (i < ARRAY_SIZE) {
90 const prev_value : u64 = out.array[i - 1];
91 out.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32;
90 const prev_value : u64 = r.array[i - 1];
91 r.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32;
9292 i += 1;
9393 }
9494}
test/run_tests.cpp+20-27
......@@ -144,39 +144,32 @@ static void add_compiling_test_cases(void) {
144144
145145 {
146146 TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE(
147 use "libc.zig";
148 use "foo.zig";
149
150 export fn main(argc: i32, argv: &&u8, env: &&u8) -> i32 {
151 private_function();
152 }
147use "std.zig";
148use "foo.zig";
153149
154 fn private_function() -> unreachable {
155 print_text();
156 exit(0);
157 }
158 )SOURCE", "OK\n");
150pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
151 private_function();
152 print_str("OK 2\n");
153 return 0;
154}
159155
160 add_source_file(tc, "libc.zig", R"SOURCE(
161 #link("c")
162 extern {
163 pub fn puts(s: &const u8) -> i32;
164 pub fn exit(code: i32) -> unreachable;
165 }
166 )SOURCE");
156fn private_function() {
157 print_text();
158}
159 )SOURCE", "OK 1\nOK 2\n");
167160
168161 add_source_file(tc, "foo.zig", R"SOURCE(
169 use "libc.zig";
162use "std.zig";
170163
171 // purposefully conflicting function with main source file
172 // but it's private so it should be OK
173 fn private_function() {
174 puts(c"OK");
175 }
164// purposefully conflicting function with main.zig
165// but it's private so it should be OK
166fn private_function() {
167 print_str("OK 1\n");
168}
176169
177 pub fn print_text() {
178 private_function();
179 }
170pub fn print_text() {
171 private_function();
172}
180173 )SOURCE");
181174 }
182175