fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / dynpmc / subproxy.pmc
blob0b7be30020bff1d449aae02d188ebd49c2085143
1 /*
2  * $Id$
3  * Copyright (C) 2003-2009, Parrot Foundation.
4  */
6 /*
7  * Sample SubProxy class
8  *
9  * s. src/dynpmc/main.pasm for usage
10  */
13  * the real class enum is created at load time
14  */
15 #define enum_class_SubProxy -1
17 pmclass SubProxy dynpmc extends Sub auto_attrs {
19     VTABLE void init() {
20         SUPER();
21         PObj_get_FLAGS(SELF) |= PObj_private0_FLAG;
22     }
24     VTABLE void set_pmc(PMC *key) {
25         PMC_data(SELF) = key;
26     }
28     VTABLE opcode_t* invoke(void* next) {
29         if (PObj_get_FLAGS(SELF) & PObj_private0_FLAG) {
31             PMC         *key = PMC_data_typed(SELF, PMC *);
32             STRING      *file;
33             PMC         *rsub_pmc, *sub_pmc;
34             Parrot_Sub_attributes  *rsub,     *my_sub;
36             if (!key)
37                 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "SubProxy: no key");
39             file = VTABLE_get_string(INTERP, key);
40             if (!file)
41                 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "SubProxy: no file");
43             sub_pmc = key_next(INTERP, key);
44             if (!sub_pmc)
45                 Parrot_ex_throw_from_c_args(INTERP, NULL, 1, "SubProxy: no sub");
47             Parrot_load_bytecode(INTERP, file);
48             rsub_pmc = VTABLE_get_pmc_keyed(INTERP,
49                     INTERP->root_namespace, sub_pmc);
51             if (!VTABLE_defined(INTERP, rsub_pmc))
52                 Parrot_ex_throw_from_c_args(INTERP, NULL, 1,
53                     "SubProxy: sub not found");
55             PObj_get_FLAGS(SELF) &= ~PObj_private0_FLAG;
56             PMC_get_sub(INTERP, SELF,     my_sub);
57             PMC_get_sub(INTERP, rsub_pmc, rsub);
58             my_sub->seg        = rsub->seg;
59             my_sub->start_offs = rsub->start_offs;
60             my_sub->end_offs   = rsub->end_offs;
61         }
62         return SUPER(next);
63     }
68  * Local variables:
69  *   c-file-style: "parrot"
70  * End:
71  * vim: expandtab shiftwidth=4:
72  */