All -- I wanted to have a unified op func, name, argc and argtype[] member in the interpreter struct, and that led me to make all the changes in this patch. I don't know if I've gone too far, but DO_OP is simpler now, and things still seem to run for me. Anyone else interested in trying this out? Dan? Does this fly in the face of your overall design, or is this a good thing? 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 \_____________________________________________________________________/
? ;q ? op_info.patch ? t/inc.pasm ? t/jumpoob.pasm ? t/jumpsub.pasm ? t/substr.pasm ? t/jump2.pasm ? t/jump3.pasm ? t/jump4.pasm ? t/runoob.pasm ? t/test.pbc.x ? t/op/integer8.pasm ? t/op/integer8.out ? t/op/integer9.pasm ? t/op/integer9.out ? t/op/integer10.pasm ? t/op/integer10.out ? t/op/integer11.pasm ? t/op/integer11.out ? t/op/integer12.pasm ? t/op/integer12.out ? t/op/integer13.pasm ? t/op/integer13.out ? t/op/integer14.pasm ? t/op/integer14.out ? t/op/integer15.pasm ? t/op/integer15.out ? t/op/integer16.pasm ? t/op/integer16.out ? t/op/integer17.pasm ? t/op/integer17.out ? t/op/integer18.pasm ? t/op/integer18.out ? t/op/integer19.pasm ? t/op/integer19.out ? t/op/integer20.pasm ? t/op/integer20.pbc ? t/op/integer20.out ? t/op/number6.pasm ? t/op/number6.out ? t/op/number7.pasm ? t/op/number7.out ? t/op/number8.pasm ? t/op/number8.out ? t/op/number9.pasm ? t/op/number9.out ? t/op/number10.pasm ? t/op/number10.out ? t/op/number11.pasm ? t/op/number11.out ? t/op/number12.pasm ? t/op/number12.out ? t/op/number13.pasm ? t/op/number13.out ? t/op/number14.pasm ? t/op/number14.out ? t/op/number15.pasm ? t/op/number15.out ? t/op/number16.pasm ? t/op/number16.out ? t/op/number17.pasm ? t/op/number17.out ? t/op/number18.pasm ? t/op/number18.pbc ? t/op/number18.out Index: build_interp_starter.pl =================================================================== RCS file: /home/perlcvs/parrot/build_interp_starter.pl,v retrieving revision 1.11 diff -u -r1.11 build_interp_starter.pl --- build_interp_starter.pl 2001/09/19 20:05:06 1.11 +++ build_interp_starter.pl 2001/09/19 22:20:19 @@ -2,6 +2,9 @@ use strict; use Parrot::Opcode; +my %opcodes = Parrot::Opcode::read_ops(); +my $opcode_fingerprint = Parrot::Opcode::fingerprint(); + open INTERP, "> include/parrot/interp_guts.h" or die "Can't open include/parrot/interp_guts.h, $!/$^E"; print INTERP <<CONST; @@ -14,57 +17,35 @@ * Best not edit it */ -#define BUILD_TABLE(x) do { \\ +op_info_table_t builtin_op_info_table = { + /* TODO: (void *) casting here sucks! */ CONST -my %opcodes = Parrot::Opcode::read_ops(); -my $opcode_fingerprint = Parrot::Opcode::fingerprint(); - for my $name (sort {$opcodes{$a}{CODE} <=> $opcodes{$b}{CODE}} keys %opcodes) { - print INTERP "\tx[$opcodes{$name}{CODE}] = (void*)$name; \\\n"; -} -print INTERP "} while (0);\n"; + printf INTERP " { (void *)%-12s, %-14s, %d, { ", + $name, "\"$name\"", $opcodes{$name}{ARGS}; - -# -# BUILD_NAME_TABLE macro: -# - -print INTERP <<CONST; -#define BUILD_NAME_TABLE(x) do { \\ -CONST + if ($opcodes{$name}{ARGS}) { + printf INTERP " %-18s }", join(", ", map { "'$_'" } @{$opcodes{$name}{TYPES}}); + } else { + printf INTERP " %-18s }", "'*'"; + } -for my $name (sort {$opcodes{$a}{CODE} <=> $opcodes{$b}{CODE}} keys %opcodes) { - print INTERP "\tx[$opcodes{$name}{CODE}] = \"$name\"; \\\n"; -} -print INTERP "} while (0);\n"; - - -# -# BUILD_ARG_TABLE macro: -# - -print INTERP <<CONST; -#define BUILD_ARG_TABLE(x) do { \\ -CONST - -for my $name (sort {$opcodes{$a}{CODE} <=> $opcodes{$b}{CODE}} keys %opcodes) { - print INTERP "\tx[$opcodes{$name}{CODE}] = $opcodes{$name}{ARGS}; \\\n"; + printf INTERP " }, /* %4d */\n", $opcodes{$name}{CODE}; } -print INTERP "} while (0);\n"; +print INTERP "};\n\n"; # # Spit out the DO_OP function # +# w = code +# z = interpreter +# print INTERP <<EOI; -#define DO_OP(w,x,y,z) do { \\ - x = (void *)z->opcode_funcs; \\ - y = (opcode_t* (*)())x[*w]; \\ - w = (y)(w,z); \\ - } while (0); +#define DO_OP(PC,INTERP) PC = ((INTERP->opcode_info)[*PC].func)(PC,INTERP); EOI # Spit out the OPCODE_FINGERPRINT macro Index: interpreter.c =================================================================== RCS file: /home/perlcvs/parrot/interpreter.c,v retrieving revision 1.18 diff -u -r1.18 interpreter.c --- interpreter.c 2001/09/19 20:05:06 1.18 +++ interpreter.c 2001/09/19 22:20:19 @@ -13,9 +13,10 @@ #include "parrot/parrot.h" #include "parrot/interp_guts.h" -char *op_names[2048]; -int op_args[2048]; +/* char * op_names[2048]; */ +/* op_t op_info[2048]; */ + /*=for api interpreter check_fingerprint * TODO: Not really part of the API, but here's the docs. * Check the bytecode's opcode table fingerprint. @@ -46,16 +47,10 @@ */ opcode_t * runops_notrace_core (struct Parrot_Interp *interpreter, opcode_t *code, IV code_size) { - /* Move these out of the inner loop. No need to redeclare 'em each - time through */ - opcode_t *(*func)(); - void **temp; - opcode_t *code_start; - - code_start = code; + opcode_t * code_start = code; while (code >= code_start && code < (code_start + code_size) && *code) { - DO_OP(code, temp, func, interpreter); + DO_OP(code, interpreter); } return code; @@ -67,14 +62,16 @@ * and ARGS. Used by runops_trace. */ void -trace_op(opcode_t * code_start, long code_size, opcode_t *code) { +trace_op(struct Parrot_Interp * interpreter, opcode_t * code_start, long code_size, +opcode_t *code) { 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]) { + fprintf(stderr, "PC=%ld; OP=%ld (%s)", (long)(code - code_start), *code, + interpreter->opcode_info[*code].name); + + if (interpreter->opcode_info[*code].nargs) { fprintf(stderr, "; ARGS=("); - for(i = 0; i < op_args[*code]; i++) { + for(i = 0; i < interpreter->opcode_info[*code].nargs; i++) { if (i) { fprintf(stderr, ", "); } fprintf(stderr, "%ld", *(code + i + 1)); } @@ -93,20 +90,14 @@ */ opcode_t * runops_trace_core (struct Parrot_Interp *interpreter, opcode_t *code, IV code_size) { - /* Move these out of the inner loop. No need to redeclare 'em each - time through */ - opcode_t *(*func)(); - void **temp; - opcode_t *code_start; - - code_start = code; + opcode_t * code_start = code; - trace_op(code_start, code_size, code); + trace_op(interpreter, code_start, code_size, code); while (code >= code_start && code < (code_start + code_size) && *code) { - DO_OP(code, temp, func, interpreter); + DO_OP(code, interpreter); - trace_op(code_start, code_size, code); + trace_op(interpreter, code_start, code_size, code); } return code; @@ -211,18 +202,8 @@ /* Need an empty stash */ interpreter->perl_stash = mem_allocate_new_stash(); - /* The default opcode function table would be a good thing here... */ - { - void **foo; - foo = mem_sys_allocate(2048 * sizeof(void *)); - - BUILD_TABLE(foo); - - interpreter->opcode_funcs = (void*)foo; - - BUILD_NAME_TABLE(op_names); - BUILD_ARG_TABLE(op_args); - } + /* Load the building op info table */ + interpreter->opcode_info = builtin_op_info_table; /* In case the I/O system needs something */ Init_IO(interpreter); Index: include/parrot/interpreter.h =================================================================== RCS file: /home/perlcvs/parrot/include/parrot/interpreter.h,v retrieving revision 1.3 diff -u -r1.3 interpreter.h --- include/parrot/interpreter.h 2001/09/19 20:04:45 1.3 +++ include/parrot/interpreter.h 2001/09/19 22:20:19 @@ -15,6 +15,18 @@ #include "parrot/parrot.h" + +typedef opcode_t *(*op_func_t)(); /* NOTE: Sure wish we could put the types here... */ + +typedef struct { + op_func_t func; + char * name; + IV nargs; + char types[5]; +} op_info_t; + +typedef op_info_t op_info_table_t[2048]; + struct Parrot_Interp { struct IReg *int_reg; /* Current top of int reg stack */ struct NReg *num_reg; /* Current top of the float reg stack */ @@ -32,11 +44,16 @@ /* interpreter's arena */ opcode_t *(*(*opcode_funcs)[2048])(); /* Opcode */ /* function table */ + + op_info_t * opcode_info; /* Opcode info (name, nargs, arg types) */ + /* TODO: Why not 'op_info_table_t +opcode_info'? */ + STRING_FUNCS *(*(*string_funcs)[64])(); /* String function table */ IV flags; /* Various interpreter flags that signal that runops should do something */ }; + #define PARROT_DEBUG_FLAG 0x01 /* Bit in the flags that says we're debugging */