authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-08 02:52:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-08 02:52:27-07:00
loge1f498212c74c48d740b959484123478dec748ff
treefe16f946e263c2474fe081c6f02f2aff8c9162bc
parent9aea99a999997e223307d8559e0ff9fa613839a3

fix codegen for implicit maybe wrap


5 files changed, 17 insertions(+), 24 deletions(-)

README.md+3-1
......@@ -17,7 +17,7 @@ compromises backward compatibility.
1717 * Completely compatible with C libraries with no wrapper necessary.
1818 * In addition to creating executables, creating a C library is a primary use
1919 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.
2121 * Provide standard library which competes with the C standard library and is
2222 always compiled against statically in source form.
2323 * Generics so that one can write efficient data structures that work for any
......@@ -32,6 +32,8 @@ compromises backward compatibility.
3232 * Eliminate the need for header files (when using zig internally).
3333 * Tagged union enum type.
3434 * 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.
3537 * Ability to mark functions as test and automatically run them in test mode.
3638 This mode should automatically provide test coverage.
3739 * Friendly toward package maintainers.
src/analyze.cpp+1-1
......@@ -1207,7 +1207,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont
12071207 actual_type->data.pointer.child_type);
12081208 }
12091209
1210 add_node_error(g, node,
1210 add_node_error(g, first_executing_node(node),
12111211 buf_sprintf("expected type '%s', got '%s'",
12121212 buf_ptr(&expected_type->name),
12131213 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
495495 {
496496 assert(cast_node->ptr);
497497 assert(wanted_type->id == TypeTableEntryIdMaybe);
498 assert(actual_type);
498499
499500 add_debug_source_node(g, node);
500501 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_node->ptr, 0, "");
......@@ -1600,12 +1601,6 @@ static LLVMValueRef gen_expr_no_cast(CodeGen *g, AstNode *node) {
16001601 zig_unreachable();
16011602}
16021603
1603static 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
16091604static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
16101605 LLVMValueRef val = gen_expr_no_cast(g, node);
16111606
......@@ -1615,17 +1610,19 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
16151610
16161611 assert(node->codegen_node);
16171612
1618 {
1619 TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry;
1620 if (before_type && before_type->id == TypeTableEntryIdUnreachable) {
1621 return val;
1622 }
1623 val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_cast);
1613 TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry;
1614 if (before_type && before_type->id == TypeTableEntryIdUnreachable) {
1615 return val;
1616 }
1617 CastNode *cast_node = &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;
16241621 }
16251622
1626 {
1627 TypeTableEntry *before_type = node->codegen_node->expr_node.implicit_cast.after_type;
1628 val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_maybe_cast);
1623 cast_node = &node->codegen_node->expr_node.implicit_maybe_cast;
1624 if (cast_node->after_type) {
1625 val = gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node);
16291626 }
16301627
16311628 return val;
std/builtin.zig-6
......@@ -1,12 +1,6 @@
11// These functions are provided when not linking against libc because LLVM
22// sometimes generates code that calls them.
33
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
104export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
115 var index : #typeof(n) = 0;
126 while (index != n) {
std/std.zig+1-1
......@@ -42,7 +42,7 @@ pub fn print_i64(x: i64) -> isize {
4242/*
4343// TODO error handling
4444pub fn readline(buf: []u8) -> ?[]u8 {
45 var index = 0;
45 var index : usize = 0;
4646 while (index < buf.len) {
4747 // TODO unknown size array indexing operator
4848 const err = read(stdin_fileno, &buf.ptr[index], 1);