-
Notifications
You must be signed in to change notification settings - Fork 0
/
hklr_op_bitwise_xor.c
56 lines (47 loc) · 1.09 KB
/
hklr_op_bitwise_xor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <assert.h>
#include "hkl_value.h"
HklValue* hklr_op_bitwise_xor(HklValue* left_value, HklValue* right_value)
{
HklValue* result = NULL;
bool left_updated = false, right_updated = false;
// Dereference left and right sides
if (left_value->type == HKL_TYPE_REF)
{
left_updated = true;
left_value = hklr_object_dereference(left_value->as.object);
}
if (right_value->type == HKL_TYPE_REF)
{
right_updated = true;
right_value = hklr_object_dereference(right_value->as.object);
}
switch (left_value->type)
{
case HKL_TYPE_INT:
switch(right_value->type)
{
case HKL_TYPE_INT:
result = hkl_value_new(HKL_TYPE_INT,
left_value->as.integer ^ right_value->as.integer);
break;
case HKL_TYPE_REAL:
case HKL_TYPE_STRING:
default:
assert(false);
break;
}
break; // HKL_TYPE_INT
default:
assert(false);
break;
}
if (left_updated)
{
hkl_value_free(left_value);
}
if (right_updated)
{
hkl_value_free(right_value);
}
return result;
}