|
Re: How to know where a BlockClosure finish: msg#00240lang.smalltalk.squeak.beginners
Hi Mathieu, I would go for a "complete" compiler for this... so let's explain a bit. (Hmm, Compilers, Parsers, Code Generation. Perfect Newby topics :-) So: If we look at the new compiler in Squeak, it works on single methods. For each method, it does - Scann / Parse to build up a Tree of objects that describe the code The root of the tree is RBProgramNode. (other node are e.g. RBSendNode, RBVariableNode... things like that). - Analyze the names of variables. The AST only known that "a" is a name... but it does not know what it means.. so is this a definition of a temp? Or a use of an existing temp? Or an iVar?. This analysis is done in the class ASTChecker - Code Generation. The analyzed AST is visited by the ASTTranslator to build a CompiledMethod obiect (using IRBuilder). This then is installed in a class. Ok. So for your Scripting system I would do the same: 1) Scann/Parse the input, build up a Tree 2) Analyse the tree (name analysis) 3) generate all the needed elements (methods, classes) 4) run. 1) Scann/Parse. Just re-use the existing Parser, extend the grammar to not parse one method, but a whole Script. The root-node of the AST would then be some "SqueakScriptNode". This has nodes for all classes that the script defined, and nodes for all methods (these will be normal RBMethodNodes). Then it has the code of the script that starts the whole thing as a special method (named #run). Keep in mind that this Tree-Representation of the Script has not yet added any methods or classes to the system. 2) Analyse. The RBMethodNodes needs to have the ASTChecker run so all variables are bound correctly. This pass could do other analysis things, if needed (don't know any) 3) Generation. Now we need to go through the Tree and generate the smalltalk things described in it. E.g. classes that are defined need to be created, we need to generate code from the RBMethodNodes and install the resulting CompiledMethod objects in the methodDict of the class that they are defined for. The code at the end of the script that is just run will be made a CompiledMethod, too. For the Script itself, at the beginnig it would be just a method that does not get installaled but just run. Later it might be interesting to have a "SqueakScript" object that is kind of like a Class but has no name... it could contain helper methods for parsing e.g. the command line, stuff like that. This could be implemented as a subclass of Behavior. The run method then would be installed in am instance of that. Hmm... Now I fear we are completely out of the Beginners' realm ;-) Please ask if you need more explanations... I'm sure this was a much too short explanation. Marcus
Beginners mailing list Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx http://lists.squeakfoundation.org/mailman/listinfo/beginners
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
|---|---|
| Next by Date: | Re: How to know where a BlockClosure finish, Mathieu |
| Previous by Thread: | RE: How to know where a BlockClosure finish, Ron Teitelbaum |
| Next by Thread: | Re: How to know where a BlockClosure finish, Mathieu |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |