Esempio n. 1
0
    def run(self):
        from visualize.plot import resetFlagInStack
        from itertools import zip_longest
        from utils.executor import evaluate
        from utils.recursive import recursive

        glb.variable_stack.append(self)
        resetFlagInStack()

        for condition, content in zip_longest(self.conditionList,
                                              self.contentList):
            # print("\tcompile if else condition: {}".format(condition))

            self._judge = evaluate(condition)

            #TODO add return value of the condition to stack

            if self._judge:
                self.line = glb.current_line + 1

                recursive(content, 0, self)
                break
            #update glb.current_line, jump to next if else condition
            else:
                glb.current_line += len(content) + 1

        self._end_module()
    def run(self):
        from visualize.plot import resetFlagInStack
        from itertools import zip_longest
        from utils.executor import evaluate
        from utils.recursive import recursive

        glb.variable_stack.append(self)
        resetFlagInStack()

        for condition, content in zip_longest(self.conditionList, self.contentList):
            # print("\tcompile if else condition: {}".format(condition))

            self._judge = evaluate(condition)

            #TODO add return value of the condition to stack

            if self._judge:
                self.line = glb.current_line + 1

                recursive(content, 0, self)
                break
            #update glb.current_line, jump to next if else condition
            else:
                glb.current_line += len(content) + 1

        self._end_module()
    def run(self):
        from visualize.plot import resetFlagInStack
        from utils.recursive import recursive
        from utils.executor import containVariableInGlbStack, getVariableFromGlbStack, evaluate

        glb.variable_stack.append(self)
        resetFlagInStack()

        # judge the condition
        self._judge = evaluate(self.condition)

        # TODO: we may also print out the condition result

        # navigates to the next line -- start of the content
        self.line = glb.current_line + 1

        while self._judge:
            # check end_recursive flag
            if self.end_recursive:
                break

            recursive(self.content, 0, self)

            # clear flags after one loop
            resetFlagInStack()

            # re-evaluate the judge condition
            self._judge = evaluate(self.condition)

            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()

        self._end_module()
Esempio n. 4
0
    def run(self):
        from visualize.plot import resetFlagInStack
        from utils.recursive import recursive
        from utils.executor import containVariableInGlbStack, getVariableFromGlbStack, evaluate

        glb.variable_stack.append(self)
        resetFlagInStack()

        #judge the condition
        self._judge = evaluate(self.condition)

        #TODO: we may also print out the condition result

        #navigates to the next line -- start of the content
        self.line = glb.current_line + 1

        while self._judge:
            #check end_recursive flag
            if self.end_recursive:
                break

            recursive(self.content, 0, self)

            #clear flags after one loop
            resetFlagInStack()

            #re-evaluate the judge condition
            self._judge = evaluate(self.condition)

            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()

        self._end_module()
Esempio n. 5
0
    def _end_module(self):
        '''
        Tear up. Remove the variables inside this module
        '''
        from visualize.plot import resetFlagInStack
        resetFlagInStack()

        item = glb.variable_stack.pop()
        while not isinstance(item, basemodule) and len(glb.variable_stack) > 0:
            item = glb.variable_stack.pop()
Esempio n. 6
0
    def run(self):
        import utils.recursive as recursive
        from visualize.plot import resetFlagInStack

        glb.variable_stack.append(self)
        resetFlagInStack()

        recursive.recursive(self.content, 0, self)

        self._end_module()
Esempio n. 7
0
    def _end_module(self):
        '''
        Tear up. Remove the variables inside this module
        '''
        from visualize.plot import resetFlagInStack
        resetFlagInStack()

        item = glb.variable_stack.pop()
        while not isinstance(item, basemodule) and len(glb.variable_stack) > 0:
            item = glb.variable_stack.pop()
Esempio n. 8
0
    def run(self):
        import utils.recursive as recursive
        from visualize.plot import resetFlagInStack

        glb.variable_stack.append(self)
        resetFlagInStack()

        recursive.recursive(self.content, 0, self)

        self._end_module()
