Example #1
0
 public static Instruction From(OpCodeTypes typ, Value[] values)
 {
     Instruction i = new Instruction();
     i.Type = typ;
     i.Args = new List<Value>();
     foreach (Value v in values) {
         i.Args.Add(v);
     }
     return i;
 }
Example #2
0
 public static Value CreateFrom(Object o)
 {
     Value v = new Value();
     if (o.GetType() == typeof(Int16)){
         v.Type = ValueTypes.INT_16;
         v.Int16_Value = (Int16)o;
     } else if (o.GetType() == typeof(Int32)) {
         v.Type = ValueTypes.INT_32;
         v.Int32_Value = (Int32)o;
     } else if (o.GetType() == typeof(Int64)) {
         v.Type = ValueTypes.INT_64;
         v.Int64_Value = (Int64)o;
     } else if (o.GetType() == typeof(UInt16)) {
         v.Type = ValueTypes.UINT_16;
         v.UInt16_Value = (UInt16)o;
     } else if (o.GetType() == typeof(UInt32)) {
         v.Type = ValueTypes.UINT_32;
         v.UInt32_Value = (UInt32)o;
     } else if (o.GetType() == typeof(UInt64)) {
         v.Type = ValueTypes.UINT_64;
         v.UInt64_Value = (UInt64)o;
     } else if (o.GetType() == typeof(byte)) {
         v.Type = ValueTypes.BYTE;
         v.Byte_Value = (byte)o;
     } else if (o.GetType() == typeof(decimal)) {
         v.Type = ValueTypes.DECIMAL;
         v.Decimal_Value = (decimal)o;
     } else if (o.GetType() == typeof(string)) {
         v.Type = ValueTypes.STRING;
         v.String_Value = (string)o;
     } else if (o.GetType() == typeof(ValueList)) {
         v.Type = ValueTypes.ARRAY;
         v.Array_Value = (ValueList)o;
     } else if (o.GetType() == typeof(ObjectReference)) {
         v.Type = ValueTypes.OBJECT;
         v.ObjectReference_Value = (ObjectReference)o;
     } else if (o.GetType() == typeof(CodeBlock)) {
         v.Type = ValueTypes.CODE_BLOCK;
         v.CodeBlock_Value = (CodeBlock)o;
     } else if (o.GetType() == typeof(Reference)) {
         v.Type = ValueTypes.REFERENCE;
         v.Reference_Value = (Reference)o;
     } else {
         throw new Exception();
     }
     return v;
 }
Example #3
0
 /// <summary>
 /// Finds an open slot in Prototypes and adds the requested prototype to it. Returns
 /// an ObjectReference Value pointing to the Prototype.
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public Value AddObject(Prototype p)
 {
     Value v = new Value();
     v.Type = ValueTypes.OBJECT;
     v.ObjectReference_Value = new ObjectReference();
     int protLoc = -1;
     for (int x = 0; x < Prototypes.Count(); x++) {
         if (Prototypes[x] == null) {
             Prototypes[x] = p;
             protLoc = x;
             break;
         }
     }
     if (protLoc == -1) {
         Prototypes.Add(p);
         protLoc = Prototypes.Count() - 1;
         Memory = Memory + 2;
     }
     Objects.Add(protLoc);
     v.ObjectReference_Value.Home = this;
     v.ObjectReference_Value.Index = Objects.Count() - 1;
     Memory++;
     return v;
 }
Example #4
0
 public static Value New(ValueTypes vt, Object obj)
 {
     Value v = new Value();
     v.Type = vt;
     switch (v.Type) {
         case ValueTypes.ARRAY:
             v.Array_Value = new ValueList();
             break;
         case ValueTypes.BOOLEAN:
             v.Boolean_Value = Convert.ToBoolean(obj);
             break;
         case ValueTypes.BYTE:
             v.Byte_Value = Convert.ToByte(obj);
             break;
         case ValueTypes.CODE_BLOCK:
             v.CodeBlock_Value = (CodeBlock)obj;
             break;
         case ValueTypes.DATETIME:
             throw new NotImplementedException();
             break;
         case ValueTypes.DECIMAL:
             v.Decimal_Value = Convert.ToDecimal(obj);
             break;
         case ValueTypes.DOUBLE:
             v.Double_Value = Convert.ToDouble(obj);
             break;
         case ValueTypes.EMPTY:
             break;
         case ValueTypes.FLOAT:
             v.Float_Value = Convert.ToSingle(obj);
             break;
         case ValueTypes.GUID:
             throw new NotImplementedException();
             break;
         case ValueTypes.INT_16:
             v.Int16_Value = Convert.ToInt16(obj);
             break;
         case ValueTypes.INT_32:
             v.Int32_Value = Convert.ToInt32(obj);
             break;
         case ValueTypes.INT_64:
             v.Int64_Value = Convert.ToInt64(obj);
             break;
         case ValueTypes.NULL:
             break;
         case ValueTypes.OBJECT:
             throw new NotImplementedException();
             break;
         case ValueTypes.REFERENCE:
             v.Reference_Value = new Reference();
             break;
         case ValueTypes.STRING:
             v.String_Value = Convert.ToString(obj);
             break;
         case ValueTypes.UINT_16:
             v.UInt16_Value = Convert.ToUInt16(obj);
             break;
         case ValueTypes.UINT_32:
             v.UInt32_Value = Convert.ToUInt32(obj);
             break;
         case ValueTypes.UINT_64:
             v.UInt64_Value = Convert.ToUInt64(obj);
             break;
         case ValueTypes.ANY_TYPE:
             break;
     }
     return v;
 }
