Prexonite, a .NET hosted scripting language with a focus on meta-programming and embedded DSLs
0

Configure Feed

Select the types of activity you want to include in your feed.

Remove ToSeq command

Christian Klauser (Jul 14, 2026, 11:38 PM +0200) fbcedd6a 852cc9e5

+28 -105
-87
Prexonite/Commands/Lazy/ToSeqCommand.cs
··· 1 - using Prexonite.Compiler.Cil; 2 - 3 - namespace Prexonite.Commands.Lazy; 4 - 5 - public class ToSeqCommand : CoroutineCommand, ICilCompilerAware 6 - { 7 - #region Singleton pattern 8 - 9 - ToSeqCommand() { } 10 - 11 - public static ToSeqCommand Instance { get; } = new(); 12 - 13 - #endregion 14 - 15 - #region Overrides of CoroutineCommand 16 - 17 - protected override IEnumerable<PValue> CoroutineRun(ContextCarrier sctxCarrier, PValue[] args) 18 - { 19 - return CoroutineRunStatically(sctxCarrier, args); 20 - } 21 - 22 - [SuppressMessage( 23 - "Microsoft.Naming", 24 - "CA1704:IdentifiersShouldBeSpelledCorrectly", 25 - MessageId = nameof(Coroutine) 26 - )] 27 - public static IEnumerable<PValue> CoroutineRunStatically(ContextCarrier getSctx, PValue[] args) 28 - { 29 - if (args == null) 30 - throw new ArgumentNullException(nameof(args)); 31 - if (getSctx == null) 32 - throw new ArgumentNullException(nameof(getSctx)); 33 - 34 - if (args.Length < 1) 35 - throw new PrexoniteException("toseq requires one argument."); 36 - 37 - var xsT = args[0]; 38 - PValue xs; 39 - 40 - var sctx = getSctx.StackContext; 41 - 42 - while (!(xs = ForceCommand.Force(sctx, xsT)).IsNull) 43 - { 44 - //Accept key value pairs directly 45 - if (xs.Value is PValueKeyValuePair kvp) 46 - { 47 - yield return kvp.Key; 48 - xsT = kvp.Value; 49 - } 50 - //Late bound 51 - else 52 - { 53 - var k = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Key"); 54 - yield return k; 55 - xsT = xs.DynamicCall(sctx, Runtime.EmptyPValueArray, PCall.Get, "Value"); 56 - } 57 - } 58 - } 59 - 60 - #endregion 61 - 62 - #region Implementation of ICilCompilerAware 63 - 64 - CompilationFlags ICilCompilerAware.CheckQualification(Instruction ins) 65 - { 66 - return CompilationFlags.PrefersRunStatically; 67 - } 68 - 69 - public static PValue RunStatically(StackContext sctx, PValue[] args) 70 - { 71 - var carrier = new ContextCarrier(); 72 - var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args)); 73 - carrier.StackContext = corctx; 74 - return sctx.CreateNativePValue(new Coroutine(corctx)); 75 - } 76 - 77 - void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) 78 - { 79 - throw new NotSupportedException( 80 - "The command " 81 - + GetType().Name 82 - + " does not support CIL compilation via ICilCompilerAware." 83 - ); 84 - } 85 - 86 - #endregion 87 - }
-2
Prexonite/Engine.cs
··· 643 643 Commands.AddEngineCommand(ThunkAlias, ThunkCommand.Instance); 644 644 Commands.AddEngineCommand(AsThunkAlias, AsThunkCommand.Instance); 645 645 Commands.AddEngineCommand(ForceAlias, ForceCommand.Instance); 646 - Commands.AddEngineCommand(ToSeqAlias, ToSeqCommand.Instance); 647 646 648 647 // There is a macro that uses the same alias (Call_MemberAlias) 649 648 // it has the same purpose. For backwards compatibility, ··· 902 901 public const string ThunkAlias = "thunk"; 903 902 public const string AsThunkAlias = "asthunk"; 904 903 public const string ForceAlias = "force"; 905 - public const string ToSeqAlias = "toseq"; 906 904 907 905 /// <summary> 908 906 /// Alias used for the <c>caller</c> command.
+2 -2
Prexonite/prxlib/prx.core.pxs
··· 13 13 takewhile,except,range, reverse, headtail, append, sum, contains, 14 14 create_enumerator,seqconcat); 15 15 16 - namespace nonstrict export(*),prx.prim(thunk,asthunk => to_thunk,force,toseq => to_seq); 16 + namespace nonstrict export(*),prx.prim(thunk,asthunk => to_thunk,force); 17 17 18 18 namespace rt 19 19 { ··· 110 110 namespace prx.experimental 111 111 { 112 112 namespace csp export(*), prx.prim(chan,async_seq,call\async,select); 113 - } 113 + }
+1 -2
Prexonite/prxlib/prx.prim.pxs
··· 21 21 thunk = ref command "thunk", 22 22 asthunk = ref command "asthunk", 23 23 force = ref command "force", 24 - toseq = ref command "toseq", 25 24 call\member = expand macro command "call\\member", 26 25 call\member\perform = ref command "call\\member\\perform", 27 26 caller = ref command "caller", ··· 169 168 static_call_String = expand macro command "static_call_String", 170 169 static_call_Structure = expand macro command "static_call_Structure" 171 170 ); 172 - } 171 + }
+1 -2
Prexonite/prxlib/prx.v1.pxs
··· 22 22 thunk, 23 23 asthunk, 24 24 force, 25 - toseq, 26 25 call\member\perform, 27 26 caller, 28 27 pair, ··· 173 172 static_call_Structure 174 173 }; 175 174 176 - } 175 + }
+1 -1
PrexoniteTests/Tests/Compiler.Global.cs
··· 1383 1383 """ 1384 1384 1385 1385 declare function main/testApplication/0.0; 1386 - declare command print,println,meta,boxed,concat,map,select,foldl,foldr,dispose,call\perform,thunk,asthunk,force,toseq,call\member\perform,caller,pair,unbind,sort,orderby,LoadAssembly,debug,setcenter,setleft,setright,all,where,skip,limit,take,abs,ceiling,exp,floor,log,max,min,pi,round,sin,cos,sqrt,tan,char,count,distinct,union,unique,frequency,groupby,intersect,call\tail\perform,list,each,exists,forall,CompileToCil,takewhile,except,range,reverse,headtail,append,sum,contains,chan,call\async\perform,async_seq,call\sub\perform,pa\ind,pa\mem,pa\ctor,pa\check,pa\cast,pa\smem,pa\fun\call,pa\flip\call,pa\call\star,then,id,const,(+),(-),(*),(/),$mod,(^),(&),(|),$xor,(==),(!=),(>),(>=),(<),(<=),(-.),$complement,$not,create_enumerator,create_module_name,seqconcat; 1386 + declare command print,println,meta,boxed,concat,map,select,foldl,foldr,dispose,call\perform,thunk,asthunk,force,call\member\perform,caller,pair,unbind,sort,orderby,LoadAssembly,debug,setcenter,setleft,setright,all,where,skip,limit,take,abs,ceiling,exp,floor,log,max,min,pi,round,sin,cos,sqrt,tan,char,count,distinct,union,unique,frequency,groupby,intersect,call\tail\perform,list,each,exists,forall,CompileToCil,takewhile,except,range,reverse,headtail,append,sum,contains,chan,call\async\perform,async_seq,call\sub\perform,pa\ind,pa\mem,pa\ctor,pa\check,pa\cast,pa\smem,pa\fun\call,pa\flip\call,pa\call\star,then,id,const,(+),(-),(*),(/),$mod,(^),(&),(|),$xor,(==),(!=),(>),(>=),(<),(<=),(-.),$complement,$not,create_enumerator,create_module_name,seqconcat; 1387 1387 declare macro command call,call\member,call\tail,call\async,call\sub,call\sub\interpret,macro\pack,macro\unpack,macro\reference,call\star,call\macro,call\macro\impl; 1388 1388 1389 1389 """
+23 -8
PrexoniteTests/Tests/ThunkTests.cs
··· 90 90 Compile( 91 91 """ 92 92 93 - function _consT hT tT = hT.force : tT; 93 + function _consT hT tT = [hT,tT]; 94 + function _headT xsT = xsT.force[0]; 95 + function _tailT xsT = xsT.force[1]; 94 96 function _refT xT = xT.force.(); 97 + function _addT x1 x2 = x1.force + x2.force; 95 98 96 - function repeatT(x) 99 + function main(x1) 97 100 { 98 - var xsT; 99 - xsT = thunk(->_consT,x,thunk(->_refT,->xsT)); 100 - return xsT; 101 + function repeatT(x) 102 + { 103 + var xsT; 104 + xsT = thunk(->_consT,x,thunk(->_refT,->xsT)); 105 + return xsT; 106 + } 107 + 108 + var x1s = repeatT(x1); 109 + var y1 = thunk(->_headT,x1s); 110 + var y1s = thunk(->_tailT,x1s); 111 + var z1 = thunk(->_headT,y1s); 112 + var z1s = thunk(->_tailT,y1s); 113 + var a1 = thunk(->_headT,z1s); 114 + 115 + var result = thunk(->_addT,y1,thunk(->_addT,z1,a1)); 116 + 117 + return result.force; 101 118 } 102 119 103 - function main(x,n) = foldl((a,b) => a + b,0) << take(n) << toseq << repeatT << x; 104 - 105 120 """ 106 121 ); 107 122 108 - Expect(12, 4, 3); 123 + Expect(12, 4); 109 124 } 110 125 111 126 [Test]
-1
PrexoniteTests/Tests/Translation.cs
··· 361 361 thunk = ref command "thunk", 362 362 asthunk = ref command "asthunk", 363 363 force = ref command "force", 364 - toseq = ref command "toseq", 365 364 call\member = expand macro command "call\\member", 366 365 call\member\perform = ref command "call\\member\\perform", 367 366 caller = ref command "caller",