Add unit type
This commit is contained in:
parent
ae3e2270c0
commit
7ebf6982e6
5 changed files with 25 additions and 1 deletions
|
|
@ -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); }
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ template <typename T>
|
|||
%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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <pslang/type/unit.hpp>
|
||||
#include <pslang/type/primitive.hpp>
|
||||
#include <pslang/type/type_fwd.hpp>
|
||||
|
||||
|
|
@ -9,6 +10,7 @@ namespace pslang::type
|
|||
{
|
||||
|
||||
using type_impl = std::variant<
|
||||
unit_type,
|
||||
primitive_type
|
||||
>;
|
||||
|
||||
|
|
|
|||
14
libs/type/include/pslang/type/unit.hpp
Normal file
14
libs/type/include/pslang/type/unit.hpp
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
namespace pslang::type
|
||||
{
|
||||
|
||||
struct unit_type
|
||||
{};
|
||||
|
||||
inline bool operator == (unit_type const &, unit_type const &)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue