コード例 #1
0
def check_file(filename, sexp_cache, args):
    coq_filename = os.path.splitext(filename)[0] + '.v'
    fields = coq_filename.split(os.path.sep)
    loc2code = get_code(open(coq_filename, 'rb').read())
    file_data = {
        'filename': os.path.sep.join(fields[2:]),
        'coq_project': fields[1],
        'vernac_cmds': [],
        'num_extra_cmds': None,
        'proofs': [],
    }
    meta = open(filename).read()

    with SerAPI(args.timeout, args.debug) as serapi:
        # set the path
        file_data['vernac_cmds'].extend(set_paths(meta, serapi, sexp_cache))
        file_data['num_extra_cmds'] = len(file_data['vernac_cmds'])

        # extract the coq code
        coq_code = extract_code(meta, loc2code)

        # process the coq code
        for num_executed, (code_line, tags) in enumerate(coq_code):
            if 'PROOF_NAME' in tags:
                if tags['PROOF_NAME'] not in file_data['proofs']:
                    file_data['proofs'].append(tags['PROOF_NAME'])
            # execute until the proof editing mode starts
            if args.debug:
                print('%d: %s' % (num_executed, code_line))
            _, ast = serapi.execute(code_line, return_ast=True)
            file_data['vernac_cmds'].append(
                (code_line, tags['VERNAC_TYPE'], sexp_cache.dump(ast)))

    return file_data
コード例 #2
0
ファイル: extract_proof.py プロジェクト: brando90/TacTok
def get_proof(sexp_cache, args):
    coq_filename = os.path.splitext(args.file)[0] + '.v'
    fields = coq_filename.split(os.path.sep)
    loc2code = get_code(open(coq_filename, 'rb').read())
    meta = open(args.file).read()
    coq_code = extract_code(meta, loc2code)
    file_data = json.load(open(os.path.join(args.data_path, args.file[13:-5] + '.json')))

    with SerAPI(args.timeout, args.debug) as serapi:
        num_extra_cmds = len(set_paths(meta, serapi, sexp_cache))
        
        # process the coq code
        proof_start_lines = []
        in_proof = False
        for num_executed, (code_line, tags) in enumerate(coq_code):
            assert code_line == file_data['vernac_cmds'][num_extra_cmds + num_executed][0]
            if 'PROOF_NAME' in tags and tags['PROOF_NAME'] == args.proof:  # the proof ends
                serapi.pop() 
                line_nb = proof_start_lines[-1]
                proof_data = record_proof(num_extra_cmds, line_nb, coq_code[line_nb + 1:], sexp_cache, serapi, args)
                break
            # execute the code
            if args.debug:
                print('%d: %s' % (num_executed, code_line))
            serapi.execute(code_line)
            if serapi.has_open_goals():
                if not in_proof:  # the proof starts
                    in_proof = True
                    proof_start_lines.append(num_executed)
                    serapi.push()
            else:
                in_proof = False

    return proof_data 
コード例 #3
0
ファイル: check_proofs.py プロジェクト: princeton-vl/CoqGym
def check_file(filename, sexp_cache, args):
    print("\n" + filename)
    coq_filename = os.path.splitext(filename)[0] + ".v"
    fields = coq_filename.split(os.path.sep)
    loc2code = get_code(open(coq_filename, "rb").read())
    file_data = {
        "filename": os.path.sep.join(fields[2:]),
        "coq_project": fields[1],
        "vernac_cmds": [],
        "num_extra_cmds": None,
        "proofs": [],
    }
    meta = open(filename).read()

    with SerAPI(args.timeout, args.debug) as serapi:
        # set the path
        file_data["vernac_cmds"].extend(set_paths(meta, serapi, sexp_cache))
        file_data["num_extra_cmds"] = len(file_data["vernac_cmds"])

        # extract the coq code
        coq_code = extract_code(meta, loc2code)

        # process the coq code
        for num_executed, (code_line, tags) in enumerate(coq_code):
            if "PROOF_NAME" in tags:
                if tags["PROOF_NAME"] not in file_data["proofs"]:
                    file_data["proofs"].append(tags["PROOF_NAME"])
            # execute until the proof editing mode starts
            if args.debug:
                print("%d: %s" % (num_executed, code_line))
            _, ast = serapi.execute(code_line, return_ast=True)
            file_data["vernac_cmds"].append(
                (code_line, tags["VERNAC_TYPE"], sexp_cache.dump(ast)))

    return file_data
