Beispiel #1
0
def ezhil_file_parse_eval( file_input,redirectop,debug):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format
    """
    if ( redirectop ):
        sys.stdout = codecs.open(EzhilRedirectOutput.pidFileName(current_process().pid),"w","utf-8")
        sys.stderr = sys.stdout;
    lexer = EzhilLex(file_input,debug)
    if ( debug ): lexer.dump_tokens()
    parse_eval = EzhilInterpreter( lexer, debug )
    web_ast = parse_eval.parse()
    if( debug ):
        print(unicode(web_ast))
    if ( debug ):  print(u"*"*60);  print(unicode(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        exit_code = -1
        print(unicode(e))
        if ( debug ):
            traceback.print_tb(sys.exc_info()[2])
            raise e
    finally:
        if ( redirectop ):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            #sys.stdout.close()
    return exit_code
Beispiel #2
0
def ezhil_file_parse_eval(file_input, redirectop, debug):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format
    """
    if (redirectop):
        sys.stdout = open(
            EzhilRedirectOutput.pidFileName(current_process().pid), "w")
        sys.stderr = sys.stdout
    lexer = EzhilLex(file_input, debug)
    if (debug): lexer.dump_tokens()
    parse_eval = EzhilInterpreter(lexer, debug)
    web_ast = parse_eval.parse()
    if (debug):
        print(web_ast)
    if (debug):
        print("*" * 60)
        print(str(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        exit_code = -1
        print str(e)
    finally:
        if (redirectop):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            sys.stdout.close()
    return exit_code
def ezhil_eval(*args):
    global global_interpreter
    env = global_interpreter.env
    debug = global_interpreter.debug
    
    lexer = EzhilLex(fname=[args[0]])
    if ( debug ): lexer.dump_tokens()
    parse_eval = Interpreter( lexer, debug, global_interpreter.SAFE_MODE,False,env=global_interpreter.env)
    try:
        web_ast = parse_eval.parse()
        parse_eval.call_stack.append("__tmptop__")
        return parse_eval.evaluate()
    except Exception as e:
        raise e
    return
Beispiel #4
0
 def __init__(self,file_input,debug=False,redirectop=False):        
     EzhilRedirectOutput.__init__(self,redirectop)
     
     try:
         lexer = EzhilLex(file_input,debug)
         if ( debug ): lexer.dump_tokens()
         parse_eval = EzhilInterpreter( lexer, debug )
         parse_eval.parse()
         if ( debug ):  print("*"*60);  print(str(parse_eval))
         env = parse_eval.evaluate()
     except Exception as e:            
         print("exception ",str(e))
         raise e
     finally:
         if ( redirectop ):
             self.tmpf.close()
             sys.stdout = self.old_stdout
             sys.stderr = self.old_stderr
Beispiel #5
0
def ezhil_file_parse_eval( file_input,redirectop,debug,encoding="utf-8",doprofile=False,safe_mode=False):
    """ runs as a separate process with own memory space, pid etc, with @file_input, @debug values,
        the output is written out into a file named, "ezhil_$PID.out". Calling process is responsible to
        cleanup the cruft. Note file_input can be a string version of a program to be evaluated if it is
        enclosed properly in a list format.
        @doprofile : automatically attach profile("begin") to entry of a file and calls profile("results") to end of file.
    """
    if ( redirectop ):
        print(u"redirect mode @ ezhil file parse eval")
        tmpfilename = EzhilRedirectOutput.pidFileName(current_process().pid)
        sys.stdout = codecs.open(tmpfilename,"w","utf-8")
        sys.stderr = sys.stdout;
    lexer = EzhilLex(file_input,debug,encoding=encoding)
    if ( debug ): 
        print(u"####### dump tokens ########")
        lexer.dump_tokens()
        print(u"##########################")
    parse_eval = EzhilInterpreter( lexer=lexer, debug=debug, safe_mode=safe_mode )
    web_ast = parse_eval.parse()
    if doprofile:
        # add profile at entry and exit
        TransformEntryExitProfile(interpreter=parse_eval,debug=debug)
    
    if( debug ):
        print(unicode(web_ast))
    if ( debug ):  print(u"*"*60);  print(unicode(parse_eval))
    exit_code = 0
    try:
        env = parse_eval.evaluate()
    except Exception as e:
        #print(u"xxception raised... %s"%str(redirectop))
        exit_code = 255
        print(unicode(e))
        if ( debug ):
            traceback.print_tb(sys.exc_info()[2])
        raise e
    finally:
        if ( redirectop ):
            # cerrar - முடி
            sys.stdout.flush()
            sys.stderr.flush()
            #sys.stdout.close()
    #print(u"returning back...")
    return exit_code
def ezhil_execute(*args):
    global global_interpreter
    global_interpreter.reset()
    env = global_interpreter.env
    debug = global_interpreter.debug
    
    if len(args) < 1:
        raise RuntimeException(u"ezhil_execute: missing filename argument")
    if (debug): print(args[0])
    lexer = EzhilLex(fname=args[0])
    if ( debug ): lexer.dump_tokens()
    try:
        parse_eval = Interpreter( lexer, debug, global_interpreter.SAFE_MODE,False,env=global_interpreter.env)    
        web_ast = parse_eval.parse()
        parse_eval.call_stack.append("__evaluate__")
        return parse_eval.evaluate()
    except Exception as e:
        traceback.print_stack()
        raise e
    return
Beispiel #7
0
    def __init__(self, file_input, debug=False, redirectop=False):
        EzhilRedirectOutput.__init__(self, redirectop)

        try:
            lexer = EzhilLex(file_input, debug)
            if (debug): lexer.dump_tokens()
            parse_eval = EzhilInterpreter(lexer, debug)
            parse_eval.parse()
            if (debug):
                print("*" * 60)
                print(str(parse_eval))
            env = parse_eval.evaluate()
        except Exception as e:
            print("exception ", str(e))
            raise e
        finally:
            if (redirectop):
                self.tmpf.close()
                sys.stdout = self.old_stdout
                sys.stderr = self.old_stderr