Improve m2sci tool 68/13868/2
Bruno JOFRET [Fri, 28 Feb 2014 15:29:40 +0000 (16:29 +0100)]
Change-Id: I27399e2b89f010307141232ab7b95ad2bbfb4f24

scilab/modules/m2sci/macros/kernel/update_instr_list.sci
scilab/modules/m2sci/macros/kernel/updatevarslist.sci
scilab/modules/m2sci/macros/mfile2sci.sci
scilab/modules/m2sci/macros/sci_files/sci_help.sci
scilab/modules/m2sci/macros/sci_files/sci_reshape.sci
scilab/modules/m2sci/macros/translatepaths.sci

index 819873c..87526ae 100644 (file)
@@ -12,10 +12,16 @@ function [instr_list]=update_instr_list(instr_list,instr)
 
     // Global variables for M2SCI
     global("m2sci_to_insert_b")
+    if isempty(m2sci_to_insert_b)
+        m2sci_to_insert_b = list();
+    end
     global("m2sci_to_insert_a")
+    if isempty(m2sci_to_insert_a)
+        m2sci_to_insert_a = list();
+    end
 
     // Get instructions that must be inserted before converted instruction
-    for k=1:size(m2sci_to_insert_b)
+    for k=1:lstsize(m2sci_to_insert_b)
         if m2sci_to_insert_b(k)<>list() then
             instr_list($+1)=m2sci_to_insert_b(k)
         end
@@ -29,7 +35,7 @@ function [instr_list]=update_instr_list(instr_list,instr)
     end
 
     // Get instructions that must be inserted after converted instruction
-    for k=1:size(m2sci_to_insert_a)
+    for k=1:lstsize(m2sci_to_insert_a)
         if m2sci_to_insert_a(k)<>list() then
             instr_list($+1)=m2sci_to_insert_a(k)
         end
index 631fb73..a19d331 100644 (file)
@@ -19,6 +19,9 @@ function []=updatevarslist(instr_lhs)
 
     // Global variable for M2SCI
     global("varslist")
+    if isempty(varslist)
+        varslist = list()
+    end
     // level is declared in m2sci.sci and modified in clause2sci.sci
     level;
 
@@ -32,6 +35,7 @@ function []=updatevarslist(instr_lhs)
     // when end of conversion of a clause : merge infered data from the last two parts of clause
     levelsize=size(level,1)
     changepartclause=%F
+
     for i=size(varslist):-1:1
         if size(varslist(i).level,1)==levelsize then
             varlevel=varslist(i).level
index 08df734..9935252 100644 (file)
@@ -206,9 +206,12 @@ function res=mfile2sci(fil,res_path,Recmode,only_double,verbose_mode,prettyprint
             m2sci_info(mss,-1);
         end
 
+        txt($+1) = "endfunction"
         // Compilation
-        execstr("comp("+mname+",1)")
-        funcprot(fprot)
+        mputl(txt, TMPDIR+"/"+mname+".sci");
+        exec(TMPDIR+"/"+mname+".sci", -1);
+        funcprot(fprot);
+        mdelete(TMPDIR+"/"+mname+".sci");
 
         // Get Scilab pseudo code of the function
         m2sci_info(gettext("Macro to tree conversion..."),-1);
index e4f28b0..07cfb11 100644 (file)
@@ -8,22 +8,28 @@
 // http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
 
 function [tree]=sci_help(tree)
-    // M2SCI function
-    // Conversion function for Matlab help()
-    // Input: tree = Matlab funcall tree
-    // Ouput: tree = Scilab equivalent for tree
+// M2SCI function
+// Conversion function for Matlab help()
+// Input: tree = Matlab funcall tree
+// Ouput: tree = Scilab equivalent for tree
 
     if rhs==0 then
         tree.rhs=list()
     else
         topic=getrhs(tree)
-        k=strindex(topic.value,"/")
-        if k<>[] & min(k)<>2 then // help toolbox/
-            no_equiv(expression2code(tree));
-        elseif topic.value=="syntax" then
-            tree.rhs=Rhs_tlist("names")
+
+        if typeof(topic) == "funcall" then
+            tree.rhs=Rhs_tlist(topic.name)
         else
-            // Nothing to do
+            k=strindex(topic.value,"/")
+
+            if k<>[] & min(k)<>2 then // help toolbox/
+                no_equiv(expression2code(tree));
+            elseif topic.value=="syntax" then
+                tree.rhs=Rhs_tlist("names")
+            else
+// Nothing to do
+            end
         end
     end
 
index 0d345ef..dd06819 100644 (file)
@@ -54,7 +54,11 @@ function [tree]=sci_reshape(tree)
         elseif size(tree.rhs)>=2
             if ~isemptyrhs then
                 for k=2:size(tree.rhs)
-                    dims($+1)=tree.rhs(k).value
+                    if typeof(tree.rhs(k)) == "cste" then
+                        dims($+1)=tree.rhs(k).value
+                    else
+                        dims($+1) = Unknown;
+                    end
                 end
                 tree.lhs(1).dims=dims
             end
index af02c14..80c7451 100644 (file)
@@ -129,12 +129,12 @@ function   transorder=translatepaths(Paths,res_path)
         if newest(mpath,scipath,scepath)==1 then
             [fd,ierr]=file("open",pathconvert(TMPDIR)+fnam+".m","old");
             if ierr==0 & strindex(mpath,TMPDIR)==[] then
-                mfile2sci(pathconvert(TMPDIR)+fnam+".m",res_path)
+                mfile2sci(pathconvert(TMPDIR)+fnam+".m",res_path, %t, %t)
                 file("close",fd)
                 mdelete(pathconvert(TMPDIR)+fnam+".m")
                 rmdir(pathconvert(TMPDIR)+pathconvert(fnam),"s")
             else
-                mfile2sci(funpath(i),res_path)
+                mfile2sci(funpath(i),res_path, %t, %t)
             end
 
             tmp_sci_file=pathconvert(TMPDIR)+"tmp_"+fnam+".sci"
@@ -175,7 +175,13 @@ function   transorder=translatepaths(Paths,res_path)
                 mdelete(tmp_resume_m2sci_file)
             end
         end
+        if isempty(logtxt) then
+            logtxt = ""
+        end
         mputl(logtxt,res_path+"log");
+        if isempty(resumelogtxt) then
+            resumelogtxt = ""
+        end
         mputl(resumelogtxt,res_path+"resumelog");
     end