Пример #1
0
def builtin_import(engine, payload):
    if not isinstance(payload, Str):
        raise Exception('unknown data type.')
    stack = engine.current_stack()
    executable_path = rabspath(engine.executable)
    pkg = rjoin(_dirname(_dirname(executable_path)), 'pkg')
    path = rjoin(pkg, '%s.ho' % payload.str_val)
    with open(path) as f:
        env = engine.run_module_code(f.read())
        stack = engine.current_stack()
        stack.namespace.update(env.namespace)
        stack.defs.update(env.defs)
    return null
Пример #2
0
 def init_from_ini(self):
     exedir = self.get_exedir()
     if not exedir:
         return
     inifile = rpath.rjoin(exedir, "rsqueak.ini")
     if os.path.exists(inifile):
         f = streamio.open_file_as_stream(inifile, mode="r", buffering=0)
         try:
             argini = [""]
             line = f.readline().strip()
             while len(line) > 0:
                 if line.startswith("[") or line.startswith(";"):
                     pass
                 elif "=" in line:
                     option, param = line.split("=", 1)
                     option = option.strip()
                     param = param.strip()
                     param = param.strip("\"'")
                     if param == "1":
                         argini += ["--%s" % option]
                     elif param == "0":
                         pass
                     else:
                         argini += ["--%s" % option, param]
                 else:
                     raise error.Exit("Invalid line in INI file: %s" % line)
                 line = f.readline().strip()
             self.parse_args(argini)
         finally:
             f.close()
Пример #3
0
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()
Пример #4
0
 def init_from_ini(self):
     exedir = self.get_exedir()
     if not exedir:
         return
     inifile = rpath.rjoin(exedir, "rsqueak.ini")
     if os.path.exists(inifile):
         f = streamio.open_file_as_stream(inifile, mode="r", buffering=0)
         try:
             argini = [""]
             line = f.readline().strip()
             while len(line) > 0:
                 if line.startswith("[") or line.startswith(";"):
                     pass
                 elif "=" in line:
                     option, param = line.split("=", 1)
                     option = option.strip()
                     param = param.strip()
                     param = param.strip("\"'")
                     if param == "1":
                         argini += ["--%s" % option]
                     elif param == "0":
                         pass
                     else:
                         argini += ["--%s" % option, param]
                 else:
                     raise error.Exit("Invalid line in INI file: %s" % line)
                 line = f.readline().strip()
             self.parse_args(argini)
         finally:
             f.close()
Пример #5
0
def rpath_example():
    # normalize a pathname by collapsing redundant separators and up-level
    # references so that A//B, A/B/, A/./B and A/foo/../B all become A/B
    print rpath.rnormpath("///..//./foo/.//bar")    # "/foo/bar"

    # return a normalized absolutized version of the pathname path
    print rpath.rabspath('foo')                            # $(pwd)/foo

    # join two pathname components, inserting '/' as needed
    print rpath.rjoin("/foo", "bar" + rpath.sep + "foo")

    # return True if path is an absolute pathname
    print rpath.risabs('C:\\foo\\bar')              # 0

    # return True if path is an existing directory
    print rpath.risdir('_some_non_existant_file_')         # 0
Пример #6
0
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()
Пример #7
0
def load_(path, env, cont):
    # XXX: have some programmatically editable search path?
    filename = path.strval
    for dir_path in search_paths:
        whole_path = rpath.rjoin(dir_path, filename)
        if file_exists(whole_path):
            try:
                program = parse_file(whole_path)
            except ParseError as e:
                return kt.signal_parse_error(e.nice_error_message(),
                                             whole_path)
            except LexerError as e:
                return kt.signal_parse_error(e.nice_error_message(),
                                             whole_path)
            return program, env, kt.ConstantCont(kt.inert, cont)
    else:
        return kt.signal_file_not_found(filename)
Пример #8
0
 def ensure_path(self):
     path = self.path
     if path:
         if os.path.exists(path):
             self.path = rpath.rabspath(path)
             return
         exedir = self.get_exedir()
         if not exedir:
             return
         path = rpath.rjoin(exedir, path)
         if os.path.exists(path):
             self.path = rpath.rabspath(path)
             return
     else:
         for filename in os.listdir(os.getcwd()):
             if filename.startswith("Squeak") and filename.endswith(".image"):
                 path = filename
                 break
     if path is None:
         from rsqueakvm.util.dialog import get_file
         path = get_file()
     self.path = rpath.rabspath(path)
Пример #9
0
def obtainModule(libraryPaths, recorder, filePath):
    for libraryPath in libraryPaths:
        path = rjoin(libraryPath, filePath)

        if path in moduleCache.cache:
            log.log(["import"],
                    u"Importing %s (cached)" % path.decode("utf-8"))
            return moduleCache.cache[path]

        log.log(["import"], u"Importing %s" % path.decode("utf-8"))
        code = tryExtensions(path, recorder)
        if code is None:
            continue
        # Cache.
        moduleCache.cache[path] = code
        return code
    else:
        log.log(["import", "error"],
                u"Failed to import from %s" % filePath.decode("utf-8"))
        debugPrint("Failed to import:", filePath)
        raise userError(u"Module '%s' couldn't be found" %
                        filePath.decode("utf-8"))
Пример #10
0
def obtainModule(libraryPaths, recorder, filePath):
    for libraryPath in libraryPaths:
        path = rjoin(libraryPath, filePath)

        if path in moduleCache.cache:
            log.log(["import"], u"Importing %s (cached)" %
                    path.decode("utf-8"))
            return moduleCache.cache[path]

        log.log(["import"], u"Importing %s" % path.decode("utf-8"))
        code = tryExtensions(path, recorder)
        if code is None:
            continue
        # Cache.
        moduleCache.cache[path] = code
        return code
    else:
        log.log(["import", "error"], u"Failed to import from %s" %
                filePath.decode("utf-8"))
        debugPrint("Failed to import:", filePath)
        raise userError(u"Module '%s' couldn't be found" %
                        filePath.decode("utf-8"))
Пример #11
0
 def ensure_path(self):
     path = self.path
     if path:
         if os.path.exists(path):
             self.path = rpath.rabspath(path)
             return
         exedir = self.get_exedir()
         if not exedir:
             return
         path = rpath.rjoin(exedir, path)
         if os.path.exists(path):
             self.path = rpath.rabspath(path)
             return
     else:
         for filename in os.listdir(os.getcwd()):
             if filename.startswith("Squeak") and filename.endswith(
                     ".image"):
                 path = filename
                 break
     if path is None:
         from rsqueakvm.util.dialog import get_file
         path = get_file()
     self.path = rpath.rabspath(path)
Пример #12
0
def dirname(path):
    norm = rpath.rnormpath(path)
    if not rpath.risabs(norm):
        norm = rpath.rjoin(".", norm)
    return norm.rsplit(rpath.sep, 1)[0]
Пример #13
0
_exports['combine-with-non-list-operands-continuation'] = kt.combine_with_non_list_operands_cont
_exports['encapsulation-type-error-continuation'] = kt.encapsulation_type_error_cont
_exports['operand-mismatch-continuation'] = kt.operand_mismatch_cont
_exports['arity-mismatch-continuation'] = kt.arity_mismatch_cont
_exports['symbol-not-found-continuation'] = kt.symbol_not_found_cont
_exports['add-positive-to-negative-infinity-continuation'] = kt.add_positive_to_negative_infinity_cont
_exports['multiply-infinity-by-zero-continuation'] = kt.multiply_infinity_by_zero_cont
_exports['divide-infinity-continuation'] = kt.divide_infinity_cont
_exports['divide-by-zero-continuation'] = kt.divide_by_zero_cont

_ground_env = kt.Environment([], _exports)

def dirname(path):
    norm = rpath.rnormpath(path)
    if not rpath.risabs(norm):
        norm = rpath.rjoin(".", norm)
    return norm.rsplit(rpath.sep, 1)[0]

print "file si", __file__

here = dirname(__file__)

kernel_eval(parse_file(rpath.rjoin(here, "kernel.k")), _ground_env)
_extended_env = kt.Environment([_ground_env], {})
kernel_eval(parse_file(rpath.rjoin(here, "extension.k")), _extended_env)

def standard_value(name):
    return _ground_env.bindings[name]

del _exports