public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber) { CarQueue.DriveQueueForward(); CarQueue.DriveFirstCarShort(); return(new Compiler.Variable()); }
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); } }); }
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()); }
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; } }
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); }
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); } }); }
/// <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()); }
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); }); }
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); } }
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; }
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)); }
public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => throw new NotImplementedException();
public VarObject(Access access, Usage usage, string name, Compiler.Scope scope, ScriptObject script) : base(access, usage, name, scope, script) { }
public override Compiler.Variable runFunction(Compiler.Scope currentScope, Compiler.Variable[] inputParas, int lineNumber) { Main.Instance.LevelAnswer.CheckAnswer(inputParas, lineNumber); return(new Compiler.Variable()); }
public VarPrimitive(Access access, Usage usage, string name, Compiler.Scope scope) : base(access, usage, name, scope) { }
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) { }
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])); }
public VarVoid(Access access, Usage usage, string objectName, Compiler.Scope scope) : base(access, usage, objectName, scope) { }
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]); }
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)); }
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()); }
public override Variable Initialize(Access access, Usage usage, string name, Compiler.Scope scope, ScriptTrace trace) => null;
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; }
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);