def compile(path, file_filter): dir = os.path.dirname(path) text = open(path).read() maybe_xfail(text) base = os.path.splitext(path)[0] include_stdlib = False if path.endswith("include-stdlib.q"): include_stdlib = True c = Compiler(include_stdlib) try: c.urlparse(path) c.compile() failed_expectations = [] for root in c.roots: # Skip standard library: if "quarkc/lib/" in root.url: continue for ast in root.files: if ast.filename == "reflector": continue if file_filter(ast.filename): continue astname = os.path.splitext(ast.filename)[0] + ".astc" astpath = os.path.join(dir, astname) content = ast.pprint() expected = check_file(astpath, content) if content != expected: failed_expectations.append(astname) assert not failed_expectations, failed_expectations except (CompileError, ParseError), e: expected = base + ".err" computed = str(e).replace(os.path.dirname(path) + "/", "") assert_file(expected, computed)
def compile(path, file_filter): dir = os.path.dirname(path) text = open(path).read() maybe_xfail(text) base = os.path.splitext(path)[0] c = Compiler() try: c.urlparse(path) c.compile() failed_expectations = [] for root in c.roots: for ast in root.files: if ast.filename == "reflector": continue if file_filter(ast.filename): continue astname = os.path.splitext(ast.filename)[0] + ".astc" astpath = os.path.join(dir, astname) content = ast.pprint() expected = check_file(astpath, content) if content != expected: failed_expectations.append(astname) assert not failed_expectations, failed_expectations except (CompileError, ParseError), e: expected = base + ".err" computed = str(e).replace(os.path.dirname(path) + "/", "") assert_file(expected, computed)
def parse(path, file_filter): dir = os.path.dirname(path) text = open(path).read() maybe_xfail(text) c = Compiler() c.urlparse(path, recurse=False) for ast in c.roots[path].files: if file_filter(ast.filename): continue base = os.path.splitext(ast.filename)[0] assert_file(os.path.join(dir, base + ".ast"), ast.pprint()) code = ast.code() assert_file(os.path.join(dir, base + ".code"), code) rtc = Compiler() rtc.urlparse(base + ".code", recurse=False) for f in rtc.roots[base + ".code"].files: if f.name == base + ".code": assert f.code() == code break else: assert False
def get_dist(name): code = os.path.join(directory, name + ".q") cmp = Compiler() file = cmp.urlparse(code, recurse=False) name, ver = namever(file) return name
def do_compile(output, path): text = open(path).read() for b in backends: maybe_xfail(text, b().ext) return path, compile(Compiler(), path, output, *backends)