本文整理汇总了C#中P6any.IsDefined方法的典型用法代码示例。如果您正苦于以下问题:C# P6any.IsDefined方法的具体用法?C# P6any.IsDefined怎么用?C# P6any.IsDefined使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类P6any
的用法示例。
在下文中一共展示了P6any.IsDefined方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PromoteToFloat
// If a number is <= NR_FLOAT, return it as if at NR_FLOAT
public static double PromoteToFloat(int rank, P6any vret)
{
Rat r; FatRat fr;
if (!vret.IsDefined()) return 0;
switch (rank) {
case NR_FIXINT:
return Kernel.UnboxAny<int>(vret);
case NR_BIGINT:
return (double)Kernel.UnboxAny<BigInteger>(vret);
case NR_FIXRAT:
r = Kernel.UnboxAny<Rat>(vret);
return (double)r.num / (double)r.den;
case NR_FATRAT:
fr = Kernel.UnboxAny<FatRat>(vret);
return (double)fr.num / (double)fr.den;
case NR_FLOAT:
default:
return Kernel.UnboxAny<double>(vret);
}
}
示例2: 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();
}
示例3: PromoteToFixInt
// If a number is <= NR_FIXINT, return it as if at NR_FIXINT
public static int PromoteToFixInt(int rank, P6any vret)
{
if (!vret.IsDefined()) return 0;
return Kernel.UnboxAny<int>(vret);
}
示例4: PromoteToFixRat
// If a number is <= NR_FIXRAT, return it as if at NR_FIXRAT
public static Rat PromoteToFixRat(int rank, P6any vret)
{
if (!vret.IsDefined()) return new Rat(BigInteger.Zero, 1);
switch (rank) {
case NR_FIXINT:
return new Rat(Kernel.UnboxAny<int>(vret), 1);
case NR_BIGINT:
return new Rat(Kernel.UnboxAny<BigInteger>(vret), 1);
case NR_FIXRAT:
default:
return Kernel.UnboxAny<Rat>(vret);
}
}
示例5: PromoteToFatRat
// If a number is <= NR_FATRAT, return it as if at NR_FATRAT
public static FatRat PromoteToFatRat(int rank, P6any vret)
{
Rat r;
if (!vret.IsDefined()) return new FatRat(BigInteger.Zero,BigInteger.One);
switch (rank) {
case NR_FIXINT:
return new FatRat(Kernel.UnboxAny<int>(vret), BigInteger.One);
case NR_BIGINT:
return new FatRat(Kernel.UnboxAny<BigInteger>(vret), BigInteger.One);
case NR_FIXRAT:
r = Kernel.UnboxAny<Rat>(vret);
return new FatRat(r.num, r.den);
case NR_FATRAT:
default:
return Kernel.UnboxAny<FatRat>(vret);
}
}
示例6: PromoteToComplex
// If a number is <= NR_COMPLEX, return it as if at NR_COMPLEX
public static Complex PromoteToComplex(int rank, P6any vret)
{
Rat r; FatRat fr;
if (!vret.IsDefined()) return new Complex(0,0);
switch (rank) {
case NR_FIXINT:
return new Complex(Kernel.UnboxAny<int>(vret), 0);
case NR_BIGINT:
return new Complex((double)Kernel.UnboxAny<BigInteger>(vret), 0);
case NR_FIXRAT:
r = Kernel.UnboxAny<Rat>(vret);
return new Complex((double)r.num / (double)r.den, 0);
case NR_FATRAT:
fr = Kernel.UnboxAny<FatRat>(vret);
return new Complex((double)fr.num / (double)fr.den, 0);
case NR_FLOAT:
return new Complex(Kernel.UnboxAny<double>(vret), 0);
case NR_COMPLEX:
default:
return Kernel.UnboxAny<Complex>(vret);
}
}
示例7: PromoteToBigInt
// If a number is <= NR_BIGINT, return it as if at NR_BIGINT
public static BigInteger PromoteToBigInt(int rank, P6any vret)
{
if (!vret.IsDefined()) return BigInteger.Zero;
switch (rank) {
case NR_FIXINT:
return Kernel.UnboxAny<int>(vret);
case NR_BIGINT:
default:
return Kernel.UnboxAny<BigInteger>(vret);
}
}
示例8: mixin
public static Variable mixin(Constants c, P6any obj, Variable role_list, Variable init,
Variable newtype)
{
VarDeque iter = start_iter(role_list);
List<STable> roles = new List<STable>();
while (Kernel.IterHasFlat(iter, true))
roles.Add(iter.Shift().Fetch().mo);
STable n = new STable(c.setting, obj.mo.name + "+" + Kernel.JoinS(",", roles));
n.how = Kernel.BoxAny<STable>(n, obj.mo.how).Fetch();
n.typeObj = n.initObj = new P6opaque(n);
((P6opaque)n.typeObj).slots = null;
n.mo.superclasses.Add(obj.mo);
n.mo.local_roles = roles;
n.mo.Compose();
newtype.Store(n.typeObj);
string aname = null;
if (init != c.setting.AnyP) {
if (!obj.IsDefined())
throw new NieczaException("Cannot initialize a slot when mixing into a type object");
if (n.mo.local_attr.Count != 1 || (n.mo.local_attr[0].flags & P6how.A_PUBLIC) == 0)
throw new NieczaException("Role(s) being mixed in do not define precisely one, public attribute");
aname = n.mo.local_attr[0].name;
}
if (obj.IsDefined()) {
obj.ChangeType(n);
BuildMostDerived(obj);
if (aname != null)
Kernel.Assign((Variable)obj.GetSlot(n, aname), init);
return obj;
} else {
return n.typeObj;
}
}
示例9: InitSlave
// Better, but still fudgy. Relies too much on path structure.
public static void InitSlave(Variable cb, P6any cmd_obj_dir, Variable unit,
Variable staticSub, Variable type, Variable param, Variable value)
{
if (responder != null) return;
UnitP = unit.Fetch();
StaticSubP = staticSub.Fetch();
TypeP = type.Fetch();
ParamP = param.Fetch();
ValueP = value.Fetch();
obj_dir = Path.GetFullPath(cmd_obj_dir.IsDefined() ?
cmd_obj_dir.mo.mro_raw_Str.Get(cmd_obj_dir) :
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"NieczaModuleCache"));
Directory.CreateDirectory(obj_dir); // like mkdir -p
if (!File.Exists(Path.Combine(obj_dir, "Run.Kernel.dll"))) {
File.Copy(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Run.Kernel.dll"),
Path.Combine(obj_dir, "Run.Kernel.dll")
);
}
AppDomain.CurrentDomain.AssemblyResolve += ObjLoader;
upcall_cb = cb;
responder = (IDictionary) Activator.CreateInstance(Type.GetType(
"Niecza.CLRBackend.DowncallReceiver,Run.Kernel", true));
RawDowncall("set_binding", obj_dir, new UpcallReceiver());
}