Re: Draft switch for DO_OP() :-)
On Thu, Sep 20, 2001 at 11:11:42AM -0400, Dan Sugalski wrote: Actually the ops=C conversion was conceived to do exactly what's being done now--to abstract out the body of the opcodes so that they could be turned into a switch, or turned into generated machine code, or TIL'd. If you're finding that this isn't working well it's a sign we need to change things some so they will. (Better now than in six months...) The problem is that the conversion currently done by process_opcodes.pl translates the op definitions into functions, and leaves the remainder of the file untouched. This is useful, because it allows the opcode file to include headers, declare file-scope variables, and the like. Unfortunately, when translating the ops into a switch statement in a header file, there is no place to put this non-opcode code. There are a few approaches we can take. The simplest, I think, is to ignore the problem when generating inline ops; given that these ops are going to be compiled at Perl build time (they can never be dynamically loaded for obvious reasons), we can manually put any required #includes in interpreter.c. Files containing dynamically- loaded ops can be generated in the same way that process_opcodes.pl does now, preserving the file-scope code. Another approach would be to include a means of defining information that must be included by the file implementing the ops. For example: HEADER { #include math.h } This would then be placed into interp_guts.h. (Possibly surrounded by a conditional guard (#ifdef PARROT_OP_IMPLEMENTATION), so no file other than interpreter.h will pick up that code.) - Damien
Re: Draft switch for DO_OP() :-)
On Thu, Sep 20, 2001 at 11:11:42AM -0400, Dan Sugalski wrote: Actually the ops=C conversion was conceived to do exactly what's being done now--to abstract out the body of the opcodes so that they could be turned into a switch, or turned into generated machine code, or TIL'd. If you're finding that this isn't working well it's a sign we need to change things some so they will. (Better now than in six months...) The problem is that the conversion currently done by process_opcodes.pl translates the op definitions into functions, and leaves the remainder of the file untouched. This is useful, because it allows the opcode file to include headers, declare file-scope variables, and the like. Unfortunately, when translating the ops into a switch statement in a header file, there is no place to put this non-opcode code. I didn't have a problem with this. It just took some clever perl5 programming (namely outputting to separate streams and combining them at the very end). It's not fool-proof, but works for the important stuff (like includes / globals). There are a few approaches we can take. The simplest, I think, is to ignore the problem when generating inline ops; given that these ops are going to be compiled at Perl build time (they can never be dynamically loaded for obvious reasons), we can manually put any required #includes in interpreter.c. Files containing dynamically- loaded ops can be generated in the same way that process_opcodes.pl does now, preserving the file-scope code. Another approach would be to include a means of defining information that must be included by the file implementing the ops. For example: HEADER { #include math.h } This would then be placed into interp_guts.h. (Possibly surrounded by a conditional guard (#ifdef PARROT_OP_IMPLEMENTATION), so no file other than interpreter.h will pick up that code.) - Damien - /= |_ |_| /= /= \./
Re: Draft switch for DO_OP() :-)
At 12:07 AM 9/20/2001 -0700, Damien Neil wrote: I'm not at all certain what to do with things outside the opcodes themselves. The .ops = .c conversion was clearly originally concieved as translating one file into another. In order to dispatch ops via a switch, you need to pull out only the function contents; this makes the .ops file into a definition of function code only...the remainder of the file gets tossed by the wayside. Actually the ops=C conversion was conceived to do exactly what's being done now--to abstract out the body of the opcodes so that they could be turned into a switch, or turned into generated machine code, or TIL'd. If you're finding that this isn't working well it's a sign we need to change things some so they will. (Better now than in six months...) Dan --it's like this--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Re: Draft switch for DO_OP() :-)
On Thu, Sep 20, 2001 at 11:11:42AM -0400, Dan Sugalski wrote: Actually the ops=C conversion was conceived to do exactly what's being done now--to abstract out the body of the opcodes so that they could be turned into a switch, or turned into generated machine code, or TIL'd. If you're finding that this isn't working well it's a sign we need to change things some so they will. (Better now than in six months...) The problem is that the conversion currently done by process_opcodes.pl translates the op definitions into functions, and leaves the remainder of the file untouched. This is useful, because it allows the opcode file to include headers, declare file-scope variables, and the like. Unfortunately, when translating the ops into a switch statement in a header file, there is no place to put this non-opcode code. There are a few approaches we can take. The simplest, I think, is to ignore the problem when generating inline ops; given that these ops are going to be compiled at Perl build time (they can never be dynamically loaded for obvious reasons), we can manually put any required #includes in interpreter.c. Files containing dynamically- loaded ops can be generated in the same way that process_opcodes.pl does now, preserving the file-scope code. Another approach would be to include a means of defining information that must be included by the file implementing the ops. For example: HEADER { #include math.h } This would then be placed into interp_guts.h. (Possibly surrounded by a conditional guard (#ifdef PARROT_OP_IMPLEMENTATION), so no file other than interpreter.h will pick up that code.) - Damien
Re: Draft switch for DO_OP() :-)
At 01:08 PM 9/20/2001 -0700, Damien Neil wrote: Another approach would be to include a means of defining information that must be included by the file implementing the ops. For example: HEADER { #include math.h } This would then be placed into interp_guts.h. (Possibly surrounded by a conditional guard (#ifdef PARROT_OP_IMPLEMENTATION), so no file other than interpreter.h will pick up that code.) I like that approach. I'd say go for it--got time to put this in? Dan --it's like this--- Dan Sugalski even samurai [EMAIL PROTECTED] have teddy bears and even teddy bears get drunk
Draft switch for DO_OP() :-)
please see attached process_switch.pl notes inside. Very rough draft, but I think it does write a correct define ( but I might be clueless ). On the note of the enum for the case foo: Made it work, Gibbs has seen patch, but we wanted to defer to Dan/Simon because op.h has the knack of redefining every op as Parrot_op_foo. :-( so I suggested the enum fields and case be made something like add_i_op_idx. But certainly other things are possible. Heck, I'll attach the diff. Gibbs and I thought that the build_interp_starter and process_opfuncs perl files ought to be able to share more code, particularly since this submission is practically a copy of process_opfuncs, and the enum is trivially done inside build_interp_starter. However, we have not come to any decision on _where_ the shared code should go. Suggestions solicited. One bug: I can't quite deal gracefully with the #includes, I just nuke 'em and write them back, but the multi-line C-comment block at the top of basic_opcodes.ops is a pain. Eliminating it clobbers everything with a STRING * Better regexen solicited... Let me know what you think. Cheers. Michael -- Michael Fischer 7.5 million years to run [EMAIL PROTECTED]printf %d, 0x2a; -- deep thought process_switch.pl --- build_interp_starter.pl.bak Wed Sep 19 20:57:19 2001 +++ build_interp_starter.pl Wed Sep 19 21:42:35 2001 @@ -4,6 +4,7 @@ open INTERP, include/parrot/interp_guts.h or die Can't open include/parrot/interp_guts.h, $!/$^E; + print INTERP CONST; /* * @@ -27,6 +28,30 @@ # +# Write the enum of opcodes in order +# + +# +# this is failing when interpreter.c compiles, +#`Parrot_op_set_i_ic' redeclared as different kind of symbol +# + +print INTERP \n\n; +print INTERP enum {\n; + +my $names = + join ,\n, + map { \t$_ } + sort {$opcodes{$a}{CODE} = $opcodes{$b}{CODE}} + keys %opcodes; + +print INTERP $names, \n; + +print INTERP };\n\n; + + + +# # BUILD_NAME_TABLE macro: # @@ -54,12 +79,14 @@ print INTERP } while (0);\n; + + + # # Spit out the DO_OP function # print INTERP EOI; - #define DO_OP(w,x,y,z) do { \\ x = (void *)z-opcode_funcs; \\ y = (opcode_t* (*)())x[*w]; \\