1/* 2Copyright (C) 2001-2014, Parrot Foundation. 3 4=head1 NAME 5 6src/pmc/null.pmc - Null PMC 7 8=head1 DESCRIPTION 9 10This singleton simply creates a way of catching C<NULL> register accesses without 11really slowing down the bytecode execution. 12 13=cut 14 15*/ 16 17/* HEADERIZER HFILE: none */ 18/* HEADERIZER BEGIN: static */ 19/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 20 21PARROT_DOES_NOT_RETURN 22static void null_pmc_access(PARROT_INTERP, int index) 23 __attribute__nonnull__(1); 24 25#define ASSERT_ARGS_null_pmc_access __attribute__unused__ int _ASSERT_ARGS_CHECK = (\ 26 PARROT_ASSERT_ARG(interp)) 27/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 28/* HEADERIZER END: static */ 29 30pmclass Null singleton { 31 32/* 33 34=head2 Vtable functions 35 36=over 4 37 38=item C<void init()> 39 40Overrides the default to do nothing. 41 42=cut 43 44*/ 45 46 VTABLE void init() :no_wb { 47 UNUSED(INTERP) 48 UNUSED(SELF) 49 } 50 51 VTABLE void *get_pointer() :no_wb { 52 UNUSED(INTERP) 53 UNUSED(SELF) 54 return PMCNULL; 55 } 56 57 VTABLE void set_pointer(void *p) :no_wb { 58 UNUSED(INTERP) 59 UNUSED(SELF) 60 PMCNULL = (PMC *)p; 61 } 62 63 VTABLE INTVAL does(STRING *what) :no_wb { 64 UNUSED(INTERP) 65 UNUSED(SELF) 66 UNUSED(what) 67 /* XXX maybe a hack to get TGE running again */ 68 return 0; 69 } 70 71/* 72 73=item C<INTVAL is_same(PMC *value)> 74 75Returns true if value is also a null PMC, false otherwise. 76 77=cut 78 79*/ 80 VTABLE INTVAL is_same(PMC *value) :no_wb { 81 UNUSED(INTERP) 82 UNUSED(SELF) 83 return PMC_IS_NULL(value); 84 } 85 86/* 87 88=item C<PMC *find_method(STRING *method_name)> 89 90Gives a more informative message than the automaticaly generated version. 91 92=cut 93 94*/ 95 96 VTABLE PMC *find_method(STRING *method_name) :no_wb { 97 UNUSED(SELF) 98 Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_NULL_REG_ACCESS, 99 "Null PMC access in find_method('%Ss')", 100 method_name); 101 } 102 103} 104 105/* 106 107=back 108 109=head2 Auxiliary functions 110 111=over 4 112 113=item C<static void null_pmc_access(PARROT_INTERP, int index)> 114 115Throws the Null PMC access exception. 116 117=cut 118 119*/ 120 121PARROT_DOES_NOT_RETURN 122static void 123null_pmc_access(PARROT_INTERP, int index) 124{ 125 ASSERT_ARGS(null_pmc_access) 126 Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_NULL_REG_ACCESS, 127 "Null PMC access in %s()", 128 Parrot_get_vtable_name(interp, index)); 129} 130 131/* 132 133=back 134 135=cut 136 137*/ 138 139/* 140 * Local variables: 141 * c-file-style: "parrot" 142 * End: 143 * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : 144 */ 145