[Mumps2Py:] [113] added support for translating the $ORDER intrinsic

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 113
Author:   pgallot
Date:     2008-02-15 21:18:14 +0000 (Fri, 15 Feb 2008)

Log Message:
-----------
added support for translating the $ORDER intrinsic

Modified Paths:
--------------
    trunk/mumps2py/tok2python.py


Modified: trunk/mumps2py/tok2python.py
===================================================================
--- trunk/mumps2py/tok2python.py	2008-02-15 21:17:19 UTC (rev 112)
+++ trunk/mumps2py/tok2python.py	2008-02-15 21:18:14 UTC (rev 113)
@@ -190,8 +190,7 @@
             raise TranslationError(translation, token,
                                    "incorrect number of parameters")
         param = token.params[0]
-        if not param.is_var():
-            raise TranslationError(translation, token, "idiom not implemented")
+        assert(param.is_var())
 
         translation.add_cl_import()
         if param.has_index():
@@ -271,6 +270,22 @@
                                    "incorrect number of parameters")
         return length_str
 
+    def translate_intr_order(translation, token):
+        """ translates the Mumps Intrinsic function ORDER to Python"""
+        translation.add_cl_import()
+        param = token.params[0]
+        dir_str=""
+        if len(param.indices) > 1:
+            param_index = tuplify(translation, param.indices)
+        else:
+            param_index = translate_expr(translation, param.indices[0])
+           
+        if len(token.params) == 2:
+            dir_str =", %s" % translate_expr(translation, token.params[1])
+
+        order_str = "Mf_order(%s, %s%s)" % (param.varname, param_index, dir_str)
+        return order_str
+                    
     def translate_intr_piece(translation, token):
         """ translates the Mumps Intrinsic function PIECE to Python"""
         translation.add_import("re")
@@ -466,6 +481,7 @@
         F_FIND: translate_intr_find,
         F_JUSTIFY: translate_intr_justify,
         F_LENGTH: translate_intr_length,
+        F_ORDER: translate_intr_order,
         F_PIECE: translate_intr_piece,
         F_RANDOM: translate_intr_random,
         F_REVERSE: translate_intr_reverse,
@@ -582,7 +598,7 @@
     for item in token.var_set:
         if item.has_key("indirection"):
             raise TranslationError(translation, token, "idiom not implemented")
-        elif item.has_key("multiset"):
+        elif item.has_key("var_names"):
             for varname in item["var_names"]:
                 if token.indentlevel == 0 and \
                    varname.is_var() and varname.is_indexed() and \
@@ -673,8 +689,16 @@
 
 def translate_kill(translation, token):
     """translate the Mumps Kill command to Python"""
-    raise TranslationError(translation, token,
-                           "token type translation not implemented")
+    if len(token.excl_list) or not len(token.kill_list):
+        raise TranslationError(translation, token,
+                           "idiom translation not implemented")
+    indentlevel, kill_str = post_condition(translation, token,
+                                            token.indentlevel)
+    for item in token.kill_list:
+        kill_str = "%s%sdel %s\n" % \
+                   (kill_str, tab(indentlevel),
+                    translate_expr(translation, item))
+    return kill_str
 
 def translate_lock(translation, token):
     """translate the Mumps Lock command to Python"""


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/