~ubuntu-branches/ubuntu/vivid/nqp/vivid-proposed

« back to all changes in this revision

Viewing changes to src/vm/parrot/6model/reprs/Uninstantiable.c

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2013-11-01 12:09:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20131101120918-kx51sl0sxl3exsxi
Tags: 2013.10-1
* New upstream release
* Bump versioned (Build-)Depends on parrot
* Update patches
* Install new README.pod
* Fix vcs-field-not-canonical
* Do not install rubyish examples
* Do not Depends on parrot-devel anymore
* Add 07_disable-serialization-tests.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Dead easy REPR that refuses to ever be instantiated. For the
 
2
 * things you can't instantiate. */
 
3
 
 
4
#define PARROT_IN_EXTENSION
 
5
#include "parrot/parrot.h"
 
6
#include "parrot/extend.h"
 
7
#include "../sixmodelobject.h"
 
8
#include "Uninstantiable.h"
 
9
 
 
10
/* This representation's function pointer table. */
 
11
static REPROps *this_repr;
 
12
 
 
13
/* Creates a new type object of this representation, and associates it with
 
14
 * the given HOW. */
 
15
static PMC * type_object_for(PARROT_INTERP, PMC *HOW) {
 
16
    /* Create new type object instance. */
 
17
    UninstantiableInstance *obj = mem_allocate_zeroed_typed(UninstantiableInstance);
 
18
 
 
19
    /* Build an STable. */
 
20
    PMC *st_pmc = create_stable(interp, this_repr, HOW);
 
21
    STable *st  = STABLE_STRUCT(st_pmc);
 
22
 
 
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);
 
27
 
 
28
    /* Flag it as a type object. */
 
29
    MARK_AS_TYPE_OBJECT(st->WHAT);
 
30
 
 
31
    return st->WHAT;
 
32
}
 
33
 
 
34
/* Composes the representation. */
 
35
static void compose(PARROT_INTERP, STable *st, PMC *repr_info) {
 
36
    /* Nothing to do. */
 
37
}
 
38
 
 
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");
 
43
}
 
44
 
 
45
/* Initialize a new instance. */
 
46
static void initialize(PARROT_INTERP, STable *st, void *data) {
 
47
    /* Nothing to do. */
 
48
}
 
49
 
 
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. */
 
53
}
 
54
 
 
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));
 
58
    PMC_data(obj) = NULL;
 
59
}
 
60
 
 
61
/* Gets the storage specification for this representation. */
 
62
static storage_spec get_storage_spec(PARROT_INTERP, STable *st) {
 
63
    storage_spec spec;
 
64
    spec.inlineable = STORAGE_SPEC_REFERENCE;
 
65
    spec.boxed_primitive = STORAGE_SPEC_BP_NONE;
 
66
    spec.can_box = 0;
 
67
    spec.bits = sizeof(void *);
 
68
    spec.align = ALIGNOF1(void *);
 
69
    return spec;
 
70
}
 
71
 
 
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;
 
83
    return this_repr;
 
84
}