01: package sisc.nativefun;
02:
03: import java.util.*;
04: import sisc.data.*;
05: import sisc.interpreter.*;
06:
07: public abstract class IndexedLibraryAdapter extends NativeLibrary {
08: static class Token {
09: Class context;
10: int id;
11:
12: public Token(Class context, int id) {
13: this .context = context;
14: this .id = id;
15:
16: }
17: }
18:
19: protected HashMap bindings = new HashMap(0);
20:
21: public abstract Value construct(Object context, int id);
22:
23: protected void define(String s, int id) {
24: define(s, null, id);
25: }
26:
27: protected void define(String s, Class context, int id) {
28: Symbol name = Symbol.get(s);
29: bindings.put(name, new Token(context, id));
30: }
31:
32: public String getLibraryName() {
33: return getClass().getName();
34: }
35:
36: public Symbol[] getLibraryBindingNames(Interpreter r) {
37: Symbol[] slist = new Symbol[bindings.size()];
38: int x = 0;
39: for (Iterator i = bindings.keySet().iterator(); i.hasNext();)
40: slist[x++] = (Symbol) i.next();
41: return slist;
42: }
43:
44: public Value getBindingValue(Interpreter r, Symbol name)
45: throws NoSuchMethodError {
46: Token t = (Token) bindings.get(name);
47: try {
48: Value v = construct(t.context, t.id);
49: if (v instanceof NamedValue)
50: v.setName(name);
51:
52: return v;
53: } catch (NullPointerException n) {
54: throw new NoSuchMethodError();
55: }
56: }
57:
58: public float getLibraryVersion() {
59: return 0.0f;
60: }
61: }
62: /*
63: * The contents of this file are subject to the Mozilla Public
64: * License Version 1.1 (the "License"); you may not use this file
65: * except in compliance with the License. You may obtain a copy of
66: * the License at http://www.mozilla.org/MPL/
67: *
68: * Software distributed under the License is distributed on an "AS
69: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
70: * implied. See the License for the specific language governing
71: * rights and limitations under the License.
72: *
73: * The Original Code is the Second Interpreter of Scheme Code (SISC).
74: *
75: * The Initial Developer of the Original Code is Scott G. Miller.
76: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
77: * Scott G. Miller. All Rights Reserved.
78: *
79: * Contributor(s):
80: *
81: * Alternatively, the contents of this file may be used under the
82: * terms of the GNU General Public License Version 2 or later (the
83: * "GPL"), in which case the provisions of the GPL are applicable
84: * instead of those above. If you wish to allow use of your
85: * version of this file only under the terms of the GPL and not to
86: * allow others to use your version of this file under the MPL,
87: * indicate your decision by deleting the provisions above and
88: * replace them with the notice and other provisions required by
89: * the GPL. If you do not delete the provisions above, a recipient
90: * may use your version of this file under either the MPL or the
91: * GPL.
92: */
|