diff options
| author | gingerBill <bill@gingerbill.org> | 2018-12-21 11:34:15 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-12-21 11:34:15 +0000 |
| commit | b504d6e12ab70de583f70955c8ba6150b23ddc56 (patch) | |
| tree | 0099847c4b351afff21ff63b5196ef9ea42b0bb9 /src/ir.cpp | |
| parent | b4e83a430a8401e915346cd2d6063d8a8a2d1e03 (diff) | |
`notin` operator
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 47661c6e3..540347724 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -6296,13 +6296,18 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { return ir_emit_logical_binary_expr(proc, expr); - case Token_in: { + case Token_in: + case Token_notin: { irValue *right = ir_build_expr(proc, be->right); Type *rt = base_type(ir_type(right)); switch (rt->kind) { case Type_Map: { - ir_emit_comment(proc, str_lit("map in")); + if (be->op.kind == Token_in) { + ir_emit_comment(proc, str_lit("map in")); + } else { + ir_emit_comment(proc, str_lit("map notin")); + } irValue *addr = ir_address_from_load_or_generate_local(proc, right); irValue *h = ir_gen_map_header(proc, addr, rt); @@ -6313,12 +6318,20 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { args[1] = key; irValue *ptr = ir_emit_runtime_call(proc, "__dynamic_map_get", args); - return ir_emit_conv(proc, ir_emit_comp(proc, Token_NotEq, ptr, v_raw_nil), t_bool); + if (be->op.kind == Token_in) { + return ir_emit_conv(proc, ir_emit_comp(proc, Token_NotEq, ptr, v_raw_nil), t_bool); + } else { + return ir_emit_conv(proc, ir_emit_comp(proc, Token_CmpEq, ptr, v_raw_nil), t_bool); + } } break; case Type_BitSet: { - ir_emit_comment(proc, str_lit("bit_set in")); + if (be->op.kind == Token_in) { + ir_emit_comment(proc, str_lit("bit_set in")); + } else { + ir_emit_comment(proc, str_lit("bit_set notin")); + } Type *key_type = rt->BitSet.elem; GB_ASSERT(are_types_identical(ir_type(left), key_type)); @@ -6333,7 +6346,11 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { irValue *old_value = ir_emit_bitcast(proc, right, it); irValue *new_value = ir_emit_arith(proc, Token_And, old_value, bit, it); - return ir_emit_conv(proc, ir_emit_comp(proc, Token_NotEq, new_value, v_zero), t_bool); + if (be->op.kind == Token_in) { + return ir_emit_conv(proc, ir_emit_comp(proc, Token_NotEq, new_value, v_zero), t_bool); + } else { + return ir_emit_conv(proc, ir_emit_comp(proc, Token_CmpEq, new_value, v_zero), t_bool); + } } break; default: |