Ejemplo n.º 1
0
    def render(self, sexps):
        # mapping = {}
        # if len(self.args) > 0 and isinstance(self.args[-1], bach_ast.Many):
        #     if len(self.args) >= len(sexps) - 1:
        #         for arg, sexp in zip(self.args[:-1], self.sexps[:len(self.args) - 1]):
        #             mapping[arg.label] = sexp
        #         mapping[self.args[-1].label] = sexps[len(self.args) - 1:]
        #     else:
        #         raise MacroMatchError("No enough args for %s" % self.label)
        # else:
        #     if len(self.args) == len(sexps):
        #         for arg, sexp in zip(self.args, sexps):
        #             mapping[arg.label] = sexp
        #     else:
        #         raise MacroMatchError("Expected %d args got %d for %s" % (len(self.args), len(sexps), self.label))
        # value =
        if not self.args:
            args = []
        elif isinstance(self.args[-1], bach_ast.Many):
            args = self.args[:-1] + [bach_ast.Label(self.args[-1].label)]
        else:
            args = self.args

        sexps = [bach_ast.Quote(sexp) for sexp in sexps]
        sexp = bach_ast.Program([[bach_ast.Lambda(args, self.body)] + sexps])
        result = compiler.Compiler().compile_and_eval(sexp,
                                                      stl=bach_stl.load_stl(),
                                                      return_value=True)
        return self.normal_sexp(result)
Ejemplo n.º 2
0
    def __init__(self,
                 source,
                 log_function=default_logfunction,
                 sessionid=None,
                 default_datamodel="python",
                 setup_session=True):
        '''
        @param source: the scxml document to parse. source may be either:
        
            uri : similar to what you'd write to the open() function. The 
            difference is, StateMachine looks in the PYSCXMLPATH environment variable 
            for documents if none can be found at ".". As such, it's similar to the PYTHONPATH
            environment variable. Set the PYSCXMLPATH variable to exert more fine-grained control
            over the src attribute of <invoke>. self.filename and self.filedir are set as a result.
            
            xml string: if source is an xml string, it's executed as is. 
            self.filedir and self.filename aren't filled. 
            
            file-like object: if source has the .read() method, 
            the result of that method will be executed.
            
        @param log_function: the function to execute on a <log /> element. 
        signature is f(label, msg), where label is a string and msg a string.
        @param sessionid: is stored in the _session variable. Will be automatically
        generated if not provided.
        @param default_datamodel: if omitted, any document started by this instance will have 
        its datamodel expressions evaluated as Python expressions. Set to 'ecmascript' to assume 
        EMCAScript expressions.
        @param setup_session: for internal use.
        @raise IOError 
        @raise xml.parsers.expat.ExpatError 
        '''

        self.is_finished = False
        self.filedir = None
        self.filename = None
        self.compiler = compiler.Compiler()
        self.compiler.default_datamodel = default_datamodel
        self.compiler.log_function = log_function

        self.sessionid = sessionid or "pyscxml_session_" + str(id(self))
        self.interpreter = Interpreter()
        dispatcher.connect(self.on_exit, "signal_exit", self.interpreter)
        self.logger = logging.getLogger("pyscxml.%s" % self.sessionid)
        self.interpreter.logger = logging.getLogger("pyscxml.%s.interpreter" %
                                                    self.sessionid)
        self.compiler.logger = logging.getLogger("pyscxml.%s.compiler" %
                                                 self.sessionid)
        self.doc = self.compiler.parseXML(self._open_document(source),
                                          self.interpreter)
        self.interpreter.dm = self.doc.datamodel
        self.datamodel = self.doc.datamodel
        self.doc.datamodel["_x"] = {"self": self}
        self.doc.datamodel.self = self
        self.doc.datamodel["_sessionid"] = self.sessionid
        self.doc.datamodel.sessionid = self.sessionid
        self.name = self.doc.name
        self.is_response = self.compiler.is_response
        if setup_session:
            MultiSession().make_session(self.sessionid, self)
