コード例 #1
0
 def deploy_output__filtered(self):
     filtered_var = NodeOutputVariableName(self.id, 'filtered')
     entry_var = NodeOutputVariableName(self.id, 'entry')
     index_var = NodeOutputVariableName(self.id, 'index')
     array_var = self.get_input_connection_variable_name('array')
     i_var = NodePrivateVariableName(self.id, 'i')
     return LanguageConcat(
         self.resolve_input_deploy('array'),
         VariableSetStatement(entry_var, LanguageNone()),
         VariableSetStatement(index_var, LanguageNone()),
         self.resolve_input_deploy_function('keep'),
         VariableSetStatement(filtered_var,
                              LanguageValue(EmptyArraySymbol())),
         SimpleLoopStatement(
             i_var, LanguageValue(0),
             LanguageValue(UtilsArrayLength(array_var)),
             LanguageConcat(
                 VariableSetStatement(index_var, i_var),
                 VariableSetStatement(entry_var,
                                      ArrayIndex(array_var, i_var)),
                 IfStatement(
                     FunctionCall(
                         self.get_input_connection_function_name('keep')),
                     VariableSetStatement(
                         filtered_var,
                         UtilsArrayConcat(filtered_var, entry_var))))))
コード例 #2
0
def deploy_test():
    loop_node = LoopNode()
    iter_node = IncrementNode()
    eq_node = EqualsNode()
    not_node = NotNode()
    var_node = VariableNode(0)
    split_node = DummyNode()
    add_node = AddNode()
    out_node = PassThroughNode()
    BaseNode.connect(loop_node, out_node, 'value', 'in')
    BaseNode.connect(split_node, loop_node, 'out', 'iter')
    BaseNode.connect(not_node, split_node, 'out', 'in')
    BaseNode.connect(eq_node, not_node, 'result', 'in')
    BaseNode.connect(iter_node, eq_node, 'increment', 'arg1')
    BaseNode.connect(DataSourceNode(50), eq_node, 'data', 'arg2')
    BaseNode.connect(var_node, loop_node, 'value', 'value')

    BaseNode.connect(var_node, split_node, 'update', 'extra')
    BaseNode.connect(add_node, var_node, 'result', 'value')
    BaseNode.connect(iter_node, add_node, 'value', 'arg1')
    BaseNode.connect(var_node, add_node, 'value', 'arg2')

    code = LanguageConcat(deploy(out_node, 'out'),
                          FunctionCall(VariableName('main')))
    print(code.__py__(DeployContext()))
コード例 #3
0
 def deploy_output__mapped(self):
     i_var = NodePrivateVariableName(self.id, 'i')
     entry_var = NodeOutputVariableName(self.id, 'entry')
     index_var = NodeOutputVariableName(self.id, 'index')
     mapped_var = NodeOutputVariableName(self.id, 'mapped')
     return LanguageConcat(
         self.resolve_input_deploy('array'),
         VariableSetStatement(entry_var, LanguageNone()),
         VariableSetStatement(index_var, LanguageNone()),
         self.resolve_input_deploy_function('value'),
         VariableSetStatement(
             mapped_var,
             UtilsArrayClone(
                 self.get_input_connection_variable_name('array'))),
         SimpleLoopStatement(
             i_var, LanguageValue(0),
             UtilsArrayLength(
                 self.get_input_connection_variable_name('array')),
             LanguageConcat(
                 VariableSetStatement(index_var, i_var),
                 VariableSetStatement(
                     entry_var,
                     ArrayIndex(
                         self.get_input_connection_variable_name('array'),
                         i_var)),
                 VariableSetStatement(
                     ArrayIndex(mapped_var, i_var),
                     FunctionCall(
                         self.get_input_connection_function_name(
                             'value'))))))
コード例 #4
0
 def deploy_output__out(self):
     return LanguageConcat(
         self.resolve_input_deploy('in'),
         VariableSetStatement(
             NodeOutputVariableName(self.id, 'out'),
             FunctionCall(VariableName('utils_type'),
                          self.get_input_connection_variable_name('in'))))
