Exemplo n.º 1
0
 def __init__(self, context, num=0):
     global generator_context
     generator_context = context
     self.num = num
     generator_context['cache'] = Cache(
         "/tmp/qx1.5/cache", **generator_context)  # TODO: cache path
     #self.servAddr = ('',8008)
     #self.serv = BaseHTTPServer.HTTPServer(self.servAddr, httpServerHandler)
     generator_context['interruptRegistry'].register(self.shut_down)
Exemplo n.º 2
0
    def __init__(self, context):
        global console, interruptRegistry
        interruptRegistry = context['interruptRegistry']
        self._context = context
        self._config = context['config']  #config
        self._job = context['jobconf']  #config.getJob(job)
        self._console = context['console']  #console_
        self._variants = {}
        self._settings = {}
        self.approot = None
        self._classesObj = {}  # {'cid':generator.code.Class}

        if 'cache' in context:  # in case the Generator want to use a common cache object
            self._cache = context['cache']
        else:
            cache_path = self._job.get("cache/compile", "cache")
            cache_path = self._config.absPath(cache_path)
            self._cache = Cache(
                cache_path, **{
                    'interruptRegistry':
                    context['interruptRegistry'],
                    'console':
                    context['console'],
                    'cache/downloads':
                    self._job.get("cache/downloads",
                                  cache_path + "/downloads"),
                    'cache/invalidate-on-tool-change':
                    self._job.get('cache/invalidate-on-tool-change', False),
                })
            context['cache'] = self._cache

        console = self._console
        console.resetFilter()  # reset potential filters from a previous job

        Context.cache = self._cache

        return
Exemplo n.º 3
0
def run_compile(fileName, fileContent, options, args):
    fileId = fileName
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    if not options.quiet:
        print(">>> Creating tree...")
    tree = treegenerator.createFileTree(tokens)
    tree = scopes.create_scopes(tree)

    # optimizing tree
    if len(options.variants) > 0:
        if not options.quiet:
            print(">>> Selecting variants...")
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos + 1:]

        variantoptimizer.search(tree, varmap, fileId)

    if options.all or options.basecalls:
        if not options.quiet:
            print(">>> Optimizing basecalls...")
        basecalloptimizer.patch(tree)

    #if options.all or options.inline:
    #    if not options.quiet:
    #        print(">>> Optimizing inline...")
    #    inlineoptimizer.patch(tree)

    if options.all or options.strings:
        if not options.quiet:
            print(">>> Optimizing strings...")
        _optimizeStrings(tree, fileId)

    if options.all or options.variables:
        if not options.quiet:
            print(">>> Optimizing variables...")
        variableoptimizer.search(tree)

    if options.all or options.globals:
        if not options.quiet:
            print(">>> Optimizing globals...")
        tree = globalsoptimizer.process(tree)

    if options.all or options.privates:
        if not options.quiet:
            print(">>> Optimizing privates...")
        privates = {}
        if options.cache:
            cache = Cache(options.cache, interruptRegistry=interruptRegistry)
            privates, _ = cache.read(options.privateskey)
            if privates == None:
                privates = {}
        privateoptimizer.patch(tree, fileId, privates)
        if options.cache:
            cache.write(options.privateskey, privates)

    if not options.quiet:
        print(">>> Compiling...")
    result = [u'']
    result = Packer().serializeNode(tree, None, result, True)
    result = u''.join(result)
    print(result.encode('utf-8'))

    return
Exemplo n.º 4
0
def run_compile(fileName, fileContent, options, args):
    fileId = fileName
    tokens = tokenizer.Tokenizer().parseStream(fileContent, fileName)
    if not options.quiet:
        print(">>> Creating tree...")
    tree = treegenerator.createFileTree(tokens)
    tree = scopes.create_scopes(tree)

    # optimizing tree
    if len(options.variants) > 0:
        if not options.quiet:
            print(">>> Selecting variants...")
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos+1:]

        variantoptimizer.search(tree, varmap, fileId)

    if options.all or options.basecalls:
        if not options.quiet:
            print(">>> Optimizing basecalls...")
        basecalloptimizer.patch(tree)

    #if options.all or options.inline:
    #    if not options.quiet:
    #        print(">>> Optimizing inline...")
    #    inlineoptimizer.patch(tree)

    if options.all or options.strings:
        if not options.quiet:
            print(">>> Optimizing strings...")
        _optimizeStrings(tree, fileId)

    if options.all or options.variables:
        if not options.quiet:
            print(">>> Optimizing variables...")
        variableoptimizer.search(tree)

    if options.all or options.globals:
        if not options.quiet:
            print(">>> Optimizing globals...")
        tree = globalsoptimizer.process(tree)

    if options.all or options.privates:
        if not options.quiet:
            print(">>> Optimizing privates...")
        privates = {}
        if options.cache:
            cache = Cache(options.cache,
                interruptRegistry=interruptRegistry
            )
            privates, _ = cache.read(options.privateskey)
            if privates == None:
                privates = {}
        privateoptimizer.patch(tree, fileId, privates)
        if options.cache:
            cache.write(options.privateskey, privates)

    if not options.quiet:
        print(">>> Compiling...")
    result = [u'']
    result = Packer().serializeNode(tree, None, result, True)
    result = u''.join(result)
    print(result.encode('utf-8'))

    return
