Okay, here's a partial PDD on internal bytecode generation. This is *very* sketchy--at the moment it's just an enumeration of the functionality we'll need,as I see it. Take a look at this, and see where things might be missing or unclear. Once we've hashed out the desired functionality, I'll rough out the internal functions and opcodes for this. (Since we'll need to do this both from C code and from bytecode) ====================Cut here with a very sharp knife======== =head1 TITLE Dynamic Bytecode Generation =head1 VERSION =head2 CURRENT Maintainer: Dan Sugalski Class: Internals PDD Number: TBD Version: 1.0 Status: Tentative Last Modified: 26, 2002 PDD Format: 1 Language: English =head2 HISTORY =over 4 =item version 1 None. First version =back =head1 CHANGES =over 4 =item Version 1.0 None. First version =back =head1 ABSTRACT This PDD describes the facilities Parrot has to dynamically create bytecode. =head1 DESCRIPTION The bytecode segments can hold more than just bytecode. They can also hold the source that corresponds to the generated bytecode, the AST for the source that corresponds to the generated bytecode, the line number information for the generated bytecode (for error reporting), and potentially some pieces of raw binary data, both for program needs and potential future expansion. When generating bytecode, the following actions are needed: =over 4 =item Create new bytecode segment This function is needed to create a new segment of bytecode. The segment isn't, at this point, ready to use. =item Add source code to segment This adds a line or more of source code to the bytecode segment. =item Add AST to segment This adds the AST for some of the source code to the bytecode segment. =item Add line number information This adds line number info to the bytecode segment, allowing the interpreter to find out what line of source a particular piece of bytecode corresponds to. =item Add bytecode to segment Add in actual bytecode to the segment. =item Add constants (string, PMC, and float) Add one or more constants to the bytecode constant pool =item Add symbols to segment Add in symbolic information to the bytecode segment, including exported variables, classes, and functions =item Add binary data chunk to segment Add in some raw binary data to the bytecode segment =item Put segment into use Actually use the bytecode segment. Loads it into the interpreter and makes it ready for use. This needs to be an explicit step both so the interpreter can get itself ready for the code (if it needs to) and so the bytecode segment can be put in immoveable memory. (Since the interpreter may well have a copying garbage collector in place) =item Dump segment Dump out the segment to a filehandle. =back =head1 IMPLEMENTATION =head1 ATTACHMENTS =head1 FOOTNOTES =head1 REFERENCES -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunkThread Next