本文整理汇总了C#中StackContext类的典型用法代码示例。如果您正苦于以下问题:C# StackContext类的具体用法?C# StackContext怎么用?C# StackContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StackContext类属于命名空间,在下文中一共展示了StackContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Run
public override PValue Run(StackContext sctx, PValue[] args)
{
if(args.Length < 2)
throw new PrexoniteException("The Subtraction operator requires two arguments.");
return args[0].Subtraction(sctx,args[1]);
}
开发者ID:SealedSun,项目名称:prx,代码行数:7,代码来源:Operators.cs
示例2: Run
/// <summary>
/// Prints all arguments.
/// </summary>
/// <param name = "sctx">The context in which to convert the arguments to strings.</param>
/// <param name = "args">The list of arguments to print.</param>
/// <returns></returns>
public override PValue Run(StackContext sctx, PValue[] args)
{
var s = Concat.ConcatenateString(sctx, args);
_writer.Write(s);
return s;
}
开发者ID:SealedSun,项目名称:prx,代码行数:13,代码来源:Print.cs
示例3: Run
/// <summary>
/// Implementation of (obj, [isSet, ] id, arg1, arg2, arg3, ..., argn) ⇒ obj.id(arg1, arg2, arg3, ..., argn);
/// </summary>
/// <remarks>
/// <para>
/// Wrap Lists in other lists, if you want to pass them without being unfolded:
/// <code>
/// function main()
/// { var myList = [1, 2];
/// var obj = "{1}hell{0}";
/// print( call\member(obj, "format", [ myList ]) );
/// }
///
/// //Prints "2hell1"
/// </code>
/// </para>
/// </remarks>
/// <param name = "sctx">The stack context in which to call the callable argument.</param>
/// <param name = "args">A list of the form [ obj, id, arg1, arg2, arg3, ..., argn].<br />
/// Lists and coroutines are expanded.</param>
/// <returns>The result returned by the member call.</returns>
public override PValue Run(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null || args.Length < 2 || args[0] == null)
throw new ArgumentException(
"The command callmember has the signature(obj, [isSet,] id [, arg1, arg2,...,argn]).");
var isSet = false;
string id;
var i = 2;
if (args[1].Type == PType.Bool && args.Length > 2)
{
isSet = (bool) args[1].Value;
id = args[i++].CallToString(sctx);
}
else
{
id = args[1].CallToString(sctx);
}
var iargs = new PValue[args.Length - i];
Array.Copy(args, i, iargs, 0, iargs.Length);
return Run(sctx, args[0], isSet, id, iargs);
}
开发者ID:SealedSun,项目名称:prx,代码行数:49,代码来源:Call_Member.cs
示例4: TryDefer
public bool TryDefer(StackContext sctx, PValue[] args,
out StackContext partialApplicationContext, out PValue result)
{
var effectiveArgs = _getEffectiveArgs(args);
partialApplicationContext = null;
result = null;
//The following code exists in a very similar form in PartialCall.cs, FunctionalPartialCall.cs
if ((_subject.Type is ObjectPType))
{
var raw = _subject.Value;
var stackAware = raw as IStackAware;
if (stackAware != null)
{
partialApplicationContext = stackAware.CreateStackContext(sctx, effectiveArgs);
return true;
}
var partialApplication = raw as IMaybeStackAware;
if (partialApplication != null)
return partialApplication.TryDefer(sctx, effectiveArgs,
out partialApplicationContext,
out result);
}
result = _subject.IndirectCall(sctx, effectiveArgs);
return false;
}
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:FlippedFunctionalPartialCall.cs
示例5: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (args == null)
throw new ArgumentNullException("args");
if (sctx == null)
throw new ArgumentNullException("sctx");
//let sum xs acc = Seq.foldl (fun a b -> a + b) acc xs
PValue acc;
IEnumerable<PValue> xsArgs;
if (args.Length == 0)
return PType.Null;
if (args.Length == 1)
{
acc = PType.Null;
xsArgs = args;
}
else
{
acc = args[args.Length - 1];
xsArgs = args.Take(args.Length - 1);
}
var xss = xsArgs.Select(e => Map._ToEnumerable(sctx, e)).Where(e => e != null);
foreach (var xs in xss)
foreach (var x in xs)
acc = acc.Addition(sctx, x);
return acc;
}
开发者ID:SealedSun,项目名称:prx,代码行数:34,代码来源:Sum.cs
示例6: RunStatically
/// <summary>
/// Executes the command.
/// </summary>
/// <param name = "sctx">The stack context in which to execut the command.</param>
/// <param name = "args">The arguments to be passed to the command.</param>
/// <returns>The value returned by the command. Must not be null. (But possibly {null~Null})</returns>
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
throw new ArgumentNullException("args");
if (args.Length < 1)
throw new PrexoniteException("Char requires at least one argument.");
PValue v;
var arg = args[0];
if (arg.Type == PType.String)
{
var s = (string) arg.Value;
if (s.Length == 0)
throw new PrexoniteException("Cannot create char from empty string.");
else
return s[0];
}
else if (arg.TryConvertTo(sctx, PType.Char, true, out v))
{
return v;
}
else if (arg.TryConvertTo(sctx, PType.Int, true, out v))
{
return (char) (int) v.Value;
}
else
{
throw new PrexoniteException("Cannot create char from " + arg);
}
}
开发者ID:SealedSun,项目名称:prx,代码行数:39,代码来源:Char.cs
示例7: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (args.Length == 0)
{
return sctx.CreateNativePValue(NoSourcePosition.Instance);
}
string file = args[0].CallToString(sctx);
int? line, column;
PValue box;
if (args.Length >= 2 && args[1].TryConvertTo(sctx, IntPType.Instance,true,out box))
{
line = (int) box.Value;
}
else
{
line = null;
}
if (args.Length >= 3 && args[2].TryConvertTo(sctx, IntPType.Instance, true, out box))
{
column = (int) box.Value;
}
else
{
column = null;
}
return sctx.CreateNativePValue(new SourcePosition(file, line ?? -1, column ?? -1));
}
开发者ID:SealedSun,项目名称:prx,代码行数:31,代码来源:CreateSourcePosition.cs
示例8: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
throw new ArgumentNullException("args");
if (args.Length < 1)
throw new PrexoniteException("Each requires at least two arguments");
var f = args[0];
var eargs = new PValue[1];
for (var i = 1; i < args.Length; i++)
{
var arg = args[i];
var set = Map._ToEnumerable(sctx, arg);
if (set == null)
continue;
foreach (var value in set)
{
eargs[0] = value;
f.IndirectCall(sctx, eargs);
}
}
return PType.Null;
}
开发者ID:SealedSun,项目名称:prx,代码行数:27,代码来源:Each.cs
示例9: RunStatically
/// <summary>
/// Executes the command.
/// </summary>
/// <param name = "sctx">The stack context in which to execut the command.</param>
/// <param name = "args">The arguments to be passed to the command.</param>
/// <returns>The value returned by the command. Must not be null. (But possibly {null~Null})</returns>
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
var text = Concat.ConcatenateString(sctx, args);
StaticPrint.Writer.WriteLine(text);
return text;
}
开发者ID:SealedSun,项目名称:prx,代码行数:13,代码来源:StaticPrintLine.cs
示例10: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
throw new ArgumentNullException("args");
PValue needle;
if (args.Length < 2)
return false;
else
needle = args[0];
foreach (var arg in args.Skip(1))
{
var set = Map._ToEnumerable(sctx, arg);
if (set != null)
foreach (var value in set)
{
PValue result;
bool boolResult;
if (value.Equality(sctx, needle, out result) &&
result.TryConvertTo(sctx, true, out boolResult) && boolResult)
return result;
}
}
return false;
}
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:Contains.cs
示例11: Run
public override PValue Run(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
throw new ArgumentNullException("args");
if (args.Length < 1)
throw new PrexoniteException("Exists requires at least two arguments");
var f = args[0];
var eargs = new PValue[1];
for (var i = 1; i < args.Length; i++)
{
var arg = args[i];
var set = Map._ToEnumerable(sctx, arg);
if (set == null)
continue;
foreach (var value in set)
{
eargs[0] = value;
var result = f.IndirectCall(sctx, eargs);
PValue existance;
if ((!result.TryConvertTo(sctx, PType.Bool, true, out existance)) ||
(!(bool) existance.Value))
return false;
}
}
return true;
}
开发者ID:SealedSun,项目名称:prx,代码行数:31,代码来源:ForAll.cs
示例12: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
var carrier = new ContextCarrier();
var corctx = new CoroutineContext(sctx, CoroutineRunStatically(carrier, args));
carrier.StackContext = corctx;
return sctx.CreateNativePValue(new Coroutine(corctx));
}
开发者ID:SealedSun,项目名称:prx,代码行数:7,代码来源:SeqConcat.cs
示例13: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
// function setright(w,s,f)
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
args = new PValue[] {};
string s;
string f;
switch (args.Length)
{
case 0:
return "";
case 1:
s = "";
goto parseW;
}
s = args[1].CallToString(sctx);
parseW:
var w = (int) args[0].ConvertTo(sctx, PType.Int).Value;
if (args.Length > 2)
f = args[2].CallToString(sctx);
else
f = " ";
return SetRight(w, s, f);
}
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:SetRightCommand.cs
示例14: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null || args.Length == 0 || args[0] == null)
return PType.Null.CreatePValue();
var iargs = Call.FlattenArguments(sctx, args, 1);
var retChan = new Channel();
var T = new Thread(() =>
{
PValue result;
try
{
result = args[0].IndirectCall(sctx, iargs.ToArray());
}
catch (Exception ex)
{
result = sctx.CreateNativePValue(ex);
}
retChan.Send(result);
})
{
IsBackground = true
};
T.Start();
return PType.Object.CreatePValue(retChan);
}
开发者ID:SealedSun,项目名称:prx,代码行数:29,代码来源:CallAsync.cs
示例15: DoTryDefer
protected override bool DoTryDefer(StackContext sctx, PValue[] nonArguments,
PValue[] arguments, out StackContext partialApplicationContext, out PValue result)
{
partialApplicationContext = null;
result = null;
//The following code exists in a very similar form in FunctionalPartialCall.cs, FlippedFunctionalPartialCall.cs
if ((nonArguments[0].Type is ObjectPType))
{
var raw = nonArguments[0].Value;
var stackAware = raw as IStackAware;
if (stackAware != null)
{
partialApplicationContext = stackAware.CreateStackContext(sctx, arguments);
return true;
}
var partialApplication = raw as IMaybeStackAware;
if (partialApplication != null)
return partialApplication.TryDefer(sctx, arguments,
out partialApplicationContext,
out result);
}
result = Invoke(sctx, nonArguments, arguments);
return false;
}
开发者ID:SealedSun,项目名称:prx,代码行数:27,代码来源:PartialCall.cs
示例16: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (args == null)
throw new ArgumentNullException("args");
if (sctx == null)
throw new ArgumentNullException("sctx");
var xss = new List<IEnumerable<PValue>>();
foreach (var arg in args)
{
var xs = Map._ToEnumerable(sctx, arg);
if (xs != null)
xss.Add(xs);
}
var n = xss.Count;
if (n < 2)
throw new PrexoniteException("Except requires at least two sources.");
var t = new Dictionary<PValue, bool>();
//All elements of the last source are considered candidates
foreach (var x in xss[n - 1])
if (!t.ContainsKey(x))
t.Add(x, true);
for (var i = 0; i < n - 1; i++)
foreach (var x in xss[i])
if (t.ContainsKey(x))
t.Remove(x);
return sctx.CreateNativePValue(t.Keys);
}
开发者ID:SealedSun,项目名称:prx,代码行数:32,代码来源:Except.cs
示例17: IndirectCall
public override bool IndirectCall(
StackContext sctx, PValue subject, PValue[] args, out PValue result)
{
if (sctx == null)
throw new ArgumentNullException("sctx");
if (subject == null)
throw new ArgumentNullException("subject");
if (args == null)
args = new PValue[] {};
result = null;
var argc = args.Length;
var pvht = (PValueHashtable) subject.Value;
if (argc == 0)
{
result =
sctx.CreateNativePValue(new PValueEnumeratorWrapper(pvht.GetPValueEnumerator()));
}
else if (argc == 1)
{
if (!pvht.TryGetValue(args[0], out result))
result = false;
}
else
{
pvht.AddOverride(args[0], args[1]);
}
return result != null;
}
开发者ID:SealedSun,项目名称:prx,代码行数:33,代码来源:HashPType.cs
示例18: TryConstruct
public override bool TryConstruct(StackContext sctx, PValue[] args, out PValue result)
{
char c;
result = null;
if (sctx == null)
throw new ArgumentNullException("sctx");
if (args == null)
throw new ArgumentNullException("args");
PValue v;
if (args.Length < 1 || args[0].IsNull)
{
c = '\0';
}
else if (args[0].TryConvertTo(sctx, Char, out v))
{
c = (char) v.Value;
}
else if (args[0].TryConvertTo(sctx, Int, false, out v))
{
c = (char) (int) v.Value;
}
else
{
c = '\0';
}
result = c;
return true;
}
开发者ID:SealedSun,项目名称:prx,代码行数:32,代码来源:CharPType.cs
示例19: RunStatically
public static PValue RunStatically(StackContext sctx, PValue[] args)
{
if (args.Length < 2)
throw new PrexoniteException("then command requires two arguments.");
return sctx.CreateNativePValue(new CallComposition(args[0], args[1]));
}
开发者ID:SealedSun,项目名称:prx,代码行数:7,代码来源:ThenCommand.cs
示例20: EnumeratorProxy
public EnumeratorProxy(StackContext sctx, PValue moveNext, PValue current,
PValue dispose)
{
_moveNext = moveNext;
_sctx = sctx;
_current = current;
_dispose = dispose;
}
开发者ID:SealedSun,项目名称:prx,代码行数:8,代码来源:CreateEnumerator.cs
注:本文中的StackContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论