Beispiel #1
0
 public override void Compile()
 {
     if (index >= 0)
     {
         ilg.Emit(OpCodes.Ldc_I4, index);
         ilg.Emit(OpCodes.Call, getArrayViewMethod);
     }
     else
     {
         LoadErrorValue(ErrorValue.Make("#FUNERR: Range on function sheet"));
     }
 }
Beispiel #2
0
 public override void Compile()
 {
     if (index >= 0)
     {
         ilg.Emit(OpCodes.Ldc_I4, index);
         ilg.Emit(OpCodes.Call, getAddressMethod);
         // HERE
         ilg.Emit(OpCodes.Stloc, tmpFullCellAddr);
         ilg.Emit(OpCodes.Ldloca, tmpFullCellAddr);
         ilg.Emit(OpCodes.Call, FullCellAddr.evalMethod);
     }
     else
     {
         LoadErrorValue(ErrorValue.Make("#FUNERR: Ref to other function sheet"));
     }
 }
Beispiel #3
0
        public override Value Eval(Sheet sheet, int col, int row)
        {
            Value v = caf.Eval();

            if (v is ArrayValue)
            {
                return((v as ArrayValue)[ca]);
            }
            else if (v is ErrorValue)
            {
                return(v);
            }
            else
            {
                return(ErrorValue.Make("#ERR: Not array"));
            }
        }
Beispiel #4
0
 // This is used to implement the ERR function
 public CGError(CGExpr[] es)
 {
     if (es.Length != 1)
     {
         errorValue = ErrorValue.argCountError;
     }
     else
     {
         CGTextConst messageConst = es[0] as CGTextConst;
         if (messageConst == null)
         {
             errorValue = ErrorValue.argTypeError;
         }
         else
         {
             errorValue = ErrorValue.Make("#ERR: " + messageConst.value.value);
         }
     }
 }
Beispiel #5
0
        public override String ShowValue(Sheet sheet, int col, int row)
        {
            // Use the underlying cached value, do not call Eval, there might be a cycle!
            Value v = caf.CachedArray;

            if (v is ArrayValue)
            {
                Value element = (v as ArrayValue)[ca];
                return(element != null?element.ToString() : "");
            }
            else if (v is ErrorValue)
            {
                return(v.ToString());
            }
            else
            {
                return(ErrorValue.Make("#ERR: Not array").ToString());
            }
        }
Beispiel #6
0
 public CGExtern(CGExpr[] es)
     : base(es, null)
 {
     if (es.Length < 1)
     {
         errorValue = ErrorValue.argCountError;
     }
     else
     {
         CGTextConst nameAndSignatureConst = es[0] as CGTextConst;
         if (nameAndSignatureConst == null)
         {
             errorValue = ErrorValue.argTypeError;
         }
         else
         {
             try {
                 // This retrieves the method from cache, or creates it:
                 ef = ExternalFunction.Make(nameAndSignatureConst.value.value);
                 if (ef.arity != es.Length - 1)
                 {
                     ef         = null;
                     errorValue = ErrorValue.argCountError;
                 }
                 else
                 {
                     resType  = FromType(ef.ResType);
                     argTypes = new Typ[ef.arity];
                     for (int i = 0; i < argTypes.Length; i++)
                     {
                         argTypes[i] = FromType(ef.ArgType(i));
                     }
                 }
             }
             catch (Exception exn)                     // Covers a multitude of sins
             {
                 errorValue = ErrorValue.Make(exn.Message);
             }
         }
     }
 }
Beispiel #7
0
 public Error(String msg) : this(ErrorValue.Make(msg))
 {
 }
Beispiel #8
0
 public CGError(String message) : this(ErrorValue.Make(message))
 {
 }
Beispiel #9
0
        public Value Apply(Sheet sheet, Expr[] es, int col, int row)
        {
            // Arity is checked in the SdfInfo.CallN methods
            switch (es.Length)
            {
            case 0:
                return(Call0());

            case 1:
                return(Call1(es[0].Eval(sheet, col, row)));

            case 2:
                return(Call2(es[0].Eval(sheet, col, row), es[1].Eval(sheet, col, row)));

            case 3:
                return(Call3(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row)));

            case 4:
                return(Call4(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row)));

            case 5:
                return(Call5(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row),
                             es[4].Eval(sheet, col, row)));

            case 6:
                return(Call6(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row),
                             es[4].Eval(sheet, col, row),
                             es[5].Eval(sheet, col, row)));

            case 7:
                return(Call7(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row),
                             es[4].Eval(sheet, col, row),
                             es[5].Eval(sheet, col, row),
                             es[6].Eval(sheet, col, row)));

            case 8:
                return(Call8(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row),
                             es[4].Eval(sheet, col, row),
                             es[5].Eval(sheet, col, row),
                             es[6].Eval(sheet, col, row),
                             es[7].Eval(sheet, col, row)));

            case 9:
                return(Call9(es[0].Eval(sheet, col, row),
                             es[1].Eval(sheet, col, row),
                             es[2].Eval(sheet, col, row),
                             es[3].Eval(sheet, col, row),
                             es[4].Eval(sheet, col, row),
                             es[5].Eval(sheet, col, row),
                             es[6].Eval(sheet, col, row),
                             es[7].Eval(sheet, col, row),
                             es[8].Eval(sheet, col, row)));

            default:
                return(ErrorValue.Make("#FUNERR: Too many arguments"));
            }
        }