| author | |
| committer | |
| log | e1f498212c74c48d740b959484123478dec748ff |
| tree | fe16f946e263c2474fe081c6f02f2aff8c9162bc |
| parent | 9aea99a999997e223307d8559e0ff9fa613839a3 |
5 files changed, 17 insertions(+), 24 deletions(-)
README.md+3-1| ... | @@ -17,7 +17,7 @@ compromises backward compatibility. | ... | @@ -17,7 +17,7 @@ compromises backward compatibility. |
| 17 | * Completely compatible with C libraries with no wrapper necessary. | 17 | * Completely compatible with C libraries with no wrapper necessary. |
| 18 | * In addition to creating executables, creating a C library is a primary use | 18 | * In addition to creating executables, creating a C library is a primary use |
| 19 | case. You can export an auto-generated .h file. | 19 | case. You can export an auto-generated .h file. |
| 20 | * Do not depend on libc unless explicitly imported. | 20 | * Do not depend on libc unless explicitly linked. |
| 21 | * Provide standard library which competes with the C standard library and is | 21 | * Provide standard library which competes with the C standard library and is |
| 22 | always compiled against statically in source form. | 22 | always compiled against statically in source form. |
| 23 | * Generics so that one can write efficient data structures that work for any | 23 | * Generics so that one can write efficient data structures that work for any |
| ... | @@ -32,6 +32,8 @@ compromises backward compatibility. | ... | @@ -32,6 +32,8 @@ compromises backward compatibility. |
| 32 | * Eliminate the need for header files (when using zig internally). | 32 | * Eliminate the need for header files (when using zig internally). |
| 33 | * Tagged union enum type. | 33 | * Tagged union enum type. |
| 34 | * Resilient to parsing errors to make IDE integration work well. | 34 | * Resilient to parsing errors to make IDE integration work well. |
| 35 | * Eliminate the preprocessor, but have a plan for how to do things you would | ||
| 36 | want to use the preprocessor for such as conditional compilation. | ||
| 35 | * Ability to mark functions as test and automatically run them in test mode. | 37 | * Ability to mark functions as test and automatically run them in test mode. |
| 36 | This mode should automatically provide test coverage. | 38 | This mode should automatically provide test coverage. |
| 37 | * Friendly toward package maintainers. | 39 | * Friendly toward package maintainers. |
src/analyze.cpp+1-1| ... | @@ -1207,7 +1207,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont | ... | @@ -1207,7 +1207,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont |
| 1207 | actual_type->data.pointer.child_type); | 1207 | actual_type->data.pointer.child_type); |
| 1208 | } | 1208 | } |
| 1209 | 1209 | ||
| 1210 | add_node_error(g, node, | 1210 | add_node_error(g, first_executing_node(node), |
| 1211 | buf_sprintf("expected type '%s', got '%s'", | 1211 | buf_sprintf("expected type '%s', got '%s'", |
| 1212 | buf_ptr(&expected_type->name), | 1212 | buf_ptr(&expected_type->name), |
| 1213 | buf_ptr(&actual_type->name))); | 1213 | buf_ptr(&actual_type->name))); |
src/codegen.cpp+12-15| ... | @@ -495,6 +495,7 @@ static LLVMValueRef gen_bare_cast(CodeGen *g, AstNode *node, LLVMValueRef expr_v | ... | @@ -495,6 +495,7 @@ static LLVMValueRef gen_bare_cast(CodeGen *g, AstNode *node, LLVMValueRef expr_v |
| 495 | { | 495 | { |
| 496 | assert(cast_node->ptr); | 496 | assert(cast_node->ptr); |
| 497 | assert(wanted_type->id == TypeTableEntryIdMaybe); | 497 | assert(wanted_type->id == TypeTableEntryIdMaybe); |
| 498 | assert(actual_type); | ||
| 498 | 499 | ||
| 499 | add_debug_source_node(g, node); | 500 | add_debug_source_node(g, node); |
| 500 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_node->ptr, 0, ""); | 501 | LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_node->ptr, 0, ""); |
| ... | @@ -1600,12 +1601,6 @@ static LLVMValueRef gen_expr_no_cast(CodeGen *g, AstNode *node) { | ... | @@ -1600,12 +1601,6 @@ static LLVMValueRef gen_expr_no_cast(CodeGen *g, AstNode *node) { |
| 1600 | zig_unreachable(); | 1601 | zig_unreachable(); |
| 1601 | } | 1602 | } |
| 1602 | 1603 | ||
| 1603 | static LLVMValueRef gen_cast_node(CodeGen *g, AstNode *node, LLVMValueRef val, TypeTableEntry *before_type, | ||
| 1604 | CastNode *cast_node) | ||
| 1605 | { | ||
| 1606 | return cast_node->after_type ? gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node) : val; | ||
| 1607 | } | ||
| 1608 | |||
| 1609 | static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { | 1604 | static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 1610 | LLVMValueRef val = gen_expr_no_cast(g, node); | 1605 | LLVMValueRef val = gen_expr_no_cast(g, node); |
| 1611 | 1606 | ||
| ... | @@ -1615,17 +1610,19 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { | ... | @@ -1615,17 +1610,19 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) { |
| 1615 | 1610 | ||
| 1616 | assert(node->codegen_node); | 1611 | assert(node->codegen_node); |
| 1617 | 1612 | ||
| 1618 | { | 1613 | TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry; |
| 1619 | TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry; | 1614 | if (before_type && before_type->id == TypeTableEntryIdUnreachable) { |
| 1620 | if (before_type && before_type->id == TypeTableEntryIdUnreachable) { | 1615 | return val; |
| 1621 | return val; | 1616 | } |
| 1622 | } | 1617 | CastNode *cast_node = &node->codegen_node->expr_node.implicit_cast; |
| 1623 | val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_cast); | 1618 | if (cast_node->after_type) { |
| 1619 | val = gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node); | ||
| 1620 | before_type = cast_node->after_type; | ||
| 1624 | } | 1621 | } |
| 1625 | 1622 | ||
| 1626 | { | 1623 | cast_node = &node->codegen_node->expr_node.implicit_maybe_cast; |
| 1627 | TypeTableEntry *before_type = node->codegen_node->expr_node.implicit_cast.after_type; | 1624 | if (cast_node->after_type) { |
| 1628 | val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_maybe_cast); | 1625 | val = gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node); |
| 1629 | } | 1626 | } |
| 1630 | 1627 | ||
| 1631 | return val; | 1628 | return val; |
std/builtin.zig-6| ... | @@ -1,12 +1,6 @@ | ... | @@ -1,12 +1,6 @@ |
| 1 | // These functions are provided when not linking against libc because LLVM | 1 | // These functions are provided when not linking against libc because LLVM |
| 2 | // sometimes generates code that calls them. | 2 | // sometimes generates code that calls them. |
| 3 | 3 | ||
| 4 | // In the future we may put these functions in separate compile units, make them .o files, | ||
| 5 | // and then use | ||
| 6 | // ar rcs foo.a foo.o memcpy.o memset.o | ||
| 7 | // ld -o foo foo.a | ||
| 8 | // This will omit the machine code if the function is unused. | ||
| 9 | |||
| 10 | export fn memset(dest: &u8, c: u8, n: usize) -> &u8 { | 4 | export fn memset(dest: &u8, c: u8, n: usize) -> &u8 { |
| 11 | var index : #typeof(n) = 0; | 5 | var index : #typeof(n) = 0; |
| 12 | while (index != n) { | 6 | while (index != n) { |
std/std.zig+1-1| ... | @@ -42,7 +42,7 @@ pub fn print_i64(x: i64) -> isize { | ... | @@ -42,7 +42,7 @@ pub fn print_i64(x: i64) -> isize { |
| 42 | /* | 42 | /* |
| 43 | // TODO error handling | 43 | // TODO error handling |
| 44 | pub fn readline(buf: []u8) -> ?[]u8 { | 44 | pub fn readline(buf: []u8) -> ?[]u8 { |
| 45 | var index = 0; | 45 | var index : usize = 0; |
| 46 | while (index < buf.len) { | 46 | while (index < buf.len) { |
| 47 | // TODO unknown size array indexing operator | 47 | // TODO unknown size array indexing operator |
| 48 | const err = read(stdin_fileno, &buf.ptr[index], 1); | 48 | const err = read(stdin_fileno, &buf.ptr[index], 1); |