예제 #1
0
    public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber)
    {
        CarQueue.DriveQueueForward();
        CarQueue.DriveFirstCarShort();

        return(new Compiler.Variable());
    }
예제 #2
0
        public VarEntity(Access access, Usage usage, string name, Compiler.Scope scope) : base(access, usage, name, scope)
        {
            AddAutoProperty(Selector = new VarSelector(Access.Public, Usage.Default, NamingStyleConverter.FromSingleToCamel(VarSelector.StaticTypeName), InnerScope));

            Compiler.Scope[] scopesMergeData = new Compiler.Scope[1];
            for (int i = 0; i < scopesMergeData.Length; i++)
            {
                scopesMergeData[i] = new Compiler.Scope(InnerScope);
            }
            ParameterInfo[] infoMergeData = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarString.StaticTypeName, "name", scopesMergeData[0]),
                    (true, VarString.StaticTypeName, "data", scopesMergeData[0])
                    )
            };
            Methods.Add("MergeData", (arguments) => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoMergeData, arguments);
                match.Grab(arguments);

                switch (index)
                {
                case 0:
                    VarString name = match[0].Value as VarString;
                    VarString data = match[1].Value as VarString;
                    new Spy(null, $"data merge entity {Selector.GetConstant()} {{{name.GetConstant()}:{data.GetConstant()}}}", null);
                    return(null);

                default: throw new MissingOverloadException("MergeData", index, arguments);
                }
            });
        }
예제 #3
0
    public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber)
    {
        GameObject currentCar = CarQueue.GetFirstCar();

        if (currentCar == null)
        {
            PMWrapper.RaiseError(lineNumber, "Hittade inget tåg att tömma. ");
        }

        UnloadableItem[] itemsToUnload = currentCar.GetComponentsInChildren <UnloadableItem>();

        if (itemsToUnload.Length == 0)
        {
            PMWrapper.RaiseError(lineNumber, "Kan inte tömma ett tomt tåg. Kom ihåg att köra fram nästa tåg innan du tömmer igen.");
        }

        foreach (UnloadableItem item in itemsToUnload)
        {
            if (item != null)
            {
                item.IsUnloading = true;
            }
        }
        GameObject.FindGameObjectWithTag("SceneController").GetComponent <SceneController1_3>().carsUnloaded += 1;

        return(new Compiler.Variable());
    }
예제 #4
0
 public static void linkFunctionCall(FunctionCall theFunc, int lineNumber, Compiler.Scope currentScope)
 {
     Compiler.Function searchedFunc = currentScope.scopeFunctions.getSavedFunction(theFunc.name, lineNumber);
     if (searchedFunc != null)
     {
         Compiler.Variable[] inputVariables = validParameters(PackageUnWrapper.removeSurrondingParanteser(theFunc.parameter), searchedFunc, lineNumber, currentScope);
         theFunc.targetFunc = searchedFunc;
     }
 }
예제 #5
0
 public Variable GetVariable(Compiler.Scope scope)
 {
     if (Initializers.TryGetValue(Type, out var compiler))
     {
         return(compiler.Invoke(Access.Private, Usage.Default, Name, scope, scope.DeclaringMethod.ScriptTrace));
     }
     else
     {
         throw new Compiler.SyntaxException($"Unknown type '{Type}'.", Compiler.CurrentScriptTrace);
     }
 }
        /// <summary>
        /// Used to set the value of an argument.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="scope"> The scope (global or eval context) or the parent scope (function
        /// context). </param>
        /// <param name="thisObject"> The value of the <c>this</c> keyword. </param>
        /// <param name="functionObject"> The function object. </param>
        /// <param name="argumentValues"> The arguments that were passed to the function. </param>
        /// <returns> The result of calling the method. </returns>
        private object ArgumentSetter(ScriptEngine engine, Compiler.Scope scope, object thisObject, Library.FunctionInstance functionObject, object[] argumentValues)
        {
            int argumentIndex = TypeConverter.ToInteger(functionObject.GetPropertyValue("argumentIndex"));

            if (argumentValues != null && argumentValues.Length >= 1)
            {
                object value = argumentValues[0];
                this.m_scope.SetValue(this.m_callee.ArgumentNames[argumentIndex], value);
            }
            return(Undefined.Value);
        }
