Salome HOME
Small changes to yacsdecorator. V9_8_0a1 V9_8_0a2
authorOvidiu MIRCESCU <ovidiu.mircescu@edf.fr>
Mon, 14 Jun 2021 09:07:18 +0000 (11:07 +0200)
committerOvidiu MIRCESCU <ovidiu.mircescu@edf.fr>
Thu, 7 Oct 2021 13:08:55 +0000 (15:08 +0200)
src/py2yacs/Test/example_while.py
src/py2yacs/Test/formule.py
src/py2yacs/Test/testDeco.py
src/py2yacs/Test/testforeach.py
src/py2yacs/yacsdecorator.py

index b68d57b5703115ad3598b0faccf9ec3f52b80751..c28d543c9ecae63cdfe25de3621baf9292895111 100644 (file)
@@ -34,20 +34,20 @@ def g(a, b):
     cond = r < 100
     return cond, r
 
-@yacsdecorator.bloc
-def while_bloc(context):
+@yacsdecorator.block
+def while_block(context):
     a = f1(context)
     b = f2(context)
     cond, r = g(a,b)
     return cond, r
 
-@yacsdecorator.bloc
+@yacsdecorator.block
 def main():
     v = extra_init()
     x = yacsdecorator.whileloop(while_func, v)
     post(x)
     yacsdecorator.whileloop(while_func, 3)
-    r = yacsdecorator.whileloop(while_bloc, 1)
+    r = yacsdecorator.whileloop(while_block, 1)
     print("r final:", r)
 
 if __name__ == "__main__" :
index eba73c6217d0a1f0b2d230cecba08fcdb927ca08..4e182483497912508960f76782cf4b27f833473a 100755 (executable)
@@ -17,7 +17,7 @@ def f3(x, y):
   p = x*y
   return s,p
 
-@yacsdecorator.bloc
+@yacsdecorator.block
 def b1():
   x = f1(x=3,y=4)
   a,b = f3(x, 2)
