m-file compiler

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

m-file compiler

GoSim
Hello, hello.
 
I am requesting a compiler to be able to run m-files faster. I am writing this in a tired state but I think I have a good idea.
 
I read this:
http://octave.1599824.n4.nabble.com/compiling-m-files-td1616306.html
 
in particular this:
"It could be a lot faster, if you can determine that some variables
will only be ints, doubles, double precision matrices, etc., and not
have to worry about the possibility that a variable can hold many
different kinds of values at different times during the lifetime of
the program.  But doing that automatically is what makes writing the
compiler far from trivial. "
 
 
I have no practical experience of compilers or interpreters but I get the concepts. The interpreters interpret the code in real time and every line is run like this and this interpreting procedure is CPU-heavy.
If the main problem is the variables and that in octave they can change type during it's life time this is my idea:
 
Case 1: No loops.
Every time a variable changes value, re-declare it and rename it. Your interpreter obviously already can figure out what kind of variable it is, use this and constantly re-declare the variable with a new name. Example:
 
%matlab code:
A=1; %some code where A is int, I don't know exactly when you use int or double etc
 
A=1+0.2; %now A changed to float/double
%some code where A is double
 
A=0; %A is once again int
 
 
//compiler code:
//A changes name and is always newly declared
int A_0=1; //declared int
//A_0 can be used as int
 
//A changes value and is re-declared and renamed:
double A_1=1+0.2;
//code using A_1 as double
 
//A changes value and is once again declared and renamed:
int A_2=0;
 
etc....
 
 
So you need a counter for every variable to keep track of the name change but if this is the main problem I consider non loop m-files simple.
Even if the variable is declared all the time it would probably be faster than running an interpreter.
 
I have a solution for loops and nested loops as weel that is more tricky but since I am not sure that this is your main problem, let me know if this is interesting. Otherwise I am sorry I wasted your time. I am not part of you mail list so you have to answer this mail for me to get it.
 
Kind regards.