diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-01-25 15:45:05 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-01-25 15:45:05 -0700 |
| commit | deb35868841fc3eb99228fe102a5b8ed1991d51f (patch) | |
| tree | e84077cf298eec6f95cd3a75f1f05cd4cb0b501f /src/codegen.cpp | |
| parent | c0dc0ca6c90649f157dfcb43c7ec69fa4b5f6b09 (diff) | |
| download | zig-deb35868841fc3eb99228fe102a5b8ed1991d51f.tar.gz zig-deb35868841fc3eb99228fe102a5b8ed1991d51f.zip | |
implement %% prefix operator
See #23
also make undefined constants use llvm undef value
Diffstat (limited to 'src/codegen.cpp')
| -rw-r--r-- | src/codegen.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp index b86f3b3b5a..6d26793013 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -833,6 +833,24 @@ static LLVMValueRef gen_prefix_op_expr(CodeGen *g, AstNode *node) { { zig_panic("TODO codegen PrefixOpError"); } + case PrefixOpUnwrapError: + { + LLVMValueRef expr_val = gen_expr(g, expr_node); + TypeTableEntry *expr_type = get_expr_type(expr_node); + assert(expr_type->id == TypeTableEntryIdErrorUnion); + TypeTableEntry *child_type = expr_type->data.error.child_type; + // TODO in debug mode, put a panic here if the error is not 0 + if (child_type->size_in_bits > 0) { + LLVMValueRef child_val_ptr = LLVMBuildStructGEP(g->builder, expr_val, 1, ""); + if (handle_is_ptr(child_type)) { + return child_val_ptr; + } else { + return expr_val; + } + } else { + return nullptr; + } + } } zig_unreachable(); } @@ -2219,7 +2237,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, TypeTableEntry *type_entry, ConstE assert(const_val->ok); if (const_val->undef) { - return LLVMConstNull(type_entry->type_ref); + return LLVMGetUndef(type_entry->type_ref); } if (type_entry->id == TypeTableEntryIdInt) { |
