Skip to content

Commit

Permalink
Add P5SV as a base class for P5 data
Browse files Browse the repository at this point in the history
This includes reference count logic; eventually will be much more.
  • Loading branch information
sorear committed Mar 18, 2010
1 parent 9fb0458 commit 882df17
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 83 deletions.
1 change: 1 addition & 0 deletions build/Makefile.in
Expand Up @@ -38,6 +38,7 @@ BLIZKOST_GROUP = $(PMC_DIR)/blizkost_group$(LOAD_EXT)

PMC_DEPS = \
build/src/pmc/Makefile.in \
$(PMC_DIR)/p5sv.pmc \
$(PMC_DIR)/p5array.pmc \
$(PMC_DIR)/p5hash.pmc \
$(PMC_DIR)/p5interpreter.pmc \
Expand Down
3 changes: 3 additions & 0 deletions build/src/pmc/Makefile.in
Expand Up @@ -44,6 +44,7 @@ LINKARGS = $(LDFLAGS) $(LD_LOAD_FLAGS) $(LIBPARROT) $(LIBPERL)
BLIZKOST_GROUP = blizkost_group

PMC_SOURCES = \
p5sv.pmc \
p5interpreter.pmc \
p5scalar.pmc \
p5array.pmc \
Expand All @@ -56,6 +57,7 @@ PMC_C = $(PMC_SOURCES:.pmc=.c)

OBJS = \
lib-$(BLIZKOST_GROUP)$(O) \
p5sv$(O) \
p5scalar$(O) \
p5array$(O) \
p5hash$(O) \
Expand Down Expand Up @@ -89,6 +91,7 @@ generate: init_with_xs.h $(PMC_SOURCES)
$(PMC2C) --no-lines --library $(BLIZKOST_GROUP) --c $(PMC_SOURCES)

compile: generate
$(CC) $(CC_OUT)p5sv$(O) $(INCLUDES) $(CFLAGS) p5sv.c
$(CC) $(CC_OUT)p5scalar$(O) $(INCLUDES) $(CFLAGS) p5scalar.c
$(CC) $(CC_OUT)p5array$(O) $(INCLUDES) $(CFLAGS) p5array.c
$(CC) $(CC_OUT)p5hash$(O) $(INCLUDES) $(CFLAGS) p5hash.c
Expand Down
2 changes: 1 addition & 1 deletion src/pmc/p5array.pmc
Expand Up @@ -14,5 +14,5 @@ These are the vtable functions for the P5Array class.

*/

pmclass P5Array provides array group blizkost_group dynpmc {
pmclass P5Array extends P5SV provides array group blizkost_group dynpmc {
}
5 changes: 1 addition & 4 deletions src/pmc/p5hash.pmc
Expand Up @@ -14,10 +14,7 @@ These are the vtable functions for the P5Hash class

*/

pmclass P5Hash group blizkost_group dynpmc provides hash {
VTABLE void init() {
}

pmclass P5Hash extends P5SV group blizkost_group dynpmc provides hash {
VTABLE PMC *get_pmc_keyed_str(STRING *key) {
}

Expand Down
65 changes: 2 additions & 63 deletions src/pmc/p5scalar.pmc
Expand Up @@ -30,70 +30,9 @@ These are the vtable functions for the P5Scalar class.
/* Plus need to know about the interpreter and invocation PMCs. */
#include "pmc_p5interpreter.h"
#include "pmc_p5invocation.h"
#include "pmc_p5sv.h"

pmclass P5Scalar group blizkost_group dynpmc {
ATTR PMC *p5i;
ATTR struct sv *sv;

/*

=item C<void init()>

Set up P5Scalar PMC.

=cut

*/

VTABLE void init() {
/* Set up the underlying structure. */
PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_P5Scalar_attributes);
PObj_custom_mark_SET(SELF);
PObj_custom_destroy_SET(SELF);
}

/*

=item C<void mark()>

Mark GC-ables.

=cut

*/
VTABLE void mark() {
if (PMC_data(SELF)) {
PMC *p5i;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
}
}


/*

=item C<void destroy()>

Decrement reference count of held SV.

=cut

*/
VTABLE void destroy() {
if (PMC_data(SELF)) {
PMC *p5i;
PerlInterpreter *my_perl;
struct sv *sv;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5Scalar_sv(interp, SELF, sv);
SvREFCNT_dec(sv);
mem_sys_free(PMC_data(SELF));
PMC_data(SELF) = NULL;
}
}

pmclass P5Scalar extends P5SV group blizkost_group dynpmc {

/*

Expand Down
16 changes: 1 addition & 15 deletions src/pmc/p5sub.pmc
Expand Up @@ -27,21 +27,7 @@ These are the vtable functions for the P5Sub class.
#include <EXTERN.h>
#include <perl.h>

pmclass P5Sub group blizkost_group dynpmc {

/*

=item C<void init()>

Set up P5Sub PMC.


=cut

*/

VTABLE void init() {
}
pmclass P5Sub extends P5SV group blizkost_group dynpmc {


/*
Expand Down
96 changes: 96 additions & 0 deletions src/pmc/p5sv.pmc
@@ -0,0 +1,96 @@
/*
Copyright (C) 2009-2010, Jonathan Worthington and friends
$Id$

=head1 NAME

src/pmc/p5sv.pmc - common base class for Perl 5 objects

=head1 DESCRIPTION

These are the vtable functions for the P5SV class.

=cut

*/

/* Various Perl 5 headers that we need. */
#undef __attribute__
#undef __attribute__noreturn__
#undef __attribute__deprecated__
#undef __attribute__pure__
#undef __attribute__format__
#undef __attribute__nonnull__
#undef __attribute__warn_unused_result__
#undef __attribute__unused__
#define __attribute__(x) /* */
#include <EXTERN.h>
#include <perl.h>

/* Plus need to know about the interpreter PMC. */
#include "pmc_p5interpreter.h"

pmclass P5SV group blizkost_group dynpmc {
ATTR PMC *p5i;
ATTR struct sv *sv;

/*

=item C<void init()>

Set up P5SV PMC.

=cut

*/

VTABLE void init() {
/* Set up the underlying structure. */
PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_P5SV_attributes);
PObj_custom_mark_SET(SELF);
PObj_custom_destroy_SET(SELF);
}

/*

=item C<void mark()>

Mark GC-ables.

=cut

*/
VTABLE void mark() {
if (PMC_data(SELF)) {
PMC *p5i;
GETATTR_P5Scalar_p5i(interp, SELF, p5i);
if (p5i)
Parrot_gc_mark_PObj_alive(interp, (PObj*)p5i);
}
}


/*

=item C<void destroy()>

Decrement reference count of held SV.

=cut

*/
VTABLE void destroy() {
if (PMC_data(SELF)) {
PMC *p5i;
PerlInterpreter *my_perl;
struct sv *sv;
GETATTR_P5SV_p5i(interp, SELF, p5i);
GETATTR_P5Interpreter_my_perl(interp, p5i, my_perl);
GETATTR_P5SV_sv(interp, SELF, sv);
SvREFCNT_dec(sv);
mem_sys_free(PMC_data(SELF));
PMC_data(SELF) = NULL;
}
}

}

0 comments on commit 882df17

Please sign in to comment.