Ejemplo n.º 1
0
        LocalVariableInfo EmitFunction(CompilerState state, Node node)
        {
            if (state == null)
            {
                throw new Exception();
            }
            if (node == null)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.CustomFunctionData data = node.Token.Data as Evaluation.Tokenizing.CustomFunctionData;
            if (data == null)
            {
                throw new Exception();
            }

            if (data.Type == typeof(Triggers.Const) || data.Type == typeof(Triggers.GetHitVar))
            {
                return(EmitSpecialFunction(state, data.Type, (String)node.Arguments[0]));
            }

            List <LocalVariableInfo> functionargs = EmitDescendants(state, node);
            MethodInfo method = FindCorrectMethod(data.Type, functionargs);

            ParameterInfo[] parameters = method.GetParameters();

            LoadLocalVariable(state, state.FunctionState);
            state.Generator.Emit(OpCodes.Ldloca, state.ErrorVariable.LocalIndex);

            for (Int32 i = 0; i != functionargs.Count; ++i)
            {
                LocalVariableInfo arg       = functionargs[i];
                ParameterInfo     parameter = parameters[i + 2];

                LoadLocalVariable(state, arg);

                //if (parameter.ParameterType == typeof(Int32) && arg.LocalType == typeof(Single)) state.Generator.Emit(OpCodes.Conv_I4);
                //if (parameter.ParameterType == typeof(Single) && arg.LocalType == typeof(Int32)) state.Generator.Emit(OpCodes.Conv_R4);
            }

            state.Generator.Emit(OpCodes.Call, method);

            Type returntype = method.ReturnType;

            if (returntype == typeof(Boolean))
            {
                returntype = typeof(Int32);
            }

            LocalVariableInfo result = state.Generator.DeclareLocal(returntype);

            StoreLocalVariable(state, result);

            LoadLocalVariable(state, state.ErrorVariable);
            state.Generator.Emit(OpCodes.Brtrue, state.ErrorLabel);

            return(result);
        }
Ejemplo n.º 2
0
        LocalVariableInfo EmitAssignmentOperator(CompilerState state, Node node)
        {
            if (state == null)
            {
                throw new Exception();
            }
            if (node == null)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.OperatorData data = node.Token.Data as Evaluation.Tokenizing.OperatorData;
            if (data == null || data.Operator != Operator.Assignment)
            {
                throw new Exception();
            }

            if (node.Children.Count != 2)
            {
                throw new Exception();
            }

            Evaluation.Tokenizing.CustomFunctionData vardata = node.Children[0].Token.Data as Evaluation.Tokenizing.CustomFunctionData;
            if (vardata == null)
            {
                throw new Exception();
            }

            if (node.Children[0].Children.Count != 1)
            {
                throw new Exception();
            }

            LocalVariableInfo index = Emit(state, node.Children[0].Children[0]);
            LocalVariableInfo value = Emit(state, node.Children[1]);

            List <LocalVariableInfo> args = new List <LocalVariableInfo>()
            {
                state.FunctionState, index, value
            };

            if (vardata.Type == typeof(Triggers.Var))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_Var"), args));
            }

            if (vardata.Type == typeof(Triggers.FVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_FVar"), args));
            }

            if (vardata.Type == typeof(Triggers.SysVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_SysVar"), args));
            }

            if (vardata.Type == typeof(Triggers.SysFVar))
            {
                return(EmitMethod(state, typeof(SpecialFunctions).GetMethod("Assignment_SysFVar"), args));
            }

            throw new Exception();
        }