Example #1
0
 public PrgState(ISymbolTable <string, int> s, IExeStack <Statement> exe, IOutput <int> o, IFileTable <int, FileData> ft)
 {
     this.symbolTable = s;
     this.exeStack    = exe;
     this.output      = o;
     this.filetable   = ft;
 }
Example #2
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt> stk = state.getExeStack();
            // stk.pop();

            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);


            FileTuple ft = fileTbl.getValue(value_exp);

            if (!fileTbl.isDefined(value_exp))
            {
                throw new Exception("The key is not defined in the file table");
            }

            StreamReader streamReader = fileTbl.getValue(value_exp).getStreamReader();

            try
            {
                streamReader.Close();
            }
            catch (IOException ex) { throw new Exception(ex.Message); }

            fileTbl.remove(value_exp);
            return(state);
        }
Example #3
0
 public PrgState(ADT.IDictionary <string, int> s, IExeStack <Statement> exe, IOutput <int> o, IFileTable <int, FileData> ft, Statement st)
 {
     this.symbolTable = s;
     this.exeStack    = exe;
     this.output      = o;
     this.filetable   = ft;
     exe.Push(st);
 }
Example #4
0
 public PrgState(IStmt prg)
 {
     this.exeStack        = new MyStack <IStmt>();
     this.symTable        = new MyDictionary <String, int>();
     this.outTbl          = new MyList <int>();
     this.originalProgram = prg.deepCopy();
     this.fileTable       = new FileTable <int, FileTuple>();
     this.exeStack.push(prg);
 }
Example #5
0
 public PrgState(MyIStack <IStmt> stk, MyIDictionary <string, int> symtbl,
                 MyIList <int> ot, IFileTable <int, FileTuple> fileTable, IStmt prg)
 {
     this.exeStack        = stk;
     this.symTable        = symtbl;
     this.outTbl          = ot;
     this.originalProgram = prg.deepCopy();
     this.fileTable       = fileTable;
     this.exeStack.push(prg);
 }
Example #6
0
 public PrgState(Statement ip,
                 IExeStack <Statement> es,
                 ISymbolTable <string, int> st,
                 IFileTable <int, FileStream> ft,
                 IOutput <int> o)
 {
     this.initialProg = ip;
     this.exeStack    = es; this.exeStack.push(ip);
     this.symTable    = st;
     this.fileTable   = ft;
     this.output      = o;
 }
 bool isOpen(string filename, IFileTable <int, FileStream> ft)
 {
     foreach (var item in ft.getMap())
     {
         int    workDirLen   = Directory.GetCurrentDirectory().Length + 1; // !!! + 1 because of windows slashes !!!
         string fullPath     = item.Value.Name;
         string relativePath = fullPath.Substring(workDirLen, fullPath.Length - workDirLen);
         if (filename.Equals(relativePath))
         {
             return(true);
         }
     }
     return(false);
 }
Example #8
0
 public PrgState(
     IExeStack <IStmt> _exeStack,
     IModDictionary <string, int> _symbTable,
     IModList <int> _outList,
     IFileTable <int, FileData> _fileTable,
     IStmt _originalProgram
     )
 {
     this.ExeStack        = _exeStack;
     this.SymbTable       = _symbTable;
     this.OutList         = _outList;
     this.FileTable       = _fileTable;
     this.OriginalProgram = _originalProgram;
     ExeStack.Push(OriginalProgram);
 }
Example #9
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk     = state.getExeStack();
            MyIDictionary <String, int> symTbl  = state.getSymTable();
            IFileTable <int, FileTuple> fileTbl = state.getFileTable();

            int value_exp = this.exp_file_id.eval(symTbl);

            FileTuple ft = fileTbl.getValue(value_exp);

            if (!symTbl.isDefined(ft.getFileName()))
            {
                //throw new MyStmtExecException("The key is not defined in the file table");
            }

            StreamReader streamReader = ft.getStreamReader();
            int          val          = -1;

            try
            {
                String line = streamReader.ReadLine();

                if (line == null)
                {
                    val = 0;
                }
                else
                {
                    try
                    {
                        val = int.Parse(line);
                    }
                    catch (Exception ex) { Console.WriteLine(ex.Message); }
                }


                symTbl.put(this.var_name, val);
            }
            catch (IOException ex) { throw new Exception(ex.Message); }
            return(state);
        }
Example #10
0
        public PrgState execute(PrgState state)
        {
            MyIStack <IStmt>            stk       = state.getExeStack();
            IFileTable <int, FileTuple> filetable = state.getFileTable();
            MyIDictionary <String, int> symTbl    = state.getSymTable();

            try
            {
                FileStream   reader         = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
                StreamReader bufferedStream = new StreamReader(reader);
                int          id             = IdGenerator.generateId();
                FileTuple    tuple          = new FileTuple(this.filename, bufferedStream);
                filetable.put(id, tuple);

                symTbl.put(this.var_file_id, id);
            }
            catch (Exception ex) { throw new Exception(ex.Message); }


            return(state);
        }
        public NintendoDSRom(string path, byte[] data)
        {
            Path     = path;
            _data    = new Slice <byte>(data);
            Segments = new List <Segment>();

            // Global file name table: pointer at 0x40, length at 0x44
            // Global file allocation table: pointer at 0x48, length at 0x4c
            var fntOffset = _data.ReadUInt(0x40);
            var fntLength = _data.ReadUInt(0x44);
            var fatOffset = _data.ReadUInt(0x48);
            var fatLength = _data.ReadUInt(0x4C);

            log.Info("FAT at {0:x}..{1:x}", fatOffset, fatOffset + fatLength);
            log.Info("FNT at {0:x}..{1:x}", fntOffset, fntOffset + fntLength);

            var fat = _data[fatOffset, fatOffset + fatLength];
            var fnt = _data[fntOffset, fntOffset + fntLength];

            FileTable = new RomFileTable();
            FileTable.Load(fat, fnt, _data);
        }
Example #12
0
 public void setFileTable(IFileTable <int, FileStream> ft)
 {
     this.fileTable = ft;
 }