Module: Klam::CompilationStages::ConvertLexicalVariables
- Included in:
- Klam::Compiler
- Defined in:
- lib/klam/compilation_stages/convert_lexical_variables.rb
Overview
Convert Lexical Variables
Lexically bound variable names are symbols in Kl. In Ruby, variable and parameter names are represented differently than symbol literals. The latter are indicated with a leading ‘:’ (e.g., :foo) and allow an extended set of characters when using the :“foo-bar” literal syntax. Ruby variables have no such provision for using additional characters.
Therefore, if lexical variables remain as symbols, the emission of Ruby code for symbols would be complicated by the need to differentiate between symbol literals and lexical variables and to transform Kl variable names to legal Ruby variable names. Instead, this stage converts lexical variables to instances of Klam::Variable. This is essentially alpha conversion and the names of Klam::Variable are generated to be locally unique and using only allowed Ruby variable names.
Alpha conversion also avoids potential problems when the let primitive is used to re-bind an already bound lexical var.
Instance Method Summary collapse
Instance Method Details
#convert_lexical_variables(sexp) ⇒ Object
22 23 24 |
# File 'lib/klam/compilation_stages/convert_lexical_variables.rb', line 22 def convert_lexical_variables(sexp) convert_lexical_vars(sexp, {}) end |