public override void Execute(ExecutionEnvironment environment) { DemandArgs(2); int offSet = environment.OpCodes.JumpTable.GetIndex(Arguments[0].Value.StringValue); int argCount = Arguments[1].Value.IntegerValue; LexicalScope ls = new LexicalScope(environment.GlobalScope); ExecutionStack s = new ExecutionStack(ls); if(argCount > 0) { ExecutionStackItem [] tmpItems = new ExecutionStackItem[argCount]; for(int i = 0; i < argCount; i++) { tmpItems[i] = environment.LocalStack.PopItem(); } for(int i = argCount - 1; i >= 0; i--) { s.PushItem(tmpItems[i]); } } environment.PushStack(s); environment.OpCodes.PushCurrentIPAndSet(offSet); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(2); string name = Arguments[0].Value.StringValue; int length = -1; if(Arguments[1].Value.Type == HVMType.Variable) { Variable v = environment.LocalScope.ResolveAny(Arguments[1].Value.StringValue); if(v == null) { throw new OpCodeArgumentException(1, HVMType.Variable, this); } VariableItem vi = v as VariableItem; if(vi == null) { throw new OpCodeArgumentException(1, HVMType.Variable, this); } length = vi.Value.IntegerValue; } else { length = Arguments[1].Value.IntegerValue; } VariableArray va = new VariableArray(name, length); environment.LocalScope.Add(va); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); int size = Arguments[0].Value.IntegerValue; environment.LocalStack.MaxSize = size; }
public override void Execute(ExecutionEnvironment environment) { environment.LocalStack.DemandSize(1, this); ExecutionStackItem item = environment.LocalStack.PopItem(); VariableItem var = environment.LocalScope.ResolveStackItem(item); Console.Write("{0}", var.Value.StringValue); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(2); environment.LocalStack.DemandSize(1, this); string name = Arguments[0].Value.StringValue; int index = -1; if(Arguments[1].Value.Type == HVMType.Variable) { Variable v = environment.LocalScope.ResolveAny(Arguments[1].Value.StringValue); if(v == null) { throw new OpCodeArgumentException(1, HVMType.Variable, this); } VariableItem vi = v as VariableItem; if(vi == null) { throw new OpCodeArgumentException(1, HVMType.Variable, this); } index = vi.Value.IntegerValue; } else { index = Arguments[1].Value.IntegerValue; } Variable vName = environment.LocalScope.ResolveAny(name); if(vName == null) { throw new OpCodeException(string.Format("Variable not found: {0}", name), this); } if(vName.Type != HVMType.Array) { throw new OpCodeException( string.Format("Attempt to index into non-array element: {0}", name), this); } VariableArray va = vName as VariableArray; if(va == null) { throw new OpCodeException( string.Format("Variable was not convertable to VariableArray: {0}", name), this); } ExecutionStackItem esi = environment.LocalStack.PopItem(); VariableItem vTemp = environment.LocalScope.ResolveStackItem(esi); va.SetAtIndex(index, vTemp); environment.LocalScope.Update(va); }
public override void Execute(ExecutionEnvironment environment) { if(System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } else { System.Diagnostics.Debug.Assert(false, "dbg opcode hit."); } }
public override void Execute(ExecutionEnvironment environment) { environment.LocalStack.DemandSize(1, this); ExecutionStackItem item_rhs = environment.LocalStack.PopItem(); VariableItem var_rhs = environment.LocalStack.Scope.ResolveStackItem(item_rhs); int result = ~var_rhs.Value.IntegerValue; Variant vResult = new Variant(result); environment.LocalStack.PushItem(new ExecutionStackItem(new Argument(vResult))); }
public override void Execute(ExecutionEnvironment environment) { ExecutionStackItem esi = environment.LocalStack.PopItem(); if(esi.Value.Value.Type != HVMType.Boolean) { throw new RuntimeException("Conditional Branch brtrue requires a boolean type on the stack"); } if(esi.Value.Value.BooleanValue == false) { int offSet = environment.OpCodes.JumpTable.GetIndex(Arguments[0].Value.StringValue); environment.OpCodes.BranchTo(offSet); } }
public override void Execute(ExecutionEnvironment environment) { environment.LocalStack.DemandSize(2, this); ExecutionStackItem item_rhs = environment.LocalStack.PopItem(); VariableItem var_rhs = environment.LocalStack.Scope.ResolveStackItem(item_rhs); ExecutionStackItem item_lhs = environment.LocalStack.PopItem(); VariableItem var_lhs = environment.LocalStack.Scope.ResolveStackItem(item_lhs); bool result = (var_lhs.Value.CompareTo(var_rhs.Value) > 0); VariableItem v = new VariableItem(null, result); environment.LocalStack.PushItem(new ExecutionStackItem(v)); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); int arg = Arguments[0].Value.IntegerValue; if(arg <= 0) { return; } environment.LocalStack.DemandSize(arg, this); for(int i = 0; i < arg; i++) { environment.LocalStack.PopItem(); } }
public static void Main(string [] args) { DateTime start = DateTime.Now; if(args.Length == 0) { Console.WriteLine("missing argument: file name"); return; } if(!File.Exists(args[0])) { Console.WriteLine("File not found: {0}", args[0]); return; } try { ExecutionEnvironment ee; using(StreamReader sr = new StreamReader(args[0])) { ParseStream ps = new ParseStream(sr.BaseStream); ee = new ExecutionEnvironment(); ee.Initialize(ps); sr.Close(); } while(!ee.OpCodes.EndOfStream) { OpCode oc = ee.OpCodes.GetNext(); oc.Execute(ee); } } catch(HVMException he) { Console.WriteLine(he.Message); } TimeSpan ts = DateTime.Now - start; Console.WriteLine("Runtime: {0}ms", ts.TotalMilliseconds); return; }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); Variable v = environment.LocalScope.ResolveAny(Arguments[0].Value.StringValue); if(v == null || v.Type != HVMType.Array) { throw new OpCodeArgumentException(0, HVMType.Variable, this); } VariableArray va = v as VariableArray; if(va == null) { throw new OpCodeArgumentException(0, HVMType.Variable, this); } VariableItem result = new VariableItem(null, va.Length); environment.LocalStack.PushItem(new ExecutionStackItem(result)); }
public override void Execute(ExecutionEnvironment environment) { environment.LocalStack.DemandSize(1, this); ExecutionStackItem esi = environment.LocalStack.PopItem(); if(esi.Value.Value.Type == HVMType.Variable) { VariableItem var = environment.LocalScope.ResolveStackItem(esi); if(var != null) { try { var.Value.IntegerValue++; } catch(Exception) { throw new RuntimeException("Opcode can only be used on integer types (or types convertable to int): inc"); } environment.LocalScope.Update(var); environment.LocalStack.PushItem(esi); } else { throw new RuntimeException( string.Format("Unable to locate variable named: {0}", esi.Value.Name) ); } } else { try { esi.Value.Value.IntegerValue++; } catch(Exception) { throw new RuntimeException("Opcode can only be used on integer types (or types convertable to int): inc"); } environment.LocalStack.PushItem(esi); } }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); environment.LocalStack.DemandSize(1, this); ExecutionStackItem item = environment.LocalStack.PopItem(); Variable v = environment.LocalScope.ResolveAny(Arguments[0].Value.StringValue); VariableItem vi= null; if(v.Type != HVMType.Array) { vi = v as VariableItem; } if(v == null) { throw new OpCodeArgumentException(0, HVMType.String, this); } vi.Value = item.Value.Value.Clone() as Variant; environment.LocalScope.Update(vi); }
public override void Execute(ExecutionEnvironment environment) { environment.LocalStack.DemandSize(1, this); ExecutionStackItem esi = environment.LocalStack.Peek() as ExecutionStackItem; if(esi.Value.Value.Type == HVMType.Variable) { VariableItem v = environment.LocalScope.ResolveStackItem(esi); if(v == null) { throw new RuntimeException("Unable to resolve stack item as variable"); } VariableItem v2 = v.Clone() as VariableItem; environment.LocalStack.PushItem(new ExecutionStackItem(v2)); } else { ExecutionStackItem esi2 = new ExecutionStackItem(esi.Value.Clone() as VariableItem); environment.LocalStack.PushItem(esi2); } }
public override void Execute(ExecutionEnvironment environment) { }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); environment.LocalStack.PushItem(new ExecutionStackItem(Arguments[0])); }
public override void Execute(ExecutionEnvironment environment) { DemandArgs(1); VariableItem v = new VariableItem(null, Arguments[0].Value.StringValue); environment.LocalStack.PushItem(new ExecutionStackItem(v)); }
public override void Execute(ExecutionEnvironment environment) { environment.OpCodes.BranchTo(environment.OpCodes.Length); }
public override void Execute(ExecutionEnvironment environment) { environment.LocalScope.Add(GetVariable()); }
public override void Execute(ExecutionEnvironment environment) { string val = Console.ReadLine(); VariableItem v = new VariableItem(null, val); environment.LocalStack.PushItem(new ExecutionStackItem(v)); }
public abstract void Execute(ExecutionEnvironment environment);