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 @@...@@ -1,9 +1,9 @@
1use "libc.zig";1use "std.zig";
22
3// purposefully conflicting function with main.zig3// purposefully conflicting function with main.zig
4// but it's private so it should be OK4// but it's private so it should be OK
5fn private_function() {5fn private_function() {
6 puts(c"it works!");6 print_str("OK 1\n");
7}7}
88
9pub fn print_text() {9pub 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 @@...@@ -1,13 +1,14 @@
1export executable "test-multiple-files";1export executable "test-multiple-files";
22
3use "libc.zig";3use "std.zig";
4use "foo.zig";4use "foo.zig";
55
6export fn _start() -> unreachable {6pub 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}
911
10fn private_function() -> unreachable {12fn 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}
8383
84/// Initialize random state with the given seed.84/// Initialize random state with the given seed.
85pub fn rand_init(seed: u32) -> (out: Rand) {85pub 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) {
144144
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";147use "std.zig";
148 use "foo.zig";148use "foo.zig";
149
150 export fn main(argc: i32, argv: &&u8, env: &&u8) -> i32 {
151 private_function();
152 }
153149
154 fn private_function() -> unreachable {150pub 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}
159155
160 add_source_file(tc, "libc.zig", R"SOURCE(156fn 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");
167160
168 add_source_file(tc, "foo.zig", R"SOURCE(161 add_source_file(tc, "foo.zig", R"SOURCE(
169 use "libc.zig";162use "std.zig";
170163
171 // purposefully conflicting function with main source file164// purposefully conflicting function with main.zig
172 // but it's private so it should be OK165// but it's private so it should be OK
173 fn private_function() {166fn private_function() {
174 puts(c"OK");167 print_str("OK 1\n");
175 }168}
176169
177 pub fn print_text() {170pub fn print_text() {
178 private_function();171 private_function();
179 }172}
180 )SOURCE");173 )SOURCE");
181 }174 }
182175