[svn:parrot] r38074 - in branches/packfile_revamp: src/pmc t/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun Apr 12 08:01:45 UTC 2009
Author: bacek
Date: Sun Apr 12 08:01:43 2009
New Revision: 38074
URL: https://trac.parrot.org/parrot/changeset/38074
Log:
Implement PackfileAnnotation
Modified:
branches/packfile_revamp/src/pmc/packfileannotation.pmc
branches/packfile_revamp/t/pmc/packfileannotation.t
Modified: branches/packfile_revamp/src/pmc/packfileannotation.pmc
==============================================================================
--- branches/packfile_revamp/src/pmc/packfileannotation.pmc Sun Apr 12 02:07:29 2009 (r38073)
+++ branches/packfile_revamp/src/pmc/packfileannotation.pmc Sun Apr 12 08:01:43 2009 (r38074)
@@ -22,7 +22,47 @@
#include "parrot/parrot.h"
pmclass PackfileAnnotation {
+ ATTR INTVAL value;
+ ATTR INTVAL offset;
+ ATTR INTVAL key_id;
+/*
+
+=item C<init>
+
+Create empty PackfileAnnotation.
+
+=cut
+
+*/
+
+ VTABLE void init() {
+ Parrot_PackfileAnnotation_attributes * attrs =
+ mem_allocate_zeroed_typed(Parrot_PackfileAnnotation_attributes);
+
+ PObj_active_destroy_SET(SELF);
+ PMC_data(SELF) = attrs;
+ }
+
+/*
+
+=item C<void destroy()>
+
+Destroys the PMC and frees all allocated memory.
+
+=cut
+
+*/
+
+ VTABLE void destroy() {
+ Parrot_PackfileAnnotation_attributes * attrs =
+ PARROT_PACKFILEANNOTATION(SELF);
+
+ if (attrs) {
+ mem_sys_free(attrs);
+ PMC_data(SELF) = NULL;
+ }
+ }
/*
@@ -33,8 +73,9 @@
=cut
*/
- INTVAL get_offset() {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ METHOD get_offset() {
+ INTVAL offset = PARROT_PACKFILEANNOTATION(SELF)->offset;
+ RETURN(INTVAL offset);
}
@@ -47,8 +88,8 @@
=cut
*/
- void set_offset(INTVAL offset) {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ METHOD set_offset(INTVAL offset) {
+ PARROT_PACKFILEANNOTATION(SELF)->offset = offset;
}
@@ -61,8 +102,9 @@
=cut
*/
- INTVAL get_key_id() {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ METHOD get_key_id() {
+ INTVAL key_id = PARROT_PACKFILEANNOTATION(SELF)->key_id;
+ RETURN(INTVAL key_id);
}
@@ -75,8 +117,8 @@
=cut
*/
- void set_key_id(INTVAL offset) {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ METHOD set_key_id(INTVAL key_id) {
+ PARROT_PACKFILEANNOTATION(SELF)->key_id = key_id;
}
@@ -90,7 +132,7 @@
*/
VTABLE INTVAL get_integer() {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ return PARROT_PACKFILEANNOTATION(SELF)->value;
}
@@ -103,8 +145,8 @@
=cut
*/
- VTABLE void set_integer(INTVAL offset) {
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNIMPLEMENTED, "Not implemented yet.");
+ VTABLE void set_integer_native(INTVAL value) {
+ PARROT_PACKFILEANNOTATION(SELF)->value = value;
}
}
Modified: branches/packfile_revamp/t/pmc/packfileannotation.t
==============================================================================
--- branches/packfile_revamp/t/pmc/packfileannotation.t Sun Apr 12 02:07:29 2009 (r38073)
+++ branches/packfile_revamp/t/pmc/packfileannotation.t Sun Apr 12 08:01:43 2009 (r38074)
@@ -1,13 +1,6 @@
-#!perl
+#!parrot
# Copyright (C) 2006-2009, Parrot Foundation.
-use strict;
-use warnings;
-use lib qw( . lib ../lib ../../lib );
-use Test::More;
-use Parrot::Test tests => 1;
-use Parrot::Config;
-
=head1 NAME
t/pmc/packfileannotation.t - test the PackfileAnnotation PMC
@@ -23,16 +16,26 @@
=cut
+# PackfileAnnotation constructor
+.sub 'test' :main
+.include 'test_more.pir'
+ .local pmc pa
+
+ plan(4)
-# Packfile constructor
+ pa = new ['PackfileAnnotation']
+ $I0 = defined pa
+ ok($I0, 'PackfileAnnotation created')
+
+ pa = 42
+ pa.'set_key_id'(1)
+ pa.'set_offset'(115200)
+
+ $I0 = pa
+ is($I0, 42, 'Value stored and fetched')
+ $I0 = pa.'get_key_id'()
+ is($I0, 1, 'KeyId stored and fetched')
+ $I0 = pa.'get_offset'()
+ is($I0, 115200, 'Offset stored and fetched')
-pir_output_is( <<'CODE', <<'OUT', 'new' );
-.sub 'test' :main
- .local pmc pf
- pf = new ['PackfileAnnotation']
- $I0 = defined pf
- say $I0
.end
-CODE
-1
-OUT
More information about the parrot-commits
mailing list