Exemple #1
0
def main(argv=None):
    """
    """
    
    if not argv:
        argv = sys.argv[:]

    gui = False
    if len(argv) == 1:
        file = argv[0]
    elif len(argv) == 2 and argv[0] == 'gui':
        gui = True
        file = argv[1]
    else:
        print u'Naudojimas: pyemu <failas>'
        sys.exit(1)

    if gui:
        pyemu.gui.start_gui(file)
    else:

        def stdin():
            return raw_input('INPUT: ')

        def stdout(block):
            for i in range(0, len(block), 8):
                print 'Word {0:2}: "{1}"'.format(i/8, block[i:i+8])

        rm = RealMachine()
        rm.load_virtual_machine(file, stdin, stdout)
        for name in file_system.get_files():
            print 'Failas {0}'.format(name)
        rm.processor.execute()
Exemple #2
0
    def test_init_real_machine(self):

        rm = RealMachine()
        tests_dir = os.path.abspath(os.path.dirname(__file__))
        rm.load_virtual_machine(os.path.join(tests_dir, 'test_program_1'))
        assert rm.processor.IC == 0
        rm.processor.step()
        assert rm.processor.IC == 1

        try:
            rm.load_virtual_machine(
                    open(os.path.join(tests_dir, 'test_program_1')))
        except Exception, e:
            assert str(e) == 'Not implemented!'
Exemple #3
0
    def setUp(self):
        u""" Užkrauna mašiną testavimui.
        """

        self.rm = RealMachine()
        tests_dir = os.path.abspath(os.path.dirname(__file__))
        self.rm.load_virtual_machine(
                os.path.join(tests_dir, 'test_program_1'))
        self.proc = self.rm.processor
        self.code = self.rm.virtual_memory_code
        self.data = self.rm.virtual_memory_data
Exemple #4
0
class ProcessorTest(unittest.TestCase):
    u""" Testai procesoriaus funkcijoms.
    """


    def setUp(self):
        u""" Užkrauna mašiną testavimui.
        """

        self.rm = RealMachine()
        tests_dir = os.path.abspath(os.path.dirname(__file__))
        self.rm.load_virtual_machine(
                os.path.join(tests_dir, 'test_program_1'))
        self.proc = self.rm.processor
        self.code = self.rm.virtual_memory_code
        self.data = self.rm.virtual_memory_data

    def test_environment(self):
        assert self.code.pager.get_C() == 1
        assert self.data.pager.get_D() == 1

    def test_command_NONE(self):
        self.code[0] = 'NONE'
        assert self.proc.PI == '0'
        assert self.proc.step() == False
        assert self.proc.PI == '1'

    def test_command_wrong(self):
        self.code[0] = 'HALT 5'
        assert self.proc.PI == '0'
        assert self.proc.step() == False
        assert self.proc.PI == '1'

        assert self.proc.IC == 0
        self.code[0] = 'LR1 0 1'
        try:
            self.proc._step()
        except WrongOpCode, e:
            assert unicode(e) == u'Netinkamas argumentų kiekis.'
        else: