def racket_fasl_to_sexp(fasl_file): from pycket.prims.input_output import open_infile from rpython.rlib import rtime load_fasl() fasl_to_sexp = get_primitive("fasl->s-exp") port = open_infile(W_Path(fasl_file), "r") start_time = rtime.time() sexp = fasl_to_sexp.call_interpret([port, w_true]) console_log("racket fasl->s-exp time : %s" % (rtime.time()-start_time), debug=True) console_log("%s" % sexp.tostring(), 1)
def test_peek_bug(tmpdir): from pycket.prims.input_output import open_infile from pycket import values_string s = "abc\ndef\nghi" f = tmpdir.join("example.txt") f.write(s) w_n = values_string.W_String.fromstr_utf8(str(f)) w_p = open_infile(w_n, "r") for c in s: c1 = w_p.peek() assert c1 == c c2 = w_p.read(1) assert c == c c = w_p.peek() assert c == '' c = w_p.read(1) assert c == '' w_p.close()
def test_peek_bug(tmpdir): from pycket.prims.input_output import open_infile from pycket import values_string s = "abc\ndef\nghi" f = tmpdir.join("example.txt") f.write(s) w_n = values_string.W_String.fromstr_utf8(str(f)) w_p = open_infile(w_n, "r") for c in s: c1 = w_p.peek() assert c1 == c c2 = w_p.read(1) assert c == c c = w_p.peek() assert c == '' c = w_p.read(1) assert c == '' w_p.close()
def dev_mode_metainterp_fasl_zo(): load_fasl() from pycket.prims.input_output import open_infile, open_outfile from pycket.values import W_Path import os # Stuff for writing out the fasl if not os.path.exists("sample.fasl"): print("Generating sample.fasl first") sexp_to_fasl = get_primitive("s-exp->fasl") w_replace_sym = W_Symbol.make("replace") sexp = sample_sexp() out_port = open_outfile(W_Path("sample.fasl"), "w", w_replace_sym) sexp_to_fasl.call_interpret([sexp, out_port]) out_port.close() fasl_to_sexp = get_primitive("fasl->s-exp") port = open_infile(W_Path("sample.fasl"), "r") r = fasl_to_sexp.call_interpret([port, w_true])
def dev_mode_metainterp_fasl_zo(): load_fasl() from pycket.prims.input_output import open_infile, open_outfile from pycket.values import W_Path import os # Stuff for writing out the fasl if not os.path.exists("sample.fasl"): print("Generating sample.fasl first") sexp_to_fasl = get_primitive("s-exp->fasl") w_replace_sym = W_Symbol.make("replace") sexp = sample_sexp() out_port = open_outfile(W_Path("sample.fasl"), "w", w_replace_sym) sexp_to_fasl.call_interpret([sexp, out_port]) out_port.close() fasl_to_sexp = get_primitive("fasl->s-exp") port = open_infile(W_Path("sample.fasl"), "r") r = fasl_to_sexp.call_interpret([port, w_true])
def to_sexp_from_file(self, file_name): from pycket.values_string import W_String from pycket.prims.input_output import open_infile port = open_infile(W_String.make(file_name), "rb") return self.to_sexp_from_w_port(port)
def to_sexp_from_file(self, file_name): from pycket.values_string import W_String from pycket.prims.input_output import open_infile port = open_infile(W_String.make(file_name), "rb") return self.to_sexp_from_w_port(port)