本文整理汇总了C#中Variable.Fetch方法的典型用法代码示例。如果您正苦于以下问题:C# Variable.Fetch方法的具体用法?C# Variable.Fetch怎么用?C# Variable.Fetch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Variable
的用法示例。
在下文中一共展示了Variable.Fetch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRanges
public override int[] GetRanges(Variable filter) {
bool[] cfilter = new bool[values.Length];
var setting = filter.Fetch().mo.setting;
// minor hack to make :BoolProp work - converts to True/False
if (filter.Fetch().Isa(setting.BoolMO))
filter = filter.Fetch().mo.mro_Str.Get(filter);
for (int i = 0; i < values.Length; i++) {
foreach (string s in values[i]) {
if (DoMatch(s, filter)) {
cfilter[i] = true;
break;
}
}
}
List<int> res = new List<int>();
for (int i = 0; i < data.Length; i += 2) {
if (cfilter[data[i+1]]) {
int upto = (i+2 == data.Length) ? 0x110000 : data[i+2];
if (res.Count > 0 && res[res.Count-1] == data[i]) {
res[res.Count-1] = upto;
} else {
res.Add(data[i]);
res.Add(upto);
}
}
}
return res.ToArray();
}
示例2: DCArg
internal static object DCArg(Variable v) {
P6any o = v.Fetch();
var s = o.mo.setting;
if (o is BoxObject<object>)
return Kernel.UnboxAny<object>(o);
else if (o.IsDefined()) {
if (o.Isa(s.StrMO))
return (string) o.mo.mro_raw_Str.Get(v);
else if (o.Isa(s.BoolMO))
return (bool) o.mo.mro_raw_Bool.Get(v);
else if (o.Isa(s.NumMO)) {
double d = Kernel.UnboxAny<double>(o);
if ((d % 1) == 0 && d <= int.MaxValue && d >= int.MinValue)
return (object)(int)d;
return (object)d;
} else if (o.Isa(s.ListMO)) {
VarDeque it = o.mo.mro_raw_iterator.Get(v);
var lo = new List<object>();
while (Kernel.IterHasFlat(it, true))
lo.Add(DCArg(it.Shift()));
return lo.ToArray();
} else
return (int) o.mo.mro_raw_Numeric.Get(v);
} else
return null;
}
示例3: AssignV
public static void AssignV(Variable lhs, IP6 rhs)
{
if (!lhs.islist) {
lhs.Store(rhs);
} else {
Frame n = lhs.Fetch().InvokeMethod(Kernel.GetInferiorRoot(),
"LISTSTORE",
new Variable[2] { lhs, Kernel.NewROScalar(rhs) }, null);
Kernel.RunInferior(n);
}
}
示例4: CompileCClass
public static object CompileCClass(Variable pair)
{
P6any pairo = pair.Fetch();
Variable tbl = (Variable)pairo.GetSlot(Kernel.EnumMO, "$!key");
Variable sm = (Variable)pairo.GetSlot(Kernel.EnumMO, "$!value");
Property p = (Property)DataSet.GetTable(
tbl.Fetch().mo.mro_raw_Str.Get(tbl));
int[] rranges = p.GetRanges(sm);
object[] cranges = new object[rranges.Length * 2];
for (int i = 0; i < rranges.Length; i++) {
cranges[2*i] = rranges[i];
cranges[2*i+1] = ((i & 1) != 0) ? 0 : 0x3FFFFFFF;
}
return cranges;
}
示例5: tan
[ImplicitConsts] public static Variable tan(Constants c, Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(c, a1,o1, tan_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return c.setting.MakeComplex(v1.Tan());
}
{
double v1 = PromoteToFloat(r1, n1);
return c.setting.MakeFloat(Math.Tan(v1));
}
}
示例6: acosec
public static Variable acosec(Variable a1)
{
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, acosec_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.Acosec());
}
{
double v1 = PromoteToFloat(r1, n1);
return MakeFloat(Math.Asin(1 / v1));
}
}
示例7: cursor_allcaps
public static Variable cursor_allcaps(Variable cv)
{
Cursor c = (Cursor) cv.Fetch();
VarDeque dq = new VarDeque();
for (CapInfo it = c.captures; it != null; it = it.prev) {
if (it.names[0] == null || it.cap == null)
continue; // special node
if (!it.cap.Fetch().Isa(Kernel.MatchMO))
continue;
foreach (string name in it.names)
dq.Unshift(pair(MakeStr(name), it.cap));
}
P6opaque lst = new P6opaque(Kernel.ListMO);
lst.slots[0 /*items*/] = dq;
lst.slots[1 /*rest*/ ] = new VarDeque();
return Kernel.NewRWListVar(lst);
}
示例8: acosech
public static Variable acosech(Variable a1)
{
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(a1,o1, acosech_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return MakeComplex(v1.Acosech());
}
{
Complex v1 = PromoteToComplex(r1, n1);
Complex v2 = v1.Acosech();
if (v2.im < -1e-15 || v2.im > 1e-15) {
return MakeFloat(double.NaN);
} else {
return MakeFloat(v2.re);
}
}
}
示例9: divide
public static Variable divide(Variable a1, Variable a2)
{
int r1, r2;
P6any o1 = a1.Fetch(), o2 = a2.Fetch();
if (!(o1.mo.is_any && o2.mo.is_any))
return HandleSpecial2(a1,a2, o1,o2, divide_d);
P6any n1 = GetNumber(a1, o1, out r1);
P6any n2 = GetNumber(a2, o2, out r2);
if (r1 == NR_COMPLEX || r2 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
Complex v2 = PromoteToComplex(r2, n2);
double sn2 = v2.re*v2.re + v2.im*v2.im;
return MakeComplex((v1.re*v2.re + v1.im*v2.im)/sn2,
(v2.re*v1.im - v2.im*v1.re)/sn2);
}
if (r1 == NR_FLOAT || r2 == NR_FLOAT) {
return MakeFloat(PromoteToFloat(r1, n1) / PromoteToFloat(r2, n2));
}
if (r1 == NR_FATRAT || r2 == NR_FATRAT) {
FatRat v1 = PromoteToFatRat(r1, n1);
FatRat v2 = PromoteToFatRat(r2, n2);
return MakeFatRat(v1.num*v2.den, v1.den*v2.num);
}
if (r1 == NR_FIXRAT || r2 == NR_FIXRAT) {
Rat v1 = PromoteToFixRat(r1, n1);
Rat v2 = PromoteToFixRat(r2, n2);
return MakeFixRat(v1.num*v2.den, v2.num*v1.den);
}
if (r1 == NR_BIGINT || r2 == NR_BIGINT) {
return MakeFixRat(PromoteToBigInt(r1, n1), PromoteToBigInt(r2, n2));
}
return MakeFixRat(PromoteToFixInt(r1, n1), PromoteToFixInt(r2, n2));
}
示例10: sech
[ImplicitConsts] public static Variable sech(Constants c, Variable a1) {
P6any o1 = a1.Fetch();
int r1;
if (!o1.mo.is_any)
return HandleSpecial1(c, a1,o1, sech_d);
P6any n1 = GetNumber(a1, o1, out r1);
if (r1 == NR_COMPLEX) {
Complex v1 = PromoteToComplex(r1, n1);
return c.setting.MakeComplex(v1.Sech());
}
{
Complex v1 = PromoteToComplex(r1, n1);
Complex v2 = v1.Sech();
if (v2.im < -1e-15 || v2.im > 1e-15) {
return c.setting.MakeFloat(double.NaN);
} else {
return c.setting.MakeFloat(v2.re);
}
}
}
示例11: GetAsRational
// Coerce a number to a real rational value - note that this loses
// the "inexact" annotation carried by Nums
public static void GetAsRational(Variable v,
out BigInteger num, out BigInteger den)
{
int rk;
P6any n = GetNumber(v, v.Fetch(), out rk);
if (rk == NR_COMPLEX || rk == NR_FLOAT) {
double dbl = 0;
if (rk == NR_COMPLEX) {
Complex c = Kernel.UnboxAny<Complex>(n);
if (c.im != 0)
throw new NieczaException("Complex cannot be used here");
dbl = c.re;
} else {
dbl = Kernel.UnboxAny<double>(n);
}
ulong bits = (ulong)BitConverter.DoubleToInt64Bits(dbl);
num = (bits & ((1UL << 52) - 1)) + (1UL << 52);
den = (1UL << 52);
if ((bits & (1UL << 63)) != 0) num = -num;
int power = ((int)((bits >> 52) & 0x7FF)) - 0x3FF;
if (power > 0) num <<= power;
else den <<= -power;
SimplifyFrac(ref num, ref den);
}
else if (rk == NR_FATRAT) {
FatRat r = Kernel.UnboxAny<FatRat>(n);
num = r.num; den = r.den;
}
else if (rk == NR_FIXRAT) {
Rat r = Kernel.UnboxAny<Rat>(n);
num = r.num; den = r.den;
}
else if (rk == NR_BIGINT) {
num = Kernel.UnboxAny<BigInteger>(n); den = BigInteger.One;
}
else {
num = Kernel.UnboxAny<int>(n); den = BigInteger.One;
}
}
示例12: GetAsInteger
// Coerce a real number to an integer, truncating towards 0
public static bool GetAsInteger(Variable v, out int small,
out BigInteger big)
{
int rk;
P6any n = GetNumber(v, v.Fetch(), out rk);
small = 0;
if (rk == NR_COMPLEX || rk == NR_FLOAT) {
double dbl = 0;
if (rk == NR_COMPLEX) {
Complex c = Kernel.UnboxAny<Complex>(n);
if (c.im != 0)
throw new NieczaException("Complex cannot be used here");
dbl = c.re;
} else {
dbl = Kernel.UnboxAny<double>(n);
}
ulong bits = (ulong)BitConverter.DoubleToInt64Bits(dbl);
big = (bits & ((1UL << 52) - 1)) + (1UL << 52);
int power = ((int)((bits >> 52) & 0x7FF)) - 0x433;
if (power > 0) big <<= power;
else big >>= -power;
if ((bits & (1UL << 63)) != 0) big = -big;
}
else if (rk == NR_FATRAT) {
FatRat r = Kernel.UnboxAny<FatRat>(n);
big = r.num / r.den;
}
else if (rk == NR_FIXRAT) {
Rat r = Kernel.UnboxAny<Rat>(n);
big = r.num / r.den;
}
else if (rk == NR_BIGINT) {
big = Kernel.UnboxAny<BigInteger>(n);
}
else {
big = BigInteger.Zero; small = Kernel.UnboxAny<int>(n); return false;
}
return true;
}
示例13: cb_finish
public static Variable cb_finish(Variable si, Variable nam) {
StringBuilder sb = new StringBuilder();
List<object> refs = new List<object>();
Downcaller.SerializeNam(nam, sb, refs);
object[] args = new object[refs.Count + 3];
args[0] = "sub_finish";
args[1] = Kernel.UnboxAny<object>(si.Fetch());
args[2] = sb.ToString();
refs.CopyTo(args, 3);
return Downcaller.DCResult(si.Fetch().mo.setting, Downcaller.RawDowncall(args));
}
示例14: cb_init_slave
// Better, but still fudgy. Relies too much on path structure.
public static void cb_init_slave(Variable cb, P6any cmd_obj_dir, Variable unit,
Variable staticSub, Variable type, Variable param, Variable value) {
if (Downcaller.responder != null) return;
Downcaller.UnitP = unit.Fetch();
Downcaller.StaticSubP = staticSub.Fetch();
Downcaller.TypeP = type.Fetch();
Downcaller.ParamP = param.Fetch();
Downcaller.ValueP = value.Fetch();
string[] obj_dirs =
!cmd_obj_dir.IsDefined() ? new string[0] :
cmd_obj_dir.Isa(cmd_obj_dir.mo.setting.StrMO) ?
new string[] { cmd_obj_dir.mo.mro_raw_Str.Get(cmd_obj_dir) } :
Builtins.UnboxLoS(Kernel.NewRWListVar(cmd_obj_dir)) ;
if (obj_dirs.Length == 0) {
obj_dirs = new string[2];
obj_dirs[0] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Path.Combine("..", "obj"));
obj_dirs[1] = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NieczaModuleCache");
}
for (int i = 0; i < obj_dirs.Length; i++) {
Directory.CreateDirectory(obj_dirs[i]); // mkdir -p
obj_dirs[i] = Path.GetFullPath(obj_dirs[i]);
}
Downcaller.obj_dirs = obj_dirs;
Downcaller.upcall_cb = cb;
Downcaller.responder = (IDictionary) new Niecza.CLRBackend.DowncallReceiver();
}
示例15: SerializeNam
internal static void SerializeNam(Variable v, StringBuilder sb,
List<object> refs) {
P6any o = v.Fetch();
if (o is BoxObject<int>) { /* includes bool */
sb.Append(Kernel.UnboxAny<int>(o));
} else if (o is BoxObject<double>) {
sb.Append(Utils.N2S(Kernel.UnboxAny<double>(o)));
} else if (o is BoxObject<string>) {
string s = Kernel.UnboxAny<string>(o);
sb.Append('"');
foreach (char c in s) {
if (c >= ' ' && c <= '~' && c != '\\' && c != '"')
sb.Append(c);
else {
sb.Append("\\u");
sb.AppendFormat("{0:X4}", (int)c);
}
}
sb.Append('"');
} else if (!o.IsDefined()) {
sb.Append("null");
} else if (o.Isa(o.mo.setting.ListMO)) {
VarDeque d = o.mo.mro_raw_iterator.Get(v);
bool comma = false;
sb.Append('[');
while (Kernel.IterHasFlat(d, true)) {
if (comma) sb.Append(',');
SerializeNam(d.Shift(), sb, refs);
comma = true;
}
sb.Append(']');
} else if (o is BoxObject<object>) {
sb.Append('!');
sb.Append(refs.Count);
refs.Add(Kernel.UnboxAny<object>(o));
} else {
throw new NieczaException("weird object in sub_finish " + o.mo.name);
}
}