Example #5
0
 public static Value New(ValueTypes vt)
 {
     Value v = new Value();
     v.Type = vt;
     switch (vt) {
         case ValueTypes.STRING:
             v.String_Value = "";
             break;
         case ValueTypes.ARRAY:
             v.Array_Value = new ValueList();
             break;
         case ValueTypes.CODE_BLOCK:
             v.CodeBlock_Value = new CodeBlock();
             break;
             break;
         default:
             break;
     }
     return v;
 }
Example #6
0
        internal static void TestGreaterThanEquals(VirtualMachine vm, Instruction i)
        {
            Value b = vm.Stack.Shift();
            Value a = vm.Stack.Shift();

            if (a.IsNumeric() == false || b.IsNumeric() == false) {
                vm.RaiseError("Attempted to compare non-comparable type " + a.Type);
                return;
            }
            Value v = new Value();
            switch (a.Type) {
                case ValueTypes.INT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int16_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int16_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int16_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int16_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int16_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Int16_Value >= (long)b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int16_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int16_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int16_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int32_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int32_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int32_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int32_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int32_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Int32_Value >= (long)b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int32_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int32_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int32_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int64_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int64_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int64_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int64_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int64_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            if (b.UInt64_Value <= Int64.MaxValue) {
                                var val6 = a.Int64_Value >= Convert.ToInt64(b.UInt64_Value);
                                v.Type = ValueTypes.BOOLEAN;
                                v.Boolean_Value = val6;
                                vm.Stack.Push(v);
                            } else {
                                vm.RaiseError("Overflow error");
                            }
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int64_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int64_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int64_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt16_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt16_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt16_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt16_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt16_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt16_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.UInt16_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.UInt16_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.UInt16_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt32_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt32_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt32_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt32_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt32_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt32_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.UInt32_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.UInt32_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.UInt32_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            vm.RaiseError("Incommensurate value error: Int16 to UInt64");
                            return;
                        case ValueTypes.INT_32:
                            vm.RaiseError("Incommensurate value error: Int32 to UInt64");
                            return;
                        case ValueTypes.INT_64:
                            vm.RaiseError("Incommensurate value error: Int64 to UInt64");
                            return;
                        case ValueTypes.UINT_16:
                            var val1 = a.UInt64_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val2 = a.UInt64_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val3 = a.UInt64_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val4 = a.UInt64_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val5 = a.UInt64_Value >= Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val6 = a.UInt64_Value >= Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DECIMAL:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Decimal_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Decimal_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Decimal_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Decimal_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Decimal_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Decimal_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Decimal_Value >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Decimal_Value >= Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Decimal_Value >= Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.FLOAT:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Float_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Float_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Float_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Float_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Float_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Float_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Float_Value) >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = Convert.ToDouble(a.Float_Value) >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Float_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DOUBLE:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Double_Value >= b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Double_Value >= b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Double_Value >= b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Double_Value >= b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Double_Value >= b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Double_Value >= b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Double_Value) >= b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Double_Value >= b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Double_Value >= b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
            }
        }
Example #7
0
 internal void SetGlobal(String name, Value val)
 {
     Globals.Add(name, val);
 }
Example #8
0
 internal void Set(String name, Value val)
 {
     CurrentEnvironment.Variables[name] = val;
 }
Example #9
0
 /// <summary>
 /// Sets 'property' to 'val' on the Prototype denoted locally by 'index'.
 /// Properties are *always* set *locally*, though they may be retrieved
 /// from other environment scopes.
 /// </summary>
 /// <param name="index"></param>
 /// <param name="property"></param>
 /// <param name="val"></param>
 public void SetObjectProperty(int index, string property, Value val)
 {
     int loc = Objects[index];
     Prototype prot = Prototypes[loc];
     prot.Add(property, val);
     Memory++;
 }
