Front page | perl.perl6.internals |
Postings from June 2002
[Patch] typeof op
Thread Next
From:
brian wheeler
Date:
June 29, 2002 11:59
Subject:
[Patch] typeof op
Message ID:
1025376550.11838.3.camel@thor
This patch implements a typeof op which returns the integer type or
string type of a PMC.
The test I used is:
new P0,.PerlInt
typeof S0,P0
eq S0,"PerlInt",OK_1
print "not "
OK_1:
print "ok 1\\n"
typeof I0,P0
eq I0,.PerlInt,OK_2
print "not "
OK_2:
print "ok 2\\n"
end
This should allow a program to know what kind of PMC they're playing
with.
Brian
diff -u -r1.174 core.ops
--- core.ops 28 Jun 2002 18:50:05 -0000 1.174
+++ core.ops 29 Jun 2002 18:49:32 -0000
@@ -3884,6 +3884,27 @@
goto NEXT();
}
+
+=item B<typeof>(out STR, in PMC)
+
+=item B<typeof>(out INT, in PMC)
+
+Return the type of PMC in $2.
+
+=cut
+
+inline op typeof (out STR, in PMC) {
+ PMC *p = $2;
+ $1 = (p->vtable->name(interpreter, p));
+ goto NEXT();
+}
+
+inline op typeof (out INT, in PMC) {
+ PMC *p = $2;
+ $1 = (p->vtable->type(interpreter, p));
+ goto NEXT();
+}
+
########################################
=item B<find_type>(out INT, in STR)
Thread Next
-
[Patch] typeof op
by brian wheeler