Esempio n. 9
0
    def run(self):
        from visualize.plot import resetFlagInStack
        from utils.recursive import recursive
        from utils.executor import containVariableInGlbStack, getVariableFromGlbStack

        glb.variable_stack.append(self)
        resetFlagInStack()

        #insert iterate variable inside global variable stack
        iterVarObj = variable(self.iter_var, None)
        glb.variable_stack.append([self.iter_var, iterVarObj])
        setPointer = False #whether we should treat iter_var as a pointer

        var_being_iter = getVariableFromGlbStack(self.range_var_name)

        if self.range_var_name and containVariableInGlbStack(self.range_var_name):# for x in range_var_name
            setPointer = True

        #navigates to the next line -- start of the content
        self.line = glb.current_line + 1

        #start the loop
        for index, value in enumerate(self.loop_range):
            #check end_recursive flag
            if self.end_recursive:
                break

            iterVarObj.var_obj = value
            iterVarObj.var_flag = glb.flag_dict['changed']

            if setPointer:
                iterVarObj.pointerIndexList = [index]
                iterVarObj.pointer = getVariableFromGlbStack(self.range_var_name).var_name

            if var_being_iter:
                #update index of this variable
                var_being_iter.indexList = [index]

            # printVar() #do not need to specially call printVar for iter_var
            recursive(self.content, 0, self)

            #clear flags after one loop
            resetFlagInStack()

            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()

        self._end_module()
    def __call__(self, *args, **kwargs):
        from visualize.plot import resetFlagInStack
        from utils.variable import variable
        from utils.executor import isPrimitiveType, getMatchingObject
        from utils.recursive import recursive

        #increase function call depth by one
        glb.funcall_depth += 1

        glb.variable_stack.append(self)
        resetFlagInStack()

        try:
            if len(args) + len(kwargs) != len(self.param_list):
                raise TypeError('{} positional arguments but {} given'.format(
                    len(self.param_list),
                    len(args) + len(kwargs)))
            else:
                from itertools import zip_longest

                #combine args with values of kwargs
                args = list(args) + list(kwargs.values())

                for param, arg in zip_longest(self.param_list, args):
                    #insert parameters into global variable stack and store pointer.
                    #TODO:currently we only deal with single variable pointer. In other words, paramaters like x[1] are not handled.
                    paramVarObj = variable(param, arg)

                    #check whether variables are primitive type
                    if not isPrimitiveType(arg):
                        findObj = getMatchingObject(arg)
                        paramVarObj.pointer = findObj.var_name

                    glb.variable_stack.append([param, paramVarObj])

                #printVar()

                recursive(self.content, 0, self)

                #return function return value
                return self.return_list
        except Exception as e:
            raise Exception(
                "Exception: \"{}\"  occurred during execution of function {}".
                format(e, self.func_name))
        finally:
            self._end_module()
            glb.funcall_depth -= 1
    def __call__(self, *args, **kwargs):
        from visualize.plot import resetFlagInStack
        from utils.variable import variable
        from utils.executor import isPrimitiveType, getMatchingObject
        from utils.recursive import recursive

        #increase function call depth by one
        glb.funcall_depth += 1

        glb.variable_stack.append(self)
        resetFlagInStack()

        try:
            if len(args) + len(kwargs) != len(self.param_list):
                raise TypeError('{} positional arguments but {} given'
                                .format(len(self.param_list), len(args)+len(kwargs)))
            else:
                from itertools import zip_longest

                #combine args with values of kwargs
                args = list(args) + list(kwargs.values())

                for param, arg in zip_longest(self.param_list, args):
                    #insert parameters into global variable stack and store pointer.
                    #TODO:currently we only deal with single variable pointer. In other words, paramaters like x[1] are not handled.
                    paramVarObj = variable(param, arg)

                    #check whether variables are primitive type
                    if not isPrimitiveType(arg):
                        findObj = getMatchingObject(arg)
                        paramVarObj.pointer = findObj.var_name

                    glb.variable_stack.append([param, paramVarObj])

                #printVar()

                recursive(self.content, 0, self)

                #return function return value
                return self.return_list
        except Exception as e:
            raise Exception("Exception: \"{}\"  occurred during execution of function {}".format(e, self.func_name))
        finally:
            self._end_module()
            glb.funcall_depth -= 1