(self, iargs)
Evaluate user-defined function.
Evaluate user-defined function.
Evaluate user - defined function .
def evaluate(self, iargs):
        """Evaluate user-defined function."""
        # parse/evaluate arguments
        conversions = (values.TYPE_TO_CONV[self._memory.complete_name(name)[-1:]] for name in self._varnames)
        args = [conv(arg) for arg, conv in zip(iargs, conversions)]
        # recursion is not allowed as there's no way to terminate it
        if self._is_parsing:
            raise error.BASICError(error.OUT_OF_MEMORY)
        # parse/evaluate function expression
        # save existing vars
        varsave = {}
        varnames = [self._memory.complete_name(_v) for _v in self._varnames]
        for name in varnames:
            # set to 0 if they don't yet exist
            if name not in self._memory.scalars:
                self._memory.scalars.set(name)
            # copy the buffer
            varsave[name] = self._memory.scalars.view(name).clone()
        # set variables
        for name, value in zip(varnames, args):
            # append sigil, if missing
            name = self._memory.complete_name(name)
            self._memory.scalars.set(name, value)
        # set recursion flag
        self._is_parsing = True
        save_loc = self._codestream.tell()
        try:
            self._codestream.seek(self._start_loc)
            value = self._expression_parser.parse(self._codestream)
            return values.to_type(self._sigil, value)
        finally:
            self._codestream.seek(save_loc)
            # unset recursion flag
            self._is_parsing = False
            # restore existing vars, remove ones added
            for name in varsave:
                # re-assign the stored value
                self._memory.scalars.view(name).copy_from(varsave[name])
def evaluate ( self , iargs ) : # parse/evaluate arguments conversions = ( values . TYPE_TO_CONV [ self . _memory . complete_name ( name ) [ - 1 : ] ] for name in self . _varnames ) args = [ conv ( arg ) for arg , conv in zip ( iargs , conversions ) ] # recursion is not allowed as there's no way to terminate it if self . _is_parsing : raise error . BASICError ( error . OUT_OF_MEMORY ) # parse/evaluate function expression # save existing vars varsave = { } varnames = [ self . _memory . complete_name ( _v ) for _v in self . _varnames ] for name in varnames : # set to 0 if they don't yet exist if name not in self . _memory . scalars : self . _memory . scalars . set ( name ) # copy the buffer varsave [ name ] = self . _memory . scalars . view ( name ) . clone ( ) # set variables for name , value in zip ( varnames , args ) : # append sigil, if missing name = self . _memory . complete_name ( name ) self . _memory . scalars . set ( name , value ) # set recursion flag self . _is_parsing = True save_loc = self . _codestream . tell ( ) try : self . _codestream . seek ( self . _start_loc ) value = self . _expression_parser . parse ( self . _codestream ) return values . to_type ( self . _sigil , value ) finally : self . _codestream . seek ( save_loc ) # unset recursion flag self . _is_parsing = False # restore existing vars, remove ones added for name in varsave : # re-assign the stored value self . _memory . scalars . view ( name ) . copy_from ( varsave [ name ] )