public static void DataBind(this Motor engine, Route route) { var list = new Dictionary<string, object>(); var function = engine.RuntimeContext.Runnable.FunctionTable[route.Action]; var instructions = engine.RuntimeContext.Runnable.Instructions; for (int i = function.EntryPoint; i < instructions.Length; i++) { var inst = instructions[i]; if (inst.OpCode == OpCode.DCL) { var value = route.Context.Request[inst.Operands[0].Value.ToString()] ?? string.Empty; list.Add(inst.Operands[0].Value.ToString(), value); } if (inst.OpCode == OpCode.EMP) break; } foreach (var keypar in list.Reverse()) { var op = new Operand(OperandType.Literal, keypar.Value); engine.RuntimeContext.Runnable.ParamStack.Push(op); } }
public OperandResolver In(Operand operand) { target = operand; if (target.Value != null) targetName = target.Value.ToString(); return this; }
public void SimpleInstruction() { var op0 = new Operand(OperandType.Variable, "x", 0); var op1 = new Operand(OperandType.Literal, 1, 0); var inst = new Instruction(OpCode.MOV, 1, op0, op1); var inst2 = new Instruction(OpCode.MOV, 2, op0, op1); Assert.AreEqual("00001:", inst.IndexName); Assert.AreEqual("00002:", inst2.IndexName); }
public void CreateStream() { var op0 = new Operand(OperandType.Literal, 1, 0); var op1 = new Operand(OperandType.Literal, 1, 0); var runtimeStream = new InstrucStream( new Instruction(OpCode.ADD, 1, op0, op1), new Instruction(OpCode.MOV, 2, op0, op1) ); Assert.AreEqual(2, runtimeStream.Size); }
public Instruction[] GetInstructions2() { var list = new List<Instruction>(); var op_name = new Operand(OperandType.Variable, "name"); var op_name2 = new Operand(OperandType.Variable, "name2"); var op_value = new Operand(OperandType.Literal, "Ricardo"); list.Add(new Instruction(OpCode.DCL, 0, op_name)); list.Add(new Instruction(OpCode.DCL, 1, op_name2)); list.Add(new Instruction(OpCode.MOV, 2, op_name, op_value)); list.Add(new Instruction(OpCode.MOV, 3, op_name2, op_name)); list.Add(new Instruction(OpCode.EXIT, 4)); return list.ToArray(); }
public OperandResolver At(int index) { target = context.CurrentInst.Operands[index]; targetName = target.Value.ToString(); return this; }
private bool ProcessJump(Operand firstOp, Operand secondOp) { var fp = firstOp.Value; //float.Parse(firstOp.Value.ToString()); var sp = secondOp.Value; // float.Parse(secondOp.Value.ToString()); switch (Instruction.OpCode) { case OpCode.JG: if (JG(fp, sp)) return true; break; case OpCode.JL: if (JL(fp, sp)) return true; break; case OpCode.JGE: if (JGE(fp, sp)) return true; break; case OpCode.JLE: if (JLE(fp, sp)) return true; break; } return false; }
private void ProcessPUSH() { var operand = Instruction.Operands[0]; var @new = new Operand(OperandType.Literal, operand.Value); if (operand.Type == OperandType.Variable) @new.Value = opResolver.At(0).Value(); if (@new.Value == null) new Ops().ThrowVarNonInit(operand.Value.ToString()); context.Runnable.ParamStack.Push(@new); }
private void ProcessHostedFunction(string name) { var handler = Container.ResolveHandler(name); var function = Container.Resolve(name); IList<object> parameters = new List<object>(); foreach (Operand item in ParamStack) { if (item.Type == OperandType.Literal) { if (item.Value != null) parameters.Add(item.Value); } else { parameters.Add(SymbolValue(item.Value.ToString())); } } var result = handler != null ? handler.Invoke(parameters.Reverse().ToArray()) : function.Executar(parameters.Reverse().ToArray()); var operand = new Operand(OperandType.Literal, result); ParamStack.Clear(); if (!Container.IsVoid(name)) ParamStack.Push(operand); }
private void ProcessCALL() { var name = opResolver.At(0).Name(); if (Container.IsRegistered(name)) { ProcessHostedFunction(name); return; } var returnInst = context.Runnable.Instructions[Instruction.Index + 1]; var returnAddress = new Operand(OperandType.InstructionRef, returnInst); RuntimeStack.Push(returnAddress); var function = context.Runnable.RetrieveFunction(name); context.Runnable.IP = function.EntryPoint; RuntimeStack.Push(function); context.CurrentFunction = null; }
private void ProcessArithmetic(bool stack) { float f1, f2; if (stack) { var op2 = ParamStack.Pop() as Operand; var op1 = ParamStack.Pop() as Operand; f1 = float.Parse(op1.Value.ToString()); f2 = float.Parse(op2.Value.ToString()); } else { Operand op = null; object opValue = null; var name = opResolver.At(0).SymbolId(); var curValue = SymbolValue(name); if (Instruction.OperandCount > 1) op = Instruction.Operands[1]; if (op != null) opValue = opResolver.At(1).Value(); if (curValue == null) throw new Exception("Variable was not initialized."); f1 = float.Parse(curValue.ToString()); f2 = 0f; if (opValue != null) f2 = float.Parse(opValue.ToString()); } switch (context.CurrentInst.OpCode) { case OpCode.SADD: case OpCode.ADD: f1 += f2; break; case OpCode.SSUB: case OpCode.SUB: f1 -= f2; break; case OpCode.SMUL: case OpCode.MUL: f1 *= f2; break; case OpCode.SDIV: case OpCode.DIV: f1 /= f2; break; case OpCode.SMOD: case OpCode.MOD: f1 %= f2; break; case OpCode.POW: f1 = (float)Math.Pow(f1, f2); break; case OpCode.INC: f1++; break; case OpCode.DEC: f1--; break; case OpCode.NEG: f1 = -f1; break; } int r; if (stack) { var result = new Operand(OperandType.Literal, int.TryParse(f1.ToString(), out r) ? r : f1); ParamStack.Push(result); } else { object value = int.TryParse(f1.ToString(), out r) ? r : f1; SetSymbolValue(Instruction.Operands[0], value); } }
public object SetSymbolValue(Operand target, Operand opvalue) { var id = opResolver.In(target).SymbolId(); var name = opResolver.Name(); var _value = opResolver.In(opvalue).Value(); int? index = null; if (target.IndexOffSet != null) index = ResolveIndex(target.IndexOffSet); return SymbolTable.SetSymbolValue(name, id, context.CurrentFunction.Name, _value, index); }
public object SetSymbolValue(Operand target, object value) { SetSymbolValue(target, new Operand(OperandType.Literal, value)); return value; }