···11-using Prexonite.Compiler.Cil;
22-33-namespace Prexonite.Commands.Lazy;
44-55-public class ToSeqCommand : CoroutineCommand, ICilCompilerAware
66-{
77- #region Singleton pattern
88-99- ToSeqCommand() { }
1010-1111- public static ToSeqCommand Instance { get; } = new();
1212-1313- #endregion
1414-1515- #region Overrides of CoroutineCommand
1616-1717- protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier, PValue[] args)
1818- {
1919- return CoroutineRunStatically(sctxCarrier, args);
2020- }
2121-2222- [SuppressMessage(
2323- "Microsoft.Naming",
2424- "CA1704:IdentifiersShouldBeSpelledCorrectly",
2525- MessageId = nameof(Coroutine)
2626- )]
2727- public static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier getSctx, PValue[] args)
2828- {
2929- if (args == null)
3030- throw new ArgumentNullException(nameof(args));
3131- if (getSctx == null)
3232- throw new ArgumentNullException(nameof(getSctx));
3333-3434- if (args.Length < 1)
3535- throw new PrexoniteException("toseq requires one argument.");
3636-3737- var xsT = args[0];
3838- PValue xs;
3939-4040- var sctx = getSctx.StackContext;
4141-4242- while (!(xs = ForceCommand.Force(sctx, xsT)).IsNull)
4343- {
4444- //Accept key value pairs directly
4545- if (xs.Value is PValueKeyValuePair kvp)
4646- {
4747- yield return kvp.Key;
4848- xsT = kvp.Value;
4949- }
5050- //Late bound
5151- else
5252- {
5353- var k = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Key");
5454- yield return k;
5555- xsT = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Value");
5656- }
5757- }
5858- }
5959-6060- #endregion
6161-6262- #region Implementation of ICilCompilerAware
6363-6464- CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins)
6565- {
6666- return CompilationFlags.PrefersRunStatically;
6767- }
6868-6969- public static PValue RunStatically(StackContext sctx, PValue[] args)
7070- {
7171- var carrier = new ContextCarrier();
7272- var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args));
7373- carrier.StackContext = corctx;
7474- return sctx.CreateNativePValue(new Coroutine(corctx));
7575- }
7676-7777- void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins)
7878- {
7979- throw new NotSupportedException(
8080- "The command "
8181- + GetType().Name
8282- + " does not support CIL compilation via ICilCompilerAware."
8383- );
8484- }
8585-8686- #endregion
8787-}
-2
Prexonite/Engine.cs
···643643 Commands.AddEngineCommand(ThunkAlias, ThunkCommand.Instance);
644644 Commands.AddEngineCommand(AsThunkAlias, AsThunkCommand.Instance);
645645 Commands.AddEngineCommand(ForceAlias, ForceCommand.Instance);
646646- Commands.AddEngineCommand(ToSeqAlias, ToSeqCommand.Instance);
647646648647 // There is a macro that uses the same alias (Call_MemberAlias)
649648 // it has the same purpose. For backwards compatibility,
···902901 public const string ThunkAlias = "thunk";
903902 public const string AsThunkAlias = "asthunk";
904903 public const string ForceAlias = "force";
905905- public const string ToSeqAlias = "toseq";
906904907905 /// <summary>
908906 /// Alias used for the <c>caller</c> command.