Beispiel #1
0
    public static IntPtr VariableToSV(Variable var)
    {
        P6any obj = var.Fetch();

        if (obj is SVany)
        {
            return(((SVany)obj).sv);
        }
        else if (obj.Does(Kernel.StrMO))
        {
            string s = Kernel.UnboxAny <string>(obj);
            return(Perl5Interpreter.newSVpvn(s, s.Length));
        }
        else
        {
            throw new NieczaException("can't convert argument to p5 type");
        }
    }
Beispiel #2
0
    public static IntPtr VariableToSV(Variable var)
    {
        P6any obj = var.Fetch();

        if (obj is SVany)
        {
            return(((SVany)obj).sv);
        }
        else if (obj.Does(Compartment.Top.StrMO))
        {
            string s = Kernel.UnboxAny <string>(obj);
            return(MarshalString(s));
        }
        else
        {
            throw new NieczaException("can't convert argument to p5 type");
        }
    }
Beispiel #3
0
 // Coerce a value to numeric and return the group code
 public static P6any GetNumber(Variable v, P6any o, out int rank)
 {
     if (o.mo.num_rank >= 0) {
         rank = o.mo.num_rank;
     } else {
         if (o.Does(o.mo.setting.RealMO)) {
             rank = NR_FLOAT;
             o = InvokeMethod("Bridge", v).Fetch();
             return o;
         }
         o = o.mo.mro_Numeric.Get(v).Fetch();
         rank = o.mo.num_rank;
         if (rank < 0)
             throw new NieczaException("Not a valid primitive number " +
                     o.mo.name);
     }
     if (rank == NR_FIXINT && o is BoxObject<BigInteger>)
         rank = NR_BIGINT;
     return o;
 }
Beispiel #4
0
 // Coerce a value to numeric and return the group code
 public static P6any GetNumber(Variable v, P6any o, out int rank)
 {
     if (o.mo.num_rank >= 0) {
         rank = o.mo.num_rank;
     } else {
         if (o.Does(Kernel.RealMO)) {
             rank = NR_FLOAT;
             o = Kernel.RunInferior(o.InvokeMethod(Kernel.GetInferiorRoot(), "Bridge", new Variable[] { v }, null)).Fetch();
             return o;
         }
         o = o.mo.mro_Numeric.Get(v).Fetch();
         rank = o.mo.num_rank;
         if (rank < 0)
             throw new NieczaException("Not a valid primitive number " +
                     o.mo.name);
     }
     if (rank == NR_FIXINT && o is BoxObject<BigInteger>)
         rank = NR_BIGINT;
     return o;
 }