From dc162c7f8385d82f1e5513a5412b98ec8c70e993 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 15 Jan 2016 18:45:52 -0700 Subject: [PATCH] rename "use" to "import" --- doc/langref.md | 4 +- example/guess_number/main.zig | 4 +- example/hello_world/hello.zig | 2 +- example/maybe_type/main.zig | 35 ------------- example/multiple_files/foo.zig | 2 +- example/multiple_files/main.zig | 4 +- src/parser.cpp | 2 +- src/tokenizer.cpp | 6 +-- src/tokenizer.hpp | 2 +- std/bootstrap.zig | 2 +- std/std.zig | 2 +- test/run_tests.cpp | 88 ++++++++++++++++----------------- 12 files changed, 59 insertions(+), 94 deletions(-) delete mode 100644 example/maybe_type/main.zig diff --git a/doc/langref.md b/doc/langref.md index 647e73e72d..add823a1d8 100644 --- a/doc/langref.md +++ b/doc/langref.md @@ -32,7 +32,7 @@ zig | C equivalent | Description ``` Root : many(TopLevelDecl) token(EOF) -TopLevelDecl : FnDef | ExternBlock | RootExportDecl | Use | ContainerDecl | VariableDeclaration +TopLevelDecl : FnDef | ExternBlock | RootExportDecl | Import | ContainerDecl | VariableDeclaration VariableDeclaration : option(FnVisibleMod) (token(Var) | token(Const)) token(Symbol) (token(Eq) Expression | token(Colon) PrefixOpExpression option(token(Eq) Expression)) @@ -42,7 +42,7 @@ StructMember: StructField | FnDecl StructField : token(Symbol) option(token(Colon) Expression) token(Comma)) -Use : many(Directive) token(Use) token(String) token(Semicolon) +Import : many(Directive) token(Import) token(String) token(Semicolon) RootExportDecl : many(Directive) token(Export) token(Symbol) token(String) token(Semicolon) diff --git a/example/guess_number/main.zig b/example/guess_number/main.zig index 4f469d47b2..f42ff5586f 100644 --- a/example/guess_number/main.zig +++ b/example/guess_number/main.zig @@ -1,7 +1,7 @@ export executable "guess_number"; -use "std.zig"; -use "rand.zig"; +import "std.zig"; +import "rand.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { print_str("Welcome to the Guess Number Game in Zig.\n"); diff --git a/example/hello_world/hello.zig b/example/hello_world/hello.zig index e273f5a812..0b009aee54 100644 --- a/example/hello_world/hello.zig +++ b/example/hello_world/hello.zig @@ -1,6 +1,6 @@ export executable "hello"; -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { print_str("Hello, world!\n"); diff --git a/example/maybe_type/main.zig b/example/maybe_type/main.zig deleted file mode 100644 index 426b5ea95a..0000000000 --- a/example/maybe_type/main.zig +++ /dev/null @@ -1,35 +0,0 @@ -export executable "maybe_type"; - -use "std.zig"; - -pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { - const x : ?bool = true; - - if (const y ?= x) { - if (y) { - print_str("x is true\n"); - } else { - print_str("x is false\n"); - } - } else { - print_str("x is none\n"); - } - - const next_x : ?i32 = null; - - const z = next_x ?? 1234; - - if (z != 1234) { - print_str("BAD\n"); - } - - const final_x : ?i32 = 13; - - const num = final_x ?? unreachable{}; - - if (num != 13) { - print_str("BAD\n"); - } - - return 0; -} diff --git a/example/multiple_files/foo.zig b/example/multiple_files/foo.zig index 5f7484f916..2ab13b2457 100644 --- a/example/multiple_files/foo.zig +++ b/example/multiple_files/foo.zig @@ -1,4 +1,4 @@ -use "std.zig"; +import "std.zig"; // purposefully conflicting function with main.zig // but it's private so it should be OK diff --git a/example/multiple_files/main.zig b/example/multiple_files/main.zig index a29f720b8a..d1f4d80a2e 100644 --- a/example/multiple_files/main.zig +++ b/example/multiple_files/main.zig @@ -1,7 +1,7 @@ export executable "test-multiple-files"; -use "std.zig"; -use "foo.zig"; +import "std.zig"; +import "foo.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { private_function(); diff --git a/src/parser.cpp b/src/parser.cpp index adcbeae830..2b2e8736be 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2542,7 +2542,7 @@ Use : many(Directive) token(Use) token(String) token(Semicolon) */ static AstNode *ast_parse_use(ParseContext *pc, int *token_index) { Token *use_kw = &pc->tokens->at(*token_index); - if (use_kw->id != TokenIdKeywordUse) + if (use_kw->id != TokenIdKeywordImport) return nullptr; *token_index += 1; diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 941126c0a8..2172c0ccbc 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -211,8 +211,8 @@ static void end_token(Tokenize *t) { t->cur_tok->id = TokenIdKeywordPub; } else if (mem_eql_str(token_mem, token_len, "export")) { t->cur_tok->id = TokenIdKeywordExport; - } else if (mem_eql_str(token_mem, token_len, "use")) { - t->cur_tok->id = TokenIdKeywordUse; + } else if (mem_eql_str(token_mem, token_len, "import")) { + t->cur_tok->id = TokenIdKeywordImport; } else if (mem_eql_str(token_mem, token_len, "true")) { t->cur_tok->id = TokenIdKeywordTrue; } else if (mem_eql_str(token_mem, token_len, "false")) { @@ -1017,7 +1017,7 @@ const char * token_name(TokenId id) { case TokenIdKeywordExtern: return "extern"; case TokenIdKeywordPub: return "pub"; case TokenIdKeywordExport: return "export"; - case TokenIdKeywordUse: return "use"; + case TokenIdKeywordImport: return "import"; case TokenIdKeywordTrue: return "true"; case TokenIdKeywordFalse: return "false"; case TokenIdKeywordIf: return "if"; diff --git a/src/tokenizer.hpp b/src/tokenizer.hpp index 32b5c8e754..a7f0ddc506 100644 --- a/src/tokenizer.hpp +++ b/src/tokenizer.hpp @@ -20,7 +20,7 @@ enum TokenId { TokenIdKeywordExtern, TokenIdKeywordPub, TokenIdKeywordExport, - TokenIdKeywordUse, + TokenIdKeywordImport, TokenIdKeywordTrue, TokenIdKeywordFalse, TokenIdKeywordIf, diff --git a/std/bootstrap.zig b/std/bootstrap.zig index 88b84fde52..06191d47e7 100644 --- a/std/bootstrap.zig +++ b/std/bootstrap.zig @@ -1,4 +1,4 @@ -use "syscall.zig"; +import "syscall.zig"; // The compiler treats this file special by implicitly importing the function `main` // from the root source file. diff --git a/std/std.zig b/std/std.zig index c17072284e..28e626cd88 100644 --- a/std/std.zig +++ b/std/std.zig @@ -1,4 +1,4 @@ -use "syscall.zig"; +import "syscall.zig"; pub const stdin_fileno : isize = 0; pub const stdout_fileno : isize = 1; diff --git a/test/run_tests.cpp b/test/run_tests.cpp index 8d85f7782c..d8bb9b51d9 100644 --- a/test/run_tests.cpp +++ b/test/run_tests.cpp @@ -108,8 +108,8 @@ export fn main(argc: i32, argv: &&u8, env: &&u8) i32 => { )SOURCE", "Hello, world!\n"); add_simple_case("function call", R"SOURCE( -use "std.zig"; -use "syscall.zig"; +import "std.zig"; +import "syscall.zig"; fn empty_function_1() => {} fn empty_function_2() => { return; } @@ -127,7 +127,7 @@ fn this_is_a_function() unreachable => { )SOURCE", "OK\n"); add_simple_case("comments", R"SOURCE( -use "std.zig"; +import "std.zig"; /** * multi line doc comment @@ -144,8 +144,8 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { { TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE( -use "std.zig"; -use "foo.zig"; +import "std.zig"; +import "foo.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { private_function(); @@ -159,7 +159,7 @@ fn private_function() => { )SOURCE", "OK 1\nOK 2\n"); add_source_file(tc, "foo.zig", R"SOURCE( -use "std.zig"; +import "std.zig"; // purposefully conflicting function with main.zig // but it's private so it should be OK @@ -175,8 +175,8 @@ pub fn print_text() => { { TestCase *tc = add_simple_case("import segregation", R"SOURCE( -use "foo.zig"; -use "bar.zig"; +import "foo.zig"; +import "bar.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { foo_function(); @@ -186,15 +186,15 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\nOK\n"); add_source_file(tc, "foo.zig", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn foo_function() => { print_str("OK\n"); } )SOURCE"); add_source_file(tc, "bar.zig", R"SOURCE( -use "other.zig"; -use "std.zig"; +import "other.zig"; +import "std.zig"; pub fn bar_function() => { if (foo_function()) { @@ -212,7 +212,7 @@ pub fn foo_function() bool => { } add_simple_case("if statements", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { if (1 != 0) { @@ -233,7 +233,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "1 is true\n!0 is true\n"); add_simple_case("params", R"SOURCE( -use "std.zig"; +import "std.zig"; fn add(a: i32, b: i32) i32 => { a + b @@ -248,7 +248,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "pass\n"); add_simple_case("goto", R"SOURCE( -use "std.zig"; +import "std.zig"; fn loop(a : i32) => { if (a == 0) { @@ -268,7 +268,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "loop\nloop\nloop\n"); add_simple_case("local variables", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { const a : i32 = 1; @@ -281,7 +281,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("bool literals", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { if (true) { print_str("OK 1\n"); } @@ -293,7 +293,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK 1\nOK 2\n"); add_simple_case("separate block scopes", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { if (true) { @@ -311,7 +311,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK 1\nOK 2\n"); add_simple_case("void parameters", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { void_fun(1, void{}, 2); @@ -327,7 +327,7 @@ fn void_fun(a : i32, b : void, c : i32) => { )SOURCE", "OK\n"); add_simple_case("void struct fields", R"SOURCE( -use "std.zig"; +import "std.zig"; struct Foo { a : void, b : i32, @@ -352,7 +352,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("void arrays", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var array: [4]void; @@ -371,7 +371,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { add_simple_case("mutable local variables", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var zero : i32 = 0; @@ -391,7 +391,7 @@ done: )SOURCE", "zero\nloop\nloop\nloop\n"); add_simple_case("arrays", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var array : [5]u32; @@ -427,7 +427,7 @@ fn get_array_len(a: []u32) usize => { add_simple_case("hello world without libc", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { print_str("Hello, world!\n"); @@ -437,7 +437,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { add_simple_case("a + b + c", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { if (false || false || false) { print_str("BAD 1\n"); } @@ -459,7 +459,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("short circuit", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { if (true || { print_str("BAD 1\n"); false }) { @@ -482,7 +482,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "OK 1\nOK 2\nOK 3\nOK 4\n"); add_simple_case("modify operators", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { var i : i32 = 0; @@ -634,7 +634,7 @@ export fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )OUTPUT"); add_simple_case("structs", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { var foo : Foo; @@ -706,7 +706,7 @@ fn test_initializer() => { )SOURCE", "OK\n"); add_simple_case("global variables", R"SOURCE( -use "std.zig"; +import "std.zig"; const g1 : i32 = 1233 + 1; var g2 : i32 = 0; @@ -721,7 +721,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("while loop", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { var i : i32 = 0; while (i < 4) { @@ -738,7 +738,7 @@ fn f() i32 => { )SOURCE", "loop\nloop\nloop\nloop\n"); add_simple_case("continue and break", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { var i : i32 = 0; while (true) { @@ -754,7 +754,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "loop\nloop\nloop\nloop\n"); add_simple_case("maybe type", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { const x : ?bool = true; @@ -789,7 +789,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "x is true\n"); add_simple_case("implicit cast after unreachable", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { const x = outer(); if (x == 1234) { @@ -804,7 +804,7 @@ fn outer() isize => { )SOURCE", "OK\n"); add_simple_case("@sizeof() and @typeof()", R"SOURCE( -use "std.zig"; +import "std.zig"; const x: u16 = 13; const z: @typeof(x) = 19; pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { @@ -816,7 +816,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "2\n"); add_simple_case("member functions", R"SOURCE( -use "std.zig"; +import "std.zig"; struct Rand { seed: u32, pub fn get_seed(r: Rand) u32 => { @@ -834,7 +834,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("pointer dereferencing", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var x = i32(3); @@ -854,7 +854,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("constant expressions", R"SOURCE( -use "std.zig"; +import "std.zig"; const ARRAY_SIZE : u8 = 20; @@ -867,7 +867,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "20\n"); add_simple_case("#min_value() and #max_value()", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { print_str("max u8: "); print_u64(@max_value(u8)); @@ -955,7 +955,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { add_simple_case("slicing", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var array : [20]i32; @@ -983,7 +983,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { add_simple_case("else if expression", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { if (f(1) == 1) { print_str("OK\n"); @@ -1002,7 +1002,7 @@ fn f(c: u8) u8 => { )SOURCE", "OK\n"); add_simple_case("overflow intrinsics", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var result: u8; if (!@add_with_overflow(u8, 250, 100, &result)) { @@ -1020,7 +1020,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("memcpy and memset intrinsics", R"SOURCE( -use "std.zig"; +import "std.zig"; pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { var foo : [20]u8; var bar : [20]u8; @@ -1038,7 +1038,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => { )SOURCE", "OK\n"); add_simple_case("order-independent declarations", R"SOURCE( -use "std.zig"; +import "std.zig"; const z : @typeof(stdin_fileno) = 0; const x : @typeof(y) = 1234; const y : u16 = 5678; @@ -1053,7 +1053,7 @@ const foo : i32 = 0; )SOURCE", "OK\n"); add_simple_case("enum type", R"SOURCE( -use "std.zig"; +import "std.zig"; struct Point { x: u64, @@ -1167,7 +1167,7 @@ export executable "test"; )SOURCE", 1, ".tmp_source.zig:2:1: error: invalid version string"); add_compile_fail_case("bad import", R"SOURCE( -use "bogus-does-not-exist.zig"; +import "bogus-does-not-exist.zig"; )SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'"); add_compile_fail_case("undeclared identifier", R"SOURCE(