Search for Pharo documentation for compilation and evaluation methods, etc. In the compiler class

I have a confusing simple question here. I am a little newbie (I try to argue with him every 5 years or so) and I have Pharo 6.1. How do I find the official standard library documentation? Especially for the compiler class? Things like compilation and evaluation methods? I don’t see how to search using the help browser, and the method comments in the compiler class are rather complicated and cryptic. I also don't see an obvious link to the documentation for the standard library APIs: http://pharo.org/documentation . The books Faro in Example and Deep in Faro do not seem to cover this class either. I assume the class is probably similar to Squeak and other small fonts, so a link to their documentation for the compiler class might also be useful.

Thanks!

+5
source share
3 answers

There are several classes that are involved in compiling a method (or expression), and given your interest in the subject, I am tempted to stimulate you even further in my study and understanding.

In general, the main classes are Scanner, Parser, Compiler, and Encoder. Depending on the dialect, they may have slightly different names and implementations, but the central idea remains the same.

The scanner analyzes the source code character stream and creates a stream of tokens. These tokens are then parsed, which converts them to AST nodes (abstract syntax tree). The compiler then visits the nodes of the AST to analyze them semantically. Here, all variable nodes are classified: method arguments, method temporary methods, general, blocking arguments, temporary locks, etc. It is during this analysis that all variables are bound in the corresponding area. At this stage, the AST is no longer "abstract" because it was annotated with the required information. Finally, the nodes are reviewed to generate the literal and bytecodes of the compiled method.

Of course, there are many things that I exclude from this summary (pragmas, blocking blocks, etc.), but with these basic ideas in mind, you should be prepared to debug a very simple example. For example, start with

Object compile: 'm ^3' 

to internalize the process.

After a step back and forth, you will reach the first interesting piece of code, which is the OpalCompiler >> #compile . If we remove the error handling blocks, these methods speak for themselves:

 compile | cm | ast := self parse. self doSemanticAnalysis. self callPlugins. cm := ast generate: self compilationContext compiledMethodTrailer ^cm 

First, we have a #parse message where analysis nodes are created. Then we have the semantic analysis that I mentioned above, and finally #generate: creates the encoding. You must debug each of these methods to understand the compilation process in depth. Given that you are dealing with a tree, you will be ready to navigate through many visitors.

Once you get familiar with the basic ideas, you can try more elaborate simple examples to see other objects in the scene.

+5
source

Here are some simple facts:

  • Evaluation in Smalltalk is available everywhere: in workspaces, in Transcript, in browsers, inspectors, debugger, etc. In principle, if you are allowed to edit the text, most likely you can also give an assessment.
  • There are 4 assessment teams

    • Do it (value without showing an answer)
    • Print it (evaluate and print the answer next to the expression)
    • Inspect it (evaluates and opens the inspector for the result)
    • Debug it (opens the debugger so that you can evaluate your expression step by step).
  • Your expression can contain any literal (numbers, arrays, strings, characters, etc.)

     17 "valid expression" 
  • Your expression can contain any message.

     3 + 4. 'Hello world' size. 1 bitShift: 28 
  • Your expression can use any global variable.

     Object new. Smalltalk compiler 
  • Your expression may refer to self , super , true , nil , false .

     SharedRandom globalGenerator next < 0.2 ifTrue: [nil] ifFalse: [self] 
  • Your expression can use any variables declared in the context of the area where you are writing. For instance:

    • If you write in the class browser, self will be bound to the current class
    • If you write to the inspector, self bound to the object being checked. You can also use your instance variables in an expression.
    • If you are in a debugger, your expression may refer to self , instance variables, message arguments, temporary files, etc.

enter image description here

  1. Finally, if you are in the workspace (aka playground), you can use any temporary files there that will be automatically created and saved, without the need to declare them.

enter image description here

+1
source

As far as I can tell, there is no API documentation for the standard Pharo library, for example, with other programming languages. This is similar to the confirmation on the Pharo user mailing list: http://forum.world.st/Essential-Documentation-td4916861.html

... there is an available version of the ANSI standard: http://wiki.squeak.org/squeak/uploads/172/standard_v1_9-indexed.pdf

... but this does not look like a compiler class.

0
source

Source: https://habr.com/ru/post/1275657/


All Articles