コード例 #4
0
def get_proof(args):

    coq_filename = os.path.splitext(args.file)[0] + '.v'
    fields = coq_filename.split(os.path.sep)
    loc2code = get_code(open(coq_filename, 'rb').read())
    meta = open(args.file).read()
    coq_code = extract_code(meta, loc2code)
    with open(os.path.join(args.data_path, args.file[13:-5] + '.json'),
              "r") as json_data:
        file_data = json.load(json_data)
    with open(args.file0, "r") as json_data:
        proof_data0 = json.load(json_data)
    proof_data0 = [tempdic['name'] for tempdic in proof_data0['proofs']]
    for tempproof in file_data['proofs']:
        args.proof = tempproof
        if tempproof not in proof_data0:
            continue
        if os.path.isfile(os.path.join(
                dirname, args.proof +
                '.json')):  # tempproof != 'loc_unconstrained_satisf':
            continue
        db_path = os.path.join(dirname, args.proof + '-sexp_cache')
        sexp_cache = SexpCache(db_path)

        with SerAPI(args.timeout, args.debug) as serapi:
            num_extra_cmds = len(set_paths(meta, serapi, sexp_cache))

            # process the coq code
            proof_start_lines = []
            in_proof = False
            for num_executed, (code_line, tags) in enumerate(coq_code):
                assert code_line == file_data['vernac_cmds'][num_extra_cmds +
                                                             num_executed][0]
                if 'PROOF_NAME' in tags and tags[
                        'PROOF_NAME'] == args.proof:  # the proof ends
                    serapi.pop()
                    line_nb = proof_start_lines[-1]

                    proof_data = record_proof(num_extra_cmds, line_nb,
                                              coq_code[line_nb + 1:],
                                              sexp_cache, serapi, args)
                    if proof_data is not None:
                        dump(proof_data, args)
                    break
                # execute the code
                if args.debug:
                    print('%d: %s' % (num_executed, code_line))
                serapi.execute(code_line)
                if serapi.has_open_goals():
                    if not in_proof:  # the proof starts
                        in_proof = True
                        proof_start_lines.append(num_executed)
                        serapi.push()
                else:
                    in_proof = False

    return
コード例 #5
0
def get_subproofs(human_proof_file, vernac_cmds, sexp_cache, args):
    prf = json.load(open(human_proof_file))
    line_nb = prf['line_nb']
    with SerAPI(args.timeout, args.debug) as serapi:
        for cmd, _, _ in vernac_cmds[:line_nb + 1]:
            serapi.execute(cmd)
        subproofs_data = record_subproofs(line_nb, vernac_cmds[line_nb + 1 : line_nb + 1 + len(prf['steps'])], 
                                          sexp_cache, serapi)

    return subproofs_data 
コード例 #6
0
ファイル: eval_env.py プロジェクト: HelingZhang/CoqGym
 def initialize_serapi(self):
     serapi = SerAPI(timeout=1200)
     if self.with_hammer is not None:
         atp_limit = 29 * self.hammer_timeout // 60
         reconstr_limit = 28 * self.hammer_timeout // 60
         crush_limit = 3 * self.hammer_timeout // 60
         serapi.execute(
             'From Hammer Require Import Hammer. Set Hammer ATPLimit %d. Set Hammer ReconstrLimit %d. Set Hammer CrushLimit %d.'
             % (atp_limit, reconstr_limit, crush_limit))
         if self.with_hammer == 'Z3':
             serapi.execute(
                 'Unset Hammer Vampire. Unset Hammer Eprover. Unset Hammer CVC4.'
             )
         elif self.with_hammer == 'Vampire':
             serapi.execute(
                 'Unset Hammer Z3. Unset Hammer Eprover. Unset Hammer CVC4.'
             )
         elif self.with_hammer == 'Eprover':
             serapi.execute(
                 'Unset Hammer Z3. Unset Hammer Vampire. Unset Hammer CVC4.'
             )
         elif self.with_hammer == 'CVC4':
             serapi.execute(
                 'Unset Hammer Z3. Unset Hammer Vampire. Unset Hammer Eprover.'
             )
         else:
             assert self.with_hammer == 'All'
     return serapi
コード例 #7
0
 def initialize_serapi(self):
     serapi = SerAPI(timeout=1200)
     if self.with_hammer is not None:
         atp_limit = 29 * self.hammer_timeout // 60
         reconstr_limit = 28 * self.hammer_timeout // 60
         crush_limit = 3 * self.hammer_timeout // 60
         serapi.execute(
             "From Hammer Require Import Hammer. Set Hammer ATPLimit %d. Set Hammer ReconstrLimit %d. Set Hammer CrushLimit %d."
             % (atp_limit, reconstr_limit, crush_limit)
         )
         if self.with_hammer == "Z3":
             serapi.execute(
                 "Unset Hammer Vampire. Unset Hammer Eprover. Unset Hammer CVC4."
             )
         elif self.with_hammer == "Vampire":
             serapi.execute(
                 "Unset Hammer Z3. Unset Hammer Eprover. Unset Hammer CVC4."
             )
         elif self.with_hammer == "Eprover":
             serapi.execute(
                 "Unset Hammer Z3. Unset Hammer Vampire. Unset Hammer CVC4."
             )
         elif self.with_hammer == "CVC4":
             serapi.execute(
                 "Unset Hammer Z3. Unset Hammer Vampire. Unset Hammer Eprover."
             )
         else:
             assert self.with_hammer == "All"
     return serapi