[svn:parrot] r48965 - in trunk: . compilers/data_json compilers/imcc compilers/pct compilers/pge compilers/tge config/auto/sizes config/auto/zlib docs/book/draft docs/book/pct docs/dev docs/pdds examples/benchmarks examples/embed examples/languages/abc examples/languages/squaak examples/pge examples/tools ext/nqp-rx include/parrot lib/Parrot lib/Parrot/Configure/Step ports/cygwin ports/debian runtime/parrot/languages runtime/parrot/library runtime/parrot/library/Math src/call src/gc src/interp src/pmc src/runcore t/codingstd t/compilers/tge t/examples t/oo t/pmc t/src t/steps/init/hints tools/build tools/dev tools/release
Paul at osuosl.org
Paul at osuosl.org
Sun Sep 12 16:31:59 UTC 2010
Author: Paul C. Anagnostopoulos
Date: Sun Sep 12 16:31:59 2010
New Revision: 48965
URL: https://trac.parrot.org/parrot/changeset/48965
Log:
Merging sleeker_boolean branch into trunk as per TT #1770
Added:
trunk/examples/benchmarks/boolean.pir
- copied unchanged from r48964, branches/sleeker_boolean/examples/benchmarks/boolean.pir
Modified:
trunk/ (props changed)
trunk/MANIFEST
trunk/compilers/data_json/Rules.mak (props changed)
trunk/compilers/imcc/Rules.in (props changed)
trunk/compilers/pct/Rules.mak (props changed)
trunk/compilers/pge/Rules.mak (props changed)
trunk/compilers/tge/Rules.mak (props changed)
trunk/config/auto/sizes/intval_maxmin_c.in (props changed)
trunk/config/auto/zlib/ (props changed)
trunk/docs/book/draft/README (props changed)
trunk/docs/book/draft/appa_glossary.pod (props changed)
trunk/docs/book/draft/appb_patch_submission.pod (props changed)
trunk/docs/book/draft/appc_command_line_options.pod (props changed)
trunk/docs/book/draft/appd_build_options.pod (props changed)
trunk/docs/book/draft/appe_source_code.pod (props changed)
trunk/docs/book/draft/ch01_introduction.pod (props changed)
trunk/docs/book/draft/ch02_getting_started.pod (props changed)
trunk/docs/book/draft/ch07_dynpmcs.pod (props changed)
trunk/docs/book/draft/ch08_dynops.pod (props changed)
trunk/docs/book/draft/ch10_opcode_reference.pod (props changed)
trunk/docs/book/draft/ch11_directive_reference.pod (props changed)
trunk/docs/book/draft/ch12_operator_reference.pod (props changed)
trunk/docs/book/draft/chXX_hlls.pod (props changed)
trunk/docs/book/draft/chXX_library.pod (props changed)
trunk/docs/book/draft/chXX_testing_and_debugging.pod (props changed)
trunk/docs/book/pct/ch01_introduction.pod (props changed)
trunk/docs/book/pct/ch02_getting_started.pod (props changed)
trunk/docs/book/pct/ch03_compiler_tools.pod (props changed)
trunk/docs/book/pct/ch04_pge.pod (props changed)
trunk/docs/book/pct/ch05_nqp.pod (props changed)
trunk/docs/dev/c_functions.pod (props changed)
trunk/docs/pdds/pdd30_install.pod (props changed)
trunk/examples/embed/cotorra.c (props changed)
trunk/examples/languages/abc/ (props changed)
trunk/examples/languages/squaak/ (props changed)
trunk/examples/pge/demo.pir (props changed)
trunk/examples/tools/pgegrep (props changed)
trunk/ext/nqp-rx/Rules.mak (props changed)
trunk/include/parrot/call.h (props changed)
trunk/include/parrot/gc_api.h (props changed)
trunk/include/parrot/runcore_api.h (props changed)
trunk/include/parrot/runcore_profiling.h (props changed)
trunk/include/parrot/runcore_trace.h (props changed)
trunk/lib/Parrot/Configure/Step/Test.pm (props changed)
trunk/lib/Parrot/H2inc.pm (props changed)
trunk/ports/cygwin/parrot-1.0.0-1.cygport (props changed)
trunk/ports/debian/libparrot-dev.install.in (props changed)
trunk/ports/debian/libparrot.install.in (props changed)
trunk/ports/debian/parrot-doc.install.in (props changed)
trunk/ports/debian/parrot.install.in (props changed)
trunk/runtime/parrot/languages/ (props changed)
trunk/runtime/parrot/library/Math/Rand.pir (props changed)
trunk/runtime/parrot/library/Rules.mak (props changed)
trunk/src/call/ops.c (props changed)
trunk/src/call/pcc.c (props changed)
trunk/src/gc/alloc_memory.c (props changed)
trunk/src/gc/alloc_resources.c (props changed)
trunk/src/gc/api.c (props changed)
trunk/src/gc/malloc.c (props changed)
trunk/src/gc/malloc_trace.c (props changed)
trunk/src/gc/mark_sweep.c (props changed)
trunk/src/gc/system.c (props changed)
trunk/src/interp/inter_cb.c (props changed)
trunk/src/interp/inter_create.c (props changed)
trunk/src/interp/inter_misc.c (props changed)
trunk/src/pmc/boolean.pmc
trunk/src/runcore/cores.c (props changed)
trunk/src/runcore/main.c (props changed)
trunk/src/runcore/profiling.c (props changed)
trunk/src/runcore/trace.c (props changed)
trunk/t/codingstd/pmc_docs.t (props changed)
trunk/t/compilers/tge/NoneGrammar.tg (props changed)
trunk/t/examples/pgegrep.t (props changed)
trunk/t/oo/objects.t (contents, props changed)
trunk/t/oo/root_new.t (props changed)
trunk/t/pmc/boolean.t
trunk/t/pmc/namespace-old.t (props changed)
trunk/t/src/embed.t (props changed)
trunk/t/steps/init/hints/linux-01.t (props changed)
trunk/tools/build/README (props changed)
trunk/tools/build/h2inc.pl (props changed)
trunk/tools/dev/README (props changed)
trunk/tools/dev/addopstags.pl (props changed)
trunk/tools/dev/dump_pbc.pl (props changed)
trunk/tools/dev/fetch_languages.pl (props changed)
trunk/tools/dev/headerizer.pl (props changed)
trunk/tools/dev/mk_gitignore.pl (props changed)
trunk/tools/dev/ncidef2pasm.pl (props changed)
trunk/tools/dev/parrot-config.pir (props changed)
trunk/tools/dev/perlcritic-cage.conf (props changed)
trunk/tools/dev/perlcritic.conf (props changed)
trunk/tools/dev/perltidy.conf (props changed)
trunk/tools/dev/update_copyright.pl (props changed)
trunk/tools/release/crow.pir (props changed)
trunk/tools/release/gen_release_info.pl (props changed)
trunk/tools/release/inc_ver.pir (props changed)
trunk/tools/release/release.json (props changed)
trunk/tools/release/templates.json (props changed)
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST Sun Sep 12 16:15:07 2010 (r48964)
+++ trunk/MANIFEST Sun Sep 12 16:31:59 2010 (r48965)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Sun Sep 5 23:53:29 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sun Sep 12 16:20:50 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -511,6 +511,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]
Copied: trunk/examples/benchmarks/boolean.pir (from r48964, branches/sleeker_boolean/examples/benchmarks/boolean.pir)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/examples/benchmarks/boolean.pir Sun Sep 12 16:31:59 2010 (r48965, copy of r48964, branches/sleeker_boolean/examples/benchmarks/boolean.pir)
@@ -0,0 +1,63 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+=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: trunk/src/pmc/boolean.pmc
==============================================================================
--- trunk/src/pmc/boolean.pmc Sun Sep 12 16:15:07 2010 (r48964)
+++ trunk/src/pmc/boolean.pmc Sun Sep 12 16:31:59 2010 (r48965)
@@ -8,125 +8,196 @@
=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)
+
+#define set_boolean_FLAG(pmc, val) \
+ if (val) \
+ PObj_get_FLAGS(pmc) |= boolean_FLAG; \
+ else \
+ PObj_get_FLAGS(pmc) &= ~boolean_FLAG;
+
+#define flip_boolean_FLAG(pmc) \
+ PObj_get_FLAGS(pmc) ^= boolean_FLAG
+
+
+pmclass Boolean extends scalar provides boolean provides scalar manual_attrs {
/*
+=item C<void init()>
+
+Create a new C<Boolean> with initial value C<FALSE>.
+
=item C<void init_pmc(PMC *value)>
-Initialises SELF value according to the boolean value of the passed PMC.
+Create a new C<Boolean> with the given initial value interpreted
+as a Boolean.
=cut
*/
+
+ /* These two init functions set the boolean flag directly. */
+
+ VTABLE void init() {
+ set_boolean_FLAG(SELF, 0);
+ }
+
VTABLE void init_pmc(PMC *value) {
- INTVAL v = PMC_IS_NULL(value) ? (INTVAL) 0 : VTABLE_get_bool(INTERP, value);
- SELF.set_bool(v);
+ INTVAL v = PMC_IS_NULL(value) ? 0 : VTABLE_get_bool(INTERP, value);
+ set_boolean_FLAG(SELF, v);
}
+
/*
-=item C<STRING *get_string()>
+=item C<INTVAL get_bool()>
-Return "1" or "0".
+Obtain the value of the C<Boolean> as an integer: 1 = C<TRUE>, 0 = C<FALSE>.
-=cut
+=item C<INTVAL get_integer()>
-*/
- VTABLE STRING *get_string() {
- return SUPER();
- }
+Same as C<get_bool()>.
+=item C<FLOATVAL get_number()>
-/*
-
-=item C<void set_integer_native(INTVAL value)>
+Obtain the value of the C<Boolean> as a float: 1.0 = C<TRUE>, 0.0 = C<FALSE>.
-=item C<void set_bool(INTVAL value)>
+=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 FLOATVAL get_number() {
+ INTVAL value = SELF.get_bool();
+ return (FLOATVAL)value;
+ }
- VTABLE void set_bool(INTVAL value) {
- SELF.set_integer_native(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_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)>
+
+Used to archive the C<Boolean>.
-=item C<void i_neg()>
+=item C<void thaw(PMC *info)>
-Set C<dest> to the ''negated'' value of C<SELF>. The negative of a
-boolean value is the identical value.
+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
*/
Modified: trunk/t/oo/objects.t
==============================================================================
--- trunk/t/oo/objects.t Sun Sep 12 16:15:07 2010 (r48964)
+++ trunk/t/oo/objects.t Sun Sep 12 16:31:59 2010 (r48965)
@@ -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: trunk/t/pmc/boolean.t
==============================================================================
--- trunk/t/pmc/boolean.t Sun Sep 12 16:15:07 2010 (r48964)
+++ trunk/t/pmc/boolean.t Sun Sep 12 16:31:59 2010 (r48965)
@@ -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