From 3746d6f829bca04fdd7e08bfa3bc967165c2459d Mon Sep 17 00:00:00 2001 From: Shin-ichi MORITA Date: Sun, 25 Feb 2024 06:36:11 +0900 Subject: [PATCH] Made true & false the tags themselves. --- doc/TermExpressions.md | 2 +- include/xemmai/ast.h | 27 +++++++-------------------- include/xemmai/boolean.h | 10 +++------- include/xemmai/fiber.h | 6 ++++-- include/xemmai/float.h | 3 ++- include/xemmai/global.h | 24 ++++++++++++++---------- include/xemmai/integer.h | 3 ++- include/xemmai/module.h | 7 +++---- include/xemmai/object.h | 3 ++- include/xemmai/parser.h | 2 +- include/xemmai/value.h | 19 +++++-------------- src/ast.cc | 17 ++++++++++------- src/boolean.cc | 2 +- src/code.cc | 26 +++++++++++++------------- src/code_operator.h | 40 +++++++++++++++++++--------------------- src/main.cc | 7 +++++-- src/parser.cc | 22 +++++++++++----------- 17 files changed, 103 insertions(+), 117 deletions(-) diff --git a/doc/TermExpressions.md b/doc/TermExpressions.md index f2396eea..d7d1a589 100644 --- a/doc/TermExpressions.md +++ b/doc/TermExpressions.md @@ -42,7 +42,7 @@ Relational, equality, and identity operators return either `true` or `false`. and: identity ('&' identity)* ; -Bitwise operators (`&`, `^`, and `|`) do bitwise operations if both the operands are integers, do boolean operations if both the operands are booleans, throws an exception otherwise. +Bitwise operators (`&`, `^`, and `|`) do bitwise operations if both the operands are integers, do boolean operations if the left operand is boolean, throws an exception otherwise. ## Xor Expressions diff --git a/include/xemmai/ast.h b/include/xemmai/ast.h index 2a536ad3..4504e595 100644 --- a/include/xemmai/ast.h +++ b/include/xemmai/ast.h @@ -72,23 +72,16 @@ struct t_operand e_tag__TEMPORARY }; - static inline const t_pvalue v_null{}; - static inline const t_pvalue v_true{true}; - static inline const t_pvalue v_false{false}; - t_tag v_tag; union { intptr_t v_integer; double v_float; - const t_pvalue* v_value; + t_object* v_value; size_t v_index; }; - t_operand(nullptr_t) : v_tag(e_tag__LITERAL), v_value(&v_null) - { - } - t_operand(bool a_value) : v_tag(e_tag__LITERAL), v_value(a_value ? &v_true : &v_false) + t_operand(bool a_value) : v_tag(e_tag__LITERAL), v_value(reinterpret_cast(a_value ? e_tag__TRUE : e_tag__FALSE)) { } t_operand(intptr_t a_value) : v_tag(e_tag__INTEGER), v_integer(a_value) @@ -97,7 +90,7 @@ struct t_operand t_operand(double a_value) : v_tag(e_tag__FLOAT), v_float(a_value) { } - t_operand(t_svalue& a_value) : v_tag(e_tag__LITERAL), v_value(reinterpret_cast(&a_value)) + t_operand(t_object* a_value) : v_tag(e_tag__LITERAL), v_value(a_value) { } t_operand() : v_tag(e_tag__TEMPORARY) @@ -571,8 +564,7 @@ struct XEMMAI__LOCAL t_emit } t_emit& operator<<(bool a_operand) { - v_code->v_instructions.push_back(reinterpret_cast(a_operand ? 1 : 0)); - return *this; + return *this << (a_operand ? 1 : 0); } t_emit& operator<<(double a_operand) { @@ -585,14 +577,9 @@ struct XEMMAI__LOCAL t_emit for (size_t i = 0; i < sizeof(double) / sizeof(void*); ++i) v_code->v_instructions.push_back(v1[i]); return *this; } - t_emit& operator<<(const t_pvalue& a_operand) - { - v_code->v_instructions.push_back(const_cast(&a_operand)); - return *this; - } - t_emit& operator<<(t_svalue& a_operand) + t_emit& operator<<(t_object* a_operand) { - v_code->v_instructions.push_back(&a_operand); + v_code->v_instructions.push_back(a_operand); return *this; } t_emit& operator<<(t_label& a_label) @@ -663,7 +650,7 @@ t_operand t_literal::f_emit(t_emit& a_emit, bool a_tail, bool a_operand, bool if (a_clear) return {}; if (a_tail) { a_emit.f_emit_safe_point(this); - a_emit << static_cast(t_emit::f_instruction_of() + e_instruction__RETURN_BOOLEAN - e_instruction__BOOLEAN) << v_value; + a_emit << static_cast(t_emit::f_instruction_of() + e_instruction__RETURN_NUL - e_instruction__NUL) << v_value; } else { a_emit << t_emit::f_instruction_of() << a_emit.v_stack << v_value; } diff --git a/include/xemmai/boolean.h b/include/xemmai/boolean.h index 4b264837..4c76724f 100644 --- a/include/xemmai/boolean.h +++ b/include/xemmai/boolean.h @@ -14,7 +14,7 @@ struct t_type_of : t_uninstantiatable> { static bool f_as(auto&& a_object) { - return a_object && (a_object.f_tag() != e_tag__BOOLEAN || a_object.f_boolean()); + return a_object.f_boolean(); } static bool f_is(t_object* a_object) { @@ -22,13 +22,9 @@ struct t_type_of : t_uninstantiatable> } }; - static t_object* f__string(bool a_self) + static t_object* f__string(const t_pvalue& a_self) { - return t_string::f_instantiate(a_self ? L"true"sv : L"false"sv); - } - static intptr_t f__hash(bool a_self) - { - return a_self ? 1 : 0; + return t_string::f_instantiate(a_self.f_boolean() ? L"true"sv : L"false"sv); } XEMMAI__LOCAL static void f_define(); diff --git a/include/xemmai/fiber.h b/include/xemmai/fiber.h index b3915da5..fa494138 100644 --- a/include/xemmai/fiber.h +++ b/include/xemmai/fiber.h @@ -265,7 +265,8 @@ inline t_pvalue t_value::f_##a_name() const\ auto p = static_cast(*this);\ switch (reinterpret_cast(p)) {\ case e_tag__NULL:\ - case e_tag__BOOLEAN:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ f_throw(L"not supported."sv);\ case e_tag__INTEGER:\ return a_operator(v_integer);\ @@ -287,7 +288,8 @@ inline t_pvalue t_value::f_complement() const case e_tag__INTEGER: return ~v_integer; case e_tag__NULL: - case e_tag__BOOLEAN: + case e_tag__FALSE: + case e_tag__TRUE: case e_tag__FLOAT: f_throw(L"not supported."sv); default: diff --git a/include/xemmai/float.h b/include/xemmai/float.h index 7c05867e..272274e5 100644 --- a/include/xemmai/float.h +++ b/include/xemmai/float.h @@ -42,7 +42,8 @@ struct t_type_of : t_derivable, t_derived_primitive::t_type, double>) return reinterpret_cast(a_object) >= e_tag__OBJECT && a_object->f_type()->f_derives::t_type>(); switch (reinterpret_cast(a_object)) { case e_tag__NULL: - case e_tag__BOOLEAN: + case e_tag__FALSE: + case e_tag__TRUE: return false; case e_tag__INTEGER: case e_tag__FLOAT: diff --git a/include/xemmai/global.h b/include/xemmai/global.h index 026d5011..349d55ea 100644 --- a/include/xemmai/global.h +++ b/include/xemmai/global.h @@ -245,7 +245,8 @@ XEMMAI__PORTABLE__ALWAYS_INLINE inline t_type* t_value::f_type() const switch (reinterpret_cast(p)) { case e_tag__NULL: return f_global()->f_type(); - case e_tag__BOOLEAN: + case e_tag__FALSE: + case e_tag__TRUE: return f_global()->f_type(); case e_tag__INTEGER: return f_global()->f_type(); @@ -282,8 +283,9 @@ inline t_pvalue t_value::f_##a_name() const\ switch (reinterpret_cast(p)) {\ case e_tag__NULL:\ return t_type_of::f__##a_name(*this);\ - case e_tag__BOOLEAN:\ - return t_type_of::f__##a_name(v_boolean);\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ + return t_type_of::f__##a_name(f_as(*this));\ case e_tag__INTEGER:\ return t_type_of::f__##a_name(v_integer);\ case e_tag__FLOAT:\ @@ -315,7 +317,8 @@ inline t_pvalue t_value::f_##a_name(const t_pvalue& a_value) const\ auto p = static_cast(*this);\ switch (reinterpret_cast(p)) {\ case e_tag__NULL:\ - case e_tag__BOOLEAN:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ f_throw(L"not supported."sv);\ case e_tag__INTEGER:\ return t_type_of::f__##a_name(v_integer, a_value);\ @@ -336,7 +339,8 @@ inline t_pvalue t_value::f_##a_name(const t_pvalue& a_value) const\ f_check(a_value, L"argument0");\ return static_cast(v_integer) a_operator f_as(a_value);\ case e_tag__NULL:\ - case e_tag__BOOLEAN:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ case e_tag__FLOAT:\ f_throw(L"not supported."sv);\ default:\ @@ -350,9 +354,9 @@ inline t_pvalue t_value::f_##a_name(const t_pvalue& a_value) const\ auto p = static_cast(*this);\ switch (reinterpret_cast(p)) {\ case e_tag__NULL:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ return a_operator(p == a_value.v_p);\ - case e_tag__BOOLEAN:\ - return a_operator(p == a_value.v_p && v_boolean == a_value.v_boolean);\ case e_tag__INTEGER:\ return t_type_of::f__##a_name(v_integer, a_value);\ case e_tag__FLOAT:\ @@ -367,9 +371,9 @@ inline t_pvalue t_value::f_##a_name(const t_pvalue& a_value) const\ {\ auto p = static_cast(*this);\ switch (reinterpret_cast(p)) {\ - case e_tag__BOOLEAN:\ - if (a_value.f_tag() != e_tag__BOOLEAN) [[unlikely]] f_throw_type_error(L"argument0");\ - return v_boolean a_operator a_value.v_boolean;\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ + return f_as(*this) a_operator f_as(a_value);\ case e_tag__INTEGER:\ f_check(a_value, L"argument0");\ return v_integer a_operator f_as(a_value);\ diff --git a/include/xemmai/integer.h b/include/xemmai/integer.h index 6ab095b7..2b517297 100644 --- a/include/xemmai/integer.h +++ b/include/xemmai/integer.h @@ -38,7 +38,8 @@ struct t_type_of : t_derivable, t_derived_primitive< case e_tag__INTEGER: return true; case e_tag__NULL: - case e_tag__BOOLEAN: + case e_tag__FALSE: + case e_tag__TRUE: case e_tag__FLOAT: return false; default: diff --git a/include/xemmai/module.h b/include/xemmai/module.h index 5bdaca8f..39fe3285 100644 --- a/include/xemmai/module.h +++ b/include/xemmai/module.h @@ -42,20 +42,19 @@ struct t_module struct t_script : t_module::t_body { std::wstring v_path; - std::deque v_slots; + std::deque v_slots; std::mutex v_mutex; t_script(std::wstring_view a_path) : v_path(a_path) { } virtual void f_scan(t_scan a_scan); - t_svalue& f_slot(t_object* a_p) + t_object* f_slot(t_object* a_p) { v_mutex.lock(); auto& p = v_slots.emplace_back(); v_mutex.unlock(); - p = a_p; - return p; + return p = a_p; } }; diff --git a/include/xemmai/object.h b/include/xemmai/object.h index d440c1dc..65bb52bc 100644 --- a/include/xemmai/object.h +++ b/include/xemmai/object.h @@ -356,7 +356,8 @@ struct t_type::t_cast switch (reinterpret_cast(a_object)) { case e_tag__NULL: return true; - case e_tag__BOOLEAN: + case e_tag__FALSE: + case e_tag__TRUE: case e_tag__INTEGER: case e_tag__FLOAT: return false; diff --git a/include/xemmai/parser.h b/include/xemmai/parser.h index eb0ce1b6..c364f727 100644 --- a/include/xemmai/parser.h +++ b/include/xemmai/parser.h @@ -30,7 +30,7 @@ class XEMMAI__LOCAL t_parser { f_throw(a_message, v_lexer.f_at()); } - t_svalue& f_symbol() const + t_object* f_symbol() const { return v_module.f_slot(t_symbol::f_instantiate(v_lexer.f_value())); } diff --git a/include/xemmai/value.h b/include/xemmai/value.h index ba087d73..e26043ce 100644 --- a/include/xemmai/value.h +++ b/include/xemmai/value.h @@ -21,7 +21,8 @@ using t_type = t_type_of; enum t_tag { e_tag__NULL, - e_tag__BOOLEAN, + e_tag__FALSE, + e_tag__TRUE, e_tag__INTEGER, e_tag__FLOAT, e_tag__OBJECT @@ -236,7 +237,6 @@ class t_value : public T_tag union { - bool v_boolean; intptr_t v_integer; double v_float; }; @@ -251,7 +251,7 @@ class t_value : public T_tag public: using T_tag::T_tag; - t_value(bool a_value) : T_tag(reinterpret_cast(e_tag__BOOLEAN)), v_boolean(a_value) + t_value(bool a_value) : T_tag(reinterpret_cast(a_value ? e_tag__TRUE : e_tag__FALSE)) { } template, bool> = true> @@ -289,8 +289,6 @@ class t_value : public T_tag auto p = f_tag(); if (p != a_value.f_tag()) return false; switch (p) { - case e_tag__BOOLEAN: - return v_boolean == a_value.v_boolean; case e_tag__INTEGER: return v_integer == a_value.v_integer; case e_tag__FLOAT: @@ -305,7 +303,7 @@ class t_value : public T_tag } bool f_boolean() const { - return v_boolean; + return f_tag() >= e_tag__TRUE; } intptr_t f_integer() const; double f_float() const; @@ -344,14 +342,7 @@ class t_value : public T_tag t_value f_minus() const; t_value f_not() const { - switch (reinterpret_cast(f_tag())) { - case e_tag__NULL: - return true; - case e_tag__BOOLEAN: - return !v_boolean; - default: - return false; - } + return f_tag() < e_tag__TRUE; } t_value f_complement() const; t_value f_multiply(const t_value& a_value) const; diff --git a/src/ast.cc b/src/ast.cc index eb4110ad..a3f6e95e 100644 --- a/src/ast.cc +++ b/src/ast.cc @@ -717,15 +717,18 @@ t_operand t_scope_put::f_emit(t_emit& a_emit, bool a_tail, bool a_operand, bool a_emit << e_instruction__FLOAT << v_variable.v_index << operand.v_float; break; case t_operand::e_tag__LITERAL: - switch (operand.v_value->f_tag()) { + switch (reinterpret_cast(operand.v_value)) { case e_tag__NULL: a_emit << e_instruction__NUL << v_variable.v_index; break; - case e_tag__BOOLEAN: - a_emit << e_instruction__BOOLEAN << v_variable.v_index << operand.v_value->f_boolean(); + case e_tag__FALSE: + a_emit << e_instruction__BOOLEAN << v_variable.v_index << 0; + break; + case e_tag__TRUE: + a_emit << e_instruction__BOOLEAN << v_variable.v_index << 1; break; default: - a_emit << e_instruction__INSTANCE << v_variable.v_index << *operand.v_value; + a_emit << e_instruction__INSTANCE << v_variable.v_index << operand.v_value; } break; case t_operand::e_tag__VARIABLE: @@ -870,7 +873,7 @@ t_operand t_unary::f_emit(t_emit& a_emit, bool a_tail, bool a_operand, bool a_cl if (!a_tail) a_emit << a_emit.v_stack; switch (operand.v_tag) { case t_operand::e_tag__LITERAL: - a_emit << *operand.v_value; + a_emit << operand.v_value; break; case t_operand::e_tag__VARIABLE: a_emit << operand.v_index; @@ -1071,7 +1074,7 @@ t_operand t_binary::f_emit(t_emit& a_emit, bool a_tail, bool a_operand, bool a_c a_emit << left.v_float; break; case t_operand::e_tag__LITERAL: - a_emit << *left.v_value; + a_emit << left.v_value; break; case t_operand::e_tag__VARIABLE: a_emit << left.v_index; @@ -1085,7 +1088,7 @@ t_operand t_binary::f_emit(t_emit& a_emit, bool a_tail, bool a_operand, bool a_c a_emit << right.v_float; break; case t_operand::e_tag__LITERAL: - a_emit << *right.v_value; + a_emit << right.v_value; break; case t_operand::e_tag__VARIABLE: a_emit << right.v_index; diff --git a/src/boolean.cc b/src/boolean.cc index f57424ad..5bee8e1b 100644 --- a/src/boolean.cc +++ b/src/boolean.cc @@ -6,7 +6,7 @@ namespace xemmai void t_type_of::f_define() { t_define{f_global()} - (f_global()->f_symbol_string(), t_member()) + (f_global()->f_symbol_string(), t_member()) .f_derive(); } diff --git a/src/code.cc b/src/code.cc index fb58a803..4a739bf8 100644 --- a/src/code.cc +++ b/src/code.cc @@ -485,7 +485,7 @@ size_t t_code::f_loop(t_context* a_context) XEMMAI__CODE__CASE(INSTANCE) { auto stack = base + reinterpret_cast(*++pc); - auto& value = *static_cast(*++pc); + auto value = static_cast(*++pc); ++pc; stack[0] = value; } @@ -506,7 +506,7 @@ size_t t_code::f_loop(t_context* a_context) } return -1; XEMMAI__CODE__CASE(RETURN_INSTANCE) - a_context->f_return(*static_cast(*++pc)); + a_context->f_return(static_cast(*++pc)); return -1; XEMMAI__CODE__CASE(RETURN_V) a_context->f_return(base[reinterpret_cast(*++pc)]); @@ -579,7 +579,7 @@ size_t t_code::f_loop(t_context* a_context) auto& a0 = stack[1]; #define XEMMAI__CODE__PREPARE() #define XEMMAI__CODE__FETCH_L()\ - auto& a0 = *static_cast(*++pc); + t_pvalue a0 = static_cast(*++pc); #define XEMMAI__CODE__PREPARE_L() #define XEMMAI__CODE__FETCH_V()\ auto& a0 = base[reinterpret_cast(*++pc)]; @@ -589,7 +589,7 @@ size_t t_code::f_loop(t_context* a_context) #define XEMMAI__CODE__PREPARE_A1()\ stack[2] = a1; #define XEMMAI__CODE__FETCH_LI()\ - auto& a0 = *static_cast(*++pc);\ + t_pvalue a0 = static_cast(*++pc);\ auto a1 = reinterpret_cast(*++pc); #define XEMMAI__CODE__PREPARE_LI() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_VI()\ @@ -601,7 +601,7 @@ size_t t_code::f_loop(t_context* a_context) auto a1 = reinterpret_cast(*++pc); #define XEMMAI__CODE__PREPARE_TI() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_LF()\ - auto& a0 = *static_cast(*++pc);\ + t_pvalue a0 = static_cast(*++pc);\ XEMMAI__CODE__FLOAT(a1, v1) #define XEMMAI__CODE__PREPARE_LF() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_VF()\ @@ -614,21 +614,21 @@ size_t t_code::f_loop(t_context* a_context) #define XEMMAI__CODE__PREPARE_TF() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_IL()\ auto a0 = reinterpret_cast(*++pc);\ - auto& a1 = *static_cast(*++pc); + t_pvalue a1 = static_cast(*++pc); #define XEMMAI__CODE__FETCH_FL()\ XEMMAI__CODE__FLOAT(a0, v0)\ - auto& a1 = *static_cast(*++pc); + t_pvalue a1 = static_cast(*++pc); #define XEMMAI__CODE__FETCH_LL()\ - auto& a0 = *static_cast(*++pc);\ - auto& a1 = *static_cast(*++pc); + t_pvalue a0 = static_cast(*++pc);\ + t_pvalue a1 = static_cast(*++pc); #define XEMMAI__CODE__PREPARE_LL() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_VL()\ auto& a0 = base[reinterpret_cast(*++pc)];\ - auto& a1 = *static_cast(*++pc); + t_pvalue a1 = static_cast(*++pc); #define XEMMAI__CODE__PREPARE_VL() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_TL()\ auto& a0 = stack[1];\ - auto& a1 = *static_cast(*++pc); + t_pvalue a1 = static_cast(*++pc); #define XEMMAI__CODE__PREPARE_TL() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_IV()\ auto a0 = reinterpret_cast(*++pc);\ @@ -637,7 +637,7 @@ size_t t_code::f_loop(t_context* a_context) XEMMAI__CODE__FLOAT(a0, v0)\ auto& a1 = base[reinterpret_cast(*++pc)]; #define XEMMAI__CODE__FETCH_LV()\ - auto& a0 = *static_cast(*++pc);\ + t_pvalue a0 = static_cast(*++pc);\ auto& a1 = base[reinterpret_cast(*++pc)]; #define XEMMAI__CODE__PREPARE_LV() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_VV()\ @@ -655,7 +655,7 @@ size_t t_code::f_loop(t_context* a_context) XEMMAI__CODE__FLOAT(a0, v0)\ auto& a1 = stack[1]; #define XEMMAI__CODE__FETCH_LT()\ - auto& a0 = *static_cast(*++pc);\ + t_pvalue a0 = static_cast(*++pc);\ auto& a1 = stack[1]; #define XEMMAI__CODE__PREPARE_LT() XEMMAI__CODE__PREPARE_A1() #define XEMMAI__CODE__FETCH_VT()\ diff --git a/src/code_operator.h b/src/code_operator.h index 597909dc..14a1d8b6 100644 --- a/src/code_operator.h +++ b/src/code_operator.h @@ -13,12 +13,6 @@ } else {\ XEMMAI__CODE__PRIMITIVE_CALL(a_operator(false))\ } -#define XEMMAI__CODE__BOOLEAN_OR_THROW(a_operator)\ - if (a1.f_tag() == e_tag__BOOLEAN) {\ - XEMMAI__CODE__PRIMITIVE_CALL(static_cast(a0.v_boolean a_operator a1.v_boolean))\ - } else {\ - goto label__THROW_NOT_SUPPORTED;\ - } #define XEMMAI__CODE__OTHERS_OBJECT(a_name, a_method)\ XEMMAI__CODE__CASE_BEGIN(a_name)\ XEMMAI__CODE__OBJECT_OR_THROW(a_method)\ @@ -32,7 +26,8 @@ XEMMAI__CODE__CASE_BEGIN(a_name)\ switch (a0.f_tag()) {\ case e_tag__NULL:\ - case e_tag__BOOLEAN:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ goto label__THROW_NOT_SUPPORTED;\ case e_tag__INTEGER:\ XEMMAI__CODE__PRIMITIVE_CALL(a_operator(a0.v_integer))\ @@ -101,9 +96,14 @@ #define XEMMAI__CODE__BINARY_EQUALITY_PRIMITIVE(a_operator) #define XEMMAI__CODE__BINARY_BITWISE(a_name, a_operator, a_method)\ XEMMAI__CODE__CASE_BEGIN(a_name)\ - if (a0.f_tag() == e_tag__BOOLEAN) {\ - XEMMAI__CODE__BOOLEAN_OR_THROW(a_operator)\ - } else XEMMAI__CODE__OBJECT_OR_THROW(a_method)\ + switch (a0.f_tag()) {\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ + XEMMAI__CODE__PRIMITIVE_CALL(static_cast(f_as(a0) a_operator f_as(a1)))\ + break;\ + default:\ + XEMMAI__CODE__OBJECT_OR_THROW(a_method)\ + }\ XEMMAI__CODE__CASE_END #else #ifdef XEMMAI__CODE__BINARY_XL @@ -145,7 +145,8 @@ XEMMAI__CODE__CASE_BEGIN(a_name)\ switch (a0.f_tag()) {\ case e_tag__NULL:\ - case e_tag__BOOLEAN:\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ goto label__THROW_NOT_SUPPORTED;\ case e_tag__INTEGER:\ XEMMAI__CODE__BINARY_ARITHMETIC_INTEGER(a_operator)\ @@ -178,18 +179,16 @@ #define XEMMAI__CODE__BINARY_BITWISE(a_name, a_operator, a_method)\ XEMMAI__CODE__CASE_BEGIN(a_name)\ switch (a0.f_tag()) {\ - case e_tag__BOOLEAN:\ - XEMMAI__CODE__BOOLEAN_OR_THROW(a_operator)\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ + XEMMAI__CODE__PRIMITIVE_CALL(static_cast(f_as(a0) a_operator f_as(a1)))\ break;\ case e_tag__INTEGER:\ XEMMAI__CODE__BINARY_INTEGER(a_operator, )\ XEMMAI__CODE__BINARY_DERIVED_OR_THROW(a_operator, intptr_t, , .v_integer)\ break;\ - case e_tag__NULL:\ - case e_tag__FLOAT:\ - goto label__THROW_NOT_SUPPORTED;\ default:\ - XEMMAI__CODE__OBJECT_CALL(a_method)\ + XEMMAI__CODE__OBJECT_OR_THROW(a_method)\ }\ XEMMAI__CODE__CASE_END #endif @@ -197,10 +196,9 @@ XEMMAI__CODE__CASE_BEGIN(a_name)\ switch (a0.f_tag()) {\ case e_tag__NULL:\ - XEMMAI__CODE__PRIMITIVE_CALL(a_operator(a1.f_tag() == e_tag__NULL))\ - break;\ - case e_tag__BOOLEAN:\ - XEMMAI__CODE__PRIMITIVE_CALL(a_operator(a1.f_tag() == e_tag__BOOLEAN && a0.v_boolean == a1.v_boolean))\ + case e_tag__FALSE:\ + case e_tag__TRUE:\ + XEMMAI__CODE__PRIMITIVE_CALL(a_operator(a0.v_p == a1.v_p))\ break;\ XEMMAI__CODE__BINARY_EQUALITY_PRIMITIVE(a_operator)\ default:\ diff --git a/src/main.cc b/src/main.cc index 4cbc651b..0f2324dd 100644 --- a/src/main.cc +++ b/src/main.cc @@ -189,8 +189,11 @@ class t_debugger : public xemmai::t_debugger case e_tag__NULL: std::fputs("null", v_out); break; - case e_tag__BOOLEAN: - std::fputs(f_as(a_value) ? "true" : "false", v_out); + case e_tag__FALSE: + std::fputs("false", v_out); + break; + case e_tag__TRUE: + std::fputs("true", v_out); break; case e_tag__INTEGER: std::fprintf(v_out, "%" PRIdPTR, f_as(a_value)); diff --git a/src/parser.cc b/src/parser.cc index 8b8c70f6..5ab67c5d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -36,7 +36,7 @@ std::unique_ptr t_parser::f_target(bool a_assignable) switch (v_lexer.f_token()) { case t_lexer::e_token__SYMBOL: { - t_object* symbol = f_symbol(); + auto symbol = f_symbol(); v_lexer.f_next(); if (v_lexer.f_token() == t_lexer::e_token__EQUAL) { if (!a_assignable) f_throw(L"can not assign to expression."sv); @@ -58,7 +58,7 @@ std::unique_ptr t_parser::f_target(bool a_assignable) v_lexer.f_next(); if (!v_lexer.f_newline() && v_lexer.f_token() == t_lexer::e_token__SYMBOL) { t_at at = v_lexer.f_at(); - t_object* key = f_symbol(); + auto key = f_symbol(); v_lexer.f_next(); if (v_lexer.f_token() == t_lexer::e_token__EQUAL) { if (!a_assignable) f_throw(L"can not assign to expression."sv); @@ -78,15 +78,15 @@ std::unique_ptr t_parser::f_target(bool a_assignable) switch (v_lexer.f_token()) { case t_lexer::e_token__SYMBOL: { - auto& symbol = f_symbol(); + auto symbol = f_symbol(); v_lexer.f_next(); - return std::make_unique>(at, symbol); + return std::make_unique>(at, symbol); } case t_lexer::e_token__LEFT_PARENTHESIS: { size_t indent = v_lexer.f_indent(); v_lexer.f_next(); - auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); + auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); if ((!v_lexer.f_newline() || v_lexer.f_indent() > indent) && v_lexer.f_token() != t_lexer::e_token__RIGHT_PARENTHESIS) call->v_expand = f_expressions(indent, call->v_arguments); if ((!v_lexer.f_newline() || v_lexer.f_indent() >= indent) && v_lexer.f_token() == t_lexer::e_token__RIGHT_PARENTHESIS) v_lexer.f_next(); return call; @@ -193,7 +193,7 @@ std::unique_ptr t_parser::f_target(bool a_assignable) { size_t indent = v_lexer.f_indent(); v_lexer.f_next(); - auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); + auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); if ((!v_lexer.f_newline() || v_lexer.f_indent() > indent) && v_lexer.f_token() != t_lexer::e_token__RIGHT_BRACKET) call->v_expand = f_expressions(indent, call->v_arguments); if ((!v_lexer.f_newline() || v_lexer.f_indent() >= indent) && v_lexer.f_token() == t_lexer::e_token__RIGHT_BRACKET) v_lexer.f_next(); return call; @@ -202,7 +202,7 @@ std::unique_ptr t_parser::f_target(bool a_assignable) { size_t indent = v_lexer.f_indent(); v_lexer.f_next(); - auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); + auto call = std::make_unique(at, std::make_unique>(at, v_module.f_slot(t_object::f_of(f_global()->f_type())))); if ((!v_lexer.f_newline() || v_lexer.f_indent() > indent) && v_lexer.f_token() != t_lexer::e_token__RIGHT_BRACE) while (true) { call->v_arguments.push_back(f_expression()); @@ -244,7 +244,7 @@ std::unique_ptr t_parser::f_target(bool a_assignable) { auto value = v_lexer.f_string(); v_lexer.f_next(); - return std::make_unique>(at, v_module.f_slot(value)); + return std::make_unique>(at, v_module.f_slot(value)); } case t_lexer::e_token__BREAK: { @@ -314,7 +314,7 @@ std::unique_ptr t_parser::f_action(size_t a_indent, std::unique_ptr } case t_lexer::e_token__SYMBOL: { - t_object* key = f_symbol(); + auto key = f_symbol(); v_lexer.f_next(); if (v_lexer.f_token() == t_lexer::e_token__EQUAL) { if (!a_assignable) f_throw(L"can not assign to expression."sv); @@ -346,7 +346,7 @@ std::unique_ptr t_parser::f_action(size_t a_indent, std::unique_ptr } case t_lexer::e_token__SYMBOL: { - t_object* key = f_symbol(); + auto key = f_symbol(); v_lexer.f_next(); a_target.reset(new ast::t_object_has(at, std::move(a_target), key)); continue; @@ -709,7 +709,7 @@ std::unique_ptr t_parser::f_expression() v_lexer.f_next(); auto expression = f_expression(); if (v_lexer.f_token() != t_lexer::e_token__SYMBOL) f_throw(L"expecting symbol."sv); - t_object* symbol = f_symbol(); + auto symbol = f_symbol(); v_lexer.f_next(); auto c = std::make_unique(std::move(expression), f_variable(v_scope, symbol)); f_block_or_expression(indent, c->v_block);