Ejemplo n.º 3
0
def get_compiler():
    import compiler
    cmp = compiler.Compiler()
    cmp.misc.changed_images = {}
    cmp.add_tag("{{Meta(?:|\|([^}]*))}}", "<head><meta charset='utf-8'><title>{0}</title></head><body>", default_arg=("No title","Foo","Bar"))
    cmp.add_tag("{{img\|([^}]+)}}", handle_image)
    cmp.add_tag("{{avatar\|([a-zA-Z0-9_-]+)}}", get_avatar)
    return cmp
Ejemplo n.º 4
0
def main(args):
	if len(args) < 3:
		print "[ERROR] Usage: %s <project_dir> <deploytype>" % os.path.basename(args[0])
		sys.exit(1)
		
	project_dir = os.path.expanduser(args[1])
	deploytype = args[2]
	compiler.Compiler(project_dir,deploytype)
Ejemplo n.º 5
0
    def run(self, text):
        l2c = compiler.Compiler(self.view)
        sublime.status_message("Compiling .less files...")
        resp = l2c.convertAll()

        if resp != "":
            MessageWindow(resp)
        else:
            sublime.message_dialog("All .less files compiled successfully")
Ejemplo n.º 6
0
    def test_compile_file(self):

        file_path = "D:\\longTimeProgram1.py"

        file = open(file_path)
        content = file.read()

        comp = compiler.Compiler()
        result = comp.compile_file(content)

        self.assertEqual(1, result)
Ejemplo n.º 7
0
def extract_text():
    outputFile = (outputsDir / 'wikitext_anarchism.txt').open(encoding="utf8",
                                                              mode="w")
    with (ROOT /
          'examples/data/wikitext_anarchism.txt').open(encoding="utf8") as f:
        w_compiler = c.Compiler()
        text = f.read()
        try:
            text = w_compiler.compile(text)
            outputFile.write(text)
        except Exception as e:
            traceback.print_exc()

    outputFile.close()
Ejemplo n.º 8
0
 def test_bare_sequence(self):
     s = Sequence()
     c = compiler.Compiler()
     c.TRUNCATE = False
     c.load(s)
     compiled_sequence = c.compile(variant=0)
     print(c.instruction_list.human)
     #compiler.prettyprint(compiled_sequence)
     i = ipu.IPU()
     i.showBuffer = False
     i._RAM = compiled_sequence
     s.shots = 2
     i.nRepeats = s.shots
     i.idleState = s.hardware.idle_state ^ s.hardware.polarity_mask
     i.run()
Ejemplo n.º 9
0
 def test_minimal_sequence(self):
     s = Sequence.from_file(
         "./compiler/test_sequences/minimal_sequence.xml")
     c = compiler.Compiler()
     c.TRUNCATE = False
     c.load(s)
     compiled_sequence = c.compile(variant=0)
     print(c.instruction_list.human)
     i = ipu.IPU()
     i.showBuffer = False
     i._RAM = compiled_sequence
     i.nRepeats = 10
     i._spcMemoryRange[0] = (8000, 12000)
     i.idleState = s.HWConfig.idle_state ^ s.HWConfig.polarity_mask
     i.run()
    def find_password_for_username(self):
        x = self.find_username()
        file = open(self.passwords_file)
        lines = file.readlines()
        try:
            i = compiler.Compiler(self.password)
            compile_password = i.compile()
            if compile_password in lines:
                compiled_password = lines[x]
                return compiled_password
            else:
                return 'Invalid password.'

        except Exception:
            return 'Invalid password.'
Ejemplo n.º 11
0
def extract_links():
    outputFile = (outputsDir / 'wikitext_link_extraction.txt').open(
        encoding="utf8", mode="w")
    with (ROOT / 'examples/data/wikitext_link_extraction.txt').open(
            encoding="utf8") as f:
        w_compiler = c.Compiler()
        listener = w_compiler.on(lambda node: parse_link(node),
                                 c.ParseTypes.LINK)
        text = f.read()
        try:
            w_compiler.compile(text)
            outputFile.write(
                f'\n\n* Links\n\n {reverse_graph} \n\n* Categories\n {categories}'
            ),
        except Exception as e:
            traceback.print_exc()
        finally:
            listener()  # free listener
