Esempio n. 1
0
File: Call.cs Progetto: 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);
        }
Esempio n. 2
0
        public void Initialize(ParseStream strm)
        {
            if(strm == null)
            {
                throw new ArgumentNullException("strm", "Can not initialize from a null stream");
            }

            globalLexicalScope = new LexicalScope(null);
            globalLexicalScope.Add(new VariableItem("true", true));
            globalLexicalScope.Add(new VariableItem("false", false));

            executionStacks.Push(new ExecutionStack(globalLexicalScope));

            opcodeStream = new OpcodeStream(strm, LocalStack);
        }
Esempio n. 3
0
File: Push.cs Progetto: bubbafat/HVM
        public override int ReadArguments(ParseStream strm, LexicalScope scope)
        {
            int read = 0;

            Argument arg = new Argument();

            if(strm.NextTokenCouldBeVariable())
            {
                string vresult = null;
                if(strm.ReadVariableName(ref vresult))
                {
                    arg.Value.StringValue = vresult;
                    arg.Value.Type = HVMType.Variable;
                    read++;
                }
            }
            else
            {
                if(strm.Eof)
                {
                    throw new ParseException("Argument to opcode: push", "Unexpected end of file");
                }

                int val = int.MinValue;
                if(strm.ReadNumeric(ref val))
                {
                    arg.Value.Type = HVMType.Integer;
                    arg.Value.IntegerValue = val;
                    read++;
                }
            }

            if(read == 0)
            {
                if(strm.Eof)
                {
                    throw new ParseException("Argument to opcode: push", "Unexpected end of file");
                }

                throw new ParseException("Argument to opcode: push", "Unable to read valid data from stream");
            }

            Arguments[0] = arg;

            return read;
        }
Esempio n. 4
0
 public override int ReadArguments(ParseStream strm, LexicalScope scope)
 {
     return this.ReadVariableNameAndIntegerOrVariableInt(strm, scope);
 }
Esempio n. 5
0
 public ExecutionStack(LexicalScope scope)
 {
     _scope = scope;
 }
Esempio n. 6
0
        public virtual int ReadArguments(ParseStream strm, LexicalScope scope)
        {
            int read = 0;

            for(int i = 0; i < ArgumentCount; i++)
            {
                HVMType type = ArgumentTypes[i];
                Argument arg = new Argument();
                arg.Value.Type = type;
                bool valParse = false;

                switch(type)
                {
                    case HVMType.Boolean:
                        bool bresult = false;
                        if(strm.ReadBoolean(ref bresult))
                        {
                            arg.Value.BooleanValue = bresult;
                            valParse = true;
                        }
                        break;
                    case HVMType.Integer:
                        int iresult = int.MinValue;
                        if(strm.ReadNumeric(ref iresult))
                        {
                            arg.Value.IntegerValue = iresult;
                            valParse = true;
                        }
                        break;
                    case HVMType.String:
                        string sresult = null;
                        if(strm.ReadWord(ref sresult))
                        {
                            arg.Value.StringValue = sresult;
                            valParse = true;
                        }
                        break;
                    case HVMType.VariableName:
                        string vnresult = null;
                        valParse = strm.ReadVariableName(ref vnresult);
                        arg.Value.StringValue = vnresult;
                        if(!valParse)
                        {
                            throw new ParseException("Variable name", vnresult);
                        }
                        break;
                    case HVMType.QuotedString:
                        string qsresult = null;
                        if(strm.ReadQuotedString(ref qsresult))
                        {
                            arg.Value.StringValue = qsresult;
                            valParse = true;
                        }
                        break;
                    case HVMType.Variable:
                        string vresult = null;
                        valParse = strm.ReadVariableName(ref vresult);
                        arg.Value.StringValue = vresult;
                        if(!valParse)
                        {
                            throw new ParseException("word begining with @ (variable name)", vresult);
                        }
                        break;
                }

                if(!valParse)
                {
                    if(strm.Eof)
                    {
                        throw new ParseException( string.Format("{0} data", type.ToString()),
                            "unexpected end of file");
                    }

                    throw new OpCodeArgumentException(i, type, this);
                }

                Arguments[i] = arg;
                read++;
            }

            return read;
        }
Esempio n. 7
0
        protected int ReadVariableNameAndIntegerOrVariableInt(ParseStream strm, LexicalScope scope)
        {
            int read = 0;

            Argument argName = new Argument();
            Argument argIndex = new Argument();

            if(strm.NextTokenCouldBeVariable())
            {
                string vresult = null;
                if(strm.ReadVariableName(ref vresult))
                {
                    argName.Value.StringValue = vresult;
                    argName.Value.Type = HVMType.Variable;
                    read++;
                }
            }
            else
            {
                throw new OpCodeArgumentException(0, HVMType.Variable, this);
            }

            if(strm.NextTokenCouldBeVariable())
            {
                string vresult = null;
                if(strm.ReadVariableName(ref vresult))
                {
                    argIndex.Value.StringValue = vresult;
                    argIndex.Value.Type = HVMType.Variable;
                    read++;
                }
            }
            else
            {
                if(strm.Eof)
                {
                    throw new ParseException("Argument to opcode: stidx", "Unexpected end of file");
                }
                int val = int.MinValue;
                if(strm.ReadNumeric(ref val))
                {
                    argIndex.Value.Type = HVMType.Integer;
                    argIndex.Value.IntegerValue = val;
                    read++;
                }
            }

            if(read != 2)
            {
                if(strm.Eof)
                {
                    throw new ParseException("Argument to opcode: stidx", "Unexpected end of file");
                }

                throw new ParseException("Argument to opcode: stidx", "Unable to read valid data from stream");
            }

            Arguments[0] = argName;
            Arguments[1] = argIndex;

            return read;
        }
Esempio n. 8
0
 public LexicalScope(LexicalScope parent)
 {
     _symbols = new Hashtable();
     _parent = parent;
 }