aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs
diff options
context:
space:
mode:
authorUbitUmarov2018-02-25 00:18:41 +0000
committerUbitUmarov2018-02-25 00:18:41 +0000
commit85b973ce1d8dc034546c9c572a7f57e73b6017d3 (patch)
treea03332d9233e3788f8bc2e535b6863d8fe195b0b /OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs
parentYengine fix its section name on opensim.ini.example (diff)
downloadopensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.zip
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.gz
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.bz2
opensim-SC-85b973ce1d8dc034546c9c572a7f57e73b6017d3.tar.xz
Y(xmr)engine cosmetics...
Diffstat (limited to 'OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs198
1 files changed, 64 insertions, 134 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs
index d3ae165..76762dd 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMRObjectTokens.cs
@@ -501,10 +501,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
501 */ 501 */
502 public override void EndMethod() 502 public override void EndMethod()
503 { 503 {
504 /* 504 // Convert CIL code to primitive statements.
505 * Convert CIL code to primitive statements. 505 // There are a bunch of labels and internal code such as call stack save restore.
506 * There are a bunch of labels and internal code such as call stack save restore.
507 */
508 topBlock = new OTStmtBlock(); 506 topBlock = new OTStmtBlock();
509 blockstack.Push(topBlock); 507 blockstack.Push(topBlock);
510 for(LinkedListNode<OTCilInstr> link = cilinstrs.First; link != null; link = link.Next) 508 for(LinkedListNode<OTCilInstr> link = cilinstrs.First; link != null; link = link.Next)
@@ -512,10 +510,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
512 link.Value.BuildStatements(this, link); 510 link.Value.BuildStatements(this, link);
513 } 511 }
514 512
515 /* 513 // Strip out stuff we don't want, such as references to callMode.
516 * Strip out stuff we don't want, such as references to callMode. 514 // This strips out stack frame capture and restore code.
517 * This strips out stack frame capture and restore code.
518 */
519 topBlock.StripStuff(null); 515 topBlock.StripStuff(null);
520 516
521 // including a possible final return statement 517 // including a possible final return statement
@@ -532,22 +528,16 @@ namespace OpenSim.Region.ScriptEngine.Yengine
532 } 528 }
533 } 529 }
534 530
535 /** 531 // At this point, all behind-the-scenes references are removed except
536 * At this point, all behind-the-scenes references are removed except 532 // that the do/for/if/while blocks are represented by OTStmtCont-style
537 * that the do/for/if/while blocks are represented by OTStmtCont-style 533 // if/jumps. So try to convert them to the higher-level structures.
538 * if/jumps. So try to convert them to the higher-level structures.
539 */
540 topBlock.DetectDoForIfWhile(null); 534 topBlock.DetectDoForIfWhile(null);
541 535
542 /* 536 // Final strip to get rid of unneeded @forbreak_<suffix>; labels and the like.
543 * Final strip to get rid of unneeded @forbreak_<suffix>; labels and the like.
544 */
545 topBlock.StripStuff(null); 537 topBlock.StripStuff(null);
546 538
547 /* 539 // Build reference counts so we don't output unneeded declarations,
548 * Build reference counts so we don't output unneeded declarations, 540 // especially temps and internal variables.
549 * especially temps and internal variables.
550 */
551 foreach(OTLocal local in locals.Values) 541 foreach(OTLocal local in locals.Values)
552 { 542 {
553 local.nlclreads = 0; 543 local.nlclreads = 0;
@@ -564,10 +554,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
564 } 554 }
565 } 555 }
566 556
567 /* 557 // Strip the $n off of local vars that are not ambiguous.
568 * Strip the $n off of local vars that are not ambiguous. 558 // Make sure they don't mask globals and arguments as well.
569 * Make sure they don't mask globals and arguments as well.
570 */
571 Dictionary<string, int> namecounts = new Dictionary<string, int>(); 559 Dictionary<string, int> namecounts = new Dictionary<string, int>();
572 foreach(Dictionary<int, string> varnames in scriptObjCode.globalVarNames.Values) 560 foreach(Dictionary<int, string> varnames in scriptObjCode.globalVarNames.Values)
573 { 561 {
@@ -607,9 +595,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
607 local.name = name; 595 local.name = name;
608 } 596 }
609 597
610 /* 598 // Print out result.
611 * Print out result.
612 */
613 if(method.Name == _globalvarinit) 599 if(method.Name == _globalvarinit)
614 { 600 {
615 GlobalsDump(); 601 GlobalsDump();
@@ -725,10 +711,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
725 */ 711 */
726 private void GlobalsDump() 712 private void GlobalsDump()
727 { 713 {
728 /* 714 // Scan $globalvarinit(). It should only have global var assignments in it.
729 * Scan $globalvarinit(). It should only have global var assignments in it. 715 // Also gather up list of variables it initializes.
730 * Also gather up list of variables it initializes.
731 */
732 bool badinit = false; 716 bool badinit = false;
733 Dictionary<string, string> inittypes = new Dictionary<string, string>(); 717 Dictionary<string, string> inittypes = new Dictionary<string, string>();
734 foreach(OTStmt stmt in topBlock.blkstmts) 718 foreach(OTStmt stmt in topBlock.blkstmts)
@@ -748,11 +732,9 @@ namespace OpenSim.Region.ScriptEngine.Yengine
748 inittypes[globalop.PrintableString] = ""; 732 inittypes[globalop.PrintableString] = "";
749 } 733 }
750 734
751 /* 735 // Scan through list of all global variables in the script.
752 * Scan through list of all global variables in the script. 736 // Output declarations for those what don't have any init statement for them.
753 * Output declarations for those what don't have any init statement for them. 737 // Save the type for those that do have init statements.
754 * Save the type for those that do have init statements.
755 */
756 bool first = true; 738 bool first = true;
757 foreach(string iartypename in scriptObjCode.globalVarNames.Keys) 739 foreach(string iartypename in scriptObjCode.globalVarNames.Keys)
758 { 740 {
@@ -778,10 +760,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
778 } 760 }
779 } 761 }
780 762
781 /* 763 // If $globalvarinit() has anything bad in it, output it as a function.
782 * If $globalvarinit() has anything bad in it, output it as a function. 764 // Otherwise, output it as a series of global declarations with init values.
783 * Otherwise, output it as a series of global declarations with init values.
784 */
785 if(badinit) 765 if(badinit)
786 { 766 {
787 MethodDump(); 767 MethodDump();
@@ -809,19 +789,14 @@ namespace OpenSim.Region.ScriptEngine.Yengine
809 { 789 {
810 string indent; 790 string indent;
811 791
812 /* 792 // Event handlers don't have an argument list as such in the original
813 * Event handlers don't have an argument list as such in the original 793 // code. Instead they have a series of assignments from ehargs[] to
814 * code. Instead they have a series of assignments from ehargs[] to 794 // local variables. So make those local variables look like they are
815 * local variables. So make those local variables look like they are 795 // an argument list.
816 * an argument list.
817 */
818 int i = method.Name.IndexOf(' '); 796 int i = method.Name.IndexOf(' ');
819 if(i >= 0) 797 if(i >= 0)
820 { 798 {
821 799 // Maybe we have to output the state name.
822 /*
823 * Maybe we have to output the state name.
824 */
825 string statename = method.Name.Substring(0, i); 800 string statename = method.Name.Substring(0, i);
826 string eventname = method.Name.Substring(++i); 801 string eventname = method.Name.Substring(++i);
827 802
@@ -844,10 +819,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
844 twout.Write('\n'); 819 twout.Write('\n');
845 } 820 }
846 821
847 /* 822 // Output event name and argument list.
848 * Output event name and argument list. 823 // Remove from locals list so they don't print below.
849 * Remove from locals list so they don't print below.
850 */
851 twout.Write('\n' + INDENT + eventname + " ("); 824 twout.Write('\n' + INDENT + eventname + " (");
852 MethodInfo meth = typeof(IEventHandlers).GetMethod(eventname); 825 MethodInfo meth = typeof(IEventHandlers).GetMethod(eventname);
853 i = 0; 826 i = 0;
@@ -873,35 +846,26 @@ namespace OpenSim.Region.ScriptEngine.Yengine
873 } 846 }
874 twout.Write(')'); 847 twout.Write(')');
875 848
876 /* 849 // Indent method body by 4 spaces.
877 * Indent method body by 4 spaces.
878 */
879 indent = INDENT; 850 indent = INDENT;
880 } 851 }
881 else 852 else
882 { 853 {
883 854 // Maybe need to close out previous state.
884 /*
885 * Maybe need to close out previous state.
886 */
887 if(laststate != null) 855 if(laststate != null)
888 { 856 {
889 twout.Write("\n}"); 857 twout.Write("\n}");
890 laststate = null; 858 laststate = null;
891 } 859 }
892 860
893 /* 861 // Output blank line and return type (if any).
894 * Output blank line and return type (if any).
895 */
896 twout.Write("\n\n"); 862 twout.Write("\n\n");
897 if(method.ReturnType != typeof(void)) 863 if(method.ReturnType != typeof(void))
898 { 864 {
899 twout.Write(AbbrType(method.ReturnType) + ' '); 865 twout.Write(AbbrType(method.ReturnType) + ' ');
900 } 866 }
901 867
902 /* 868 // Output method name and argument list.
903 * Output method name and argument list.
904 */
905 int j = method.Name.IndexOf('('); 869 int j = method.Name.IndexOf('(');
906 if(j < 0) 870 if(j < 0)
907 { 871 {
@@ -926,15 +890,11 @@ namespace OpenSim.Region.ScriptEngine.Yengine
926 twout.Write(')'); 890 twout.Write(')');
927 } 891 }
928 892
929 /* 893 // Don't indent method body at all.
930 * Don't indent method body at all.
931 */
932 indent = ""; 894 indent = "";
933 } 895 }
934 896
935 /* 897 // Output local variable declarations.
936 * Output local variable declarations.
937 */
938 twout.Write('\n' + indent + '{'); 898 twout.Write('\n' + indent + '{');
939 bool didOne = false; 899 bool didOne = false;
940 foreach(OTLocal local in locals.Values) 900 foreach(OTLocal local in locals.Values)
@@ -945,9 +905,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
945 if(didOne) 905 if(didOne)
946 twout.Write('\n'); 906 twout.Write('\n');
947 907
948 /* 908 // Output statements.
949 * Output statements.
950 */
951 if(topBlock.blkstmts.Count == 0) 909 if(topBlock.blkstmts.Count == 0)
952 { 910 {
953 twout.Write(" }"); 911 twout.Write(" }");
@@ -1634,22 +1592,19 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1634 { 1592 {
1635 switch(opCode.ToString()) 1593 switch(opCode.ToString())
1636 { 1594 {
1637 1595 // We don't handle non-empty stack at branch points.
1638 /* 1596 //
1639 * We don't handle non-empty stack at branch points. 1597 // So handle this case specially:
1640 * 1598 //
1641 * So handle this case specially: 1599 // dup
1642 * 1600 // ldc.i4.0
1643 * dup 1601 // bge.s llAbstemp << we are here
1644 * ldc.i4.0 1602 // neg
1645 * bge.s llAbstemp << we are here 1603 // llAbstemp:
1646 * neg 1604 //
1647 * llAbstemp: 1605 // becomes:
1648 * 1606 //
1649 * becomes: 1607 // call llAbs
1650 *
1651 * call llAbs
1652 */
1653 case "bge.s": 1608 case "bge.s":
1654 { 1609 {
1655 OTOpnd rite = decompile.opstack.Pop(); // alleged zero 1610 OTOpnd rite = decompile.opstack.Pop(); // alleged zero
@@ -2103,50 +2058,33 @@ namespace OpenSim.Region.ScriptEngine.Yengine
2103 2058
2104 public static OTOpnd Make(OTOpnd array, OTOpnd index, bool byref, OTDecompile decompile) 2059 public static OTOpnd Make(OTOpnd array, OTOpnd index, bool byref, OTDecompile decompile)
2105 { 2060 {
2106 /* 2061 // arg$0.glblVars.iar<type>[<intconst>] is a reference to a global variable
2107 * arg$0.glblVars.iar<type>[<intconst>] is a reference to a global variable 2062 // likewise so is __xmrinst.glblVars.iar<type>[<intconst>]
2108 * likewise so is __xmrinst.glblVars.iar<type>[<intconst>]
2109 */
2110 if((array is OTOpndField) && (index is OTOpndInt)) 2063 if((array is OTOpndField) && (index is OTOpndInt))
2111 { 2064 {
2112 2065 // arrayfield = (arg$0.glblVars).iar<type>
2113 /* 2066 // arrayfieldobj = arg$0.glblVars
2114 * arrayfield = (arg$0.glblVars).iar<type> 2067 // iartypename = iar<type>
2115 * arrayfieldobj = arg$0.glblVars
2116 * iartypename = iar<type>
2117 */
2118 OTOpndField arrayfield = (OTOpndField)array; 2068 OTOpndField arrayfield = (OTOpndField)array;
2119 OTOpnd arrayfieldobj = arrayfield.obj; 2069 OTOpnd arrayfieldobj = arrayfield.obj;
2120 string iartypename = arrayfield.field.Name; 2070 string iartypename = arrayfield.field.Name;
2121 2071
2122 /* 2072 // See if they are what they are supposed to be.
2123 * See if they are what they are supposed to be.
2124 */
2125 if((arrayfieldobj is OTOpndField) && iartypename.StartsWith("iar")) 2073 if((arrayfieldobj is OTOpndField) && iartypename.StartsWith("iar"))
2126 { 2074 {
2127 2075 // arrayfieldobjfield = arg$0.glblVars
2128 /*
2129 * arrayfieldobjfield = arg$0.glblVars
2130 */
2131 OTOpndField arrayfieldobjfield = (OTOpndField)arrayfieldobj; 2076 OTOpndField arrayfieldobjfield = (OTOpndField)arrayfieldobj;
2132 2077
2133 /* 2078 // See if the parts are what they are supposed to be.
2134 * See if the parts are what they are supposed to be.
2135 */
2136 if(IsArg0OrXMRInst(arrayfieldobjfield.obj) && (arrayfieldobjfield.field.Name == "glblVars")) 2079 if(IsArg0OrXMRInst(arrayfieldobjfield.obj) && (arrayfieldobjfield.field.Name == "glblVars"))
2137 { 2080 {
2138 2081 // Everything matches up, make a global variable instead of an array reference.
2139 /*
2140 * Everything matches up, make a global variable instead of an array reference.
2141 */
2142 return new OTOpndGlobal(iartypename, ((OTOpndInt)index).value, byref, decompile.scriptObjCode); 2082 return new OTOpndGlobal(iartypename, ((OTOpndInt)index).value, byref, decompile.scriptObjCode);
2143 } 2083 }
2144 } 2084 }
2145 } 2085 }
2146 2086
2147 /* 2087 // Other array reference.
2148 * Other array reference.
2149 */
2150 OTOpndArrayElem it = new OTOpndArrayElem(); 2088 OTOpndArrayElem it = new OTOpndArrayElem();
2151 it.array = array; 2089 it.array = array;
2152 it.index = index; 2090 it.index = index;
@@ -3097,17 +3035,13 @@ namespace OpenSim.Region.ScriptEngine.Yengine
3097 return false; 3035 return false;
3098 int listsize = ((OTOpndInt)storeval.index).value; 3036 int listsize = ((OTOpndInt)storeval.index).value;
3099 3037
3100 /* 3038 // Good chance of having list initializer, malloc an object to hold it.
3101 * Good chance of having list initializer, malloc an object to hold it.
3102 */
3103 OTOpndListIni it = new OTOpndListIni(); 3039 OTOpndListIni it = new OTOpndListIni();
3104 it.values = new OTOpnd[listsize]; 3040 it.values = new OTOpnd[listsize];
3105 3041
3106 /* 3042 // There should be exactly listsize statements following that of the form:
3107 * There should be exactly listsize statements following that of the form: 3043 // dup$<n>[<i>] = bla
3108 * dup$<n>[<i>] = bla 3044 // If so, save the bla values in the values[] array.
3109 * If so, save the bla values in the values[] array.
3110 */
3111 LinkedListNode<OTStmt> vallink = link; 3045 LinkedListNode<OTStmt> vallink = link;
3112 for(int i = 0; i < listsize; i++) 3046 for(int i = 0; i < listsize; i++)
3113 { 3047 {
@@ -3129,10 +3063,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
3129 it.values[i] = valstore.value; 3063 it.values[i] = valstore.value;
3130 } 3064 }
3131 3065
3132 /* 3066 // The next statement should have a 'newobj list (dup$<n>)' in it somewhere
3133 * The next statement should have a 'newobj list (dup$<n>)' in it somewhere 3067 // that we want to replace with 'it'.
3134 * that we want to replace with 'it'.
3135 */
3136 ConstructorInfo protoctor = typeof(LSL_List).GetConstructor(new Type[] { typeof(object[]) }); 3068 ConstructorInfo protoctor = typeof(LSL_List).GetConstructor(new Type[] { typeof(object[]) });
3137 OTOpnd[] protoargs = new OTOpnd[] { storevar }; 3069 OTOpnd[] protoargs = new OTOpnd[] { storevar };
3138 OTOpnd proto = OTOpndNewobj.Make(protoctor, protoargs); 3070 OTOpnd proto = OTOpndNewobj.Make(protoctor, protoargs);
@@ -3140,9 +3072,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine
3140 vallink = vallink.Next; 3072 vallink = vallink.Next;
3141 bool rc = vallink.Value.ReplaceOperand(proto, it); 3073 bool rc = vallink.Value.ReplaceOperand(proto, it);
3142 3074
3143 /* 3075 // If successful, delete 'dup$n =' and all 'dup$n[i] =' statements.
3144 * If successful, delete 'dup$n =' and all 'dup$n[i] =' statements.
3145 */
3146 if(rc) 3076 if(rc)
3147 { 3077 {
3148 do 3078 do