use
5.010;
use
Mo
qw(build default)
;
our
$AUTHORITY
=
'cpan:PERLANCAR'
;
our
$DATE
=
'2024-02-16'
;
our
$DIST
=
'Data-Sah'
;
our
$VERSION
=
'0.917'
;
sub
handle_type {
my
(
$self
,
$cd
) =
@_
;
my
$c
=
$self
->compiler;
my
$dt
=
$cd
->{data_term};
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$cd
->{_ccl_check_type} =
"$dt =~ "
.
'/\A(?:[+-]?(?:0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?|((?i)\s*nan\s*)|((?i)\s*[+-]?inf(inity)?)\s*)\z/'
;
}
else
{
$c
->add_sun_module(
$cd
);
$cd
->{_ccl_check_type} =
"$cd->{_sun_module}::isnum($dt)"
;
}
}
sub
clause_is_nan {
my
(
$self
,
$cd
) =
@_
;
my
$c
=
$self
->compiler;
my
$ct
=
$cd
->{cl_term};
my
$dt
=
$cd
->{data_term};
if
(
$cd
->{cl_is_expr}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$ct ? lc($dt+0) eq "nan" : defined($ct) ? lc($dt+0) ne "nan" : 1]
,
);
}
else
{
$c
->add_ccl(
$cd
,
join
(
""
,
"$ct ? $cd->{_sun_module}::isnan($dt) : "
,
"defined($ct) ? !$cd->{_sun_module}::isnan($dt) : 1"
,
)
);
}
}
else
{
if
(
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[lc($dt+0) eq "nan"]
);
}
else
{
$c
->add_ccl(
$cd
,
"$cd->{_sun_module}::isnan($dt)"
);
}
}
elsif
(
defined
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[lc($dt+0) ne "nan"]
);
}
else
{
$c
->add_ccl(
$cd
,
"!$cd->{_sun_module}::isnan($dt)"
);
}
}
}
}
sub
clause_is_neg_inf {
my
(
$self
,
$cd
) =
@_
;
my
$c
=
$self
->compiler;
my
$ct
=
$cd
->{cl_term};
my
$dt
=
$cd
->{data_term};
if
(
$cd
->{cl_is_expr}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
join
(
''
,
qq[$ct ? $dt =~ /\\A\\s*-inf(inity)?\\s*\\z/i : ]
,
qq[defined($ct) ? $dt !~ /\\A\\s*inf(inity)?\\s*\\z/i : 1]
));
}
else
{
$c
->add_ccl(
$cd
,
join
(
''
,
"$ct ? $cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt) : "
,
"defined($ct) ? !($cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt)) : 1"
,
));
}
}
else
{
if
(
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt =~ /\\A\\s*-inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"$cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt)"
);
}
}
elsif
(
defined
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt !~ /\\A\\s*-inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"!($cd->{_sun_module}::isinf($dt) && $cd->{_sun_module}::isneg($dt))"
);
}
}
}
}
sub
clause_is_pos_inf {
my
(
$self
,
$cd
) =
@_
;
my
$c
=
$self
->compiler;
my
$ct
=
$cd
->{cl_term};
my
$dt
=
$cd
->{data_term};
if
(
$cd
->{cl_is_expr}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
join
(
''
,
qq[$ct ? $dt =~ /\\A\\s*inf(inity)?\\s*\\z/i : ]
,
qq[defined($ct) ? $dt !~ /\\A\\s*inf(inity)?\\s*\\z/i : 1]
));
}
else
{
$c
->add_ccl(
$cd
,
join
(
''
,
"$ct ? $cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt) : "
,
"defined($ct) ? !($cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt)) : 1"
,
));
}
}
else
{
if
(
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt =~ /\\A\\s*inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"$cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt)"
);
}
}
elsif
(
defined
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt !~ /\\A\\s*inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"!($cd->{_sun_module}::isinf($dt) && !$cd->{_sun_module}::isneg($dt))"
);
}
}
}
}
sub
clause_is_inf {
my
(
$self
,
$cd
) =
@_
;
my
$c
=
$self
->compiler;
my
$ct
=
$cd
->{cl_term};
my
$dt
=
$cd
->{data_term};
if
(
$cd
->{cl_is_expr}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
join
(
''
,
qq[$ct ? $dt =~ /\\A\\s*-?inf(inity)?\\s*\\z/i : ]
,
qq[defined($ct) ? $dt+0 !~ /\\A-?inf\\z/ : 1]
));
}
else
{
$c
->add_ccl(
$cd
,
"$ct ? $cd->{_sun_module}::isinf($dt) : "
.
"defined($ct) ? $cd->{_sun_module}::isinf($dt) : 1"
);
}
}
else
{
if
(
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt =~ /\\A\\s*-?inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"$cd->{_sun_module}::isinf($dt)"
);
}
}
elsif
(
defined
$cd
->{cl_value}) {
if
(
$cd
->{args}{core} ||
$cd
->{args}{no_modules}) {
$c
->add_ccl(
$cd
,
qq[$dt !~ /\\A\\s*-?inf(inity)?\\s*\\z/i]
);
}
else
{
$c
->add_ccl(
$cd
,
"!$cd->{_sun_module}::isinf($dt)"
);
}
}
}
}
1;