index 588c7ab13a9a0373b08508ffd64ac9be7dd8e688..2585f8373a14e341646ddd94ed3022c7da0c05ee 100755 (executable)
@@ -86,11 +86,11 @@ class TestDeco(unittest.TestCase):
       Foreach initialized by value.
       """
       import testforeach
-      expected_1, expected_2 = testforeach.mainbloc()
+      expected_1, expected_2 = testforeach.mainblock()
       yacs_schema_file = os.path.join(dir_test, "schema_t2.xml")
       yacs_build_command = "yacsbuild.py"
       test_script = "testforeach.py"
-      main_function_name = "mainbloc"
+      main_function_name = "mainblock"
       subprocess.run([yacs_build_command,
                       test_script, main_function_name, yacs_schema_file])
       l = loader.YACSLoader()
@@ -149,7 +149,7 @@ def f_def(x,y):
   d = x - y
   return d
 
-@yacsdecorator.bloc
+@yacsdecorator.block
 def main():
   s1 = f_c1(3,4)
   p1 = f_c2(5,6)
index 5df0dfec50eea0958b5003430e6d8a683792bdaf..fd5b989aa8007b50d3f3c8bcf1ec01c6e7946b49 100755 (executable)
@@ -44,16 +44,16 @@ def post(t):
     s += e
   return s
 
-@yacsdecorator.bloc
-def mainbloc():
+@yacsdecorator.block
+def mainblock():
   return fr(range(10))
 
-@yacsdecorator.bloc
+@yacsdecorator.block
 def maindoublefr():
   vals = [ list(range(x)) for x in range(10)]
   return doublefr(vals)
 
-@yacsdecorator.bloc
+@yacsdecorator.block
 def main():
   vals = jdd()
   result = fr2(vals)
index 2aa4dc023ff581be0080292fa7278d8c4499f183..1d785faac8154c9bc72f93279c7f4f80cefb47ff 100644 (file)
@@ -167,7 +167,7 @@ class SchemaGenerator():
     self.pyobjtype = self.runtime.getTypeCode("pyobj")
     self.seqpyobjtype = self.runtime.getTypeCode("seqpyobj")
     self.booltype = self.runtime.getTypeCode("bool")
-    self.bloc_stack = [self.proc]
+    self.block_stack = [self.proc]
     self.name_index = 0 # used to ensure unique names
     self.container_manager = ContainerManager()
 
@@ -185,9 +185,9 @@ class SchemaGenerator():
 
   def getContextName(self):
     context_name = ""
-    if len(self.bloc_stack) > 1:
+    if len(self.block_stack) > 1:
       # We are in a block
-      block_path = ".".join([ b.getName() for b in self.bloc_stack[1:] ])
+      block_path = ".".join([ b.getName() for b in self.block_stack[1:] ])
       context_name = block_path + "."
     return context_name
 
@@ -255,7 +255,7 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
     new_node.setContainer(container)
     new_node.setExecutionMode("remote")
     new_node.setScript(script)
-    self.bloc_stack[-1].edAddChild(new_node)
+    self.block_stack[-1].edAddChild(new_node)
     # create ports
     for p in inputs:
       new_node.edAddInputPort(p, self.pyobjtype)
@@ -282,9 +282,9 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
     foreach_name = self.newName(fn_name)
     new_foreach = self.runtime.createForEachLoopDyn(foreach_name,
                                                     self.pyobjtype)
-    self.bloc_stack[-1].edAddChild(new_foreach)
-    bloc_name = "bloc_"+foreach_name
-    new_block = self.runtime.createBloc(bloc_name)
+    self.block_stack[-1].edAddChild(new_foreach)
+    block_name = "block_"+foreach_name
+    new_block = self.runtime.createBloc(block_name)
     new_foreach.edAddChild(new_block)
     sample_port = new_foreach.edGetSamplePort()
     input_list_port = new_foreach.edGetSeqOfSamplesPort()
@@ -303,20 +303,20 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
       conversion_node.setExecutionMode("local") # no need for container
       # no script, the same variable for input and output
       conversion_node.setScript("")
-      self.bloc_stack[-1].edAddChild(conversion_node)
+      self.block_stack[-1].edAddChild(conversion_node)
       input_values.linkTo(input_port, conversion_node, self)
       self.proc.edAddLink(output_port, input_list_port)
       # No need to look for ancestors. Both nodes are on the same level.
       self.proc.edAddCFLink(conversion_node, new_foreach)
     else:
       input_list_port.edInitPy(list(input_values))
-    self.bloc_stack.append(new_foreach)
-    self.bloc_stack.append(new_block)
+    self.block_stack.append(new_foreach)
+    self.block_stack.append(new_block)
     return OutputPort(new_foreach, sample_port)
 
   def endForeach(self, outputs):
-    self.bloc_stack.pop() # remove the block
-    for_each_node = self.bloc_stack.pop() # remove the foreach
+    self.block_stack.pop() # remove the block
+    for_each_node = self.block_stack.pop() # remove the foreach
     converted_ret = None
     if outputs is not None:
       # We need a conversion node seqpyobj -> pyobj
@@ -329,7 +329,7 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
                                                       conversion_node_name)
       conversion_node.setExecutionMode("local") # no need for container
       conversion_node.setScript("")
-      self.bloc_stack[-1].edAddChild(conversion_node)
+      self.block_stack[-1].edAddChild(conversion_node)
       list_ret = []
       idx_name = 0 # for unique port names
       for port in list_out :
@@ -369,7 +369,7 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
   def beginWhileloop(self, fn_name, context):
     whileloop_name = self.newName("whileloop_"+fn_name)
     while_node = self.runtime.createWhileLoop(whileloop_name)
-    self.bloc_stack[-1].edAddChild(while_node)
+    self.block_stack[-1].edAddChild(while_node)
     if not self.isAManagedPort(context):
       # create a init node in order to get a port for the context
       indata_name = "Inputdata_" + whileloop_name
@@ -378,19 +378,19 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
       indata_outport = indata_node.edAddOutputPort("context", self.pyobjtype)
       indata_inport.edInitPy(context)
       context = OutputPort(indata_node, indata_outport)
-      self.bloc_stack[-1].edAddChild(indata_node)
+      self.block_stack[-1].edAddChild(indata_node)
 
-    bloc_name = "bloc_"+whileloop_name
-    new_block = self.runtime.createBloc(bloc_name)
+    block_name = "block_"+whileloop_name
+    new_block = self.runtime.createBloc(block_name)
     while_node.edAddChild(new_block)
-    self.bloc_stack.append(while_node)
-    self.bloc_stack.append(new_block)
+    self.block_stack.append(while_node)
+    self.block_stack.append(new_block)
     self.proc.edAddCFLink(context.getNode(), while_node)
     ret = OutputPortWithCollector(context)
     return ret
 
   def endWhileloop(self, condition, collected_context, loop_result):
-    while_node = self.bloc_stack[-2]
+    while_node = self.block_stack[-2]
     cport = while_node.edGetConditionPort()
     # need a conversion node pyobj -> bool
     conversion_node = self.runtime.createScriptNode("Salome",
@@ -400,14 +400,14 @@ study_function = yacstools.getFunction("{file_path}", "{function_name}")
     port_name = "val"
     input_port = conversion_node.edAddInputPort(port_name, self.pyobjtype)
     output_port = conversion_node.edAddOutputPort(port_name, self.booltype)
-    self.bloc_stack[-1].edAddChild(conversion_node)
+    self.block_stack[-1].edAddChild(conversion_node)
     condition.linkTo(input_port, conversion_node, self)
     self.proc.edAddLink(output_port, cport)
     if not loop_result is None:
       for p in collected_context.connectedPorts():
         self.proc.edAddLink(loop_result.getPort(), p)
-    self.bloc_stack.pop() # remove the block
-    self.bloc_stack.pop() # remove the while node
+    self.block_stack.pop() # remove the block
+    self.block_stack.pop() # remove the while node
 
 _generator = None
 
@@ -485,17 +485,27 @@ def leaf(arg):
     ret = LeafDecorator(arg)
   return ret
 
-def bloc(f):
+def block(f):
   """
