Skip to content

Commit

Permalink
use key functions in packfile
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.parrot.org/parrot/trunk@2370 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
leo committed Oct 10, 2002
1 parent 3bed088 commit 3898587
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 95 deletions.
4 changes: 3 additions & 1 deletion include/parrot/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ PMC *key_new_pmc(struct Parrot_Interp *interpreter, PMC *value);

void key_set_integer(struct Parrot_Interp *interpreter, PMC *key, INTVAL value);
void key_set_number(struct Parrot_Interp *interpreter, PMC *key, FLOATVAL value);
void key_set_register(struct Parrot_Interp *interpreter, PMC *key, INTVAL value,
INTVAL flag);
void key_set_string(struct Parrot_Interp *interpreter, PMC *key, STRING *value);
void key_set_pmc(struct Parrot_Interp *interpreter, PMC *key, PMC *value);

Expand All @@ -57,7 +59,7 @@ PMC *key_mark(struct Parrot_Interp *interpreter, PMC *key, PMC *end_of_used_list
* Local variables:
* c-indentation-style: bsd
* c-basic-offset: 4
* indent-tabs-mode: nil
* indent-tabs-mode: nil
* End:
*
* vim: expandtab shiftwidth=4:
Expand Down
11 changes: 11 additions & 0 deletions key.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ key_set_integer(struct Parrot_Interp *interpreter, PMC *key, INTVAL value)
return;
}

void
key_set_register(struct Parrot_Interp *interpreter, PMC *key, INTVAL value,
INTVAL flag)
{
key->flags &= ~KEY_type_FLAGS;
key->flags |= KEY_register_FLAG | flag;
key->cache.int_val = value;

return;
}


void
key_set_number(struct Parrot_Interp *interpreter, PMC *key, FLOATVAL value)
Expand Down
89 changes: 42 additions & 47 deletions packfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ PackFile_new(void)
PackFile_destroy(pf);
return NULL;
}

/* Create fixup table */
pf->fixup_table =
mem_sys_allocate(sizeof(struct PackFile_FixupTable));
Expand Down Expand Up @@ -148,7 +148,7 @@ PackFile_fetch_nv(struct PackFile *pf, opcode_t *stream) {
FLOATVAL f;
if(pf->fetch_nv == NULL) {
#if TRACE_PACKFILE
fprintf(stderr, "PackFile_fetch_nv: Native [%d bytes]..\n",
fprintf(stderr, "PackFile_fetch_nv: Native [%d bytes]..\n",
sizeof(FLOATVAL));
#endif
memcpy(&f, stream, sizeof(FLOATVAL));
Expand Down Expand Up @@ -188,7 +188,7 @@ void PackFile_assign_transforms(struct PackFile *pf) {
pf->header->byteorder, PARROT_BIGENDIAN);
}
# endif
#endif
#endif
}

/***************************************
Expand All @@ -208,7 +208,7 @@ PackFile_destroy(struct PackFile *pf)
fprintf(stderr, "PackFile_destroy: pf == NULL!\n");
return;
}

if (pf->header) {
mem_sys_free(pf->header);
}
Expand Down Expand Up @@ -289,7 +289,7 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
struct PackFile_Header * header = self->header;
opcode_t *cursor;
int i;

if (!self) {
fprintf(stderr, "PackFile_unpack: self == NULL!\n");
return 0;
Expand All @@ -306,12 +306,12 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
if(header->wordsize == 0) {
fprintf(stderr, "PackFile_unpack: Invalid wordsize %d\n",
header->wordsize);
return 0;
return 0;
}
}

PackFile_assign_transforms(self);

#if TRACE_PACKFILE
fprintf(stderr, "wordsize: %d\n", header->wordsize);
fprintf(stderr, "byteorder: %d\n", header->byteorder);
Expand All @@ -321,13 +321,13 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
* FIXME
*/
if(self->need_wordsize) {
fprintf(stderr,
fprintf(stderr,
"PackFile_unpack: Unimplemented wordsize transform.\n");
fprintf(stderr, "File has wordsize: %d (native is %d)\n",
fprintf(stderr, "File has wordsize: %d (native is %d)\n",
header->wordsize, sizeof(opcode_t));
return 0;
}
return 0;
}

/*
* Unpack and verify the magic which is stored byteorder of the file:
*/
Expand All @@ -346,7 +346,7 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
}

header->opcodetype = PackFile_fetch_op(self, cursor++);

#if TRACE_PACKFILE
fprintf(stderr, "PackFile_unpack(): Magic verified.\n");
#endif
Expand All @@ -361,15 +361,15 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
return 0;
}