Ejemplo n.º 12
0
def rodarFilaArquivos(every_minute):
    print("Rodando Fila de Arquivos a cada " + str(every_minute) +
          " minuto(s)")
    rodou = False
    minute = datetime.datetime.now().strftime('%M')
    while (True):
        if minute != datetime.datetime.now().strftime('%M'):
            minute = datetime.datetime.now().strftime('%M')
            rodou = False
        if not (int(datetime.datetime.now().strftime('%M')) %
                every_minute) and not rodou:
            print("Verificando..")
            rodou = True
            with Database.Database('rubik_platform.db') as db:
                envios = db.query('SELECT * FROM envios WHERE env_status = 0')
            if envios:
                for envio in envios:
                    print(envio)
                    with Database.Database('rubik_platform.db') as db:
                        estados = db.query(
                            'SELECT * FROM estados_cubo ORDER BY cub_robo DESC LIMIT 5',
                            ())
                    if estados:
                        comp = compiler.Compiler(envio['env_filename'])
                        success = comp.Compile(estados)

                        if success:
                            print("sucesso")
                            with Database.Database('rubik_platform.db') as db:
                                db.execute(
                                    "UPDATE envios SET env_status = ? WHERE env_id = ?",
                                    (1, envio['env_id']))
                        else:
                            print("erro")
                            with Database.Database('rubik_platform.db') as db:
                                db.execute(
                                    "UPDATE envios SET env_status = ? WHERE env_id = ?",
                                    (2, envio['env_id']))
                    else:
                        print("Não há estados disponiveis")
            print("fim")
Ejemplo n.º 13
0
def rodarFilaArquivos(every_minute):
    print("Rodando Fila para envio do robô a cada " + str(every_minute) +
          " minuto(s)")
    rodou = False
    minute = datetime.datetime.now().strftime('%M')
    while (True):
        if minute != datetime.datetime.now().strftime('%M'):
            minute = datetime.datetime.now().strftime('%M')
            rodou = False
        if not (int(datetime.datetime.now().strftime('%M')) %
                every_minute) and not rodou:
            print("Verificando..")
            rodou = True
            with Database.Database('rubik_platform.db') as db:
                fila_robo = db.query(
                    'SELECT * FROM fila_robo JOIN envios ON env_id = rob_idenvio WHERE rob_status = 0 AND env_status = 1'
                )
            if fila_robo:
                for row in fila_robo:
                    print(row)
                    with Database.Database('rubik_platform.db') as db:
                        estados = db.query(
                            'SELECT * FROM estados_cubo ORDER BY cub_robo DESC LIMIT 5',
                            ())
                    if estados:
                        comp = compiler.Compiler(row['env_filename'])
                        movements = comp.Compile(estados, True)
                        print(movements)
                        if movements:
                            ser = serial.Serial('/dev/ttyUSB0')
                            ser.write(movements.encode())
                            with Database.Database('rubik_platform.db') as db:
                                db.execute(
                                    "UPDATE fila_robo SET rob_status = ? WHERE rob_id = ?",
                                    (1, row['rob_id']))
                            ser.close()

            print("Fim")
Ejemplo n.º 14
0
def repl():
    """
    This function defines the debugging monkelang REPL environment. It runs 
    code with the VM class's run_once method.
    """
    machine = vm.VM([])
    duck_compiler = compiler.Compiler([], machine)

    print("DuckLang REPL :D")

    while True:
        command = input("duck> ")

        ast = duck_parser.DuckParser(command).parse()

        duck_compiler.ast = ast

        code, constant_table = duck_compiler.compile()
        
        machine.constant_table = constant_table
        machine.code = code

        machine.run_once(code)
Ejemplo n.º 15
0
def job_compile(kwargs):
    if not kwargs.has_key(u'task_id'):
        return

    task_id = kwargs[u'task_id']
    tasks = models.CovTask.objects.filter(id=task_id)
    if 0 >= len(tasks):
        return

    task = tasks[0]

    module = task.module

    task.pack_state = u'doing'
    task.save()

    cmpler = compiler.Compiler(module.name, module.repos_type.name,
                               module.repos_addr)
    cmpler.init_work_space(conf.FMT_TASK_DIR % (task.id, task.name))
    ret = cmpler.download_code(task.version)
    if 0 != ret:
        task.pack_state = u'failed'
        task.save()
        return

    ret = cmpler.compile()
    if 0 != ret:
        task.pack_state = u'failed'
        task.save()
        return

    task.pack_state = u'success'
    task.bgjob_id = u''
    task.save()

    return
