From 181544bf604637899b3f866ca69cde43c7bc069c Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Wed, 9 Feb 2011 22:26:42 -0500 Subject: [PATCH 01/27] add PMC_HEADER_PREAMBLE section to PMC grammar This allows declarations to be inserted before all PMC supporting definitions, allowing changes in behaviour. An example of where this might be desirable is user-defined typedefs in attributes. --- lib/Parrot/Pmc2c/PMC.pm | 9 +++++++++ lib/Parrot/Pmc2c/Parser.pm | 30 ++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/Parrot/Pmc2c/PMC.pm b/lib/Parrot/Pmc2c/PMC.pm index bed5d828ae..69a01f8609 100644 --- a/lib/Parrot/Pmc2c/PMC.pm +++ b/lib/Parrot/Pmc2c/PMC.pm @@ -300,6 +300,12 @@ sub preamble { return $self->{preamble}; } +sub hdr_preamble { + my ( $self, $value ) = @_; + $self->{hdr_preamble} = $value if $value; + return $self->{hdr_preamble}; +} + sub postamble { my ( $self, $value ) = @_; $self->{postamble} = $value if $value; @@ -555,6 +561,9 @@ EOH $h->emit("#define PARROT_IN_EXTENSION\n") if ( $self->is_dynamic ); + # Emit header preamble + $h->emit($self->hdr_preamble) if $self->hdr_preamble; + # Emit available functions for work with vtables. my $export = 'PARROT_EXPORT '; if ($self->is_dynamic) { diff --git a/lib/Parrot/Pmc2c/Parser.pm b/lib/Parrot/Pmc2c/Parser.pm index e34f51738a..8d42a5549e 100644 --- a/lib/Parrot/Pmc2c/Parser.pm +++ b/lib/Parrot/Pmc2c/Parser.pm @@ -64,7 +64,7 @@ sub parse_pmc { $filename = $pmc2cMain->find_file( filename( $filename, '.pmc' ), 1 ); my $code = slurp($filename); - my ( $preamble, $pmcname, $flags, $parents, $pmcbody, $post, $chewed_lines ) = + my ( $preamble, $hdr_preamble, $pmcname, $flags, $parents, $pmcbody, $post, $chewed_lines ) = parse_top_level($code); my $filebase = basename($filename); @@ -73,6 +73,7 @@ sub parse_pmc { unless lc($filebase) eq lc($pmcname); my $pmc = Parrot::Pmc2c::PMC->create($pmcname); $pmc->preamble( Parrot::Pmc2c::Emitter->text( $preamble, $filename, 1 ) ); + $pmc->hdr_preamble($hdr_preamble); $pmc->name($pmcname); $pmc->set_filename($filename); $pmc->set_flags($flags); @@ -320,14 +321,14 @@ sub strip_outer_brackets { =head2 C - my ($preamble, $pmcname, $flags, $parents, $pmcbody, $post, $chewed_lines) + my ($preamble, $hdr_preamble, $pmcname, $flags, $parents, $pmcbody, $post, $chewed_lines) = parse_top_level(\$code); B Extract a pmc signature from the code ref. B PMC file contents slurped by C. -B List of seven elements: +B List of eight elements: =over 4 @@ -337,6 +338,10 @@ the code found before the pmc signature; =item * +the code declared to be the header preamble. will be included at the start of the header. + +=item * + the name of the pmc =item * @@ -372,7 +377,15 @@ sub parse_top_level { my $top_level_re = qr{ ^ # beginning of line - (.*?) # preamble + (?: + (.*?) # preamble 1 + ^ BEGIN_PMC_HEADER_PREAMBLE \s* + ^ (.*?) # header preamble + ^ END_PMC_HEADER_PREAMBLE \s* + ^ (.*?) # preamble 2 + | (.*?) # preamble 3 + ) + ^ ( \s* @@ -385,7 +398,11 @@ sub parse_top_level { \{ # pmc body beginning marker }smx; $code =~ s[$top_level_re][{]smx or die "No pmclass found\n"; - my ( $preamble, $pmc_signature, $pmcname, $attributes ) = ( $1, $2, $3, $4 ); + my ( $hdr_preamble, $pmc_signature, $pmcname, $attributes ) = ( $2, $5, $6, $7 ); + my $preamble = do { + no warnings 'uninitialized'; + $1 . $3 . $4; + }; my $chewed_lines = count_newlines($pmc_signature); my ( $flags, $parents ) = parse_flags( $attributes, $pmcname ); @@ -394,7 +411,8 @@ sub parse_top_level { # trim out the { } $body = strip_outer_brackets($body); - return ( $preamble, $pmcname, $flags, $parents, $body, $postamble, $chewed_lines ); + return ( $preamble, $hdr_preamble, $pmcname, $flags, $parents, + $body, $postamble, $chewed_lines ); } our %has_value = map { $_ => 1 } qw(does group hll); From 48506be984f5772d6a930cce06191f5a897bedc6 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Wed, 9 Feb 2011 22:26:00 -0500 Subject: [PATCH 02/27] implement 3 levels of pointer-type objects Ptr - baseline pointerish function. big nastygram in description to fight feature creep. PtrBuf - can also keeps track of size PtrObj - can also clone and manage memory --- src/pmc/ptr.pmc | 161 +++++++++++++++++++++++++++++++++++++++ src/pmc/ptrbuf.pmc | 74 ++++++++++++++++++ src/pmc/ptrobj.pmc | 182 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 417 insertions(+) create mode 100644 src/pmc/ptr.pmc create mode 100644 src/pmc/ptrbuf.pmc create mode 100644 src/pmc/ptrobj.pmc diff --git a/src/pmc/ptr.pmc b/src/pmc/ptr.pmc new file mode 100644 index 0000000000..6ecc1a9134 --- /dev/null +++ b/src/pmc/ptr.pmc @@ -0,0 +1,161 @@ +/* +Copyright (C) 2011, Parrot Foundation. + +=head1 NAME + +src/pmc/ptr.pmc - Pointer base type + +=head1 DESCRIPTION + +C is a bare bones PMC for representing pointers. It is intended that +additional functionality be added via subclassing. Any functionality added +to this PMC not critical to its operation as a pointer representation is +deprecated in advance and subject to removal without notice. + +=head2 Fat versus Thin + +C can be implemented with two separate representations - C, which +makes use of the conventional PMC attributes structure and C which is +more efficient and stores the pointer directly, avoiding memory allocation and +pointer dereference costs at the expense of extensibility. + +The distinction is managed via a set of macros - C, +C, and C. Internally, these use the +C flag, and this flag is therefore unavailable for subclass use. + +=cut + +*/ + +BEGIN_PMC_HEADER_PREAMBLE +#define PTR_FAT_TEST(i, s) PObj_flag_TEST(private1, (s)) +#define PTR_FAT_SET(i, s) PObj_flag_SET(private1, (s)) +#define PTR_FAT_CLEAR(i, s) PObj_flag_CLEAR(private1, (s)) +END_PMC_HEADER_PREAMBLE + +/* + +=head2 VTABLEs + +=over 4 + +=cut + +*/ + +pmclass Ptr manual_attrs { + ATTR void *ptr; + +/* + +=item C + +If C and attributes have not yet been otherwise allocated, will allocate +room for the representation. + +Unless otherwise initialized, Parrot will have zeroed this and the pointer +value will be C. + +=item C + +C with a value from an C. + +=item C + +C with a value from an existing pointer-ish PMC. + +=cut + +*/ + + VTABLE void init() { + if (PTR_FAT_TEST(INTERP, SELF) && !PMC_data(SELF)) { + PMC_data(SELF) = (void *)mem_gc_allocate_zeroed_typed(INTERP, Parrot_Ptr_attributes); + PObj_custom_destroy_SET(SELF); + } + } + + VTABLE void init_int(INTVAL i) { + void *ptr = (void *)i; + SELF.init(); + STATICSELF.set_pointer(ptr); + } + + VTABLE void init_pmc(PMC *p) { + void *ptr = VTABLE_get_pointer(INTERP, p); + SELF.init(); + STATICSELF.set_pointer(ptr); + } + +/* + +=item C + +=item C + +Get and set the pointer value. + +=cut + +*/ + + VTABLE void *get_pointer() { + void *ptr; + if (PTR_FAT_TEST(INTERP, SELF)) + GET_ATTR_ptr(INTERP, SELF, ptr); + else + ptr = PMC_data(SELF); + return ptr; + } + + VTABLE void set_pointer(void *ptr) { + if (PTR_FAT_TEST(INTERP, SELF)) + SET_ATTR_ptr(INTERP, SELF, ptr); + else + PMC_data(SELF) = ptr; + } + +/* + +=item C + +Boolean value of the pointer. Non-C is true, following in the C tradition. + +=cut + +*/ + + VTABLE INTVAL get_bool() { + return STATICSELF.get_pointer() != NULL; + } + +/* + +=item C + +Manage attribute deallocation for C representation. + +=cut + +*/ + + VTABLE void destroy() { + if (PTR_FAT_TEST(INTERP, SELF) && PMC_data(SELF)) + mem_gc_free(INTERP, PMC_data(SELF)); + } +} + +/* + +=back + +=cut + +*/ + +/* + * Local variables: + * c-file-style: "parrot" + * End: + * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : + */ diff --git a/src/pmc/ptrbuf.pmc b/src/pmc/ptrbuf.pmc new file mode 100644 index 0000000000..ba7bbea725 --- /dev/null +++ b/src/pmc/ptrbuf.pmc @@ -0,0 +1,74 @@ +/* +Copyright (C) 2011, Parrot Foundation. + +=head1 NAME + +src/pmc/ptrbuf.pmc - PtrBuf + +=head1 DESCRIPTION + +C is a pointer to a buffer. No affordances for memory management have +been made. It has two things - a pointer and a size. + +=head2 VTABLEs + +=over 4 + +=cut + +*/ + +pmclass PtrBuf extends Ptr auto_attrs { + ATTR UINTVAL size; + +/* + +=item C + +C is always C and manages its own attributes. Let C know about this. + +=cut + +*/ + + VTABLE void init() { + PTR_FAT_SET(INTERP, SELF); + } + +/* + +=item C + +=item C + +Get and set the buffer size. + +=cut + +*/ + + VTABLE INTVAL get_integer() { + INTVAL i; + GET_ATTR_size(INTERP, SELF, i); + return i; + } + + VTABLE void set_integer_native(INTVAL i) { + SET_ATTR_size(INTERP, SELF, i); + } +} + +/* + +=back + +=cut + +*/ + +/* + * Local variables: + * c-file-style: "parrot" + * End: + * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : + */ diff --git a/src/pmc/ptrobj.pmc b/src/pmc/ptrobj.pmc new file mode 100644 index 0000000000..4c32cb28cb --- /dev/null +++ b/src/pmc/ptrobj.pmc @@ -0,0 +1,182 @@ +/* +Copyright (C) 2011, Parrot Foundation. + +=head1 NAME + +src/pmc/ptrobj.pmc - PtrObj + +=head1 DESCRIPTION + +C is for object-ish pointers. These augment C to afford memory management. + +=head2 VTABLEs + +=over 4 + +=cut + +*/ + +BEGIN_PMC_HEADER_PREAMBLE +typedef PMC *(*ptrobj_clone_func_t)(PARROT_INTERP, PMC *, void *); +typedef void (*ptrobj_mark_func_t)(PARROT_INTERP, PMC *, void *); +typedef void (*ptrobj_destroy_func_t)(PARROT_INTERP, PMC *, void *); + +#define PTROBJ_SET_CLONE(i, p, c) do { \ + SETATTR_PtrObj_clone((i), (p), (c)); \ +} while (0) + +#define PTROBJ_SET_MARK(i, p, m) do { \ + SETATTR_PtrObj_mark((i), (p), (m)); \ + if (m) \ + PObj_custom_mark_SET(p); \ + else \ + PObj_custom_mark_CLEAR(p); \ +} while (0) + +#define PTROBJ_SET_DESTROY(i, p, d) do { \ + SETATTR_PtrObj_destroy((i), (p), (d)); \ + if (d) \ + PObj_custom_destroy_SET(p); \ + else \ + PObj_custom_destroy_CLEAR(p); \ +} while (0) +END_PMC_HEADER_PREAMBLE + +pmclass PtrObj extends PtrBuf auto_attrs { + ATTR ptrobj_clone_func_t clone; + ATTR ptrobj_mark_func_t mark; + ATTR ptrobj_destroy_func_t destroy; + +/* + +=item C + +Invoke the custom C function, if one has been provided. Otherwise, cloning is an error. + +=item C + +Get or set the custom C function. + +=cut + +*/ + + + VTABLE PMC *clone() { + void *ptr; + ptrobj_clone_func_t clone; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_clone(INTERP, SELF, clone); + if (clone) + return clone(INTERP, SELF, ptr); + else + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "clone not implemented for PtrObj %x", ptr); + } + + METHOD clone_func(PMC *func :optional, INTVAL has_func :opt_flag) { + if (has_func) { + void *f = VTABLE_get_pointer(INTERP, func); + PTROBJ_SET_CLONE(INTERP, SELF, (ptrobj_clone_func_t)f); + RETURN (); + } + else { + ptrobj_clone_func_t f; + GET_ATTR_clone(INTERP, SELF, f); + func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); + RETURN (PMC func); + } + } + +/* + +=item C + +Invoke the custom C function, if one has been provided. + +=item C + +Get or set the custom C function. + +=cut + +*/ + + VTABLE void mark() { + void *ptr; + ptrobj_mark_func_t mark; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_mark(INTERP, SELF, mark); + /* invariant: custom mark flag only set when a custom mark function has been provided */ + PARROT_ASSERT(mark); + mark(INTERP, SELF, ptr); + } + + METHOD mark_func(PMC *func :optional, INTVAL has_func :opt_flag) { + if (has_func) { + void *f = VTABLE_get_pointer(INTERP, func); + PTROBJ_SET_MARK(INTERP, SELF, (ptrobj_clone_func_t)f); + RETURN (); + } + else { + ptrobj_mark_func_t f; + GET_ATTR_mark(INTERP, SELF, f); + func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); + RETURN (PMC func); + } + } + +/* + +=item C + +Invoke the custom C function if one has been provided. + +=item C + +Get or set the custom C function. + +=cut + +*/ + + VTABLE void destroy() { + void *ptr; + ptrobj_destroy_func_t destroy; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_destroy(INTERP, SELF, destroy); + /* invariant: custom destroy flag only set when a destroy function has been provided */ + PARROT_ASSERT(destroy); + destroy(INTERP, SELF, ptr); + } + + METHOD destroy_func(PMC *func :optional, INTVAL has_func :opt_flag) { + if (has_func) { + void *f = VTABLE_get_pointer(INTERP, func); + PTROBJ_SET_DESTROY(INTERP, SELF, (ptrobj_clone_func_t)f); + RETURN (); + } + else { + ptrobj_destroy_func_t f; + GET_ATTR_destroy(INTERP, SELF, f); + func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); + RETURN (PMC func); + } + } +} + +/* + +=back + +=cut + +*/ + +/* + * Local variables: + * c-file-style: "parrot" + * End: + * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : + */ From eafa11af08da3cfbc522fd5262b54b80a34a8202 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Thu, 17 Feb 2011 20:06:02 -0500 Subject: [PATCH 03/27] move bit and nybble handling to unsigned bits are unsigned by definition (otherwise they'd just be signed nothingness) nybbles are hard to do signed (hardware and compiler support are uncommon) and not really all that useful. --- include/parrot/datatypes.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index 543eca7c57..8be140a4b6 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -41,14 +41,14 @@ typedef enum { enum_type_double, enum_type_longdouble, - enum_type_bit, /* fixed size types */ - enum_type_int1 = enum_type_bit, - enum_type_int4, - enum_type_int8, + enum_type_int8, /* fixed size types */ enum_type_int16, enum_type_int32, enum_type_int64, + enum_type_bit, + enum_type_uint1 = enum_type_bit, + enum_type_uint4, enum_type_uint8, /* unsigned variants */ enum_type_uint16, enum_type_uint32, @@ -97,14 +97,14 @@ const struct _data_types data_types[] = { { "double", sizeof (double) }, { "longdouble", 0 }, /* TODO */ - { "int1", 0 }, /* = bit */ - { "int4", 0 }, { "int8", 1 }, { "int16", 2 }, { "int32", 4 }, { "int64", 8 }, - { "uint8", 1 }, /* unsigned variants */ + { "uint1", 0 }, /* = bit */ + { "uint4", 0 }, + { "uint8", 1 }, /* unsigned variants */ { "uint16", 2 }, { "uint32", 4 }, { "uint64", 8 }, From ec609ace938f1c1154b1e89ca51c999650e9fb8f Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Thu, 17 Feb 2011 22:26:25 -0500 Subject: [PATCH 04/27] add union type --- include/parrot/datatypes.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index 8be140a4b6..df3e4dac95 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -57,7 +57,8 @@ typedef enum { enum_type_ptr, /* native pointer */ enum_type_cstr, /* c string */ enum_type_struct_ptr, /* pointer to another struct */ - enum_type_struct, /* a nested struct */ + enum_type_struct, /* a struct */ + enum_type_union, /* a union */ enum_type_func_ptr, /* a function pointer */ enum_type_sized, /* arbitrary size type for list_new */ @@ -113,6 +114,7 @@ const struct _data_types data_types[] = { { "cstr", sizeof (char *) }, { "struct_ptr", sizeof (void*) }, { "struct", 0 }, + { "union", 0 }, { "func_ptr", sizeof (void (*)(void)) }, { "sized", 0 }, From 5aeabf5c31c7af9e10798aeeac2e98ee581c4bd7 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Thu, 17 Feb 2011 22:29:42 -0500 Subject: [PATCH 05/27] eliminate unused type flags for DPOINTER and BIGINT --- include/parrot/datatypes.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index df3e4dac95..ec6f350863 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -22,8 +22,6 @@ typedef enum { enum_type_FLOATVAL, enum_type_STRING, enum_type_PMC, /* actual PMCs have positive class numbers */ - enum_type_BIGINT, - enum_type_DPOINTER, enum_type_char, /* native integer types */ enum_type_short, @@ -79,8 +77,6 @@ const struct _data_types data_types[] = { { "FLOATVAL", NUMVAL_SIZE }, { "STRING", sizeof (void *) }, { "PMC", sizeof (void *) }, /* actual PMCs have positive class numbers */ - { "BIGINT", sizeof (void *) }, - { "DPOINTER", sizeof (void *) }, { "char", sizeof (char) }, /* native integer types */ { "short", sizeof (short) }, From dd8f2850f5bd79bc990581d1f2372173a2308b72 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Fri, 18 Feb 2011 13:02:30 -0500 Subject: [PATCH 06/27] add alignment field to data type description --- include/parrot/datatypes.h | 113 ++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index ec6f350863..316efe191a 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -13,6 +13,10 @@ #ifndef PARROT_DATATYPES_H_GUARD #define PARROT_DATATYPES_H_GUARD +/* TODO: detect these with configure */ +#define HAS_LONGLONG 0 +#define HAS_LONGDOUBLE 0 + /* &gen_from_enum(datatypes.pasm) subst(s/enum_type_(\w+)/uc("DATATYPE_$1")/e) */ typedef enum { enum_type_undef, /* illegal */ @@ -67,55 +71,76 @@ typedef enum { /* &end_gen */ struct _data_types { PARROT_OBSERVER const char *name; - int size; + size_t size; + size_t align; }; +#define ALIGNOF(x) offsetof(struct { char c; x d; }, d) + extern const struct _data_types data_types[]; #if defined(INSIDE_GLOBAL_SETUP) const struct _data_types data_types[] = { - { "INTVAL", INTVAL_SIZE }, /* parrot types */ - { "FLOATVAL", NUMVAL_SIZE }, - { "STRING", sizeof (void *) }, - { "PMC", sizeof (void *) }, /* actual PMCs have positive class numbers */ - - { "char", sizeof (char) }, /* native integer types */ - { "short", sizeof (short) }, - { "int", sizeof (int) }, - { "long", sizeof (long) }, - { "longlong", 0 }, /* TODO */ - - { "uchar", sizeof (char) }, /* native unsigned types */ - { "ushort", sizeof (short)}, - { "uint", sizeof (int) }, - { "ulong", sizeof (long) }, - { "ulonglong", 0 }, /* TODO */ - - { "float", sizeof (float) }, /* native float types */ - { "double", sizeof (double) }, - { "longdouble", 0 }, /* TODO */ - - { "int8", 1 }, - { "int16", 2 }, - { "int32", 4 }, - { "int64", 8 }, - - { "uint1", 0 }, /* = bit */ - { "uint4", 0 }, - { "uint8", 1 }, /* unsigned variants */ - { "uint16", 2 }, - { "uint32", 4 }, - { "uint64", 8 }, - - { "ptr", sizeof (void*) }, - { "cstr", sizeof (char *) }, - { "struct_ptr", sizeof (void*) }, - { "struct", 0 }, - { "union", 0 }, - { "func_ptr", sizeof (void (*)(void)) }, - - { "sized", 0 }, - - { "illegal", 0 } + /* parrot types */ + { "INTVAL", sizeof (INTVAL), ALIGNOF(INTVAL) }, + { "FLOATVAL", sizeof (FLOATVAL), ALIGNOF(FLOATVAL) }, + { "STRING", sizeof (STRING *), ALIGNOF(STRING *) }, + { "PMC", sizeof (PMC *), ALIGNOF(PMC *) }, + + /* native integer types */ + { "char", sizeof (char), ALIGNOF(char) }, + { "short", sizeof (short), ALIGNOF(short) }, + { "int", sizeof (int), ALIGNOF(int) }, + { "long", sizeof (long), ALIGNOF(long) }, +#if HAS_LONGLONG + { "longlong", sizeof (long long), ALIGNOF(long long) }, +#else + { "longlong", 0, 0 }, +#endif + + /* native unsigned types */ + { "uchar", sizeof (unsigned char), ALIGNOF(unsigned char) }, + { "ushort", sizeof (unsigned short), ALIGNOF(unsigned short) }, + { "uint", sizeof (unsigned int), ALIGNOF(unsigned int) }, + { "ulong", sizeof (unsigned long), ALIGNOF(unsigned long) }, +#if HAS_LONGLONG + { "ulonglong", sizeof (unsigned long long), ALIGNOF(unsigned long long) }, +#else + { "ulonglong", 0, 0 }, +#endif + + /* native float types */ + { "float", sizeof (float), ALIGNOF(float) }, + { "double", sizeof (double), ALIGNOF(double) }, +#if HAS_LONGDOUBLE + { "longdouble", sizeof (long double), ALIGNOF(long double)}, +#else + { "longdouble", 0, 0 }, +#endif + + /* explicitly sized integer types */ + { "int8", 1, ALIGNOF(int /* TODO */) }, + { "int16", 2, ALIGNOF(int /* TODO */) }, + { "int32", 4, ALIGNOF(int /* TODO */) }, + { "int64", 8, ALIGNOF(int /* TODO */) }, + + /* unsigned variants */ + { "uint1", 0, 0 }, /* = bit */ + { "uint4", 0, 0 }, + { "uint8", 1, ALIGNOF(int /* TODO */) }, + { "uint16", 2, ALIGNOF(int /* TODO */) }, + { "uint32", 4, ALIGNOF(int /* TODO */) }, + { "uint64", 8, ALIGNOF(int /* TODO */) }, + + { "ptr", sizeof (void *), ALIGNOF(void *) }, + { "cstr", sizeof (char *), ALIGNOF(char *) }, + { "struct_ptr", sizeof (void *), ALIGNOF(void *) }, + { "struct", 0, 0 }, + { "union", 0, 0 }, + { "func_ptr", sizeof (funcptr_t), ALIGNOF(funcptr_t) }, + + { "sized", 0, 0 }, + + { "illegal", 0, 0 } }; #endif /* INSIDE_GLOBAL_SETUP */ From ab0f1b81e85a5b72771022f89139945dd230be94 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Fri, 18 Feb 2011 13:09:33 -0500 Subject: [PATCH 07/27] list_new is long gone but the concept of arbitrarily sized object is still useful --- include/parrot/datatypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index 316efe191a..1c9cc96584 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -63,7 +63,7 @@ typedef enum { enum_type_union, /* a union */ enum_type_func_ptr, /* a function pointer */ - enum_type_sized, /* arbitrary size type for list_new */ + enum_type_sized, enum_last_type /* + one */ } PARROT_DATA_TYPE; From 3357e4f917a09e270d9cbc3e1dcd41c4a320125d Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Sun, 20 Feb 2011 16:23:43 -0500 Subject: [PATCH 08/27] allow PMC registers to be used in keys --- compilers/imcc/imclexer.c | 32 +- compilers/imcc/imcparser.c | 614 +++++++++++++++++++------------------ compilers/imcc/imcparser.h | 13 +- compilers/imcc/pbc.c | 13 +- 4 files changed, 338 insertions(+), 334 deletions(-) diff --git a/compilers/imcc/imclexer.c b/compilers/imcc/imclexer.c index 6642cde332..70931c4373 100644 --- a/compilers/imcc/imclexer.c +++ b/compilers/imcc/imclexer.c @@ -78,6 +78,7 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -108,8 +109,6 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif -#endif /* ! C99 */ - #endif /* ! FLEXINT_H */ #ifdef __cplusplus @@ -183,15 +182,7 @@ typedef void* yyscan_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -2245,7 +2236,7 @@ static int handle_identifier(PARROT_INTERP, YYSTYPE *valp, ARGIN(const char *id) -#line 2249 "compilers/imcc/imclexer.c" +#line 2240 "compilers/imcc/imclexer.c" #define INITIAL 0 #define emit 1 @@ -2340,6 +2331,10 @@ int yyget_lineno (yyscan_t yyscanner ); void yyset_lineno (int line_number ,yyscan_t yyscanner ); +int yyget_column (yyscan_t yyscanner ); + +void yyset_column (int column_no ,yyscan_t yyscanner ); + /* Macros after this point can all be overridden by user definitions in * section 1. */ @@ -2380,12 +2375,7 @@ static int input (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -2404,7 +2394,7 @@ static int input (yyscan_t yyscanner ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - size_t n; \ + unsigned n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -2509,7 +2499,7 @@ YY_DECL return 0; } -#line 2513 "compilers/imcc/imclexer.c" +#line 2503 "compilers/imcc/imclexer.c" if ( !yyg->yy_init ) { @@ -3692,7 +3682,7 @@ YY_RULE_SETUP #line 724 "compilers/imcc/imcc.l" ECHO; YY_BREAK -#line 3696 "compilers/imcc/imclexer.c" +#line 3686 "compilers/imcc/imclexer.c" case YY_STATE_EOF(pod): case YY_STATE_EOF(cmt1): case YY_STATE_EOF(cmt2): @@ -4481,8 +4471,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ diff --git a/compilers/imcc/imcparser.c b/compilers/imcc/imcparser.c index 2a692e9cf6..bc3b351bc8 100644 --- a/compilers/imcc/imcparser.c +++ b/compilers/imcc/imcparser.c @@ -9,13 +9,12 @@ */ /* HEADERIZER HFILE: none */ /* HEADERIZER STOP */ - -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton implementation for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -57,7 +56,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.4.1" +#define YYBISON_VERSION "2.4.3" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -1073,7 +1072,7 @@ do_loadlib(PARROT_INTERP, ARGIN(const char *lib)) /* Line 189 of yacc.c */ -#line 1066 "compilers/imcc/imcparser.c" +#line 1065 "compilers/imcc/imcparser.c" /* Enabling traces. */ #ifndef YYDEBUG @@ -1351,7 +1350,7 @@ typedef union YYSTYPE /* Line 214 of yacc.c */ -#line 1344 "compilers/imcc/imcparser.c" +#line 1343 "compilers/imcc/imcparser.c" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -1363,7 +1362,7 @@ typedef union YYSTYPE /* Line 264 of yacc.c */ -#line 1356 "compilers/imcc/imcparser.c" +#line 1355 "compilers/imcc/imcparser.c" #ifdef short # undef short @@ -1413,7 +1412,7 @@ typedef short int yytype_int16; #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ -# if YYENABLE_NLS +# if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) @@ -2343,9 +2342,18 @@ static const yytype_uint16 yystos[] = /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ #define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif #define YYRECOVERING() (!!yyerrstatus) @@ -2402,7 +2410,7 @@ while (YYID (0)) we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT -# if YYLTYPE_IS_TRIVIAL +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ @@ -3153,28 +3161,28 @@ YYSTYPE yylval; { case 2: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1087 "compilers/imcc/imcc.y" { if (yynerrs) YYABORT; (yyval.i) = 0; } break; case 5: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1096 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 6: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1097 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 7: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1099 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); @@ -3185,7 +3193,7 @@ YYSTYPE yylval; case 8: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1105 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); @@ -3196,42 +3204,42 @@ YYSTYPE yylval; case 9: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1110 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 10: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1111 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 11: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1112 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 12: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1113 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 13: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1117 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 14: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1119 "compilers/imcc/imcc.y" { (yyval.i) = 0; @@ -3242,7 +3250,7 @@ YYSTYPE yylval; case 15: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1128 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->line = atoi((yyvsp[(2) - (5)].s)); @@ -3253,7 +3261,7 @@ YYSTYPE yylval; case 16: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1134 "compilers/imcc/imcc.y" { /* set_filename() frees the STRINGC */ @@ -3263,7 +3271,7 @@ YYSTYPE yylval; case 17: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1142 "compilers/imcc/imcc.y" { /* We'll want to store an entry while emitting instructions, so just @@ -3276,7 +3284,7 @@ YYSTYPE yylval; case 18: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1154 "compilers/imcc/imcc.y" { STRING * const hll_name = Parrot_str_unescape(interp, (yyvsp[(2) - (2)].s) + 1, '"', NULL); @@ -3291,14 +3299,14 @@ YYSTYPE yylval; case 19: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1166 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 20: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1167 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 1); @@ -3309,14 +3317,14 @@ YYSTYPE yylval; case 21: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1175 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 22: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1176 "compilers/imcc/imcc.y" { (yyval.i) = mk_pmc_const_named(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (6)].s), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].s)); @@ -3328,49 +3336,49 @@ YYSTYPE yylval; case 27: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1194 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 28: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1195 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 29: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1196 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 30: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1197 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 31: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1198 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 34: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1203 "compilers/imcc/imcc.y" { clear_state(interp); } break; case 35: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1205 "compilers/imcc/imcc.y" { (yyval.i) = INS(interp, IMCC_INFO(interp)->cur_unit, @@ -3382,7 +3390,7 @@ YYSTYPE yylval; case 36: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1212 "compilers/imcc/imcc.y" { imc_close_unit(interp, IMCC_INFO(interp)->cur_unit); @@ -3392,7 +3400,7 @@ YYSTYPE yylval; case 37: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1217 "compilers/imcc/imcc.y" { (yyval.i) = iSUBROUTINE(interp, @@ -3405,7 +3413,7 @@ YYSTYPE yylval; case 38: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1225 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(2) - (2)].sr)); @@ -3414,7 +3422,7 @@ YYSTYPE yylval; case 39: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1229 "compilers/imcc/imcc.y" { char *name = mem_sys_strdup((yyvsp[(2) - (4)].s) + 1); @@ -3432,21 +3440,21 @@ YYSTYPE yylval; case 40: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1241 "compilers/imcc/imcc.y" { (yyval.i) = 0;} break; case 42: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1249 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_unit = imc_open_unit(interp, IMC_PASM); } break; case 43: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1252 "compilers/imcc/imcc.y" { /* if (optimizer_level & OPT_PASM) @@ -3459,7 +3467,7 @@ YYSTYPE yylval; case 46: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1268 "compilers/imcc/imcc.y" { int re_open = 0; @@ -3476,21 +3484,21 @@ YYSTYPE yylval; case 47: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1282 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); } break; case 48: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1283 "compilers/imcc/imcc.y" { (yyval.sr) = NULL; } break; case 49: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1287 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -3499,7 +3507,7 @@ YYSTYPE yylval; case 50: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1291 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -3510,14 +3518,14 @@ YYSTYPE yylval; case 51: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1299 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(1) - (1)].sr); } break; case 52: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1301 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(3) - (3)].sr); @@ -3527,7 +3535,7 @@ YYSTYPE yylval; case 53: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1309 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_unit = imc_open_unit(interp, IMC_PCCSUB); @@ -3536,7 +3544,7 @@ YYSTYPE yylval; case 54: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1313 "compilers/imcc/imcc.y" { iSUBROUTINE(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (3)].sr)); @@ -3545,7 +3553,7 @@ YYSTYPE yylval; case 55: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1317 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_call->pcc_sub->pragma = (yyvsp[(5) - (6)].t); @@ -3558,28 +3566,28 @@ YYSTYPE yylval; case 56: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1325 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 57: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1329 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 58: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1330 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 59: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1332 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -3594,21 +3602,21 @@ YYSTYPE yylval; case 60: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1344 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 61: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1344 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(3) - (3)].sr); IMCC_INFO(interp)->is_def = 0; } break; case 62: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1349 "compilers/imcc/imcc.y" { if ((yyvsp[(3) - (3)].t) & VT_OPT_FLAG && (yyvsp[(1) - (3)].t) != 'I') { @@ -3633,14 +3641,14 @@ YYSTYPE yylval; case 63: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1373 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 64: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1378 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3651,7 +3659,7 @@ YYSTYPE yylval; case 65: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1384 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3662,7 +3670,7 @@ YYSTYPE yylval; case 66: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1393 "compilers/imcc/imcc.y" { (yyval.t) = P_VTABLE; @@ -3673,7 +3681,7 @@ YYSTYPE yylval; case 67: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1399 "compilers/imcc/imcc.y" { (yyval.t) = P_VTABLE; @@ -3684,7 +3692,7 @@ YYSTYPE yylval; case 68: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1408 "compilers/imcc/imcc.y" { (yyval.t) = P_METHOD; @@ -3695,7 +3703,7 @@ YYSTYPE yylval; case 69: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1414 "compilers/imcc/imcc.y" { (yyval.t) = P_METHOD; @@ -3706,7 +3714,7 @@ YYSTYPE yylval; case 70: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1423 "compilers/imcc/imcc.y" { (yyval.t) = P_NSENTRY; @@ -3717,7 +3725,7 @@ YYSTYPE yylval; case 71: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1429 "compilers/imcc/imcc.y" { (yyval.t) = P_NSENTRY; @@ -3728,7 +3736,7 @@ YYSTYPE yylval; case 72: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1438 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3738,7 +3746,7 @@ YYSTYPE yylval; case 73: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1446 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3748,7 +3756,7 @@ YYSTYPE yylval; case 74: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1451 "compilers/imcc/imcc.y" { SymReg *r = mk_const(interp, (yyvsp[(3) - (4)].s), 'S'); @@ -3761,7 +3769,7 @@ YYSTYPE yylval; case 75: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1462 "compilers/imcc/imcc.y" { add_pcc_multi(interp, IMCC_INFO(interp)->cur_call, NULL); @@ -3770,7 +3778,7 @@ YYSTYPE yylval; case 76: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1466 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3780,7 +3788,7 @@ YYSTYPE yylval; case 77: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1471 "compilers/imcc/imcc.y" { (yyval.t) = 0; @@ -3790,35 +3798,35 @@ YYSTYPE yylval; case 78: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1478 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "INTVAL", 'S'); } break; case 79: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1479 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "FLOATVAL", 'S'); } break; case 80: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1480 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "PMC", 'S'); } break; case 81: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1481 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, "STRING", 'S'); } break; case 82: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1483 "compilers/imcc/imcc.y" { SymReg *r; @@ -3834,7 +3842,7 @@ YYSTYPE yylval; case 83: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1494 "compilers/imcc/imcc.y" { SymReg *r; @@ -3850,14 +3858,14 @@ YYSTYPE yylval; case 84: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1504 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); } break; case 87: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1514 "compilers/imcc/imcc.y" { char name[128]; @@ -3884,112 +3892,112 @@ YYSTYPE yylval; case 88: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1540 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 89: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1544 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->label = 0; } break; case 90: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1545 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->label = 1; } break; case 91: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1549 "compilers/imcc/imcc.y" { (yyval.i) = NULL; } break; case 92: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1550 "compilers/imcc/imcc.y" { (yyval.i) = NULL; IMCC_INFO(interp)->cur_call->pcc_sub->object = (yyvsp[(2) - (3)].sr); } break; case 93: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1554 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 95: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1559 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (1)].t); } break; case 96: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1560 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 97: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1564 "compilers/imcc/imcc.y" { (yyval.t) = P_LOAD; } break; case 98: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1565 "compilers/imcc/imcc.y" { (yyval.t) = P_INIT; } break; case 99: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1566 "compilers/imcc/imcc.y" { (yyval.t) = P_MAIN; } break; case 100: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1567 "compilers/imcc/imcc.y" { (yyval.t) = P_IMMEDIATE; } break; case 101: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1568 "compilers/imcc/imcc.y" { (yyval.t) = P_POSTCOMP; } break; case 102: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1569 "compilers/imcc/imcc.y" { (yyval.t) = P_ANON; } break; case 103: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1570 "compilers/imcc/imcc.y" { (yyval.t) = P_NEED_LEX; } break; case 111: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1582 "compilers/imcc/imcc.y" { add_pcc_sub(IMCC_INFO(interp)->cur_call, (yyvsp[(2) - (5)].sr)); @@ -3999,7 +4007,7 @@ YYSTYPE yylval; case 112: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1587 "compilers/imcc/imcc.y" { add_pcc_sub(IMCC_INFO(interp)->cur_call, (yyvsp[(2) - (3)].sr)); @@ -4008,14 +4016,14 @@ YYSTYPE yylval; case 113: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1593 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 114: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1594 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4030,21 +4038,21 @@ YYSTYPE yylval; case 115: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1606 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (2)].sr); } break; case 116: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1611 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 117: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1613 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4054,21 +4062,21 @@ YYSTYPE yylval; case 118: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1620 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 119: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1621 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 120: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1622 "compilers/imcc/imcc.y" { IdList * const l = (yyvsp[(4) - (4)].idlist); @@ -4082,84 +4090,84 @@ YYSTYPE yylval; case 121: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1633 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 122: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1634 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 123: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1638 "compilers/imcc/imcc.y" { (yyval.t) = VT_FLAT; } break; case 124: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1639 "compilers/imcc/imcc.y" { (yyval.t) = VT_OPTIONAL; } break; case 125: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1640 "compilers/imcc/imcc.y" { (yyval.t) = VT_OPT_FLAG; } break; case 126: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1641 "compilers/imcc/imcc.y" { (yyval.t) = VT_NAMED; } break; case 127: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1642 "compilers/imcc/imcc.y" { adv_named_set(interp, (yyvsp[(3) - (4)].s)); (yyval.t) = VT_NAMED; mem_sys_free((yyvsp[(3) - (4)].s)); } break; case 128: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1643 "compilers/imcc/imcc.y" { adv_named_set_u(interp, (yyvsp[(3) - (4)].s)); (yyval.t) = VT_NAMED; mem_sys_free((yyvsp[(3) - (4)].s)); } break; case 129: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1644 "compilers/imcc/imcc.y" { (yyval.t) = VT_CALL_SIG; } break; case 130: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1649 "compilers/imcc/imcc.y" { begin_return_or_yield(interp, 0); } break; case 131: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1651 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->asm_state = AsmDefault; } break; case 132: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1653 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->asm_state = AsmDefault; @@ -4169,28 +4177,28 @@ YYSTYPE yylval; case 133: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1660 "compilers/imcc/imcc.y" { begin_return_or_yield(interp, 1); } break; case 134: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1662 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->asm_state = AsmDefault; } break; case 135: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1666 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 136: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1668 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (2)].sr)) @@ -4200,7 +4208,7 @@ YYSTYPE yylval; case 137: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1673 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4210,14 +4218,14 @@ YYSTYPE yylval; case 138: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1680 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 139: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1682 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (2)].sr)) @@ -4227,7 +4235,7 @@ YYSTYPE yylval; case 140: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1687 "compilers/imcc/imcc.y" { if ((yyvsp[(2) - (3)].sr)) @@ -4237,21 +4245,21 @@ YYSTYPE yylval; case 141: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1694 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 142: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1698 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(2) - (3)].sr); (yyval.sr)->type |= (yyvsp[(3) - (3)].t); } break; case 143: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1703 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->asm_state == AsmDefault) @@ -4261,7 +4269,7 @@ YYSTYPE yylval; case 144: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1708 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->asm_state = AsmDefault; @@ -4271,28 +4279,28 @@ YYSTYPE yylval; case 145: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1715 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 146: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1716 "compilers/imcc/imcc.y" { (yyval.t) = 1; } break; case 147: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1720 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 148: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1722 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4307,7 +4315,7 @@ YYSTYPE yylval; case 149: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1732 "compilers/imcc/imcc.y" { SymReg * const name = mk_const(interp, (yyvsp[(1) - (3)].s), 'S'); @@ -4317,7 +4325,7 @@ YYSTYPE yylval; case 150: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1737 "compilers/imcc/imcc.y" { if (IMCC_INFO(interp)->adv_named_id) { @@ -4332,7 +4340,7 @@ YYSTYPE yylval; case 151: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1747 "compilers/imcc/imcc.y" { SymReg * const name = mk_const(interp, (yyvsp[(3) - (5)].s), 'S'); @@ -4342,63 +4350,63 @@ YYSTYPE yylval; case 154: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1768 "compilers/imcc/imcc.y" { clear_state(interp); } break; case 155: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1773 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (2)].i); } break; case 156: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1774 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 157: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1775 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 158: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1776 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 159: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1777 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 160: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1778 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 161: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1782 "compilers/imcc/imcc.y" { (yyval.i) = NULL; } break; case 165: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1793 "compilers/imcc/imcc.y" { Instruction * const i = iLABEL(interp, IMCC_INFO(interp)->cur_unit, mk_local_label(interp, (yyvsp[(1) - (1)].s))); @@ -4409,14 +4417,14 @@ YYSTYPE yylval; case 166: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1803 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (3)].i); } break; case 167: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1805 "compilers/imcc/imcc.y" { if (yynerrs >= PARROT_MAX_RECOVER_ERRORS) { @@ -4429,7 +4437,7 @@ YYSTYPE yylval; case 168: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1816 "compilers/imcc/imcc.y" { IdList* const l = (yyvsp[(1) - (1)].idlist); @@ -4440,7 +4448,7 @@ YYSTYPE yylval; case 169: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1823 "compilers/imcc/imcc.y" { IdList* const l = (yyvsp[(3) - (3)].idlist); @@ -4451,7 +4459,7 @@ YYSTYPE yylval; case 170: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1832 "compilers/imcc/imcc.y" { IdList* const l = mem_gc_allocate_n_zeroed_typed(interp, 1, IdList); @@ -4462,14 +4470,14 @@ YYSTYPE yylval; case 173: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1842 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 174: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1843 "compilers/imcc/imcc.y" { IdList *l = (yyvsp[(4) - (4)].idlist); @@ -4487,7 +4495,7 @@ YYSTYPE yylval; case 175: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1856 "compilers/imcc/imcc.y" { if ((yyvsp[(4) - (4)].sr)->set != 'P') { @@ -4509,7 +4517,7 @@ YYSTYPE yylval; case 176: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1873 "compilers/imcc/imcc.y" { if ((yyvsp[(4) - (4)].sr)->set != 'P') { @@ -4527,14 +4535,14 @@ YYSTYPE yylval; case 177: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1885 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 178: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1886 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 0); @@ -4545,14 +4553,14 @@ YYSTYPE yylval; case 180: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1893 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->is_def = 1; } break; case 181: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1894 "compilers/imcc/imcc.y" { mk_const_ident(interp, (yyvsp[(4) - (6)].s), (yyvsp[(3) - (6)].t), (yyvsp[(6) - (6)].sr), 1); @@ -4563,7 +4571,7 @@ YYSTYPE yylval; case 182: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1900 "compilers/imcc/imcc.y" { (yyval.i) = NULL; @@ -4574,7 +4582,7 @@ YYSTYPE yylval; case 183: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1906 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "branch", 1, (yyvsp[(2) - (2)].sr)); @@ -4583,7 +4591,7 @@ YYSTYPE yylval; case 184: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1910 "compilers/imcc/imcc.y" { (yyval.i) = INS(interp, @@ -4600,98 +4608,98 @@ YYSTYPE yylval; case 185: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1921 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(2) - (2)].sr)); } break; case 186: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1922 "compilers/imcc/imcc.y" { (yyval.i) = 0; IMCC_INFO(interp)->cur_call = NULL; } break; case 187: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1923 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 190: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1926 "compilers/imcc/imcc.y" { (yyval.i) = 0;} break; case 191: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1930 "compilers/imcc/imcc.y" { (yyval.t) = 'I'; } break; case 192: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1931 "compilers/imcc/imcc.y" { (yyval.t) = 'N'; } break; case 193: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1932 "compilers/imcc/imcc.y" { (yyval.t) = 'S'; } break; case 194: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1933 "compilers/imcc/imcc.y" { (yyval.t) = 'P'; } break; case 195: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1938 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "set", 2, (yyvsp[(1) - (3)].sr), (yyvsp[(3) - (3)].sr)); } break; case 196: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1940 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (4)].s), 2, (yyvsp[(1) - (4)].sr), (yyvsp[(4) - (4)].sr)); } break; case 197: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1942 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(4) - (5)].s), 3, (yyvsp[(1) - (5)].sr), (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); } break; case 198: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1944 "compilers/imcc/imcc.y" { (yyval.i) = iINDEXFETCH(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (6)].sr), (yyvsp[(3) - (6)].sr), (yyvsp[(5) - (6)].sr)); } break; case 199: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1946 "compilers/imcc/imcc.y" { (yyval.i) = iINDEXSET(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (6)].sr), (yyvsp[(3) - (6)].sr), (yyvsp[(6) - (6)].sr)); } break; case 200: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1949 "compilers/imcc/imcc.y" { add_pcc_result(interp, (yyvsp[(3) - (3)].i)->symregs[0], (yyvsp[(1) - (3)].sr)); @@ -4702,7 +4710,7 @@ YYSTYPE yylval; case 201: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1955 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -4711,7 +4719,7 @@ YYSTYPE yylval; case 202: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1959 "compilers/imcc/imcc.y" { IMCC_itcall_sub(interp, (yyvsp[(6) - (9)].sr)); @@ -4721,7 +4729,7 @@ YYSTYPE yylval; case 206: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1967 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "null", 1, (yyvsp[(1) - (3)].sr)); @@ -4730,189 +4738,189 @@ YYSTYPE yylval; case 207: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1974 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"not"; } break; case 208: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1975 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bnot"; } break; case 209: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1976 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"neg"; } break; case 210: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1980 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"sub"; } break; case 211: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1981 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"add"; } break; case 212: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1982 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mul"; } break; case 213: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1983 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"div"; } break; case 214: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1984 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mod"; } break; case 215: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1985 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"fdiv"; } break; case 216: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1986 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"pow"; } break; case 217: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1987 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"concat"; } break; case 218: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1988 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"iseq"; } break; case 219: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1989 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isne"; } break; case 220: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1990 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isgt"; } break; case 221: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1991 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isge"; } break; case 222: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1992 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"islt"; } break; case 223: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1993 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"isle"; } break; case 224: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1994 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shl"; } break; case 225: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1995 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shr"; } break; case 226: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1996 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lsr"; } break; case 227: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1997 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"and"; } break; case 228: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1998 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"or"; } break; case 229: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 1999 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"xor"; } break; case 230: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2000 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"band"; } break; case 231: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2001 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bor"; } break; case 232: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2002 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bxor"; } break; case 233: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2008 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -4923,21 +4931,21 @@ YYSTYPE yylval; case 234: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2013 "compilers/imcc/imcc.y" { (yyval.i) = 0; } break; case 235: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2020 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(2) - (3)].s), 2, (yyvsp[(1) - (3)].sr), (yyvsp[(3) - (3)].sr)); } break; case 236: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2022 "compilers/imcc/imcc.y" { if ((yyvsp[(1) - (3)].sr)->set == 'P') @@ -4949,91 +4957,91 @@ YYSTYPE yylval; case 237: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2031 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"add"; } break; case 238: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2032 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"sub"; } break; case 239: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2033 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mul"; } break; case 240: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2034 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"div"; } break; case 241: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2035 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"mod"; } break; case 242: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2036 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"fdiv"; } break; case 243: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2037 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"band"; } break; case 244: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2038 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bor"; } break; case 245: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2039 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"bxor"; } break; case 246: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2040 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shr"; } break; case 247: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2041 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"shl"; } break; case 248: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2042 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lsr"; } break; case 249: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2048 "compilers/imcc/imcc.y" { (yyval.i) = func_ins(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(1) - (4)].sr), (yyvsp[(3) - (4)].s), @@ -5046,28 +5054,28 @@ YYSTYPE yylval; case 250: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2058 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 251: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2059 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_fromc(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 252: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2060 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_u(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 253: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2062 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); @@ -5078,7 +5086,7 @@ YYSTYPE yylval; case 254: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2068 "compilers/imcc/imcc.y" { /* disallow bareword method names; SREG name constants are fine */ @@ -5097,7 +5105,7 @@ YYSTYPE yylval; case 255: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2082 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); @@ -5108,7 +5116,7 @@ YYSTYPE yylval; case 256: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2088 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); @@ -5119,14 +5127,14 @@ YYSTYPE yylval; case 257: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2093 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->cur_obj = (yyvsp[(1) - (3)].sr); (yyval.sr) = (yyvsp[(3) - (3)].sr); } break; case 258: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2099 "compilers/imcc/imcc.y" { (yyval.i) = IMCC_create_itcall_label(interp); @@ -5136,21 +5144,21 @@ YYSTYPE yylval; case 259: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2103 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(2) - (5)].i); } break; case 260: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2107 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 261: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2109 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5165,7 +5173,7 @@ YYSTYPE yylval; case 262: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2119 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5180,7 +5188,7 @@ YYSTYPE yylval; case 263: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2129 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5192,7 +5200,7 @@ YYSTYPE yylval; case 264: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2136 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5202,7 +5210,7 @@ YYSTYPE yylval; case 265: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2141 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5214,70 +5222,70 @@ YYSTYPE yylval; case 266: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2150 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (2)].sr); (yyval.sr)->type |= (yyvsp[(2) - (2)].t); } break; case 267: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2154 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 268: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2155 "compilers/imcc/imcc.y" { (yyval.t) = (yyvsp[(1) - (2)].t) | (yyvsp[(2) - (2)].t); } break; case 269: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2159 "compilers/imcc/imcc.y" { (yyval.t) = VT_FLAT; } break; case 270: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2160 "compilers/imcc/imcc.y" { (yyval.t) = VT_NAMED; } break; case 271: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2161 "compilers/imcc/imcc.y" { (yyval.t) = VT_CALL_SIG; } break; case 272: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2163 "compilers/imcc/imcc.y" { adv_named_set_u(interp, (yyvsp[(3) - (4)].s)); mem_sys_free((yyvsp[(3) - (4)].s)); (yyval.t) = 0; } break; case 273: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2164 "compilers/imcc/imcc.y" { adv_named_set(interp, (yyvsp[(3) - (4)].s)); mem_sys_free((yyvsp[(3) - (4)].s)); (yyval.t) = 0; } break; case 274: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2168 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (2)].sr); (yyval.sr)->type |= (yyvsp[(2) - (2)].t); } break; case 275: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2173 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5292,7 +5300,7 @@ YYSTYPE yylval; case 276: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2183 "compilers/imcc/imcc.y" { add_pcc_named_result(interp, IMCC_INFO(interp)->cur_call, @@ -5303,7 +5311,7 @@ YYSTYPE yylval; case 277: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2189 "compilers/imcc/imcc.y" { (yyval.sr) = 0; @@ -5318,7 +5326,7 @@ YYSTYPE yylval; case 278: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2199 "compilers/imcc/imcc.y" { add_pcc_named_result(interp, IMCC_INFO(interp)->cur_call, mk_const(interp, (yyvsp[(1) - (3)].s), 'S'), (yyvsp[(3) - (3)].sr)); @@ -5328,28 +5336,28 @@ YYSTYPE yylval; case 279: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2203 "compilers/imcc/imcc.y" { (yyval.sr) = 0; } break; case 280: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2207 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 281: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2208 "compilers/imcc/imcc.y" { (yyval.i) = (yyvsp[(1) - (1)].i); } break; case 282: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2213 "compilers/imcc/imcc.y" { (yyval.i) =MK_I(interp, IMCC_INFO(interp)->cur_unit, inv_op((yyvsp[(3) - (6)].s)), 3, (yyvsp[(2) - (6)].sr), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].sr)); @@ -5358,7 +5366,7 @@ YYSTYPE yylval; case 283: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2217 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "unless_null", 2, (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); @@ -5367,7 +5375,7 @@ YYSTYPE yylval; case 284: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2221 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "unless", 2, (yyvsp[(2) - (4)].sr), (yyvsp[(4) - (4)].sr)); @@ -5376,7 +5384,7 @@ YYSTYPE yylval; case 285: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2228 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "if", 2, (yyvsp[(2) - (4)].sr), (yyvsp[(4) - (4)].sr)); @@ -5385,7 +5393,7 @@ YYSTYPE yylval; case 286: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2232 "compilers/imcc/imcc.y" { (yyval.i) =MK_I(interp, IMCC_INFO(interp)->cur_unit, (yyvsp[(3) - (6)].s), 3, (yyvsp[(2) - (6)].sr), (yyvsp[(4) - (6)].sr), (yyvsp[(6) - (6)].sr)); @@ -5394,7 +5402,7 @@ YYSTYPE yylval; case 287: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2236 "compilers/imcc/imcc.y" { (yyval.i) = MK_I(interp, IMCC_INFO(interp)->cur_unit, "if_null", 2, (yyvsp[(3) - (5)].sr), (yyvsp[(5) - (5)].sr)); @@ -5403,91 +5411,91 @@ YYSTYPE yylval; case 288: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2242 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 289: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2243 "compilers/imcc/imcc.y" { (yyval.t) = 0; } break; case 290: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2247 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"eq"; } break; case 291: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2248 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"ne"; } break; case 292: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2249 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"gt"; } break; case 293: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2250 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"ge"; } break; case 294: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2251 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"lt"; } break; case 295: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2252 "compilers/imcc/imcc.y" { (yyval.s) = (char *)"le"; } break; case 298: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2261 "compilers/imcc/imcc.y" { (yyval.sr) = NULL; } break; case 299: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2262 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); } break; case 300: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2266 "compilers/imcc/imcc.y" { (yyval.sr) = IMCC_INFO(interp)->regs[0]; } break; case 302: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2271 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(1) - (1)].sr); } break; case 303: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2273 "compilers/imcc/imcc.y" { IMCC_INFO(interp) -> regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(1) - (4)].sr); @@ -5499,7 +5507,7 @@ YYSTYPE yylval; case 304: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2280 "compilers/imcc/imcc.y" { IMCC_INFO(interp) -> regs[IMCC_INFO(interp)->nargs++] = (yyvsp[(2) - (3)].sr); @@ -5509,49 +5517,49 @@ YYSTYPE yylval; case 306: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2287 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_fromc(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 307: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2288 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address_u(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 308: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2292 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 309: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2293 "compilers/imcc/imcc.y" { (yyval.sr) = mk_sub_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 310: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2297 "compilers/imcc/imcc.y" { (yyval.sr) = mk_label_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 311: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2298 "compilers/imcc/imcc.y" { (yyval.sr) = mk_label_address(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 316: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2312 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -5560,7 +5568,7 @@ YYSTYPE yylval; case 317: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2316 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -5571,7 +5579,7 @@ YYSTYPE yylval; case 318: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2324 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->nkeys = 0; @@ -5580,7 +5588,7 @@ YYSTYPE yylval; case 319: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2328 "compilers/imcc/imcc.y" { (yyval.sr) = link_keys(interp, @@ -5591,14 +5599,14 @@ YYSTYPE yylval; case 320: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2336 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(1) - (1)].sr); } break; case 321: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2338 "compilers/imcc/imcc.y" { IMCC_INFO(interp)->keys[IMCC_INFO(interp)->nkeys++] = (yyvsp[(3) - (3)].sr); @@ -5608,7 +5616,7 @@ YYSTYPE yylval; case 322: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2346 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); @@ -5617,78 +5625,78 @@ YYSTYPE yylval; case 323: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2352 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'I'); } break; case 324: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2353 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'N'); } break; case 325: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2354 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'S'); } break; case 326: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2355 "compilers/imcc/imcc.y" { (yyval.sr) = mk_symreg(interp, (yyvsp[(1) - (1)].s), 'P'); } break; case 327: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2356 "compilers/imcc/imcc.y" { (yyval.sr) = mk_pasm_reg(interp, (yyvsp[(1) - (1)].s)); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 328: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2360 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'S'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 329: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2361 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'U'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 330: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2365 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'I'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 331: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2366 "compilers/imcc/imcc.y" { (yyval.sr) = mk_const(interp, (yyvsp[(1) - (1)].s), 'N'); mem_sys_free((yyvsp[(1) - (1)].s)); } break; case 332: -/* Line 1455 of yacc.c */ +/* Line 1464 of yacc.c */ #line 2367 "compilers/imcc/imcc.y" { (yyval.sr) = (yyvsp[(1) - (1)].sr); } break; -/* Line 1455 of yacc.c */ -#line 5681 "compilers/imcc/imcparser.c" +/* Line 1464 of yacc.c */ +#line 5689 "compilers/imcc/imcparser.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -5899,7 +5907,7 @@ YYSTYPE yylval; -/* Line 1675 of yacc.c */ +/* Line 1684 of yacc.c */ #line 2373 "compilers/imcc/imcc.y" diff --git a/compilers/imcc/imcparser.h b/compilers/imcc/imcparser.h index cd5f8b35d4..dad4aeb7bc 100644 --- a/compilers/imcc/imcparser.h +++ b/compilers/imcc/imcparser.h @@ -9,13 +9,12 @@ */ /* HEADERIZER HFILE: none */ /* HEADERIZER STOP */ - -/* A Bison parser, made by GNU Bison 2.4.1. */ +/* A Bison parser, made by GNU Bison 2.4.3. */ /* Skeleton interface for Bison's Yacc-like parsers in C - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006 - Free Software Foundation, Inc. + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2009, 2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -289,7 +288,7 @@ typedef union YYSTYPE { -/* Line 1676 of yacc.c */ +/* Line 1685 of yacc.c */ #line 993 "compilers/imcc/imcc.y" IdList * idlist; @@ -300,8 +299,8 @@ typedef union YYSTYPE -/* Line 1676 of yacc.c */ -#line 294 "compilers/imcc/imcparser.h" +/* Line 1685 of yacc.c */ +#line 293 "compilers/imcc/imcparser.h" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ diff --git a/compilers/imcc/pbc.c b/compilers/imcc/pbc.c index 26d0cc0339..10980245ff 100644 --- a/compilers/imcc/pbc.c +++ b/compilers/imcc/pbc.c @@ -1638,12 +1638,19 @@ build_key(PARROT_INTERP, ARGIN(SymReg *key_reg), ARGMOD(PackFile_ByteCode * bc)) /* don't emit mapped regs in key parts */ regno = r->color >= 0 ? r->color : -1 - r->color; - if (r->set == 'I') + switch (r->set) { + case 'I': Parrot_key_set_register(interp, tail, regno, KEY_integer_FLAG); - else if (r->set == 'S') + break; + case 'S': Parrot_key_set_register(interp, tail, regno, KEY_string_FLAG); - else + break; + case 'P': + Parrot_key_set_register(interp, tail, regno, KEY_pmc_FLAG); + break; + default: IMCC_fatal(interp, 1, "build_key: wrong register set\n"); + } IMCC_debug(interp, DEBUG_PBC_CONST, " keypart reg %s %c%d\n", From cf5ccfb846579ddd42c2b0799117089fd3d9a582 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Sun, 20 Feb 2011 22:53:32 -0500 Subject: [PATCH 09/27] implement StructView PMC to view pointers as struct and union type objects --- src/pmc/structview.pmc | 682 +++++++++++++++++++++++++++++++++++++++++ t/pmc/structview.t | 157 ++++++++++ 2 files changed, 839 insertions(+) create mode 100644 src/pmc/structview.pmc create mode 100644 t/pmc/structview.t diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc new file mode 100644 index 0000000000..7be1520c4e --- /dev/null +++ b/src/pmc/structview.pmc @@ -0,0 +1,682 @@ +/* +Copyright (C) 2001-2010, Parrot Foundation. + +=head1 NAME + +src/pmc/structview.pmc - C struct view for pointers. + +=head1 DESCRIPTION + +PMC class to view pointers as C Cs. This includes read, write, allocate, +and deallocate operations. Bounds checking is implemented where the pointer +class supports a bound. + +=head2 Vtables and Methods + +=over 4 + +=cut + +*/ + +#include "pmc/pmc_ptrobj.h" + +BEGIN_PMC_HEADER_PREAMBLE +typedef enum { + int_access = 1, + unaligned_access, + num_access, + str_access, + pmc_access +} elt_access_t; + +typedef struct { + elt_access_t access; + PARROT_DATA_TYPE type; + size_t byte_offset; + unsigned char bit_offset; + size_t size; +} elt_desc_t; +END_PMC_HEADER_PREAMBLE + +/* TODO: detect with configure */ +#define HAS_64BIT 0 + +#define ALIGN_UP(addr, align) (((addr) + ((align) - 1)) & ~((align) - 1)) + +#define MAX(x, y) ((y) > (x) ? (y) : (x)) + +#define BEGIN_KEYED(interp, s, k) \ + size_t n_elts; \ + elt_desc_t *elts; \ + PMC *ptr_pmc; \ + void *ptr, *base_ptr; \ + INTVAL i; \ + GETATTR_StructView_n_elts((interp), (s), n_elts); \ + GETATTR_StructView_elts((interp), (s), elts); \ + ptr_pmc = Parrot_key_pmc((interp), (k)); \ + (k) = Parrot_key_next((interp), (k)); \ + i = Parrot_key_integer((interp), (k)); \ + if (i < 0 || n_elts <= i) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Struct index out of bounds (%d)", \ + i); \ + base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ + ptr = ((char *)base_ptr) + elts[i].byte_offset; + +static void deallocate_ptrobj(PARROT_INTERP, PMC *obj, void *ptr) { + mem_sys_free(ptr); +} + +pmclass StructView auto_attrs { + ATTR size_t n_elts; + ATTR elt_desc_t *elts; + ATTR size_t align; + ATTR size_t size; + + VTABLE void init() { + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Meaningless creation of %Ss without initializer", + SELF->vtable->whoami); + } + + VTABLE void init_pmc(PMC *p) { + INTVAL init_len = VTABLE_elements(INTERP, p); + PARROT_DATA_TYPE pack_type = VTABLE_get_integer_keyed_int(INTERP, p, 0); + INTVAL n_elts = VTABLE_get_integer_keyed_int(INTERP, p, 1); + elt_desc_t *elt_ary; + size_t bit_cursor = 0; + size_t byte_cursor = 0; + size_t size, align; + int incr, i, j; + + switch (pack_type) { + case enum_type_struct: + case enum_type_union: + align = 1; /* sorry, no sub-byte alignment */ + incr = 1; + i = 2; + break; + case enum_type_sized: + size = VTABLE_get_integer_keyed_int(INTERP, p, 2); + align = VTABLE_get_integer_keyed_int(INTERP, p, 3); + incr = 3; + i = 4; + break; + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unknown struct type `%Ss'", + Parrot_dt_get_datatype_name(INTERP, pack_type)); + } + + if (init_len < n_elts + i) + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Initializer too short (%d) for struct type `%Ss' with %d elements", + init_len, + Parrot_dt_get_datatype_name(INTERP, pack_type), + n_elts); + + elt_ary = mem_gc_allocate_n_zeroed_typed(INTERP, n_elts, elt_desc_t); + PObj_custom_destroy_SET(SELF); + + SET_ATTR_elts(INTERP, SELF, elt_ary); + SET_ATTR_n_elts(INTERP, SELF, n_elts); + + for (/* i already initialized */ j = 0; i < init_len && j < n_elts; i += incr, j++) { + elt_desc_t *elt = &elt_ary[j]; + PARROT_DATA_TYPE elt_type = VTABLE_get_integer_keyed_int(INTERP, p, i); + size_t elt_size, elt_align; + elt_access_t elt_access; + + if (elt_type < enum_first_type || enum_last_type <= elt_type) + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Invalid type flag for struct element (%d)", elt_type); + + elt->type = elt_type; + elt_size = data_types[elt_type - enum_first_type].size; + elt_align = data_types[elt_type - enum_first_type].align; + + switch (elt_type) { + /* aligned integer types */ + case enum_type_INTVAL: + case enum_type_char: + case enum_type_short: + case enum_type_int: + case enum_type_long: +#if HAS_LONGLONG + case enum_type_longlong: +#endif + case enum_type_uchar: + case enum_type_ushort: + case enum_type_uint: + case enum_type_ulong: +#if HAS_LONGLONG + case enum_type_ulonglong: +#endif + elt_access = int_access; + break; + + /* unaligned integer types */ + case enum_type_uint1: + case enum_type_uint4: + elt_access = unaligned_access; + break; + + /* float types */ + case enum_type_FLOATVAL: + case enum_type_float: + case enum_type_double: +#if HAS_LONGDOUBLE + case enum_type_longdouble: +#endif + elt_access = num_access; + break; + + /* other types */ + case enum_type_STRING: + elt_access = str_access; + break; + case enum_type_sized: + /* arbitrary buffers extended with size and align fields */ + elt->size = elt_size = VTABLE_get_integer_keyed_int(INTERP, p, ++i); + elt_align = VTABLE_get_integer_keyed_int(INTERP, p, ++i); + /* fallthrough */ + case enum_type_PMC: + case enum_type_ptr: + case enum_type_func_ptr: + elt_access = pmc_access; + break; + + /* TODO: explicitly sized type support */ + case enum_type_int8: + case enum_type_int16: + case enum_type_int32: +#if HAS_64BIT + case enum_type_int64: +#endif + case enum_type_uint8: + case enum_type_uint16: + case enum_type_uint32: +#if HAS_64BIT + case enum_type_uint64: +#endif + + /* locally unsupported types */ +#if !HAS_LONGLONG + case enum_type_longlong: + case enum_type_ulonglong: +#endif +#if !HAS_64BIT + case enum_type_int64: + case enum_type_uint64: +#endif +#if !HAS_LONGDOUBLE + case enum_type_longdouble: +#endif + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unsupported struct element type `%Ss' (index %d)", + Parrot_dt_get_datatype_name(INTERP, elt_type), + j); + + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unknown struct element type `%s' (index %i)", + Parrot_dt_get_datatype_name(INTERP, elt_type), + j); + } + + switch (pack_type) { + case enum_type_struct: + elt->access = elt_access; + align = MAX(align, elt_align); + switch (elt_access) { + case int_access: + case num_access: + case pmc_access: + if (bit_cursor) { + byte_cursor += 1; + bit_cursor = 0; + } + elt->byte_offset = ALIGN_UP(byte_cursor, elt_align); + byte_cursor = elt->byte_offset + elt_size; + break; + case unaligned_access: + elt->byte_offset = byte_cursor; + elt->bit_offset = bit_cursor; + byte_cursor = (bit_cursor + 1) / 8; + bit_cursor = (bit_cursor + 1) % 8; + break; + } + break; + case enum_type_union: + elt->access = elt_access; + size = MAX(size, elt_size); + align = MAX(align, elt_align); + /* all union elements are at 0 offset */ + break; + case enum_type_sized: + elt->byte_offset = VTABLE_get_integer_keyed_int(INTERP, p, i + 1); + elt->bit_offset = VTABLE_get_integer_keyed_int(INTERP, p, i + 2); + switch (elt_access) { + case num_access: + case str_access: + case pmc_access: + if (align < elt_align + || elt->bit_offset + || elt->byte_offset % elt_align) + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unaligned access unsupported on type `%Ss' (index: %i)", + Parrot_dt_get_datatype_name(INTERP, elt_type), + j); + elt->access = elt_access; + break; + case int_access: + if (align < elt_align + || elt->bit_offset + || elt->byte_offset % elt_align) { + switch (elt_type) { + case enum_type_uchar: + case enum_type_ushort: + case enum_type_uint: + case enum_type_ulong: +#if HAS_LONGLONG + case enum_type_ulonglong: +#endif + elt->access = unaligned_access; + break; + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unaligned access unsupported on type `%Ss' (index: %i)", + Parrot_dt_get_datatype_name(INTERP, elt_type), + j); + } + } + else { + elt->access = int_access; + } + break; + case unaligned_access: + elt->access = unaligned_access; + break; + } + } + } + + if (pack_type == enum_type_struct) { + size = byte_cursor + !!bit_cursor; + } + + SET_ATTR_align(INTERP, SELF, align); + SET_ATTR_size(INTERP, SELF, size); + } + + VTABLE void destroy() { + elt_desc_t *elts; + GET_ATTR_elts(INTERP, SELF, elts); + mem_gc_free(INTERP, elts); + } + + VTABLE INTVAL get_integer_keyed(PMC *k) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case int_access: + switch (elts[i].type) { +#define _CASE_RET(type, name) \ + case enum_type_ ## name: return *(type *)ptr; +#define CASE_RET(type) \ + _CASE_RET(type, type) \ + _CASE_RET(unsigned type, u ## type) + _CASE_RET(INTVAL, INTVAL) + CASE_RET(char); + CASE_RET(short); + CASE_RET(int); + CASE_RET(long); +#if HAS_LONGLONG + _CASE_RET(long long, longlong); + _CASE_RET(unsigned long long, ulonglong); +#endif +#undef CASE_RET +#undef _CASE_RET + } + break; + case unaligned_access: + { + INTVAL acc = 0; + size_t bits, n; + unsigned char *cptr = (unsigned char *)ptr; + + switch (elts[i].type) { + case enum_type_uint1: + bits = 1; + break; + case enum_type_uint4: + bits = 4; + break; + default: + bits = 8 * data_types[elts[i].type - enum_first_type].size; + break; + } + +#if PARROT_BIGENDIAN + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unaligned access not yet implemented for big-endian systems"); +#else + /* fetch hi bits of first byte */ + acc = *cptr++ >> elts[i].bit_offset; + n = 8 - elts[i].bit_offset; + + /* read whole bytes until complete */ + while (n < bits) { + acc |= ((UINTVAL)*cptr++) << n; + n += 8; + } + + /* mask off hi bits of last byte */ + acc &= (~(UINTVAL)0) >> (sizeof (UINTVAL) * 8 - bits); +#endif + + return acc; + } + break; + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid integer type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE void set_integer_keyed(PMC *k, INTVAL x) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case int_access: + switch (elts[i].type) { +#define _CASE_SET(type, name) \ + case enum_type_ ## name: *(type *)ptr = x; return; +#define CASE_SET(type) \ + _CASE_SET(type, type) \ + _CASE_SET(unsigned type, u ## type) + _CASE_SET(INTVAL, INTVAL) + CASE_SET(char); + CASE_SET(short); + CASE_SET(int); + CASE_SET(long); +#if HAS_LONGLONG + _CASE_SET(long long, longlong); + _CASE_SET(unsigned long long, ulonglong); +#endif +#undef CASE_SET +#undef _CASE_SET + } + break; + case unaligned_access: + { + UINTVAL ux = x; + size_t bits, n; + unsigned char tempc; + unsigned char *cptr = ptr; + + switch (elts[i].type) { + case enum_type_uint1: + bits = 1; + break; + case enum_type_uint4: + bits = 4; + break; + default: + bits = 8 * data_types[elts[i].type - enum_first_type].size; + break; + } + +#if PARROT_BIGENDIAN + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Unaligned write not yet implemented for big-endian systems"); +#else + /* cache last byte (for restoring hi bits) */ + tempc = cptr[(bits + elts[i].bit_offset)/8]; + + /* write hi bits of first byte */ + n = 8 - elts[i].bit_offset; + *cptr &= (1 << elts[i].bit_offset) - 1; + *cptr++ |= (ux & (1 << n) - 1) << elts[i].bit_offset; + + /* write whole bytes until complete */ + while (n < bits) { + *cptr++ = ux >> n; + n += 8; + } + + /* restore hi bits of last byte */ + cptr--; + n = 8 - (n - bits); /* how many bits of last byte we should have written */ + *cptr &= (1 << n) - 1; + *cptr |= tempc & ~((1 << n) - 1); +#endif + } + break; + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid integer type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE FLOATVAL get_number_keyed(PMC *k) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case num_access: + switch (elts[i].type) { + case enum_type_FLOATVAL: + return *(FLOATVAL *)ptr; + case enum_type_float: + return *(float *)ptr; + case enum_type_double: + return *(double *)ptr; +#if HAS_LONGDOUBLE + case enum_type_longdouble: + return *(long double *)ptr; +#endif + } + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid number type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE void set_number_keyed(PMC *k, FLOATVAL n) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case num_access: + switch (elts[i].type) { + case enum_type_FLOATVAL: + *(FLOATVAL *)ptr = n; + return; + case enum_type_float: + *(float *)ptr = n; + return; + case enum_type_double: + *(double *)ptr = n; + return; +#if HAS_LONGDOUBLE + case enum_type_longdouble: + *(long double *)ptr = n; + return; +#endif + } + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid number type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE STRING *get_string_keyed(PMC *k) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case str_access: + switch (elts[i].type) { + case enum_type_STRING: + return *(STRING **)ptr; + } + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid string type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE void set_string_keyed(PMC *k, STRING *s) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case str_access: + switch (elts[i].type) { + case enum_type_STRING: + *(STRING **)ptr = s; + return; + } + default: + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Not a valid string type (`%Ss')", + Parrot_dt_get_datatype_name(INTERP, elts[i].type)); + } + } + + VTABLE PMC *get_pmc_keyed(PMC *k) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case int_access: + case unaligned_access: + return Parrot_pmc_box_integer(INTERP, SELF.get_integer_keyed(k)); + case num_access: + return Parrot_pmc_box_number(INTERP, SELF.get_number_keyed(k)); + case str_access: + return Parrot_pmc_box_string(INTERP, SELF.get_string_keyed(k)); + case pmc_access: + { + PMC *ret; + switch (elts[i].type) { + case enum_type_PMC: + return *(PMC **)ptr; + case enum_type_func_ptr: + case enum_type_ptr: + return Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, + (INTVAL)*(void **)ptr); + case enum_type_sized: + ret = Parrot_pmc_new_init_int(INTERP, enum_class_PtrBuf, + (INTVAL)*(void **)ptr); + VTABLE_set_integer_native(INTERP, ret, elts[i].size); + return ret; + } + } + } + } + + VTABLE void *set_pmc_keyed(PMC *k, PMC *p) { + BEGIN_KEYED(INTERP, SELF, k) + switch (elts[i].access) { + case int_access: + case unaligned_access: + SELF.set_integer_keyed(k, VTABLE_get_integer(INTERP, p)); + break; + case num_access: + SELF.set_number_keyed(k, VTABLE_get_number(INTERP, p)); + break; + case str_access: + SELF.set_string_keyed(k, VTABLE_get_string(INTERP, p)); + break; + case pmc_access: + { + PMC *ret; + switch (elts[i].type) { + case enum_type_PMC: + *(PMC **)ptr = p; + break; + case enum_type_func_ptr: + case enum_type_ptr: + *(void **)ptr = VTABLE_get_pointer(INTERP, p); + break; + case enum_type_sized: + if (VTABLE_does(INTERP, p, CONST_STRING(INTERP, "buffer"))) { + void *q = VTABLE_get_pointer(INTERP, p); + size_t len = VTABLE_get_integer(INTERP, p); + if (!len || len > elts[i].size) + len = elts[i].size; + memcpy(ptr, q, len); + break; + } + else { + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + "Type `%Ss' unsuitable for buffer assignment", + p->vtable->whoami); + } + } + } + } + } + + VTABLE INTVAL get_integer() { + size_t size; + GET_ATTR_size(INTERP, SELF, size); + return size; + } + + METHOD size() { + size_t size; + GET_ATTR_size(INTERP, SELF, size); + RETURN (INTVAL size); + } + + METHOD align() { + size_t align; + GET_ATTR_align(INTERP, SELF, align); + RETURN (INTVAL align); + } + + METHOD aligned_size() { + size_t size, align; + INTVAL ret; + GET_ATTR_size(INTERP, SELF, size); + GET_ATTR_align(INTERP, SELF, align); + ret = ALIGN_UP(size, align); + RETURN (INTVAL ret); + } + + METHOD alloc(INTVAL n :optional, int has_n :opt_flag) { + size_t size, align; + PMC *ret; + void *buf; + + GET_ATTR_size(INTERP, SELF, size); + + if (has_n) { + GET_ATTR_align(INTERP, SELF, align); + size = ALIGN_UP(size, align) * n; + } + + buf = mem_sys_allocate_zeroed(size); + ret = Parrot_pmc_new_init_int(INTERP, enum_class_PtrObj, (INTVAL)buf); + SETATTR_PtrObj_destroy(INTERP, ret, deallocate_ptrobj); + + RETURN (PMC ret); + } +} + +/* + +=back + +=head1 SEE ALSO + +F + +=cut + +*/ + +/* + * Local variables: + * c-file-style: "parrot" + * End: + * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : + */ + diff --git a/t/pmc/structview.t b/t/pmc/structview.t new file mode 100644 index 0000000000..5ce3884851 --- /dev/null +++ b/t/pmc/structview.t @@ -0,0 +1,157 @@ +#!./parrot +# Copyright (C) 2011, Parrot Foundation. + +.include 'datatypes.pasm' + +.sub 'main' :main + .include 'test_more.pir' + + plan(11) + + test_bit_struct() + test_unaligned_struct() + test_union() + test_fp() +.end + +.sub test_bit_struct + $P0 = new ['FixedIntegerArray'], 10 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 8 + $I0 = 2 + loop: + $P0[$I0] = .DATATYPE_BIT + inc $I0 + unless $I0 > 9 goto loop + + .local pmc sv + sv = new ['StructView'], $P0 + + $I0 = sv.'size'() + is($I0, 1, '8 bits in one byte') + $I0 = sv.'align'() + is($I0, 1, 'single byte is byte-aligned') + $I0 = sv.'aligned_size'() + is($I0, 1, 'byte-aligned single byte is single byte when aligned') + + .local pmc buf + buf = sv.'alloc'() + ok(buf, 'allocate an instance') + + $I0 = 1 + loop2: + sv[buf; $I0] = 1 + $I0 += 2 + unless $I0 > 8 goto loop2 + + $P0 = new ['FixedIntegerArray'], 3 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 1 + $P0[2] = .DATATYPE_UCHAR + + .local pmc sv2 + sv2 = new ['StructView'], $P0 + + $I0 = sv2[buf; 0] + is($I0, 0xAA, 'bitpattern gives correct byte') +.end + +.sub 'test_unaligned_struct' + $P0 = new ['FixedIntegerArray'], 13 + $P0[0] = .DATATYPE_SIZED # custom layout struct + $P0[1] = 3 + $P0[2] = 2 # size + $P0[3] = 1 # alignment + $P0[4] = .DATATYPE_UINT4 + $P0[5] = 0 # byte-offset + $P0[6] = 0 # bit-offset + $P0[7] = .DATATYPE_UCHAR + $P0[8] = 0 + $P0[9] = 4 + $P0[10] = .DATATYPE_UINT4 + $P0[11] = 1 + $P0[12] = 4 + + .local pmc sv, buf + sv = new ['StructView'], $P0 + buf = sv.'alloc'() + sv[buf; 0] = 0xB + sv[buf; 1] = 0xDA + sv[buf; 2] = 0xC + + $P0 = new ['FixedIntegerArray'], 4 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 2 + $P0[2] = .DATATYPE_UCHAR + $P0[3] = .DATATYPE_UCHAR + + .local pmc sv2 + sv2 = new ['StructView'], $P0 + $I0 = sv2[buf; 0] + is($I0, 0xAB, 'unaligned struct first byte') + $I0 = sv2[buf; 1] + is($I0, 0xCD, 'unaligned struct second byte') +.end + +.sub 'test_union' + $P0 = new ['FixedIntegerArray'], 4 + $P0[0] = .DATATYPE_UNION + $P0[1] = 2 + $P0[2] = .DATATYPE_UINT + $P0[3] = .DATATYPE_UCHAR + + .local pmc sv, buf + sv = new ['StructView'], $P0 + buf = sv.'alloc'() + + sv[buf; 0] = 0xFEDC + $I0 = sv[buf; 1] + $I1 = $I0 == 0xFE + $I2 = $I0 == 0xDC + $I0 = $I1 || $I2 + ok($I0, 'union { short s; char c; }') +.end + +.sub 'test_fp' + $P0 = new ['FixedIntegerArray'], 5 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 3 + $P0[2] = .DATATYPE_FLOAT + $P0[3] = .DATATYPE_DOUBLE + $P0[4] = .DATATYPE_FLOATVAL + + .local pmc sv, buf + sv = new ['StructView'], $P0 + buf = sv.'alloc'() + + $N0 = 2.41241 + sv[buf; 0] = $N0 + sv[buf; 1] = $N0 + sv[buf; 2] = $N0 + + $N1 = sv[buf; 0] + $I0 = fp_like($N0, $N1, 0.0001) + ok($I0, 'float roundtrip') + $N1 = sv[buf; 1] + $I0 = fp_like($N0, $N1, 0.000001) + ok($I0, 'double roundtrip') + $N1 = sv[buf; 2] + $I0 = fp_like($N0, $N1, 0.000001) + ok($I0, 'floatval roundtrip') +.end + +.sub 'fp_like' + .param num n1 + .param num n2 + .param num eps + $N0 = n1 - n2 + $N0 = abs $N0 + $I0 = eps > $N0 + .return ($I0) +.end + +# Local Variables: +# mode: pir +# fill-column: 100 +# End: +# vim: expandtab shiftwidth=4 ft=pir: From 15e98d650c99672c545b136ddb5137247a41367a Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Sun, 20 Feb 2011 23:20:09 -0500 Subject: [PATCH 10/27] add support for explicitly sized types to StructView --- src/pmc/structview.pmc | 105 +++++++++++++++++++++++++---------------- t/pmc/structview.t | 60 ++++++++++++++++++++++- 2 files changed, 124 insertions(+), 41 deletions(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 7be1520c4e..f1a42bd579 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -145,6 +145,12 @@ pmclass StructView auto_attrs { case enum_type_long: #if HAS_LONGLONG case enum_type_longlong: +#endif + case enum_type_int8: + case enum_type_int16: + case enum_type_int32: +#if HAS_64BIT + case enum_type_int64: #endif case enum_type_uchar: case enum_type_ushort: @@ -153,6 +159,13 @@ pmclass StructView auto_attrs { #if HAS_LONGLONG case enum_type_ulonglong: #endif + case enum_type_uint8: + case enum_type_uint16: + case enum_type_uint32: +#if HAS_64BIT + case enum_type_uint64: +#endif + elt_access = int_access; break; @@ -187,20 +200,6 @@ pmclass StructView auto_attrs { elt_access = pmc_access; break; - /* TODO: explicitly sized type support */ - case enum_type_int8: - case enum_type_int16: - case enum_type_int32: -#if HAS_64BIT - case enum_type_int64: -#endif - case enum_type_uint8: - case enum_type_uint16: - case enum_type_uint32: -#if HAS_64BIT - case enum_type_uint64: -#endif - /* locally unsupported types */ #if !HAS_LONGLONG case enum_type_longlong: @@ -281,6 +280,12 @@ pmclass StructView auto_attrs { case enum_type_ulong: #if HAS_LONGLONG case enum_type_ulonglong: +#endif + case enum_type_uint8: + case enum_type_uint16: + case enum_type_uint32: +#if HAS_64BIT + case enum_type_uint64: #endif elt->access = unaligned_access; break; @@ -321,22 +326,32 @@ pmclass StructView auto_attrs { switch (elts[i].access) { case int_access: switch (elts[i].type) { -#define _CASE_RET(type, name) \ +#define CASE_RET2(type, name) \ case enum_type_ ## name: return *(type *)ptr; -#define CASE_RET(type) \ - _CASE_RET(type, type) \ - _CASE_RET(unsigned type, u ## type) - _CASE_RET(INTVAL, INTVAL) - CASE_RET(char); - CASE_RET(short); - CASE_RET(int); - CASE_RET(long); +#define CASE_RET1(type) \ + CASE_RET2(type, type) \ + CASE_RET2(unsigned type, u ## type) + CASE_RET2(INTVAL, INTVAL) + CASE_RET1(char); + CASE_RET1(short); + CASE_RET1(int); + CASE_RET1(long); #if HAS_LONGLONG - _CASE_RET(long long, longlong); - _CASE_RET(unsigned long long, ulonglong); + CASE_RET2(long long, longlong); + CASE_RET2(unsigned long long, ulonglong); #endif -#undef CASE_RET -#undef _CASE_RET + CASE_RET2(Parrot_Int1, int8); + CASE_RET2(Parrot_UInt1, uint8); + CASE_RET2(Parrot_Int2, int16); + CASE_RET2(Parrot_UInt2, uint16); + CASE_RET2(Parrot_Int4, int32); + CASE_RET2(Parrot_UInt4, uint32); +#if HAS_64BIT + CASE_RET2(Parrot_Int8, int64); + CASE_RET2(Parrot_UInt8, uint64); +#endif +#undef CASE_RET1 +#undef CASE_RET2 } break; case unaligned_access: @@ -390,22 +405,32 @@ pmclass StructView auto_attrs { switch (elts[i].access) { case int_access: switch (elts[i].type) { -#define _CASE_SET(type, name) \ +#define CASE_SET2(type, name) \ case enum_type_ ## name: *(type *)ptr = x; return; -#define CASE_SET(type) \ - _CASE_SET(type, type) \ - _CASE_SET(unsigned type, u ## type) - _CASE_SET(INTVAL, INTVAL) - CASE_SET(char); - CASE_SET(short); - CASE_SET(int); - CASE_SET(long); +#define CASE_SET1(type) \ + CASE_SET2(type, type) \ + CASE_SET2(unsigned type, u ## type) + CASE_SET2(INTVAL, INTVAL) + CASE_SET1(char); + CASE_SET1(short); + CASE_SET1(int); + CASE_SET1(long); #if HAS_LONGLONG - _CASE_SET(long long, longlong); - _CASE_SET(unsigned long long, ulonglong); + CASE_SET2(long long, longlong); + CASE_SET2(unsigned long long, ulonglong); +#endif + CASE_SET2(Parrot_Int1, int8); + CASE_SET2(Parrot_UInt1, uint8); + CASE_SET2(Parrot_Int2, int16); + CASE_SET2(Parrot_UInt2, uint16); + CASE_SET2(Parrot_Int4, int32); + CASE_SET2(Parrot_UInt4, uint32); +#if HAS_64BIT + CASE_SET2(Parrot_Int8, int64); + CASE_SET2(Parrot_UInt8, uint64); #endif -#undef CASE_SET -#undef _CASE_SET +#undef CASE_SET1 +#undef CASE_SET2 } break; case unaligned_access: diff --git a/t/pmc/structview.t b/t/pmc/structview.t index 5ce3884851..c9f45515a8 100644 --- a/t/pmc/structview.t +++ b/t/pmc/structview.t @@ -6,12 +6,14 @@ .sub 'main' :main .include 'test_more.pir' - plan(11) + plan(16) test_bit_struct() test_unaligned_struct() test_union() test_fp() + test_explicit_sized_types() + test_struct_pad() .end .sub test_bit_struct @@ -150,6 +152,62 @@ .return ($I0) .end +.sub 'test_explicit_sized_types' + $P0 = new ['FixedPMCArray'], 3 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 1 + $P0[2] = .DATATYPE_INT8 + + .local pmc sv + sv = new ['StructView'], $P0 + $I0 = sv.'size'() + is($I0, 1, 'sizeof (struct { int8 c; })') + + $P0[2] = .DATATYPE_UINT16 + sv = new ['StructView'], $P0 + $I0 = sv.'size'() + is($I0, 2, 'sizeof (struct { uint16 s; })') + + $P0[2] = .DATATYPE_UINT32 + sv = new ['StructView'], $P0 + $I0 = sv.'size'() + is($I0, 4, 'sizeof (struct { int32 i; })') +.end + +.sub 'test_struct_pad' + $P0 = new ['FixedIntegerArray'], 5 + $P0[0] = .DATATYPE_STRUCT + $P0[1] = 3 + $P0[2] = .DATATYPE_INT8 + $P0[3] = .DATATYPE_INT32 + $P0[4] = .DATATYPE_INT8 + + .local pmc sv, sv2 + sv = new ['StructView'], $P0 + + $P0[1] = 1 + $P0[2] = .DATATYPE_INT8 + sv2 = new ['StructView'], $P0 + $I0 = sv2.'size'() + + $P0[1] = 1 + $P0[2] = .DATATYPE_INT32 + sv2 = new ['StructView'], $P0 + $I1 = sv2.'size'() + + $I0 *= 2 + $I0 += $I1 + + $I1 = sv.'size'() + + $I2 = $I1 > $I0 + ok($I2, 'sizeof poorly aligned struct greater than the sum of the sizes') + + $I0 = sv.'aligned_size'() + $I2 = $I0 > $I1 + ok($I2, 'aligned size of poorly aligned struct greater than size') +.end + # Local Variables: # mode: pir # fill-column: 100 From d3937253dbf70354050a0a9b38d4959ee2c29c58 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Sun, 20 Feb 2011 23:27:41 -0500 Subject: [PATCH 11/27] flag StructView as not possible to init() (only init_pmc() is supported) --- t/pmc/pmc.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/pmc/pmc.t b/t/pmc/pmc.t index 7f49d6819d..7fd393e7ed 100644 --- a/t/pmc/pmc.t +++ b/t/pmc/pmc.t @@ -52,7 +52,7 @@ my %types_we_cant_test = map { $_ => 1; } ( # These require initializers. qw(default Null Iterator ArrayIterator HashIterator StringIterator OrderedHashIterator Enumerate ParrotObject ParrotThread BigInt LexInfo - LexPad Object Handle Opcode OpLib), + LexPad Object Handle Opcode OpLib StructView), # Instances of these appear to have other types. qw(PMCProxy Class) ); From 761c9a95d35ad828b99aed4244e1348694b99ec3 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 10:51:44 -0500 Subject: [PATCH 12/27] expand macro-argument type loophole to include ALIGN_OF --- t/codingstd/c_macro_args.t | 1 + 1 file changed, 1 insertion(+) diff --git a/t/codingstd/c_macro_args.t b/t/codingstd/c_macro_args.t index c50602c709..0dbf5e17ee 100644 --- a/t/codingstd/c_macro_args.t +++ b/t/codingstd/c_macro_args.t @@ -76,6 +76,7 @@ sub check_macro_args { # eliminate args used as types $definition =~ s/\Q$arg\E[ ]+\*//g; + $definition =~ s/((?:struct|union)\s+\{(?:[^}]+;\s+)*)\Q$arg\E/$1/g; # eliminate all function argument instrumentation macros next if $definition =~ m/\*@[\w ]+@\*/; From 2ab64cf3abd74df5178e069e1f0250f2c724a56c Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 10:53:35 -0500 Subject: [PATCH 13/27] [codingstd] c_indent --- include/parrot/datatypes.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index 1c9cc96584..edcc261d4c 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -91,31 +91,31 @@ const struct _data_types data_types[] = { { "short", sizeof (short), ALIGNOF(short) }, { "int", sizeof (int), ALIGNOF(int) }, { "long", sizeof (long), ALIGNOF(long) }, -#if HAS_LONGLONG +# if HAS_LONGLONG { "longlong", sizeof (long long), ALIGNOF(long long) }, -#else +# else { "longlong", 0, 0 }, -#endif +# endif /* native unsigned types */ { "uchar", sizeof (unsigned char), ALIGNOF(unsigned char) }, { "ushort", sizeof (unsigned short), ALIGNOF(unsigned short) }, { "uint", sizeof (unsigned int), ALIGNOF(unsigned int) }, { "ulong", sizeof (unsigned long), ALIGNOF(unsigned long) }, -#if HAS_LONGLONG +# if HAS_LONGLONG { "ulonglong", sizeof (unsigned long long), ALIGNOF(unsigned long long) }, -#else +# else { "ulonglong", 0, 0 }, -#endif +# endif /* native float types */ { "float", sizeof (float), ALIGNOF(float) }, { "double", sizeof (double), ALIGNOF(double) }, -#if HAS_LONGDOUBLE +# if HAS_LONGDOUBLE { "longdouble", sizeof (long double), ALIGNOF(long double)}, -#else +# else { "longdouble", 0, 0 }, -#endif +# endif /* explicitly sized integer types */ { "int8", 1, ALIGNOF(int /* TODO */) }, From c264306ed97cf62dbd3caf725945c0e3f0bd59d2 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 10:55:24 -0500 Subject: [PATCH 14/27] [codingstd] trailing_space --- include/parrot/datatypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/parrot/datatypes.h b/include/parrot/datatypes.h index edcc261d4c..6a841c772f 100644 --- a/include/parrot/datatypes.h +++ b/include/parrot/datatypes.h @@ -48,7 +48,7 @@ typedef enum { enum_type_int32, enum_type_int64, - enum_type_bit, + enum_type_bit, enum_type_uint1 = enum_type_bit, enum_type_uint4, enum_type_uint8, /* unsigned variants */ From 55c4db22d0f3c9d02f39d19a77347feceacaab57 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 11:05:42 -0500 Subject: [PATCH 15/27] mk_manifest_and_skip --- MANIFEST | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/MANIFEST b/MANIFEST index de45a10179..ce069858e4 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1385,6 +1385,9 @@ src/pmc/parrotthread.pmc [] src/pmc/pmc.num [] src/pmc/pmcproxy.pmc [] src/pmc/pointer.pmc [] +src/pmc/ptr.pmc [] +src/pmc/ptrbuf.pmc [] +src/pmc/ptrobj.pmc [] src/pmc/resizablebooleanarray.pmc [] src/pmc/resizablefloatarray.pmc [] src/pmc/resizableintegerarray.pmc [] @@ -1400,6 +1403,7 @@ src/pmc/string.pmc [] src/pmc/stringbuilder.pmc [] src/pmc/stringhandle.pmc [] src/pmc/stringiterator.pmc [] +src/pmc/structview.pmc [] src/pmc/sub.pmc [] src/pmc/task.pmc [] src/pmc/threadinterpreter.pmc [] @@ -1916,6 +1920,7 @@ t/pmc/string.t [test] t/pmc/stringbuilder.t [test] t/pmc/stringhandle.t [test] t/pmc/stringiterator.t [test] +t/pmc/structview.t [test] t/pmc/sub.t [test] t/pmc/sys.t [test] t/pmc/task.t [test] From 2ac830f0fe10bcddffa693d25a0b03e7155d8270 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 11:13:04 -0500 Subject: [PATCH 16/27] add newly created PMCs to installation list --- MANIFEST.generated | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MANIFEST.generated b/MANIFEST.generated index 251edbe57a..4adbfa7ce4 100644 --- a/MANIFEST.generated +++ b/MANIFEST.generated @@ -104,6 +104,9 @@ include/pmc/pmc_parrotlibrary.h [devel]include include/pmc/pmc_parrotthread.h [devel]include include/pmc/pmc_pmcproxy.h [devel]include include/pmc/pmc_pointer.h [devel]include +include/pmc/pmc_ptr.h [devel]include +include/pmc/pmc_ptrbuf.h [devel]include +include/pmc/pmc_ptrobj.h [devel]include include/pmc/pmc_resizablebooleanarray.h [devel]include include/pmc/pmc_resizablefloatarray.h [devel]include include/pmc/pmc_resizableintegerarray.h [devel]include @@ -119,6 +122,7 @@ include/pmc/pmc_string.h [devel]include include/pmc/pmc_stringbuilder.h [devel]include include/pmc/pmc_stringhandle.h [devel]include include/pmc/pmc_stringiterator.h [devel]include +include/pmc/pmc_structview.h [devel]include include/pmc/pmc_sub.h [devel]include include/pmc/pmc_task.h [devel]include include/pmc/pmc_threadinterpreter.h [devel]include @@ -406,6 +410,9 @@ src/pmc/parrotlibrary.dump [devel]src src/pmc/parrotthread.dump [devel]src src/pmc/pmcproxy.dump [devel]src src/pmc/pointer.dump [devel]src +src/pmc/ptr.dump [devel]src +src/pmc/ptrbuf.dump [devel]src +src/pmc/ptrobj.dump [devel]src src/pmc/resizablebooleanarray.dump [devel]src src/pmc/resizablefloatarray.dump [devel]src src/pmc/resizableintegerarray.dump [devel]src @@ -421,6 +428,7 @@ src/pmc/string.dump [devel]src src/pmc/stringbuilder.dump [devel]src src/pmc/stringhandle.dump [devel]src src/pmc/stringiterator.dump [devel]src +src/pmc/structview.dump [devel]src src/pmc/sub.dump [devel]src src/pmc/task.dump [devel]src src/pmc/threadinterpreter.dump [devel]src From af7885367a0fe431a5dc95c87ec97b7bad212327 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 17:35:45 -0500 Subject: [PATCH 17/27] add documentation for StructView --- src/pmc/structview.pmc | 186 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 185 insertions(+), 1 deletion(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index f1a42bd579..a6c55a54cc 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -9,7 +9,12 @@ src/pmc/structview.pmc - C struct view for pointers. PMC class to view pointers as C Cs. This includes read, write, allocate, and deallocate operations. Bounds checking is implemented where the pointer -class supports a bound. +class supports a bound. Recursive definition through nesting is not supported +but can be emulated by interpreting pointer or buffer elements as structs once +dereferenced. + +Elements are get/set using keyed access of the form C<[Ptr; Idx]>, which will +interpret the C PMC and lookup the C'th element. =head2 Vtables and Methods @@ -74,12 +79,86 @@ pmclass StructView auto_attrs { ATTR size_t align; ATTR size_t size; +/* + +=item C + +Creating an instance without an initializer is dissallowed and will throw an +exception. + +=cut + +*/ + VTABLE void init() { Parrot_ex_throw_from_c_args(INTERP, NULL, 0, "Meaningless creation of %Ss without initializer", SELF->vtable->whoami); } +/* + +=item C + +Create a new StructView for viewing buffers as described by the initializer. + +An initializer is an array-aggregate of integers. For example, +C will work for this purpose. + +The first elemnt of the initializer is interpreted as the type of the +C. There are three supported types of view: struct, indicated with +the C flag; union, indicated with the C flag; +and custom, indicated with the C flag. + +The second element of the initializer is interpreted as the number of elements +contained within the view. + +If using a custom view, the third and fourth elements are interpreted as the +size and alignment in bytes respectively. + +The remainder of the initializer is interpreted as a description of the +elements of the view. For struct and union views, elements are described +by a single integer flag from C, with layout being determined +automatically identical to what your C compiler would have done. For custom +views, elements are represented by a 3-tuple of +C<{type, byte-offset, bit-offset}>, which can be used for arbitrary layouts. +Note, however, that unaligned access is only supported on unsigned integers, +and even then, it is inefficient. You have been warned. + +Supported element types are include: + +=over 4 + +=item Parrot Types + +C, C, C, and C + +=item C-Native Types + +Integer: C, C, C, C, C, C, C, +C, C (*), and C (*) +Float: C, C, C (**) +PMC: data pointer (C), function pointer (C), buffer (C) (***) + +(*) Only available if your C system sports a C type. + +(**) Only available if your C system sports a C type. + +(***) Requires 2 additional following parameters - buffer size and alignment. + +=item Explicitly Sized Types + +C (also known as C), C, C, C, C, +C, C, C, C(*), and C(*) + +(*) Only available if your C system sports a 64 bit integer type. + +=back + +=cut + +*/ + VTABLE void init_pmc(PMC *p) { INTVAL init_len = VTABLE_elements(INTERP, p); PARROT_DATA_TYPE pack_type = VTABLE_get_integer_keyed_int(INTERP, p, 0); @@ -315,12 +394,34 @@ pmclass StructView auto_attrs { SET_ATTR_size(INTERP, SELF, size); } +/* + +=item C + +Free internal offsets array. + +=cut + +*/ + VTABLE void destroy() { elt_desc_t *elts; GET_ATTR_elts(INTERP, SELF, elts); mem_gc_free(INTERP, elts); } +/* + +=item C + +=item C + +Get/Set an integer-type element from a struct-pointer PMC. + +=cut + +*/ + VTABLE INTVAL get_integer_keyed(PMC *k) { BEGIN_KEYED(INTERP, SELF, k) switch (elts[i].access) { @@ -485,6 +586,21 @@ pmclass StructView auto_attrs { } } +/* + +=item C + +=item C + +Get/Set a float-like element from a struct-pointer PMC. + +=cut + +*/ + + +*/ + VTABLE FLOATVAL get_number_keyed(PMC *k) { BEGIN_KEYED(INTERP, SELF, k) switch (elts[i].access) { @@ -535,6 +651,18 @@ pmclass StructView auto_attrs { } } +/* + +=item C + +=item C + +Get/Set a string element from a struct-pointer PMC. + +=cut + +*/ + VTABLE STRING *get_string_keyed(PMC *k) { BEGIN_KEYED(INTERP, SELF, k) switch (elts[i].access) { @@ -566,6 +694,19 @@ pmclass StructView auto_attrs { } } +/* + +=item C + +=item C + +Get/Set a PMC-like element from a struct-pointer PMC or box/unbox values from +any other type of element. + +=cut + +*/ + VTABLE PMC *get_pmc_keyed(PMC *k) { BEGIN_KEYED(INTERP, SELF, k) switch (elts[i].access) { @@ -639,6 +780,18 @@ pmclass StructView auto_attrs { } } +/* + +=item C + +=item C + +Get the size (in bytes) required for one instance. + +=cut + +*/ + VTABLE INTVAL get_integer() { size_t size; GET_ATTR_size(INTERP, SELF, size); @@ -651,12 +804,33 @@ pmclass StructView auto_attrs { RETURN (INTVAL size); } +/* + +=item C + +Get the alignment (in bytes) required for an instance. + +=cut + +*/ + METHOD align() { size_t align; GET_ATTR_align(INTERP, SELF, align); RETURN (INTVAL align); } +/* + +=item C + +Get the size of one instance plus the pad bytes to align a subsequent +instance. + +=cut + +*/ + METHOD aligned_size() { size_t size, align; INTVAL ret; @@ -666,6 +840,16 @@ pmclass StructView auto_attrs { RETURN (INTVAL ret); } +/* + +=item C + +Allocate an instance, or an array of instances when C has been provided. + +=cut + +*/ + METHOD alloc(INTVAL n :optional, int has_n :opt_flag) { size_t size, align; PMC *ret; From 572a1e4d03bb8257ade60f1e90853ff603b957e0 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 17:37:42 -0500 Subject: [PATCH 18/27] [codingstd] c_struct --- src/pmc/structview.pmc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index a6c55a54cc..3e0b5312ce 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -35,7 +35,7 @@ typedef enum { pmc_access } elt_access_t; -typedef struct { +typedef struct elt_desc_t { elt_access_t access; PARROT_DATA_TYPE type; size_t byte_offset; From f42c67d7cf5a3dd8b7cdcfa8a601b3911ba6a2a2 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 17:40:33 -0500 Subject: [PATCH 19/27] [codingstd] tabs --- src/pmc/ptr.pmc | 46 ++++++++++++++++++++++---------------------- src/pmc/ptrobj.pmc | 48 +++++++++++++++++++++++----------------------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/pmc/ptr.pmc b/src/pmc/ptr.pmc index 6ecc1a9134..658d970063 100644 --- a/src/pmc/ptr.pmc +++ b/src/pmc/ptr.pmc @@ -69,22 +69,22 @@ C with a value from an existing pointer-ish PMC. */ VTABLE void init() { - if (PTR_FAT_TEST(INTERP, SELF) && !PMC_data(SELF)) { - PMC_data(SELF) = (void *)mem_gc_allocate_zeroed_typed(INTERP, Parrot_Ptr_attributes); - PObj_custom_destroy_SET(SELF); - } + if (PTR_FAT_TEST(INTERP, SELF) && !PMC_data(SELF)) { + PMC_data(SELF) = (void *)mem_gc_allocate_zeroed_typed(INTERP, Parrot_Ptr_attributes); + PObj_custom_destroy_SET(SELF); + } } VTABLE void init_int(INTVAL i) { - void *ptr = (void *)i; - SELF.init(); - STATICSELF.set_pointer(ptr); + void *ptr = (void *)i; + SELF.init(); + STATICSELF.set_pointer(ptr); } VTABLE void init_pmc(PMC *p) { - void *ptr = VTABLE_get_pointer(INTERP, p); - SELF.init(); - STATICSELF.set_pointer(ptr); + void *ptr = VTABLE_get_pointer(INTERP, p); + SELF.init(); + STATICSELF.set_pointer(ptr); } /* @@ -100,19 +100,19 @@ Get and set the pointer value. */ VTABLE void *get_pointer() { - void *ptr; - if (PTR_FAT_TEST(INTERP, SELF)) - GET_ATTR_ptr(INTERP, SELF, ptr); - else - ptr = PMC_data(SELF); - return ptr; + void *ptr; + if (PTR_FAT_TEST(INTERP, SELF)) + GET_ATTR_ptr(INTERP, SELF, ptr); + else + ptr = PMC_data(SELF); + return ptr; } VTABLE void set_pointer(void *ptr) { - if (PTR_FAT_TEST(INTERP, SELF)) - SET_ATTR_ptr(INTERP, SELF, ptr); - else - PMC_data(SELF) = ptr; + if (PTR_FAT_TEST(INTERP, SELF)) + SET_ATTR_ptr(INTERP, SELF, ptr); + else + PMC_data(SELF) = ptr; } /* @@ -126,7 +126,7 @@ Boolean value of the pointer. Non-C is true, following in the C tradition. */ VTABLE INTVAL get_bool() { - return STATICSELF.get_pointer() != NULL; + return STATICSELF.get_pointer() != NULL; } /* @@ -140,8 +140,8 @@ Manage attribute deallocation for C representation. */ VTABLE void destroy() { - if (PTR_FAT_TEST(INTERP, SELF) && PMC_data(SELF)) - mem_gc_free(INTERP, PMC_data(SELF)); + if (PTR_FAT_TEST(INTERP, SELF) && PMC_data(SELF)) + mem_gc_free(INTERP, PMC_data(SELF)); } } diff --git a/src/pmc/ptrobj.pmc b/src/pmc/ptrobj.pmc index 4c32cb28cb..5140f5112a 100644 --- a/src/pmc/ptrobj.pmc +++ b/src/pmc/ptrobj.pmc @@ -29,17 +29,17 @@ typedef void (*ptrobj_destroy_func_t)(PARROT_INTERP, PMC *, void *); #define PTROBJ_SET_MARK(i, p, m) do { \ SETATTR_PtrObj_mark((i), (p), (m)); \ if (m) \ - PObj_custom_mark_SET(p); \ + PObj_custom_mark_SET(p); \ else \ - PObj_custom_mark_CLEAR(p); \ + PObj_custom_mark_CLEAR(p); \ } while (0) #define PTROBJ_SET_DESTROY(i, p, d) do { \ SETATTR_PtrObj_destroy((i), (p), (d)); \ if (d) \ - PObj_custom_destroy_SET(p); \ + PObj_custom_destroy_SET(p); \ else \ - PObj_custom_destroy_CLEAR(p); \ + PObj_custom_destroy_CLEAR(p); \ } while (0) END_PMC_HEADER_PREAMBLE @@ -64,14 +64,14 @@ Get or set the custom C function. VTABLE PMC *clone() { - void *ptr; - ptrobj_clone_func_t clone; - GET_ATTR_ptr(INTERP, SELF, ptr); - GET_ATTR_clone(INTERP, SELF, clone); - if (clone) - return clone(INTERP, SELF, ptr); - else - Parrot_ex_throw_from_c_args(INTERP, NULL, 0, + void *ptr; + ptrobj_clone_func_t clone; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_clone(INTERP, SELF, clone); + if (clone) + return clone(INTERP, SELF, ptr); + else + Parrot_ex_throw_from_c_args(INTERP, NULL, 0, "clone not implemented for PtrObj %x", ptr); } @@ -104,13 +104,13 @@ Get or set the custom C function. */ VTABLE void mark() { - void *ptr; - ptrobj_mark_func_t mark; - GET_ATTR_ptr(INTERP, SELF, ptr); - GET_ATTR_mark(INTERP, SELF, mark); + void *ptr; + ptrobj_mark_func_t mark; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_mark(INTERP, SELF, mark); /* invariant: custom mark flag only set when a custom mark function has been provided */ - PARROT_ASSERT(mark); - mark(INTERP, SELF, ptr); + PARROT_ASSERT(mark); + mark(INTERP, SELF, ptr); } METHOD mark_func(PMC *func :optional, INTVAL has_func :opt_flag) { @@ -142,13 +142,13 @@ Get or set the custom C function. */ VTABLE void destroy() { - void *ptr; - ptrobj_destroy_func_t destroy; - GET_ATTR_ptr(INTERP, SELF, ptr); - GET_ATTR_destroy(INTERP, SELF, destroy); + void *ptr; + ptrobj_destroy_func_t destroy; + GET_ATTR_ptr(INTERP, SELF, ptr); + GET_ATTR_destroy(INTERP, SELF, destroy); /* invariant: custom destroy flag only set when a destroy function has been provided */ - PARROT_ASSERT(destroy); - destroy(INTERP, SELF, ptr); + PARROT_ASSERT(destroy); + destroy(INTERP, SELF, ptr); } METHOD destroy_func(PMC *func :optional, INTVAL has_func :opt_flag) { From a4d4bdd726d748ff8c01896314831b21034ad333 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 18:13:03 -0500 Subject: [PATCH 20/27] [codingstd] c_parens --- src/pmc/ptrobj.pmc | 12 ++++++------ src/pmc/structview.pmc | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/pmc/ptrobj.pmc b/src/pmc/ptrobj.pmc index 5140f5112a..db25ee4064 100644 --- a/src/pmc/ptrobj.pmc +++ b/src/pmc/ptrobj.pmc @@ -79,13 +79,13 @@ Get or set the custom C function. if (has_func) { void *f = VTABLE_get_pointer(INTERP, func); PTROBJ_SET_CLONE(INTERP, SELF, (ptrobj_clone_func_t)f); - RETURN (); + RETURN(); } else { ptrobj_clone_func_t f; GET_ATTR_clone(INTERP, SELF, f); func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); - RETURN (PMC func); + RETURN(PMC func); } } @@ -117,13 +117,13 @@ Get or set the custom C function. if (has_func) { void *f = VTABLE_get_pointer(INTERP, func); PTROBJ_SET_MARK(INTERP, SELF, (ptrobj_clone_func_t)f); - RETURN (); + RETURN(); } else { ptrobj_mark_func_t f; GET_ATTR_mark(INTERP, SELF, f); func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); - RETURN (PMC func); + RETURN(PMC func); } } @@ -155,13 +155,13 @@ Get or set the custom C function. if (has_func) { void *f = VTABLE_get_pointer(INTERP, func); PTROBJ_SET_DESTROY(INTERP, SELF, (ptrobj_clone_func_t)f); - RETURN (); + RETURN(); } else { ptrobj_destroy_func_t f; GET_ATTR_destroy(INTERP, SELF, f); func = Parrot_pmc_new_init_int(INTERP, enum_class_Ptr, (INTVAL)f); - RETURN (PMC func); + RETURN(PMC func); } } } diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 3e0b5312ce..79f6a5cc0a 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -801,7 +801,7 @@ Get the size (in bytes) required for one instance. METHOD size() { size_t size; GET_ATTR_size(INTERP, SELF, size); - RETURN (INTVAL size); + RETURN(INTVAL size); } /* @@ -817,7 +817,7 @@ Get the alignment (in bytes) required for an instance. METHOD align() { size_t align; GET_ATTR_align(INTERP, SELF, align); - RETURN (INTVAL align); + RETURN(INTVAL align); } /* @@ -837,7 +837,7 @@ instance. GET_ATTR_size(INTERP, SELF, size); GET_ATTR_align(INTERP, SELF, align); ret = ALIGN_UP(size, align); - RETURN (INTVAL ret); + RETURN(INTVAL ret); } /* @@ -866,7 +866,7 @@ Allocate an instance, or an array of instances when C has been provided. ret = Parrot_pmc_new_init_int(INTERP, enum_class_PtrObj, (INTVAL)buf); SETATTR_PtrObj_destroy(INTERP, ret, deallocate_ptrobj); - RETURN (PMC ret); + RETURN(PMC ret); } } From ceb741c40bb769b019e175c8ff10c7989233a517 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 18:14:52 -0500 Subject: [PATCH 21/27] [codingstd] trailing_space --- src/pmc/structview.pmc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 79f6a5cc0a..7a7ba47a1c 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -214,7 +214,7 @@ C, C, C, C(*), and C(*) elt->type = elt_type; elt_size = data_types[elt_type - enum_first_type].size; elt_align = data_types[elt_type - enum_first_type].align; - + switch (elt_type) { /* aligned integer types */ case enum_type_INTVAL: From fbf595a86d5edd7f28ae1f35a52eb0c3151630ad Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 20:14:56 -0500 Subject: [PATCH 22/27] ignore begin/end pmc header preamble statements --- lib/Parrot/Headerizer.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Parrot/Headerizer.pm b/lib/Parrot/Headerizer.pm index 11e1a8b2f2..b119fd0d0e 100644 --- a/lib/Parrot/Headerizer.pm +++ b/lib/Parrot/Headerizer.pm @@ -245,6 +245,10 @@ sub extract_function_declarations { # Drop all text after HEADERIZER STOP $text =~ s{/\*\s*HEADERIZER STOP.+}{}s; + # Drop begin/end PMC HEADER sections + $text =~ s{BEGIN_PMC_HEADER_PREAMBLE}{}sx; + $text =~ s{END_PMC_HEADER_PREAMBLE}{}sx; + # Strip blocks of comments $text =~ s{^/\*.*?\*/}{}mxsg; From ab9ce3779edca7e7b150fe8f59f25f1a5ac448fc Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Mon, 21 Feb 2011 20:39:23 -0500 Subject: [PATCH 23/27] [codingstd] pmc_docs --- src/pmc/structview.pmc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 7a7ba47a1c..5bc0543230 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -69,7 +69,18 @@ END_PMC_HEADER_PREAMBLE base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ ptr = ((char *)base_ptr) + elts[i].byte_offset; -static void deallocate_ptrobj(PARROT_INTERP, PMC *obj, void *ptr) { +/* + +=item C + +Deallocation function to be attached to allocated instances. + +=cut + +*/ + +static void +deallocate_ptrobj(PARROT_INTERP, PMC *obj, void *ptr) { mem_sys_free(ptr); } @@ -596,9 +607,6 @@ Get/Set a float-like element from a struct-pointer PMC. =cut -*/ - - */ VTABLE FLOATVAL get_number_keyed(PMC *k) { @@ -874,10 +882,6 @@ Allocate an instance, or an array of instances when C has been provided. =back -=head1 SEE ALSO - -F - =cut */ From a42364c459eb0a09cd4d96c7cb3ca674c7f48bea Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Tue, 22 Feb 2011 11:43:30 -0500 Subject: [PATCH 24/27] skip checkdepend on pmc directories checkdepend doesn't handle inheritance properly, but pmc2c and config/auto/pmc.pm do. --- t/src/checkdepend.t | 3 +++ 1 file changed, 3 insertions(+) diff --git a/t/src/checkdepend.t b/t/src/checkdepend.t index bce34e5825..d7b2f1061f 100644 --- a/t/src/checkdepend.t +++ b/t/src/checkdepend.t @@ -55,6 +55,9 @@ find( { wanted => \&wanted, no_chdir => 1 }, our %deps; foreach my $file (sort grep /\.[hc]$/, @incfiles) { + # skip pmcs - we don't handle inheritance correctly + next if $file =~ m{^src/(?:dyn)?pmc/}; + open my $fh, '<', $file; my $guts; { From be6b94f7577ce567d82fa031d3e8c0bb98071680 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Tue, 22 Feb 2011 19:56:00 -0500 Subject: [PATCH 25/27] implement null, alignment, and bounds checking for StructView --- src/pmc/ptr.pmc | 16 +++++++++++ src/pmc/structview.pmc | 65 +++++++++++++++++++++++++++++------------- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/src/pmc/ptr.pmc b/src/pmc/ptr.pmc index 658d970063..c8ff26e8f2 100644 --- a/src/pmc/ptr.pmc +++ b/src/pmc/ptr.pmc @@ -143,6 +143,22 @@ Manage attribute deallocation for C representation. if (PTR_FAT_TEST(INTERP, SELF) && PMC_data(SELF)) mem_gc_free(INTERP, PMC_data(SELF)); } + +/* + +=item C + +Implement C interface. Specifies length of the buffer. + +In this case, always returns C<0>, indicating undetermined length. + +=cut + +*/ + + VTABLE INTVAL get_integer() { + return 0; + } } /* diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 5bc0543230..289d09bc56 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -9,9 +9,9 @@ src/pmc/structview.pmc - C struct view for pointers. PMC class to view pointers as C Cs. This includes read, write, allocate, and deallocate operations. Bounds checking is implemented where the pointer -class supports a bound. Recursive definition through nesting is not supported -but can be emulated by interpreting pointer or buffer elements as structs once -dereferenced. +class reports a non-zero bound. Recursive definition through nesting is not +supported but can be emulated by interpreting pointer or buffer elements as +structs once dereferenced. Elements are get/set using keyed access of the form C<[Ptr; Idx]>, which will interpret the C PMC and lookup the C'th element. @@ -51,23 +51,48 @@ END_PMC_HEADER_PREAMBLE #define MAX(x, y) ((y) > (x) ? (y) : (x)) -#define BEGIN_KEYED(interp, s, k) \ - size_t n_elts; \ - elt_desc_t *elts; \ - PMC *ptr_pmc; \ - void *ptr, *base_ptr; \ - INTVAL i; \ - GETATTR_StructView_n_elts((interp), (s), n_elts); \ - GETATTR_StructView_elts((interp), (s), elts); \ - ptr_pmc = Parrot_key_pmc((interp), (k)); \ - (k) = Parrot_key_next((interp), (k)); \ - i = Parrot_key_integer((interp), (k)); \ - if (i < 0 || n_elts <= i) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Struct index out of bounds (%d)", \ - i); \ - base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ - ptr = ((char *)base_ptr) + elts[i].byte_offset; +#define BEGIN_KEYED(interp, s, k) \ + size_t n_elts; \ + elt_desc_t *elts; \ + PMC *ptr_pmc; \ + void *ptr, *base_ptr; \ + INTVAL i; \ + GETATTR_StructView_n_elts((interp), (s), n_elts); \ + GETATTR_StructView_elts((interp), (s), elts); \ + ptr_pmc = Parrot_key_pmc((interp), (k)); \ + (k) = Parrot_key_next((interp), (k)); \ + i = Parrot_key_integer((interp), (k)); \ + if (i < 0 || n_elts <= i) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Struct index out of bounds (%d)", \ + i); \ + base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ + ptr = ((char *)base_ptr) + elts[i].byte_offset; \ + /* guard against null pointer dereference */ \ + if (!base_ptr) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to derefrence null pointer"); \ + /* guard against out of bounds access */ \ + { \ + size_t buf_size = VTABLE_get_integer((interp), ptr_pmc); \ + size_t self_size; \ + GETATTR_StructView_size((interp), (s), self_size); \ + if (buf_size && buf_size < self_size) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Buffer length too small for struct " \ + "(at least %d required, got %d)", \ + self_size, buf_size); \ + } \ + /* guard against unaligned access */ \ + { \ + size_t align; \ + GETATTR_StructView_align((interp), (s), align); \ + if (base_ptr != ALIGN_UP(base_ptr - NULL, align)) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to dereference unaligned pointer " \ + "(%x, required alignment: %d)", \ + base_ptr, align); \ + } /* From 3069a312fddeac5b28f922fdf96d6020a8dc7220 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Wed, 23 Feb 2011 10:41:19 -0500 Subject: [PATCH 26/27] fix c++ build --- src/pmc/ptrobj.pmc | 4 +- src/pmc/structview.pmc | 92 +++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/pmc/ptrobj.pmc b/src/pmc/ptrobj.pmc index db25ee4064..e69d7348fc 100644 --- a/src/pmc/ptrobj.pmc +++ b/src/pmc/ptrobj.pmc @@ -116,7 +116,7 @@ Get or set the custom C function. METHOD mark_func(PMC *func :optional, INTVAL has_func :opt_flag) { if (has_func) { void *f = VTABLE_get_pointer(INTERP, func); - PTROBJ_SET_MARK(INTERP, SELF, (ptrobj_clone_func_t)f); + PTROBJ_SET_MARK(INTERP, SELF, (ptrobj_mark_func_t)f); RETURN(); } else { @@ -154,7 +154,7 @@ Get or set the custom C function. METHOD destroy_func(PMC *func :optional, INTVAL has_func :opt_flag) { if (has_func) { void *f = VTABLE_get_pointer(INTERP, func); - PTROBJ_SET_DESTROY(INTERP, SELF, (ptrobj_clone_func_t)f); + PTROBJ_SET_DESTROY(INTERP, SELF, (ptrobj_destroy_func_t)f); RETURN(); } else { diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index 289d09bc56..a06dce502e 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -51,47 +51,47 @@ END_PMC_HEADER_PREAMBLE #define MAX(x, y) ((y) > (x) ? (y) : (x)) -#define BEGIN_KEYED(interp, s, k) \ - size_t n_elts; \ - elt_desc_t *elts; \ - PMC *ptr_pmc; \ - void *ptr, *base_ptr; \ - INTVAL i; \ - GETATTR_StructView_n_elts((interp), (s), n_elts); \ - GETATTR_StructView_elts((interp), (s), elts); \ - ptr_pmc = Parrot_key_pmc((interp), (k)); \ - (k) = Parrot_key_next((interp), (k)); \ - i = Parrot_key_integer((interp), (k)); \ - if (i < 0 || n_elts <= i) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Struct index out of bounds (%d)", \ - i); \ - base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ - ptr = ((char *)base_ptr) + elts[i].byte_offset; \ - /* guard against null pointer dereference */ \ - if (!base_ptr) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Attempt to derefrence null pointer"); \ - /* guard against out of bounds access */ \ - { \ - size_t buf_size = VTABLE_get_integer((interp), ptr_pmc); \ - size_t self_size; \ - GETATTR_StructView_size((interp), (s), self_size); \ - if (buf_size && buf_size < self_size) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Buffer length too small for struct " \ - "(at least %d required, got %d)", \ - self_size, buf_size); \ - } \ - /* guard against unaligned access */ \ - { \ - size_t align; \ - GETATTR_StructView_align((interp), (s), align); \ - if (base_ptr != ALIGN_UP(base_ptr - NULL, align)) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Attempt to dereference unaligned pointer " \ - "(%x, required alignment: %d)", \ - base_ptr, align); \ +#define BEGIN_KEYED(interp, s, k) \ + size_t n_elts; \ + elt_desc_t *elts; \ + PMC *ptr_pmc; \ + void *ptr, *base_ptr; \ + INTVAL i; \ + GETATTR_StructView_n_elts((interp), (s), n_elts); \ + GETATTR_StructView_elts((interp), (s), elts); \ + ptr_pmc = Parrot_key_pmc((interp), (k)); \ + (k) = Parrot_key_next((interp), (k)); \ + i = Parrot_key_integer((interp), (k)); \ + if (i < 0 || n_elts <= i) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Struct index out of bounds (%d)", \ + i); \ + base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ + ptr = ((char *)base_ptr) + elts[i].byte_offset; \ + /* guard against null pointer dereference */ \ + if (!base_ptr) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to derefrence null pointer"); \ + /* guard against out of bounds access */ \ + { \ + size_t buf_size = VTABLE_get_integer((interp), ptr_pmc); \ + size_t self_size; \ + GETATTR_StructView_size((interp), (s), self_size); \ + if (buf_size && buf_size < self_size) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Buffer length too small for struct " \ + "(at least %d required, got %d)", \ + self_size, buf_size); \ + } \ + /* guard against unaligned access */ \ + { \ + size_t align; \ + GETATTR_StructView_align((interp), (s), align); \ + if ((size_t)base_ptr != ALIGN_UP((size_t)base_ptr - NULL, align)) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to dereference unaligned pointer " \ + "(%x, required alignment: %d)", \ + base_ptr, align); \ } /* @@ -197,7 +197,8 @@ C, C, C, C(*), and C(*) VTABLE void init_pmc(PMC *p) { INTVAL init_len = VTABLE_elements(INTERP, p); - PARROT_DATA_TYPE pack_type = VTABLE_get_integer_keyed_int(INTERP, p, 0); + PARROT_DATA_TYPE pack_type = (PARROT_DATA_TYPE) + VTABLE_get_integer_keyed_int(INTERP, p, 0); INTVAL n_elts = VTABLE_get_integer_keyed_int(INTERP, p, 1); elt_desc_t *elt_ary; size_t bit_cursor = 0; @@ -239,7 +240,8 @@ C, C, C, C(*), and C(*) for (/* i already initialized */ j = 0; i < init_len && j < n_elts; i += incr, j++) { elt_desc_t *elt = &elt_ary[j]; - PARROT_DATA_TYPE elt_type = VTABLE_get_integer_keyed_int(INTERP, p, i); + PARROT_DATA_TYPE elt_type = (PARROT_DATA_TYPE) + VTABLE_get_integer_keyed_int(INTERP, p, i); size_t elt_size, elt_align; elt_access_t elt_access; @@ -575,7 +577,7 @@ Get/Set an integer-type element from a struct-pointer PMC. UINTVAL ux = x; size_t bits, n; unsigned char tempc; - unsigned char *cptr = ptr; + unsigned char *cptr = (unsigned char *)ptr; switch (elts[i].type) { case enum_type_uint1: @@ -770,7 +772,7 @@ any other type of element. } } - VTABLE void *set_pmc_keyed(PMC *k, PMC *p) { + VTABLE void set_pmc_keyed(PMC *k, PMC *p) { BEGIN_KEYED(INTERP, SELF, k) switch (elts[i].access) { case int_access: From 0f23cb8e49c7bd7433441c893bdd33e53590b4b9 Mon Sep 17 00:00:00 2001 From: Peter Lobsinger Date: Wed, 23 Feb 2011 12:51:38 -0500 Subject: [PATCH 27/27] fix C build --- src/pmc/structview.pmc | 82 +++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/pmc/structview.pmc b/src/pmc/structview.pmc index a06dce502e..dbfe792a51 100644 --- a/src/pmc/structview.pmc +++ b/src/pmc/structview.pmc @@ -51,47 +51,47 @@ END_PMC_HEADER_PREAMBLE #define MAX(x, y) ((y) > (x) ? (y) : (x)) -#define BEGIN_KEYED(interp, s, k) \ - size_t n_elts; \ - elt_desc_t *elts; \ - PMC *ptr_pmc; \ - void *ptr, *base_ptr; \ - INTVAL i; \ - GETATTR_StructView_n_elts((interp), (s), n_elts); \ - GETATTR_StructView_elts((interp), (s), elts); \ - ptr_pmc = Parrot_key_pmc((interp), (k)); \ - (k) = Parrot_key_next((interp), (k)); \ - i = Parrot_key_integer((interp), (k)); \ - if (i < 0 || n_elts <= i) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Struct index out of bounds (%d)", \ - i); \ - base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ - ptr = ((char *)base_ptr) + elts[i].byte_offset; \ - /* guard against null pointer dereference */ \ - if (!base_ptr) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Attempt to derefrence null pointer"); \ - /* guard against out of bounds access */ \ - { \ - size_t buf_size = VTABLE_get_integer((interp), ptr_pmc); \ - size_t self_size; \ - GETATTR_StructView_size((interp), (s), self_size); \ - if (buf_size && buf_size < self_size) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Buffer length too small for struct " \ - "(at least %d required, got %d)", \ - self_size, buf_size); \ - } \ - /* guard against unaligned access */ \ - { \ - size_t align; \ - GETATTR_StructView_align((interp), (s), align); \ - if ((size_t)base_ptr != ALIGN_UP((size_t)base_ptr - NULL, align)) \ - Parrot_ex_throw_from_c_args((interp), NULL, 0, \ - "Attempt to dereference unaligned pointer " \ - "(%x, required alignment: %d)", \ - base_ptr, align); \ +#define BEGIN_KEYED(interp, s, k) \ + size_t n_elts; \ + elt_desc_t *elts; \ + PMC *ptr_pmc; \ + void *ptr, *base_ptr; \ + INTVAL i; \ + GETATTR_StructView_n_elts((interp), (s), n_elts); \ + GETATTR_StructView_elts((interp), (s), elts); \ + ptr_pmc = Parrot_key_pmc((interp), (k)); \ + (k) = Parrot_key_next((interp), (k)); \ + i = Parrot_key_integer((interp), (k)); \ + if (i < 0 || n_elts <= i) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Struct index out of bounds (%d)", \ + i); \ + base_ptr = VTABLE_get_pointer((interp), ptr_pmc); \ + ptr = ((char *)base_ptr) + elts[i].byte_offset; \ + /* guard against null pointer dereference */ \ + if (!base_ptr) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to derefrence null pointer"); \ + /* guard against out of bounds access */ \ + { \ + size_t buf_size = VTABLE_get_integer((interp), ptr_pmc); \ + size_t self_size; \ + GETATTR_StructView_size((interp), (s), self_size); \ + if (buf_size && buf_size < self_size) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Buffer length too small for struct " \ + "(at least %d required, got %d)", \ + self_size, buf_size); \ + } \ + /* guard against unaligned access */ \ + { \ + size_t align; \ + GETATTR_StructView_align((interp), (s), align); \ + if ((size_t)base_ptr != ALIGN_UP((size_t)base_ptr, align)) \ + Parrot_ex_throw_from_c_args((interp), NULL, 0, \ + "Attempt to dereference unaligned pointer " \ + "(%x, required alignment: %d)", \ + base_ptr, align); \ } /*