How to use fetch_state method in localstack

Best Python code snippet using localstack_python

instructions.py

Source:instructions.py Github

copy

Full Screen

1from bitarray import bitarray2from ._instruction import Instruction3from .microcode import Microcode, NO_OP4from sap1.types import Bit, Pointer, nibble, HIGH, LOW5from .validators import validate_ptr6FETCH_STATE = [7 Microcode(MI=HIGH, OC=HIGH),8 Microcode(CE=HIGH),9 Microcode(RO=HIGH, II=HIGH),10]11@validate_ptr12def lda(ptr: Pointer) -> Instruction:13 """14 load the accumulator (A register) with value at *ptr15 Args:16 ptr(bitarray): pointer to memory location to load into memory17 ptr(int): integer representation of pointer18 Returns:19 (Instruction) object20 """21 opcode = bitarray('0000')22 states = [23 *FETCH_STATE, # unpack the fetch state24 Microcode(MI=HIGH, IO=HIGH), # load operand into MAR from IR25 Microcode(RO=HIGH, AI=HIGH), # load *operand from RAM into Register A26 NO_OP # t=6, no operation27 ]28 return Instruction(mnemonic="LDA", opcode=opcode, states=states, operand=ptr)29# noinspection PyUnusedLocal30def hlt(**kwargs) -> Instruction:31 """32 Halt instruction33 Returns:34 (Instruction) halt object35 """36 opcode = bitarray('1111')37 states = [38 *FETCH_STATE, # unpack the fetch state39 Microcode(HLT=HIGH), # t=3, set halt high40 NO_OP, # t=5, no operation41 NO_OP # t=6, no operation42 ]43 return Instruction(mnemonic="HLT", opcode=opcode, states=states)44@validate_ptr45def add(ptr: Pointer, subtract: Bit = LOW) -> Instruction:46 """47 add the value *ptr and store the result in register A48 Args:49 subtract (Bit): subtract flag (used by the :meth:`sub` method)50 ptr(bitarray): pointer to memory location to load into memory51 ptr(int): integer representation of pointer52 Returns:53 (Instruction) object54 """55 opcode = bitarray('0001')56 states = [57 *FETCH_STATE, # unpack the fetch state58 # load operand into MAR59 Microcode(MI=HIGH, IO=HIGH),60 # load *operand from RAM into Register B. set subtract flag61 Microcode(RO=HIGH, BI=HIGH, SUB=subtract),62 # push ALU result into register A63 Microcode(AI=HIGH, EO=HIGH, SUB=subtract)64 ]65 return Instruction(mnemonic="ADD", opcode=opcode, states=states, operand=ptr)66@validate_ptr67def sub(ptr: Pointer) -> Instruction:68 """69 Subtract operation.70 a-=(*ptr)71 Args:72 ptr ():73 Returns:74 (Instruction) subtract instruction75 """76 instruction = add(ptr=ptr, subtract=HIGH)77 instruction.mnemonic = "SUB"78 instruction.opcode = nibble(0b0010)79 return instruction80@validate_ptr81def jmp(ptr: Pointer) -> Instruction:82 """83 Jump to ptr84 Args:85 ptr ():86 Returns:87 """88 opcode = bitarray('0101')89 states = [90 *FETCH_STATE, # unpack the fetch state91 # Push operand from IR to PC via JMP flag92 Microcode(IO=HIGH, JMP=HIGH),93 # no op94 NO_OP,95 # no op96 NO_OP97 ]98 return Instruction(mnemonic="JMP", opcode=opcode, states=states, operand=ptr)99def out(ptr: Pointer) -> Instruction:100 """101 OUT instruction. pushes the A register to the output register102 Args:103 ptr(Pointer): unused.104 Returns:105 Instruction: instance of OUT instruction106 """107 opcode = bitarray('1110')108 states = [109 *FETCH_STATE, # unpack the fetch state110 # push A register to bus, enable output register update111 Microcode(AO=HIGH, OI=HIGH),112 # no op113 NO_OP,114 # no op115 NO_OP116 ]...

Full Screen

Full Screen

codebook.py

Source:codebook.py Github

copy

Full Screen

1ONE_GUN = 02TWO_GUN = 13class CodeBook(object):4 # code book for generating move command5 def __init__(self, mode=TWO_GUN):6 self.moves = ['fetch_0', 'fetch_1', 'shoot_0', 'shoot_1']7 self.fetch_states = ['START', 'left', 'right', 'both', 'END']8 self.shoot_states = ['START', 'left', 'right', 'both', 'END']9 self.fetch_inputs = ['fetch_0', 'fetch_1']10 self.shoot_inputs = ['shoot_0', 'shoot_1']11 12 self.fetch_trans = {"fetch_0": {"START": "left", "left": "right", "right": "left"},13 "fetch_1": {"left": "both", "right": "both", "both": "both"}}14 self.shoot_trans = {"shoot_0": {"START": "left", "left": "right", "right": "left"},15 "shoot_1": {"left": "both", "right": "both", "both": "both"}}16 self.fetch_state = "START"17 self.shoot_state = "START"18 if mode == TWO_GUN:19 self.fetch_dict = {"left": {"button_0": 1.0, "button_1": 0.0},20 "right": {"button_0": 0.0, "button_1": 1.0},21 "both": {"button_0": 1.0, "button_1": 1.0}}22 self.shoot_dict = {"left": {"button_0": 1.0, "button_1": 0.0},23 "right": {"button_0": 0.0, "button_1": 1.0},24 "both": {"button_0": 1.0, "button_1": 1.0}}25 else:26 self.fetch_dict = {"left": {"button_0": 1.0, "button_1": 0.0},27 "right": {"button_0": 0.0, "button_1": 1.0},28 "both": {"button_0": 1.0, "button_1": 1.0}}29 self.shoot_dict = {"left": {"button_0": 1.0, "button_1": 0.0},30 "right": {"button_0": 0.0, "button_1": 1.0},31 "both": {"button_0": 1.0, "button_1": 1.0}}32 33 def lookup(self, input):34 if input in self.fetch_inputs:35 self.fetch_state = self.fetch_trans[input][self.fetch_state]36 if self.fetch_state == "START":37 button_1 = button_0 = 0.038 else:39 button_0 = self.fetch_dict[self.fetch_state]["button_0"]40 button_1 = self.fetch_dict[self.fetch_state]["button_1"]41 return button_0, button_142 if input in self.shoot_inputs:43 #self.shoot_state = self.shoot_trans[input][self.shoot_state]44 self.shoot_state = self.fetch_state45 if self.shoot_state == "START":46 button_1 = button_0 = 0.047 else:48 button_0 = self.shoot_dict[self.shoot_state]["button_0"]49 button_1 = self.shoot_dict[self.shoot_state]["button_1"]50 return button_0, button_151 52TEST = False53if TEST:54 c = CodeBook()55 print c.lookup('fetch_0'), c.fetch_state56 print c.lookup('fetch_0'), c.fetch_state57 print c.lookup('shoot_0'), c.shoot_state58 print c.lookup('fetch_0'), c.fetch_state59 print c.lookup('shoot_0'), c.shoot_state60 print c.lookup('fetch_0'), c.fetch_state61 print c.lookup('fetch_0'), c.fetch_state62 print c.lookup('shoot_0'), c.shoot_state63 print c.lookup('fetch_0'), c.fetch_state64 print c.lookup('shoot_0'), c.shoot_state65 print c.lookup('fetch_1'), c.fetch_state66 print c.lookup('shoot_1'), c.shoot_state67 print c.lookup('fetch_1'), c.fetch_state68 print c.lookup('shoot_1'), c.shoot_state69 print c.lookup('fetch_1'), c.fetch_state...

Full Screen

Full Screen

inst_fetch.py

Source:inst_fetch.py Github

copy

Full Screen

1# _*_ coding: utf-8 _*_2"""3inst_fetch.py by xianhu4"""5import time6class Fetcher(object):7 """8 class of Fetcher, must include function working()9 """10 def __init__(self, sleep_time=0, max_repeat=3):11 """12 constructor13 :param sleep_time: default 0, sleeping time before fetching14 :param max_repeat: default 3, maximum repeat count of fetching15 """16 self._sleep_time = sleep_time17 self._max_repeat = max_repeat18 return19 def working(self, priority: int, url: str, keys: dict, deep: int, repeat: int, proxies=None) -> (int, object, int):20 """21 working function, must "try-except" and don't change the parameters and returns22 :return fetch_state: can be -1(fetch failed), 0(need repeat), 1(fetch success)23 :return content: which waits to be parsed, can be any object, or exception[class_name, excep]24 :return proxies_state: can be -1(unavaiable), 0(return to queue), 1(avaiable)25 """26 time.sleep(self._sleep_time)27 try:28 fetch_state, content, proxies_state = self.url_fetch(priority, url, keys, deep, repeat, proxies=proxies)29 except Exception as excep:30 fetch_state, content, proxies_state = (-1 if repeat >= self._max_repeat else 0), [self.__class__.__name__, excep], -131 return fetch_state, content, proxies_state32 def url_fetch(self, priority: int, url: str, keys: dict, deep: int, repeat: int, proxies=None) -> (int, object, int):33 """34 fetch the content of a url. You must overwrite this function, parameters and returns refer to self.working()35 """...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful