Author: particle
Date: Sat Mar 24 09:09:48 2007
New Revision: 17712
Added:
trunk/src/pmc/exporter.pmc (contents, props changed)
trunk/t/pmc/exporter.t (contents, props changed)
Modified:
trunk/MANIFEST
Log:
[pmc]: beginnings of an Exporter PMC
~ more to come shortly
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Sat Mar 24 09:09:48 2007
@@ -2562,6 +2562,7 @@
src/pmc/eval.pmc []
src/pmc/exception.pmc []
src/pmc/exception_handler.pmc []
+src/pmc/exporter.pmc []
src/pmc/file.pmc []
src/pmc/fixedbooleanarray.pmc []
src/pmc/fixedfloatarray.pmc []
@@ -2940,6 +2941,7 @@
t/pmc/unmanagedstruct.t []
t/pmc/version.t []
t/pmc/vtablecache.t []
+t/pmc/exporter.t []
t/run/README []
t/run/exit.t []
t/run/options.t []
Added: trunk/src/pmc/exporter.pmc
==============================================================================
--- (empty file)
+++ trunk/src/pmc/exporter.pmc Sat Mar 24 09:09:48 2007
@@ -0,0 +1,188 @@
+/*
+Copyright (C) 2007, The Perl Foundation.
+$Id$
+
+=head1 NAME
+
+src/pmc/exporter.pmc - Export globals from one namespace to another
+
+=head1 DESCRIPTION
+
+Exports globals from one namespace to another
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+#define PARROT_EXPORTER(e) ((Parrot_Exporter *) PMC_data(e))
+
+typedef struct Parrot_Exporter {
+ PMC *ns_src; /* The source NameSpace PMC */
+ PMC *ns_dest; /* The destination NameSpace PMC */
+ PMC *globals; /* The globals to export - a ResizableStringArray */
+} Parrot_Exporter;
+
+
+pmclass Exporter
+ need_ext {
+
+
+/*
+
+=item C<void init()>
+
+Instantiates an Exporter.
+
+=cut
+
+*/
+
+ void init() {
+ Parrot_Exporter *exp = NULL;
+
+ /* Custom DOD mark and destory. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* Set up the object. */
+ exp = mem_sys_allocate_zeroed(sizeof(Parrot_Exporter));
+ exp->ns_src = pmc_new(interp, enum_class_NameSpace);
+ exp->ns_dest = pmc_new(interp, enum_class_NameSpace);
+ exp->globals = pmc_new(interp, enum_class_ResizableStringArray);
+ PMC_data(SELF) = exp;
+ }
+
+
+/*
+
+=item C<void src(PMC *)>
+
+Return the C<globals> array.
+
+=cut
+
+*/
+
+ PCCMETHOD void src(PMC *src :optional, int got_src :opt_flag) {
+ Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
+ PMC *ret_ns_src;
+
+ /* TODO deal with non-namespace pmcs */
+ if (got_src) {
+ exp->ns_src = VTABLE_clone(interp, src);
+ }
+ else {
+ ret_ns_src = VTABLE_clone(interp, exp->ns_src);
+ PCCRETURN(PMC *ret_ns_src);
+ }
+ }
+
+
+/*
+
+=item C<PMC *globals(void)>
+
+Return the C<globals> array.
+
+=cut
+
+*/
+
+ PCCMETHOD void globals() {
+ Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
+ PMC *ret_globals = VTABLE_clone(interp, exp->globals);
+ PCCRETURN(PMC *ret_globals);
+ }
+
+
+/*
+
+=item C<void add_global(PMC *global)>
+
+Add C<global> to the array of globals.
+
+=cut
+
+*/
+
+ void add_global(PMC *global) {
+ Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
+ PMC *globals = exp->globals;
+ }
+
+
+/*
+
+=item C<PMC *import(PMC *dest, PMC *src, PMC *globals)>
+
+Import C<globals> from the C<src> namespace to the C<dest> namespace.
+
+=cut
+
+*/
+
+ PMC *import(PMC *dest, PMC *src, PMC *globals) {
+ Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
+ /* */
+ return PMCNULL;
+ }
+
+/*
+
+=item C<void destory()>
+
+Free the object's underlying struct.
+
+=cut
+
+*/
+ void destroy() {
+ mem_sys_free(PMC_data(SELF));
+ }
+
+
+/*
+
+=item C<void mark()>
+
+Mark any referenced strings and PMCs.
+
+=cut
+
+*/
+ void mark() {
+ Parrot_Exporter *exp = PARROT_EXPORTER(SELF);
+ if (exp->ns_src)
+ pobject_lives(interp, (PObj*)exp->ns_src);
+ if (exp->ns_dest)
+ pobject_lives(interp, (PObj*)exp->ns_dest);
+ if (exp->globals)
+ pobject_lives(interp, (PObj*)exp->globals);
+ }
+
+
+}
+
+/*
+
+=back
+
+=head1 SEE ALSO
+
+F<docs/pdds/pdd17_basic_types.pod>.
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
Added: trunk/t/pmc/exporter.t
==============================================================================
--- (empty file)
+++ trunk/t/pmc/exporter.t Sat Mar 24 09:09:48 2007
@@ -0,0 +1,61 @@
+#!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 => 2;
+
+=head1 NAME
+
+t/pmc/exporter.t - test the Exporter PMC
+
+=head1 SYNOPSIS
+
+ % prove t/pmc/exporter.t
+
+=head1 DESCRIPTION
+
+Tests the Exporter PMC.
+
+=cut
+
+# L<PDD17/Exporter PMC>
+# TODO fix smartlinks once this is specced
+pir_output_is( <<'CODE', <<'OUT', 'new' );
+.sub 'test' :main
+ $P0 = new .Exporter
+ say 'ok 1 - $P0 = new .Exporter'
+
+ $I0 = isa $P0, 'Exporter'
+ if $I0 goto ok_2
+ print 'not '
+ ok_2:
+ say "ok 2 - isa $P0, 'Exporter'"
+.end
+CODE
+ok 1 - $P0 = new .Exporter
+ok 2 - isa $P0, 'Exporter'
+OUT
+
+
+pir_output_is( <<'CODE', <<'OUT', 'globals' );
+.sub 'test' :main
+ $P0 = new .Exporter
+
+ $P1 = $P0.'globals'()
+.end
+CODE
+OUT
+
+
+## TODO add more tests as this is documented and implemented
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4: