# Copyright 2006-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ pragma.syntax("0.9") pragma.enable("one-method-object") /** Converts an optional unget value into an optional uncall value. Currently does not check whether 'name' is a string. */ def ungetToUncall(loader, name) { return if (name != null) { [loader, "get", [name]] } } /** * Such-that isn't ordinarily defined at this level so we copy in a minimal definition * Copyright 2005 Mark S. Miller under the terms of the MIT X license * found at http://www.opensource.org/licenses/mit-license.html ................ */ def __suchThat { to run(specimen, optEjector) :any { return [specimen, specimen] } to handle(expr, flag) :any { return def suchThatFunc(_, optEjector) :void { if (!flag) { throw.eject(optEjector, "such-that failure") } } return suchThatFunc } } /** Converts an optional uncall value into an optional unget value. That is, returns 'name' if 'portrayal' matches [==loader, =="get", [name]]; otherwise null. */ def uncallToUnget (loader, portrayal) { # xxx I do not understand the justification in the doc-comment of E-on-Java baseLoader#optUnget. def [a ? (a==loader), b ? (b=="get"), [name]] exit fn _ {return null} := portrayal return name } def scopeToRightInvertibleLoader(scope) implements DeepFrozenStamp { def inversion := __makeMap.fromIteratable(def _.iterate(f) { for noun => binding in scope.bindings() { f(binding[][], noun) } }, false) return def invertibleScopeLoader { to fetch(key :String, absentThunk) { return scope.fetch(key, absentThunk) } to optUnget(specimen) { return inversion.fetch(specimen, fn {null}) } to optUncall(specimen) { return ungetToUncall(invertibleScopeLoader, invertibleScopeLoader.optUnget(specimen)) } } } def makePathLoader implements DeepFrozenStamp { to run(self, name :String, fetchpath :ConstList) { def loader { to __printOn(tw :TextWriter) { tw.print("<", name, ":*>") } to fetch(fqn :String, absentThunk) { return \ if (fqn.run(fqn.size() - 2, fqn.size()) == ".*") { getSafeScope().fetch("import__uriGetter", throw) \ ["org.erights.e.elang.interp.makePackageLoader"] \ .run(self, name + ":", fqn) } else { for sub in fetchpath { escape next { return sub.fetch(fqn, next) } } absentThunk() } } to get(fqn) { return loader.fetch(fqn, def getFailureThunk() { throw(E.toQuote(self) + " can't find " + E.toQuote(fqn)) }) } to optUncall(specimen) { for sub ? sub.__respondsTo("optUnget", 1) in fetchpath { def uncall := ungetToUncall(self, sub.optUnget(specimen)) if (uncall != null) { return uncall } } return null } to optUnget(specimen) { # xxx this is how Java-E does it, and claims a justification, but *what*? return uncallToUnget(self, self.optUncall(specimen)) } } return loader } } lisp["E.KNOT", "+THE-MAKE-PATH-LOADER+"].put(makePathLoader) lisp["E.KNOT", "+SCOPE-TO-RIGHT-INVERTIBLE-LOADER+"].put(scopeToRightInvertibleLoader)