Skip to content

Commit

Permalink
Made ! operator not overridable.
Browse files Browse the repository at this point in the history
  • Loading branch information
shin1m committed Aug 24, 2023
1 parent 32977e4 commit 700eb0f
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 65 deletions.
2 changes: 1 addition & 1 deletion include/xemmai/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct t_type_of<t_type> : t_uninstantiatable<t_bears<t_type>>
f_finalize = f_do_scan;
v_get = static_cast<t_pvalue (t_type::*)(t_object*, t_object*, size_t&)>(&t_type_of::f_do_get);
f_string = f_hash = f_not_supported0;
f_get_at = f_set_at = f_plus = f_minus = f_not = f_complement = f_multiply = f_divide = f_modulus = f_subtract = f_left_shift = f_right_shift = f_less = f_less_equal = f_greater = f_greater_equal = f_equals = f_not_equals = f_and = f_xor = f_or = f_not_supported1;
f_get_at = f_set_at = f_plus = f_minus = f_complement = f_multiply = f_divide = f_modulus = f_subtract = f_left_shift = f_right_shift = f_less = f_less_equal = f_greater = f_greater_equal = f_equals = f_not_equals = f_and = f_xor = f_or = f_not_supported1;
}
static void f_do_scan(t_object* a_this, t_scan a_scan);
XEMMAI__PORTABLE__EXPORT t_pvalue f_do_get(t_object* a_this, t_object* a_key, size_t& a_index);
Expand Down
15 changes: 0 additions & 15 deletions include/xemmai/fiber.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,21 +302,6 @@ inline t_pvalue t_value<T_tag>::f_##a_name() const\
XEMMAI__VALUE__UNARY_ARITHMETIC(plus, )
XEMMAI__VALUE__UNARY_ARITHMETIC(minus, -)

template<typename T_tag>
inline t_pvalue t_value<T_tag>::f_not() const
{
auto p = static_cast<t_object*>(*this);
switch (reinterpret_cast<uintptr_t>(p)) {
case e_tag__NULL:
return true;
case e_tag__INTEGER:
case e_tag__FLOAT:
return false;
default:
XEMMAI__VALUE__UNARY(f_not)
}
}

