Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Stub VMArray/VMHash/VMIter reprs.
Not going to fill them out just yet, but they should at least exist to
facilitate cross-compilations involving them.
  • Loading branch information
jnthn committed Feb 24, 2013
1 parent f70f431 commit 6d196e4
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/6model/repr_registry.c
Expand Up @@ -236,6 +236,12 @@ void REPR_initialize_registry(PARROT_INTERP) {
Uninstantiable_initialize(interp));
register_repr(interp, Parrot_str_new_constant(interp, "NFA"),
NFA_initialize(interp));
register_repr(interp, Parrot_str_new_constant(interp, "VMArray"),
VMArray_initialize(interp));
register_repr(interp, Parrot_str_new_constant(interp, "VMHash"),
VMHash_initialize(interp));
register_repr(interp, Parrot_str_new_constant(interp, "VMIter"),
VMIter_initialize(interp));

/* Set up object for dynamically registering extra representations. */
dyn_reg_func = Parrot_pmc_new(interp, enum_class_Pointer);
Expand Down
84 changes: 84 additions & 0 deletions src/6model/reprs/VMArray.c
@@ -0,0 +1,84 @@
#define PARROT_IN_EXTENSION
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "../sixmodelobject.h"
#include "VMArray.h"

/* This representation's function pointer table. */
static REPROps *this_repr;

/* Creates a new type object of this representation, and associates it with
* the given HOW. */
static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
/* Create new object instance. */
VMArrayInstance *obj = mem_allocate_zeroed_typed(VMArrayInstance);

/* Build an STable. */
PMC *st_pmc = create_stable(interp, this_repr, HOW);
STable *st = STABLE_STRUCT(st_pmc);

/* Create type object and point it back at the STable. */
obj->common.stable = st_pmc;
st->WHAT = wrap_object(interp, obj);
PARROT_GC_WRITE_BARRIER(interp, st_pmc);

/* Flag it as a type object. */
MARK_AS_TYPE_OBJECT(st->WHAT);

return st->WHAT;
}

/* Composes the representation. */
static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
/* Nothing to do yet, but should handle type in the future. */
}

/* Creates a new instance based on the type object. */
static PMC * allocate(PARROT_INTERP, STable *st) {
VMArrayInstance *obj = mem_allocate_zeroed_typed(VMArrayInstance);
obj->common.stable = st->stable_pmc;
return wrap_object(interp, obj);
}

/* Initialize a new instance. */
static void initialize(PARROT_INTERP, STable *st, void *data) {
/* Nothing to do here. */
}

/* Copies to the body of one object to another. */
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
VMArrayBody *src_body = (VMArrayBody *)src;
VMArrayBody *dest_body = (VMArrayBody *)dest;
/* Nothing to do yet. */
}

/* This Parrot-specific addition to the API is used to free an object. */
static void gc_free(PARROT_INTERP, PMC *obj) {
mem_sys_free(PMC_data(obj));
PMC_data(obj) = NULL;
}

/* Gets the storage specification for this representation. */
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
storage_spec spec;
spec.inlineable = STORAGE_SPEC_REFERENCE;
spec.boxed_primitive = STORAGE_SPEC_BP_NONE;
spec.can_box = 0;
spec.bits = sizeof(void *) * 8;
spec.align = ALIGNOF1(void *);
return spec;
}

/* Initializes the VMArray representation. */
REPROps * VMArray_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
this_repr = mem_allocate_zeroed_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->compose = compose;
this_repr->allocate = allocate;
this_repr->initialize = initialize;
this_repr->copy_to = copy_to;
this_repr->gc_free = gc_free;
this_repr->get_storage_spec = get_storage_spec;
return this_repr;
}
21 changes: 21 additions & 0 deletions src/6model/reprs/VMArray.h
@@ -0,0 +1,21 @@
#ifndef VMARRAY_H_GUARD
#define VMARRAY_H_GUARD

/* Body of a VMArray. */
typedef struct {
INTVAL elems;
INTVAL start;
INTVAL ssize;
PMC **slots;
} VMArrayBody;

/* This is how an instance with the VMArray representation looks. */
typedef struct {
SixModelObjectCommonalities common;
VMArrayBody body;
} VMArrayInstance;

/* Initializes the VMArray REPR. */
REPROps * VMArray_initialize(PARROT_INTERP);

#endif
84 changes: 84 additions & 0 deletions src/6model/reprs/VMHash.c
@@ -0,0 +1,84 @@
#define PARROT_IN_EXTENSION
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "../sixmodelobject.h"
#include "VMHash.h"

/* This representation's function pointer table. */
static REPROps *this_repr;

/* Creates a new type object of this representation, and associates it with
* the given HOW. */
static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
/* Create new object instance. */
VMHashInstance *obj = mem_allocate_zeroed_typed(VMHashInstance);

