Class: Rjq::BytecodeCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/rjq/compiler.rb

Instance Method Summary collapse

Constructor Details

#initialize(allow_comments: true, max_filter_depth: Parser::DEFAULT_MAX_FILTER_DEPTH) ⇒ BytecodeCompiler

Returns a new instance of BytecodeCompiler.



36
37
38
39
40
41
42
# File 'lib/rjq/compiler.rb', line 36

def initialize(allow_comments: true, max_filter_depth: Parser::DEFAULT_MAX_FILTER_DEPTH)
  @constants = []
  @constant_indices = {}
  @current_nodes = []
  @allow_comments = allow_comments
  @max_filter_depth = max_filter_depth
end

Instance Method Details

#compile(ast, module_metadata: {}, module_variables: {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/rjq/compiler.rb', line 44

def compile(ast, module_metadata: {}, module_variables: {})
  instructions = compile_node(ast.body)
  Rjq::Program.new(
    instructions: instructions,
    constants: @constants,
    definitions: ast.definitions.map { |definition| compile_definition(definition) },
    module_metadata: ,
    module_variables: module_variables
  )
end