Sha256: 44bdd2d93076aa3a97eecb524db196e7ac088e1ef126a4a651083c884fba77de

Contents?: true

Size: 1.32 KB

Versions: 13

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.


[sexps]: https://github.com/opal/opal/tree/master/lib/opal/parser/sexp.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

13 entries across 13 versions & 1 rubygems

Version Path
opal-1.5.1 docs/compiler.md
opal-1.5.0 docs/compiler.md
opal-1.5.0.rc1 docs/compiler.md
opal-1.4.1 docs/compiler.md
opal-1.4.0 docs/compiler.md
opal-1.4.0.alpha1 docs/compiler.md
opal-1.3.2 docs/compiler.md
opal-1.3.1 docs/compiler.md
opal-1.3.0 docs/compiler.md
opal-1.3.0.rc1 docs/compiler.md
opal-1.3.0.alpha1 docs/compiler.md
opal-1.2.0 docs/compiler.md
opal-1.2.0.beta1 docs/compiler.md