コード例 #1
0
ファイル: Variable.cs プロジェクト: Baltasarq/CSim
 public Variable(Id id, Type t, Machine m)
     : this(m)
 {
     this.Name = id;
     this.type = t;
     this.Address = -1;
 }
コード例 #2
0
ファイル: Opcode.cs プロジェクト: Baltasarq/CSim
        /// <summary>
        /// Coerce the specified vble to type t, by creating another vble.
        /// </summary>
        /// <param name="t">The type to coerce the value, as Type.</param>
        /// <param name="vble">A Variable which is to be coerced.</param>
        /// <returns>>A new variable with coerced type, or the same variable.</returns>
        public static Variable Coerce(CSim.Core.Type t, Variable vble)
        {
            Variable toret = vble;
            Id id = new Id( "a" );

            id.SetIdWithoutChecks( "coerced_" + vble.Name.Name );

            if ( t != vble.Type ) {
                toret = new Variable( id, t, vble.Machine );
                toret.Address = vble.Address;
            }

            return toret;
        }
コード例 #3
0
ファイル: L18n.cs プロジェクト: Baltasarq/CSim
        /// <summary>
        /// Returns a localized string, given its id.
        /// </summary>
        /// <param name="id">The id for the string to get</param>
        /// <see cref="CSim.Core.L18n.Id"/>
        public static string Get(Id id)
        {
            string toret = null;
            int numId = (int) id;

            if ( numId < strings.Count ) {
                toret = strings[ numId ];
            }

            return toret;
        }
コード例 #4
0
ファイル: RefVariable.cs プロジェクト: Baltasarq/CSim
 public RefVariable(Id id, CSim.Core.Type t, Machine m)
     : base(id, t, m)
 {
     this.SetType( m.TypeSystem.GetRefType( t ) );
     this.pointedVble = null;
 }
コード例 #5
0
ファイル: RefVariable.cs プロジェクト: Baltasarq/CSim
 public RefVariable(Id id, CSim.Core.Type t, Machine m, int address)
     : this(id, t, m)
 {
     this.Address = address;
 }
コード例 #6
0
ファイル: SymbolTable.cs プロジェクト: Baltasarq/CSim
 public Variable Add(Id id, CSim.Core.Type t)
 {
     return this.Add( new Variable( id, t, this.Machine, -1 ) );
 }
コード例 #7
0
ファイル: SymbolTable.cs プロジェクト: Baltasarq/CSim
 /// <summary>
 /// Determines whether there is a variable with an identifier like the specified one.
 /// </summary>
 /// <returns><c>true</c> if there is a variable with that identifier; otherwise, <c>false</c>.</returns>
 /// <param name="idVble">The identifier in question, as a string.</param>
 public bool IsIdOfExistingVariable(Id id)
 {
     return ( this.LookForVariableOfId( id.Name ) != null );
 }
コード例 #8
0
ファイル: SymbolTable.cs プロジェクト: Baltasarq/CSim
 public Variable AddVector(Id id, CSim.Core.Type t, long size)
 {
     return this.Add( new ArrayVariable( id, t, this.Machine, size ) );
 }
コード例 #9
0
ファイル: Variable.cs プロジェクト: Baltasarq/CSim
 public Variable(Id id, Type t, Machine m, int address)
     : this(id, t, m)
 {
     this.Address = address;
 }
コード例 #10
0
ファイル: Parser.cs プロジェクト: Baltasarq/CSim
        private void ParseNew()
        {
            bool isVector = false;
            lexer.SkipSpaces();

            if ( lexer.GetToken() == Reserved.OpNew ) {
                Type type = this.Machine.TypeSystem.GetPrimitiveType( lexer.GetToken() );

                // Match square brackets
                if ( lexer.GetCurrentChar() == '[' ) {
                    isVector = true;
                    lexer.Advance();
                    lexer.SkipSpaces();
                    this.ParseExpression();
                    lexer.SkipSpaces();

                    if ( lexer.GetCurrentChar() != ']' ) {
                        throw new ParsingException( "]?" );
                    }
                }

                // Create variable (memory block)
                if ( isVector ) {
                    this.opcodes.Add( new CallOpcode( this.Machine, Malloc.Name ) );
                } else {
                    Id memBlkId = new Id( SymbolTable.GetNextMemoryBlockName() );
                    this.opcodes.Add( new CreateOpcode( this.Machine, memBlkId, type ) );
                    this.opcodes.Add( new AddressOpcode( this.Machine, memBlkId ) );
                }

                // Make the vble "id" point to it
                this.opcodes.Add( new AssignOpcode( this.Machine ) );
            } else {
                throw new EngineException(
                    L18n.Get( L18n.Id.ErrExpected )
                    + ": " + Reserved.OpNew );
            }

            return;
        }
コード例 #11
0
ファイル: Parser.cs プロジェクト: Baltasarq/CSim
        /// <summary>
        /// Parses the creation of a variable.
        /// </summary>
        private void ParseCreation(string typeId)
        {
            int oldPos;
            Id id;
            int ptrLevel = 0;
            bool isRef = false;

            lexer.SkipSpaces();

            // Is it a star over there?
            while ( lexer.GetCurrentChar() == Reserved.OpAccess[ 0 ] ) {
                ++ptrLevel;
                lexer.Advance();
                lexer.SkipSpaces();
            }

            // Is there an ampersand there?
            if ( lexer.GetCurrentChar() == Reserved.OpAddressOf[ 0 ] ) {
                isRef = true;
                lexer.Advance();
            }

            // Get id
            lexer.SkipSpaces();
            oldPos = lexer.Pos;
            id = new Id( lexer.GetToken() );

            if ( isRef ) {
                this.opcodes.Add( new CreateOpcode( this.Machine, id,
                                  	this.Machine.TypeSystem.GetRefType(
                                        this.Machine.TypeSystem.GetPrimitiveType( typeId ) ) ) );
            } else {
                if ( ptrLevel > 0 ) {
                    this.opcodes.Add(
                        new CreateOpcode( this.Machine, id,
                            this.Machine.TypeSystem.GetPtrType(
                                this.Machine.TypeSystem.GetPrimitiveType( typeId ),
                                ptrLevel ) )
                    );
                } else {
                    this.opcodes.Add( new CreateOpcode( this.Machine, id,
                                      	this.Machine.TypeSystem.GetPrimitiveType( typeId ) ) );
                }
            }

            // Check whether there is an assign on creation
            lexer.SkipSpaces();
            if ( !lexer.IsEOL() ) {
                if ( lexer.GetCurrentChar() == Reserved.OpAssign[ 0 ] ) {
                    lexer.Pos = oldPos;
                    this.ParseAssign();
                } else {
                        throw new EngineException(
                            L18n.Get( L18n.Id.ErrExpected )
                            + " " + L18n.Get( L18n.Id.ErrEOL ) );
                }
            } else {
                if ( isRef ) {
                    throw new EngineException( L18n.Get( L18n.Id.ErrRefInit ) );
                }
            }

            return;
        }