Module: Ikra::Symbolic::ArrayCommand

Included in:
ArrayIdentityCommand, ArrayMapCommand, ArrayNewCommand, ArraySelectCommand
Defined in:
lib/symbolic/symbolic.rb

Constant Summary collapse

@@unique_id =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#unique_idObject (readonly)

Fixnum

Returns a unique ID for this command. It is used during name mangling in the code generator to determine the name of array identifiers (and do other stuff?).



35
36
37
# File 'lib/symbolic/symbolic.rb', line 35

def unique_id
  @unique_id
end

Instance Method Details

#[](index) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/symbolic/symbolic.rb', line 47

def [](index)
    if @result == nil
        execute
    end
    
    @result[index]
end

#astObject

Returns the abstract syntax tree for a parallel section.



86
87
88
89
90
91
92
# File 'lib/symbolic/symbolic.rb', line 86

def ast
    # TODO: add caching for AST here
    # TODO: maybe set dummy class_owner here?
    parser_local_vars = block.binding.local_variables + block_parameter_names
    source = Parsing.parse_block(block, parser_local_vars)
    AST::Builder.from_parser_ast(source)
end

#block_parameter_namesArray(Symbol)

Returns a collection of the names of all block parameters.

Returns:



69
70
71
72
73
# File 'lib/symbolic/symbolic.rb', line 69

def block_parameter_names
    block.parameters.map do |param|
        param[1]
    end
end

#executeObject



55
56
57
# File 'lib/symbolic/symbolic.rb', line 55

def execute
    @result = Translator.translate_command(self).execute
end

#externalsObject

Returns a collection of external objects that are accessed within a parallel section.



111
112
113
# File 'lib/symbolic/symbolic.rb', line 111

def externals
    lexical_externals.keys
end

#initializeObject



39
40
41
42
43
44
45
# File 'lib/symbolic/symbolic.rb', line 39

def initialize
    super

    # Generate unique ID
    @unique_id = @@unique_id
    @@unique_id += 1
end

#lexical_externalsHash{Symbol => Object}

Returns a collection of lexical variables that are accessed within a parallel section.

Returns:



96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/symbolic/symbolic.rb', line 96

def lexical_externals
    all_lexical_vars = block.binding.local_variables
    lexical_vars_enumerator = AST::LexicalVariablesEnumerator.new(all_lexical_vars)
    ast.accept(lexical_vars_enumerator)
    accessed_variables = lexical_vars_enumerator.lexical_variables

    result = Hash.new
    for var_name in accessed_variables
        result[var_name] = block.binding.local_variable_get(var_name)
    end

    result
end

#pmap(&block) ⇒ Object



63
64
65
# File 'lib/symbolic/symbolic.rb', line 63

def pmap(&block)
    ArrayMapCommand.new(self, block)
end

#sizeFixnum

Returns the size (number of elements) of the result, after executing the parallel section.

Returns:

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/symbolic/symbolic.rb', line 77

def size
    raise NotImplementedError
end

#targetObject

Raises:

  • (NotImplementedError)


81
82
83
# File 'lib/symbolic/symbolic.rb', line 81

def target
    raise NotImplementedError
end

#to_commandObject



59
60
61
# File 'lib/symbolic/symbolic.rb', line 59

def to_command
    self
end