def _get_integer_values(self, operator1, operator2): val1 = '' type1 = '' isvalue = utilities.isbinarystring(operator1) if isvalue: val1 = operator1 else: type1, mem_address = self._fetch(operator1) if type1 == False: return val1 = self._value_of(mem_address) val2 = '' type2 = '' isvalue = utilities.isbinarystring(operator2) if isvalue: val2 = operator2 else: type2, mem_address = self._fetch(operator2) if type2 == False: return val2 = self._value_of(mem_address) val1 = val1.zfill(WORD_SIZE) val2 = val2.zfill(WORD_SIZE) val1 = Integer(val1).convert() val2 = Integer(val2).convert() return val1, val2
def _get_integer_values(self, operator1, operator2): val1 = '' type1 = '' isvalue = utilities.isbinarystring(operator1) if isvalue: val1 = operator1 else: type1, mem_address = self._fetch(operator1) if type1 == False: return val1 = self._value_of(mem_address) val2 = '' type2 = '' isvalue = utilities.isbinarystring(operator2) if isvalue: val2 = operator2 else: type2, mem_address = self._fetch(operator2) if type2 == False: return val2 = self._value_of(mem_address) val1 = val1.zfill(WORD_SIZE) val2 = val2.zfill(WORD_SIZE) val1 = Integer(val1).convert() val2 = Integer(val2).convert() return val1, val2
def _mov(self, variable, operator): isvalue = utilities.isbinarystring(operator) _, mem_address1 = self._fetch(variable) if _ == False: return value = None if isvalue: value = operator else: _, mem_address2 = self._fetch(operator) if _ == False: return value = self._value_of(mem_address2) value = '1' + value.zfill(WORD_SIZE) self._set_value(mem_address1, value)
def _mov(self, variable, operator): isvalue = utilities.isbinarystring(operator) _, mem_address1 = self._fetch(variable) if _ == False: return value = None if isvalue: value = operator else: _, mem_address2 = self._fetch(operator) if _ == False: return value = self._value_of(mem_address2) value = '1' + value.zfill(WORD_SIZE) self._set_value(mem_address1, value)
def _push(self, argument): '''Implements the logic for communicating between the debugger and the vm, for the purpose of pushin some value or a variable's value to the vm arguments stack''' isvalue = utilities.isbinarystring(argument) if isvalue: print 'Trying to push a value' return else: type_name, address = self._fetch(argument) if type_name == False: return value = self.memory[int(address, 0)] self.args.push((type_name, address)) return True
def _get_binary_pair(self, variable, operator): isvalue = utilities.isbinarystring(operator) _, mem_address1 = self._fetch(variable) if _ == False: return val1 = self._value_of(mem_address1) val2 = '' if isvalue: val2 = operator else: _, mem_address2 = self._fetch(operator) if _ == False: return val2 = self._value_of(mem_address2) val1 = val1.zfill(WORD_SIZE) val2 = val2.zfill(WORD_SIZE) return val1, val2, mem_address1
def _push(self, argument): '''Implements the logic for communicating between the debugger and the vm, for the purpose of pushin some value or a variable's value to the vm arguments stack''' isvalue = utilities.isbinarystring(argument) if isvalue: print 'Trying to push a value' return else: type_name, address = self._fetch(argument) if type_name == False: return value = self.memory[int(address, 0)] self.args.push((type_name, address)) return True
def _get_binary_pair(self, variable, operator): isvalue = utilities.isbinarystring(operator) _, mem_address1 = self._fetch(variable) if _ == False: return val1 = self._value_of(mem_address1) val2 = '' if isvalue: val2 = operator else: _, mem_address2 = self._fetch(operator) if _ == False: return val2 = self._value_of(mem_address2) val1 = val1.zfill(WORD_SIZE) val2 = val2.zfill(WORD_SIZE) return val1, val2, mem_address1
def _print(self, variable): '''Implements the logic for communicating between the debugger and the vm, for the purpose of printing the current value of some variable allocated in the vm's memory''' isvalue = utilities.isbinarystring(variable) if isvalue: msg = Integer(variable).convert() elif variable[0] == variable[-1] == '"': msg = variable[1:-1] msg = msg.replace('_', ' ') else: type_name, mem_address = self._fetch(variable) if type_name == False: return value = self._value_of(mem_address) msg = fetch_atomic_value(type_name, value) sys.stdout.write(str(msg))
def _print(self, variable): '''Implements the logic for communicating between the debugger and the vm, for the purpose of printing the current value of some variable allocated in the vm's memory''' isvalue = utilities.isbinarystring(variable) if isvalue: msg = Integer(variable).convert() elif variable[0] == variable[-1] == '"': msg = variable[1:-1] msg = msg.replace('_', ' ') else: type_name, mem_address = self._fetch(variable) if type_name == False: return value = self._value_of(mem_address) msg = fetch_atomic_value(type_name, value) sys.stdout.write(str(msg))
def _fetch(self, variable): '''Returns the type and arress of the variable given by parameter, if variable points to a not-structured data, it returns the address that stores the value pointed by variable. If it's a 1-dimensional array, it treats variable as var_name[num] and returns the address of var_name[num]. If it's a 2-dimensinonal array, the function treats variable as var_name[i][j], and returns the address of it. Address conversion is independent from this function, it uses self._index() instead. If the given parameter is not a variable but a value, it returns \'NULL\'''' atomic_type, address = '', '' isarray, dimension = utilities.isarrayvariable(variable) if isarray: min_bound = variable.index('[') max_bound = variable.index(']') var_name = variable[:min_bound] try: atomic_type, _ = self.amv[var_name] atomic_type = atomic_type[:atomic_type.index('#')] except: # No existe ese arreglo print 'ERROR: VAR002_ERROR', var_name if QUITTER: quit() else: return False, False if dimension == 1: index = variable[min_bound + 1:max_bound] address = self._index(var_name, index) elif dimension == 2: rows = variable[min_bound + 1:max_bound] scnd_index = variable[max_bound + 1:] min_bound = scnd_index.index('[') max_bound = scnd_index.index(']') cols = scnd_index[min_bound + 1:max_bound] address = self._index(var_name, rows, cols) else: isvalue = utilities.isbinarystring(variable) if isvalue: atomic_type = 'NULL' address = 'NULL' else: try: atomic_type, address = self.amv[variable] except: # No existe la variable print 'ERROR: VAR001_ERROR', variable if QUITTER: quit() else: return False, False return atomic_type, address
def _fetch(self, variable): '''Returns the type and arress of the variable given by parameter, if variable points to a not-structured data, it returns the address that stores the value pointed by variable. If it's a 1-dimensional array, it treats variable as var_name[num] and returns the address of var_name[num]. If it's a 2-dimensinonal array, the function treats variable as var_name[i][j], and returns the address of it. Address conversion is independent from this function, it uses self._index() instead. If the given parameter is not a variable but a value, it returns \'NULL\'''' atomic_type, address = '', '' isarray, dimension = utilities.isarrayvariable(variable) if isarray: min_bound = variable.index('[') max_bound = variable.index(']') var_name = variable[:min_bound] try: atomic_type, _ = self.amv[var_name] atomic_type = atomic_type[:atomic_type.index('#')] except: # No existe ese arreglo print 'ERROR: VAR002_ERROR', var_name if QUITTER: quit() else: return False, False if dimension == 1: index = variable[min_bound + 1 : max_bound] address = self._index(var_name, index) elif dimension == 2: rows = variable[min_bound + 1 : max_bound] scnd_index = variable[max_bound + 1:] min_bound = scnd_index.index('[') max_bound = scnd_index.index(']') cols = scnd_index[min_bound + 1 : max_bound] address = self._index(var_name, rows, cols) else: isvalue = utilities.isbinarystring(variable) if isvalue: atomic_type = 'NULL' address = 'NULL' else: try: atomic_type, address = self.amv[variable] except: # No existe la variable print 'ERROR: VAR001_ERROR', variable if QUITTER: quit() else: return False, False return atomic_type, address