On Wed, Sep 12, 2001 at 10:03:55PM -0400, Dan Sugalski wrote:
> At 05:06 PM 9/12/2001 -0700, Hong Zhang wrote:
>
> >I think we should use int32_t instead of IV for all code related
> >data.
>
> Absolutely. Using an IV was a quick answer to get things working--a first
> draft if you will. It needs rewriting so all the ops are I32 and the
> floating point constants are N64s. (Whether you can play Pokemon Stadium or
> not on your floats is a question I'm not touching... :)
>
> Patches welcome (with configure patches to choose the right type), and I'll
> see about fixing it up tomorrow if nobody's got a chance before that.
The attached patch makes all bytecode have a type of int32_t rather than
IV; it also contains the other stuff I needed to get the tests running
on my Alpha (modifications to config.h.in and register.c).
I think this works on both my Alpha and i386 boxen...
Phil
Index: basic_opcodes.ops
===================================================================
RCS file: /home/perlcvs/parrot/basic_opcodes.ops,v
retrieving revision 1.14
diff -u -r1.14 basic_opcodes.ops
--- basic_opcodes.ops 2001/09/13 16:16:38 1.14
+++ basic_opcodes.ops 2001/09/13 20:30:51
@@ -122,7 +122,7 @@
/* PRINT ic */
AUTO_OP print_ic {
- printf("%li", P1);
+ printf("%li", (IV)P1);
}
Index: bytecode.c
===================================================================
RCS file: /home/perlcvs/parrot/bytecode.c,v
retrieving revision 1.5
diff -u -r1.5 bytecode.c
--- bytecode.c 2001/09/12 09:54:46 1.5
+++ bytecode.c 2001/09/13 20:30:51
@@ -21,7 +21,7 @@
#include "parrot.h"
-#define GRAB_IV(x) *((IV*)*x)++
+#define GRAB_BYTECODE(x) *((int32_t*)*x)++
/*
@@ -40,7 +40,7 @@
static int
check_magic(void** program_code) {
- return (GRAB_IV(program_code) == PARROT_MAGIC);
+ return (GRAB_BYTECODE(program_code) == PARROT_MAGIC);
}
/*
@@ -63,34 +63,34 @@
static void
read_constants_table(void** program_code)
{
- IV len = GRAB_IV(program_code);
- IV num;
+ int32_t len = GRAB_BYTECODE(program_code);
+ int32_t num;
IV i = 0;
if (len == 0)
return;
- num = GRAB_IV(program_code);
- len -= sizeof(IV);
+ num = GRAB_BYTECODE(program_code);
+ len -= sizeof(int32_t);
Parrot_string_constants = Allocate_Aligned(num * sizeof(STRING*));
while (len > 0) {
- IV flags = GRAB_IV(program_code);
- IV encoding = GRAB_IV(program_code);
- IV type = GRAB_IV(program_code);
- IV buflen = GRAB_IV(program_code);
+ IV flags = GRAB_BYTECODE(program_code);
+ IV encoding = GRAB_BYTECODE(program_code);
+ IV type = GRAB_BYTECODE(program_code);
+ IV buflen = GRAB_BYTECODE(program_code);
int pad;
- len -= 4 * sizeof(IV);
+ len -= 4 * sizeof(int32_t);
Parrot_string_constants[i++] = string_make(*program_code /* ouch */, buflen,
encoding, flags, type);
(char*)*program_code += buflen;
len -= buflen;
/* Padding */
- pad=buflen % sizeof(IV);
+ pad=buflen % sizeof(int32_t);
if(pad) {
- pad=sizeof(IV)-pad;
+ pad=sizeof(int32_t)-pad;
len -= pad;
(char*)*program_code += pad;
}
@@ -120,9 +120,9 @@
static void
read_fixup_table(void** program_code)
{
- IV len = GRAB_IV(program_code);
+ int32_t len = GRAB_BYTECODE(program_code);
/* For now, just skip over it */
- ((IV*)*program_code) += len;
+ ((int32_t*)*program_code) += len;
}
/*
Index: config.h.in
===================================================================
RCS file: /home/perlcvs/parrot/config.h.in,v
retrieving revision 1.1
diff -u -r1.1 config.h.in
--- config.h.in 2001/09/11 09:44:00 1.1
+++ config.h.in 2001/09/13 20:30:52
@@ -7,7 +7,7 @@
#if !defined(PARROT_CONFIG_H_GUARD)
#define PARROT_CONFIG_H_GUARD
typedef ${iv} IV;
-typedef ${iv} double NV;
+typedef ${nv} NV;
typedef struct _vtable VTABLE;
typedef void DPOINTER;
@@ -22,7 +22,7 @@
#define FRAMES_PER_INT_REG_CHUNK FRAMES_PER_CHUNK
#define FRAMES_PER_STR_REG_CHUNK FRAMES_PER_CHUNK
-#define MASK_CHUNK_LOW_BITS 0xfffff000
+#define MASK_CHUNK_LOW_BITS ((IV)~0x0fff)
${headers}
Index: events.h
===================================================================
RCS file: /home/perlcvs/parrot/events.h,v
retrieving revision 1.1
diff -u -r1.1 events.h
--- events.h 2001/08/29 12:07:02 1.1
+++ events.h 2001/09/13 20:30:52
@@ -7,7 +7,7 @@
#if !defined(PARROT_EVENT_H_GUARD)
#define PARROT_EVENT_H_GUARD
-#define EXECUTE_OPCODE(x) interpreter->opcode_funcs[*(IV *)x]->(code, interpreter)
+#define EXECUTE_OPCODE(x) interpreter->opcode_funcs[*(int32_t *)x]->(code,
+interpreter)
#define CHECK_EVENTS(x)
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.6
diff -u -r1.6 interpreter.c
--- interpreter.c 2001/09/11 22:21:17 1.6
+++ interpreter.c 2001/09/13 20:30:53
@@ -8,10 +8,10 @@
#include "parrot.h"
#include "interp_guts.h"
-void runops (struct Perl_Interp *interpreter, IV *code) {
+void runops (struct Perl_Interp *interpreter, int32_t *code) {
/* Move these out of the inner loop. No need to redeclare 'em each
time through */
- IV *(*func)();
+ int32_t *(*func)();
void **temp;
while (*code) {
DO_OP(code, temp, func, interpreter);
Index: interpreter.h
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.h,v
retrieving revision 1.4
diff -u -r1.4 interpreter.h
--- interpreter.h 2001/09/13 08:44:08 1.4
+++ interpreter.h 2001/09/13 20:30:53
@@ -26,13 +26,12 @@
/* variable area */
struct Arenas *arena_base; /* Pointer to this */
/* interpreter's arena */
- IV *(*(*opcode_funcs)[2048])(); /* Opcode */
- /* function table */
+ int32_t *(*(*opcode_funcs)[2048])(); /* Opcode function table */
STRING_FUNCS *(*(*string_funcs)[64])(); /* String function table */
};
struct Perl_Interp *make_interpreter();
-void runops(struct Perl_Interp *, IV *);
+void runops(struct Perl_Interp *, int32_t *);
#endif
Index: make_op_header.pl
===================================================================
RCS file: /home/perlcvs/parrot/make_op_header.pl,v
retrieving revision 1.4
diff -u -r1.4 make_op_header.pl
--- make_op_header.pl 2001/09/12 09:54:46 1.4
+++ make_op_header.pl 2001/09/13 20:30:53
@@ -6,7 +6,7 @@
next if /^\s*#/ or /^\s*$/;
chomp;
($name, undef) = split /\s+/, $_;
- print "IV *$name(IV *, struct Perl_Interp *);\n";
+ print "int32_t *$name(int32_t *, struct Perl_Interp *);\n";
}
BEGIN {
@@ -19,7 +19,7 @@
#if !defined(PARROT_OP_H_GUARD)
#define PARROT_OP_H_GUARD
-typedef IV OP;
+typedef int32_t OP;
#define DEFAULT_OPCODE_TABLE NULL
}
Index: process_opfunc.pl
===================================================================
RCS file: /home/perlcvs/parrot/process_opfunc.pl,v
retrieving revision 1.4
diff -u -r1.4 process_opfunc.pl
--- process_opfunc.pl 2001/09/12 09:54:46 1.4
+++ process_opfunc.pl 2001/09/13 20:30:54
@@ -120,7 +120,7 @@
my $line = shift;
my ($name) = $line =~ /AUTO_OP\s+(\w+)/;
- print OUTPUT "IV *$name(IV cur_opcode[], struct Perl_Interp *interpreter) {\n";
+ print OUTPUT "int32_t *$name(int32_t cur_opcode[], struct Perl_Interp
+*interpreter) {\n";
return($name, " return cur_opcode + "
. $opcode{$name}{RETURN_OFFSET}. ";\n}\n");
}
@@ -129,7 +129,7 @@
my $line = shift;
my ($name) = $line =~ /MANUAL_OP\s+(\w+)/;
- print OUTPUT "IV *$name(IV cur_opcode[], struct Perl_Interp *interpreter) {\n";
+ print OUTPUT "int32_t *$name(int32_t cur_opcode[], struct Perl_Interp
+*interpreter) {\n";
print OUTPUT " IV return_offset = 1;\n";
return($name, " return cur_opcode + return_offset;\n}\n");
}
Index: register.c
===================================================================
RCS file: /home/perlcvs/parrot/register.c,v
retrieving revision 1.3
diff -u -r1.3 register.c
--- register.c 2001/09/10 21:40:33 1.3
+++ register.c 2001/09/13 20:30:56
@@ -44,7 +44,7 @@
/* Do so. We don't need to adjust used/free, since they're
already OK for the "We're full" case */
chunk_base = chunk_base->prev;
- interpreter->int_reg = &chunk_base->IReg[chunk_base->used];
+ interpreter->int_reg = &chunk_base->IReg[chunk_base->used - 1];
}
/* Nope. So pitch a fit */
else {
@@ -98,7 +98,7 @@
/* Do so. We don't need to adjust used/free, since they're
already OK for the "We're full" case */
chunk_base = chunk_base->prev;
- interpreter->string_reg = &chunk_base->SReg[chunk_base->used];
+ interpreter->string_reg = &chunk_base->SReg[chunk_base->used - 1];
}
/* Nope. So pitch a fit */
else {
@@ -152,7 +152,7 @@
/* Do so. We don't need to adjust used/free, since they're
already OK for the "We're full" case */
chunk_base = chunk_base->prev;
- interpreter->num_reg = &chunk_base->NReg[chunk_base->used];
+ interpreter->num_reg = &chunk_base->NReg[chunk_base->used - 1];
}
/* Nope. So pitch a fit */
else {
@@ -206,7 +206,7 @@
/* Do so. We don't need to adjust used/free, since they're
already OK for the "We're full" case */
chunk_base = chunk_base->prev;
- interpreter->pmc_reg = &chunk_base->PReg[chunk_base->used];
+ interpreter->pmc_reg = &chunk_base->PReg[chunk_base->used - 1];
}
/* Nope. So pitch a fit */
else {
Index: test_main.c
===================================================================
RCS file: /home/perlcvs/parrot/test_main.c,v
retrieving revision 1.4
diff -u -r1.4 test_main.c
--- test_main.c 2001/09/13 08:44:08 1.4
+++ test_main.c 2001/09/13 20:30:57
@@ -6,18 +6,18 @@
#include "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 */
- };
+int32_t 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) {
struct Perl_Interp *interpreter;