Sha256: 57500bbfac41496edea79bd51814eb0f2fab4a9e2158cc9d1086912bf18285bf

Contents?: true

Size: 1.32 KB

Versions: 9

Compression:

Stored size: 1.32 KB

Contents

# 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/Parser

The [opal parser][parser] relies on the `parser` gem, see debug/development documentation there to know more about its internals: https://whitequark.github.io/parser/.

### Code generation

The [opal compiler][compiler] takes these sexps from the parser
and generates ruby code from them. Each type of sexp has [its own node type][base-node]
used to generate javascript. Each node creates an array of one or more
[fragments][fragments] which are the concatenated 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.


[parser]: https://github.com/opal/opal/tree/master/lib/opal/parser.rb
[compiler]: https://github.com/opal/opal/tree/master/lib/opal/compiler.rb
[fragments]: https://github.com/opal/opal/tree/master/lib/opal/fragment.rb
[base-node]: https://github.com/opal/opal/tree/master/lib/opal/nodes/base.rb

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 docs/compiler.md
opal-1.8.2 docs/compiler.md
opal-1.8.1 docs/compiler.md
opal-1.8.0 docs/compiler.md
opal-1.8.0.beta1 docs/compiler.md
opal-1.7.4 docs/compiler.md
opal-1.8.0.alpha1 docs/compiler.md
opal-1.7.3 docs/compiler.md
opal-1.7.2 docs/compiler.md