Vm Merge

lua-users home
wiki

Overview

This script is designed to take a Lua source file, run luac to generate the Lua VM code, and merge the two together.

eg. Using the following code :-

a = {}
b = a.x
print(b)
luac produces :-
main <0:@a.lua> (9 instructions/36 bytes at 002F29E8)
0 params, 2 stacks, 0 locals, 4 strings, 0 numbers, 0 functions, 5 lines
     1	[2]	CREATETABLE	0
     2	[2]	SETGLOBAL  	0	; a
     3	[3]	GETGLOBAL  	0	; a
     4	[3]	GETDOTTED  	2	; x
     5	[3]	SETGLOBAL  	1	; b
     6	[4]	GETGLOBAL  	3	; print
     7	[4]	GETGLOBAL  	1	; b
     8	[4]	CALL       	0 0
     9	[4]	END        	
The script will merge the source and VM code to produce :-
 a = {}
 	CREATETABLE	0
 	SETGLOBAL  	0	; a
 b = a.x
 	GETGLOBAL  	0	; a
 	GETDOTTED  	2	; x
 	SETGLOBAL  	1	; b
 print(b)
 	GETGLOBAL  	3	; print
 	GETGLOBAL  	1	; b
 	CALL       	0 0
 	END        	
It can also produce the above in HTML format to make it a bit easier on the eye (unfortunately no HTML preview facility is available on this site) :-
<html><pre>
<b>a = {}</b>
        CREATETABLE	0
        SETGLOBAL  	0	; a
<b>b = a.x</b>
        GETGLOBAL  	0	; a
        GETDOTTED  	2	; x
        SETGLOBAL  	1	; b
<b>print(b)</b>
        GETGLOBAL  	3	; print
        GETGLOBAL  	1	; b
        CALL       	0 0
        END</pre></html>

Note, the above example is without line numbers. You can find some more examples on OptimisationTips page.

Command line

Download

See Also


RecentChanges · preferences
edit · history
Last edited January 11, 2007 4:19 am GMT (diff)