コード例 #5
0
    def deploy_output__selected(self):
        test_functions = []
        return_functions = []
        if_statements = []
        for n in range(self.condition_count):
            test_functions.append(self.resolve_input_deploy_function('test_%d' % n))
            return_functions.append(self.resolve_input_deploy_function('return_%d' % n))
            if_statements.append(
                IfStatement(
                    LanguageOperation(
                        CompareEqualsSymbol(),
                        FunctionCall(self.get_input_connection_function_name('test_%d' % n)),
                        self.get_input_connection_variable_name('value')
                    ),
                    VariableSetStatement(
                        NodeOutputVariableName(self.id, 'selected'),
                        FunctionCall(self.get_input_connection_function_name('return_%d' % n))
                    ),
                    if_type=('if' if n == 0 else 'elseif')
                )
            )
        return_functions.append(self.resolve_input_deploy_function('default'))
        if_statements.append(
            IfStatement(
                None,
                VariableSetStatement(
                    NodeOutputVariableName(self.id, 'selected'),
                    FunctionCall(self.get_input_connection_function_name('default'))
                ),
                if_type='else'
            )
        )

        return LanguageConcat(
            self.resolve_input_deploy('value'),
            *test_functions,
            *return_functions,
            VariableSetStatement(
                NodeOutputVariableName(self.id, 'selected'),
                LanguageNone()
            ),
            *if_statements
        )
コード例 #6
0
 def deploy_output__value(self):
     return LanguageConcat(
         self.resolve_input_deploy_function('iter'),
         ConditionalLoopStatement(
             FunctionCall(self.get_input_connection_function_name('iter')),
             LanguageNoop()
         ),
         self.resolve_input_deploy('value'),
         VariableSetStatement(
             NodeOutputVariableName(self.id, 'value'),
             self.get_input_connection_variable_name('value')
         )
     )
コード例 #7
0
 def deploy_output__reduced(self):
     array_var = self.get_input_connection_variable_name('array')
     i_var = NodePrivateVariableName(self.id, 'i')
     acc_var = NodeOutputVariableName(self.id, 'accumulator')
     cur_var = NodeOutputVariableName(self.id, 'current')
     return LanguageConcat(
         self.resolve_input_deploy('array'),
         VariableSetStatement(acc_var,
                              ArrayIndex(array_var, LanguageValue(0))),
         VariableSetStatement(cur_var, LanguageNone()),
         self.resolve_input_deploy_function('accumulator'),
         SimpleLoopStatement(
             i_var, LanguageValue(1), UtilsArrayLength(array_var),
             LanguageConcat(
                 VariableSetStatement(cur_var, ArrayIndex(array_var,
                                                          i_var)),
                 VariableSetStatement(
                     acc_var,
                     FunctionCall(
                         self.get_input_connection_function_name(
                             'accumulator'))))),
         VariableSetStatement(NodeOutputVariableName(self.id, 'reduced'),
                              acc_var))
コード例 #8
0
 def __es6__(self, c):
     return FunctionCall(VariableName('Math.pow'), self.base,
                         self.power).__es6__(c)
コード例 #9
0
 def __py__(self, c):
     return FunctionCall(VariableName(f'math.{self.func}'),
                         self.value).__py__(c)
コード例 #10
0
 def __py__(self, c):
     return FunctionCall(VariableName('abs'), self.value).__py__(c)
コード例 #11
0
 def __es6__(self, c):
     return FunctionCall(VariableName('Math.abs'), self.value).__es6__(c)
コード例 #12
0
 def __py__(self, c):
     return FunctionCall(VariableName('math.log'), self.value,
                         self.base).__py__(c)
コード例 #13
0
 def __es6__(self, c):
     return LanguageOperation(
         DivideSymbol(), FunctionCall(VariableName('Math.log'), self.value),
         FunctionCall(VariableName('Math.log'), self.base)).__es6__(c)
コード例 #14
0
 def __py__(self, c):
     return FunctionCall(
         VariableName('math.pow'), self.value,
         LanguageOperation(DivideSymbol(), LanguageValue(1),
                           self.root)).__py__(c)