Exemplo n.º 5
0
def main():
    parser = optparse.OptionParser(option_class=ExtendAction)

    usage_str = '''%prog [options] file.js,...'''
    parser.set_usage(usage_str)

    # General flags
    parser.add_option("-v",
                      "--verbose",
                      action="store_true",
                      dest="verbose",
                      default=False,
                      help="verbose output mode (extra verbose)")
    parser.add_option("-q",
                      "--quiet",
                      action="store_true",
                      dest="quiet",
                      default=False,
                      help="quiet output")

    # Optimization flags
    parser.add_option("-n",
                      "--variables",
                      action="store_true",
                      dest="variables",
                      default=False,
                      help="optimize variables")
    parser.add_option("-s",
                      "--strings",
                      action="store_true",
                      dest="strings",
                      default=False,
                      help="optimize strings")
    parser.add_option("-p",
                      "--privates",
                      action="store_true",
                      dest="privates",
                      default=False,
                      help="optimize privates")
    parser.add_option("-b",
                      "--basecalls",
                      action="store_true",
                      dest="basecalls",
                      default=False,
                      help="optimize basecalls")
    parser.add_option("-i",
                      "--inline",
                      action="store_true",
                      dest="inline",
                      default=False,
                      help="optimize inline")
    parser.add_option("--all",
                      action="store_true",
                      dest="all",
                      default=False,
                      help="optimize all")

    # Variant support
    parser.add_option("--variant",
                      action="extend",
                      dest="variants",
                      metavar="KEY:VALUE",
                      type="string",
                      default=[],
                      help="Selected variants")

    # Action modifier
    parser.add_option("--pretty",
                      action="store_true",
                      dest="pretty",
                      default=False,
                      help="print out pretty printed")
    parser.add_option("--tree",
                      action="store_true",
                      dest="tree",
                      default=False,
                      help="print out tree")
    parser.add_option("--lint",
                      action="store_true",
                      dest="lint",
                      default=False,
                      help="ecmalint the file")

    # Cache support
    parser.add_option("-c",
                      "--cache",
                      dest="cache",
                      metavar="CACHEPATH",
                      type="string",
                      default="",
                      help="path to cache directory")
    parser.add_option("--privateskey",
                      dest="privateskey",
                      metavar="CACHEKEY",
                      type="string",
                      default="",
                      help="cache key for privates")

    #
    # Process arguments
    #
    (options, args) = parser.parse_args(sys.argv[1:])

    if len(args) == 0:
        print ">>> Missing filename!"
        return

    if not options.quiet:
        print ">>> Parsing file..."
    fileName = args[0]
    fileContent = filetool.read(fileName, "utf-8")
    fileId = "xxx"
    tokens = tokenizer.parseStream(fileContent, fileName)

    if not options.quiet:
        print ">>> Creating tree..."
    tree = treegenerator.createSyntaxTree(tokens)

    #
    # Optimizing tree
    #

    if len(options.variants) > 0:
        if not options.quiet:
            print ">>> Selecting variants..."
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos + 1:]

        variantoptimizer.search(tree, varmap, fileId)

    if options.all or options.basecalls:
        if not options.quiet:
            print ">>> Optimizing basecalls..."
        basecalloptimizer.patch(tree)

    if options.all or options.inline:
        if not options.quiet:
            print ">>> Optimizing inline..."
        inlineoptimizer.patch(tree)

    if options.all or options.strings:
        if not options.quiet:
            print ">>> Optimizing strings..."
        _optimizeStrings(tree, fileId)

    if options.all or options.variables:
        if not options.quiet:
            print ">>> Optimizing variables..."
        variableoptimizer.search(tree)

    if options.all or options.privates:
        if not options.quiet:
            print ">>> Optimizing privates..."
        if options.cache:
            cache = Cache(options.cache, Log())
            privates, _ = cache.read(options.privateskey)
            if privates != None:
                privateoptimizer.load(privates)
        privateoptimizer.patch(tree, fileId)
        if options.cache:
            cache.write(options.privateskey, privateoptimizer.get())

    #
    # Output the result
    #

    if options.lint:
        if not options.quiet:
            print ">>> Executing ecmalint..."
        print "Needs implementation"

    elif options.tree:
        if not options.quiet:
            print ">>> Printing out tree..."
        print tree.toXml().encode('utf-8')

    else:
        if not options.quiet:
            print ">>> Compiling..."
        compiled = _compileTree(tree, options.pretty)
        print compiled.encode('utf-8')
