Commit e1f498212c

Andrew Kelley <superjoe30@gmail.com>
2016-01-08 10:52:27
fix codegen for implicit maybe wrap
1 parent 9aea99a
src/analyze.cpp
@@ -1207,7 +1207,7 @@ static TypeTableEntry *resolve_type_compatibility(CodeGen *g, BlockContext *cont
                 actual_type->data.pointer.child_type);
     }
 
-    add_node_error(g, node,
+    add_node_error(g, first_executing_node(node),
         buf_sprintf("expected type '%s', got '%s'",
             buf_ptr(&expected_type->name),
             buf_ptr(&actual_type->name)));
src/codegen.cpp
@@ -495,6 +495,7 @@ static LLVMValueRef gen_bare_cast(CodeGen *g, AstNode *node, LLVMValueRef expr_v
             {
                 assert(cast_node->ptr);
                 assert(wanted_type->id == TypeTableEntryIdMaybe);
+                assert(actual_type);
 
                 add_debug_source_node(g, node);
                 LLVMValueRef val_ptr = LLVMBuildStructGEP(g->builder, cast_node->ptr, 0, "");
@@ -1600,12 +1601,6 @@ static LLVMValueRef gen_expr_no_cast(CodeGen *g, AstNode *node) {
     zig_unreachable();
 }
 
-static LLVMValueRef gen_cast_node(CodeGen *g, AstNode *node, LLVMValueRef val, TypeTableEntry *before_type,
-        CastNode *cast_node)
-{
-    return cast_node->after_type ? gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node) : val;
-}
-
 static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
     LLVMValueRef val = gen_expr_no_cast(g, node);
 
@@ -1615,17 +1610,19 @@ static LLVMValueRef gen_expr(CodeGen *g, AstNode *node) {
 
     assert(node->codegen_node);
 
-    {
-        TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry;
-        if (before_type && before_type->id == TypeTableEntryIdUnreachable) {
-            return val;
-        }
-        val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_cast);
+    TypeTableEntry *before_type = node->codegen_node->expr_node.type_entry;
+    if (before_type && before_type->id == TypeTableEntryIdUnreachable) {
+        return val;
+    }
+    CastNode *cast_node = &node->codegen_node->expr_node.implicit_cast;
+    if (cast_node->after_type) {
+        val = gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node);
+        before_type = cast_node->after_type;
     }
 
-    {
-        TypeTableEntry *before_type = node->codegen_node->expr_node.implicit_cast.after_type;
-        val = gen_cast_node(g, node, val, before_type, &node->codegen_node->expr_node.implicit_maybe_cast);
+    cast_node = &node->codegen_node->expr_node.implicit_maybe_cast;
+    if (cast_node->after_type) {
+        val = gen_bare_cast(g, node, val, before_type, cast_node->after_type, cast_node);
     }
 
     return val;
std/builtin.zig
@@ -1,12 +1,6 @@
 // These functions are provided when not linking against libc because LLVM
 // sometimes generates code that calls them.
 
-// In the future we may put these functions in separate compile units, make them .o files,
-// and then use
-// ar rcs foo.a foo.o memcpy.o memset.o
-// ld -o foo foo.a
-// This will omit the machine code if the function is unused.
-
 export fn memset(dest: &u8, c: u8, n: usize) -> &u8 {
     var index : #typeof(n) = 0;
     while (index != n) {
std/std.zig
@@ -42,7 +42,7 @@ pub fn print_i64(x: i64) -> isize {
 /*
 // TODO error handling
 pub fn readline(buf: []u8) -> ?[]u8 {
-    var index = 0;
+    var index : usize = 0;
     while (index < buf.len) {
         // TODO unknown size array indexing operator
         const err = read(stdin_fileno, &buf.ptr[index], 1);
README.md
@@ -17,7 +17,7 @@ compromises backward compatibility.
  * Completely compatible with C libraries with no wrapper necessary.
  * In addition to creating executables, creating a C library is a primary use
    case. You can export an auto-generated .h file.
- * Do not depend on libc unless explicitly imported.
+ * Do not depend on libc unless explicitly linked.
  * Provide standard library which competes with the C standard library and is
    always compiled against statically in source form.
  * Generics so that one can write efficient data structures that work for any
@@ -32,6 +32,8 @@ compromises backward compatibility.
  * Eliminate the need for header files (when using zig internally).
  * Tagged union enum type.
  * Resilient to parsing errors to make IDE integration work well.
+ * Eliminate the preprocessor, but have a plan for how to do things you would
+   want to use the preprocessor for such as conditional compilation.
  * Ability to mark functions as test and automatically run them in test mode.
    This mode should automatically provide test coverage.
  * Friendly toward package maintainers.