Author: jonathan
Date: Wed Jun  6 15:56:04 2007
New Revision: 18848

Added:
   trunk/src/pmc/pmcproxy.pmc   (contents, props changed)
   trunk/t/pmc/pmcproxy.t   (contents, props changed)
Modified:
   trunk/MANIFEST

Log:
[PDD17] Start to stub in the PMCProxy PMC, which will eventually allow a PMC to 
sit in an inheritance hierarchy, be introspected and so on.

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Wed Jun  6 15:56:04 2007
@@ -2653,6 +2653,7 @@
 src/pmc/parrotthread.pmc                                    []
 src/pmc/pccmethod_test.pmc                                  []
 src/pmc/pmc.num                                             []
+src/pmc/pmcproxy.pmc                                        []
 src/pmc/pointer.pmc                                         []
 src/pmc/random.pmc                                          []
 src/pmc/ref.pmc                                             []
@@ -3034,6 +3035,7 @@
 t/pmc/parrotthread.t                                        []
 t/pmc/pccmethod_test.t                                      []
 t/pmc/pmc.t                                                 []
+t/pmc/pmcproxy.t                                            []
 t/pmc/pointer.t                                             []
 t/pmc/prop.t                                                []
 t/pmc/random.t                                              []

Added: trunk/src/pmc/pmcproxy.pmc
==============================================================================
--- (empty file)
+++ trunk/src/pmc/pmcproxy.pmc  Wed Jun  6 15:56:04 2007
@@ -0,0 +1,167 @@
+/*
+Copyright (C) 2001-2007, The Perl Foundation.
+$Id$
+
+=head1 NAME
+
+src/pmc/pmcproxy.pmc - proxy class object for a PMC enabling introspection
+
+=head1 DESCRIPTION
+
+This class is used to describe a PMC. It can sit in an inheritance hierarchy
+of a PDD15 class as well as allowing introspection of the PMC.
+
+Class is not derived from any other PMC.
+
+=head2 Structure
+
+This class stores its state in the Parrot_PMCProxy structure, which has the
+following fields.
+
+=over 4
+
+=item C<id>
+
+The type number of the PMC that is being described.
+
+=item C<name>
+
+The name of the PMC -- a STRING.
+
+=item C<namespace>
+
+The namespace the PMC is associated with, if any.
+
+=item C<parents>
+
+An array of immediate parent classes.
+An empty ResizablePMCArray PMC is allocated during initialization.
+
+=item C<all_parents>
+
+A cached array of ourself and all parent classes, in MRO order.
+A ResizablePMCArray PMC is allocated during initialization,
+and is populated with the current class.
+
+=back
+
+NOTE: No doubt we will need other things later; this is a start.
+
+*/
+
+#include "parrot/parrot.h"
+
+typedef struct Parrot_PMCProxy {
+    int id;               /* The type number of the PMC. */
+    STRING *name;         /* The name of the PMC. */
+    PMC *_namespace;      /* The namespace it's linked to, if any. */
+    PMC *parents;         /* Proxy PMCs of any immediate parent classes. */
+    PMC *all_parents;     /* Cached list of ourself and all parents, in MRO 
order. */
+} Parrot_PMCProxy;
+
+/* Macro to access underlying structure of a PMCProxy PMC. */
+#define PARROT_PMCPROXY(o) ((Parrot_PMCProxy *) PMC_data(o))
+
+/*
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+pmclass PMCProxy
+    need_ext {
+
+/*
+
+=item C<void init()>
+
+Initializes a PMCProxy PMC.
+
+=cut
+
+*/
+
+    void init() {
+        Parrot_PMCProxy *_pmc = NULL;
+
+        /* Set flags for custom DOD mark and destroy. */
+        PObj_custom_mark_SET(SELF);
+        PObj_active_destroy_SET(SELF);
+
+        /* We are a class. */
+        PObj_is_class_SET(SELF);
+
+        /* Set up the object. */
+        _pmc = mem_allocate_zeroed_typed(Parrot_PMCProxy);
+        _pmc->id              = 0;
+        _pmc->name            = CONST_STRING(interp, "");
+        _pmc->_namespace      = PMCNULL;
+        _pmc->parents         = pmc_new(interp, enum_class_ResizablePMCArray);
+        _pmc->all_parents     = pmc_new(interp, enum_class_ResizablePMCArray);
+
+        /* We put ourself on the all parents list. */
+        VTABLE_push_pmc(interp, _pmc->all_parents, SELF);
+        
+        PMC_data(SELF)         = _pmc;
+    }
+
+/*
+
+=item C<void destroy()>
+
+Free the memory associated with the object's underlying struct.
+
+=cut
+
+*/
+
+    void destroy() {
+            mem_sys_free(PMC_data(SELF));
+    }
+
+/*
+
+=item C<void mark()>
+
+Mark any referenced strings and PMCs in the structure as live.
+
+=cut
+
+*/
+
+    void mark() {
+        Parrot_PMCProxy * const _pmc = PARROT_PMCPROXY(SELF);
+        if (_pmc->name)
+            pobject_lives(interp, (PObj*)_pmc->name);
+        if (_pmc->_namespace)
+            pobject_lives(interp, (PObj*)_pmc->_namespace);
+        if (_pmc->parents)
+            pobject_lives(interp, (PObj*)_pmc->parents);
+        if (_pmc->all_parents)
+            pobject_lives(interp, (PObj*)_pmc->all_parents);
+    }
+
+} /* END pmclass */
+
+/*
+
+=back
+
+=head1 SEE ALSO
+
+F<docs/pdds/pdd17_pmc.pod>.
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Added: trunk/t/pmc/pmcproxy.t
==============================================================================
--- (empty file)
+++ trunk/t/pmc/pmcproxy.t      Wed Jun  6 15:56:04 2007
@@ -0,0 +1,46 @@
+#!perl
+# Copyright (C) 2007, The Perl Foundation.
+# $Id$
+
+use strict;
+use warnings;
+use lib qw( . lib ../lib ../../lib );
+use Test::More;
+use Parrot::Test tests => 1;
+
+=head1 NAME
+
+t/pmc/pmcproxy.t - test the PMCProxy PMC
+
+=head1 SYNOPSIS
+
+    % prove t/pmc/pmcproxy.t
+
+=head1 DESCRIPTION
+
+Tests the PMCProxy PMC.
+
+=cut
+
+pir_output_is( <<'CODE', <<'OUT', 'new' );
+.sub 'test' :main
+    new $P0, .PMCProxy
+    say 'ok 1 - $P0 = new .PMCProxy'
+
+    $I0 = isa $P0, 'PMCProxy'
+    if $I0 goto ok_2
+    print 'not '
+  ok_2:
+    say "ok 2 - isa $P0, 'PMCProxy'"
+.end
+CODE
+ok 1 - $P0 = new .PMCProxy
+ok 2 - isa $P0, 'PMCProxy'
+OUT
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Reply via email to