Ejemplo n.º 16
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--compiler',
                        required=True,
                        help='Path to compiler')
    parser.add_argument('-s',
                        '--sources',
                        nargs='*',
                        default=[],
                        help='List of js source files')
    parser.add_argument('-o',
                        '--output',
                        required=False,
                        help='Compile to output')
    parser.add_argument('--chunks',
                        action='store_true',
                        help='Compile each source to its own chunk')
    parser.add_argument(
        '--chunk_suffix',
        required=False,
        help='String appended to the source when naming a chunk')
    parser.add_argument('-d',
                        '--deps',
                        nargs='*',
                        default=[],
                        help='List of js_libarary dependencies')
    parser.add_argument('-b',
                        '--bootstrap',
                        help='A file to include before all others')
    parser.add_argument('-cf',
                        '--config',
                        nargs='*',
                        default=[],
                        help='A list of files to include after bootstrap and '
                        'before all others')
    parser.add_argument('-f',
                        '--flags',
                        nargs='*',
                        default=[],
                        help='A list of custom flags to pass to the compiler. '
                        'Do not include leading dashes')
    parser.add_argument('-e',
                        '--externs',
                        nargs='*',
                        default=[],
                        help='A list of extern files to pass to the compiler')
    parser.add_argument('-co',
                        '--checks-only',
                        action='store_true',
                        help='Only performs checks and writes an empty output')

    args = parser.parse_args()

    # If --chunks is used, args.sources will be added later
    sources, externs = CrawlRootDepsTree(args.deps,
                                         [] if args.chunks else args.sources,
                                         args.externs)
    compiler_args = ['--%s' % flag for flag in args.flags]
    compiler_args += ['--externs=%s' % e for e in externs]

    if not args.chunks:
        compiler_args += [
            '--js_output_file',
            args.output,
        ]

    compiler_args += [
        '--js',
    ]

    if args.bootstrap:
        compiler_args += [args.bootstrap]

    compiler_args += args.config
    compiler_args += sources

    if args.chunks:
        chunk_suffix = args.chunk_suffix
        common_chunk_name = 'common' + chunk_suffix
        compiler_args += [
            '--chunk_output_path_prefix {}'.format(args.output),
            '--chunk {}:auto'.format(common_chunk_name)
        ]

        for s in args.sources:
            # '//path/to/target.js' becomes 'target'
            chunk_name = '{}{}'.format(
                s.split('/')[-1].split('.')[0], chunk_suffix)
            compiler_args += [
                '--chunk {}:1:{}: {}'.format(chunk_name, common_chunk_name, s)
            ]

    if args.checks_only:
        compiler_args += ['--checks-only']
        open(args.output, 'w').close()

    returncode, errors = compiler.Compiler().run_jar(args.compiler,
                                                     compiler_args)
    if returncode != 0:
        print(args.compiler, ' '.join(compiler_args))
        print(errors)

    return returncode
Ejemplo n.º 17
0
 def setUp(self):
     self.compiler = compiler.Compiler()
Ejemplo n.º 18
0
 def __init__(self):
     self.t = tokenizer.Tokenizer()
     self.p = parser.Parser()
     self.c = compiler.Compiler()
Ejemplo n.º 19
0
 def run(self, text):
     l2c = compiler.Compiler(self.view)
     resp = l2c.convertOne()
     MessageWindow(resp)
Ejemplo n.º 20
0
def main():
    compiler = cp.Compiler(True)
    ret = compiler(thisyear, 1, 1)
    print(ret)
