mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
rename "use" to "import"
This commit is contained in:
parent
86f55bce53
commit
dc162c7f83
@ -32,7 +32,7 @@ zig | C equivalent | Description
|
|||||||
```
|
```
|
||||||
Root : many(TopLevelDecl) token(EOF)
|
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))
|
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))
|
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)
|
RootExportDecl : many(Directive) token(Export) token(Symbol) token(String) token(Semicolon)
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
export executable "guess_number";
|
export executable "guess_number";
|
||||||
|
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
use "rand.zig";
|
import "rand.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
print_str("Welcome to the Guess Number Game in Zig.\n");
|
print_str("Welcome to the Guess Number Game in Zig.\n");
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
export executable "hello";
|
export executable "hello";
|
||||||
|
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
print_str("Hello, world!\n");
|
print_str("Hello, world!\n");
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
// purposefully conflicting function with main.zig
|
// purposefully conflicting function with main.zig
|
||||||
// but it's private so it should be OK
|
// but it's private so it should be OK
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
export executable "test-multiple-files";
|
export executable "test-multiple-files";
|
||||||
|
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
use "foo.zig";
|
import "foo.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
private_function();
|
private_function();
|
||||||
|
@ -2542,7 +2542,7 @@ Use : many(Directive) token(Use) token(String) token(Semicolon)
|
|||||||
*/
|
*/
|
||||||
static AstNode *ast_parse_use(ParseContext *pc, int *token_index) {
|
static AstNode *ast_parse_use(ParseContext *pc, int *token_index) {
|
||||||
Token *use_kw = &pc->tokens->at(*token_index);
|
Token *use_kw = &pc->tokens->at(*token_index);
|
||||||
if (use_kw->id != TokenIdKeywordUse)
|
if (use_kw->id != TokenIdKeywordImport)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
*token_index += 1;
|
*token_index += 1;
|
||||||
|
|
||||||
|
@ -211,8 +211,8 @@ static void end_token(Tokenize *t) {
|
|||||||
t->cur_tok->id = TokenIdKeywordPub;
|
t->cur_tok->id = TokenIdKeywordPub;
|
||||||
} else if (mem_eql_str(token_mem, token_len, "export")) {
|
} else if (mem_eql_str(token_mem, token_len, "export")) {
|
||||||
t->cur_tok->id = TokenIdKeywordExport;
|
t->cur_tok->id = TokenIdKeywordExport;
|
||||||
} else if (mem_eql_str(token_mem, token_len, "use")) {
|
} else if (mem_eql_str(token_mem, token_len, "import")) {
|
||||||
t->cur_tok->id = TokenIdKeywordUse;
|
t->cur_tok->id = TokenIdKeywordImport;
|
||||||
} else if (mem_eql_str(token_mem, token_len, "true")) {
|
} else if (mem_eql_str(token_mem, token_len, "true")) {
|
||||||
t->cur_tok->id = TokenIdKeywordTrue;
|
t->cur_tok->id = TokenIdKeywordTrue;
|
||||||
} else if (mem_eql_str(token_mem, token_len, "false")) {
|
} 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 TokenIdKeywordExtern: return "extern";
|
||||||
case TokenIdKeywordPub: return "pub";
|
case TokenIdKeywordPub: return "pub";
|
||||||
case TokenIdKeywordExport: return "export";
|
case TokenIdKeywordExport: return "export";
|
||||||
case TokenIdKeywordUse: return "use";
|
case TokenIdKeywordImport: return "import";
|
||||||
case TokenIdKeywordTrue: return "true";
|
case TokenIdKeywordTrue: return "true";
|
||||||
case TokenIdKeywordFalse: return "false";
|
case TokenIdKeywordFalse: return "false";
|
||||||
case TokenIdKeywordIf: return "if";
|
case TokenIdKeywordIf: return "if";
|
||||||
|
@ -20,7 +20,7 @@ enum TokenId {
|
|||||||
TokenIdKeywordExtern,
|
TokenIdKeywordExtern,
|
||||||
TokenIdKeywordPub,
|
TokenIdKeywordPub,
|
||||||
TokenIdKeywordExport,
|
TokenIdKeywordExport,
|
||||||
TokenIdKeywordUse,
|
TokenIdKeywordImport,
|
||||||
TokenIdKeywordTrue,
|
TokenIdKeywordTrue,
|
||||||
TokenIdKeywordFalse,
|
TokenIdKeywordFalse,
|
||||||
TokenIdKeywordIf,
|
TokenIdKeywordIf,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use "syscall.zig";
|
import "syscall.zig";
|
||||||
|
|
||||||
// The compiler treats this file special by implicitly importing the function `main`
|
// The compiler treats this file special by implicitly importing the function `main`
|
||||||
// from the root source file.
|
// from the root source file.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use "syscall.zig";
|
import "syscall.zig";
|
||||||
|
|
||||||
pub const stdin_fileno : isize = 0;
|
pub const stdin_fileno : isize = 0;
|
||||||
pub const stdout_fileno : isize = 1;
|
pub const stdout_fileno : isize = 1;
|
||||||
|
@ -108,8 +108,8 @@ export fn main(argc: i32, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "Hello, world!\n");
|
)SOURCE", "Hello, world!\n");
|
||||||
|
|
||||||
add_simple_case("function call", R"SOURCE(
|
add_simple_case("function call", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
use "syscall.zig";
|
import "syscall.zig";
|
||||||
|
|
||||||
fn empty_function_1() => {}
|
fn empty_function_1() => {}
|
||||||
fn empty_function_2() => { return; }
|
fn empty_function_2() => { return; }
|
||||||
@ -127,7 +127,7 @@ fn this_is_a_function() unreachable => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("comments", R"SOURCE(
|
add_simple_case("comments", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* multi line doc comment
|
* 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(
|
TestCase *tc = add_simple_case("multiple files with private function", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
use "foo.zig";
|
import "foo.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
private_function();
|
private_function();
|
||||||
@ -159,7 +159,7 @@ fn private_function() => {
|
|||||||
)SOURCE", "OK 1\nOK 2\n");
|
)SOURCE", "OK 1\nOK 2\n");
|
||||||
|
|
||||||
add_source_file(tc, "foo.zig", R"SOURCE(
|
add_source_file(tc, "foo.zig", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
// purposefully conflicting function with main.zig
|
// purposefully conflicting function with main.zig
|
||||||
// but it's private so it should be OK
|
// 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(
|
TestCase *tc = add_simple_case("import segregation", R"SOURCE(
|
||||||
use "foo.zig";
|
import "foo.zig";
|
||||||
use "bar.zig";
|
import "bar.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
foo_function();
|
foo_function();
|
||||||
@ -186,15 +186,15 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK\nOK\n");
|
)SOURCE", "OK\nOK\n");
|
||||||
|
|
||||||
add_source_file(tc, "foo.zig", R"SOURCE(
|
add_source_file(tc, "foo.zig", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn foo_function() => {
|
pub fn foo_function() => {
|
||||||
print_str("OK\n");
|
print_str("OK\n");
|
||||||
}
|
}
|
||||||
)SOURCE");
|
)SOURCE");
|
||||||
|
|
||||||
add_source_file(tc, "bar.zig", R"SOURCE(
|
add_source_file(tc, "bar.zig", R"SOURCE(
|
||||||
use "other.zig";
|
import "other.zig";
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn bar_function() => {
|
pub fn bar_function() => {
|
||||||
if (foo_function()) {
|
if (foo_function()) {
|
||||||
@ -212,7 +212,7 @@ pub fn foo_function() bool => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_simple_case("if statements", R"SOURCE(
|
add_simple_case("if statements", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
if (1 != 0) {
|
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");
|
)SOURCE", "1 is true\n!0 is true\n");
|
||||||
|
|
||||||
add_simple_case("params", R"SOURCE(
|
add_simple_case("params", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
fn add(a: i32, b: i32) i32 => {
|
fn add(a: i32, b: i32) i32 => {
|
||||||
a + b
|
a + b
|
||||||
@ -248,7 +248,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "pass\n");
|
)SOURCE", "pass\n");
|
||||||
|
|
||||||
add_simple_case("goto", R"SOURCE(
|
add_simple_case("goto", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
fn loop(a : i32) => {
|
fn loop(a : i32) => {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
@ -268,7 +268,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "loop\nloop\nloop\n");
|
)SOURCE", "loop\nloop\nloop\n");
|
||||||
|
|
||||||
add_simple_case("local variables", R"SOURCE(
|
add_simple_case("local variables", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
const a : i32 = 1;
|
const a : i32 = 1;
|
||||||
@ -281,7 +281,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("bool literals", R"SOURCE(
|
add_simple_case("bool literals", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
if (true) { print_str("OK 1\n"); }
|
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");
|
)SOURCE", "OK 1\nOK 2\n");
|
||||||
|
|
||||||
add_simple_case("separate block scopes", R"SOURCE(
|
add_simple_case("separate block scopes", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
if (true) {
|
if (true) {
|
||||||
@ -311,7 +311,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK 1\nOK 2\n");
|
)SOURCE", "OK 1\nOK 2\n");
|
||||||
|
|
||||||
add_simple_case("void parameters", R"SOURCE(
|
add_simple_case("void parameters", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
void_fun(1, void{}, 2);
|
void_fun(1, void{}, 2);
|
||||||
@ -327,7 +327,7 @@ fn void_fun(a : i32, b : void, c : i32) => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("void struct fields", R"SOURCE(
|
add_simple_case("void struct fields", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
struct Foo {
|
struct Foo {
|
||||||
a : void,
|
a : void,
|
||||||
b : i32,
|
b : i32,
|
||||||
@ -352,7 +352,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("void arrays", R"SOURCE(
|
add_simple_case("void arrays", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var array: [4]void;
|
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(
|
add_simple_case("mutable local variables", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var zero : i32 = 0;
|
var zero : i32 = 0;
|
||||||
@ -391,7 +391,7 @@ done:
|
|||||||
)SOURCE", "zero\nloop\nloop\nloop\n");
|
)SOURCE", "zero\nloop\nloop\nloop\n");
|
||||||
|
|
||||||
add_simple_case("arrays", R"SOURCE(
|
add_simple_case("arrays", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var array : [5]u32;
|
var array : [5]u32;
|
||||||
@ -427,7 +427,7 @@ fn get_array_len(a: []u32) usize => {
|
|||||||
|
|
||||||
|
|
||||||
add_simple_case("hello world without libc", R"SOURCE(
|
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 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
print_str("Hello, world!\n");
|
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(
|
add_simple_case("a + b + c", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
if (false || false || false) { print_str("BAD 1\n"); }
|
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");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("short circuit", R"SOURCE(
|
add_simple_case("short circuit", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
if (true || { print_str("BAD 1\n"); false }) {
|
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");
|
)SOURCE", "OK 1\nOK 2\nOK 3\nOK 4\n");
|
||||||
|
|
||||||
add_simple_case("modify operators", R"SOURCE(
|
add_simple_case("modify operators", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
var i : i32 = 0;
|
var i : i32 = 0;
|
||||||
@ -634,7 +634,7 @@ export fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
|||||||
)OUTPUT");
|
)OUTPUT");
|
||||||
|
|
||||||
add_simple_case("structs", R"SOURCE(
|
add_simple_case("structs", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
var foo : Foo;
|
var foo : Foo;
|
||||||
@ -706,7 +706,7 @@ fn test_initializer() => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("global variables", R"SOURCE(
|
add_simple_case("global variables", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
const g1 : i32 = 1233 + 1;
|
const g1 : i32 = 1233 + 1;
|
||||||
var g2 : i32 = 0;
|
var g2 : i32 = 0;
|
||||||
@ -721,7 +721,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("while loop", R"SOURCE(
|
add_simple_case("while loop", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
var i : i32 = 0;
|
var i : i32 = 0;
|
||||||
while (i < 4) {
|
while (i < 4) {
|
||||||
@ -738,7 +738,7 @@ fn f() i32 => {
|
|||||||
)SOURCE", "loop\nloop\nloop\nloop\n");
|
)SOURCE", "loop\nloop\nloop\nloop\n");
|
||||||
|
|
||||||
add_simple_case("continue and break", R"SOURCE(
|
add_simple_case("continue and break", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
var i : i32 = 0;
|
var i : i32 = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -754,7 +754,7 @@ pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
|||||||
)SOURCE", "loop\nloop\nloop\nloop\n");
|
)SOURCE", "loop\nloop\nloop\nloop\n");
|
||||||
|
|
||||||
add_simple_case("maybe type", R"SOURCE(
|
add_simple_case("maybe type", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
const x : ?bool = true;
|
const x : ?bool = true;
|
||||||
|
|
||||||
@ -789,7 +789,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "x is true\n");
|
)SOURCE", "x is true\n");
|
||||||
|
|
||||||
add_simple_case("implicit cast after unreachable", R"SOURCE(
|
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 => {
|
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
||||||
const x = outer();
|
const x = outer();
|
||||||
if (x == 1234) {
|
if (x == 1234) {
|
||||||
@ -804,7 +804,7 @@ fn outer() isize => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("@sizeof() and @typeof()", R"SOURCE(
|
add_simple_case("@sizeof() and @typeof()", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
const x: u16 = 13;
|
const x: u16 = 13;
|
||||||
const z: @typeof(x) = 19;
|
const z: @typeof(x) = 19;
|
||||||
pub fn main(argc : isize, argv : &&u8, env : &&u8) i32 => {
|
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");
|
)SOURCE", "2\n");
|
||||||
|
|
||||||
add_simple_case("member functions", R"SOURCE(
|
add_simple_case("member functions", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
struct Rand {
|
struct Rand {
|
||||||
seed: u32,
|
seed: u32,
|
||||||
pub fn get_seed(r: Rand) 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");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("pointer dereferencing", R"SOURCE(
|
add_simple_case("pointer dereferencing", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var x = i32(3);
|
var x = i32(3);
|
||||||
@ -854,7 +854,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("constant expressions", R"SOURCE(
|
add_simple_case("constant expressions", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
const ARRAY_SIZE : u8 = 20;
|
const ARRAY_SIZE : u8 = 20;
|
||||||
|
|
||||||
@ -867,7 +867,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "20\n");
|
)SOURCE", "20\n");
|
||||||
|
|
||||||
add_simple_case("#min_value() and #max_value()", R"SOURCE(
|
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 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
print_str("max u8: ");
|
print_str("max u8: ");
|
||||||
print_u64(@max_value(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(
|
add_simple_case("slicing", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var array : [20]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(
|
add_simple_case("else if expression", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
if (f(1) == 1) {
|
if (f(1) == 1) {
|
||||||
print_str("OK\n");
|
print_str("OK\n");
|
||||||
@ -1002,7 +1002,7 @@ fn f(c: u8) u8 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("overflow intrinsics", R"SOURCE(
|
add_simple_case("overflow intrinsics", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var result: u8;
|
var result: u8;
|
||||||
if (!@add_with_overflow(u8, 250, 100, &result)) {
|
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");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("memcpy and memset intrinsics", R"SOURCE(
|
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 => {
|
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||||
var foo : [20]u8;
|
var foo : [20]u8;
|
||||||
var bar : [20]u8;
|
var bar : [20]u8;
|
||||||
@ -1038,7 +1038,7 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("order-independent declarations", R"SOURCE(
|
add_simple_case("order-independent declarations", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
const z : @typeof(stdin_fileno) = 0;
|
const z : @typeof(stdin_fileno) = 0;
|
||||||
const x : @typeof(y) = 1234;
|
const x : @typeof(y) = 1234;
|
||||||
const y : u16 = 5678;
|
const y : u16 = 5678;
|
||||||
@ -1053,7 +1053,7 @@ const foo : i32 = 0;
|
|||||||
)SOURCE", "OK\n");
|
)SOURCE", "OK\n");
|
||||||
|
|
||||||
add_simple_case("enum type", R"SOURCE(
|
add_simple_case("enum type", R"SOURCE(
|
||||||
use "std.zig";
|
import "std.zig";
|
||||||
|
|
||||||
struct Point {
|
struct Point {
|
||||||
x: u64,
|
x: u64,
|
||||||
@ -1167,7 +1167,7 @@ export executable "test";
|
|||||||
)SOURCE", 1, ".tmp_source.zig:2:1: error: invalid version string");
|
)SOURCE", 1, ".tmp_source.zig:2:1: error: invalid version string");
|
||||||
|
|
||||||
add_compile_fail_case("bad import", R"SOURCE(
|
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'");
|
)SOURCE", 1, ".tmp_source.zig:2:1: error: unable to find 'bogus-does-not-exist.zig'");
|
||||||
|
|
||||||
add_compile_fail_case("undeclared identifier", R"SOURCE(
|
add_compile_fail_case("undeclared identifier", R"SOURCE(
|
||||||
|
Loading…
Reference in New Issue
Block a user