From 7ebf6982e617d9b843426262ac95b569e934aa72 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Tue, 16 Dec 2025 15:16:06 +0300 Subject: [PATCH] Add unit type --- libs/parser/rules/pslang.l | 1 + libs/parser/rules/pslang.y | 4 +++- libs/type/include/pslang/type/type.hpp | 2 ++ libs/type/include/pslang/type/unit.hpp | 14 ++++++++++++++ libs/type/source/print.cpp | 5 +++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 libs/type/include/pslang/type/unit.hpp diff --git a/libs/parser/rules/pslang.l b/libs/parser/rules/pslang.l index c579cf4..0a19f0b 100644 --- a/libs/parser/rules/pslang.l +++ b/libs/parser/rules/pslang.l @@ -31,6 +31,7 @@ as { return bp::make_as(ctx.location); } true { return bp::make_true(ctx.location); } false { return bp::make_false(ctx.location); } +unit { return bp::make_unit(ctx.location); } bool { return bp::make_bool(ctx.location); } i8 { return bp::make_i8(ctx.location); } u8 { return bp::make_u8(ctx.location); } diff --git a/libs/parser/rules/pslang.y b/libs/parser/rules/pslang.y index 0e0a0dc..9874d9e 100644 --- a/libs/parser/rules/pslang.y +++ b/libs/parser/rules/pslang.y @@ -119,6 +119,7 @@ template %token true %token false +%token unit %token bool %token i8 %token u8 @@ -190,7 +191,8 @@ variable_keyword ; type_expression -: primitive_type { $$ = type::type($1); } +: unit { $$ = type::type(type::unit_type{}); } +| primitive_type { $$ = type::type($1); } ; primitive_type diff --git a/libs/type/include/pslang/type/type.hpp b/libs/type/include/pslang/type/type.hpp index b1125e7..fb9dd19 100644 --- a/libs/type/include/pslang/type/type.hpp +++ b/libs/type/include/pslang/type/type.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -9,6 +10,7 @@ namespace pslang::type { using type_impl = std::variant< + unit_type, primitive_type >; diff --git a/libs/type/include/pslang/type/unit.hpp b/libs/type/include/pslang/type/unit.hpp new file mode 100644 index 0000000..1b9928b --- /dev/null +++ b/libs/type/include/pslang/type/unit.hpp @@ -0,0 +1,14 @@ +#pragma once + +namespace pslang::type +{ + + struct unit_type + {}; + + inline bool operator == (unit_type const &, unit_type const &) + { + return true; + } + +} diff --git a/libs/type/source/print.cpp b/libs/type/source/print.cpp index a5bd063..cc67923 100644 --- a/libs/type/source/print.cpp +++ b/libs/type/source/print.cpp @@ -7,6 +7,11 @@ namespace pslang::type namespace { + void print_impl(std::ostream & out, unit_type const & type) + { + out << "unit"; + } + void print_impl(std::ostream & out, bool_type const &) { out << "bool";