Index: src/dynpmc/pair.pmc =================================================================== --- src/dynpmc/pair.pmc (revision 37815) +++ src/dynpmc/pair.pmc (working copy) @@ -1,356 +0,0 @@ -/* -Copyright (C) 2005-2009, Parrot Foundation. -$Id$ - -=head1 NAME - -src/pmc/pair.pmc - Pair PMC - -=head1 DESCRIPTION - -A Pair PMC represents one key => value mapping like a one element hash. - -'EclectusPair' subclasses this. - -=head2 Functions - -=over 4 - -=cut - -*/ - -#include "parrot/parrot.h" -#include "pmc_pair.h" - -pmclass Pair dynpmc need_ext { - ATTR PMC *key; - ATTR PMC *value; - -/* - -=item C - -Initializes the instance. - -=item C - -Class method to construct an Integer according to passed arguments. - -=cut - -*/ - - VTABLE void init() { - PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_Pair_attributes); - PObj_custom_mark_SET(SELF); - } - - VTABLE PMC *instantiate(PMC *sig) { - return PMCNULL; - - /* TODO -- really create this thing */ -#if 0 - PMC * const _class = REG_PMC(interp, 2); - Parrot_Pair_attributes *pair = PARROT_PAIR(SELF); - const int argcP = REG_INT(interp, 3); - const int argcS = REG_INT(interp, 2); - - SELF = pmc_new(INTERP, _class->vtable->base_type); - if (argcS == 1 && argcP == 1) { - PObj_key_is_string_SET(SELF); - pair->key = REG_STR(interp, 5); - pair->value = REG_PMC(interp, 5); - } - else if (argcP == 2) { - pair->key = REG_PMC(interp, 5); - pair->value = REG_PMC(interp, 6); - } - else - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, - "wrong argument count for Pair creation"); - - return SELF; -#endif - } -/* - -=item C - -Marks the hash as live. - -=cut - -*/ - - VTABLE void mark() { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - - if (pair->key) - pobject_lives(INTERP, (PObj *)pair->key); - - if (pair->value) - pobject_lives(INTERP, (PObj *)pair->value); - } - -/* - -=item C - -=item C - -=cut - -*/ - - VTABLE PMC *get_pmc_keyed_str(STRING *key) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - /* check key ? */ - return pair->value; - } - - VTABLE PMC *get_pmc_keyed(PMC *key) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - /* check key ? */ - return pair->value; - } - -/* - -=item C - -=item C - -Set key and value. The key can only set once. - -=item C - -Set the value of the Pair. - -=cut - -*/ - - VTABLE void set_pmc_keyed(PMC *key, PMC *value) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - - if (pair->key) - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, - "attempt to set existing Pair key"); - - - pair->key = key; - pair->value = value; - } - - - VTABLE void set_pmc_keyed_str(STRING *key, PMC *value) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - PMC *key_pmc; - - if (pair->key) - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, - "attempt to set existing Pair key"); - - - key_pmc = pmc_new(interp, enum_class_String); - VTABLE_set_string_native(interp, key_pmc, key); - - pair->key = key_pmc; - pair->value = value; - } - - VTABLE void assign_pmc(PMC *value) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - pair->value = value; - } - -/* - -=item C - -Sets this pair to hold the value of another. - -=cut - -*/ - - void set_pmc(PMC *pair) { - if (pair->vtable->base_type == SELF->vtable->base_type) { - Parrot_Pair_attributes * const from = PARROT_PAIR(SELF); - Parrot_Pair_attributes * const to = PARROT_PAIR(SELF); - - to->key = from->key; - to->value = from->value; - } - else - Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION, - "Can only set a pair to another pair."); - } - -/* - -=item C - -The C<==> operation. - -Check if two Pairs hold the same keys and values. - -=cut - -*/ - - VTABLE INTVAL is_equal(PMC *value) { - Parrot_Pair_attributes * const from = PARROT_PAIR(SELF); - Parrot_Pair_attributes * const to = PARROT_PAIR(SELF); - PMC *p1, *p2; - PMC *k1, *k2; - INTVAL result; - - if (value->vtable->base_type != SELF->vtable->base_type) - return 0; - - k1 = from->key; - k2 = to->key; - - Parrot_mmd_multi_dispatch_from_c_args(INTERP, "is_equal", - "PP->I", k1, k2, &result); - if (!result) - return 0; - - p1 = from->value; - p2 = to->value; - - if (!p1 && !p2) - return 1; - else - return 0; - } - -/* - -=item C - -Used during archiving to visit the elements in the pair. - -=item C - -Used to archive the Pair. - -=item C - -Used to unarchive the Pair. - -=cut - -*/ - - VTABLE void visit(visit_info *info) { - PMC **pos; - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - IMAGE_IO * const io = info->image_io; - DPOINTER ** const temp_pos = (DPOINTER **)pair->key; - info->thaw_ptr = (PMC **)temp_pos; - (info->visit_pmc_now)(INTERP, (PMC *)temp_pos, info); - - pos = &pair->value; - info->thaw_ptr = pos; - - (info->visit_pmc_now)(INTERP, *pos, info); - - SUPER(info); - } - - VTABLE void freeze(visit_info *info) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - IMAGE_IO * const io = info->image_io; - SUPER(info); - VTABLE_push_pmc(INTERP, io, pair->key); - VTABLE_push_pmc(INTERP, io, pair->value); - } - - VTABLE void thaw(visit_info *info) { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - IMAGE_IO * const io = info->image_io; - - SUPER(info); - - pair->key = VTABLE_shift_pmc(interp, io); - pair->value = VTABLE_shift_pmc(interp, io); - } -/* - -=back - -=head2 Methods - -=over 4 - -=item C - -Return the key of the pair. - -=cut - -*/ - - METHOD key() { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - PMC *key = pair->key; - - RETURN(PMC *key); - } - -/* - -=item C - -Return the value of the pair. - -=cut - -*/ - - METHOD value() { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - PMC * const value = pair->value; - RETURN(PMC *value); - } - -/* - -=item C - -Return a tuple of (key, value) for the pair. - -=cut - -*/ - - METHOD kv() { - Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF); - PMC * const t = pmc_new(INTERP, - Parrot_get_ctx_HLL_type(INTERP, enum_class_FixedPMCArray)); - - VTABLE_set_integer_native(INTERP, t, 2); - VTABLE_set_pmc_keyed_int(INTERP, t, 0, pair->key); - - VTABLE_set_pmc_keyed_int(INTERP, t, 1, pair->value); - RETURN(PMC *t); - } -} - -/* - -=back - -=cut - -*/ - -/* - * Local variables: - * c-file-style: "parrot" - * End: - * vim: expandtab shiftwidth=4: - */ Index: MANIFEST =================================================================== --- MANIFEST (revision 37815) +++ MANIFEST (working copy) @@ -1,7 +1,7 @@ # ex: set ro: # $Id$ # -# generated by tools/dev/mk_manifest_and_skip.pl Sat Mar 28 14:40:23 2009 UT +# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 30 01:40:17 2009 UT # # See tools/dev/install_files.pl for documentation on the # format of this file. @@ -1240,7 +1240,6 @@ src/dynpmc/foo.pmc [devel]src src/dynpmc/gdbmhash.pmc [devel]src src/dynpmc/main.pasm [] -src/dynpmc/pair.pmc [devel]src src/dynpmc/rational.pmc [devel]src src/dynpmc/rotest.pmc [devel]src src/dynpmc/subproxy.pmc [devel]src @@ -1667,7 +1666,6 @@ t/dynpmc/dynlexpad.t [test] t/dynpmc/foo.t [test] t/dynpmc/gdbmhash.t [test] -t/dynpmc/pair.t [test] t/dynpmc/rational.t [test] t/dynpmc/rotest.t [test] t/dynpmc/subclass_with_pir_method.t [test] Index: t/dynpmc/pair.t =================================================================== --- t/dynpmc/pair.t (revision 37815) +++ t/dynpmc/pair.t (working copy) @@ -1,85 +0,0 @@ -#! parrot -# Copyright (C) 2001-2009, Parrot Foundation. -# $Id$ - -.const int NUM_OF_TESTS = 8 - -.sub main :main - loadlib $P1, 'pair' - load_bytecode 'library/Test/More.pir' - - .local pmc plan, is, ok - plan = get_hll_global [ 'Test'; 'More' ], 'plan' - is = get_hll_global [ 'Test'; 'More' ], 'is' - ok = get_hll_global [ 'Test'; 'More' ], 'ok' - - # set a test plan - plan(NUM_OF_TESTS) - - new $P0, ['Pair'] - ok(1, "still alive") - new $P1, ['Integer'] - set $P1, 42 - set $P0["key"], $P1 - ok(1, "still alive") - set $P2, $P0["key"] - is($P2, 42, "fetching value") - - .local pmc p, kv - new p, ['Pair'] - new $P1, ['Integer'] - set $P1, 42 - set p["key"], $P1 - - $P0 = p."key"() - is( $P0, 'key', 'get key' ) - $P0 = p."value"() - is( $P0, 42, 'get key' ) - kv = p."kv"() - $I0 = elements kv - is( $I0, 2, 'number of elements returned from "kv"' ) - $P0 = kv[0] - is( $P0, 'key', 'first element returned from "kv"' ) - $P0 = kv[1] - is( $P0, 42, 'third element returned from "kv"' ) -.end - -=for get it - -SKIP: { - skip( "instantiate disabled", 1 ); - pir_output_is( <<'CODE', <<'OUT', 'instantiate, assign' ); -.sub main :main - .local pmc cl, p, kv, k, v - k = new ['String'] - k = "key" - v = new ['String'] - v = "value" - cl = get_class "Pair" - p = cl."instantiate"(k, v) - - $P0 = p."key"() - print $P0 - print ' ' - $P0 = p."value"() - print $P0 - print ' ' - - v = new ['Integer'] - v = 77 - assign p, v - $P0 = p."value"() - say $P0 -.end -CODE -key value 77 -OUT -} - -=cut - -# Local Variables: -# mode: pir -# fill-column: 100 -# End: -# vim: expandtab shiftwidth=4 ft=pir: Index: config/gen/makefiles/dynpmc.in =================================================================== --- config/gen/makefiles/dynpmc.in (revision 37815) +++ config/gen/makefiles/dynpmc.in (working copy) @@ -34,7 +34,6 @@ PMC_TARGETS := \ dynlexpad$(LOAD_EXT) \ foo$(LOAD_EXT) \ - pair$(LOAD_EXT) \ rotest$(LOAD_EXT) \ #IF(has_gdbm): gdbmhash$(LOAD_EXT) \ rational$(LOAD_EXT) \ @@ -122,18 +121,6 @@ foo.dump: foo.pmc $(PMC2CD) foo.pmc -pair$(LOAD_EXT): pair$(O) - $(LD) $(LD_OUT)pair$(LOAD_EXT) pair$(O) $(LINKARGS) - -pair$(O): pair.c - $(CC) $(CC_OUT)pair$(O) $(INCLUDES) $(CFLAGS) pair.c - -pair.c: pair.dump - $(PMC2CC) pair.pmc - -pair.dump: pair.pmc - $(PMC2CD) pair.pmc - rotest$(LOAD_EXT): rotest$(O) $(LD) $(LD_OUT)rotest$(LOAD_EXT) rotest$(O) $(LINKARGS)