Exemplo n.º 6
0
def main():
    parser = optparse.OptionParser(option_class=ExtendAction)

    usage_str = '''%prog [options] file.js,...'''
    parser.set_usage(usage_str)
    
    # General flags
    parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="verbose output mode (extra verbose)")
    parser.add_option("-q", "--quiet", action="store_true", dest="quiet", default=False, help="quiet output")

    # Optimization flags
    parser.add_option("-n", "--variables", action="store_true", dest="variables", default=False, help="optimize variables")
    parser.add_option("-s", "--strings", action="store_true", dest="strings", default=False, help="optimize strings")
    parser.add_option("-p", "--privates", action="store_true", dest="privates", default=False, help="optimize privates")
    parser.add_option("-b", "--basecalls", action="store_true", dest="basecalls", default=False, help="optimize basecalls")            
    parser.add_option("-i", "--inline", action="store_true", dest="inline", default=False, help="optimize inline")
    parser.add_option("-r", "--variants", action="store_true", dest="variantsopt", default=False, help="optimize variants")
    parser.add_option("-m", "--comments", action="store_true", dest="comments", default=False, help="optimize comments")
    parser.add_option("--all", action="store_true", dest="all", default=False, help="optimize all")            

    # Variant support
    parser.add_option("--variant", action="extend", dest="variants", metavar="KEY:VALUE", type="string", default=[], help="Selected variants")
    
    # Action modifier
    parser.add_option("--pretty", action="store_true", dest="pretty", default=False, help="print out pretty printed")            
    parser.add_option("--tree", action="store_true", dest="tree", default=False, help="print out tree")
    parser.add_option("--lint", action="store_true", dest="lint", default=False, help="ecmalint the file")

    # Cache support
    parser.add_option("-c", "--cache", dest="cache", metavar="CACHEPATH", type="string", default="", help="path to cache directory")
    parser.add_option("--privateskey", dest="privateskey", metavar="CACHEKEY", type="string", default="", help="cache key for privates")
    
    
    #
    # Process arguments
    #
    (options, args) = parser.parse_args(sys.argv[1:])
    
    if len(args) == 0:
        print ">>> Missing filename!"
        return

    if not options.quiet:
        print ">>> Parsing file..."
    fileName = args[0]
    fileContent = filetool.read(fileName, "utf-8")
    fileId = "xxx"
    tokens = tokenizer.parseStream(fileContent, fileName)
    
    if not options.quiet:
        print ">>> Creating tree..."
    tree = treegenerator.createFileTree(tokens)
    
    
    #
    # Optimizing tree
    #
    
    if len(options.variants) > 0:
        if not options.quiet:
            print ">>> Selecting variants..."
        varmap = {}
        for entry in options.variants:
            pos = entry.index(":")
            varmap[entry[0:pos]] = entry[pos+1:]
            
        variantoptimizer.search(tree, varmap, fileId)
    
    if options.all or options.basecalls:
        if not options.quiet:
            print ">>> Optimizing basecalls..."
        basecalloptimizer.patch(tree)   

    if options.all or options.inline:
        if not options.quiet:
            print ">>> Optimizing inline..."
        inlineoptimizer.patch(tree)   

    if options.all or options.strings:
        if not options.quiet:
            print ">>> Optimizing strings..."
        _optimizeStrings(tree, fileId)

    if options.all or options.variables:
        if not options.quiet:
            print ">>> Optimizing variables..."
        variableoptimizer.search(tree)

    if options.all or options.privates:
        if not options.quiet:
            print ">>> Optimizing privates..."
        privates = {}
        if options.cache:
            cache = Cache(options.cache, 
                interruptRegistry=interruptRegistry
            )
            privates, _ = cache.read(options.privateskey)
            if privates == None:
                privates = {}
        privateoptimizer.patch(tree, fileId, privates)
        if options.cache:
            cache.write(options.privateskey, privates)
         
         
    #
    # Output the result
    #
            
    if options.lint:
        if not options.quiet:
            print ">>> Executing ecmalint..."
        print "Needs implementation"
    
    elif options.tree:
        if not options.quiet:
            print ">>> Printing out tree..."
        print tree.toXml().encode('utf-8')
        
    else:
        if not options.quiet:
            print ">>> Compiling..."
        compiled = _compileTree(tree, options.pretty)
        print compiled.encode('utf-8')