[RfC] Testing for null

0 views
Skip to first unread message

Juergen Boemmels

unread,
Dec 3, 2003, 9:46:11 AM12/3/03
to Perl6 Internals
Hi,

I'm curently playing around with open calls returning a PMCNULL
instead of a half valid IO-Object. But the main problem with that is
that there is currently no way for the byte-code to detect such a
case.
The if and unless ops call the get_boolean vtable method which throws
an internal exception.
As we can create a PMCNULL with the null_p op there should at least
be a way to test for a PMCNULL. Two possible solutions come to my mind

* A PMCNULL has false semantics. This may be done by letting
get_boolean return FALSE, or by adding a test to if_p_ic op:
if(!PMC_IS_NULL($1) && $1->vtable->get_boolean($1))
* Have a special op for this if_null and unless_null which exlusively
test for NULL.

Comments
boe
--
Juergen Boemmels boem...@physik.uni-kl.de
Fachbereich Physik Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F 23 F6 C7 2F 85 93 DD 47

Melvin Smith

unread,
Dec 3, 2003, 10:08:20 AM12/3/03
to Juergen Boemmels, Perl6 Internals
At 03:46 PM 12/3/2003 +0100, Juergen Boemmels wrote:
>I'm curently playing around with open calls returning a PMCNULL
>instead of a half valid IO-Object. But the main problem with that is
>that there is currently no way for the byte-code to detect such a
>case.
>The if and unless ops call the get_boolean vtable method which throws
>an internal exception.
>As we can create a PMCNULL with the null_p op there should at least
>be a way to test for a PMCNULL. Two possible solutions come to my mind
>
>* A PMCNULL has false semantics. This may be done by letting
> get_boolean return FALSE, or by adding a test to if_p_ic op:
> if(!PMC_IS_NULL($1) && $1->vtable->get_boolean($1))
>* Have a special op for this if_null and unless_null which exlusively
> test for NULL.

My intention for PMCNULL was to catch invalid interpreter state, or
invalid bytecode; cases which used to give us core dumps.

Explicitly returning PMCNULL and allowing tests on PMCNULL may
or may not fit into this, depending on your point of view. I'm not even
certain what my view of it is. Allowing ANY valid test on PMCNULL
seems to muddy the water by allowing it to actually be used.

The question is: should we allow a NULL register test
and would this replace Undef as the de facto way to return
"nothing". Probably the answer is "yes" but I'd like to hear Dan's
take on it.

-Melvin

Juergen Boemmels

unread,
Dec 3, 2003, 10:41:32 AM12/3/03
to Melvin Smith, Perl6 Internals
Melvin Smith <mrjol...@mindspring.com> writes:

[...]

> My intention for PMCNULL was to catch invalid interpreter state, or
> invalid bytecode; cases which used to give us core dumps.
>
> Explicitly returning PMCNULL and allowing tests on PMCNULL may
> or may not fit into this, depending on your point of view. I'm not even
> certain what my view of it is. Allowing ANY valid test on PMCNULL
> seems to muddy the water by allowing it to actually be used.

There is currently a way of creating such an object:
null P0
But you can't do anything with this object. If there are valid reasons
to create such an object, there should be a way to test for it.

> The question is: should we allow a NULL register test
> and would this replace Undef as the de facto way to return
> "nothing". Probably the answer is "yes" but I'd like to hear Dan's
> take on it.

There is currently no general Undef, only a PerlUndef, which warns if
used and morphs to a PerlInt when incremented. It might be best to
create a undef.pmc.

bye

Leopold Toetsch

unread,
Dec 3, 2003, 10:43:21 AM12/3/03
to Juergen Boemmels, perl6-i...@perl.org
Juergen Boemmels <boem...@physik.uni-kl.de> wrote:
> Hi,

> I'm curently playing around with open calls returning a PMCNULL
> instead of a half valid IO-Object. But the main problem with that is
> that there is currently no way for the byte-code to detect such a
> case.

C<defined> tests for PMCNULL too and is usable.

> * A PMCNULL has false semantics. This may be done by letting
> get_boolean return FALSE, or by adding a test to if_p_ic op:
> if(!PMC_IS_NULL($1) && $1->vtable->get_boolean($1))

Or the null.pmc gets a valid get_bool() vtable slot returning 0.
OTOH when PMCNULL is a real NULL, this will fail then.

> * Have a special op for this if_null and unless_null which exlusively
> test for NULL.

Probably better.

> boe

leo

Reply all
Reply to author
Forward
0 new messages