def exp(self, op, quad): '''Evaluates expression using ops table''' mode_params = utils.mode_params op1 = memory.get(quad[2], mode_params) if (quad[3]): # If operation is binary op2 = memory.get(quad[3], mode_params) value = ops[op](op1, op2) else: # If operation is unary value = ops[op](op1) memory.set(quad[4], value, mode_params)
def ver(self, quad): '''Verifies if index is inbounds''' func = utils.func_stack[len(utils.func_stack) - 1] var_name = quad[4] + '-' + str(memory.get(quad[2])) if (var_name not in memory.func_dir[func]['vars'] and var_name not in memory.func_dir['global']['vars']): err('Out of bounds!', var_name)
def test_get_use_non_existent_var_exp_none(self): self.assertIsNotNone(not memory.get("not_existent_var"))
def test_get_use_server_config_exp_success(self): self.assertIsNotNone(memory.get("server_config"))
def addLiteral(key, port, val): inst = memory.get(key) inst.addLiteral(port, val)
def addDestination(srcKey, srcPort, dstKey, dstPort): inst = memory.get(srcKey) inst.addDestination(srcPort, dstKey, dstPort)
def param(self, quad): '''Set param to function''' val = memory.get(quad[2], True) memory.set(quad[4], val)
def gotof(self, quad): '''Evalates an expression to see if it is false it makes a jump''' value = memory.get(quad[2]) if (not value): self.pos = quad[4] - 2
def equal(self, quad): '''Assigns value of an expression to a variable''' value = memory.get(quad[2]) memory.set(quad[4], value)
def eprint(self, quad): '''Prints to terminal and IDE output''' value = str(memory.get(quad[4])).upper() for char in value: if char in emoji_letters: self.output.write(emoji_letters[char] + '\n')
def print(self, quad): '''Prints to terminal and IDE output''' value = memory.get(quad[4]) self.output.write(str(value) + '\n') print(value)
def ret(self, quad): '''Sets the return value to the global variable that stores returns''' func = utils.func_stack[len(utils.func_stack) - 1] val = memory.get(quad[2]) memory.set(quad[4], val) self.pos = memory.func_dir[func]['end'] - 2