Example #10
0
        internal static void Add(VirtualMachine vm, Instruction i)
        {
            Value b = vm.Stack.Shift();
            Value a = vm.Stack.Shift();

            if (a.IsNumeric() == false || b.IsNumeric() == false) {
                vm.RaiseError("Tried to add one or more non-numeric values");
                return;
            }
            Value v = new Value();
            switch (a.Type) {
                case ValueTypes.INT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int16_Value + b.Int16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int16_Value + b.Int32_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = (Int32)val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int16_Value + b.Int64_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int16_Value + b.UInt16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int16_Value + b.UInt32_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            if (b.UInt64_Value <= Int64.MaxValue) {
                                var val6 = a.Int16_Value + (long)b.UInt64_Value;
                                v.Type = ValueTypes.INT_64;
                                v.Int64_Value = val6;
                                vm.Stack.Push(v);
                            } else {
                                vm.RaiseError("Overflow error");
                            }
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.Int16_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            double val8 = a.Int16_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            float val9 = a.Int16_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int32_Value + b.Int16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = (Int32)val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int32_Value + b.Int32_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = (Int32)val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int32_Value + b.Int64_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int32_Value + b.UInt16_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int32_Value + b.UInt16_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            if (b.UInt64_Value <= Int64.MaxValue) {
                                var val6 = a.Int32_Value + (long)b.UInt64_Value;
                                v.Type = ValueTypes.INT_64;
                                v.Int64_Value = val6;
                                vm.Stack.Push(v);
                            } else {
                                vm.RaiseError("Overflow error");
                            }
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.Int32_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            double val8 = a.Int32_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            float val9 = a.Int32_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int64_Value + b.Int16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = (Int32)val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int64_Value + b.Int32_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = (Int32)val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int64_Value + b.Int64_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int64_Value + b.UInt16_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int64_Value + b.UInt32_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            if (b.UInt64_Value <= Int64.MaxValue) {
                                var val6 = a.Int64_Value + (long)b.UInt64_Value;
                                v.Type = ValueTypes.INT_64;
                                v.Int64_Value = val6;
                                vm.Stack.Push(v);
                            } else {
                                vm.RaiseError("Overflow error");
                            }
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.Int64_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            double val8 = a.Int64_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            float val9 = a.Int64_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt16_Value + b.Int16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt16_Value + b.Int32_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt16_Value + b.Int64_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt16_Value + b.UInt16_Value;
                            v.Type = ValueTypes.INT_32;
                            v.Int32_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt16_Value + b.UInt32_Value;
                            v.Type = ValueTypes.UINT_32;
                            v.UInt32_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt16_Value + b.UInt64_Value;
                            v.Type = ValueTypes.UINT_64;
                            v.UInt64_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.UInt16_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            double val8 = a.UInt16_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            float val9 = a.UInt16_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt32_Value + b.Int16_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt32_Value + b.Int32_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt32_Value + b.Int64_Value;
                            v.Type = ValueTypes.INT_64;
                            v.Int64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt32_Value + b.UInt16_Value;
                            v.Type = ValueTypes.UINT_32;
                            v.UInt32_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt32_Value + b.UInt32_Value;
                            v.Type = ValueTypes.UINT_32;
                            v.UInt32_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt32_Value + b.UInt64_Value;
                            v.Type = ValueTypes.UINT_64;
                            v.UInt64_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.UInt32_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            double val8 = a.UInt32_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            float val9 = a.UInt32_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            vm.RaiseError("Incommensurate value error: Int16 to UInt64");
                            return;
                        case ValueTypes.INT_32:
                            vm.RaiseError("Incommensurate value error: Int32 to UInt64");
                            return;
                        case ValueTypes.INT_64:
                            vm.RaiseError("Incommensurate value error: Int64 to UInt64");
                            return;
                        case ValueTypes.UINT_16:
                            var val1 = a.UInt64_Value + b.UInt16_Value;
                            v.Type = ValueTypes.UINT_64;
                            v.UInt64_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val2 = a.UInt64_Value + b.UInt32_Value;
                            v.Type = ValueTypes.UINT_64;
                            v.UInt64_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val3 = a.UInt64_Value + b.UInt64_Value;
                            v.Type = ValueTypes.UINT_64;
                            v.UInt64_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val4 = a.UInt64_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            decimal val5 = a.UInt64_Value + Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            decimal val6 = a.UInt64_Value + Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val6;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DECIMAL:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            decimal val1 = a.Decimal_Value + b.Int16_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            decimal val2 = a.Decimal_Value + b.Int32_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            decimal val3 = a.Decimal_Value + b.Int64_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            decimal val4 = a.Decimal_Value + b.UInt16_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            decimal val5 = a.Decimal_Value + b.UInt32_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            decimal val6 = a.Decimal_Value + b.UInt64_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            decimal val7 = a.Decimal_Value + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            decimal val8 = a.Decimal_Value + Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            decimal val9 = a.Decimal_Value + Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.FLOAT:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Float_Value + b.Int16_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Float_Value + b.Int32_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Float_Value + b.Int64_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Float_Value + b.UInt16_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Float_Value + b.UInt32_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Float_Value + b.UInt64_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Float_Value) + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = Convert.ToDouble(a.Float_Value) + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Float_Value + b.Float_Value;
                            v.Type = ValueTypes.FLOAT;
                            v.Float_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DOUBLE:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Double_Value + b.Int16_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Double_Value + b.Int32_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Double_Value + b.Int64_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Double_Value + b.UInt16_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Double_Value + b.UInt32_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Double_Value + b.UInt64_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Double_Value) + b.Decimal_Value;
                            v.Type = ValueTypes.DECIMAL;
                            v.Decimal_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Double_Value + b.Double_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Double_Value + b.Float_Value;
                            v.Type = ValueTypes.DOUBLE;
                            v.Double_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
            }
        }