template<typename T_tag>
inline t_pvalue t_value<T_tag>::f_complement() const
{
Expand Down
5 changes: 0 additions & 5 deletions include/xemmai/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class t_global : public t_library
t_slot v_symbol_set_at;
t_slot v_symbol_plus;
t_slot v_symbol_minus;
t_slot v_symbol_not;
t_slot v_symbol_complement;
t_slot v_symbol_multiply;
t_slot v_symbol_divide;
Expand Down Expand Up @@ -120,10 +119,6 @@ class t_global : public t_library
{
return v_symbol_minus;
}
t_object* f_symbol_not() const
{
return v_symbol_not;
}
t_object* f_symbol_complement() const
{
return v_symbol_complement;
Expand Down
10 changes: 1 addition & 9 deletions include/xemmai/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ struct t_type_of<t_object>

static XEMMAI__TYPE__IDS_MODIFIER std::array<t_type_id, 1> V_ids{f_type_id<t_object>()};
static constexpr size_t V_native = 0;
static constexpr size_t V_fields = 26;
static constexpr size_t V_fields = 25;

static t_pvalue f_transfer(auto* a_library, auto&& a_value)
{
Expand All @@ -140,10 +140,6 @@ struct t_type_of<t_object>
{
return a_self.f_tag();
}
static bool f__not(const t_pvalue& a_self)
{
return false;
}
static bool f__equals(const t_pvalue& a_self, const t_pvalue& a_other)
{
return a_self == a_other;
Expand Down Expand Up @@ -263,8 +259,6 @@ struct t_type_of<t_object>
size_t (*f_plus)(t_object*, t_pvalue*) = f_do_plus;
XEMMAI__PORTABLE__EXPORT static size_t f_do_minus(t_object* a_this, t_pvalue* a_stack);
size_t (*f_minus)(t_object*, t_pvalue*) = f_do_minus;
XEMMAI__PORTABLE__EXPORT static size_t f_do_not(t_object* a_this, t_pvalue* a_stack);
size_t (*f_not)(t_object*, t_pvalue*) = f_do_not;
XEMMAI__PORTABLE__EXPORT static size_t f_do_complement(t_object* a_this, t_pvalue* a_stack);
size_t (*f_complement)(t_object*, t_pvalue*) = f_do_complement;
XEMMAI__PORTABLE__EXPORT static size_t f_do_multiply(t_object* a_this, t_pvalue* a_stack);
Expand Down Expand Up @@ -312,7 +306,6 @@ struct t_type_of<t_object>
if (T::f_do_set_at != U::f_do_set_at) f_set_at = T::f_do_set_at;
if (T::f_do_plus != U::f_do_plus) f_plus = T::f_do_plus;
if (T::f_do_minus != U::f_do_minus) f_minus = T::f_do_minus;
if (T::f_do_not != U::f_do_not) f_not = T::f_do_not;
if (T::f_do_complement != U::f_do_complement) f_complement = T::f_do_complement;
if (T::f_do_multiply != U::f_do_multiply) f_multiply = T::f_do_multiply;
if (T::f_do_divide != U::f_do_divide) f_divide = T::f_do_divide;
Expand Down Expand Up @@ -433,7 +426,6 @@ struct t_derived : T
this->f_set_at = t_type::f_do_set_at;
this->f_plus = t_type::f_do_plus;
this->f_minus = t_type::f_do_minus;
this->f_not = t_type::f_do_not;
this->f_complement = t_type::f_do_complement;
this->f_multiply = t_type::f_do_multiply;
this->f_divide = t_type::f_do_divide;
Expand Down
1 change: 0 additions & 1 deletion include/xemmai/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ class t_value : public T_tag
t_value<t_pointer> f_set_at(const t_value<t_pointer>& a_index, const t_value<t_pointer>& a_value) const;
t_value<t_pointer> f_plus() const;
t_value<t_pointer> f_minus() const;
t_value<t_pointer> f_not() const;
t_value<t_pointer> f_complement() const;
t_value<t_pointer> f_multiply(const t_value<t_pointer>& a_value) const;
t_value<t_pointer> f_divide(const t_value<t_pointer>& a_value) const;
Expand Down
12 changes: 1 addition & 11 deletions src/code_operator.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,7 @@
XEMMAI__CODE__UNARY_ARITHMETIC(PLUS, , f_plus)
XEMMAI__CODE__UNARY_ARITHMETIC(MINUS, -, f_minus)
XEMMAI__CODE__CASE_BEGIN(NOT)
switch (a0.f_tag()) {
case e_tag__NULL:
XEMMAI__CODE__PRIMITIVE_CALL(true)
break;
case e_tag__INTEGER:
case e_tag__FLOAT:
XEMMAI__CODE__PRIMITIVE_CALL(false)
break;
default:
XEMMAI__CODE__OBJECT_CALL(f_not)
}
XEMMAI__CODE__PRIMITIVE_CALL(!a0)
XEMMAI__CODE__CASE_END
XEMMAI__CODE__CASE_BEGIN(COMPLEMENT)
if (a0.f_tag() == e_tag__INTEGER) {
Expand Down
2 changes: 0 additions & 2 deletions src/global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ void t_global::f_scan(t_scan a_scan)
a_scan(v_symbol_set_at);
a_scan(v_symbol_plus);
a_scan(v_symbol_minus);
a_scan(v_symbol_not);
a_scan(v_symbol_complement);
a_scan(v_symbol_multiply);
a_scan(v_symbol_divide);
Expand Down Expand Up @@ -79,7 +78,6 @@ std::vector<std::pair<t_root, t_rvalue>> t_global::f_define()
v_symbol_set_at = t_symbol::f_instantiate(L"__set_at"sv);
v_symbol_plus = t_symbol::f_instantiate(L"__plus"sv);
v_symbol_minus = t_symbol::f_instantiate(L"__minus"sv);
v_symbol_not = t_symbol::f_instantiate(L"__not"sv);
v_symbol_complement = t_symbol::f_instantiate(L"__complement"sv);
v_symbol_multiply = t_symbol::f_instantiate(L"__multiply"sv);
v_symbol_divide = t_symbol::f_instantiate(L"__divide"sv);
Expand Down
36 changes: 17 additions & 19 deletions src/type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ void t_type::f_define()
(f_global()->f_symbol_set_at(), f_not_supported)
(f_global()->f_symbol_plus(), f_not_supported)
(f_global()->f_symbol_minus(), f_not_supported)
(f_global()->f_symbol_not(), t_member<bool(*)(const t_pvalue&), f__not>())
(f_global()->f_symbol_complement(), f_not_supported)
(f_global()->f_symbol_multiply(), f_not_supported)
(f_global()->f_symbol_divide(), f_not_supported)
Expand Down Expand Up @@ -242,24 +241,23 @@ XEMMAI__TYPE__METHOD(get_at, 4, 1)
XEMMAI__TYPE__METHOD(set_at, 5, 2)
XEMMAI__TYPE__METHOD(plus, 6, 0)
XEMMAI__TYPE__METHOD(minus, 7, 0)
XEMMAI__TYPE__METHOD(not, 8, 0)
XEMMAI__TYPE__METHOD(complement, 9, 0)
XEMMAI__TYPE__METHOD(multiply, 10, 1)
XEMMAI__TYPE__METHOD(divide, 11, 1)
XEMMAI__TYPE__METHOD(modulus, 12, 1)
XEMMAI__TYPE__METHOD(add, 13, 1)
XEMMAI__TYPE__METHOD(subtract, 14, 1)
XEMMAI__TYPE__METHOD(left_shift, 15, 1)
XEMMAI__TYPE__METHOD(right_shift, 16, 1)
XEMMAI__TYPE__METHOD(less, 17, 1)
XEMMAI__TYPE__METHOD(less_equal, 18, 1)
XEMMAI__TYPE__METHOD(greater, 19, 1)
XEMMAI__TYPE__METHOD(greater_equal, 20, 1)
XEMMAI__TYPE__METHOD(equals, 21, 1)
XEMMAI__TYPE__METHOD(not_equals, 22, 1)
XEMMAI__TYPE__METHOD(and, 23, 1)
XEMMAI__TYPE__METHOD(xor, 24, 1)
XEMMAI__TYPE__METHOD(or, 25, 1)
XEMMAI__TYPE__METHOD(complement, 8, 0)
XEMMAI__TYPE__METHOD(multiply, 9, 1)
XEMMAI__TYPE__METHOD(divide, 10, 1)
XEMMAI__TYPE__METHOD(modulus, 11, 1)
XEMMAI__TYPE__METHOD(add, 12, 1)
XEMMAI__TYPE__METHOD(subtract, 13, 1)
XEMMAI__TYPE__METHOD(left_shift, 14, 1)
XEMMAI__TYPE__METHOD(right_shift, 15, 1)
XEMMAI__TYPE__METHOD(less, 16, 1)
XEMMAI__TYPE__METHOD(less_equal, 17, 1)
XEMMAI__TYPE__METHOD(greater, 18, 1)
XEMMAI__TYPE__METHOD(greater_equal, 19, 1)
XEMMAI__TYPE__METHOD(equals, 20, 1)
XEMMAI__TYPE__METHOD(not_equals, 21, 1)
XEMMAI__TYPE__METHOD(and, 22, 1)
XEMMAI__TYPE__METHOD(xor, 23, 1)
XEMMAI__TYPE__METHOD(or, 24, 1)

void f_throw_type_error [[noreturn]] (const std::type_info& a_type, const wchar_t* a_name)
{
Expand Down
2 changes: 0 additions & 2 deletions test/operators.xm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Foo = Object + @
$__set_at = @(x, y) "a[" + x + "] = " + y
$__plus = @ "+a"
$__minus = @ "-a"
$__not = @ "!a"
$__complement = @ "~a"
$__multiply = @(x) "a * " + x
$__divide = @(x) "a / " + x
Expand All @@ -31,7 +30,6 @@ assert(a["x"] == "a[x]"
assert((a["x"] = "y") == "a[x] = y"
assert(+a == "+a"
assert(-a == "-a"
assert(!a == "!a"
assert(~a == "~a"
assert(a * "x" == "a * x"
assert(a / "x" == "a / x"
Expand Down

0 comments on commit 700eb0f

Please sign in to comment.