예제 #1
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
        public override void Execute(CPU cpu)
        {
            argument2 = cpu.PopValue();
            argument1 = cpu.PopValue();

            // convert floats to doubles
            if (argument1 is float) argument1 = Convert.ToDouble(argument1);
            if (argument2 is float) argument2 = Convert.ToDouble(argument2);

            Calculator calc = Calculator.GetCalculator(argument1, argument2);
            object result = ExecuteCalculation(calc);
            cpu.PushStack(result);
        }
예제 #2
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     int functionPointer = (int)cpu.PopValue();
     cpu.RemoveTrigger(functionPointer);
 }
예제 #3
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     cpu.PushStack(argument);
 }
예제 #4
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     cpu.PopStack();
 }
예제 #5
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
        public override void Execute(CPU cpu)
        {
            object value = cpu.PopValue();
            object result;

            if (value is int)
                result = -((int)value);
            else if (value is float)
                result = -(Convert.ToDouble(value));
            else if (value is double)
                result = -((double)value);
            else
                throw new ArgumentException(string.Format("Can't negate object {0} of type {1}", value, value.GetType()));

            cpu.PushStack(result);
        }
예제 #6
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object waitTime = cpu.PopValue();
     if (waitTime is double)
         cpu.StartWait((double)waitTime);
     else if (waitTime is int)
         cpu.StartWait((int)waitTime);
 }
예제 #7
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object value = cpu.PopValue();
     string identifier = (string)cpu.PopStack();
     cpu.SetValue(identifier, value);
 }
예제 #8
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public virtual void Execute(CPU cpu)
 {
 }
예제 #9
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     cpu.EndWait();
 }
예제 #10
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object functionPointer = cpu.GetValue(destination);
     if (functionPointer is int)
     {
         int currentPointer = cpu.InstructionPointer;
         DeltaInstructionPointer = (int)functionPointer - currentPointer;
         cpu.PushStack(currentPointer + 1);
         cpu.MoveStackPointer(-1);
     }
     else
     {
         if (functionPointer is string)
         {
             string functionName = (string)functionPointer;
             functionName = functionName.Substring(0, functionName.Length - 2);
             cpu.CallBuiltinFunction(functionName);
         }
     }
 }
예제 #11
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     DeltaInstructionPointer = distance;
 }
예제 #12
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     bool condition = Convert.ToBoolean(cpu.PopValue());
     if (!condition) DeltaInstructionPointer = distance;
     else DeltaInstructionPointer = 1;
 }
예제 #13
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     int functionPointer = (int)cpu.PopValue();
     cpu.AddTrigger(functionPointer);
     if (shouldWait)
         cpu.StartWait(0);
 }
예제 #14
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     cpu.MoveStackPointer(1);
     int destinationPointer = (int)cpu.PopValue();
     int currentPointer = cpu.InstructionPointer;
     DeltaInstructionPointer = destinationPointer - currentPointer;
 }
예제 #15
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
        public override void Execute(CPU cpu)
        {
            object value = cpu.PopValue();
            object result;

            if (value is bool)
                result = !((bool)value);
            else if (value is int)
                result = (int)(Convert.ToBoolean(value) ? 0 : 1);
            else if ((value is double) || (value is float))
                result = (double)(Convert.ToBoolean(value) ? 0.0 : 1.0);
            else
                throw new ArgumentException(string.Format("Can't negate object {0} of type {1}", value, value.GetType()));

            cpu.PushStack(result);
        }
예제 #16
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
        public override void Execute(CPU cpu)
        {
            object value = cpu.PopValue();
            object index = cpu.PopValue();
            object list = cpu.PopValue();
            if (index is double || index is float)
            {
                index = Convert.ToInt32(index);  // allow expressions like (1.0) to be indexes
            }
            if (!(list is IIndexable)) throw new Exception(string.Format("Can't iterate on an object of type {0}", list.GetType()));
            if (!(index is int)) throw new Exception("The index must be an integer number");

            if (value != null)
            {
                ((IIndexable)list).SetIndex((int)index, value);
            }
        }
예제 #17
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     bool argument2 = Convert.ToBoolean(cpu.PopValue());
     bool argument1 = Convert.ToBoolean(cpu.PopValue());
     object result = argument1 | argument2;
     cpu.PushStack(result);
 }
예제 #18
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
        public override void Execute(CPU cpu)
        {
            object value = cpu.PopValue();
            string suffixName = cpu.PopStack().ToString().ToUpper();
            object specialValue = cpu.PopValue();

            if (specialValue is SpecialValue)
            {
                if (!((SpecialValue)specialValue).SetSuffix(suffixName, value))
                {
                    throw new Exception(string.Format("Suffix {0} not found on object", suffixName));
                }
            }
            else
            {
                throw new Exception(string.Format("Values of type {0} cannot have suffixes", specialValue.GetType().ToString()));
            }
        }
예제 #19
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object value = cpu.PopValue();
     bool result = Convert.ToBoolean(value);
     cpu.PushStack(result);
 }
예제 #20
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object value1 = cpu.PopStack();
     object value2 = cpu.PopStack();
     cpu.PushStack(value1);
     cpu.PushStack(value2);
 }
예제 #21
0
파일: Opcode.cs 프로젝트: WazWaz/KOS
 public override void Execute(CPU cpu)
 {
     object identifier = cpu.PopStack();
     if (identifier != null)
     {
         cpu.RemoveVariable(identifier.ToString());
     }
     else
     {
         cpu.RemoveAllVariables();
     }
 }