def main0(): instruction1 = BasicInstruction() instruction2 = IO_Instruction() instruction3 = Priority_Instruction() program = Program('a') program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) programb = Program('b') programb.addInstruction(instruction3) programc = Program('c') programc.addInstruction(instruction1) programc.addInstruction(instruction1) programc.addInstruction(instruction1) timer = Timer(2) memory = Memory() memory.buildMemory(9) frame1 = Frame(memory,0,9) mmu = MMU() mmu.addEmptyFrame(frame1) cpu = CPU(None,mmu,None,timer) scheduler = Scheduler(PFIFO()) ioqueue = IOQueue(scheduler) disk = Disk(None) kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk) disk.setKernel(kernel) cpu.setKernel(kernel) kernel.saveProgram(program) kernel.saveProgram(programb) kernel.saveProgram(programc) kernel.start() cpu.start() ioqueue.start()
def main1(): instruction1 = BasicInstruction() instruction3 = Priority_Instruction() logger = Logger("../resource/log.txt") program = Program('a') program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) programb = Program('b') programb.addInstruction(instruction3) programc = Program('c') programc.addInstruction(instruction1) programc.addInstruction(instruction1) programc.addInstruction(instruction1) timer = Timer(2) memory = Memory() memory.buildMemory(9) frame1 = Frame(memory,0,9) mmu = MMU() mmu.addEmptyFrame(frame1) cpu = CPU(None,mmu,None,timer,logger) scheduler = Scheduler(PFIFO()) ioqueue = IOQueue(scheduler,logger) disk = Disk(None) kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk,logger) disk.setKernel(kernel) disk.save(program) disk.save(programb) disk.save(programc) cpu.setKernel(kernel) kernel.executeProgram('a')
def __init__(self, pc=1): self.registers = [Register(i) for i in range(32)] self.params = None self.op = None self.pc = pc self.saved_flags = Flags() self.memory = Memory()
def main2(): instruction1 = BasicInstruction() instruction2 = BasicInstruction() memory = Memory() memory.buildMemory(5) frame1 = Frame(memory,0,1) frame2 = Frame(memory,1,2) frame3 = Frame(memory,3,1) frame4 = Frame(memory,4,1) mmu = MMU() mmu.fullFrames.append(frame1) mmu.fullFrames.append(frame3) mmu.emptyFrames.append(frame2) mmu.emptyFrames.append(frame4) program = Program('a') program.addInstruction(instruction1) pcbA = PCB('a',0,0,1) programb = Program('b') pcbB = PCB('b',0,3,1) programb.addInstruction(instruction1) frame1.load(pcbA,program) frame3.load(pcbB,programb) memory.printMemory() print(memory.getEmptyCells()) mmu.compact() memory.printMemory()
def start_execution(options): f = open(options.file, 'r') content = f.read() read_content = ReadContents() instructions = Instructions() #print "Id 2 :", id(instructions) registers = Registers() memory = Memory() read_content.read_iregisters(content) read_content.read_fpregisters(content) read_content.read_memory(content) read_content.get_instructions(content) #instructions, registers, memory = read_content.return_attrs() instructions = read_content.return_attrs() #print "registers: ", id(registers), " Inst : ", id(instructions.registers), id(memory), id(instructions.memory) #print instructions.get_instructions(), '\n', registers.r['R2'], '\n', memory.location, '\n', registers.f instructions.build_instruction_objects() #print instructions.instructions_object_list #print "In main file : ", id(memory), id(registers), id(instructions) clock = Clock(instructions) #clock.print_object_ids() #print clock.start_clock() #print clock.clock clock.next_instruction() #print "log : ", Registers.f['F4']['contents'] writer = Writer(clock.clock_execution_dict, Registers.f, len(instructions.instructions_object_list)) writer.write_to_file() writer.write_to_file_registers()
def __init__(self, memorySize): self._memory = Memory(memorySize) self._mmu = MMU(self._memory) self._irqVector = IRQVector() self._cpu = CPU(self._mmu, self._irqVector) self._IOdevice = IOdevice(self._irqVector) self._clock = Clock(self._cpu, self._IOdevice) self._timer = DummyTimer()
def main3(): if(1==1): instruction1 = BasicInstruction() instruction2 = BasicInstruction() memory = Memory() memory.buildMemory(5) frame1 = Frame(memory,0,1) frame2 = Frame(memory,1,2) frame3 = Frame(memory,3,1) frame4 = Frame(memory,4,1) mmu = MMU() mmu.fullFrames.append(frame1) mmu.fullFrames.append(frame3) mmu.emptyFrames.append(frame2) mmu.emptyFrames.append(frame4) program = Program('a') program.addInstruction(instruction1) pcbA = PCB('a',0,0,1) programb = Program('b') pcbB = PCB('b',0,3,1) programb.addInstruction(instruction1) frame1.load(pcbA,program) frame3.load(pcbB,programb) programc = Program('c') programc.addInstruction(instruction1) programc.addInstruction(instruction1) programc.addInstruction(instruction1) programd = Program('d') programd.addInstruction(instruction2) programd.addInstruction(instruction2) programd.addInstruction(instruction2) scheduler = Scheduler(PFIFO()) disk = Disk(None) kernel = Kernel (None,None,scheduler,mmu,disk) disk.setKernel(kernel) memory.printMemory() kernel.saveProgram(programc) print( " ") memory.printMemory() kernel.saveProgram(programd) print( " ") memory.printMemory() print(len(disk.programList))
def main(): instruction1 = BasicInstruction() instruction2 = IO_Instruction() instruction3 = Priority_Instruction() program = Program('a') program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) program.addInstruction(instruction1) programd = Program('d') programd.addInstruction(instruction1) programd.addInstruction(instruction1) programd.addInstruction(instruction1) programd.addInstruction(instruction1) programd.addInstruction(instruction1) programb = Program('b') programb.addInstruction(instruction3) programc = Program('c') programc.addInstruction(instruction1) programc.addInstruction(instruction1) programc.addInstruction(instruction1) timer = Timer(2) memory = Memory() memory.buildMemory(9) frame1 = Frame(memory,0,9) logger = Logger("/home/matlock/Escritorio/Sistemas Operativos/OSProyect/resource/log.txt") mmu = MMU(logger) mmu.addEmptyFrame(frame1) cpu = CPU(None,mmu,None,timer,logger) scheduler = Scheduler(PFIFO()) ioqueue = IOQueue(scheduler,logger) disk = Disk(None) kernel = Kernel(cpu,ioqueue,scheduler,mmu,disk,logger) disk.setKernel(kernel) cpu.setKernel(kernel) x = [] x.append(program) x.append(programb) x.append(programc) x.append(programd) kernel.saveOnDisk(x) kernel.executeProgram('a')
from src.LexicalException import LexicalException from src.Memory import Memory from src.Parser import Parser from src.ParserException import ParserException __author__ = 'thamilton' if __name__ == "__main__": try: parser = Parser("/Users/thamilton/PycharmProjects/Project_2/test_data/test3.e") parser.feature().execute() memory = Memory() memory.display_memory() except (OSError, IOError, ValueError, Exception, LexicalException, ParserException) as e: print(e)
def setUp(self): self.memory = Memory(20) self.instruction1 = InstructionProgram("An Instruction") self.instruction2 = InstructionIO("IO") self.instruction3 = InstructionProgram("Other Instruction")
class MemoryTest(unittest.TestCase): #Arrange def setUp(self): self.memory = Memory(20) self.instruction1 = InstructionProgram("An Instruction") self.instruction2 = InstructionIO("IO") self.instruction3 = InstructionProgram("Other Instruction") def test_whenTheMemoryAddsAnInstructionAndIAskForIt_thenIGetIt(self): self.memory.put(0, self.instruction1) self.memory.put(1, self.instruction2) self.memory.put(2, self.instruction3) self.assertEqual(self.memory.get(0), self.instruction1) self.assertEqual(self.memory.get(1), self.instruction2) self.assertEqual(self.memory.get(2), self.instruction3) def test_whenISetThreeInstructions_thenIGetTwoFreeSpaces(self): self.memory.put(0, self.instruction1) self.memory.put(1, self.instruction2) self.memory.put(2, self.instruction3) self.assertEqual(self.memory.get_free_space(), 17) def test_whenIHaveSomeInstructionsAndCompact_thenItAllGoesUp(self): for index in range(0, 5): self.memory.put(index, self.instruction1) for index in range(12, 14): self.memory.put(index, self.instruction2) for index in range(17, 20): self.memory.put(index, self.instruction2) self.memory.compact() self.assertEqual(self.memory.get(19), None)
traceback.print_exc() return json_error("Illegal filter parameters", 422, e) @app.route('/property-types', methods=['GET']) def get_property_types(): types = [{'name': t.name, 'value': t.value} for t in PropertyType] return jsonify(types) def prepare(df): return df.fillna('NaN') @app.route('/predict', methods=['POST']) def cost_prediction(): sent = dict(request.json) return jsonify(cost_predictor(sent)) if __name__ == '__main__': print('Loading memory ...') memory = Memory('new_data.csv') graph_cache = create_graph_cache(memory.data) print(f'Loaded {len(memory.data)} records.') cost_predictor = create_cost_predictor(memory.data) prop_type_predictor, ptc_acc = create_pt_classifier(memory.data) print(f'Trained property type classifier, accuracy={ptc_acc}') app.run()
def execute(self): memory = Memory() memory.store(self.input_val, self.expression.evaluate())
class CPU: def __init__(self, pc=1): self.registers = [Register(i) for i in range(32)] self.params = None self.op = None self.pc = pc self.saved_flags = Flags() self.memory = Memory() def set_flags(self, flags): self.saved_flags.set_flags(flags) # Readies an instruction to be executed def decode(self, instruction, labels): # This is for if the instruction is just a label if not instruction.opcode: self.params = None self.op = None return # Changing the tokens into usable values self.params = [] for i in instruction.params: if i.type == TTS.REGISTER: self.params.append(self.registers[i.r_val]) elif i.type == TTS.IMMEDIATE: self.params.append(i.i_val) elif i.type == TTS.LABEL: try: goto = labels[i.l_val] except KeyError: raise ExecutionError(f"Invalid label: {i.l_val}") self.params.append(goto) self.op = INSTRUCTION_SET[instruction.opcode][FUNC](self) def execute(self): # pc inc is done before execution to not mess up jumps self.pc += 1 if not self.op: return ret = self.op.execute(*self.params) # op.s says if it was a set flag instruction # ret should always exist if true but I check anyway if self.op.s and ret: self.set_flags(ret) def reg_dump(self, mode="dec", row_size=4): row_counter = 0 s = "" for reg in self.registers: s += reg.__repr__(mode=mode) row_counter += 1 if row_counter == row_size: row_counter = 0 s += "\n" else: s += "\t" print(s) def mem_dump(self, register_num=None, mode="dec"): address = self.registers[ register_num].value if register_num is not None else None self.memory.print(address=address, mode=mode) def __repr__(self): return str(self.registers)
def evaluate(self): memory = Memory() return memory.fetch(self.character)