Ticket #187: remove-pair

File remove-pair, 11.9 KB (added by kraai, 13 years ago)

Patch to remove Pair PMC

Line 
1Index: src/dynpmc/pair.pmc
2===================================================================
3--- src/dynpmc/pair.pmc (revision 37815)
4+++ src/dynpmc/pair.pmc (working copy)
5@@ -1,356 +0,0 @@
6-/*
7-Copyright (C) 2005-2009, Parrot Foundation.
8-$Id$
9-
10-=head1 NAME
11-
12-src/pmc/pair.pmc - Pair PMC
13-
14-=head1 DESCRIPTION
15-
16-A Pair PMC represents one key => value mapping like a one element hash.
17-
18-'EclectusPair' subclasses this.
19-
20-=head2 Functions
21-
22-=over 4
23-
24-=cut
25-
26-*/
27-
28-#include "parrot/parrot.h"
29-#include "pmc_pair.h"
30-
31-pmclass Pair dynpmc need_ext {
32-    ATTR PMC *key;
33-    ATTR PMC *value;
34-
35-/*
36-
37-=item C<void init()>
38-
39-Initializes the instance.
40-
41-=item C<PMC *instantiate(PMC *sig)>
42-
43-Class method to construct an Integer according to passed arguments.
44-
45-=cut
46-
47-*/
48-
49-    VTABLE void init() {
50-        PMC_data(SELF) = mem_allocate_zeroed_typed(Parrot_Pair_attributes);
51-        PObj_custom_mark_SET(SELF);
52-    }
53-
54-    VTABLE PMC *instantiate(PMC *sig) {
55-        return PMCNULL;
56-
57-        /* TODO -- really create this thing */
58-#if 0
59-        PMC * const  _class = REG_PMC(interp, 2);
60-        Parrot_Pair_attributes *pair   = PARROT_PAIR(SELF);
61-        const int    argcP  = REG_INT(interp, 3);
62-        const int    argcS  = REG_INT(interp, 2);
63-
64-        SELF = pmc_new(INTERP, _class->vtable->base_type);
65-        if (argcS == 1 && argcP == 1) {
66-            PObj_key_is_string_SET(SELF);
67-            pair->key   = REG_STR(interp, 5);
68-            pair->value = REG_PMC(interp, 5);
69-        }
70-        else if (argcP == 2) {
71-            pair->key   = REG_PMC(interp, 5);
72-            pair->value = REG_PMC(interp, 6);
73-        }
74-        else
75-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
76-                "wrong argument count for Pair creation");
77-
78-        return SELF;
79-#endif
80-    }
81-/*
82-
83-=item C<void mark()>
84-
85-Marks the hash as live.
86-
87-=cut
88-
89-*/
90-
91-    VTABLE void mark() {
92-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
93-
94-        if (pair->key)
95-            pobject_lives(INTERP, (PObj *)pair->key);
96-
97-        if (pair->value)
98-            pobject_lives(INTERP, (PObj *)pair->value);
99-    }
100-
101-/*
102-
103-=item C<PMC *get_pmc_keyed_str(STRING *key)>
104-
105-=item C<PMC *get_pmc_keyed(PMC *key)>
106-
107-=cut
108-
109-*/
110-
111-    VTABLE PMC *get_pmc_keyed_str(STRING *key) {
112-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
113-        /* check key ? */
114-        return pair->value;
115-    }
116-
117-    VTABLE PMC *get_pmc_keyed(PMC *key) {
118-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
119-        /* check key ? */
120-        return pair->value;
121-    }
122-
123-/*
124-
125-=item C<void set_pmc_keyed(PMC *key, PMC *value)>
126-
127-=item C<void set_pmc_keyed_str(STRING *key, PMC *value)>
128-
129-Set key and value. The key can only set once.
130-
131-=item C<void assign_pmc(PMC *value)>
132-
133-Set the value of the Pair.
134-
135-=cut
136-
137-*/
138-
139-    VTABLE void set_pmc_keyed(PMC *key, PMC *value) {
140-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
141-
142-        if (pair->key)
143-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
144-                "attempt to set existing Pair key");
145-
146-
147-        pair->key   = key;
148-        pair->value = value;
149-    }
150-
151-
152-    VTABLE void set_pmc_keyed_str(STRING *key, PMC *value) {
153-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
154-        PMC                *key_pmc;
155-
156-        if (pair->key)
157-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
158-                "attempt to set existing Pair key");
159-
160-
161-        key_pmc = pmc_new(interp, enum_class_String);
162-        VTABLE_set_string_native(interp, key_pmc, key);
163-
164-        pair->key   = key_pmc;
165-        pair->value = value;
166-    }
167-
168-    VTABLE void assign_pmc(PMC *value) {
169-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
170-        pair->value              = value;
171-    }
172-
173-/*
174-
175-=item C<void set_pmc(PMC *pair)>
176-
177-Sets this pair to hold the value of another.
178-
179-=cut
180-
181-*/
182-
183-    void set_pmc(PMC *pair) {
184-        if (pair->vtable->base_type == SELF->vtable->base_type) {
185-            Parrot_Pair_attributes * const from = PARROT_PAIR(SELF);
186-            Parrot_Pair_attributes * const to   = PARROT_PAIR(SELF);
187-
188-            to->key   = from->key;
189-            to->value = from->value;
190-        }
191-        else
192-            Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
193-                "Can only set a pair to another pair.");
194-    }
195-
196-/*
197-
198-=item C<INTVAL is_equal(PMC *value)>
199-
200-The C<==> operation.
201-
202-Check if two Pairs hold the same keys and values.
203-
204-=cut
205-
206-*/
207-
208-    VTABLE INTVAL is_equal(PMC *value) {
209-        Parrot_Pair_attributes * const from = PARROT_PAIR(SELF);
210-        Parrot_Pair_attributes * const to   = PARROT_PAIR(SELF);
211-        PMC *p1, *p2;
212-        PMC *k1, *k2;
213-        INTVAL result;
214-
215-        if (value->vtable->base_type != SELF->vtable->base_type)
216-            return 0;
217-
218-        k1 = from->key;
219-        k2 = to->key;
220-
221-        Parrot_mmd_multi_dispatch_from_c_args(INTERP, "is_equal",
222-            "PP->I", k1, k2, &result);
223-        if (!result)
224-            return 0;
225-
226-        p1 = from->value;
227-        p2 = to->value;
228-
229-        if (!p1 && !p2)
230-            return 1;
231-        else
232-            return 0;
233-    }
234-
235-/*
236-
237-=item C<void visit(visit_info *info)>
238-
239-Used during archiving to visit the elements in the pair.
240-
241-=item C<void freeze(visit_info *info)>
242-
243-Used to archive the Pair.
244-
245-=item C<void thaw(visit_info *info)>
246-
247-Used to unarchive the Pair.
248-
249-=cut
250-
251-*/
252-
253-    VTABLE void visit(visit_info *info) {
254-        PMC               **pos;
255-        Parrot_Pair_attributes * const pair     = PARROT_PAIR(SELF);
256-        IMAGE_IO    * const io       = info->image_io;
257-        DPOINTER   ** const temp_pos = (DPOINTER **)pair->key;
258-        info->thaw_ptr               = (PMC **)temp_pos;
259-        (info->visit_pmc_now)(INTERP, (PMC *)temp_pos, info);
260-
261-        pos            = &pair->value;
262-        info->thaw_ptr = pos;
263-
264-        (info->visit_pmc_now)(INTERP, *pos, info);
265-
266-        SUPER(info);
267-    }
268-
269-    VTABLE void freeze(visit_info *info) {
270-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
271-        IMAGE_IO    * const io   = info->image_io;
272-        SUPER(info);
273-        VTABLE_push_pmc(INTERP, io, pair->key);
274-        VTABLE_push_pmc(INTERP, io, pair->value);
275-    }
276-
277-    VTABLE void thaw(visit_info *info) {
278-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
279-        IMAGE_IO    * const io   = info->image_io;
280-
281-        SUPER(info);
282-
283-        pair->key   = VTABLE_shift_pmc(interp, io);
284-        pair->value = VTABLE_shift_pmc(interp, io);
285-    }
286-/*
287-
288-=back
289-
290-=head2 Methods
291-
292-=over 4
293-
294-=item C<METHOD key()>
295-
296-Return the key of the pair.
297-
298-=cut
299-
300-*/
301-
302-    METHOD key() {
303-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
304-        PMC                *key  = pair->key;
305-
306-        RETURN(PMC *key);
307-    }
308-
309-/*
310-
311-=item C<METHOD value()>
312-
313-Return the value of the pair.
314-
315-=cut
316-
317-*/
318-
319-    METHOD value() {
320-        Parrot_Pair_attributes * const pair  = PARROT_PAIR(SELF);
321-        PMC         * const value = pair->value;
322-        RETURN(PMC *value);
323-    }
324-
325-/*
326-
327-=item C<METHOD kv()>
328-
329-Return a tuple of (key, value) for the pair.
330-
331-=cut
332-
333-*/
334-
335-    METHOD kv() {
336-        Parrot_Pair_attributes * const pair = PARROT_PAIR(SELF);
337-        PMC         * const t    = pmc_new(INTERP,
338-            Parrot_get_ctx_HLL_type(INTERP, enum_class_FixedPMCArray));
339-
340-        VTABLE_set_integer_native(INTERP, t, 2);
341-        VTABLE_set_pmc_keyed_int(INTERP, t, 0, pair->key);
342-
343-        VTABLE_set_pmc_keyed_int(INTERP, t, 1, pair->value);
344-        RETURN(PMC *t);
345-    }
346-}
347-
348-/*
349-
350-=back
351-
352-=cut
353-
354-*/
355-
356-/*
357- * Local variables:
358- *   c-file-style: "parrot"
359- * End:
360- * vim: expandtab shiftwidth=4:
361- */
362Index: MANIFEST
363===================================================================
364--- MANIFEST    (revision 37815)
365+++ MANIFEST    (working copy)
366@@ -1,7 +1,7 @@
367 # ex: set ro:
368 # $Id$
369 #
370-# generated by tools/dev/mk_manifest_and_skip.pl Sat Mar 28 14:40:23 2009 UT
371+# generated by tools/dev/mk_manifest_and_skip.pl Mon Mar 30 01:40:17 2009 UT
372 #
373 # See tools/dev/install_files.pl for documentation on the
374 # format of this file.
375@@ -1240,7 +1240,6 @@
376 src/dynpmc/foo.pmc                                          [devel]src
377 src/dynpmc/gdbmhash.pmc                                     [devel]src
378 src/dynpmc/main.pasm                                        []
379-src/dynpmc/pair.pmc                                         [devel]src
380 src/dynpmc/rational.pmc                                     [devel]src
381 src/dynpmc/rotest.pmc                                       [devel]src
382 src/dynpmc/subproxy.pmc                                     [devel]src
383@@ -1667,7 +1666,6 @@
384 t/dynpmc/dynlexpad.t                                        [test]
385 t/dynpmc/foo.t                                              [test]
386 t/dynpmc/gdbmhash.t                                         [test]
387-t/dynpmc/pair.t                                             [test]
388 t/dynpmc/rational.t                                         [test]
389 t/dynpmc/rotest.t                                           [test]
390 t/dynpmc/subclass_with_pir_method.t                         [test]
391Index: t/dynpmc/pair.t
392===================================================================
393--- t/dynpmc/pair.t     (revision 37815)
394+++ t/dynpmc/pair.t     (working copy)
395@@ -1,85 +0,0 @@
396-#! parrot
397-# Copyright (C) 2001-2009, Parrot Foundation.
398-# $Id$
399-
400-.const int NUM_OF_TESTS = 8
401-
402-.sub main :main
403-    loadlib $P1, 'pair'
404-    load_bytecode 'library/Test/More.pir'
405-
406-    .local pmc plan, is, ok
407-    plan = get_hll_global [ 'Test'; 'More' ], 'plan'
408-    is   = get_hll_global [ 'Test'; 'More' ], 'is'
409-    ok   = get_hll_global [ 'Test'; 'More' ], 'ok'
410-
411-    # set a test plan
412-    plan(NUM_OF_TESTS)
413-
414-    new $P0, ['Pair']
415-    ok(1, "still alive")
416-    new $P1, ['Integer']
417-    set $P1, 42
418-    set $P0["key"], $P1
419-    ok(1, "still alive")
420-    set $P2, $P0["key"]
421-    is($P2, 42, "fetching value")
422-
423-    .local pmc p, kv
424-    new p, ['Pair']
425-    new $P1, ['Integer']
426-    set $P1, 42
427-    set p["key"], $P1
428-
429-    $P0 = p."key"()
430-    is( $P0, 'key', 'get key' )
431-    $P0 = p."value"()
432-    is( $P0, 42, 'get key' )
433-    kv = p."kv"()
434-    $I0 = elements kv
435-    is( $I0, 2, 'number of elements returned from "kv"' )
436-    $P0 = kv[0]
437-    is( $P0, 'key', 'first element returned from "kv"' )
438-    $P0 = kv[1]
439-    is( $P0, 42, 'third element returned from "kv"' )
440-.end
441-
442-=for get it
443-
444-SKIP: {
445-    skip( "instantiate disabled", 1 );
446-    pir_output_is( <<'CODE', <<'OUT', 'instantiate, assign' );
447-.sub main :main
448-    .local pmc cl, p, kv, k, v
449-    k = new ['String']
450-    k = "key"
451-    v = new ['String']
452-    v = "value"
453-    cl = get_class "Pair"
454-    p = cl."instantiate"(k, v)
455-
456-    $P0 = p."key"()
457-    print $P0
458-    print ' '
459-    $P0 = p."value"()
460-    print $P0
461-    print ' '
462-
463-    v = new ['Integer']
464-    v = 77
465-    assign p, v
466-    $P0 = p."value"()
467-    say $P0
468-.end
469-CODE
470-key value 77
471-OUT
472-}
473-
474-=cut
475-
476-# Local Variables:
477-#   mode: pir
478-#   fill-column: 100
479-# End:
480-# vim: expandtab shiftwidth=4 ft=pir:
481Index: config/gen/makefiles/dynpmc.in
482===================================================================
483--- config/gen/makefiles/dynpmc.in      (revision 37815)
484+++ config/gen/makefiles/dynpmc.in      (working copy)
485@@ -34,7 +34,6 @@
486 PMC_TARGETS := \
487   dynlexpad$(LOAD_EXT) \
488   foo$(LOAD_EXT) \
489-  pair$(LOAD_EXT) \
490   rotest$(LOAD_EXT) \
491 #IF(has_gdbm):  gdbmhash$(LOAD_EXT) \
492   rational$(LOAD_EXT) \
493@@ -122,18 +121,6 @@
494 foo.dump: foo.pmc
495        $(PMC2CD) foo.pmc
496 
497-pair$(LOAD_EXT): pair$(O)
498-       $(LD) $(LD_OUT)pair$(LOAD_EXT) pair$(O) $(LINKARGS)
499-
500-pair$(O): pair.c
501-       $(CC) $(CC_OUT)pair$(O) $(INCLUDES) $(CFLAGS) pair.c
502-
503-pair.c: pair.dump
504-       $(PMC2CC) pair.pmc
505-
506-pair.dump: pair.pmc
507-       $(PMC2CD) pair.pmc
508-
509 rotest$(LOAD_EXT): rotest$(O)
510        $(LD) $(LD_OUT)rotest$(LOAD_EXT) rotest$(O) $(LINKARGS)
511