if (!PackFile_FixupTable_unpack(self->fixup_table, cursor,
if (!PackFile_FixupTable_unpack(self->fixup_table, cursor,
header->fixup_ss)) {
fprintf(stderr,
"PackFile_unpack: Error reading fixup table segment!\n");
return 0;
}

/* Segment size is in bytes */
cursor += header->fixup_ss / sizeof(opcode_t);
cursor += header->fixup_ss / sizeof(opcode_t);

/*
* Unpack the Constant Table Segment:
Expand All @@ -389,7 +389,7 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
}

/* Segment size is in bytes */
cursor += header->const_ss / sizeof(opcode_t);
cursor += header->const_ss / sizeof(opcode_t);

/*
* Unpack the Byte Code Segment:
Expand Down Expand Up @@ -425,9 +425,9 @@ PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
fprintf(stderr, "op[%u]->[%u]\n", *(cursor-1),
self->byte_code[i]);
#endif
}
}
}

}

return ((size_t)(cursor - packed) * sizeof(opcode_t)) == packed_size;
Expand Down Expand Up @@ -684,7 +684,7 @@ PackFile_Constant_destroy(struct PackFile_Constant *self)
=item pack_size
Determine the size of the buffer needed in order to pack the PackFile
Determine the size of the buffer needed in order to pack the PackFile
Constant into a contiguous region of memory.
=cut
Expand Down Expand Up @@ -782,7 +782,7 @@ PackFile_Constant_unpack(struct Parrot_Interp *interpreter,

type = PackFile_fetch_op(pf, cursor++);
size = PackFile_fetch_op(pf, cursor++);

#if TRACE_PACKFILE
printf("PackFile_Constant_unpack(): Type is %ld ('%c')...\n", type,
(char)type);
Expand All @@ -798,7 +798,7 @@ PackFile_Constant_unpack(struct Parrot_Interp *interpreter,
break;

case PFC_STRING:
rc = PackFile_Constant_unpack_string(interpreter, pf, self,
rc = PackFile_Constant_unpack_string(interpreter, pf, self,
cursor, size);
break;

Expand Down Expand Up @@ -832,7 +832,7 @@ Returns one (1) if everything is OK, else zero (0).
***************************************/

INTVAL
PackFile_Constant_unpack_number(struct PackFile * pf,
PackFile_Constant_unpack_number(struct PackFile * pf,
struct PackFile_Constant *self,
opcode_t *packed, opcode_t packed_size)
{
Expand All @@ -844,7 +844,7 @@ PackFile_Constant_unpack_number(struct PackFile * pf,
} f;
int i;
*/
*/
UNUSED(packed_size);

if (!self) {
Expand All @@ -853,18 +853,18 @@ PackFile_Constant_unpack_number(struct PackFile * pf,

cursor = packed;

/* We need to do a memcpy from the packed area to the value
* because we can't guarantee that the packed area (which is
/* We need to do a memcpy from the packed area to the value
* because we can't guarantee that the packed area (which is
* aligned for an opcode_t) is suitably aligned for a FLOATVAL.
* This could be made contingent upon some preprocessor defines
* This could be made contingent upon some preprocessor defines
* determined by Configure.
*/
#if TRACE_PACKFILE
fprintf(stderr,
"FIXME: PackFile_Constant_unpack_number: assuming size of FLOATVAL!\n");
#endif
self->number = PackFile_fetch_nv(pf, (opcode_t *)cursor);

self->type = PFC_NUMBER;
/* self->number = f.value; */

Expand Down Expand Up @@ -931,7 +931,7 @@ PackFile_Constant_unpack_string(struct Parrot_Interp *interpreter,
self->type = PFC_STRING;

self->string = string_make(interpreter, cursor, size,
encoding_lookup_index(encoding),
encoding_lookup_index(encoding),
flags | BUFFER_constant_FLAG,
chartype_lookup_index(type));

Expand Down Expand Up @@ -967,11 +967,11 @@ PackFile_Constant_unpack_key(struct Parrot_Interp *interpreter,

UNUSED(packed_size);

if (!self)
if (!self)
{
return 0;
}

cursor = packed;

components = *cursor++;
Expand All @@ -980,43 +980,38 @@ PackFile_Constant_unpack_key(struct Parrot_Interp *interpreter,

while (components-- > 0) {
if (tail) {
tail->data = pmc_new(interpreter, enum_class_Key);
tail->data = key_new(interpreter);
tail = tail->data;
}
else {
head = tail = pmc_new(interpreter, enum_class_Key);
head = tail = key_new(interpreter);
}

tail->flags |= PMC_constant_FLAG;

switch (*cursor++) {
case PARROT_ARG_IC:
tail->flags |= KEY_integer_FLAG;
tail->cache.int_val = *cursor++;
key_set_integer(interpreter, tail, *cursor++);
break;
case PARROT_ARG_NC:
tail->flags |= KEY_number_FLAG;
tail->cache.num_val = pf->const_table->constants[*cursor++]->number;
key_set_number(interpreter, tail,
pf->const_table->constants[*cursor++]->number);
break;
case PARROT_ARG_SC:
tail->flags |= KEY_string_FLAG;
tail->cache.string_val = pf->const_table->constants[*cursor++]->string;
key_set_string(interpreter, tail,
pf->const_table->constants[*cursor++]->string);
break;
case PARROT_ARG_I:
tail->flags |= KEY_integer_FLAG|KEY_register_FLAG;
tail->cache.int_val = *cursor++;
key_set_register(interpreter, tail, *cursor++, KEY_integer_FLAG);
break;
case PARROT_ARG_N:
tail->flags |= KEY_number_FLAG|KEY_register_FLAG;
tail->cache.int_val = *cursor++;
key_set_register(interpreter, tail, *cursor++, KEY_number_FLAG);
break;
case PARROT_ARG_S:
tail->flags |= KEY_string_FLAG|KEY_register_FLAG;
tail->cache.int_val = *cursor++;
key_set_register(interpreter, tail, *cursor++, KEY_string_FLAG);
break;
case PARROT_ARG_P:
tail->flags |= KEY_pmc_FLAG|KEY_register_FLAG;
tail->cache.int_val = *cursor++;
key_set_register(interpreter, tail, *cursor++, KEY_pmc_FLAG);
break;
default:
return 0;
Expand Down
11 changes: 11 additions & 0 deletions src/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ key_set_integer(struct Parrot_Interp *interpreter, PMC *key, INTVAL value)
return;
}

void
key_set_register(struct Parrot_Interp *interpreter, PMC *key, INTVAL value,
INTVAL flag)
{
key->flags &= ~KEY_type_FLAGS;
key->flags |= KEY_register_FLAG | flag;
key->cache.int_val = value;

return;
}


void
key_set_number(struct Parrot_Interp *interpreter, PMC *key, FLOATVAL value)
Expand Down

0 comments on commit 3898587

Please sign in to comment.