From 92fa5e6f3f804de7e8088144696acffa15b247a9 Mon Sep 17 00:00:00 2001 From: Shin-ichi MORITA Date: Sat, 6 May 2023 09:07:53 +0900 Subject: [PATCH] Made ! operator not overridable. --- include/xemmai/class.h | 2 +- include/xemmai/fiber.h | 15 --------------- include/xemmai/global.h | 5 ----- include/xemmai/type.h | 10 +--------- include/xemmai/value.h | 1 - src/code_operator.h | 12 +----------- src/global.cc | 2 -- src/type.cc | 36 +++++++++++++++++------------------- test/operators.xm | 2 -- 9 files changed, 20 insertions(+), 65 deletions(-) diff --git a/include/xemmai/class.h b/include/xemmai/class.h index 634199a8..1f549d31 100644 --- a/include/xemmai/class.h +++ b/include/xemmai/class.h @@ -15,7 +15,7 @@ struct t_type_of : t_uninstantiatable> f_finalize = f_do_scan; v_get = static_cast(&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__PUBLIC t_pvalue f_do_get(t_object* a_this, t_object* a_key, size_t& a_index); diff --git a/include/xemmai/fiber.h b/include/xemmai/fiber.h index 62b9a36e..5943b90b 100644 --- a/include/xemmai/fiber.h +++ b/include/xemmai/fiber.h @@ -278,21 +278,6 @@ inline t_pvalue t_value::f_##a_name() const\ XEMMAI__VALUE__UNARY_ARITHMETIC(plus, ) XEMMAI__VALUE__UNARY_ARITHMETIC(minus, -) -template -inline t_pvalue t_value::f_not() const -{ - auto p = static_cast(*this); - switch (reinterpret_cast(p)) { - case e_tag__NULL: - return true; - case e_tag__INTEGER: - case e_tag__FLOAT: - return false; - default: - XEMMAI__VALUE__UNARY(f_not) - } -} - template inline t_pvalue t_value::f_complement() const { diff --git a/include/xemmai/global.h b/include/xemmai/global.h index 9907f522..4cf010b3 100644 --- a/include/xemmai/global.h +++ b/include/xemmai/global.h @@ -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; @@ -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; diff --git a/include/xemmai/type.h b/include/xemmai/type.h index fbcf5d4b..a7e3cbf5 100644 --- a/include/xemmai/type.h +++ b/include/xemmai/type.h @@ -127,7 +127,7 @@ struct t_type_of static XEMMAI__TYPE__IDS_MODIFIER std::array V_ids{f_type_id()}; 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) { @@ -140,10 +140,6 @@ struct t_type_of { 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; @@ -264,8 +260,6 @@ struct t_type_of size_t (*f_plus)(t_object*, t_pvalue*) = f_do_plus; XEMMAI__PUBLIC 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__PUBLIC 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__PUBLIC 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__PUBLIC static size_t f_do_multiply(t_object* a_this, t_pvalue* a_stack); @@ -313,7 +307,6 @@ struct t_type_of 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; @@ -434,7 +427,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; diff --git a/include/xemmai/value.h b/include/xemmai/value.h index 014dcc92..65d44a55 100644 --- a/include/xemmai/value.h +++ b/include/xemmai/value.h @@ -335,7 +335,6 @@ class t_value : public T_tag t_value f_set_at(const t_value& a_index, const t_value& a_value) const; t_value f_plus() const; t_value f_minus() const; - t_value f_not() const; t_value f_complement() const; t_value f_multiply(const t_value& a_value) const; t_value f_divide(const t_value& a_value) const; diff --git a/src/code_operator.h b/src/code_operator.h index e6d3cf71..84dceab9 100644 --- a/src/code_operator.h +++ b/src/code_operator.h @@ -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) { diff --git a/src/global.cc b/src/global.cc index fb631799..ada1bc73 100644 --- a/src/global.cc +++ b/src/global.cc @@ -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); @@ -79,7 +78,6 @@ std::vector> 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); diff --git a/src/type.cc b/src/type.cc index 3608e626..72d1d6b2 100644 --- a/src/type.cc +++ b/src/type.cc @@ -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()) (f_global()->f_symbol_complement(), f_not_supported) (f_global()->f_symbol_multiply(), f_not_supported) (f_global()->f_symbol_divide(), f_not_supported) @@ -248,24 +247,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) { diff --git a/test/operators.xm b/test/operators.xm index c1ea3493..b3fe5f05 100644 --- a/test/operators.xm +++ b/test/operators.xm @@ -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 @@ -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"