protected Block getExpandedBlock(Arguments arguments) { var region = new Region(); using var popper = new RegionPopper(region, "invoke expanded"); items.Must().HaveCountOfExactly(2).OrThrow(LOCATION, () => "There must be exactly two functions"); var item0 = items[0]; var item1 = items[1]; var lambda0 = item0.Lambda; var lambda1 = item1.Lambda; var parameters0 = lambda0.Parameters; var parameters1 = lambda1.Parameters; parameters0.AnyComparisands.Must().BeTrue().OrThrow(LOCATION, () => "The first function must have a comparisand"); var values = parameters1.GetArguments(arguments); popper.Push(); var(checkExpression, checkVariable) = firstComparisand(lambda0.Parameters); var expander = new Expander(functionName, item1.Lambda.Block, checkExpression, checkVariable, lambda0.Block, region); SetArguments(values); foreach (var parameter in parameters1.GetParameters()) { expander.AddParameter(parameter); } var block = expander.Expand(); return(block); }
public Value Next() { using var popper = new RegionPopper(region, "object-seq-next"); popper.Push(); return(MessageManager.MessagingState.SendMessage(obj, "next", new Arguments())); }
Block getExpandedBlock(Arguments arguments) { var region = new Region(); using (var popper = new RegionPopper(region, "invoke expanded")) { Assert(items.Count == 2, LOCATION, "There must be exactly two functions"); var item0 = items[0]; var item1 = items[1]; var lambda0 = item0.Lambda; var lambda1 = item1.Lambda; var parameters0 = lambda0.Parameters; var parameters1 = lambda1.Parameters; Assert(parameters0.AnyComparisands, LOCATION, "The first function must have a comparisand"); var values = parameters1.GetArguments(arguments); popper.Push(); (var checkExpression, var checkVariable) = firstComparisand(lambda0.Parameters); var expander = new Expander(functionName, item1.Lambda.Block, checkExpression, checkVariable, lambda0.Block, region); SetArguments(values); foreach (var parameter in parameters1.GetParameters()) { expander.AddParameter(parameter); } var block = expander.Expand(); return(block); } }
public virtual Value EvaluateAsLambda(NSIterator iterator, Parameters parameters, Block block) { using (var popper = new RegionPopper(new Region(), "any-of")) { popper.Push(); for (var i = 0; i < MAX_LOOP; i++) { var current = iterator.Next(); if (current.IsNil) { return(IfNil()); } parameters.SetValues(current, i); if (BlockCompare(block)) { var success = Success(); if (success.IsSome) { return(success.Value); } } } return(Final()); } }
public override Value Evaluate() { var continuing = isWhile ? func(() => condition.IsTrue) : func(() => !condition.IsTrue); var index = 0; using (var popper = new RegionPopper(new Region(), "c-for")) { popper.Push(); for (initialization.Evaluate(); continuing() && index++ < MAX_LOOP; increment.Evaluate()) { using (var innerPopper = new RegionPopper(new Region(), "c-for-body")) { innerPopper.Push(); body.Evaluate(); var signal = Signal(); if (signal == Breaking || signal == ReturningNull) { break; } } } result = index == 1 ? "1 loop" : $"{index} loops"; return(index); } }
public override Value Next() { using var popper = new RegionPopper(region, "for-generator"); popper.Push(); if (blockGenerating) { parameters.SetValues(sourceValue, index); var value = blockGenerator.Next(); if (!value.IsNil) { index++; return(value); } blockGenerating = false; } sourceValue = sourceGenerator.Next(); if (sourceValue.IsNil) { return(sourceValue); } blockGenerator.Reset(); index++; blockGenerating = true; return(Values.Ignore.IgnoreValue); }
public static string Iterate(INSGenerator generator, Parameters parameters, Block block) { var iterator = new NSIterator(generator); var index = 0; using var popper = new RegionPopper(new Region(), "for"); popper.Push(); iterator.Reset(); for (var i = 0; i < MAX_LOOP; i++) { index = i; var next = iterator.Next(); if (next.IsNil) { break; } parameters.SetValues(next, i); block.Evaluate(); var signal = Signal(); if (signal == Breaking || signal == ReturningNull) { break; } } return(index == 1 ? "1 iteration" : $"{index} iterations"); }
public Value SetItem() { var popped = Arguments.Values.Pop(); if (popped.IsNone) { return(this); } var value = popped.Value.Element.AssignmentValue(); var values = popped.Value.Array; using (var popper = new RegionPopper(new Region(), "set-item")) { popper.Push(); Regions.Current.SetParameter("$", builder.Length); var arguments = new Array(values); var iterator = new NSIteratorByLength(arguments.GetGenerator(), builder.Length); var list = iterator.ToList(); var text = value.Text; foreach (var index in list) { setItem(index, text); } } return(this); }
public static bool Match(Value left, Value right, Region region, bool usePopper, bool required, Block condition, string bindingName = "", bool assigning = false) { if (usePopper) { using var popper = new RegionPopper(region, "case match"); popper.Push(); return(Match(left, right, required, condition, bindingName, assigning)); } return(Match(left, right, required, condition, bindingName, assigning)); }
public static Value SendSuperMessage(Class super, string messageName, Arguments arguments) { var reference = State.GetInvokeable(Object.InvokeableName(super.Name, true, messageName)); RejectNull(reference, LOCATION, $"reference for super.{Unmangle(messageName)} couldn't be found"); using (var popper = new RegionPopper(new Region(), "super")) { if (super.SuperName.IsNotEmpty()) { var newSuper = Regions[super.SuperName]; popper.Push(); Regions.SetParameter("super", newSuper); } else { popper.Push(); Regions.SetParameter("super", ""); } var value = reference.Invoke(arguments); return(value); } }
public override Value Next() { using var popper = new RegionPopper(region, "pseudo-stream-next"); popper.Push(); if (++index < array.Length) { var value = array[index]; if (evaluate(ifBlock, value).IsTrue) { return(value); } } return(new Nil()); }
public Value GetItem() { using (var popper = new RegionPopper(new Region(), "get-item")) { popper.Push(); Regions.Current.SetParameter("$", builder.Length); var arguments = new Array(Arguments.GetValues(builder.Length)); var iterator = new NSIteratorByLength(arguments.GetGenerator(), builder.Length); var list = iterator.ToList(); if (list.Count == 0) { return(""); } return(list.Select(getItem).Listify()); } }
public override Value Evaluate() { var generator = source.Evaluate().PossibleGenerator(); Assert(generator.IsSome, LOCATION, "Generator required"); var array = (Array)generator.Value.Array(); if (array.Length == 0) { return(null); } using (var popper = new RegionPopper(new Region(), "each")) { popper.Push(); var length = array.Length; switch (length) { case 1: evaluateFirst(array[0]); result = "1 iteration"; return(null); case 2: evaluateFirst(array[0]); evaluateLast(array[1], 1); result = "2 iterations"; return(null); } var lastIndex = length - 1; evaluateFirst(array[0]); for (var i = 1; i < lastIndex; i++) { evaluateMiddle(array[i], i); } evaluateLast(array[lastIndex], lastIndex); result = $"{array.Length} iterations"; return(null); } }
public Value Evaluate() { var aGenerator = generator.GetGenerator(); var looping = true; var region = new Region(); using var popper = new RegionPopper(region, GetType().Name.CamelToObjectGraphCase()); popper.Push(); generator.SharedRegion?.CopyAllVariablesTo(region); aGenerator.Before(); for (var i = 0; i < MAX_ARRAY && looping; i++) { var value = generator.GetNext(aGenerator, i, out var control); if (value.IsNil) { break; } switch (control) { case Continuing: SetParameter(parameterName, value, argumentName); value = Map(value); if (Exit(value)) { aGenerator.End(); return(value); } break; case Skipping: continue; case Exiting: looping = false; break; } } aGenerator.End(); return(ReturnValue()); }
public override Value Next() { using (var popper = new RegionPopper(region, "if-generator")) { popper.Push(); switch (ifStage) { case IfStage.Condition: if (condition.IsTrue) { ifStage = IfStage.Result; return(resultGenerator.Next()); } if (elseIf.IsSome) { ifStage = IfStage.ElseIf; return(elseIf.Value.Next()); } if (elseBlockGenerator.IsSome) { ifStage = IfStage.Else; return(elseBlockGenerator.Value.Next()); } return(NilValue); case IfStage.Result: return(resultGenerator.Next()); case IfStage.ElseIf: return(elseIf.Value.Next()); case IfStage.Else: return(elseBlockGenerator.Value.Next()); default: return(IgnoreValue); } } }
public override Value Evaluate() { var value = sourceBlock.Evaluate(); if (value is Object obj) { var region = obj.Region; using (var popper = new RegionPopper(region, "with")) { popper.Push(); result = value.ToString(); typeName = value.Type.ToString(); actionsBlock.Evaluate(); } return(obj); } return(value); }
public override Value Next() { using var popper = new RegionPopper(region, "while-generator"); popper.Push(); if (index++ < MAX_LOOP && (!checkPredicate || predicate())) { var next = blockGenerator.Next(); checkPredicate = false; if (next.IsNil) { next = IgnoreValue; Reset(); } return(next); } return(NilValue); }
public override Value Next() { using (var popper = new RegionPopper(region, "scalar-stream-next")) { popper.Push(); if (current == null) { current = (Double)seed.Number; } else { if (current.Number >= limit) { return(new Nil()); } current = (Double)(current.Number + 1); } return(current); } }
public Value Map() { var region = new Region(); using (var popper = new RegionPopper(region, "and")) { popper.Push(); var block = Arguments.Executable; if (block.CanExecute) { var matched = Case.Match(left.Value, left.Comparisand, region, false, false, null); if (matched) { matched = Case.Match(right.Value, right.Comparisand, region, false, false, null); if (matched) { if (If != null && !If.Evaluate().IsTrue) { left.Matched = false; return(new Nil()); } var result = block.Evaluate(); return(result); } left.Matched = false; return(new Nil()); } left.Matched = false; return(new Nil()); } return(this); } }
public override Value Evaluate() { var evaluated = expression.Evaluate(); Value returned; switch (evaluated) { case None when _guardBlock.IsSome: returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); return(returned); case None when _ifFalse.If(out var ifFalse): returned = ifFalse.Evaluate(); result = _ifFalse.ToString(); typeName = returned.Type.ToString(); return(returned); case None: return(null); case Some when _ifFalse.If(out var ifFalse): returned = ifFalse.Evaluate(); result = returned.ToString(); typeName = returned.Type.ToString(); return(returned); case Some: return(null); } if (_guardBlock.If(out var guardBlock)) { if (guardBlock.IsTrue) { result = guardBlock.ToString(); typeName = guardBlock.Type.ToString(); return(null); } returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); return(returned); } using var popper = new RegionPopper(new Region(), "maybe"); popper.Push(); returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); return(returned); }
public override Value Evaluate() { var evaluated = expression.Evaluate(); Value returned; if (evaluated is None) { if (guardBlock.IsSome) { returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); return(returned); } if (ifFalse.IsSome) { returned = ifFalse.Value.Evaluate(); result = ifFalse.ToString(); typeName = returned.Type.ToString(); return(returned); } return(null); } //var maybe = evaluated.As<Some>(); if (evaluated is Some) { if (ifFalse.IsSome) { returned = ifFalse.Value.Evaluate(); result = returned.ToString(); typeName = returned.Type.ToString(); return(returned); } return(null); } //var value = maybe.Value(); if (guardBlock.IsSome) { //Regions.Current.SetParameter(fieldName, value); if (guardBlock.Value.IsTrue) { result = guardBlock.Value.ToString(); typeName = guardBlock.Value.Type.ToString(); return(null); } returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); return(returned); } using (var popper = new RegionPopper(new Region(), "maybe")) { popper.Push(); //Regions.Current.SetParameter(fieldName, value); returned = ifTrue.Evaluate(); result = ifTrue.ToString(); typeName = returned.Type.ToString(); } return(returned); }