Commit 333a322127
Changed files (5)
test
example/multiple_files/foo.zig
@@ -1,9 +1,9 @@
-use "libc.zig";
+use "std.zig";
// purposefully conflicting function with main.zig
// but it's private so it should be OK
fn private_function() {
- puts(c"it works!");
+ print_str("OK 1\n");
}
pub fn print_text() {
example/multiple_files/libc.zig
@@ -1,5 +0,0 @@
-#link("c")
-extern {
- pub fn puts(s: &const u8) -> i32;
- pub fn exit(code: i32) -> unreachable;
-}
example/multiple_files/main.zig
@@ -1,13 +1,14 @@
export executable "test-multiple-files";
-use "libc.zig";
+use "std.zig";
use "foo.zig";
-export fn _start() -> unreachable {
+pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
private_function();
+ print_str("OK 2\n");
+ return 0;
}
-fn private_function() -> unreachable {
+fn private_function() {
print_text();
- exit(0);
}
example/rand/main.zig
@@ -82,13 +82,13 @@ struct Rand {
}
/// Initialize random state with the given seed.
-pub fn rand_init(seed: u32) -> (out: Rand) {
- out.index = 0;
- out.array[0] = seed;
+pub fn rand_init(r: &Rand, seed: u32) {
+ r.index = 0;
+ r.array[0] = seed;
var i : #typeof(ARRAY_SIZE) = 1;
while (i < ARRAY_SIZE) {
- const prev_value : u64 = out.array[i - 1];
- out.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32;
+ const prev_value : u64 = r.array[i - 1];
+ r.array[i] = ((previous_value ^ (previous_value << 30)) * 0x6c078965 + i) as u32;
i += 1;
}
}
test/run_tests.cpp
@@ -144,39 +144,32 @@ static void add_compiling_test_cases(void) {
{
TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE(
- use "libc.zig";
- use "foo.zig";
-
- export fn main(argc: i32, argv: &&u8, env: &&u8) -> i32 {
- private_function();
- }
+use "std.zig";
+use "foo.zig";
- fn private_function() -> unreachable {
- print_text();
- exit(0);
- }
- )SOURCE", "OK\n");
+pub fn main(argc: isize, argv: &&u8, env: &&u8) -> i32 {
+ private_function();
+ print_str("OK 2\n");
+ return 0;
+}
- add_source_file(tc, "libc.zig", R"SOURCE(
- #link("c")
- extern {
- pub fn puts(s: &const u8) -> i32;
- pub fn exit(code: i32) -> unreachable;
- }
- )SOURCE");
+fn private_function() {
+ print_text();
+}
+ )SOURCE", "OK 1\nOK 2\n");
add_source_file(tc, "foo.zig", R"SOURCE(
- use "libc.zig";
+use "std.zig";
- // purposefully conflicting function with main source file
- // but it's private so it should be OK
- fn private_function() {
- puts(c"OK");
- }
+// purposefully conflicting function with main.zig
+// but it's private so it should be OK
+fn private_function() {
+ print_str("OK 1\n");
+}
- pub fn print_text() {
- private_function();
- }
+pub fn print_text() {
+ private_function();
+}
)SOURCE");
}