All --
As a first step to moving NV constants out of the byte code stream
and other goodness, I have produced this patch that gets rid of
bytecode.[hc] (for now) and has the interpreter rely on packfile.[hc]
for its bytecode interface.
The packfile.[hc] stuff has been modified a bit in anticipation of
multiple types of constants (NV soon, PV later). It now has a type
field (IV) and a string field (STRING *).
The packing and unpacking of constants has been modified (of course)
to reflect this new structure.
Also, I added 'end' to some of the test cases in t/op/*.t and modified
basic_opcodes.ops to access constants via the new 'code' member of
the Parrot_Interp struct.
I just made clean and test here and things went well. I'd like to get
some feedback from folks on other architectures (I'm on Linux Intel)
so we can know if I've hurt anyone on portability.
Something very much like this is going to be committed soon as part of
our final push for 0.0.2, which requires us to move NVs into the
const_table.
Stay tuned for more...
Regards,
-- Gregor
_____________________________________________________________________
/ perl -e 'srand(-2091643526); print chr rand 90 for (0..4)' \
Gregor N. Purdy [EMAIL PROTECTED]
Focus Research, Inc. http://www.focusresearch.com/
8080 Beckett Center Drive #203 513-860-3570 vox
West Chester, OH 45069 513-860-3579 fax
\_____________________________________________________________________/
? packfile.patch
Index: MANIFEST
===================================================================
RCS file: /home/perlcvs/parrot/MANIFEST,v
retrieving revision 1.21
diff -u -r1.21 MANIFEST
--- MANIFEST 2001/09/25 09:12:57 1.21
+++ MANIFEST 2001/09/25 16:11:15
@@ -15,7 +15,6 @@
assemble.pl
basic_opcodes.ops
build_interp_starter.pl
-bytecode.c
config_h.in
disassemble.pl
docs/opcodes.pod
@@ -26,7 +25,6 @@
docs/vtables.pod
global_setup.c
hints/mswin32.pl
-include/parrot/bytecode.h
include/parrot/events.h
include/parrot/exceptions.h
include/parrot/global_setup.h
Index: Makefile.in
===================================================================
RCS file: /home/perlcvs/parrot/Makefile.in,v
retrieving revision 1.13
diff -u -r1.13 Makefile.in
--- Makefile.in 2001/09/22 17:20:58 1.13
+++ Makefile.in 2001/09/25 16:11:15
@@ -1,9 +1,9 @@
O = ${o}
INC=include/parrot
-H_FILES = $(INC)/config.h $(INC)/exceptions.h $(INC)/io.h $(INC)/op.h
$(INC)/register.h $(INC)/string.h $(INC)/events.h $(INC)/interpreter.h $(INC)/memory.h
$(INC)/parrot.h $(INC)/stacks.h $(INC)/packfile.h $(INC)/bytecode.h
$(INC)/global_setup.h
+H_FILES = $(INC)/config.h $(INC)/exceptions.h $(INC)/io.h $(INC)/op.h
+$(INC)/register.h $(INC)/string.h $(INC)/events.h $(INC)/interpreter.h
+$(INC)/memory.h $(INC)/parrot.h $(INC)/stacks.h $(INC)/packfile.h
+$(INC)/global_setup.h
-O_FILES = global_setup$(O) interpreter$(O) parrot$(O) register$(O) basic_opcodes$(O)
memory$(O) packfile$(O) bytecode$(O) string$(O) strnative$(O)
+O_FILES = global_setup$(O) interpreter$(O) parrot$(O) register$(O) basic_opcodes$(O)
+memory$(O) packfile$(O) string$(O) strnative$(O)
#DO NOT ADD C COMPILER FLAGS HERE
#Add them in Configure.pl--look for the
@@ -48,8 +48,6 @@
interpreter$(O): interpreter.c $(H_FILES) $(INC)/interp_guts.h
memory$(O): $(H_FILES)
-
-bytecode$(O): $(H_FILES)
packfile$(O): $(H_FILES)
Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.24
diff -u -r1.24 basic_opcodes.ops
--- basic_opcodes.ops 2001/09/24 16:27:48 1.24
+++ basic_opcodes.ops 2001/09/25 16:11:16
@@ -425,7 +425,7 @@
/* SET Sx, CONSTANT */
AUTO_OP set_s_sc {
- STR_REG(P1) = Parrot_string_constants[P2];
+ STR_REG(P1) = PCONST(P2)->string;
}
/* PRINT Sx */
@@ -436,8 +436,9 @@
/* PRINT sc */
AUTO_OP print_sc {
- STRING *s = Parrot_string_constants[P1];
- printf("%.*s",(int)string_length(s),(char *) s->bufstart);
+ STRING *s = PCONST(P1)->string;
+ IV l = string_length(s);
+ printf("%.*s",(int)l, (char *)s->bufstart);
}
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.19
diff -u -r1.19 interpreter.c
--- interpreter.c 2001/09/24 17:19:47 1.19
+++ interpreter.c 2001/09/25 16:11:16
@@ -21,16 +21,17 @@
* Check the bytecode's opcode table fingerprint.
*/
void
-check_fingerprint(void) {
- if (Parrot_num_string_constants == 0) {
+check_fingerprint(struct Parrot_Interp *interpreter) {
+/* if (PNCONST == 0) { */
+ if (interpreter->code->const_table->const_count == 0) {
fprintf(stderr, "Warning: Bytecode does not include opcode table
fingerprint!\n");
}
else {
const char * fp_data;
IV fp_len;
- fp_data = Parrot_string_constants[0]->bufstart;
- fp_len = Parrot_string_constants[0]->buflen;
+ fp_data = PCONST(0)->string->bufstart;
+ fp_len = PCONST(0)->string->buflen;
if (strncmp(OPCODE_FINGERPRINT, fp_data, fp_len)) {
fprintf(stderr, "Error: Opcode table fingerprint in bytecode does not
match interpreter!\n");
@@ -45,20 +46,27 @@
* run parrot operations until the program is complete
*/
opcode_t *
-runops_notrace_core (struct Parrot_Interp *interpreter, opcode_t *code, IV code_size)
{
+runops_notrace_core (struct Parrot_Interp *interpreter) {
/* Move these out of the inner loop. No need to redeclare 'em each
time through */
opcode_t *(* func)();
opcode_t *(**temp)();
- opcode_t *code_start;
+ opcode_t * code_start;
+ IV code_size;
+ opcode_t * code_end;
+ opcode_t * pc;
+
+ code_start = (opcode_t *)interpreter->code->byte_code;
+ code_size = interpreter->code->byte_code_size;
+ code_end = (opcode_t *)(interpreter->code->byte_code + code_size);
- code_start = code;
+ pc = code_start;
- while (code >= code_start && code < (code_start + code_size) && *code) {
- DO_OP(code, temp, func, interpreter);
+ while (pc >= code_start && pc < code_end && *pc) {
+ DO_OP(pc, temp, func, interpreter);
}
- return code;
+ return pc;
}
/*
@@ -67,23 +75,23 @@
* and ARGS. Used by runops_trace.
*/
void
-trace_op(opcode_t * code_start, long code_size, opcode_t *code) {
+trace_op(opcode_t * code_start, opcode_t * code_end, opcode_t *pc) {
int i;
- if (code >= code_start && code < (code_start + code_size)) {
- fprintf(stderr, "PC=%ld; OP=%ld (%s)", (long)(code - code_start), *code,
op_names[*code]);
- if (op_args[*code]) {
+ if (pc >= code_start && pc < code_end) {
+ fprintf(stderr, "PC=%ld; OP=%ld (%s)", (long)(pc - code_start), *pc,
+op_names[*pc]);
+ if (op_args[*pc]) {
fprintf(stderr, "; ARGS=(");
- for(i = 0; i < op_args[*code]; i++) {
+ for(i = 0; i < op_args[*pc]; i++) {
if (i) { fprintf(stderr, ", "); }
- fprintf(stderr, "%ld", *(code + i + 1));
+ fprintf(stderr, "%ld", *(pc + i + 1));
}
fprintf(stderr, ")");
}
fprintf(stderr, "\n");
}
else {
- fprintf(stderr, "PC=%ld; OP=<err>\n", (long)(code - code_start));
+ fprintf(stderr, "PC=%ld; OP=<err>\n", (long)(pc - code_start));
}
}
@@ -92,24 +100,31 @@
* Passed to runops_generic() by runops_trace().
*/
opcode_t *
-runops_trace_core (struct Parrot_Interp *interpreter, opcode_t *code, IV code_size) {
+runops_trace_core (struct Parrot_Interp *interpreter) {
/* Move these out of the inner loop. No need to redeclare 'em each
time through */
opcode_t *( *func)();
opcode_t *(**temp)();
- opcode_t *code_start;
+ opcode_t * code_start;
+ IV code_size;
+ opcode_t * code_end;
+ opcode_t * pc;
- code_start = code;
+ code_start = (opcode_t *)interpreter->code->byte_code;
+ code_size = interpreter->code->byte_code_size;
+ code_end = (opcode_t *)(interpreter->code->byte_code + code_size);
- trace_op(code_start, code_size, code);
+ pc = code_start;
- while (code >= code_start && code < (code_start + code_size) && *code) {
- DO_OP(code, temp, func, interpreter);
+ trace_op(code_start, code_end, pc);
+
+ while (pc >= code_start && pc < code_end && *pc) {
+ DO_OP(pc, temp, func, interpreter);
- trace_op(code_start, code_size, code);
+ trace_op(code_start, code_end, pc);
}
- return code;
+ return pc;
}
/*=for api interpreter runops_generic
@@ -117,17 +132,22 @@
* Generic runops, which takes a function pointer for the core.
*/
void
-runops_generic (opcode_t * (*core)(struct Parrot_Interp *, opcode_t *, IV), struct
Parrot_Interp *interpreter, opcode_t *code, IV code_size) {
+runops_generic (opcode_t * (*core)(struct Parrot_Interp *), struct Parrot_Interp
+*interpreter) {
opcode_t * code_start;
+ IV code_size;
+ opcode_t * code_end;
+ IV * pc;
- check_fingerprint();
+ check_fingerprint(interpreter);
- code_start = code;
+ code_start = (opcode_t *)interpreter->code->byte_code;
+ code_size = interpreter->code->byte_code_size;
+ code_end = (opcode_t *)(interpreter->code->byte_code + code_size);
- code = core(interpreter, code, code_size);
+ pc = core(interpreter);
- if (code < code_start || code >= (code_start + code_size)) {
- fprintf(stderr, "Error: Control left bounds of byte-code block (now at
location %d)!\n", code - code_start);
+ if (pc < code_start || pc >= code_end) {
+ fprintf(stderr, "Error: Control left bounds of byte-code block (now at
+location %d)!\n", pc - code_start);
exit(1);
}
}
@@ -137,8 +157,8 @@
* run parrot operations until the program is complete
*/
void
-runops (struct Parrot_Interp *interpreter, opcode_t *code, IV code_size) {
- opcode_t * (*core)(struct Parrot_Interp *, opcode_t *, IV);
+runops (struct Parrot_Interp *interpreter, struct PackFile * code) {
+ opcode_t * (*core)(struct Parrot_Interp *);
if (interpreter->flags & PARROT_TRACE_FLAG) {
core = runops_trace_core;
@@ -147,7 +167,9 @@
core = runops_notrace_core;
}
- runops_generic(core, interpreter, code, code_size);
+ interpreter->code = code;
+
+ runops_generic(core, interpreter);
}
/*=for api interpreter make_interpreter
@@ -228,6 +250,9 @@
Init_IO(interpreter);
/* Done. Return and be done with it */
+
+ interpreter->code = (struct PackFile *)NULL;
+
return interpreter;
}
Index: packfile.c
===================================================================
RCS file: /home/perlcvs/parrot/packfile.c,v
retrieving revision 1.4
diff -u -r1.4 packfile.c
--- packfile.c 2001/09/20 21:41:40 1.4
+++ packfile.c 2001/09/25 16:11:16
@@ -53,9 +53,9 @@
***************************************/
-PackFile *
+struct PackFile *
PackFile_new(void) {
- PackFile * self = mem_sys_allocate(sizeof(PackFile));
+ struct PackFile * self = mem_sys_allocate(sizeof(struct PackFile));
if (!self) {
fprintf(stderr, "PackFile_new: Unable to allocate!\n");
@@ -99,7 +99,7 @@
***************************************/
void
-PackFile_DELETE(PackFile * self) {
+PackFile_DELETE(struct PackFile * self) {
if (!self) {
fprintf(stderr, "PackFile_DELETE: self == NULL!\n");
return;
@@ -130,7 +130,7 @@
***************************************/
void
-PackFile_clear(PackFile * self) {
+PackFile_clear(struct PackFile * self) {
if (!self) {
fprintf(stderr, "PackFile_clear: self == NULL!\n");
return;
@@ -164,7 +164,7 @@
***************************************/
IV
-PackFile_get_magic(PackFile * self) {
+PackFile_get_magic(struct PackFile * self) {
return self->magic;
}
@@ -181,7 +181,7 @@
***************************************/
void
-PackFile_set_magic(PackFile * self, IV magic) {
+PackFile_set_magic(struct PackFile * self, IV magic) {
self->magic = magic;
}
@@ -197,7 +197,7 @@
***************************************/
IV
-PackFile_get_byte_code_size(PackFile * self) {
+PackFile_get_byte_code_size(struct PackFile * self) {
return self->byte_code_size;
}
@@ -215,7 +215,7 @@
***************************************/
char *
-PackFile_get_byte_code(PackFile * self) {
+PackFile_get_byte_code(struct PackFile * self) {
return self->byte_code;
}
@@ -234,7 +234,7 @@
***************************************/
void
-PackFile_set_byte_code(PackFile * self, IV byte_code_size, char * byte_code) {
+PackFile_set_byte_code(struct PackFile * self, IV byte_code_size, char * byte_code) {
if (self->byte_code) {
mem_sys_free(self->byte_code);
self->byte_code = NULL;
@@ -281,7 +281,7 @@
***************************************/
IV
-PackFile_unpack(PackFile * self, char * packed, IV packed_size) {
+PackFile_unpack(struct PackFile * self, char * packed, IV packed_size) {
IV * segment_ptr;
IV segment_size;
char * byte_code_ptr;
@@ -386,7 +386,7 @@
***************************************/
IV
-PackFile_pack_size(PackFile * self) {
+PackFile_pack_size(struct PackFile * self) {
IV magic_size = sizeof(IV);
IV segment_length_size = sizeof(IV);
IV fixup_table_size = PackFile_FixupTable_pack_size(self->fixup_table);
@@ -412,7 +412,7 @@
***************************************/
void
-PackFile_pack(PackFile * self, char * packed) {
+PackFile_pack(struct PackFile * self, char * packed) {
char * cursor = packed;
IV * iv_ptr;
IV fixup_table_size = PackFile_FixupTable_pack_size(self->fixup_table);
@@ -455,7 +455,7 @@
***************************************/
void
-PackFile_dump(PackFile * self) {
+PackFile_dump(struct PackFile * self) {
IV i;
printf("MAGIC => 0x%08x,\n", self->magic);
@@ -511,9 +511,9 @@
***************************************/
-PackFile_FixupTable *
+struct PackFile_FixupTable *
PackFile_FixupTable_new(void) {
- PackFile_FixupTable * self = mem_sys_allocate(sizeof(PackFile_FixupTable));
+ struct PackFile_FixupTable * self = mem_sys_allocate(sizeof(struct
+PackFile_FixupTable));
self->dummy = 0;
@@ -532,7 +532,7 @@
***************************************/
void
-PackFile_FixupTable_DELETE(PackFile_FixupTable * self) {
+PackFile_FixupTable_DELETE(struct PackFile_FixupTable * self) {
if (!self) {
fprintf(stderr, "PackFile_FixupTable_DELETE: self == NULL!\n");
return;
@@ -555,7 +555,7 @@
***************************************/
void
-PackFile_FixupTable_clear(PackFile_FixupTable * self) {
+PackFile_FixupTable_clear(struct PackFile_FixupTable * self) {
if (!self) {
fprintf(stderr, "PackFile_FixupTable_clear: self == NULL!\n");
return;
@@ -580,7 +580,7 @@
***************************************/
IV
-PackFile_FixupTable_unpack(PackFile_FixupTable * self, char * packed, IV packed_size)
{
+PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char * packed, IV
+packed_size) {
return 1;
}
@@ -597,7 +597,7 @@
***************************************/
IV
-PackFile_FixupTable_pack_size(PackFile_FixupTable * self) {
+PackFile_FixupTable_pack_size(struct PackFile_FixupTable * self) {
return 0;
}
@@ -615,7 +615,7 @@
***************************************/
void
-PackFile_FixupTable_pack(PackFile_FixupTable * self, char * packed) {
+PackFile_FixupTable_pack(struct PackFile_FixupTable * self, char * packed) {
return;
}
@@ -631,7 +631,7 @@
***************************************/
void
-PackFile_FixupTable_dump(PackFile_FixupTable * self) {
+PackFile_FixupTable_dump(struct PackFile_FixupTable * self) {
return;
}
@@ -667,9 +667,9 @@
***************************************/
-PackFile_ConstTable *
+struct PackFile_ConstTable *
PackFile_ConstTable_new(void) {
- PackFile_ConstTable * self = mem_sys_allocate(sizeof(PackFile_ConstTable));
+ struct PackFile_ConstTable * self = mem_sys_allocate(sizeof(struct
+PackFile_ConstTable));
self->const_count = 0;
self->constants = NULL;
@@ -689,7 +689,7 @@
***************************************/
void
-PackFile_ConstTable_DELETE(PackFile_ConstTable * self) {
+PackFile_ConstTable_DELETE(struct PackFile_ConstTable * self) {
if (!self) {
fprintf(stderr, "PackFile_ConstTable_DELETE: self == NULL!\n");
return;
@@ -714,7 +714,7 @@
***************************************/
void
-PackFile_ConstTable_clear(PackFile_ConstTable * self) {
+PackFile_ConstTable_clear(struct PackFile_ConstTable * self) {
IV i;
if (!self) {
@@ -747,7 +747,7 @@
***************************************/
IV
-PackFile_ConstTable_get_const_count(PackFile_ConstTable * self) {
+PackFile_ConstTable_get_const_count(struct PackFile_ConstTable * self) {
return self->const_count;
}
@@ -764,15 +764,15 @@
***************************************/
void
-PackFile_ConstTable_push_constant(PackFile_ConstTable * self, PackFile_Constant *
constant) {
- PackFile_Constant ** temp;
+PackFile_ConstTable_push_constant(struct PackFile_ConstTable * self, struct
+PackFile_Constant * constant) {
+ struct PackFile_Constant ** temp;
IV i;
if (!constant) {
return;
}
- temp = mem_sys_allocate((self->const_count + 1) * sizeof(PackFile_Constant *));
+ temp = mem_sys_allocate((self->const_count + 1) * sizeof(struct PackFile_Constant
+*));
if (!temp) {
fprintf(stderr, "Unable to reallocate Constant array to push a new
Constant!\n");
@@ -799,8 +799,8 @@
***************************************/
-PackFile_Constant *
-PackFile_ConstTable_constant(PackFile_ConstTable * self, IV index) {
+struct PackFile_Constant *
+PackFile_ConstTable_constant(struct PackFile_ConstTable * self, IV index) {
if (index < 0 || index >= self->const_count) {
return NULL;
}
@@ -825,7 +825,7 @@
***************************************/
IV
-PackFile_ConstTable_unpack(PackFile_ConstTable * self, char * packed, IV packed_size)
{
+PackFile_ConstTable_unpack(struct PackFile_ConstTable * self, char * packed, IV
+packed_size) {
char * cursor;
IV * iv_ptr;
IV i;
@@ -842,7 +842,7 @@
return 1;
}
- self->constants = mem_sys_allocate(self->const_count * sizeof(PackFile_Constant
*));
+ self->constants = mem_sys_allocate(self->const_count * sizeof(struct
+PackFile_Constant *));
if (!self->constants) {
fprintf(stderr, "PackFile_ConstTable_unpack: Could not allocate memory for
array!\n");
@@ -874,7 +874,7 @@
***************************************/
IV
-PackFile_ConstTable_pack_size(PackFile_ConstTable * self) {
+PackFile_ConstTable_pack_size(struct PackFile_ConstTable * self) {
IV i;
IV size = 0;
@@ -899,7 +899,7 @@
***************************************/
void
-PackFile_ConstTable_pack(PackFile_ConstTable * self, char * packed) {
+PackFile_ConstTable_pack(struct PackFile_ConstTable * self, char * packed) {
char * cursor;
IV * iv_ptr;
IV i;
@@ -931,7 +931,7 @@
***************************************/
void
-PackFile_ConstTable_dump(PackFile_ConstTable * self) {
+PackFile_ConstTable_dump(struct PackFile_ConstTable * self) {
IV i;
for(i = 0; i < self->const_count; i++) {
@@ -974,15 +974,12 @@
***************************************/
-PackFile_Constant *
+struct PackFile_Constant *
PackFile_Constant_new(void) {
- PackFile_Constant * self = mem_sys_allocate(sizeof(PackFile_Constant));
+ struct PackFile_Constant * self = mem_sys_allocate(sizeof(struct
+PackFile_Constant));
- self->flags = 0;
- self->encoding = 0;
- self->type = 0;
- self->size = 0;
- self->data = NULL;
+ self->type = '\0';
+ self->string = NULL;
return self;
}
@@ -999,7 +996,7 @@
***************************************/
void
-PackFile_Constant_DELETE(PackFile_Constant * self) {
+PackFile_Constant_DELETE(struct PackFile_Constant * self) {
if (!self) {
fprintf(stderr, "PackFile_Constant_DELETE: self == NULL!\n");
return;
@@ -1024,20 +1021,17 @@
***************************************/
void
-PackFile_Constant_clear(PackFile_Constant * self) {
+PackFile_Constant_clear(struct PackFile_Constant * self) {
if (!self) {
fprintf(stderr, "PackFile_Constant_clear: self == NULL!\n");
return;
}
- self->flags = 0;
- self->encoding = 0;
- self->type = 0;
- self->size = 0;
-
- if (self->data) {
- mem_sys_free(self->data);
- self->data = NULL;
+ self->type = '\0';
+
+ if (self->string) {
+ string_destroy(self->string);
+ self->string = NULL;
}
return;
@@ -1055,8 +1049,12 @@
***************************************/
IV
-PackFile_Constant_get_flags(PackFile_Constant * self) {
- return self->flags;
+PackFile_Constant_get_flags(struct PackFile_Constant * self) {
+ if (!self || !self->string) {
+ return 0;
+ }
+
+ return self->string->flags;
}
@@ -1071,8 +1069,12 @@
***************************************/
void
-PackFile_Constant_set_flags(PackFile_Constant * self, IV flags) {
- self->flags = flags;
+PackFile_Constant_set_flags(struct PackFile_Constant * self, IV flags) {
+ if (!self || !self->string) {
+ return;
+ }
+
+ self->string->flags = flags;
}
@@ -1087,8 +1089,12 @@
***************************************/
IV
-PackFile_Constant_get_encoding(PackFile_Constant * self) {
- return self->encoding;
+PackFile_Constant_get_encoding(struct PackFile_Constant * self) {
+ if (!self || !self->string) {
+ return;
+ }
+
+ return self->string->encoding->which;
}
/***************************************
@@ -1102,8 +1108,12 @@
***************************************/
void
-PackFile_Constant_set_encoding(PackFile_Constant * self, IV encoding) {
- self->encoding = encoding;
+PackFile_Constant_set_encoding(struct PackFile_Constant * self, IV encoding) {
+ if (!self || !self->string) {
+ return;
+ }
+
+ self->string->encoding = &Parrot_string_vtable[encoding];
}
@@ -1118,7 +1128,11 @@
***************************************/
IV
-PackFile_Constant_get_type(PackFile_Constant * self) {
+PackFile_Constant_get_type(struct PackFile_Constant * self) {
+ if (!self || !self->string) {
+ return;
+ }
+
return self->type;
}
@@ -1134,7 +1148,11 @@
***************************************/
void
-PackFile_Constant_set_type(PackFile_Constant * self, IV type) {
+PackFile_Constant_set_type(struct PackFile_Constant * self, IV type) {
+ if (!self || !self->string) {
+ return;
+ }
+
self->type = type;
}
@@ -1151,8 +1169,12 @@
***************************************/
IV
-PackFile_Constant_get_size(PackFile_Constant * self) {
- return self->size;
+PackFile_Constant_get_size(struct PackFile_Constant * self) {
+ if (!self || !self->string) {
+ return;
+ }
+
+ return self->string->bufused;
}
@@ -1160,15 +1182,19 @@
=item get_data
-Retrieve the Constant's data.
+Retrieve the Constant's data. The data belongs to the PackFile Constant.
=cut
***************************************/
char *
-PackFile_Constant_get_data(PackFile_Constant * self) {
- return self->data;
+PackFile_Constant_get_data(struct PackFile_Constant * self) {
+ if (!self || !self->string) {
+ return;
+ }
+
+ return self->string->bufstart;
}
@@ -1176,31 +1202,35 @@
=item set_data
-Set the Constant's data.
+Set the Constant's data. A copy is made.
=cut
***************************************/
void
-PackFile_Constant_set_data(PackFile_Constant * self, IV size, char * data) {
- if (self->data) {
- mem_sys_free(self->data);
- self->data = NULL;
- self->size = 0;
- }
+PackFile_Constant_set_data(struct PackFile_Constant * self, IV size, char * data) {
+ IV flags;
+ IV encoding;
+ IV type;
+ STRING * new_string;
- self->data = mem_sys_allocate(size);
-
- if (!self->data) {
- fprintf(stderr, "Unable to allocate memory to copy PackFile Constant
data!\n");
+ if (!self) {
return;
}
- self->size = size;
+ flags = self->string->flags;
+ flags = self->string->encoding->which;
+ flags = self->string->type;
- mem_sys_memcopy(self->data, data, size);
+ new_string = string_make(data, size, encoding, flags, type);
+
+ if (self->string) {
+ string_destroy(self->string);
+ }
+ self->string = new_string;
+
return;
}
@@ -1227,38 +1257,34 @@
***************************************/
IV
-PackFile_Constant_unpack(PackFile_Constant * self, char * packed, IV packed_size) {
+PackFile_Constant_unpack(struct PackFile_Constant * self, char * packed, IV
+packed_size) {
char * cursor;
- IV * iv_ptr;
- IV i;
+ IV flags;
+ IV encoding;
+ IV type;
+ IV size;
- cursor = packed;
+ if (!self) {
+ return 0;
+ }
- iv_ptr = (IV *)cursor;
- self->flags = *iv_ptr;
- cursor += sizeof(IV);
-
- iv_ptr = (IV *)cursor;
- self->encoding = *iv_ptr;
- cursor += sizeof(IV);
-
- iv_ptr = (IV *)cursor;
- self->type = *iv_ptr;
- cursor += sizeof(IV);
-
- iv_ptr = (IV *)cursor;
- self->size = *iv_ptr;
- cursor += sizeof(IV);
+ cursor = packed;
- self->data = mem_sys_allocate(self->size);
+ flags = *(IV *)cursor;
+ cursor += sizeof(IV);
- if (!self->data) {
- fprintf(stderr, "PackFile_Constant_unpack: Unable to allocate memory!\n");
- return 0;
- }
+ encoding = *(IV *)cursor;
+ cursor += sizeof(IV);
+
+ type = *(IV *)cursor;
+ cursor += sizeof(IV);
- mem_sys_memcopy(self->data, cursor, self->size);
+ size = *(IV *)cursor;
+ cursor += sizeof(IV);
+ self->type = 'S';
+ self->string = string_make(cursor, size, encoding, flags, type);
+
return 1;
}
@@ -1275,10 +1301,14 @@
***************************************/
IV
-PackFile_Constant_pack_size(PackFile_Constant * self) {
+PackFile_Constant_pack_size(struct PackFile_Constant * self) {
IV padded_size;
+
+ if (!self) {
+ return 0;
+ }
- padded_size = self->size;
+ padded_size = self->string->bufused;
if (padded_size % sizeof(IV)) {
padded_size += sizeof(IV) - (padded_size % sizeof(IV));
@@ -1296,42 +1326,46 @@
block had better have at least the amount of memory indicated by
PackFile_Constant_pack_size()!
-The data is zero-badded to an IV-boundary, so pad bytes may be added.
+The data is zero-padded to an IV-boundary, so pad bytes may be added.
=cut
***************************************/
void
-PackFile_Constant_pack(PackFile_Constant * self, char * packed) {
+PackFile_Constant_pack(struct PackFile_Constant * self, char * packed) {
char * cursor;
IV * iv_ptr;
IV i;
+ if (!self) {
+ return;
+ }
+
cursor = packed;
iv_ptr = (IV *)cursor;
- *iv_ptr = self->flags;
+ *iv_ptr = self->string->flags;
cursor += sizeof(IV);
iv_ptr = (IV *)cursor;
- *iv_ptr = self->encoding;
+ *iv_ptr = self->string->encoding->which;
cursor += sizeof(IV);
iv_ptr = (IV *)cursor;
- *iv_ptr = self->type;
+ *iv_ptr = self->string->type;
cursor += sizeof(IV);
iv_ptr = (IV *)cursor;
- *iv_ptr = self->size;
+ *iv_ptr = self->string->bufused;
cursor += sizeof(IV);
- if (self->data) {
- mem_sys_memcopy(cursor, self->data, self->size);
- cursor += self->size;
+ if (self->string->bufstart) {
+ mem_sys_memcopy(cursor, self->string->bufstart, self->string->bufused);
+ cursor += self->string->bufused;
- if (self->size % sizeof(IV)) {
- for(i = 0; i < (sizeof(IV) - (self->size % sizeof(IV))); i++) {
+ if (self->string->bufused % sizeof(IV)) {
+ for(i = 0; i < (sizeof(IV) - (self->string->bufused % sizeof(IV))); i++) {
cursor[i] = 0;
}
}
@@ -1352,14 +1386,17 @@
***************************************/
void
-PackFile_Constant_dump(PackFile_Constant * self) {
+PackFile_Constant_dump(struct PackFile_Constant * self) {
+ if (!self) {
+ return;
+ }
printf(" {\n");
- printf(" FLAGS => %04x,\n", self->flags);
- printf(" ENCODING => %ld,\n", self->encoding);
- printf(" TYPE => %ld,\n", self->type);
- printf(" SIZE => %ld,\n", self->size);
- printf(" DATA => '%s'\n", self->data); /* TODO: Not a good idea in
general */
+ printf(" FLAGS => %04x,\n", self->string->flags);
+ printf(" ENCODING => %ld,\n", self->string->encoding);
+ printf(" TYPE => %ld,\n", self->string->type);
+ printf(" SIZE => %ld,\n", self->string->bufused);
+ printf(" DATA => '%s'\n", self->string->bufstart); /* TODO: Not a
+good idea in general */
printf(" },\n");
return;
Index: pdump.c
===================================================================
RCS file: /home/perlcvs/parrot/pdump.c,v
retrieving revision 1.1
diff -u -r1.1 pdump.c
--- pdump.c 2001/09/19 16:48:28 1.1
+++ pdump.c 2001/09/25 16:11:16
@@ -14,11 +14,11 @@
int
main(int argc, char **argv) {
- struct stat file_stat;
- int fd;
- char * packed;
- long packed_size;
- PackFile * pf;
+ struct stat file_stat;
+ int fd;
+ char * packed;
+ long packed_size;
+ struct PackFile * pf;
if (argc != 2) {
fprintf(stderr, "pdump: usage: pdump FILE\n");
Index: test_main.c
===================================================================
RCS file: /home/perlcvs/parrot/test_main.c,v
retrieving revision 1.12
diff -u -r1.12 test_main.c
--- test_main.c 2001/09/21 04:56:24 1.12
+++ test_main.c 2001/09/25 16:11:16
@@ -12,19 +12,6 @@
#include "parrot/parrot.h"
-IV opcodes[] = {3, 1, /* put the time in reg 1 */
- 0, 2, 0, /* Set reg 2 to 0 */
- 0, 3, 1, /* set reg 3 to 1 */
- 0, 4, 100000000, /* set reg 4 to 100M */
- 2, 2, 4, 11, 5, /* is reg 2 eq to reg 4? */
- 1, 2, 2, 3, /* Add register 2 to 3, store in 2 */
- 5, -9, /* branch back to if */
- 3, 5, /* Put the time in reg 5 */
- 4, 1, /* Print reg 1 */
- 4, 5, /* Print reg 5 */
- 6 /* exit */
- };
-
int
main(int argc, char **argv) {
int i;
@@ -48,9 +35,10 @@
tracing = 0;
}
- /* If we got only the program name, run the test program */
+ /* If we got only the program name, complain */
if (argc == 1) {
- runops(interpreter, (opcode_t*)opcodes, sizeof(opcodes));
+ fprintf(stderr, "%s: usage: %s prog\n", argv[0], argv[0]);
+ exit(1);
}
else if (argc == 2 && !strcmp(argv[1], "-s")) { /* String tests */
STRING *s = string_make("foo", 3, enc_native, 0, 0);
@@ -79,6 +67,7 @@
long program_size;
struct stat file_stat;
int fd;
+ struct PackFile * pf;
if (stat(argv[1], &file_stat)) {
printf("can't stat %s, code %i\n", argv[1], errno);
@@ -104,13 +93,14 @@
return 1;
}
- program_code = init_bytecode(program_code, &program_size);
+ pf = PackFile_new();
+ PackFile_unpack(pf, (char *)program_code, program_size);
if (tracing) {
interpreter->flags |= PARROT_TRACE_FLAG;
}
- runops(interpreter, program_code, program_size);
+ runops(interpreter, pf);
}
return 0;
Index: include/parrot/interpreter.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/interpreter.h,v
retrieving revision 1.4
diff -u -r1.4 interpreter.h
--- include/parrot/interpreter.h 2001/09/24 17:19:48 1.4
+++ include/parrot/interpreter.h 2001/09/25 16:11:17
@@ -35,17 +35,23 @@
IV flags; /* Various interpreter flags
that signal that runops
should do something */
+
+ struct PackFile * code; /* The code we are executing */
+
};
#define PARROT_DEBUG_FLAG 0x01 /* Bit in the flags that says
we're debugging */
#define PARROT_TRACE_FLAG 0x02 /* We're tracing execution */
+#define PCONST(i) PF_CONST(interpreter->code, (i))
+#define PNCONST PF_NCONST(interpreter->code)
+
struct Parrot_Interp *
make_interpreter();
void
-runops(struct Parrot_Interp *, opcode_t *, IV);
+runops(struct Parrot_Interp *, struct PackFile *);
#endif
Index: include/parrot/packfile.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/packfile.h,v
retrieving revision 1.2
diff -u -r1.2 packfile.h
--- include/parrot/packfile.h 2001/09/19 19:37:21 1.2
+++ include/parrot/packfile.h 2001/09/25 16:11:17
@@ -3,193 +3,199 @@
* $Id: packfile.h,v 1.2 2001/09/19 19:37:21 gregor Exp $
*/
+#ifndef PACKFILE_H
+#define PACKFILE_H
+
#include <parrot/parrot.h>
+#define PF_NCONST(pf) (pf)->const_table->const_count
+#define PF_CONST(pf,i) (pf)->const_table->constants[i]
+
/*
** Structure Definitions:
*/
-typedef struct {
+struct PackFile_FixupTable {
IV dummy;
-} PackFile_FixupTable;
+};
+
+
+struct PackFile_Constant {
+ IV type;
+ STRING * string;
+};
-typedef struct {
- IV flags;
- IV encoding;
- IV type;
- IV size;
- char * data;
-} PackFile_Constant;
-
-
-typedef struct {
- IV const_count;
- PackFile_Constant ** constants;
-} PackFile_ConstTable;
-
-
-typedef struct {
- IV magic;
- PackFile_FixupTable * fixup_table;
- PackFile_ConstTable * const_table;
- IV byte_code_size;
- char * byte_code;
-} PackFile;
+struct PackFile_ConstTable {
+ IV const_count;
+ struct PackFile_Constant ** constants;
+};
+struct PackFile {
+ IV magic;
+ struct PackFile_FixupTable * fixup_table;
+ struct PackFile_ConstTable * const_table;
+ IV byte_code_size;
+ char * byte_code;
+};
+
+
/*
** PackFile Functions:
*/
-PackFile *
+struct PackFile *
PackFile_new(void);
void
-PackFile_DELETE(PackFile * self);
+PackFile_DELETE(struct PackFile * self);
void
-PackFile_clear(PackFile * self);
+PackFile_clear(struct PackFile * self);
IV
-PackFile_get_magic(PackFile * self);
+PackFile_get_magic(struct PackFile * self);
void
-PackFile_set_magic(PackFile * self, IV magic);
+PackFile_set_magic(struct PackFile * self, IV magic);
IV
-PackFile_get_byte_code_size(PackFile * self);
+PackFile_get_byte_code_size(struct PackFile * self);
char *
-PackFile_get_byte_code(PackFile * self);
+PackFile_get_byte_code(struct PackFile * self);
void
-PackFile_set_byte_code(PackFile * self, IV byte_code_size, char * byte_code);
+PackFile_set_byte_code(struct PackFile * self, IV byte_code_size, char * byte_code);
IV
-PackFile_unpack(PackFile * self, char * packed, IV packed_size);
+PackFile_unpack(struct PackFile * self, char * packed, IV packed_size);
IV
-PackFile_pack_size(PackFile * self);
+PackFile_pack_size(struct PackFile * self);
void
-PackFile_pack(PackFile * self, char * packed);
+PackFile_pack(struct PackFile * self, char * packed);
void
-PackFile_dump(PackFile * self);
+PackFile_dump(struct PackFile * self);
/*
** PackFile_FixupTable Functions:
*/
-PackFile_FixupTable *
+struct PackFile_FixupTable *
PackFile_FixupTable_new(void);
void
-PackFile_FixupTable_DELETE(PackFile_FixupTable * self);
+PackFile_FixupTable_DELETE(struct PackFile_FixupTable * self);
void
-PackFile_FixupTable_clear(PackFile_FixupTable * self);
+PackFile_FixupTable_clear(struct PackFile_FixupTable * self);
IV
-PackFile_FixupTable_unpack(PackFile_FixupTable * self, char * packed, IV packed_size);
+PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char * packed, IV
+packed_size);
IV
-PackFile_FixupTable_pack_size(PackFile_FixupTable * self);
+PackFile_FixupTable_pack_size(struct PackFile_FixupTable * self);
void
-PackFile_FixupTable_pack(PackFile_FixupTable * self, char * packed);
+PackFile_FixupTable_pack(struct PackFile_FixupTable * self, char * packed);
void
-PackFile_FixupTable_dump(PackFile_FixupTable * self);
+PackFile_FixupTable_dump(struct PackFile_FixupTable * self);
/*
** PackFile_ConstTable Functions:
*/
-PackFile_ConstTable *
+struct PackFile_ConstTable *
PackFile_ConstTable_new(void);
void
-PackFile_ConstTable_DELETE(PackFile_ConstTable * self);
+PackFile_ConstTable_DELETE(struct PackFile_ConstTable * self);
void
-PackFile_ConstTable_clear(PackFile_ConstTable * self);
+PackFile_ConstTable_clear(struct PackFile_ConstTable * self);
IV
-PackFile_ConstTable_get_const_count(PackFile_ConstTable * self);
+PackFile_ConstTable_get_const_count(struct PackFile_ConstTable * self);
void
-PackFile_ConstTable_push_constant(PackFile_ConstTable * self, PackFile_Constant *
constant);
+PackFile_ConstTable_push_constant(struct PackFile_ConstTable * self, struct
+PackFile_Constant * constant);
-PackFile_Constant *
-PackFile_ConstTable_constant(PackFile_ConstTable * self, IV index);
+struct PackFile_Constant *
+PackFile_ConstTable_constant(struct PackFile_ConstTable * self, IV index);
IV
-PackFile_ConstTable_unpack(PackFile_ConstTable * self, char * packed, IV packed_size);
+PackFile_ConstTable_unpack(struct PackFile_ConstTable * self, char * packed, IV
+packed_size);
IV
-PackFile_ConstTable_pack_size(PackFile_ConstTable * self);
+PackFile_ConstTable_pack_size(struct PackFile_ConstTable * self);
void
-PackFile_ConstTable_pack(PackFile_ConstTable * self, char * packed);
+PackFile_ConstTable_pack(struct PackFile_ConstTable * self, char * packed);
void
-PackFile_ConstTable_dump(PackFile_ConstTable * self);
+PackFile_ConstTable_dump(struct PackFile_ConstTable * self);
/*
** PackFile_Constant Functions:
*/
-PackFile_Constant *
+struct PackFile_Constant *
PackFile_Constant_new(void);
void
-PackFile_Constant_DELETE(PackFile_Constant * self);
+PackFile_Constant_DELETE(struct PackFile_Constant * self);
void
-PackFile_Constant_clear(PackFile_Constant * self);
+PackFile_Constant_clear(struct PackFile_Constant * self);
IV
-PackFile_Constant_get_flags(PackFile_Constant * self);
+PackFile_Constant_get_flags(struct PackFile_Constant * self);
void
-PackFile_Constant_set_flags(PackFile_Constant * self, IV flags);
+PackFile_Constant_set_flags(struct PackFile_Constant * self, IV flags);
IV
-PackFile_Constant_get_encoding(PackFile_Constant * self);
+PackFile_Constant_get_encoding(struct PackFile_Constant * self);
void
-PackFile_Constant_set_encoding(PackFile_Constant * self, IV encoding);
+PackFile_Constant_set_encoding(struct PackFile_Constant * self, IV encoding);
IV
-PackFile_Constant_get_type(PackFile_Constant * self);
+PackFile_Constant_get_type(struct PackFile_Constant * self);
void
-PackFile_Constant_set_type(PackFile_Constant * self, IV type);
+PackFile_Constant_set_type(struct PackFile_Constant * self, IV type);
IV
-PackFile_Constant_get_size(PackFile_Constant * self);
+PackFile_Constant_get_size(struct PackFile_Constant * self);
char *
-PackFile_Constant_get_data(PackFile_Constant * self);
+PackFile_Constant_get_data(struct PackFile_Constant * self);
void
-PackFile_Constant_set_data(PackFile_Constant * self, IV size, char * data);
+PackFile_Constant_set_data(struct PackFile_Constant * self, IV size, char * data);
IV
-PackFile_Constant_unpack(PackFile_Constant * self, char * packed, IV packed_size);
+PackFile_Constant_unpack(struct PackFile_Constant * self, char * packed, IV
+packed_size);
IV
-PackFile_Constant_pack_size(PackFile_Constant * self);
+PackFile_Constant_pack_size(struct PackFile_Constant * self);
void
-PackFile_Constant_pack(PackFile_Constant * self, char * packed);
+PackFile_Constant_pack(struct PackFile_Constant * self, char * packed);
void
-PackFile_Constant_dump(PackFile_Constant * self);
+PackFile_Constant_dump(struct PackFile_Constant * self);
+
+
+#endif /* PACKFILE_H */
Index: include/parrot/parrot.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/parrot.h,v
retrieving revision 1.1
diff -u -r1.1 parrot.h
--- include/parrot/parrot.h 2001/09/18 01:16:59 1.1
+++ include/parrot/parrot.h 2001/09/25 16:11:17
@@ -69,7 +69,7 @@
#include "parrot/register.h"
#include "parrot/exceptions.h"
#include "parrot/memory.h"
-#include "parrot/bytecode.h"
+#include "parrot/packfile.h"
#include "parrot/io.h"
#include "parrot/op.h"
#include "parrot/events.h"
Index: t/op/bitwise.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/bitwise.t,v
retrieving revision 1.1
diff -u -r1.1 bitwise.t
--- t/op/bitwise.t 2001/09/25 09:12:57 1.1
+++ t/op/bitwise.t 2001/09/25 16:11:17
@@ -49,6 +49,7 @@
print "\n"
print I0
print "\n"
+ end
CODE
4
4
@@ -70,6 +71,7 @@
print "\n"
print I0
print "\n"
+ end
CODE
51
51
Index: t/op/integer.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/integer.t,v
retrieving revision 1.6
diff -u -r1.6 integer.t
--- t/op/integer.t 2001/09/25 09:12:57 1.6
+++ t/op/integer.t 2001/09/25 16:11:17
@@ -104,6 +104,7 @@
print "\\n"
end
set I0, 0
+ end
CODE
0
1
Index: t/op/stacks.t
===================================================================
RCS file: /home/perlcvs/parrot/t/op/stacks.t,v
retrieving revision 1.1
diff -u -r1.1 stacks.t
--- t/op/stacks.t 2001/09/24 17:21:33 1.1
+++ t/op/stacks.t 2001/09/25 16:11:17
@@ -44,6 +44,7 @@
@{[ print_int_regs() ]}
pop_i
@{[ print_int_regs() ]}
+ end
CODE
01234
56789