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()))
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'))))))
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))))))
def deploy_output__value(self): value_var = NodeOutputVariableName(self.id, 'value') return LanguageConcat( self.resolve_input_deploy('condition'), IfStatement( self.get_input_connection_variable_name('condition'), LanguageConcat( self.resolve_input_deploy('if'), VariableSetStatement( value_var, self.get_input_connection_variable_name('if') ) ) ), IfStatement( None, LanguageConcat( self.resolve_input_deploy('else'), VariableSetStatement( value_var, self.get_input_connection_variable_name('else') ) ) ) )
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'))))
def deploy_output__index(self): return LanguageConcat( self.resolve_input_deploy('array'), self.resolve_input_deploy('search'), VariableSetStatement( NodeOutputVariableName(self.id, 'index'), UtilsArrayIndexOf( self.get_input_connection_variable_name('array'), self.get_input_connection_variable_name('search'), )))
def deploy_output__increment(self): increment_var = NodeOutputVariableName(self.id, 'increment') return LanguageConcat( self.deploy_state_init('value', LanguageValue(0)), VariableSetStatement( increment_var, LanguageOperation(AddSymbol(), self.deploy_state_value('value'), LanguageValue(1))), self.deploy_state_update('value', increment_var))
def resolve_deploy(self, name): node_entry = self.extended_outputs[name] previous_deploys = [] for input_name in self.extended_inputs: self.extended_inputs[input_name][ 2].data = self.get_input_connection_variable_name(input_name) previous_deploys.append(self.resolve_input_deploy(input_name)) return LanguageConcat( *previous_deploys, node_entry[0].resolve_deploy(node_entry[1]), VariableSetStatement( NodeOutputVariableName(self.id, name), NodeOutputVariableName(node_entry[0].id, node_entry[1])))
def deploy_output__value(self): num_var = self.get_input_connection_variable_name('number') value_var = NodeOutputVariableName(self.id, 'value') if_statements = [] for n in range(self.count): if_statements.append( IfStatement(LanguageOperation(CompareEqualsSymbol(), num_var, LanguageValue(n)), LanguageConcat( self.resolve_input_deploy(f'in_{n}'), VariableSetStatement( value_var, self.get_input_connection_variable_name( f'in_{n}'))), if_type='if' if n == 0 else 'elseif' if n != self.count - 1 else 'else')) return LanguageConcat(self.resolve_input_deploy('number'), VariableSetStatement(value_var, LanguageNone()), *if_statements)
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') ) )
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))
def deploy_output__array(self): return LanguageConcat( self.resolve_input_deploy('array'), self.resolve_input_deploy('slice_start', allow_unconnected=True), self.resolve_input_deploy('slice_end', allow_unconnected=True), self.resolve_input_deploy('slice_step', allow_unconnected=True), VariableSetStatement( NodeOutputVariableName(self.id, 'array'), UtilsArraySlice( self.get_input_connection_variable_name('array'), self.get_input_connection_variable_name( 'slice_start', allow_unconnected=True), self.get_input_connection_variable_name( 'slice_end', allow_unconnected=True), self.get_input_connection_variable_name( 'slice_step', allow_unconnected=True), )))
def deploy_output__merged(self): merged_var = NodeOutputVariableName(self.id, 'merged') input_deploys = [] input_concats = [] for n in range(self.array_count): input_deploys.append(self.resolve_input_deploy('in_%d' % n)) input_concats.append( VariableSetStatement( merged_var, UtilsArrayConcat(merged_var, self.get_input_connection_variable_name('in_%d' % n)) ) ) return LanguageConcat( *input_deploys, VariableSetStatement(merged_var, LanguageValue(EmptyArraySymbol())), *input_concats )
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 )
def deploy_output__object(self): object_var = NodeOutputVariableName(self.id, 'object') input_deploys = [] input_sets = [] for n in range(self.property_count): input_deploys.append(self.resolve_input_deploy('key_%d' % n)) input_deploys.append(self.resolve_input_deploy('value_%d' % n)) input_sets.append( VariableSetStatement( ArrayIndex( object_var, self.get_input_connection_variable_name('key_%d' % n) ), self.get_input_connection_variable_name('value_%d' % n) ) ) return LanguageConcat( *input_deploys, VariableSetStatement( object_var, LanguageValue(EmptyDictSymbol()) ), *input_sets )
def deploy_output__out(self, env): return LanguageConcat( self.resolve_input_deploy('in'), VariableSetStatement( NodeOutputVariableName(self.id, 'out'), self.dep_func(self.get_input_connection_variable_name('in'))))
def deploy_output__value(self): return LanguageConcat( self.deploy_state_init('value', LanguageValue(0)), VariableSetStatement(NodeOutputVariableName(self.id, 'value'), self.deploy_state_value('value')))
def deploy_output__out(self): return LanguageConcat( self.resolve_input_deploy('in'), VariableSetStatement( NodeOutputVariableName(self.id, 'out'), ParseFloatCall(self.get_input_connection_variable_name('in'))))