-  Decorator for blocs.
+  Decorator for blocks.
   """
   #co = f.__code__
-  #print("bloc :", co.co_name)
+  #print("block :", co.co_name)
   #print("  file:", co.co_filename)
   #print("  line:", co.co_firstlineno)
   #print("  args:", co.co_varnames)
   return f
 
+def seqblock(f):
+  """
+  Decorator for sequential blocks.
+  """
+  if this_module._exec_mode == this_module._yacs_mode:
+  # TODO create a new block and set a flag to add dependencies between
+  # nodes in the block
+    pass
+  return f
+
 def default_foreach(f):
   def my_func(lst):
     result = []
@@ -532,7 +542,7 @@ def yacs_foreach(f):
 
 def foreach(f):
   """
-  Decorator to generate foreach blocs
+  Decorator to generate foreach blocks
   """
   if this_module._exec_mode == this_module._default_mode:
     return default_foreach(f)
@@ -627,12 +637,12 @@ def switch( t,       # integer value to test
   elif this_module._exec_mode == this_module._yacs_mode:
     return yacs_switch(t, cases, *args, **kwargs)
 
-def begin_sequential_bloc():
+def begin_sequential_block():
   if this_module._exec_mode == this_module._default_mode:
     return
   # TODO yacs mode
 
-def end_sequential_bloc():
+def end_sequential_block():
   if this_module._exec_mode == this_module._default_mode:
     return
   # TODO yacs mode