/* Build an STable. */
PMC *st_pmc = create_stable(interp, this_repr, HOW);
STable *st = STABLE_STRUCT(st_pmc);

/* Create type object and point it back at the STable. */
obj->common.stable = st_pmc;
st->WHAT = wrap_object(interp, obj);
PARROT_GC_WRITE_BARRIER(interp, st_pmc);

/* Flag it as a type object. */
MARK_AS_TYPE_OBJECT(st->WHAT);

return st->WHAT;
}

/* Composes the representation. */
static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
/* Nothing to do yet, but should handle type in the future. */
}

/* Creates a new instance based on the type object. */
static PMC * allocate(PARROT_INTERP, STable *st) {
VMHashInstance *obj = mem_allocate_zeroed_typed(VMHashInstance);
obj->common.stable = st->stable_pmc;
return wrap_object(interp, obj);
}

/* Initialize a new instance. */
static void initialize(PARROT_INTERP, STable *st, void *data) {
/* Nothing to do here. */
}

/* Copies to the body of one object to another. */
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
VMHashBody *src_body = (VMHashBody *)src;
VMHashBody *dest_body = (VMHashBody *)dest;
/* Nothing to do yet. */
}

/* This Parrot-specific addition to the API is used to free an object. */
static void gc_free(PARROT_INTERP, PMC *obj) {
mem_sys_free(PMC_data(obj));
PMC_data(obj) = NULL;
}

/* Gets the storage specification for this representation. */
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
storage_spec spec;
spec.inlineable = STORAGE_SPEC_REFERENCE;
spec.boxed_primitive = STORAGE_SPEC_BP_NONE;
spec.can_box = 0;
spec.bits = sizeof(void *) * 8;
spec.align = ALIGNOF1(void *);
return spec;
}

/* Initializes the VMHash representation. */
REPROps * VMHash_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
this_repr = mem_allocate_zeroed_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->compose = compose;
this_repr->allocate = allocate;
this_repr->initialize = initialize;
this_repr->copy_to = copy_to;
this_repr->gc_free = gc_free;
this_repr->get_storage_spec = get_storage_spec;
return this_repr;
}
18 changes: 18 additions & 0 deletions src/6model/reprs/VMHash.h
@@ -0,0 +1,18 @@
#ifndef VMHASH_H_GUARD
#define VMHASH_H_GUARD

/* Body of a VMHash. */
typedef struct {
INTVAL dummy; /* Todo... */
} VMHashBody;

/* This is how an instance with the VMHash representation looks. */
typedef struct {
SixModelObjectCommonalities common;
VMHashBody body;
} VMHashInstance;

/* Initializes the VMHash REPR. */
REPROps * VMHash_initialize(PARROT_INTERP);

#endif
84 changes: 84 additions & 0 deletions src/6model/reprs/VMIter.c
@@ -0,0 +1,84 @@
#define PARROT_IN_EXTENSION
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "../sixmodelobject.h"
#include "VMIter.h"

/* This representation's function pointer table. */
static REPROps *this_repr;

/* Creates a new type object of this representation, and associates it with
* the given HOW. */
static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
/* Create new object instance. */
VMIterInstance *obj = mem_allocate_zeroed_typed(VMIterInstance);

/* Build an STable. */
PMC *st_pmc = create_stable(interp, this_repr, HOW);
STable *st = STABLE_STRUCT(st_pmc);

/* Create type object and point it back at the STable. */
obj->common.stable = st_pmc;
st->WHAT = wrap_object(interp, obj);
PARROT_GC_WRITE_BARRIER(interp, st_pmc);

/* Flag it as a type object. */
MARK_AS_TYPE_OBJECT(st->WHAT);

return st->WHAT;
}

/* Composes the representation. */
static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
/* Nothing to do yet, but should handle type in the future. */
}

/* Creates a new instance based on the type object. */
static PMC * allocate(PARROT_INTERP, STable *st) {
VMIterInstance *obj = mem_allocate_zeroed_typed(VMIterInstance);
obj->common.stable = st->stable_pmc;
return wrap_object(interp, obj);
}

/* Initialize a new instance. */
static void initialize(PARROT_INTERP, STable *st, void *data) {
/* Nothing to do here. */
}

/* Copies to the body of one object to another. */
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
VMIterBody *src_body = (VMIterBody *)src;
VMIterBody *dest_body = (VMIterBody *)dest;
/* Nothing to do yet. */
}

/* This Parrot-specific addition to the API is used to free an object. */
static void gc_free(PARROT_INTERP, PMC *obj) {
mem_sys_free(PMC_data(obj));
PMC_data(obj) = NULL;
}

/* Gets the storage specification for this representation. */
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
storage_spec spec;
spec.inlineable = STORAGE_SPEC_REFERENCE;
spec.boxed_primitive = STORAGE_SPEC_BP_NONE;
spec.can_box = 0;
spec.bits = sizeof(void *) * 8;
spec.align = ALIGNOF1(void *);
return spec;
}

