Example #1
0
File: Call.cs Project: bubbafat/HVM
        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);
        }
Example #2
0
        public override void Execute(ExecutionEnvironment environment)
        {
            DemandArgs(2);

            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;
            }

            if(index < 0)
            {
                throw new OpCodeException("index parameter must be positive", this);
            }

            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 = new ExecutionStackItem(va.GetAtIndex(index));
            environment.LocalStack.PushItem(esi);
        }
Example #3
0
File: Dup.cs Project: bubbafat/HVM
        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);
            }
        }
Example #4
0
        public void PushItem(ExecutionStackItem item)
        {
            if(item == null)
            {
                throw new StackException("Can not push null item onto ExecutionStack");
            }

            Push(item);
        }
Example #5
0
        public VariableItem ResolveStackItem(ExecutionStackItem item)
        {
            VariableItem v = null;
            if(item.Value.Value.Type == HVMType.Variable)
            {
                v = ResolveAny(item.Value.Name) as VariableItem;
            }
            else
            {
                v = item.Value.Clone() as VariableItem;
            }

            if(v == null)
            {
                throw new ParseException( "Defined variable", string.Format("Undefined variable: {0}", item.Value.Name) );
            }

            return v;
        }