예제 #7
0
        public VarChat(string name) : base(Access.Public, Usage.Static, name, Compiler.RootScope)
        {
            Compiler.Scope[] scopeSay = new Compiler.Scope[1];
            for (int i = 0; i < scopeSay.Length; i++)
            {
                scopeSay[i] = new Compiler.Scope(InnerScope);
            }
            ParameterInfo[] infoSay = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarString.StaticTypeName, "text", scopeSay[0])
                    )
            };
            Methods.Add("Say", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoSay, arguments);
                match.Grab(arguments);

                switch (index)
                {
                case 0:
                    string text = match["text"].Value.GetConstant();
                    new Spy(null, $"say {text}", null);
                    return(null);

                default: throw new MissingOverloadException($"{TypeName}.Say", index, arguments);
                }
            });

            Compiler.Scope[] scopeTellraw = new Compiler.Scope[1];
            for (int i = 0; i < scopeTellraw.Length; i++)
            {
                scopeTellraw[i] = new Compiler.Scope(InnerScope);
            }
            ParameterInfo[] infoTellraw = new ParameterInfo[] {
                new ParameterInfo(
                    (true, VarSelector.StaticTypeName, "targets", scopeTellraw[0]),
                    (true, VarJson.StaticTypeName, "json", scopeTellraw[0])
                    )
            };
            Methods.Add("Tellraw", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoTellraw, arguments);
                match.Grab(arguments);

                switch (index)
                {
                case 0:
                    string selector = match["selector"].Value.GetConstant();
                    string json     = match["json"].Value.GetRawText().GetJson();
                    new Spy(null, $"tellraw {selector} {json}", null);
                    return(null);

                default: throw new MissingOverloadException($"{TypeName}.Tellraw", index, arguments);
                }
            });
        }
예제 #8
0
 /// <summary>
 /// Evaluates the given javascript source code and returns the result.
 /// </summary>
 /// <param name="engine"> The associated script engine. </param>
 /// <param name="code"> The source code to evaluate. </param>
 /// <param name="scope"> The containing scope. </param>
 /// <param name="thisObject"> The value of the "this" keyword in the containing scope. </param>
 /// <param name="strictMode"> Indicates whether the eval statement is being called from
 /// strict mode code. </param>
 /// <returns> The value of the last statement that was executed, or <c>undefined</c> if
 /// there were no executed statements. </returns>
 public static object Eval(ScriptEngine engine, object code, Compiler.Scope scope, object thisObject, bool strictMode)
 {
     if (scope == null)
     {
         throw new ArgumentNullException("scope");
     }
     if (TypeUtilities.IsString(code) == false)
     {
         return(code);
     }
     return(engine.Eval(TypeConverter.ToString(code), scope, thisObject, strictMode));
 }
    public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber)
    {
        GameObject chair = GameObject.FindGameObjectWithTag("Chair");

        if (chair == null)
        {
            PMWrapper.RaiseError(lineNumber, "Hittade ingen stol att lasta av.");
        }

        chair.GetComponent <UnloadableItem>().IsUnloading = true;
        GameObject.FindGameObjectWithTag("SceneController").GetComponent <SceneController1_2>().itemsUnloaded += 1;
        return(new Compiler.Variable());
    }
예제 #10
0
 public VarFunction(Access access, Usage usage, string objectName, Compiler.Scope scope, ScriptMethod function) :
     base(access, usage, objectName, scope)
 {
     GamePath     = $"{Program.Datapack.Name}:{function.Alias.Replace('\\', '/')}";
     FolderPath   = $"{Program.Datapack.Name}:{function.FullAlias}.mcfunction";
     ScriptMethod = function;
     Methods.Add("Invoke", (arguments) => {
         Parameters.Grab(arguments);
         new Spy(null, (function) => {
             //for(int i = 0; i < arguments.Count; i++) arguments[i].Value.WriteCopyTo(Compiler.FunctionStack.Peek(), Parameters[i].Value);
             function.WriteLine($"function {GamePath}");
         }, null);
         return(null);
     });
 }
예제 #11
0
 public Parameter(bool reference, string type, string name, Compiler.Scope scope)
 {
     Reference = reference;
     Name      = name;
     if (reference)
     {
         Type  = type;
         Value = null;
     }
     else
     {
         Type  = type;
         Value = Variable.Initializers[type](Access.Pass, Usage.Parameter, name, scope, Compiler.AnonScriptTrace);
     }
 }
