Пример #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()
Пример #2
0
    def __call__(self, *args, **kwargs):
        """
        __call__ function will actually exec a copy of this funcmodule, to void
        recursive function call error
        """
        from utils.recursive import recursive

        function = funcmodule.function_factory(self)

        glb.module_stack.append(function)

        try:
            if not (len(args) + len(kwargs)) == len(function.param_list):
                raise (TypeError('{} positional arguments but {} given'.format(
                    len(function.param_list),
                    len(args) + len(kwargs))))
            else:
                # register function formal param list
                # temp and brutial method
                # maybe should set up params when init function module
                from itertools import zip_longest
                args = list(args) + list(kwargs.values())
                for param, arg in zip_longest(function.param_list, args):
                    function.var_list[param] = arg
                    function.local_var_list.append(param)

                recursive(function.content, 0, function)

                return function.return_list

        except TypeError as e:
            print('TypeError: {}() take {}'.format(function.func_name, e))
            sys.exit(1)
        finally:
            function._end_module()
Пример #3
0
    def run(self):
        import utils.recursive as recursive
        glb.module_stack.append(self)

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

        self._end_module()
Пример #4
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()
Пример #5
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()
Пример #6
0
    def run(self):
        import utils.recursive as recursive
        glb.module_stack.append(self)

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

        self._end_module()
Пример #7
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()
Пример #8
0
    def __call__(self, *args, **kwargs):
        """
        __call__ function will actually exec a copy of this funcmodule, to void
        recursive function call error
        """
        from utils.recursive import recursive

        function = funcmodule.function_factory(self)

        glb.module_stack.append(function)

        try:
            if not (len(args) + len(kwargs)) == len(function.param_list):
                raise(TypeError('{} positional arguments but {} given'.format(
                                                    len(function.param_list),
                                                    len(args) + len(kwargs))))
            else:
                # register function formal param list
                # temp and brutial method
                # maybe should set up params when init function module
                from itertools import zip_longest
                args = list(args) + list(kwargs.values())
                for param, arg in zip_longest(function.param_list, args):
                    function.var_list[param] = arg
                    function.local_var_list.append(param)

                recursive(function.content, 0, function)

                return function.return_list

        except TypeError as e:
            print('TypeError: {}() take {}'.format(function.func_name, e))
            sys.exit(1)
        finally:
            function._end_module()
Пример #9
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()
Пример #10
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()
Пример #11
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        self._judge = eval(self.exp, self.var_list, glb.global_var_list)
        while self._judge:
            recursive(self.content, 0, self)
            self._judge = eval(self.exp, self.var_list, glb.global_var_list)
            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()

        self._end_module()
Пример #12
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        self._judge = eval(self.exp, self.var_list, glb.global_var_list)
        while self._judge:
            recursive(self.content, 0, self)
            self._judge = eval(self.exp, self.var_list, glb.global_var_list)
            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()

        self._end_module()
Пример #13
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        for value in self.loop:
            self.var_list[self.iter_var] = value
            recursive(self.content, 0, self)
            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()
        self.var_list.pop(self.iter_var)

        self._end_module()
Пример #14
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        for value in self.loop:
            self.var_list[self.iter_var] = value
            recursive(self.content, 0, self)
            if self.continue_flag:
                self.resetEnd()
                self.resetContinue()
        self.var_list.pop(self.iter_var)

        self._end_module()
Пример #15
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()
Пример #16
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        from itertools import zip_longest
        for exp, content in zip_longest(self.exps, self.contents):
            # execute('__judge__ = ' + exp, self)
            self._judge = eval(exp, self.var_list, glb.global_var_list)
            # assert(isinstance(self.var_list['__judge__'], bool))
            # if self.var_list['__judge__']:
            if self._judge:
                recursive(content, 0, self)
                break

        self._end_module()
Пример #17
0
    def run(self):
        from utils.recursive import recursive, execute
        glb.module_stack.append(self)

        from itertools import zip_longest
        for exp, content in zip_longest(self.exps, self.contents):
            # execute('__judge__ = ' + exp, self)
            self._judge = eval(exp, self.var_list, glb.global_var_list)
            # assert(isinstance(self.var_list['__judge__'], bool))
            # if self.var_list['__judge__']:
            if self._judge:
                recursive(content, 0, self)
                break

        self._end_module()
Пример #18
0
    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
Пример #19
0
    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