Ejemplo n.º 21
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--compiler',
                        required=True,
                        help='Path to compiler')
    parser.add_argument('-s',
                        '--sources',
                        nargs='*',
                        default=[],
                        help='List of js source files')
    parser.add_argument('-o',
                        '--output',
                        required=True,
                        help='Compile to output')
    parser.add_argument('-d',
                        '--deps',
                        nargs='*',
                        default=[],
                        help='List of js_libarary dependencies')
    parser.add_argument('-b',
                        '--bootstrap',
                        help='A file to include before all others')
    parser.add_argument('-cf',
                        '--config',
                        nargs='*',
                        default=[],
                        help='A list of files to include after bootstrap and '
                        'before all others')
    parser.add_argument('-f',
                        '--flags',
                        nargs='*',
                        default=[],
                        help='A list of custom flags to pass to the compiler. '
                        'Do not include leading dashes')
    parser.add_argument('-e',
                        '--externs',
                        nargs='*',
                        default=[],
                        help='A list of extern files to pass to the compiler')
    parser.add_argument('-co',
                        '--checks-only',
                        action='store_true',
                        help='Only performs checks and writes an empty output')

    args = parser.parse_args()
    sources, externs = CrawlRootDepsTree(args.deps, args.sources, args.externs)

    compiler_args = ['--%s' % flag for flag in args.flags]
    compiler_args += ['--externs=%s' % e for e in externs]
    compiler_args += [
        '--js_output_file',
        args.output,
        '--js',
    ]
    if args.bootstrap:
        compiler_args += [args.bootstrap]
    compiler_args += args.config
    compiler_args += sources

    if args.checks_only:
        compiler_args += ['--checks-only']
        open(args.output, 'w').close()

    returncode, errors = compiler.Compiler().run_jar(args.compiler,
                                                     compiler_args)
    if returncode != 0:
        print errors

    return returncode
Ejemplo n.º 22
0
 def run(self, text):
     l2c = compiler.Compiler(self.view)
     resp = l2c.convertOne(is_auto_save=True)
     MessageWindow(resp)
Ejemplo n.º 23
0
    global_logger = SimpleLogger("Current run")

    files = args.files if not args.dir else [os.path.join(args.files[0], x) for x in os.listdir(args.files[0]) if x.endswith(".cpp")]

    for source in files:
        assert os.path.exists(source)

        # extract student name (we have this agreement, that cpp file name 
        # will be name of the student)
        name = os.path.basename(source).split('.')[0]

        builds_num = 0
        logger = SimpleLogger(str(source))
        global_logger.print(f"Student {logger.name}", logonly=True)
        c = compiler.Compiler(source, identificator=logger.name, folder=SimpleLogger.FOLDER)
        # Compile for all configs
        errors, warnings = 0, 0
        for platform_ in compiler.Platform:
            logger.print(f"Compiling platform {platform_.name}")
            executable = c.compile(platform_)

            errors += len(executable.errors)
            warnings += len(executable.warnings)

            logger.print(str(executable))
            if executable and not executable.warnings:
                builds_num += 1
            else:
                logger.print(executable.get_log(), logonly=True)
Ejemplo n.º 24
0
import rule
import elements
import compiler
import core

l = core.GrammarList("somelist")
element = elements.Seq((
    elements.Lit("good morning"),
    elements.Lst(l),
))
r = rule.Rule("test_rule", element, exported=True)

c = compiler.Compiler()
r.compile(c)
output = c.compile()

print "Compiler state:"
print c.debug_state_string()

print "Output:"
binary = "".join(["%02x" % ord(c) for c in output])
for index in xrange(0, len(binary), 4):
    if index and not index % (8 * 4): print
    print binary[index:index + 4],
Ejemplo n.º 25
0
Archivo: rpl21.py Proyecto: wim-c/rpl
                    help='The format of the generated output.')
parser.add_argument(
    '-o',
    '--output',
    dest='output',
    metavar='FILE',
    default=None,
    help='Output will be written to this file path.  Default is stdout.')
parser.add_argument(
    '-p',
    '--prg',
    dest='prg',
    default=False,
    action='store_true',
    help=
    'Start the output with a two byte location header.  Has no effect for the output type \'print\'.'
)
parser.add_argument('file', help='File path of source to compile.')

args = parser.parse_args()

fmt = formatter.Format.create(args.fmt, args.output, args.prg)
cmp = compiler.Compiler()
cmp.compile(args.file, args.org, args.rt, fmt)

if len(cmp.errors) > 0:
    for error in cmp.errors:
        sys.stderr.write(error)
        sys.stderr.write('\n')
    sys.exit(-1)
