Exemple #1
0
 private void CheckIndexType(HeronValue index)
 {
     if (index.As(layout.GetIndexType()) == null)
     {
         throw new Exception(index.ToString() + " is not a valid index type, expected " + layout.GetIndexType().ToString());
     }
 }
Exemple #2
0
 private void CheckRecordCompatibility(HeronValue record)
 {
     if (!(record is RecordValue))
     {
         if (!(record is ListValue))
         {
             throw new Exception(record.ToString() + " is not a valid list or record type");
         }
         ListValue list = record as ListValue;
         if (layout.IsCompatible(list))
         {
             return;
         }
         throw new Exception("The list value is not compatible");
     }
     else
     {
         RecordValue rec = record as RecordValue;
         if (rec.GetLayout() == layout)
         {
             return;
         }
         // Check then that there are the same exposedFields in "record" that we require.
         if (layout.IsCompatible(rec))
         {
             return;
         }
         throw new Exception("The record layout " + layout.ToString() + " does not contain a super-set of the accepted fields");
     }
 }
Exemple #3
0
 public override HeronValue InvokeBinaryOperator(VM vm, OpCode opcode, HeronValue val)
 {
     if (opcode == OpCode.opAdd)
     {
         return(vm.MakeTemporary(GetValue() + val.ToString()));
     }
     else
     {
         return(base.InvokeBinaryOperator(vm, opcode, val));
     }
 }
Exemple #4
0
 public static void Evaluate(VM vm, string sArg)
 {
     if (sArg.Length == 0)
     {
         Console.WriteLine("No expression to evaluate");
         return;
     }
     try
     {
         Console.WriteLine("Evaluating expression : " + sArg);
         HeronValue val = vm.EvalString(sArg);
         Console.WriteLine("Result : " + val.ToString());
     }
     catch (Exception e)
     {
         Console.WriteLine("Error occured : " + e.Message);
     }
 }
Exemple #5
0
 static public void TestCompareValues(string sInput, string sOutput)
 {
     Console.WriteLine("testing evaluation of " + sInput);
     Console.WriteLine("expecting result of " + sOutput);
     try
     {
         HeronValue input  = vm.EvalString(sInput);
         HeronValue output = vm.EvalString(sOutput);
         Console.WriteLine("test input was " + input.ToString());
         Console.WriteLine("test output was " + output.ToString());
         if (!input.Equals(output))
         {
             throw new Exception("Result was different than expected");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("test failed with exception " + e.Message);
     }
 }