예제 #12
0
        public VarString(Access access, Usage usage, string name, Compiler.Scope scope) : base(access, usage, name, scope)
        {
            ParameterInfo[] infoFormat = new ParameterInfo[] {
                new ParameterInfo()
            };
            Methods.Add("Format", arguments => {
                (ParameterInfo match, int index) = ParameterInfo.HighestMatch(infoFormat, arguments);
                match.Grab(arguments);

                string format = Value;

                int est   = 1;
                char last = '\0';
                foreach (char character in format)
                {
                    if (last != character && last == '{')
                    {
                        est++;
                    }
                }
                RawTextList json = new RawTextList(est);

                int start, end;
                for (start = (end = 0) - 1; end < format.Length; end++)
                {
                    switch (format[end])
                    {
                    case '{': {
                        // Make string into JSON.
                        string prev = format[(start + 1)..end];
                        var raw     = new RawText()
                        {
                            Text = prev
                        };
                        json.Add(raw);
                        break;
                    }
예제 #13
0
 public VarSelector(Access access, Usage usage, string name, Compiler.Scope scope) : base(access, usage, name, scope)
 {
     AddAutoProperty(String = new VarString(Access.Public, Usage.Default, char.ToLower(VarString.StaticTypeName[0]) + VarString.StaticTypeName.Substring(1), InnerScope));
 }
예제 #14
0
 public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => throw new NotImplementedException();
예제 #15
0
 public VarObject(Access access, Usage usage, string name, Compiler.Scope scope, ScriptObject script)
     : base(access, usage, name, scope, script)
 {
 }
예제 #16
0
 public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber)
 {
     Main.Instance.LevelAnswer.CheckAnswer(inputParas, lineNumber);
     return(new Compiler.Variable());
 }
예제 #17
0
 public VarPrimitive(Access access, Usage usage, string name, Compiler.Scope scope) : base(access, usage, name, scope)
 {
 }
예제 #18
0
 public ScriptField(string alias, string type, Access access, Usage usage, ScriptObject declarer, ScriptString phrase, Compiler.Scope scope)
     : this(alias, type, access, usage, declarer, new ScriptWild(ScriptLine.GetWilds(phrase).Array, "(\\)", ' '), scope)
 {
 }
예제 #19
0
 public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => new VarSelector(access, usage, name, scope);
        /// <summary>
        /// Used to retrieve the value of an argument.
        /// </summary>
        /// <param name="engine"> The associated script engine. </param>
        /// <param name="scope"> The scope (global or eval context) or the parent scope (function
        /// context). </param>
        /// <param name="thisObject"> The value of the <c>this</c> keyword. </param>
        /// <param name="functionObject"> The function object. </param>
        /// <param name="argumentValues"> The arguments that were passed to the function. </param>
        /// <returns> The result of calling the method. </returns>
        private object ArgumentGetter(ScriptEngine engine, Compiler.Scope scope, object thisObject, Library.FunctionInstance functionObject, object[] argumentValues)
        {
            int argumentIndex = TypeConverter.ToInteger(functionObject.GetPropertyValue("argumentIndex"));

            return(this.m_scope.GetValue(this.m_callee.ArgumentNames[argumentIndex]));
        }
예제 #21
0
 public VarVoid(Access access, Usage usage, string objectName, Compiler.Scope scope)
     : base(access, usage, objectName, scope)
 {
 }
예제 #22
0
        static Compiler.Variable[] validParameters(string trimmedPara, Compiler.Function calledFunction, int lineNumber, Compiler.Scope currentScope)
        {
            string[] words = Compiler.WordParser.parseWords(trimmedPara);

            if (words.Length != 0)
            {
                Compiler.Logic[] logicOrder = WordLogic.determineLogicFromWords(words, lineNumber, currentScope);

                List <List <Compiler.Logic> > packedLogics = convertIntoParameterLogic(words, logicOrder, lineNumber);

                if (packedLogics != null)
                {
                    Compiler.Variable[] inputVariables = new Compiler.Variable[packedLogics.Count];

                    for (int i = 0; i < packedLogics.Count; i++)
                    {
                        inputVariables [i] = ValidSumCheck.checkIfValidSum(packedLogics [i].ToArray(), lineNumber);
                    }


                    foreach (Compiler.Variable v in inputVariables)
                    {
                        if (v.variableType == Compiler.VariableTypes.unkown)
                        {
                            ErrorMessage.sendErrorMessage(lineNumber, "one or several of the input parameters to function: " + calledFunction.name + " are corrupt!");
                        }
                    }


                    if (calledFunction.inputParameters.Contains(inputVariables.Length))
                    {
                        return(inputVariables);
                    }
                }
            }

            if (calledFunction.inputParameters.Contains(0))
            {
                return(new Compiler.Variable[0]);
            }

            ErrorMessage.sendErrorMessage(lineNumber, "Amount of parameters does not match Expected!");
            return(new Compiler.Variable[0]);
        }
예제 #23
0
        public static Compiler.Logic parseIntoFunctionCall(string word, int lineNumber, Compiler.Scope currentScope)
        {
            string funcName = getFunctionName(word, lineNumber);
            string funcPara = getFunctionInParameter(word, lineNumber);

            return(new FunctionCall(word, funcName, funcPara, null));
        }
예제 #24
0
 public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber)
 {
     PM.UISingleton.instance.levelHandler.currentLevel.levelAnswer.CheckAnswer(inputParas, lineNumber);
     return(new Compiler.Variable());
 }
예제 #25
0
파일: Spy.cs 프로젝트: SonicBlue22/MCSharp
 public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => null;
예제 #26
0
 public ScriptField(string alias, string type, Access access, Usage usage, ScriptObject declarer, ScriptWild init, Compiler.Scope scope)
     : base(alias, type, access, usage, declarer, init.ScriptTrace, scope)
 {
     Init = init;
 }
예제 #27
0
 public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => throw new Compiler.SyntaxException("Cannot make an instance of a static class.", trace);