NAME ^

src/pmc/namespace.pmc - NameSpace PMC

DESCRIPTION ^

These are the vtable functions for the namespace PMC.

Data ^

  PMC_struct_val       ... the hash, bucket->value is either a
                           var/sub or a namespace, of a FixedPMCarray
                           of 2 PMCs (namespace, sub/var) slots
  PMC_pmc_val          ... parent namespace
  PMC_data             ... name STRING of this namespace part

Functions ^

void init()

Initialize a NameSpace PMC by calling Hash.init and clearing other fields.

void mark()

Marks the namespace as live.

void set_pmc_keyed_str(STRING *key, PMC *value)

Sets *value as the namespace item for *key. This is part of the raw interface. If the PMC value is exactly a NameSpace, SELF will be set as the parent of that namespace and the name key of value is stored too.

void set_pmc_keyed(PMC *key, PMC *value)

If key is a simple key, it works like above. If key is an array of strings or a chained key, add all components to the namespace.

PMC *get_pmc_keyed(PMC *key)

Return the given namespace or PMCNULL. key is either an array of strings, or a possibly nested key.

PMC *get_pmc_keyed_str(PMC *key)

Return the given namespace item or PMCNULL. If the named item is either a NameSpace or a var, the NameSpace is returned.

void *get_pointer_keyed_str(STRING *key)

void *get_pointer_keyed(PMC *key)

Return the given namespace item or PMCNULL. If the named item is either a NameSpace or a var, the var is returned.

TOTAL KLUDGE. ON THE CHOPPING BLOCK.

STRING *get_string()

Return the name of this namespace part.

Methods ^

METHOD void PMC *add_namespace(STRING *name, PMC *namespace)

Stores the given namespace under this namespace, with the given name. Throws an invalid type exception if namespace is not a NameSpace PMC or subclass.

*/

    METHOD void add_namespace(STRING *name, PMC *namespace) {
        STRING *s_ns = CONST_STRING(INTERP, "NameSpace");
        if (!VTABLE_isa(INTERP, namespace, s_ns))
            real_exception(INTERP, NULL, E_TypeError,
                "Invalid type %d in add_namespace()",
                namespace->vtable->base_type);

        VTABLE_set_pmc_keyed_str(INTERP, SELF, name, namespace);
        return;
    }
/*

/*

METHOD void PMC *add_sub(STRING *name, PMC *sub)

Stores the given sub under this namespace, with the given name. Throws an invalid type exception if sub is not a Sub PMC or subclass.

*/

    METHOD void add_sub(STRING *name, PMC *sub) {
        STRING *s_sub = CONST_STRING(INTERP, "Sub");
        if (!VTABLE_isa(INTERP, sub, s_sub))
            real_exception(INTERP, NULL, E_TypeError,
                "Invalid type %d in add_sub()", sub->vtable->base_type);

        VTABLE_set_pmc_keyed_str(INTERP, SELF, name, sub);
        return;
    }
/*

/*

METHOD void PMC *add_var(STRING *name, PMC *var)

Stores the given sub under this namespace, with the given name.

*/

    METHOD void add_var(STRING *name, PMC *var) {
        VTABLE_set_pmc_keyed_str(INTERP, SELF, name, var);
        return;
    }
/*

METHOD PMC *get_name()

Returns the name of the namespace as an array of strings.

  $P2 = $P3.'get_name'()
  $S0 = join '::', $P2            # '::Foo::Bar'
METHOD PMC *find_namespace(STRING *name)

Return the namespace with the given name.

METHOD PMC *find_sub(STRING *name)

Return the Sub PMC with the given name.

METHOD PMC *find_var(STRING *name)

Return the PMC with the given name.

METHOD PMC *del_namespace(STRING *name)

Deletes the contained NameSpace PMC with the given name. Throws an invalid type exception if the item to delete is not a NameSpace PMC or subclass, and does not delete the PMC.

METHOD PMC *del_sub(STRING *name)

Deletes the contained Sub PMC with the given name. Throws an invalid type exception if the item to delete is not a Sub PMC or subclass, and does not delete the PMC.

METHOD PMC *del_var(STRING *name)

Deletes the contained variable-like PMC with the given name.

METHOD PMC *get_sym(STRING *name)

Return the symbol (var or sub) with the given name. This can be used to retrieve symbols, if a NameSpace with the same name exists.

METHOD void export_to(PMC *dest, PMC *what)

Export items from this NameSpace into the dest NameSpace. what is an array of (string) names to be exported.

METHOD PMC *get_parent()

Return the parent NameSpace or PMCNULL, if none.

SEE ALSO ^

docs/pdds/pdd21_namespaces.pod


parrot