diff options
| author | gingerBill <bill@gingerbill.org> | 2018-08-14 18:32:34 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-08-14 18:32:34 +0100 |
| commit | 966249c10a32425b408df5a5ea6085781f38b8a7 (patch) | |
| tree | 2338b20fac3e649db3f2682fe3cfd4218b300bad /src/ir.cpp | |
| parent | acc010cba5df63b38704245254e721187335a7b2 (diff) | |
`bit_set` constants
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 31c042264..b9a57ca55 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2355,6 +2355,11 @@ irValue *ir_emit_unary_arith(irProcedure *proc, TokenKind op, irValue *x, Type * } + if (op == Token_Not) { + irValue *cmp = ir_emit_comp(proc, Token_CmpEq, x, v_false); + return ir_emit_conv(proc, cmp, type); + } + return ir_emit(proc, ir_instr_unary_op(proc, op, x, type)); } @@ -4880,6 +4885,55 @@ irValue *ir_build_expr_internal(irProcedure *proc, Ast *expr) { case Token_CmpOr: return ir_emit_logical_binary_expr(proc, expr); + + case Token_in: { + 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")); + + irValue *addr = ir_address_from_load_or_generate_local(proc, right); + irValue *h = ir_gen_map_header(proc, addr, rt); + irValue *key = ir_gen_map_key(proc, left, rt->Map.key); + + auto args = array_make<irValue *>(ir_allocator(), 2); + args[0] = h; + 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); + } + break; + case Type_BitSet: + { + ir_emit_comment(proc, str_lit("bit_set in")); + + Type *key_type = rt->BitSet.base_type; + GB_ASSERT(are_types_identical(ir_type(left), key_type)); + + Type *it = bit_set_to_int(rt); + left = ir_emit_conv(proc, left, it); + + irValue *lower = ir_value_constant(it, exact_value_i64(rt->BitSet.min)); + irValue *key = ir_emit_arith(proc, Token_Sub, left, lower, it); + irValue *bit = ir_emit_arith(proc, Token_Shl, v_one, key, it); + + + 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); + } + break; + default: + GB_PANIC("Invalid 'in' type"); + } + break; + + } + default: GB_PANIC("Invalid binary expression"); break; |