def __init__(self): self.musics = [ pygame.mixer.Sound('../Assets/Sounds/dungeon.ogg'), pygame.mixer.Sound('../Assets/Sounds/dungeon2.ogg'), pygame.mixer.Sound('../Assets/Sounds/menu.ogg') ] self.bossMusics = [ pygame.mixer.Sound('../Assets/Sounds/bossMain.ogg'), pygame.mixer.Sound('../Assets/Sounds/bossFinal.ogg') ] self.effects = [ pygame.mixer.Sound('../Assets/Sounds/click.ogg'), pygame.mixer.Sound('../Assets/Sounds/magic.ogg'), pygame.mixer.Sound('../Assets/Sounds/youDied.ogg'), pygame.mixer.Sound('../Assets/Sounds/spike.ogg'), pygame.mixer.Sound('../Assets/Sounds/openingChest.ogg'), pygame.mixer.Sound('../Assets/Sounds/death.ogg') ] self.musicChannel = pygame.mixer.Channel(0) self.sfxChannel = pygame.mixer.Channel(1) self.sfx2Channel = pygame.mixer.Channel(2) self.musicChannel.set_volume(Interpreter().getParameter('music')) self.sfxChannel.set_volume(Interpreter().getParameter('sfx')) self.sfx2Channel.set_volume(Interpreter().getParameter('sfx')) self.lastMusic = self.musics[0] self.equalization()
def test_interpreter(self): # Test the interpreter for normal function. # To configure the state machine. intp1 = Interpreter() intp1.input_from_file("TrafficLight.txt") intp1.input_signal("TURN ON", 0) intp1.input_signal("TURN GREEN", 5) intp1.input_signal("TURN YELLOW", 8) intp1.input_signal("TURN RED", 11) intp1.input_signal("TURN OFF", 15) intp1.create_action_table() intp1.end_state.append("RED") intp1.end_input.append("TURN OFF") result = intp1.execute() self.assertEqual(result, True) # Test the interpreter's handling of receiving abnormal event list. intp2 = Interpreter() intp2.input_from_file("TrafficLight.txt") intp2.input_signal("TURN RED", 0) intp2.input_signal("TURN ON", 5) intp2.input_signal("TURN OFF", 8) intp2.input_signal("TURN GREEN", 11) intp2.input_signal("TURN OFF", 15) intp2.create_action_table() intp2.end_state.append("RED") intp2.end_input.append("TURN OFF") self.assertEqual(intp2.execute(), False)
def update(self): if not self.musicChannel.get_busy(): self.musicChannel.queue(self.lastMusic) a = Interpreter().getParameter('music') b = Interpreter().getParameter('sfx') self.musicChannel.queue(self.lastMusic) self.musicChannel.set_volume(a) self.sfxChannel.set_volume(b) self.sfx2Channel.set_volume(b)
def main(): print(sys.argv) path = os.path.join(os.getcwd(), "Roms", sys.argv[1]) if "debug" in sys.argv: interpreter = Interpreter(path, True) Debugger(interpreter).execute() else: interpreter = Interpreter(path, False) while True: interpreter.tick()
def test_OP_8xy3(self): # XOR Vx, Vy: Set Vx = Vx XOR Vy path = os.path.join(os.getcwd(), "test_roms", "XOR.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 0b10101 interpreter.registers[2] = 0b01100 interpreter.tick() self.assertEqual(interpreter.registers[1], 0b11001)
def test_OP_8xy0(self): # LD Vx, Vy: Set Vx = Vy path = os.path.join(os.getcwd(), "test_roms", "Ld_Vx_Vy.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 0x1 interpreter.registers[2] = 0xA interpreter.tick() self.assertEqual(interpreter.registers[1], 0xA)
def test_OP_2nnn(self): # CALL addr: Call subroutine at nnn path = os.path.join(os.getcwd(), "test_roms", "call_subroutine.ch8") interpreter = Interpreter(path, False) interpreter.tick() correct = [0x202, 0x204] + [0x200] * 14 self.assertEqual(interpreter.stack, correct) self.assertEqual(interpreter.stack_pointer, 1)
def test_OP_8xyE(self): # SHL Vx {, Vy}: Set Vx = Vx SHL 1 path = os.path.join(os.getcwd(), "test_roms", "SHL_VX.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 129 interpreter.tick() self.assertEqual(interpreter.registers[1], 2) # Should wrap self.assertEqual(interpreter.registers[0xF], 1)
def __init__(self, height, width): self.camera = pygame.Rect(0, 0, width, height) self.width = width self.height = height self.data = Interpreter() self.screenWidth = self.data.getParameter('screenSize')[0] self.screenHeight = self.data.getParameter('screenSize')[1]
def __init__(self, **kwargs): super(MainLayout, self).__init__(**kwargs) self.Interpreter = Interpreter() self.command_stack = [] self.cols = 2 self.orientation = "vertical" self.padding = 10 self.workspace = Workspace() self.command_panel = CommandPanel(self.workspace) self.output = Output() self.spn_menu = Spinner(text='Menu', values=('New', 'Save', 'RUN', 'Exit'), size_hint =(None, None), size=(200, 44), pos_hint={'x': .1, 'y': .9}) self.spn_menu.bind(text=self.menu_option_selected_event) self.command_panel.draw(self.spn_menu) self.command_panel.add_expression_btn('LET') self.command_panel.add_expression_btn('PRINT') self.command_panel.add_expression_btn('GOTO') self.command_panel.add_expression_btn('IF') self.command_panel.add_expression_btn('GOSUB') self.command_panel.add_expression_btn('RETURN') self.command_panel.add_expression_btn('END') self.add_widget(self.command_panel) self.orientation = "horizontal" self.workspace.draw() self.add_widget(self.workspace) self.output.draw() self.add_widget(self.output)
def main(): memory = defaultdict(int) states = ['PREFIX', 'INFIX', 'POSTFIX'] state = states[1] while True: try: text = input(state + ' --> ') except EOFError: break if not text: continue command = text.strip().upper() if command == 'EXIT': break if command in states: state = command continue lexer = Lexer(text) interpreter = Interpreter(lexer, state, memory) result = interpreter.evaluate() print(result)
def __init__(self): self.data = Interpreter() self.difficulties = ['easy', 'normal', 'hard'] self.difficultySelected = self.data.getParameter('difficulty') self.musicValue = self.data.getParameter('music') self.sfxValue = self.data.getParameter('sfx') self.buttons = [] self.menuButtons = [] self.bigButtons = [] self.sliders = [] self.texts = {} self.images = [] self.logo = pygame.image.load('../Assets/menuAssets/logo.png') self.logoPos = [5, 0] self.animBool = True # self.sfxValue = self.data.getParameter('sfx') # self.musicValue = self.data.getParameter('music') self.loadImages() self.mainMenu() self.game = game(self) self.textGui = textGui() self.menuPage = { 'new': False, 'load': False, 'options': False, 'credits': False, 'quit': False } self.screen = pygame.display.set_mode((720, 480)) self.backgroundMenu = False self.sound = Sound() self.sound.playMusic(0, 2)
def test_OP_Fx1E(self): # ADD I, Vx: Set I = I + Vx path = os.path.join(os.getcwd(), "test_roms", "ADD_I_Vx.ch8") interpreter = Interpreter(path, False) interpreter.index_register = 2 interpreter.registers[1] = 3 interpreter.tick() self.assertEqual(interpreter.index_register, 5)
def test_OP_Cxkk(self): # RND Vx, byte: Set Vx = random byte AND kk patch('Interpreter.getrandbits', lambda _: 0b10101010).start() path = os.path.join(os.getcwd(), "test_roms", "RND_Vx_byte.ch8") interpreter = Interpreter(path, False) interpreter.tick() self.assertEqual(interpreter.registers[1], 0b10101010 & 0b1100) patch.stopall()
def processFile(self): interpreter = Interpreter() # return all the documents present in the file output = self.path + '.bin' if isfile(output): print('loading tokens') self.index = pickle.load(open(output, 'rb')) self.indexer = Indexer(self.tokenizer, index=self.index) else: self.indexer = Indexer(self.tokenizer) file = open(self.path, 'r', encoding='utf-8', errors='ignore') maximum = os.stat(self.path).st_size # initialize the variables i = 0 progress = 0 document = [] for line in file: progress += len(line) if line == '\n': interpreter.process(self.indexer, document) document = [] else: document += [line] i += 1 if i >= 5000: i = 0 log(progress, maximum) file.close() self.index = self.indexer.index print('\nsaving tokens') pickle.dump(self.index, open(output, 'wb'))
def run_ide(): print(": Welcome to Dymond V0.0.0!") print( ": Play around a little in this nice IDE type simple statements in and we will process them :)" ) print(": Type exit() to exit") user_in = "" total_user_in = "" while user_in != "exit()": user_in = input(">>> ") if (user_in == "exit()"): break try: test = total_user_in + user_in lexer = Lexer(test) se_parser = Parser(lexer, "ide") semantic_analyzer = SemanticAnalyzer(se_parser) semantic_analyzer.analyze() lexer = Lexer(test) in_parser = Parser(lexer, "ide") semantic_analyzer.current_scope.reset_multi_scope_vars() interpreter = Interpreter(in_parser, semantic_analyzer.current_scope) interpreter.interpret() if "print(" not in user_in and "input(" not in user_in: total_user_in += "\n" + user_in except Exception as ex: print(ex)
def test_OP_00E0(self): # CLS: Clear the Display path = os.path.join(os.getcwd(), "test_roms", "clear_display.ch8") interpreter = Interpreter(path, False) interpreter.display = [1] * len(interpreter.display) interpreter.tick() self.assertTrue( not any(interpreter.display), F"Expected cleared display. Got {interpreter.display}")
def test_OP_8xy7( self): # SUBN Vx, Vy: Set Vx = Vy - Vx, set VF = NOT borrow path = os.path.join(os.getcwd(), "test_roms", "SHR_VX.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 0b101 interpreter.tick() self.assertEqual(interpreter.registers[1], 0b10) # Should wrap self.assertEqual(interpreter.registers[0xF], 1)
def test_OP_8xy4(self): # ADD Vx, Vy: Set Vx = Vx + Vy, set VF = carry path = os.path.join(os.getcwd(), "test_roms", "ADD_Vx_Vy.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 255 interpreter.registers[2] = 3 interpreter.tick() self.assertEqual(interpreter.registers[1], 2) # Should wrap self.assertEqual(interpreter.registers[0xF], 1)
def __init__(self, tape, ops, nodes=5): from copy import copy self.__tape = tape self.__ops = ops self.__factories = [] self.__nodes = [] for i in range(nodes - 1): ops = copy(self.__ops) self.__factories.append(FeedbackOutputFactory()) ops[4] = self.__factories[-1].construct self.__nodes.append(Interpreter(copy(self.__tape), copy(ops), [])) ops = copy(self.__ops) self.__factories.append(FeedbackOutputFactory(FeedbackAndFork)) ops[4] = self.__factories[-1].construct self.__nodes.append(Interpreter(copy(self.__tape), copy(ops), [])) for i, f in enumerate(self.__factories): f.set_outerpreter(self.__nodes[(i + 1) % len(self.__nodes)])
def __init__(self): self.hadError = False self.tokens = [] # saved tokens from previous uncompleted lines self.interp = Interpreter( ) # for retain inner statements when runPrompt() self.resolver = Resolver() self.compiler = Compiler() self.vm = StackVM()
def main(): with open("source.dd") as f: code = ''.join(f.readlines()) #print(code) lexer = Lexer(code) parser = Parser(lexer) interpreter = Interpreter(parser) result = interpreter.interpret()
def test_OP_Fx33( self ): # LD B, Vx: Store BCD representation of Vx in memory locations I, I+1, and I+2 path = os.path.join(os.getcwd(), "test_roms", "LD_B_Vx.ch8") interpreter = Interpreter(path, False) interpreter.registers[0xA] = 123 interpreter.index_register = 0x300 interpreter.tick() self.assertEqual(interpreter.memory[0x300:0x303], [1, 2, 3])
def main(): if len(sys.argv) == 2: text = open(sys.argv[1], 'r').read() else: text = open('test.txt', 'r').read() if text: lexer = Lexer(text) parser = Parser(lexer) interpreter = Interpreter(parser)
def test_OP_8xy5( self): # SUB Vx, Vy: Set Vx = Vx - Vy, set VF = NOT borrow path = os.path.join(os.getcwd(), "test_roms", "SUB_Vx_Vy.ch8") interpreter = Interpreter(path, False) interpreter.registers[1] = 3 interpreter.registers[2] = 5 interpreter.tick() self.assertEqual(interpreter.registers[1], 254) # Should wrap self.assertEqual(interpreter.registers[0xF], 0)
def __init__(self, master=None): super().__init__(master) self.master = master self.master.minsize(600, 400) self.master.title("Brainfuck interpreter by Cezary Kania v 0.1") self.interpreter = Interpreter(self) self.init_menu() self.init_body() self.pack()
def find_accumulator_before_loop(instructions): interpreter = Interpreter() outputs = set() accumulator = 0 for output in interpreter.launch_process(instructions): if output[1] in outputs: return accumulator outputs.add(output[1]) accumulator = output[0]
def test_OP_Fx29( self): # LD F, Vx: Set I = location of sprite for digit Vx path = os.path.join(os.getcwd(), "test_roms", "LD_F_Vx.ch8") BYTES_PER_DIGIT = 5 interpreter = Interpreter(path, False) interpreter.registers[1] = 3 interpreter.tick() self.assertEqual( interpreter.index_register, interpreter.FONT_SET_START_ADDRESS + (interpreter.registers[1] * BYTES_PER_DIGIT))
def test_OP_00EE(self): # RET: Return from a subroutine path = os.path.join(os.getcwd(), "test_roms", "return_from_subroutine.ch8") interpreter = Interpreter(path, False) interpreter.stack = [0x300] + [0x200] * 15 interpreter.stack_pointer = 1 interpreter.tick() correct = [0x300, 0x202] + [0x200] * 14 self.assertEqual(interpreter.stack, correct) self.assertEqual(interpreter.stack_pointer, 0)
def runSmurf(program): parser = ParserPEG(grammar, "program", "comment", debug=False) parse_tree = parser.parse(program) ast = visit_parse_tree(parse_tree, NodeVisitor(debug=False)) ast.accept(Interpreter()) # runSmurf(""" # let a = 5, b = 4 print(a+b) # """)