Esempio n. 1
0
    def template(self, translator, body, args, var):
        logging = [k.value for k in args.keywords if k.arg == 'log']
        if logging:
            logging = logging[0]
            with quote() as log:
                with unquote_bind(logging, rhs(var)) as (_logging, res):
                    if _logging:
                        print "Took", res
        else:
            log = []

        time_module = ast.Name(translator.gensym(), ast.Load())

        with quote() as q:
            with unquote_bind(var, time_module) as (res, _time):
                import time as _time
                _start = _time.time()
                unquote_stmts(body)
                res = _time.time() - _start
                unquote_stmts(log)
        return q
Esempio n. 2
0
    def template(self, translator, body, args, var):
        logging = [k.value for k in args.keywords if k.arg == 'log']
        if logging:
            logging = logging[0]
            with quote() as log:
                with unquote_bind(logging, rhs(var)) as (_logging, res):
                    if _logging:
                        print "Took", res
        else:
            log = []

        time_module = ast.Name(translator.gensym(), ast.Load())

        with quote() as q:
            with unquote_bind(var, time_module) as (res, _time):
                import time as _time
                _start = _time.time()
                unquote_stmts(body)
                res = _time.time() - _start
                unquote_stmts(log)
        return q
Esempio n. 3
0
    def template(self, translator, body, args, var):
        try:
            match_msg_node = translator.stack[-2]['match_msg_Name']
        except (IndexError, KeyError):
            raise SyntaxError("with case() should be nested in a with match() construct")

        if var:
            if isinstance(var, ast.Tuple):
                bound_vars = var
            else:
                bound_vars = ast.Tuple([var], ast.Store())
        else:
            bound_vars = ast.Name('__x__', ast.Store())

        with quote() as q:
            with unquote_bind(bound_vars) as __x:
                __is_match, __x = match(unquote([match_msg_node] + args.args))
                if __is_match:
                    unquote_stmts(body)
                    break

        return q
Esempio n. 4
0
    def template(self, translator, body, args, var):
        try:
            match_msg_node = translator.stack[-2]['match_msg_Name']
        except (IndexError, KeyError):
            raise SyntaxError(
                "with case() should be nested in a with match() construct")

        if var:
            if isinstance(var, ast.Tuple):
                bound_vars = var
            else:
                bound_vars = ast.Tuple([var], ast.Store())
        else:
            bound_vars = ast.Name('__x__', ast.Store())

        with quote() as q:
            with unquote_bind(bound_vars) as __x:
                __is_match, __x = match(unquote([match_msg_node] + args.args))
                if __is_match:
                    unquote_stmts(body)
                    break

        return q