[svn:parrot] r48957 - in branches/sleeker_boolean: . examples/benchmarks src/pmc t/oo t/pmc
Paul at osuosl.org
Paul at osuosl.org
Sun Sep 12 14:53:03 UTC 2010
Author: Paul C. Anagnostopoulos
Date: Sun Sep 12 14:53:03 2010
New Revision: 48957
URL: https://trac.parrot.org/parrot/changeset/48957
Log:
New Boolean that does not inherit from Integer
Added:
branches/sleeker_boolean/examples/benchmarks/boolean.pir
Modified:
branches/sleeker_boolean/MANIFEST
branches/sleeker_boolean/src/pmc/boolean.pmc
branches/sleeker_boolean/t/oo/objects.t
branches/sleeker_boolean/t/pmc/boolean.t
Modified: branches/sleeker_boolean/MANIFEST
==============================================================================
--- branches/sleeker_boolean/MANIFEST Sun Sep 12 13:45:25 2010 (r48956)
+++ branches/sleeker_boolean/MANIFEST Sun Sep 12 14:53:03 2010 (r48957)
@@ -1,12 +1,12 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Sep 1 00:17:03 2010 UT
+# generated by tools\dev\mk_manifest_and_skip.pl Thu Sep 9 00:10:45 2010 UT
#
# See below for documentation on the format of this file.
#
# See docs/submissions.pod and the documentation in
-# tools/dev/mk_manifest_and_skip.pl on how to recreate this file after SVN
+# tools\dev\mk_manifest_and_skip.pl on how to recreate this file after SVN
# has been told about new or deleted files.
.gitignore []
CREDITS [main]doc
@@ -513,6 +513,7 @@
examples/benchmarks/arriter.rb [examples]
examples/benchmarks/arriter_o1.pir [examples]
examples/benchmarks/bench_newp.pasm [examples]
+examples/benchmarks/boolean.pir [examples]
examples/benchmarks/fib.cs [examples]
examples/benchmarks/fib.pir [examples]
examples/benchmarks/fib.pl [examples]
Added: branches/sleeker_boolean/examples/benchmarks/boolean.pir
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/sleeker_boolean/examples/benchmarks/boolean.pir Sun Sep 12 14:53:03 2010 (r48957)
@@ -0,0 +1,63 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id: boolean.pir 38923 2009-05-19 06:07:42Z Paul C. Anagnostopoulos $
+
+=head1 NAME
+
+examples/benchmarks/boolean.pir: Manipulate the Boolean PMC
+
+=head1 SYNOPSIS
+
+parrot examples/benchmarks/boolean.pir
+
+=head1 DESCRIPTION
+
+This benchmark operates on the Boolean PMC, allocating new ones, setting them,
+and performing logical operations on them.
+
+=cut
+
+.const num iterations = 10e6 # Number of iterations.
+
+.sub main :main
+
+ .local num start_time, end_time
+ .local int counter
+ .local pmc a, b, c, result
+
+ print "Perform "
+ print iterations
+ say " iterations of various Boolean operations"
+
+ a = new 'Boolean', 1
+ start_time = time
+
+ counter = iterations
+LOOP:
+ b = new 'Boolean'
+ b = 1
+ c = new 'Boolean', b
+ result = not a
+ result = and result, b
+ result = or result, c
+ not result
+ if result goto TRUE
+ a = 0
+ goto NEXT
+TRUE:
+ a = 1
+NEXT:
+ dec counter
+ if counter > 0 goto LOOP
+
+ end_time = time
+ end_time = end_time - start_time
+ end_time = end_time / iterations
+ print "Elapsed time per iteration: "
+ say end_time
+.end
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
Modified: branches/sleeker_boolean/src/pmc/boolean.pmc
==============================================================================
--- branches/sleeker_boolean/src/pmc/boolean.pmc Sun Sep 12 13:45:25 2010 (r48956)
+++ branches/sleeker_boolean/src/pmc/boolean.pmc Sun Sep 12 14:53:03 2010 (r48957)
@@ -1,5 +1,4 @@
-/*
-Copyright (C) 2001-2010, Parrot Foundation.
+/* Copyright (c) 2010, Parrot Foundation.
$Id$
=head1 NAME
@@ -8,131 +7,201 @@
=head1 DESCRIPTION
-This class implements a boolean value variable.
+This PMC implements a Boolean type with a single true/false value.
+A C<Boolean> does not morph to other types when its value is set; it simply
+changes its value.
-Albeit the C<Boolean PMC> is derived from the C<Integer PMC>,
-it doesn't morph to other types. Only its value is changed.
+This implementation of C<Boolean> inherits from the C<Scalar> PMC.
+Unlike the previous implementation, it does I<not> inherit
+from C<Integer>.
-=head2 Methods
+=head2 Functions
-=over 4
+=over
=cut
*/
-/* HEADERIZER HFILE: none */
+/* This new Boolean PMC stores its boolean value in a private PObj flag. */
-pmclass Boolean extends Integer provides boolean provides scalar auto_attrs {
+#define boolean_FLAG PObj_private0_FLAG
-/*
+#define get_boolean_FLAG(pmc) \
+ ((PObj_get_FLAGS(pmc) & boolean_FLAG) != 0)
-=item C<void init_pmc(PMC *value)>
+#define set_boolean_FLAG(pmc, val) \
+ if (val) \
+ PObj_get_FLAGS(pmc) |= boolean_FLAG; \
+ else \
+ PObj_get_FLAGS(pmc) &= ~boolean_FLAG;
-Initialises SELF value according to the boolean value of the passed PMC.
+#define flip_boolean_FLAG(pmc) \
+ PObj_get_FLAGS(pmc) ^= boolean_FLAG
-=cut
-*/
- VTABLE void init_pmc(PMC *value) {
- INTVAL v = PMC_IS_NULL(value) ? (INTVAL) 0 : VTABLE_get_bool(INTERP, value);
- SELF.set_bool(v);
- }
+pmclass Boolean extends scalar provides boolean provides scalar manual_attrs {
+
/*
-=item C<STRING *get_string()>
+=item C<void init()>
+
+Create a new C<Boolean> with initial value C<FALSE>.
+
+=item C<void init_pmc(PMC *value)>
-Return "1" or "0".
+Create a new C<Boolean> with the given initial value interpreted
+as a Boolean.
=cut
*/
- VTABLE STRING *get_string() {
- return SUPER();
+
+ /* These two init functions set the boolean flag directly. */
+
+ VTABLE void init () {
+ set_boolean_FLAG(SELF, FALSE);
}
+ VTABLE void init_pmc (PMC *value) {
+ INTVAL v = PMC_IS_NULL(value) ? FALSE : VTABLE_get_bool(INTERP, value);
+ set_boolean_FLAG(SELF, v);
+ }
/*
-=item C<void set_integer_native(INTVAL value)>
+=item C<INTVAL get_bool()>
-=item C<void set_bool(INTVAL value)>
+Obtain the value of the C<Boolean> as an integer: 1 = C<TRUE>, 0 = C<FALSE>.
+
+=item C<INTVAL get_integer()>
+
+Same as C<get_bool()>.
+
+=item C<FLOATVAL get_number()>
+
+Obtain the value of the C<Boolean> as a float: 1.0 = C<TRUE>, 0.0 = C<FALSE>.
+
+=item C<STRING *get_string()>
-=item C<void set_pmc(PMC *value)>
+Obtain the value of the C<Boolean> as a string: "1" = C<TRUE>, "0" = C<FALSE>.
=cut
*/
- VTABLE void set_integer_native(INTVAL value) {
- SUPER((value != 0));
+
+ VTABLE INTVAL get_bool () {
+ return get_boolean_FLAG(SELF);
}
+ VTABLE INTVAL get_integer () {
+ return SELF.get_bool();
+ }
- VTABLE void set_bool(INTVAL value) {
- SELF.set_integer_native(value);
+ VTABLE FLOATVAL get_number () {
+ INTVAL value = SELF.get_bool();
+ return (FLOATVAL)value;
+ }
+
+ VTABLE STRING *get_string () {
+ return Parrot_str_from_int(INTERP, SELF.get_integer());
}
/*
-=item C<void set_number_native(FLOATVAL value)>
+=item C<void set_bool(INTVAL value)>
-Sets the value to C<value> evaluated in a boolean context.
+Sets the value of the Boolean to the specified integer value: 0 = C<FALSE>, non-0 =
+C<TRUE>.
-=cut
+=item C<void set_integer_native(INTVAL value)>
-*/
+Same as C<set_bool()>.
- VTABLE void set_number_native(FLOATVAL value) {
- SELF.set_bool(!FLOAT_IS_ZERO(value));
- }
+=item C<void set_number_native(FLOATVAL value)>
-/*
+Sets the value of the Boolean to the specified float value: 0.0 = C<FALSE>, non-0.0 =
+C<TRUE>.
=item C<void set_string_native(STRING *value)>
-Sets the value to C<*value> evaluated in a boolean context.
+Sets the Boolean to the value represented by the specified string. All values are
+considered C<TRUE> except for C<""> and C<"0>", which are considered
+C<FALSE>.
=cut
*/
- VTABLE void set_string_native(STRING *value) {
+ VTABLE void set_bool (INTVAL value) {
+ set_boolean_FLAG(SELF, value);
+ }
+
+ VTABLE void set_integer_native (INTVAL value) {
+ SELF.set_bool(value);
+ }
+
+ VTABLE void set_number_native (FLOATVAL value) {
+ SELF.set_bool(!FLOAT_IS_ZERO(value));
+ }
+
+ VTABLE void set_string_native (STRING *value) {
SELF.set_bool(Parrot_str_boolean(INTERP, value));
}
+/** VTABLE PMC *neg (PMC *dest) {
+ dest = Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
+ SELF.get_bool());
+ return dest;
+ }
+
+ VTABLE void i_neg () {
+ /* Nothing to do for an in-place negate.
+ }**/
+
+ /* No POD documentation, since the reader should see Scalar. */
+
+ VTABLE void i_logical_not () {
+ flip_boolean_FLAG(SELF);
+ }
+
/*
-=item C<PMC *neg(PMC *dest)>
+=item C<void freeze(PMC *info)>
-=item C<void i_neg()>
+Used to archive the C<Boolean>.
-Set C<dest> to the ''negated'' value of C<SELF>. The negative of a
-boolean value is the identical value.
+=item C<void thaw(PMC *info)>
+
+Used to unarchive the C<Boolean>.
=cut
*/
- VTABLE PMC *neg(PMC *dest) {
- dest = Parrot_pmc_new_init_int(INTERP, VTABLE_type(INTERP, SELF),
- SELF.get_bool());
- return dest;
+ VTABLE void freeze (PMC *info) {
+ SUPER(info);
+ VTABLE_push_integer(INTERP, info, SELF.get_bool());
}
- VTABLE void i_neg() {
+ VTABLE void thaw (PMC *info) {
+ SUPER(info);
+ SELF.set_bool(VTABLE_shift_integer(INTERP, info));
}
+
}
/*
=back
+See also the C<Scalar> PMC.
+
=cut
*/
-/*
- * Local variables:
+/* Local variables:
* c-file-style: "parrot"
* End:
* vim: expandtab shiftwidth=4:
Modified: branches/sleeker_boolean/t/oo/objects.t
==============================================================================
--- branches/sleeker_boolean/t/oo/objects.t Sun Sep 12 13:45:25 2010 (r48956)
+++ branches/sleeker_boolean/t/oo/objects.t Sun Sep 12 14:53:03 2010 (r48957)
@@ -21,7 +21,7 @@
.include "iglobals.pasm"
.include "interpinfo.pasm"
- plan(194)
+ plan(191)
get_classname_from_class()
test_get_class()
@@ -143,15 +143,6 @@
isa $I0, $P1, "calar"
is( $I0, 0, 'Boolean !isa calar' )
- isa $I0, $P1, "Integer"
- is( $I0, 1, 'Boolean isa Integer' )
-
- isa $I0, $P1, "Integ"
- is( $I0, 0, 'Boolean !isa Integ' )
-
- isa $I0, $P1, "eger"
- is( $I0, 0, 'Boolean !isa eger' )
-
isa $I0, $P1, " "
is( $I0, 0, 'Boolean !isa " "' )
Modified: branches/sleeker_boolean/t/pmc/boolean.t
==============================================================================
--- branches/sleeker_boolean/t/pmc/boolean.t Sun Sep 12 13:45:25 2010 (r48956)
+++ branches/sleeker_boolean/t/pmc/boolean.t Sun Sep 12 14:53:03 2010 (r48957)
@@ -116,9 +116,9 @@
set $I0, $P1
is($I0, 1, "cloned Boolean is not a reference")
- set $P1, 0
+ set $P1, 1
set $I0, $P1
- is($I0, 0, "cloned Boolean can change value")
+ is($I0, 1, "cloned Boolean can change value")
.end
.sub boolean_as_conditional
More information about the parrot-commits
mailing list