public ExpressionTreeParseResult(IWorkshopTree result, Element[] index, IWorkshopTree target, IGettable resultingVariable) { Result = result; ResultingIndex = index; Target = target; ResultingVariable = resultingVariable; }
public UserFunctionParameterHandler( ActionSet actionSet, CodeParameter[] codeParameters, IVariableInstance[] parameterVariables, WorkshopParameter[] providedParameters) { _recursiveParameters = actionSet.IsRecursive; _codeParameters = codeParameters; _parameters = new UserFunctionParameter[codeParameters.Length]; for (int i = 0; i < _parameters.Length; i++) { // Get the gettable provided from the ref parameter. IGettable gettable = providedParameters?[i].RefVariableElements?.Childify(); // Not provided or not a ref parameter. if (gettable == null) { // Create a gettable for the parameter. gettable = parameterVariables[i] .GetAssigner(new(actionSet)) .GetValue(new GettableAssignerValueInfo(actionSet) { SetInitialValue = SetInitialValue.DoNotSet, InitialValueOverride = providedParameters?[i].Value }); } _parameters[i] = new UserFunctionParameter(gettable, new[] { parameterVariables[i].Provider }); //todo: linkedVariables for virtual } }
public void Add(IIndexReferencer var, IGettable gettable) { if (gettable == null) { throw new ArgumentNullException(nameof(gettable)); } CheckIfAdded(var); references.Add(var, gettable); }
public void AssignParameters(ActionSet actionSet, IWorkshopTree[] parameterValues) { for (int i = 0; i < ParameterVars.Length; i++) { IGettable result = actionSet.IndexAssigner.Add(ParameterVars[i], parameterValues[i]); //if (indexResult is IndexReference indexReference && parameterValues?[i] != null) //actionSet.AddAction(indexReference.SetVariable((Element)parameterValues[i])); foreach (Var virtualParameterOption in VirtualVarGroup(i)) { actionSet.IndexAssigner.Add(virtualParameterOption, result); } } }
public bool TryGet(IIndexReferencer var, out IGettable gettable) { VarIndexAssigner current = this; while (current != null) { if (current.references.ContainsKey(var)) { gettable = current.references[var]; return(true); } current = current.parent; } gettable = null; return(false); }
public void AssignParameters(ActionSet actionSet, IWorkshopTree[] parameterValues, bool recursive) { for (int i = 0; i < ParameterVars.Length; i++) { IGettable indexResult = actionSet.IndexAssigner.Add(actionSet.VarCollection, ParameterVars[i], actionSet.IsGlobal, parameterValues?[i], recursive); if (indexResult is IndexReference indexReference && parameterValues?[i] != null) { actionSet.AddAction(indexReference.SetVariable((Element)parameterValues[i])); } foreach (Var virtualParameterOption in VirtualVarGroup(i)) { actionSet.IndexAssigner.Add(virtualParameterOption, indexResult); } } }
public IGettable[] GetVariableGettables(IVariableInstance[] variables, IWorkshopTree reference) { IGettable[] gettables = new IGettable[variables.Length]; // 'stack' represents an index in the list of class variables. int stack = StackOffset; for (int i = 0; i < variables.Length; i++) { // Get the gettable assigner. var gettableAssigner = variables[i].GetAssigner(); // Create the gettable. gettables[i] = gettableAssigner.AssignClassStacks(new GetClassStacks(_initializer, stack)).ChildFromClassReference(reference); // Increase stack by the length of the gettable. stack += gettableAssigner.StackDelta(); } return(gettables); }
public VariableElements(IGettable indexReference, Element target, Element[] index) { IndexReference = indexReference; Target = target; Index = index; }
public void Add(IVariable variable, IGettable value) { CheckIfAdded(variable); _references.Add(variable, value); }
public static T GetValue <T>(this IGettable gettable) { return((T)gettable.GetValue(typeof(T))); }
public static object GetValue(this IGettable gettable, Type type) { return(ConversionUtility.Convert(gettable.GetValue(), type)); }
public ExpressionTreeParseResult ParseTree(ActionSet actionSet, bool expectingValue) { IGettable resultingVariable = null; // The resulting variable. IWorkshopTree target = null; // The resulting player. IWorkshopTree result = null; // The resulting value. VarIndexAssigner currentAssigner = actionSet.IndexAssigner; IWorkshopTree currentObject = null; Element[] resultIndex = new Element[0]; for (int i = 0; i < Tree.Length; i++) { bool isLast = i == Tree.Length - 1; IWorkshopTree current = null; if (Tree[i] is CallVariableAction) { var callVariableAction = (CallVariableAction)Tree[i]; var reference = currentAssigner[callVariableAction.Calling]; current = reference.GetVariable((Element)target); resultIndex = new Element[callVariableAction.Index.Length]; for (int ai = 0; ai < callVariableAction.Index.Length; ai++) { var workshopIndex = callVariableAction.Index[ai].Parse(actionSet); resultIndex[ai] = (Element)workshopIndex; current = Element.Part <V_ValueInArray>(current, workshopIndex); } // If this is the last node in the tree, set the resulting variable. if (isLast) { resultingVariable = reference; } } else { var newCurrent = Tree[i].Parse(actionSet.New(currentAssigner).New(currentObject)); if (newCurrent != null) { current = newCurrent; resultIndex = new Element[0]; } } if (Tree[i].Type() == null) { // If this isn't the last in the tree, set it as the target. if (!isLast) { target = current; } currentObject = null; } else { var type = Tree[i].Type(); currentObject = current; currentAssigner = actionSet.IndexAssigner.CreateContained(); type.AddObjectVariablesToAssigner(currentObject, currentAssigner); } result = current; } if (result == null && expectingValue) { throw new Exception("Expression tree result is null"); } return(new ExpressionTreeParseResult(result, resultIndex, target, resultingVariable)); }
public void Add(IGettable gettable) => _popVariables.Add(gettable);
/// <summary> /// Parse un Statement suivi de son block. /// En général, on obtient : /// Statement + Operand + BlockGroup. /// Le statement if pouvant être composé différemment (avec else et elsif), il n'est pas traité /// dans cette fonction. /// </summary> /// <param name="tokens"></param> /// <returns></returns> public static Instruction ParseBlockStatement(TokenList tokens, GlobalContext mainContext) { // Patch if (tokens.Count == 4 && tokens.First().Type == TokenType.Statement) { PatchInstruction patchInstruction = new PatchInstruction(); InfoToken itoken = (InfoToken)tokens.First(); if (itoken.Content != "patch") { throw new Exception("Invalid statement format"); } patchInstruction.FuncName = ((InfoToken)((OperandToken)tokens[1]).Tokens[0]).Content; InfoToken keyToken = (InfoToken)((OperandToken)(((PrefixedOperatorToken)tokens[2]).Operand)).Tokens.First(); patchInstruction.Key = keyToken.Content; patchInstruction.Instructions = ParseBlock(((BlockGroupToken)tokens[3]).Tokens).Instructions; return(patchInstruction); } if (tokens.Count != 3) { throw new Exception("Invalid instruction format."); } // On récupère les jetons. InfoToken statementToken = tokens[0] as InfoToken; Token exprToken = tokens[1]; BlockGroupToken blockToken = tokens[2] as BlockGroupToken; if (statementToken == null || blockToken == null || statementToken.Type != TokenType.Statement) { throw new Exception("Invalid instruction format."); } Block block = ParseBlock(blockToken.Tokens, mainContext); switch (statementToken.Content) { case "return": throw new Exception(); case "function": throw new Exception(); /*TokenList exprTokens = ((OperandToken)exprToken).Tokens; * FunctionDeclarationInstruction declaration = new FunctionDeclarationInstruction(); * TokenList nameTokens = ((ParenthesisGroupToken)exprTokens[1]).Tokens; * * // Ici on parcours les jetons de exprToken (qui doit être un OperandToken) * // afin de trouver les noms des arguments. * * // Liste contenant les noms des arguments * List<string> argsNamesLists = new List<string>(); * string funName = ((InfoToken)(exprTokens[0])).Content; * * // Indique si le prochain jeton doit être une virgule * bool needComa = false; * foreach (Token tok in nameTokens) * { * if (needComa && tok.Type != TokenType.Separator) * throw new Exception("Expected ',' token in function declaration"); * else * needComa = false; * // Si c'est un nom : * if (tok.Type == TokenType.OperandTokens && ((OperandToken)tok).Tokens.First().Type == TokenType.Noun) * { * argsNamesLists.Add(((InfoToken)((OperandToken)tok).Tokens.First()).Content); * needComa = true; * } * } * // Setup de la déclaration de fonction. * declaration.Function = new Function(); * declaration.Function.ArgumentNames = argsNamesLists; * declaration.Function.Body = block; * declaration.FunctionName = funName; * * return declaration;*/ break; case "while": IGettable expr = ParseExpression(exprToken, mainContext); block = ParseBlock(blockToken.Tokens, mainContext); WhileStatement statement = new WhileStatement(); statement.Block = block; statement.Condition = expr; return(statement); case "for": // Dans le cas d'une boucle for, expr est une opérande, contenant // une instruction, une expression, et une autre instruction. // (bizarre, certes) TokenList initializationInstruction = new TokenList(); TokenList stepInstruction = new TokenList(); TokenList conditionExpr = new TokenList(); int step = 0; foreach (Token tok in ((OperandToken)exprToken).Tokens) { if (tok.Type == TokenType.EndOfInstruction) { step++; } else { switch (step) { case 0: initializationInstruction.Add(tok); break; case 1: conditionExpr.Add(tok); break; case 2: stepInstruction.Add(tok); break; } } } // On vérifie qu'on ait bien le bon nombre. if (step != 2) { throw new Exception("Incorrect for statement."); } // On crée et on retourne le for. ForStatement forStatement = new ForStatement(); forStatement.Initialisation = ParseInstruction(initializationInstruction, mainContext); forStatement.Condition = ParseExpression(new OperandToken(conditionExpr), mainContext); forStatement.Update = ParseInstruction(stepInstruction, mainContext); forStatement.Block = block; return(forStatement); default: throw new NotImplementedException("Not implemented statement"); } }
public UserFunctionParameter(IGettable gettable, IVariable[] linkedVariables) { Gettable = gettable; LinkedVariables = linkedVariables; }
/// <summary> /// Crée une nouvelle instance de la classe EventSubscribeInstruction. /// </summary> public EventSubscribeInstruction(IGettable evt, IGettable delegat) { Event = evt; Delegate = delegat; }
public ReturnHandler(ActionSet actionSet, IGettable gettable, bool multiplePaths) { _actionSet = actionSet; _multiplePaths = multiplePaths; _returnStore = gettable; }
public AssignedPortableParameter(IVariable variable, IGettable gettable) { Variable = variable; Gettable = gettable; }
public void ApplyChange(IGettable <float> amount) { Value += amount.Value; }
/// <summary> /// Crée un nouveau groupe d'expression. /// </summary> /// <param name="operand1">Première opérande</param> /// <param name="_operator">Opérateur</param> /// <param name="operand2">Seconde opérande.</param> public ExpressionGroup(IGettable operand1, Operator _operator, IGettable operand2) { Operand2 = operand2; Operand1 = operand1; Operator = _operator; }
void ToWorkshop(Func <VarCollection, Rule[]> addRules) { // Set up the variable collection. VarCollection.Setup(); WorkshopConverter = new ToWorkshop(this); // Set up initial global and player rules. InitialGlobal = new TranslateRule(this, "Initial Global", RuleEvent.OngoingGlobal); InitialPlayer = new TranslateRule(this, "Initial Player", RuleEvent.OngoingPlayer); WorkshopRules = new List <Rule>(); WorkshopConverter.InitStatic(); // Init called types. foreach (var workshopInit in _workshopInit) { workshopInit.WorkshopInit(this); } // Assign variables at the rule-set level. foreach (var variable in rulesetVariables) { var addToInitialRule = GetInitialRule(variable.VariableType == VariableType.Global); // Assign the variable an index. IGettable value = variable .GetDefaultInstance(null) .GetAssigner(new(addToInitialRule.ActionSet)) .GetValue(new GettableAssignerValueInfo(addToInitialRule.ActionSet) { SetInitialValue = SetInitialValue.SetIfExists }); DefaultIndexAssigner.Add(variable, value); if (value is IndexReference indexReference) { DebugVariables.Add(variable, indexReference); } } // Parse the rules. foreach (var rule in rules) { var translate = new TranslateRule(this, rule); Rule newRule = GetRule(translate.GetRule()); WorkshopRules.Add(newRule); rule.ElementCountLens.RuleParsed(newRule); } // Add built-in rules. // Initial player if (InitialPlayer.Actions.Count > 0) { WorkshopRules.Insert(0, GetRule(InitialPlayer.GetRule())); } // Initial global if (InitialGlobal.Actions.Count > 0) { WorkshopRules.Insert(0, GetRule(InitialGlobal.GetRule())); } // Additional if (addRules != null) { WorkshopRules.AddRange(addRules.Invoke(VarCollection).Where(rule => rule != null)); } // Complete portable functions WorkshopConverter.LambdaBuilder.Complete(); // Order the workshop rules by priority. WorkshopRules = WorkshopRules.OrderBy(wr => wr.Priority).ToList(); // Get the final workshop string. WorkshopBuilder result = new WorkshopBuilder(Language); LanguageInfo.I18nWarningMessage(result, Language); // Get the custom game settings. if (Importer.MergedLobbySettings != null) { Ruleset settings = Ruleset.Parse(Importer.MergedLobbySettings); settings.ToWorkshop(result); result.AppendLine(); } // Get the variables. VarCollection.ToWorkshop(result); result.AppendLine(); // Get the subroutines. SubroutineCollection.ToWorkshop(result); // Get the rules. for (int i = 0; i < WorkshopRules.Count; i++) { WorkshopRules[i].ToWorkshop(result); ElementCount += WorkshopRules[i].ElementCount(); if (i != WorkshopRules.Count - 1) { result.AppendLine(); } } WorkshopCode = result.GetResult(); }