Example #11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="i"></param>
        internal static void Append(VirtualMachine vm, Instruction i)
        {
            Value vArray = vm.Stack.Shift();
            Value vValue = vm.Stack.Shift();

            switch(vArray.Type){
                case ValueTypes.ARRAY:
                    if (i.Type == OpCodeTypes.APPEND) {
                        vArray.Array_Value.Add(vValue);
                        vm.Stack.Push(vArray);
                    } else if (i.Type == OpCodeTypes.APPEND_RANGE) {
                        if (vValue.Type == ValueTypes.ARRAY) {
                            vArray.Array_Value.AddRange(vValue.Array_Value);
                            vm.Stack.Push(vArray);
                        } else {
                            vm.RaiseError("Tried to range append using a non-array value. Use APPEND instead.");
                        }
                    } else {
                        vm.RaiseError("Tried append with unknown opcode " + i.Type);
                    }
                    return;
                case ValueTypes.STRING:
                    if (i.Type == OpCodeTypes.APPEND) {
                        vm.RaiseError("Tried to append to a string. Use APPEND_RANGE instead.");
                        return;
                    }
                    vArray.String_Value = vArray.String_Value + vValue.Get().ToString();
                    vm.Stack.Push(vArray);
                    return;
                default:
                     if (i.Type == OpCodeTypes.APPEND) {
                        vm.RaiseError("Tried to append to a string conversion. Use APPEND_RANGE instead.");
                        return;
                    }
                    Value vNew = new Value();
                    vNew.String_Value = vArray.Get().ToString() + vValue.Get().ToString();
                    vNew.Type = ValueTypes.STRING;
                    vm.Stack.Push(vNew);
                     return;
            }
        }
Example #12
0
        internal static Value ReturnProperty(VirtualMachine vm, Value refc, Value propName)
        {
            Value val = Value.New(ValueTypes.NULL);
            if (propName.Type != ValueTypes.STRING || propName.String_Value == null || propName.String_Value == "") {
                throw new Exception("Tried to access a property without a string value");
            }
            if (refc.Type != ValueTypes.OBJECT) {
                throw new Exception("Tried to access a property on something other than an object reference.");
            }

            ObjectReference reference = refc.ObjectReference_Value;
            String name = propName.String_Value;
            try {
                val = reference.Home.GetObjectProperty(reference.Index, name);
            } catch (Exception e) {
                vm.RaiseError(e.Message);
                return val;
            }
            return val;
        }
Example #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="vm"></param>
 /// <param name="i"></param>
 internal static void Length(VirtualMachine vm, Instruction i)
 {
     Value vValue = vm.Stack.Shift();
     if (vValue.Type != ValueTypes.ARRAY && vValue.Type != ValueTypes.STRING) {
         vm.RaiseError("Tried to get length of a non-array and non-string value " + vValue.Type);
         return;
     }
     Value len = new Value();
     len.Type = ValueTypes.INT_32;
     if (vValue.Type == ValueTypes.ARRAY) {
         len.Int32_Value = vValue.Array_Value.Count();
     } else if (vValue.Type == ValueTypes.STRING) {
         len.Int32_Value = vValue.String_Value.Count();
     }
     vm.Stack.Push(len);
 }