/* Initializes the VMIter representation. */
REPROps * VMIter_initialize(PARROT_INTERP) {
/* Allocate and populate the representation function table. */
this_repr = mem_allocate_zeroed_typed(REPROps);
this_repr->type_object_for = type_object_for;
this_repr->compose = compose;
this_repr->allocate = allocate;
this_repr->initialize = initialize;
this_repr->copy_to = copy_to;
this_repr->gc_free = gc_free;
this_repr->get_storage_spec = get_storage_spec;
return this_repr;
}
18 changes: 18 additions & 0 deletions src/6model/reprs/VMIter.h
@@ -0,0 +1,18 @@
#ifndef VMITER_H_GUARD
#define VMITER_H_GUARD

/* Body of a VMIter. */
typedef struct {
INTVAL dummy; /* Todo... */
} VMIterBody;

/* This is how an instance with the VMIter representation looks. */
typedef struct {
SixModelObjectCommonalities common;
VMIterBody body;
} VMIterInstance;

/* Initializes the VMIter REPR. */
REPROps * VMIter_initialize(PARROT_INTERP);

#endif
2 changes: 1 addition & 1 deletion src/pmc/sixmodelobject.pmc
Expand Up @@ -30,7 +30,7 @@
* but this will do for now. */
#include "../../3rdparty/libtommath/tommath.h"
#include "../6model/reprs/P6bigint.h"
#define bigint_repr_id 8
#define bigint_repr_id 11

PMC * decontainerize(PARROT_INTERP, PMC *var) {
ContainerSpec *spec = STABLE(var)->container_spec;
Expand Down
11 changes: 9 additions & 2 deletions tools/build/Makefile.in
Expand Up @@ -217,6 +217,9 @@ METAMODEL_SOURCE = src/6model/sixmodelobject.h src/6model/sixmodelobject.c \
src/6model/reprs/HashAttrStore.h src/6model/reprs/HashAttrStore.c \
src/6model/reprs/Uninstantiable.h src/6model/reprs/Uninstantiable.c \
src/6model/reprs/NFA.h src/6model/reprs/NFA.c \
src/6model/reprs/VMArray.h src/6model/reprs/VMArray.c \
src/6model/reprs/VMHash.h src/6model/reprs/VMHash.c \
src/6model/reprs/VMIter.h src/6model/reprs/VMIter.c \
src/6model/storage_spec.h src/6model/serialization_context.c \
src/6model/serialization_context.h src/6model/serialization.c \
src/6model/serialization.h src/guts/multi_dispatch.h \
Expand All @@ -227,9 +230,10 @@ METAMODEL_OBJS = ../6model/sixmodelobject$(O) ../6model/repr_registry$(O) \
../6model/reprs/P6opaque$(O) ../6model/reprs/P6int$(O) \
../6model/reprs/P6str$(O) ../6model/reprs/P6num$(O) \
../6model/reprs/HashAttrStore$(O) ../6model/reprs/Uninstantiable$(O) \
../6model/reprs/NFA$(O) ../6model/serialization_context$(O) \
../6model/reprs/NFA$(O) ../6model/reprs/VMArray$(O) \
../6model/reprs/VMHash$(O) ../6model/reprs/VMIter$(O) \
../6model/serialization_context$(O) ../6model/base64$(O) \
../6model/serialization$(O) ../guts/multi_dispatch$(O) \
../6model/base64$(O)

LIBTOMMATH_BIN = $(TOM)core$(O) \
$(TOM)_error$(O) \
Expand Down Expand Up @@ -786,6 +790,9 @@ $(OPS_DIR)/$(OPS)$(LOAD_EXT): $(OPS_DIR)/$(OPS_SOURCE) $(DYNPMC)
cd src/6model/reprs && $(CC) -c @cc_o_out@HashAttrStore$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) HashAttrStore.c
cd src/6model/reprs && $(CC) -c @cc_o_out@Uninstantiable$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) Uninstantiable.c
cd src/6model/reprs && $(CC) -c @cc_o_out@NFA$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) NFA.c
cd src/6model/reprs && $(CC) -c @cc_o_out@VMArray$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) VMArray.c
cd src/6model/reprs && $(CC) -c @cc_o_out@VMHash$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) VMHash.c
cd src/6model/reprs && $(CC) -c @cc_o_out@VMIter$(O) -I../../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) VMIter.c
cd src/6model && $(CC) -c @cc_o_out@serialization_context$(O) -I../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) serialization_context.c
cd src/6model && $(CC) -c @cc_o_out@serialization$(O) -I../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) serialization.c
cd src/6model && $(CC) -c @cc_o_out@base64$(O) -I../../$(PMC_DIR) $(CINCLUDES) $(CFLAGS) base64.c
Expand Down

0 comments on commit 6d196e4

Please sign in to comment.