public override Value Evaluate() { Reject(Regions.VariableExists(macroName), "Create macro", $"Macro name {macroName} already exists"); Regions.CreateVariable(macroName, true); Regions[macroName] = new Macro(); return(null); }
public override Value Evaluate() { Regions.VariableExists(macroName).Must().Not.BeTrue().OrThrow("Create macro", () => $"Macro name {macroName} already exists"); Regions.CreateVariable(macroName, true); Regions[macroName] = new Macro(); return(null); }
public override Value Evaluate() { if (sourceVariableName != null) { value = Regions[sourceVariableName]; } Regions.CreateVariable(variableName); var variable = new Variable(variableName); value.AssignTo(variable); return(null); }
public override Value Evaluate() { if (traitNames != null) { foreach (var(key, value) in traitNames .Select(name => Regions[name]).OfType <Trait>() .SelectMany(parentTrait => parentTrait.Members .Where(item => !trait.Members.ContainsKey(item.Key)))) { trait.Members[key] = value; } } Regions.CreateVariable(trait.Name); Regions[trait.Name] = trait; result = trait.ToString(); return(null); }
public override Value Evaluate() { PseudoRecursion pseudoRecursion; if (Regions.VariableExists(name)) { var value = Regions[name]; if (!(value is PseudoRecursion)) { pseudoRecursion = new PseudoRecursion(name); Regions[name] = pseudoRecursion; } else { pseudoRecursion = (PseudoRecursion)value; } } else { pseudoRecursion = new PseudoRecursion(name); Regions.CreateVariable(name); Regions[name] = pseudoRecursion; } if (parameters.Length == 0) { pseudoRecursion.Initialization = block; } else { var parameterBlock = new ParameterBlock(parameters, block, parameters.Splatting); if (pseudoRecursion.TerminalExpression == null) { pseudoRecursion.TerminalExpression = parameterBlock; } else { pseudoRecursion.Main = parameterBlock; pseudoRecursion.Initialize(); } } result = ToString(); return(null); }
public override Value Evaluate() { if (multiCapable) { MultiLambda multiLambda = null; InvokableReference reference = null; var isAReference = false; if (Regions.VariableExists(functionName)) { var value = Regions[functionName]; if (value is InvokableReference invokableReference) { isAReference = true; var invokable = invokableReference.Invokable; invokable.Must().Not.BeNull().OrThrow("Create function", () => "Not an invokable"); value = (Value)invokable; } if (value is not MultiLambda multi) { var lambdaItem = (Lambda)value; var multiLambdaItem = new MultiLambdaItem(lambdaItem, false, condition); multi = lambdaItem.Expand ? new ExpansibleLambda(functionName, memoize) : new MultiLambda(functionName, memoize); multi.Add(multiLambdaItem); multiLambda = multi; } } else { multiLambda = lambda.Expand ? new ExpansibleLambda(functionName, memoize) : new MultiLambda(functionName, memoize); Regions.CreateVariable(functionName, global, visibility, overriding); } if (multiLambda is null) { return(null); } var item = new MultiLambdaItem(lambda, false, condition); multiLambda.Add(item); if (isAReference) { reference.Invokable = multiLambda; } else { Regions[functionName] = multiLambda; } if (lambda.Where != null) { multiLambda.Where = lambda.Where; } MarkAsXMethod(functionName, lambda); lambda.Message = functionName; result = representation(); return(null); } if (overriding) { Regions.UnsetReadOnly(functionName); } Regions.CreateVariable(functionName, global, visibility, overriding); var assignedValue = autoInvoke ? (Value) new AutoInvoker(lambda) : lambda; Regions[functionName] = assignedValue; Regions.SetReadOnly(functionName); MarkAsXMethod(functionName, lambda); result = representation(); return(null); }