Ejemplo n.º 26
0
        if o == "-v":
            verbose = True
        if o == "-o":
            output = a
        if o == "-s":
            if a in ["c", "hex", "bin"]:
                style = a

    if output == None:
        print "Output file not specified."
        usage()
    if style == None:
        print "Output style not specified."
        usage()
    if len(args) == 0:
        print "Source file not specified."
        usage()
    input = args[0]

    c = compiler.Compiler(myis.instructions, myis.registers, verbose)
    c.parseFile(input)
    c.compile()
    c.link()

    program = c.getProgram()
    writeCode(output, program, style)


if __name__ == "__main__":
    main()
Ejemplo n.º 27
0
def main(args):
    if args["help"]:
        print __doc__.rstrip()
        return None

    do_log = not args["run"] or args["--verbose"]
    if do_log:
        if args["--verbose"]:
            shell.COMMAND_DEFAULTS["mvn"] = "mvn"
        logging.basicConfig(level=logging.DEBUG)
        log = logging.getLogger("quark")
        log.propagate = False
        hnd = ProgressHandler(verbose=args["--verbose"])
        log.addHandler(hnd)
        hnd.setFormatter(logging.Formatter("%(message)s"))

    version = "Quark %s run at %s" % (_metadata.__version__,
                                      datetime.datetime.now())
    helpers.Code.identifier = version

    java = args["--java"]
    ruby = args["--ruby"]
    python = args["--python"]
    python3 = args["--python3"]
    javascript = args["--javascript"]

    all = args["--all"] or not (java or python or javascript or ruby
                                or python3)

    output = args["--output"]
    offline = not args["--online"]

    try:
        shell.command_log.info("Checking environment")
        backends = []
        if java or all:
            if args["install"]: shell.check("mvn")
            backends.append(backend.Java)
        if ruby or all:
            if args["install"]: shell.check("gem")
            backends.append(backend.Ruby)
        if python or all:
            if args["install"]:
                shell.check("python2")
                shell.check("pip2")
            backends.append(backend.Python)
        if python3 or all:
            if args["install"]:
                shell.check("python3")
                shell.check("pip3")
            backends.append(backend.Python3)
        if javascript or all:
            if args["install"]: shell.check("npm")
            backends.append(backend.JavaScript)

        filenames = args["<file>"] or [
            compiler.join(None, compiler.BUILTIN_FILE)
        ]
        for url in filenames:
            c = compiler.Compiler(args["--include-stdlib"])
            c.version_warning = args["--version-warning"]
            if args["install"]:
                compiler.install(c, url, offline, *backends)
            elif args["compile"]:
                compiler.compile(c, url, output, *backends)
            elif args["run"]:
                compiler.run(c, url, args["<args>"], *backends)
            elif args["docs"]:
                compiler.make_docs(c, url, output, args["--include-private"])
            else:
                assert False
    except (KeyboardInterrupt, QuarkError) as err:
        if not args["run"]:
            shell.command_log.error("")
        if args["install"] and offline and isinstance(err, shell.ShellError):
            err = str(err) + "\n\n"
            err += "Please retry the command with the --online switch\n\n"
            err += "    quark install --online "
            for opt in "--verbose --java --javascript --ruby --python --python3".split(
            ):
                if args[opt]: err += opt + " "
            err += " ".join(shell.quote(f) for f in args["<file>"])
            err += "\n"
        return err
    except:  # pylint: disable=bare-except
        if do_log:
            import inspect
            ast_stack = helpers.format_ast_stack(inspect.trace())
            shell.command_log.error(
                "\n -- snip --\nInternal compiler error, %s\n\n" % version,
                exc_info=True)
            if ast_stack:
                shell.command_log.error("\nCompiler was looking at:\n%s\n" %
                                        ast_stack)
        instructions = textwrap.dedent("""\

        Your code triggered an internal compiler error.

        Please report the issue at https://github.com/datawire/quark/issues
        """)
        if do_log:
            instructions += textwrap.dedent("""\

            Please attach the above report up until the -- snip -- line with the issue.
            If at all possible also attach the quark file that caused the error.
            """)
        else:
            instructions += textwrap.dedent("""\

            Please re-run the quark command with --verbose flag to get the full report.
            """)
        return instructions

    shell.command_log.warn("Done")