(self, name, value=None)
Assign a value to a variable.
Assign a value to a variable.
Assign a value to a variable .
def set(self, name, value=None):
        """Assign a value to a variable."""
        if isinstance(value, values.String):
            self._memory.strings.fix_temporaries()
        type_char = name[-1:]
        if value is not None:
            value = values.to_type(type_char, value)
        # update memory model
        # check if garbage needs collecting before allocating memory
        if name not in self._var_memory:
            # don't add string length, string already stored
            size = self.memory_size(name)
            self._memory.check_free(size, error.OUT_OF_MEMORY)
            # first two bytes: chars of name or 0 if name is one byte long
            name_ptr = self._memory.var_current()
            # byte_size first_letter second_letter_or_nul remaining_length_or_nul
            var_ptr = name_ptr + self._record_size(name)
            self.current += size
            self._var_memory[name] = (name_ptr, var_ptr)
        # don't change the value if just checking allocation
        if value is None:
            if name in self._vars:
                return
            else:
                value = self._values.new(type_char)
        # copy buffers
        try:
            # in-place copy is crucial for FOR
            self._vars[name][:] = value.to_bytes()[:]
        except KeyError:
            # copy into new buffer if not existing
            self._vars[name] = value.to_bytes()[:]
def set ( self , name , value = None ) : if isinstance ( value , values . String ) : self . _memory . strings . fix_temporaries ( ) type_char = name [ - 1 : ] if value is not None : value = values . to_type ( type_char , value ) # update memory model # check if garbage needs collecting before allocating memory if name not in self . _var_memory : # don't add string length, string already stored size = self . memory_size ( name ) self . _memory . check_free ( size , error . OUT_OF_MEMORY ) # first two bytes: chars of name or 0 if name is one byte long name_ptr = self . _memory . var_current ( ) # byte_size first_letter second_letter_or_nul remaining_length_or_nul var_ptr = name_ptr + self . _record_size ( name ) self . current += size self . _var_memory [ name ] = ( name_ptr , var_ptr ) # don't change the value if just checking allocation if value is None : if name in self . _vars : return else : value = self . _values . new ( type_char ) # copy buffers try : # in-place copy is crucial for FOR self . _vars [ name ] [ : ] = value . to_bytes ( ) [ : ] except KeyError : # copy into new buffer if not existing self . _vars [ name ] = value . to_bytes ( ) [ : ]