Skip to content

Commit

Permalink
6model: headerize, podify and CONST_STRING repr_registry
Browse files Browse the repository at this point in the history
rename intern_initialize_6model to sixmodel_initialize
  • Loading branch information
Reini Urban committed Mar 19, 2014
1 parent 558e7ef commit bfc0be5
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 39 deletions.
126 changes: 97 additions & 29 deletions src/6model/repr_registry.c
@@ -1,10 +1,24 @@
/*
Copyright (C) 2011, Parrot Foundation.
*/
* Copyright (C) 2010-2011, The Perl Foundation.
* Copyright (C) 2014, Parrot Foundation.
=head1 NAME
src/6model/repr_registry.c - representation registry
=head1 DESCRIPTION
This is an implementation of a representation registry. It keeps track of
all of the available representations, and is responsible for building them
at startup.
=head2 Internal Functions
/* This is an implementation of a representation registry. It keeps track of
* all of the available representations, and is responsible for building them
* at startup. */
=over 4
=cut
*/

#include "parrot/parrot.h"
#include "repr_registry.str"
Expand Down Expand Up @@ -39,8 +53,17 @@ static INTVAL num_reprs = 0;
/* Hash mapping representation names to IDs. */
static PMC *repr_name_to_id_map = NULL;

/* Registers a representation. It this is ever made public, it should first be
* made thread-safe. */
/*
=item C<static void register_repr(PARROT_INTERP, STRING *name, REPROps *repr)>
Register a sixmodel representation.
TODO: make it public, make it thread-safe.
=cut
*/
static void
register_repr(PARROT_INTERP, STRING *name, REPROps *repr)
{
Expand All @@ -55,50 +78,95 @@ register_repr(PARROT_INTERP, STRING *name, REPROps *repr)
VTABLE_set_integer_keyed_str(interp, repr_name_to_id_map, name, ID);
}

/* Initializes the representations registry, building up all of the various
* representations. */
/*
=back
=head2 Functions
=over 4
=item C<void REPR_initialize_registry(PARROT_INTERP)>
Initializes the representations registry, building up all of the P6
various representations.
TODO: Allow other user-repr.
=cut
*/
void
REPR_initialize_registry(PARROT_INTERP)
{
const STRING * s_KnowHOWREPR = CONST_STRING(interp, "KnowHOWREPR");
const STRING * s_P6opaque = CONST_STRING(interp, "P6opaque");
const STRING * s_P6int = CONST_STRING(interp, "P6int");
const STRING * s_P6num = CONST_STRING(interp, "P6num");
const STRING * s_P6str = CONST_STRING(interp, "P6str");
const STRING * s_HashAttrStore = CONST_STRING(interp, "HashAttrStore");
const STRING * s_Uninstantiable = CONST_STRING(interp, "Uninstantiable");

/* Allocate name to ID map, and anchor it with the GC. */
repr_name_to_id_map = Parrot_pmc_new(interp, enum_class_Hash);
Parrot_pmc_gc_register(interp, repr_name_to_id_map);

/* Add all representations. */
register_repr(interp, CONST_STRING(interp, "KnowHOWREPR"),
KnowHOWREPR_initialize(interp));
register_repr(interp, CONST_STRING(interp, "P6opaque"),
P6opaque_initialize(interp));
register_repr(interp, CONST_STRING(interp, "P6int"),
P6int_initialize(interp));
register_repr(interp, CONST_STRING(interp, "P6num"),
P6num_initialize(interp));
register_repr(interp, CONST_STRING(interp, "P6str"),
P6str_initialize(interp));
register_repr(interp, CONST_STRING(interp, "HashAttrStore"),
HashAttrStore_initialize(interp));
register_repr(interp, CONST_STRING(interp, "Uninstantiable"),
Uninstantiable_initialize(interp));
register_repr(interp, s_KnowHOWREPR, KnowHOWREPR_initialize(interp));
register_repr(interp, s_P6opaque, P6opaque_initialize(interp));
register_repr(interp, s_P6int, P6int_initialize(interp));
register_repr(interp, s_P6num, P6num_initialize(interp));
register_repr(interp, s_P6str, P6str_initialize(interp));
register_repr(interp, s_HashAttrStore, HashAttrStore_initialize(interp));
register_repr(interp, s_Uninstantiable, Uninstantiable_initialize(interp));
}

/* Get a representation's ID from its name. Note that the IDs may change so
* it's best not to store references to them in e.g. the bytecode stream. */
/*
=item C<INTVAL REPR_name_to_id(PARROT_INTERP, STRING *name)>
Get a representation's ID from its name. Note that the IDs may change so
it's best not to store references to them in e.g. the bytecode stream.
=cut
*/
PARROT_WARN_UNUSED_RESULT
INTVAL
REPR_name_to_id(PARROT_INTERP, STRING *name)
{
return VTABLE_get_integer_keyed_str(interp, repr_name_to_id_map, name);
}

/* Gets a representation by ID.
TODO: thread-safe (per interp)
*/
/*
=item C<REPROps * REPR_get_by_id(PARROT_INTERP, INTVAL id)>
Gets a representation by ID.
TODO: thread-safe (per interp)
=cut
*/
PARROT_WARN_UNUSED_RESULT
REPROps *
REPR_get_by_id(SHIM_INTERP, INTVAL id)
{
return repr_registry[id];
}

/* Gets a representation by name. */
/*
=item C<REPROps * REPR_get_by_name(PARROT_INTERP, STRING *name)>
Gets a representation by name.
=cut
*/
PARROT_WARN_UNUSED_RESULT
PARROT_CANNOT_RETURN_NULL
REPROps *
REPR_get_by_name(PARROT_INTERP, STRING *name)
{
Expand Down
20 changes: 10 additions & 10 deletions src/interp/api.c
Expand Up @@ -39,19 +39,19 @@ static Interp* emergency_interp = NULL;
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */

static void intern_initialize_6model(PARROT_INTERP)
__attribute__nonnull__(1);

PARROT_WARN_UNUSED_RESULT
static int Parrot_interp_is_env_var_set(PARROT_INTERP, ARGIN(STRING* var))
__attribute__nonnull__(1)
__attribute__nonnull__(2);

#define ASSERT_ARGS_intern_initialize_6model __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
static void sixmodel_initialize(PARROT_INTERP)
__attribute__nonnull__(1);

#define ASSERT_ARGS_Parrot_interp_is_env_var_set __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(var))
#define ASSERT_ARGS_sixmodel_initialize __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp))
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */

Expand Down Expand Up @@ -366,24 +366,24 @@ Parrot_interp_initialize_interpreter(PARROT_INTERP, ARGIN(Parrot_GC_Init_Args *a
Parrot_x_on_exit(interp, Parrot_interp_really_destroy, NULL);
#endif

intern_initialize_6model(interp);
sixmodel_initialize(interp);
return interp;
}

/*
=item C<static void intern_initialize_6model(PARROT_INTERP)>
=item C<static void sixmodel_initialize(PARROT_INTERP)>
Initialize 6model
Initializes 6model
=cut
*/

static void
intern_initialize_6model(PARROT_INTERP)
sixmodel_initialize(PARROT_INTERP)
{
ASSERT_ARGS(intern_initialize_6model)
ASSERT_ARGS(sixmodel_initialize)
PMC * KnowHOW, * KnowHOWAttribute;
SixModelObject_initialize(interp, &KnowHOW, &KnowHOWAttribute);
VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_KNOWHOW, KnowHOW);
Expand Down

0 comments on commit bfc0be5

Please sign in to comment.