コード例 #1
0
ファイル: Call.cs プロジェクト: 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);
        }
コード例 #2
0
ファイル: ExecutionEnvironment.cs プロジェクト: bubbafat/HVM
        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);
        }
コード例 #3
0
ファイル: Push.cs プロジェクト: 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;
        }
コード例 #4
0
ファイル: LdIdx.cs プロジェクト: bubbafat/HVM
 public override int ReadArguments(ParseStream strm, LexicalScope scope)
 {
     return this.ReadVariableNameAndIntegerOrVariableInt(strm, scope);
 }
コード例 #5
0
ファイル: ExecutionStack.cs プロジェクト: bubbafat/HVM
 public ExecutionStack(LexicalScope scope)
 {
     _scope = scope;
 }
コード例 #6
0
ファイル: OpCode.cs プロジェクト: bubbafat/HVM
        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;
        }
コード例 #7
0
ファイル: OpCode.cs プロジェクト: bubbafat/HVM
        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;
        }
コード例 #8
0
ファイル: LexicalScope.cs プロジェクト: bubbafat/HVM
 public LexicalScope(LexicalScope parent)
 {
     _symbols = new Hashtable();
     _parent = parent;
 }