-
-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some basic docs on compiler parts
- v1.8.3.rc1
- v1.8.2
- v1.8.1
- v1.8.0
- v1.8.0.beta1
- v1.8.0.alpha1
- v1.7.4
- v1.7.3
- v1.7.2
- v1.7.1
- v1.7.0
- v1.7.0.rc1
- v1.6.1
- v1.6.0
- v1.6.0.rc1
- v1.6.0.alpha1
- v1.5.1
- v1.5.0
- v1.5.0.rc1
- v1.4.1
- v1.4.0
- v1.4.0.alpha1
- v1.3.2
- v1.3.1
- v1.3.0
- v1.3.0.rc1
- v1.3.0.alpha1
- v1.2.0
- v1.2.0.beta1
- v1.1.1
- v1.1.1.rc1
- v1.1.0
- v1.1.0.rc1
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0.beta1
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.1.pre
- v0.11.0
- v0.11.0.rc1
- v0.10.6
- v0.10.6.beta
- v0.10.5
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.10.0.rc2
- v0.10.0.rc1
- v0.10.0.beta5
- v0.10.0.beta4
- v0.10.0.beta3
- v0.10.0.beta2
- v0.10.0.beta1
- v0.9.4
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.9.0.rc1
- v0.9.0.beta2
- v0.9.0.beta1
- v0.8.1
- v0.8.1.rc1
- v0.8.0
- v0.8.0.rc3
- v0.8.0.rc2
- v0.8.0.rc1
- v0.8.0.beta1
- v0.7.2
- v0.7.1
- v0.7.0
- v0.7.0.rc1
- v0.7.0.beta3
- v0.7.0.beta2
- v0.7.0.beta1
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.0.1-alpha.1
- npm-0.0.1-alpha.8
- npm-0.0.1-alpha.7
- npm-0.0.1-alpha.6
- npm-0.0.1-alpha.5
- npm-0.0.1-alpha.4
- npm-0.0.1-alpha.3
- lerna-0.0.1-alpha.2
1 parent
492db0c
commit 1c052ec
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Opal Compiler | ||
|
||
Opal is a source to source compiler. It accepts ruby code as a string and | ||
generates javascript code which can be run in any environment. Generated | ||
code relies on the opal runtime which provides the class system and some | ||
other runtime helpers. | ||
|
||
## Compiler stages | ||
|
||
The compiler can be broken down into 3 separate stages: | ||
|
||
* lexing | ||
* parsing | ||
* code generation | ||
|
||
### Lexer | ||
|
||
The [opal lexer](../lib/opal/parser/lexer.rb) is implemented in pure ruby using | ||
the `StringScanner` class from the opal stdlib. The source code is scanned | ||
and tokens are then provided to the parser. This process simply converts | ||
the ruby code given as a string, into a list of tokens representing the | ||
parts of the ruby code. | ||
|
||
### Parser | ||
|
||
The [opal parser](../lib/opal/parser/grammar.y) is implemented using a standard | ||
bison like syntax, but relies on `racc`, a ruby implementation of yacc/bison | ||
which is again available in the standard library. The parser takes these tokens | ||
generated by the lexer and builds a syntax tree representing the ruby code. | ||
This syntax tree is represented by [sexps](../lib/opal/parser/sexp.rb). As | ||
ruby is such a complex and dynamic language, there is a lot of interaction | ||
between the parser and the lexer, namely through a preserved `lex_state`. | ||
|
||
### Code generation | ||
|
||
The [opal compiler](../lib/opal/compiler.rb) takes these sexps from the parser | ||
and generates ruby code from them. Each type of sexp has [its own node type](../lib/opal/nodes/base.rb) | ||
used to generate javascript. Each node creates an array of one or more | ||
[fragments](../lib/opal/fragment.rb) which are the concatendated together to | ||
form the final javascript. Fragments are used as they contain the generated | ||
code as well as a reference back to the original sexp which is useful for | ||
generating source maps afterwards. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters