本文整理汇总了C#中StackContext类的典型用法代码示例。如果您正苦于以下问题:C# StackContext类的具体用法?C# StackContext怎么用?C# StackContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StackContext类属于命名空间,在下文中一共展示了StackContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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;
}