1
/* Dead easy REPR that refuses to ever be instantiated. For the
2
* things you can't instantiate. */
4
#define PARROT_IN_EXTENSION
5
#include "parrot/parrot.h"
6
#include "parrot/extend.h"
7
#include "../sixmodelobject.h"
8
#include "Uninstantiable.h"
10
/* This representation's function pointer table. */
11
static REPROps *this_repr;
13
/* Creates a new type object of this representation, and associates it with
15
static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
16
/* Create new type object instance. */
17
UninstantiableInstance *obj = mem_allocate_zeroed_typed(UninstantiableInstance);
19
/* Build an STable. */
20
PMC *st_pmc = create_stable(interp, this_repr, HOW);
21
STable *st = STABLE_STRUCT(st_pmc);
23
/* Create type object and point it back at the STable. */
24
obj->common.stable = st_pmc;
25
st->WHAT = wrap_object(interp, obj);
26
PARROT_GC_WRITE_BARRIER(interp, st_pmc);
28
/* Flag it as a type object. */
29
MARK_AS_TYPE_OBJECT(st->WHAT);
34
/* Composes the representation. */
35
static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
39
/* Creates a new instance based on the type object. */
40
static PMC * allocate(PARROT_INTERP, STable *st) {
41
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
42
"You cannot create an instance of this type");
45
/* Initialize a new instance. */
46
static void initialize(PARROT_INTERP, STable *st, void *data) {
50
/* Copies to the body of one object to another. */
51
static void copy_to(PARROT_INTERP, STable *st, void *src, void *dest) {
52
/* Nothing to copy. */
55
/* This Parrot-specific addition to the API is used to free an object. */
56
static void gc_free(PARROT_INTERP, PMC *obj) {
57
mem_sys_free(PMC_data(obj));
61
/* Gets the storage specification for this representation. */
62
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
64
spec.inlineable = STORAGE_SPEC_REFERENCE;
65
spec.boxed_primitive = STORAGE_SPEC_BP_NONE;
67
spec.bits = sizeof(void *);
68
spec.align = ALIGNOF1(void *);
72
/* Initializes the Uninstantiable representation. */
73
REPROps * Uninstantiable_initialize(PARROT_INTERP) {
74
/* Allocate and populate the representation function table. */
75
this_repr = mem_allocate_zeroed_typed(REPROps);
76
this_repr->type_object_for = type_object_for;
77
this_repr->compose = compose;
78
this_repr->allocate = allocate;
79
this_repr->initialize = initialize;
80
this_repr->copy_to = copy_to;
81
this_repr->gc_free = gc_free;
82
this_repr->get_storage_spec = get_storage_spec;