Beispiel #1
0
        private void CreateFunction(ParseTreeNode node)
        {
            var name           = node.FindTokenAndGetString();
            var scriptFunction = new ScriptFunction {
                FunctionName = name, FunctionId = _resolver.ResolveIdOfString(name)
            };

            _functions.Add(scriptFunction);
            var parameters = FindParametersNode(node)?.ChildNodes
                             .Select(e => e.Token.ValueString)
                             .ToList();

            //TODO add support for parameters and local variables
            if (parameters != null)
            {
                for (byte index = 0; index < parameters.Count; index++)
                {
                    var parameter = parameters[index];
                    AddOpcode(Opcode.OpSafeCreateVariableFieldCached);
                    AddByteCode(index);
                }
            }
            AddOpcode(Opcode.OpCheckclearparams);
            CompileInternal(node.ChildNodes.Find(e => e.Term.Name == LinesId));
            AddOpcode(Opcode.OpEnd);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var resolver = new BaseResolver(false, Game.Ghosts);

            ushort functionIndex, methodIndex, fieldIndex, stringIndex, OPCodeIndex;

            functionIndex = 100;
            methodIndex   = 33523;
            fieldIndex    = 50;
            stringIndex   = 50;
            OPCodeIndex   = 30;

            Opcode testOp = resolver.ResolveOpcodes();

            string testFunction, testMethod, testField, testString, testOPCode;

            testFunction = "setdvar";
            testMethod   = "giveweapon";
            testField    = "name";
            testString   = "j_head";
            testOPCode   = "OpReturn";

            Console.WriteLine("Resolver - ResolveStringById");
            Console.WriteLine(String.Format("functionIndex: {0} | methodIndex: {1} | fieldIndex: {2} | stringIndex {3} | OPCodeIndex: {4}", functionIndex, methodIndex, fieldIndex, stringIndex, OPCodeIndex));
            Console.WriteLine();

            Console.WriteLine(String.Format("Function: {0}", resolver.ResolveFunctionNameById(functionIndex)));
            Console.WriteLine(String.Format("Method: {0}", resolver.ResolveMethodNameById(methodIndex)));
            Console.WriteLine(String.Format("Field: {0}", resolver.ResolveFieldNameById(fieldIndex)));
            Console.WriteLine(String.Format("String: {0}", resolver.ResolveStringNamegById(fieldIndex)));
            Console.WriteLine(String.Format("OPCode: {0}", resolver.ResolveOpcodeNameById(OPCodeIndex)));

            Console.WriteLine();
            Console.WriteLine("Resolver - ResolveIdByString");
            Console.WriteLine(String.Format("functionName: {0} | methodName: {1} | fieldName: {2} | stringName: {3} | OPCodeName: {4}", testFunction, testMethod, testField, testString, testOPCode));
            Console.WriteLine();

            Console.WriteLine(String.Format("Function: {0}", resolver.ResolveIdOfFunction(testFunction)));
            Console.WriteLine(String.Format("Method: {0}", resolver.ResolveIdOfMethod(testMethod)));
            Console.WriteLine(String.Format("Field: {0}", resolver.ResolveIdOfField(testField)));
            Console.WriteLine(String.Format("String: {0}", resolver.ResolveIdOfString(testString)));
            Console.WriteLine(String.Format("OPCode: {0}", resolver.ResolveIdOfOpcodeString(testOPCode)));

            Console.ReadKey();
        }