Example #14
0
        internal Instruction Parse(String line, int lineNumber)
        {
            Instruction i = new Instruction();
            i.Args = new List<Value>();

            List<Value> args = new List<Value>();

            // Strip comments (Anything that starts with * that isn't in a string literal)
            String inst = "";
            int quotes = 0;
            try {
                for (int cs = 0; cs < line.Length; cs++) {
                    if (line[cs] == '"' && line[cs - 1] != '\\') {
                        quotes++;
                    }
                    if ((line[cs] == '*' || line[cs] == ';') && (quotes == 0 || quotes % 2 == 0)) {
                        break;
                    }
                    inst = inst + line[cs];
                }
            } catch (Exception e) {
                throw new Exception("Line number: " + lineNumber + ", " + e.Message);
            }
            quotes = 0;
            String OpCode = "";
            int c = 0;

            // Skip starting whitespace
            while (c < inst.Length && (inst[c] == ' ' || inst[c] == '\t')) {
                c++;
            }
            if (inst.Length < 1 || inst.StartsWith("*") || c >= inst.Length) {
                throw new InvalidCastException();
            }

            // Find opcode
            while (c < inst.Length) {
                if (inst[c] == ' ' || inst[c] == '\t') {
                    break;
                }
                OpCode = OpCode + inst[c];
                c++;
            }
            // Parse out the opcode or blow up
            try {
                i.Type = (OpCodeTypes)Enum.Parse(typeof(OpCodeTypes), OpCode);
            } catch (Exception e) {
                throw new Exception("Illegal opcode " + OpCode + " at line " + lineNumber);
            }

            // Skip any intervening whitespace
            while (c < inst.Length && (inst[c] == ' ' || inst[c] == '\t')) {
                c++;
            }
            if (c >= inst.Length) {
                return i;
            }

            // Get arguments (type(:value)? (,type(:value)?)+)
            while (c < inst.Length) {
                Value v = new Value();
                String vType = "";
                String vValue = "";
                while (c < inst.Length && (inst[c] == ' ' || inst[c] == '\t')) {
                    c++;
                }
                // Get type
                while (c < inst.Length && inst[c] != ':' && inst[c] != ',') {
                    vType = vType + inst[c];
                    c++;
                }
                if (vType.ToLowerInvariant() == "int16") {
                    v.Type = ValueTypes.INT_16;
                } else if (vType.ToLowerInvariant() == "int32") {
                    v.Type = ValueTypes.INT_32;
                } else if (vType.ToLowerInvariant() == "int64") {
                    v.Type = ValueTypes.INT_64;
                } else if (vType.ToLowerInvariant() == "uint16") {
                    v.Type = ValueTypes.UINT_16;
                } else if (vType.ToLowerInvariant() == "uint32") {
                    v.Type = ValueTypes.UINT_32;
                } else if (vType.ToLowerInvariant() == "uint64") {
                    v.Type = ValueTypes.UINT_64;
                } else if (vType.ToLowerInvariant() == "null") {
                    v.Type = ValueTypes.NULL;
                } else if (vType.ToLowerInvariant() == "empty") {
                    v.Type = ValueTypes.EMPTY;
                } else if (vType.ToLowerInvariant() == "boolean") {
                    v.Type = ValueTypes.BOOLEAN;
                } else if (vType.ToLowerInvariant() == "byte") {
                    v.Type = ValueTypes.BYTE;
                } else if (vType.ToLowerInvariant() == "decimal") {
                    v.Type = ValueTypes.DECIMAL;
                } else if (vType.ToLowerInvariant() == "float") {
                    v.Type = ValueTypes.FLOAT;
                } else if (vType.ToLowerInvariant() == "double") {
                    v.Type = ValueTypes.DOUBLE;
                } else if (vType.ToLowerInvariant() == "string") {
                    v.Type = ValueTypes.STRING;
                } else if (vType.ToLowerInvariant() == "guid") {
                    v.Type = ValueTypes.GUID;
                } else if (vType.ToLowerInvariant() == "datetime") {
                    v.Type = ValueTypes.DATETIME;
                } else if (vType.ToLowerInvariant() == "array") {
                    v.Type = ValueTypes.ARRAY;
                } else if (vType.ToLowerInvariant() == "object") {
                    v.Type = ValueTypes.OBJECT;
                } else if (vType.ToLowerInvariant() == "code_block") {
                    v.Type = ValueTypes.CODE_BLOCK;
                } else if (vType.ToLowerInvariant() == "reference") {
                    v.Type = ValueTypes.REFERENCE;
                } else if (vType.ToLowerInvariant() == "any") {
                    v.Type = ValueTypes.ANY_TYPE;
                } else {
                    throw new Exception("Unknown type " + vType);
                }

                // If there's no literal value, add a new Value to the list and go to the next one
                if (c >= inst.Length || inst[c] == ',') {
                    i.Args.Add(v);
                    c++;
                    continue;
                }

                if (c < inst.Length && (inst[c] != ',' && inst[c] != ':')) {
                    throw new Exception("Malformed value " + inst[c] + " at line " + lineNumber);
                }
                if (c < inst.Length && inst[c] == ':') {
                    c++;
                }
                // Ignore whitespace
                while (c < inst.Length && (inst[c] == ' ' || inst[c] == '\t')) {
                    c++;
                }
                while (c < inst.Length && (inst[c] != ',' || (inst[c] == ',' && (quotes != 0 && quotes % 2 != 0)))) {
                    vValue = vValue + inst[c];
                    c++;
                }

                try {
                    // Figure out what the value is
                    if (Regex.IsMatch(vValue, @"True|False")) {
                        // Boolean
                        if (v.Type == ValueTypes.BOOLEAN) {
                            v.Boolean_Value = Convert.ToBoolean(vValue);
                        } else if (v.Type == ValueTypes.STRING) {
                            vValue = vValue.Substring(1, vValue.Length - 2);
                            vValue.Replace("\"\"", "\"");
                            v.String_Value = vValue;
                        } else {
                            throw new Exception("Tried to set literal " + vValue + " to value type " + v.Type);
                        }
                    } else if (Regex.IsMatch(vValue, @"[-]?[0-9]+\.[0-9]+")) {
                        // Decimal
                        if (v.Type == ValueTypes.DECIMAL) {
                            v.Decimal_Value = Convert.ToDecimal(vValue);
                        } else if (v.Type == ValueTypes.DOUBLE) {
                            v.Double_Value = Convert.ToDouble(vValue);
                        } else if (v.Type == ValueTypes.FLOAT) {
                            v.Float_Value = Convert.ToSingle(vValue);
                        } else if (v.Type == ValueTypes.STRING) {
                            vValue = vValue.Substring(1, vValue.Length - 2);
                            vValue.Replace("\"\"", "\"");
                            v.String_Value = vValue;
                        } else {
                            throw new Exception("Tried to set literal " + vValue + " to value type " + v.Type);
                        }
                    } else if (Regex.IsMatch(vValue, @"[-]?[0-9][0-9]*") || Regex.IsMatch(vValue, @"0x[0-9A-Fa-f]+") || Regex.IsMatch(vValue, @"0[0-7]+")) {
                        if (v.Type == ValueTypes.INT_16) {
                            v.Int16_Value = Convert.ToInt16(vValue);
                        } else if (v.Type == ValueTypes.INT_32) {
                            v.Int32_Value = Convert.ToInt32(vValue);
                        } else if (v.Type == ValueTypes.INT_64) {
                            v.Int64_Value = Convert.ToInt64(vValue);
                        } else if (v.Type == ValueTypes.UINT_16) {
                            v.UInt16_Value = Convert.ToUInt16(vValue);
                        } else if (v.Type == ValueTypes.UINT_32) {
                            v.UInt32_Value = Convert.ToUInt32(vValue);
                        } else if (v.Type == ValueTypes.UINT_64) {
                            v.UInt64_Value = Convert.ToUInt64(vValue);
                        } else if (v.Type == ValueTypes.BYTE) {
                            v.Byte_Value = Convert.ToByte(vValue);
                        } else if (v.Type == ValueTypes.STRING) {
                            vValue = vValue.Substring(1, vValue.Length - 2);
                            vValue.Replace("\"\"", "\"");
                            v.String_Value = vValue;
                        } else {
                            throw new Exception("Tried to set literal " + vValue + " to value type " + v.Type);
                        }
                    } else {
                        v = Value.New(v.Type, v.String_Value);
                        vValue = vValue.Substring(1, vValue.Length - 2);
                        vValue.Replace("\"\"", "\"");
                        v.String_Value = vValue;
                    }
                    i.Args.Add(v);
                    if (c < inst.Length && inst[c] == ',') {
                        c++;
                    }
                    while (c < inst.Length && (inst[c] == ' ' || inst[c] == '\t')) {
                        c++;
                    }
                } catch (Exception e) {
                    throw new Exception("Compile error on line number: " + lineNumber + ", " + e.Message);
                }
            }

            return i;
        }
Example #15
0
        /// <summary>
        /// 
        /// (array) (index) (end) | (value) (end)
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="i"></param>
        internal static void ArrayGet(VirtualMachine vm, Instruction i)
        {
            Value vIndex = vm.Stack.Shift();
            Value vArray = vm.Stack.Shift();

            if (vArray.Type != ValueTypes.ARRAY && vArray.Type != ValueTypes.STRING) {
                vm.RaiseError("Tried to index get a non-array and non-string type " + vArray.Type);
                return;
            }

            if(vIndex.IsNumeric() == false || vIndex.Type == ValueTypes.FLOAT || vIndex.Type == ValueTypes.DOUBLE || vIndex.Type == ValueTypes.DECIMAL){
                vm.RaiseError("Tried to index get an array with a non-integer type " + vIndex.Type);
                return;
            }

            Int32 index = Convert.ToInt32(vIndex.Get());
            Value v = new Value();
            if (vArray.Type == ValueTypes.ARRAY) {
                if (index >= vArray.Array_Value.Count()) {
                    vm.RaiseError("Tried to get index " + index + " on an array of max index " + (vArray.Array_Value.Count() - 1));
                }
                v = vArray.Array_Value[index];
            } else if (vArray.Type == ValueTypes.STRING) {
                if (index >= vArray.String_Value.Count()) {
                    vm.RaiseError("Tried to get index " + index + " on a string of max index " + (vArray.Array_Value.Count() - 1));
                }
                v = Value.New(ValueTypes.STRING, vArray.String_Value[index]);
            }
            vm.Stack.Push(v);
            return;
        }
