def run_load_stdlib(): global stdlib_loaded if stdlib_loaded.is_true(): return import pixie.vm.compiler as compiler import pixie.vm.reader as reader f = open(rpath.rjoin(str(rt.name(load_path.deref())), "pixie/stdlib.pxi")) data = f.read() f.close() rdr = reader.MetaDataReader(reader.StringReader(unicode(data)), u"pixie/stdlib.pxi") result = nil if not we_are_translated(): print "Loading stdlib while interpreted, this will take some time..." with compiler.with_ns(u"pixie.stdlib"): while True: if not we_are_translated(): sys.stdout.write(".") sys.stdout.flush() form = reader.read(rdr, False) if form is reader.eof: break result = compiler.compile(form).invoke([]) if not we_are_translated(): print "done" stdlib_loaded.set_true()
def _load_file(filename, compile=False): from pixie.vm.string import String from pixie.vm.util import unicode_from_utf8 import pixie.vm.reader as reader import pixie.vm.libs.pxic.writer as pxic_writer affirm(isinstance(filename, String), u"filename must be a string") filename = str(rt.name(filename)) if filename.endswith(".pxic"): load_pxic_file(filename) return nil if path.isfile(filename + "c") and not compile: load_pxic_file(filename + "c") return nil affirm(path.isfile(filename), unicode(filename) + u" does not exist") f = open(filename) data = f.read() f.close() if data.startswith("#!"): newline_pos = data.find("\n") if newline_pos > 0: data = data[newline_pos:] if compile: pxic_f = open(filename + "c", "wb") wtr = pxic_writer.Writer(pxic_f, True) with code.bindings(PXIC_WRITER, pxic_writer.WriterBox(wtr)): rt.load_reader( reader.MetaDataReader( reader.StringReader(unicode_from_utf8(data)), unicode(filename))) wtr.finish() pxic_f.close() else: with code.bindings(PXIC_WRITER, nil): rt.load_reader( reader.MetaDataReader( reader.StringReader(unicode_from_utf8(data)), unicode(filename))) return nil
def load_file(filename): from pixie.vm.string import String from pixie.vm.util import unicode_from_utf8 import pixie.vm.reader as reader import os.path as path affirm(isinstance(filename, String), u"filename must be a string") filename = str(rt.name(filename)) affirm(path.isfile(filename), unicode(filename) + u" does not exist") f = open(filename) data = f.read() f.close() if data.startswith("#!"): newline_pos = data.find("\n") if newline_pos > 0: data = data[newline_pos:] rt.load_reader( reader.MetaDataReader(reader.StringReader(unicode_from_utf8(data)), unicode(filename))) return nil
def _read_string(s): import pixie.vm.reader as reader return reader.read(reader.StringReader(unicode(rt.name(s))), True)