Example #16
0
 /// <summary>
 /// Promotes a Value if appropriate. 
 /// float -> double
 /// int -> int
 /// uint -> uint
 /// Attempts to promote other types will throw an exception.
 /// </summary>
 /// <param name="val"></param>
 public void Promote(Value val)
 {
     switch (this.Type) {
         case ValueTypes.DECIMAL:
             switch (val.Type) {
                 case ValueTypes.DECIMAL:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.DOUBLE:
             switch (val.Type) {
                 case ValueTypes.DOUBLE:
                 case ValueTypes.FLOAT:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.FLOAT:
             switch (val.Type) {
                 case ValueTypes.DOUBLE:
                     this.Type = ValueTypes.DOUBLE;
                     this.Double_Value = Convert.ToDouble(this.Float_Value);
                     this.Float_Value = 0;
                     return;
                 case ValueTypes.FLOAT:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.INT_16:
             switch (val.Type) {
                 case ValueTypes.INT_64:
                     this.Type = ValueTypes.INT_64;
                     this.Int64_Value = Convert.ToInt64(this.Int16_Value);
                     this.Int16_Value = 0;
                     return;
                 case ValueTypes.INT_32:
                     this.Type = ValueTypes.INT_32;
                     this.Int32_Value = Convert.ToInt32(this.Int16_Value);
                     this.Int16_Value = 0;
                     return;
                 case ValueTypes.INT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.INT_32:
             switch (val.Type) {
                 case ValueTypes.INT_64:
                     this.Type = ValueTypes.INT_64;
                     this.Int64_Value = Convert.ToInt64(this.Int16_Value);
                     this.Int16_Value = 0;
                     return;
                 case ValueTypes.INT_32:
                 case ValueTypes.INT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.INT_64:
             switch (val.Type) {
                 case ValueTypes.INT_64:
                 case ValueTypes.INT_32:
                 case ValueTypes.INT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.UINT_16:
             switch (val.Type) {
                 case ValueTypes.UINT_64:
                     this.Type = ValueTypes.UINT_64;
                     this.UInt64_Value = Convert.ToUInt64(this.UInt16_Value);
                     this.UInt16_Value = 0;
                     return;
                 case ValueTypes.UINT_32:
                     this.Type = ValueTypes.UINT_32;
                     this.UInt32_Value = Convert.ToUInt32(this.UInt16_Value);
                     this.UInt16_Value = 0;
                     return;
                 case ValueTypes.UINT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.UINT_32:
             switch (val.Type) {
                 case ValueTypes.UINT_64:
                     this.Type = ValueTypes.UINT_64;
                     this.UInt64_Value = Convert.ToUInt64(this.UInt16_Value);
                     this.UInt16_Value = 0;
                     return;
                 case ValueTypes.UINT_32:
                 case ValueTypes.UINT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
         case ValueTypes.UINT_64:
             switch (val.Type) {
                 case ValueTypes.UINT_64:
                 case ValueTypes.UINT_32:
                 case ValueTypes.UINT_16:
                     return;
                 default:
                     throw new Exception("Attempt to promote using invalid types " + this.Type + " and " + val.Type + ".");
             }
             break;
     }
 }
Example #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="vm"></param>
        /// <param name="i"></param>
        internal static void CallPrimitive(VirtualMachine vm, Instruction i)
        {
            Value pName = vm.Stack.Shift();
            if (pName.Type != ValueTypes.STRING) {
                vm.RaiseError("Tried to call a primitive with a non-string name");
                return;
            }
            Action<VirtualMachine, Instruction, List<Value>> prim = null;
            if (vm.Primitives.ContainsKey(pName.String_Value) == false) {
                vm.RaiseError("Tried to call empty primitive " + pName.String_Value);
                return;
            }
            prim = vm.Primitives[pName.String_Value];

            Value[] arity = new Value[vm.PrimitivesArity[pName.String_Value].Count()];

            vm.PrimitivesArity[pName.String_Value].CopyTo(arity);

            // We are going to get arguments in reverse order
            for (int x = arity.Count() - 1; x >= 0; x--) {
                Value v = vm.Stack.Shift();
                if (arity[x].Type != ValueTypes.ANY_TYPE && (arity[x].Type != v.Type)) {
                    vm.RaiseError("Argument arity error for primitive " + pName.String_Value + ": expected type " + arity[x].Type + ", saw " + v.Type);
                    return;
                }
                arity[x] = v;
            }
            prim(vm, i, new List<Value>(arity));
            return;
        }
Example #18
0
        internal static void TestNotEquals(VirtualMachine vm, Instruction i)
        {
            Value b = vm.Stack.Shift();
            Value a = vm.Stack.Shift();

            if (a.IsNumeric() == false || b.IsNumeric() == false) {
                if (a.Type != b.Type) {
                    vm.RaiseError("Tried to compare incommensurate values");
                    return;
                }
                Value testValue = new Value();
                testValue.Type = ValueTypes.BOOLEAN;

                if (a.Type == ValueTypes.BOOLEAN) {
                    testValue.Boolean_Value = Convert.ToBoolean(a.Get()) != Convert.ToBoolean(b.Get());
                } else if (a.Type == ValueTypes.BYTE) {
                    testValue.Boolean_Value = Convert.ToByte(a.Get()) != Convert.ToByte(b.Get());
                } else if (a.Type == ValueTypes.DATETIME) {
                    throw new NotImplementedException();
                } else if (a.Type == ValueTypes.GUID) {
                    throw new NotImplementedException();
                } else if (a.Type == ValueTypes.STRING) {
                    testValue.Boolean_Value = Convert.ToString(a.Get()) != Convert.ToString(b.Get());
                } else if (a.Type == ValueTypes.OBJECT) {
                    ObjectReference av = a.ObjectReference_Value;
                    ObjectReference bv = b.ObjectReference_Value;
                    testValue.Boolean_Value = (av.Home != bv.Home || av.Index != bv.Index);
                } else {
                    vm.RaiseError("Attempted to compare non-comparable type " + a.Type);
                }
                vm.Stack.Push(testValue);
                return;
            }
            Value v = new Value();
            switch (a.Type) {
                case ValueTypes.INT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int16_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int16_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int16_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int16_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int16_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Int16_Value != (long)b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int16_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int16_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int16_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int32_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int32_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int32_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int32_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int32_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Int32_Value != (long)b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int32_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int32_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int32_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.INT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Int64_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Int64_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Int64_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Int64_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Int64_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            if (b.UInt64_Value <= Int64.MaxValue) {
                                var val6 = a.Int64_Value != Convert.ToInt64(b.UInt64_Value);
                                v.Type = ValueTypes.BOOLEAN;
                                v.Boolean_Value = val6;
                                vm.Stack.Push(v);
                            } else {
                                vm.RaiseError("Overflow error");
                            }
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Int64_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Int64_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Int64_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_16:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt16_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt16_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt16_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt16_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt16_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt16_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.UInt16_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.UInt16_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.UInt16_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_32:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.UInt32_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.UInt32_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.UInt32_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.UInt32_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.UInt32_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.UInt32_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.UInt32_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.UInt32_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.UInt32_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.UINT_64:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            vm.RaiseError("Incommensurate value error: Int16 to UInt64");
                            return;
                        case ValueTypes.INT_32:
                            vm.RaiseError("Incommensurate value error: Int32 to UInt64");
                            return;
                        case ValueTypes.INT_64:
                            vm.RaiseError("Incommensurate value error: Int64 to UInt64");
                            return;
                        case ValueTypes.UINT_16:
                            var val1 = a.UInt64_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val2 = a.UInt64_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val3 = a.UInt64_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val4 = a.UInt64_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val5 = a.UInt64_Value != Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val6 = a.UInt64_Value != Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DECIMAL:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Decimal_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Decimal_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Decimal_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Decimal_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Decimal_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Decimal_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = a.Decimal_Value != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Decimal_Value != Convert.ToDecimal(b.Double_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Decimal_Value != Convert.ToDecimal(b.Float_Value);
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.FLOAT:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Float_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Float_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Float_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Float_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Float_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Float_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Float_Value) != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = Convert.ToDouble(a.Float_Value) != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Float_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
                case ValueTypes.DOUBLE:
                    switch (b.Type) {
                        case ValueTypes.INT_16:
                            var val1 = a.Double_Value != b.Int16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val1;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_32:
                            var val2 = a.Double_Value != b.Int32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val2;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.INT_64:
                            var val3 = a.Double_Value != b.Int64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val3;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_16:
                            var val4 = a.Double_Value != b.UInt16_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val4;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_32:
                            var val5 = a.Double_Value != b.UInt32_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val5;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.UINT_64:
                            var val6 = a.Double_Value != b.UInt64_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val6;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DECIMAL:
                            var val7 = Convert.ToDecimal(a.Double_Value) != b.Decimal_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val7;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.DOUBLE:
                            var val8 = a.Double_Value != b.Double_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val8;
                            vm.Stack.Push(v);
                            return;
                        case ValueTypes.FLOAT:
                            var val9 = a.Double_Value != b.Float_Value;
                            v.Type = ValueTypes.BOOLEAN;
                            v.Boolean_Value = val9;
                            vm.Stack.Push(v);
                            return;
                    }
                    vm.RaiseError("Incommensurate value error");
                    break;
            }
        }
Example #19
0
 public void Set(String name, Value val)
 {
     Variables[name] = val;
 }